aboutsummaryrefslogblamecommitdiffstats
path: root/packages/asset-buyer/src/utils/asset_data_utils.ts
blob: 10ff3105775ca0c9b67c3ded8bb1826f796b52aa (plain) (tree)

























                                                                                                         
import { ContractWrappers } from '@0xproject/contract-wrappers';
import { assetDataUtils as sharedAssetDataUtils } from '@0xproject/order-utils';
import * as _ from 'lodash';

import { AssetBuyerError } from '../types';

export const assetDataUtils = {
    ...sharedAssetDataUtils,
    getEtherTokenAssetData(contractWrappers: ContractWrappers): string {
        const etherTokenAddressIfExists = contractWrappers.etherToken.getContractAddressIfExists();
        if (_.isUndefined(etherTokenAddressIfExists)) {
            throw new Error(AssetBuyerError.NoEtherTokenContractFound);
        }
        const etherTokenAssetData = sharedAssetDataUtils.encodeERC20AssetData(etherTokenAddressIfExists);
        return etherTokenAssetData;
    },
    getZrxTokenAssetData(contractWrappers: ContractWrappers): string {
        let zrxTokenAssetData: string;
        try {
            zrxTokenAssetData = contractWrappers.exchange.getZRXAssetData();
        } catch (err) {
            throw new Error(AssetBuyerError.NoZrxTokenContractFound);
        }
        return zrxTokenAssetData;
    },
};