How to use the @0x/order-utils.assetDataUtils.decodeERC20AssetData 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 / website / ts / blockchain.ts View on Github external
private async _convertDecodedLogToFillAsync(decodedLog: LogWithDecodedArgs): Promise {
        const args = decodedLog.args;
        const blockTimestamp = await this._web3Wrapper.getBlockTimestampAsync(decodedLog.blockHash);
        const makerToken = assetDataUtils.decodeERC20AssetData(args.makerAssetData).tokenAddress;
        const takerToken = assetDataUtils.decodeERC20AssetData(args.takerAssetData).tokenAddress;
        const fill = {
            filledTakerTokenAmount: args.takerAssetFilledAmount,
            filledMakerTokenAmount: args.makerAssetFilledAmount,
            logIndex: decodedLog.logIndex,
            maker: args.makerAddress,
            orderHash: args.orderHash,
            taker: args.takerAddress,
            makerToken,
            takerToken,
            paidMakerFee: args.makerFeePaid,
            paidTakerFee: args.takerFeePaid,
            transactionHash: decodedLog.transactionHash,
            blockTimestamp,
        };
        return fill;
github 0xProject / 0x-monorepo / packages / website / ts / components / fill_order.tsx View on Github external
private async _checkForUntrackedTokensAndAskToAddAsync(): Promise {
        if (!_.isEmpty(this.state.orderJSONErrMsg)) {
            return;
        }
        const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
            .tokenAddress;
        const takerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.takerAssetData)
            .tokenAddress;
        const makerTokenIfExists = this.props.tokenByAddress[makerTokenAddress];
        const takerTokenIfExists = this.props.tokenByAddress[takerTokenAddress];
        const tokensToTrack: Token[] = [];
        const isUnseenMakerToken = makerTokenIfExists === undefined;
        const isMakerTokenTracked = makerTokenIfExists !== undefined && utils.isTokenTracked(makerTokenIfExists);
        if (isUnseenMakerToken) {
            tokensToTrack.push({
                ...this.state.parsedOrder.metadata.makerToken,
                address: makerTokenAddress,
                iconUrl: undefined,
                trackedTimestamp: undefined,
                isRegistered: false,
            });
        } else if (!isMakerTokenTracked) {
            tokensToTrack.push(makerTokenIfExists);
github 0xProject / 0x-monorepo / packages / order-watcher / src / order_watcher / dependent_order_hashes_tracker.ts View on Github external
private _getDependentOrderHashesByERC20AssetData(makerAddress: string, erc20AssetData: string): string[] {
        const tokenAddress = assetDataUtils.decodeERC20AssetData(erc20AssetData).tokenAddress;
        let dependentOrderHashes: string[] = [];
        if (
            !_.isUndefined(this._orderHashesByERC20ByMakerAddress[makerAddress]) &&
            !_.isUndefined(this._orderHashesByERC20ByMakerAddress[makerAddress][tokenAddress])
        ) {
            dependentOrderHashes = Array.from(this._orderHashesByERC20ByMakerAddress[makerAddress][tokenAddress]);
        }
        return dependentOrderHashes;
    }
    private _getDependentOrderHashesByERC721AssetData(makerAddress: string, erc721AssetData: string): string[] {
github 0xProject / 0x-monorepo / packages / website / ts / components / fill_order.tsx View on Github external
private _renderVisualOrder(): React.ReactNode {
        const takerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.takerAssetData)
            .tokenAddress;
        const takerToken = this.props.tokenByAddress[takerTokenAddress];
        const orderTakerAmount = this.state.parsedOrder.signedOrder.takerAssetAmount;
        const orderMakerAmount = this.state.parsedOrder.signedOrder.makerAssetAmount;
        const takerAssetToken = {
            amount: orderTakerAmount.minus(this.state.unavailableTakerAmount),
            symbol: takerToken.symbol,
        };
        const fillToken = this.props.tokenByAddress[takerTokenAddress];
        const makerTokenAddress = assetDataUtils.decodeERC20AssetData(this.state.parsedOrder.signedOrder.makerAssetData)
            .tokenAddress;
        const makerToken = this.props.tokenByAddress[makerTokenAddress];
        const makerAssetToken = {
            amount: orderMakerAmount
                .times(takerAssetToken.amount)
                .div(orderTakerAmount)
                .integerValue(BigNumber.ROUND_FLOOR),
            symbol: makerToken.symbol,
        };
        const fillAssetToken = {
            amount: this.props.orderFillAmount,
            symbol: takerToken.symbol,
        };
        const parsedOrderExpiration = this.state.parsedOrder.signedOrder.expirationTimeSeconds;

        let orderReceiveAmount = 0;
github melonproject / protocol / src / contracts / exchanges / third-party / 0x / calls / getOrderInfo.ts View on Github external
const postProcess = async (
  environment,
  result,
  { params },
): Promise => {
  const takerTokenAddress = assetDataUtils.decodeERC20AssetData(
    params.signedOrder.takerAssetData,
  ).tokenAddress;
  const takerToken = await getToken(environment, takerTokenAddress);

  const info = {
    hash: result.orderHash,
    status: result.orderStatus,
    takerFilled: createQuantity(takerToken, result.orderTakerAssetFilledAmount),
  };
  return info;
};
github 0xProject / 0x-monorepo / packages / website / ts / blockchain.ts View on Github external
private async _convertDecodedLogToFillAsync(decodedLog: LogWithDecodedArgs): Promise {
        const args = decodedLog.args;
        const blockTimestamp = await this._web3Wrapper.getBlockTimestampAsync(decodedLog.blockHash);
        const makerToken = assetDataUtils.decodeERC20AssetData(args.makerAssetData).tokenAddress;
        const takerToken = assetDataUtils.decodeERC20AssetData(args.takerAssetData).tokenAddress;
        const fill = {
            filledTakerTokenAmount: args.takerAssetFilledAmount,
            filledMakerTokenAmount: args.makerAssetFilledAmount,
            logIndex: decodedLog.logIndex,
            maker: args.makerAddress,
            orderHash: args.orderHash,
            taker: args.takerAddress,
            makerToken,
            takerToken,
            paidMakerFee: args.makerFeePaid,
            paidTakerFee: args.takerFeePaid,
            transactionHash: decodedLog.transactionHash,
            blockTimestamp,
        };
        return fill;
    }
github melonproject / protocol / src / contracts / exchanges / third-party / 0x / utils / createOrder.ts View on Github external
const approveOrder = async (
  environment: Environment,
  exchange: Address,
  order: Order,
) => {
  const erc20Proxy = await getAssetProxy(environment, exchange);

  const makerTokenAddress = assetDataUtils.decodeERC20AssetData(
    order.makerAssetData,
  ).tokenAddress;

  const makerToken = await getToken(environment, makerTokenAddress);
  const makerQuantity = createQuantity(
    makerToken,
    order.makerAssetAmount.toString(),
  );

  await approve(environment, { howMuch: makerQuantity, spender: erc20Proxy });
};
github melonproject / protocol / src / contracts / exchanges / third-party / 0x / transactions / fillOrder.ts View on Github external
const orderInfo = await getOrderInfo(environment, contractAddress, {
    signedOrder,
  });

  ensure(
    orderInfo.status === `${OrderStatus.FILLABLE}`,
    `Order is not fillable. Got status: ${OrderStatus[orderInfo.status]}`,
  );

  const validSignature = await isValidSignature(environment, contractAddress, {
    signedOrder,
  });

  ensure(validSignature, 'Signature invalid');

  const { tokenAddress } = assetDataUtils.decodeERC20AssetData(
    signedOrder.takerAssetData,
  );

  const takerToken = await getToken(environment, tokenAddress);

  const takerQuantity =
    providedTakerQuantity ||
    createQuantity(takerToken, signedOrder.takerAssetAmount.toString());

  const erc20Proxy = await getAssetProxy(environment, contractAddress);

  await approve(environment, { howMuch: takerQuantity, spender: erc20Proxy });
};