How to use the @0x/order-utils.assetDataUtils.isERC20AssetData function in @0x/order-utils

To help you get started, we’ve selected a few @0x/order-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / contract-wrappers / src / fetchers / asset_balance_and_proxy_allowance_fetcher.ts View on Github external
public async getBalanceAsync(assetData: string, userAddress: string): Promise {
        const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
        let balance: BigNumber | undefined;
        if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
            balance = await this._erc20Token.getBalanceAsync(decodedAssetData.tokenAddress, userAddress, {
                defaultBlock: this._stateLayer,
            });
        } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
            const tokenOwner = await this._erc721Token.getOwnerOfAsync(
                decodedAssetData.tokenAddress,
                decodedAssetData.tokenId,
                {
                    defaultBlock: this._stateLayer,
                },
            );
            balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0);
        } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
            // The `balance` for MultiAssetData is the total units of the entire `assetData` that are held by the `userAddress`.
            for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) {
                const nestedAmountElement = decodedAssetData.amounts[index];
github 0xProject / 0x-monorepo / packages / contract-wrappers / src / fetchers / asset_balance_and_proxy_allowance_fetcher.ts View on Github external
public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise {
        const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
        let proxyAllowance: BigNumber | undefined;
        if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
            proxyAllowance = await this._erc20Token.getProxyAllowanceAsync(decodedAssetData.tokenAddress, userAddress, {
                defaultBlock: this._stateLayer,
            });
        } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
            const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync(
                decodedAssetData.tokenAddress,
                userAddress,
                {
                    defaultBlock: this._stateLayer,
                },
            );
            if (isApprovedForAll) {
                return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS);
            } else {
                const isApproved = await this._erc721Token.isProxyApprovedAsync(
                    decodedAssetData.tokenAddress,
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / order_watcher.ts View on Github external
private _addAssetDataToAbiDecoder(assetData: string): void {
        const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
        if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
            this._collisionResistantAbiDecoder.addERC20Token(decodedAssetData.tokenAddress);
        } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
            this._collisionResistantAbiDecoder.addERC721Token(decodedAssetData.tokenAddress);
        } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
            _.each(decodedAssetData.nestedAssetData, nestedAssetDataElement =>
                this._addAssetDataToAbiDecoder(nestedAssetDataElement),
            );
        }
    }
    private _deleteLazyStoreBalance(assetData: string, userAddress: string): void {
github 0xProject / 0x-monorepo / packages / fill-scenarios / src / fill_scenarios.ts View on Github external
private async _increaseBalanceAndAllowanceWithAssetDataAsync(
        assetData: string,
        userAddress: string,
        amount: BigNumber,
    ): Promise {
        const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData);
        if (assetDataUtils.isERC20AssetData(decodedAssetData)) {
            await this._increaseERC20BalanceAndAllowanceAsync(decodedAssetData.tokenAddress, userAddress, amount);
        } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) {
            await this._increaseERC721BalanceAndAllowanceAsync(
                decodedAssetData.tokenAddress,
                userAddress,
                decodedAssetData.tokenId,
            );
        } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
            for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) {
                const amountsElement = decodedAssetData.amounts[index];
                const totalAmount = amount.times(amountsElement);
                await this._increaseBalanceAndAllowanceWithAssetDataAsync(
                    nestedAssetDataElement,
                    userAddress,
                    totalAmount,
                );