Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
use DevUtils contract to encode ERC20 asset data
Browse files Browse the repository at this point in the history
  • Loading branch information
xianny committed Sep 10, 2019
1 parent 3776e31 commit 97b8c39
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions packages/migrations/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,13 @@ import * as wrappers from '@0x/abi-gen-wrappers';
import { ContractAddresses } from '@0x/contract-addresses';
import * as artifacts from '@0x/contract-artifacts';
import { Web3ProviderEngine } from '@0x/subproviders';
import { AbiEncoder, BigNumber, providerUtils } from '@0x/utils';
import { BigNumber, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { MethodAbi, SupportedProvider, TxData } from 'ethereum-types';
import { SupportedProvider, TxData } from 'ethereum-types';
import * as _ from 'lodash';

import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info';

// HACK (xianny): Copied from @0x/order-utils to get rid of circular dependency
/**
* Encodes an ERC20 token address into a hex encoded assetData string, usable in the makerAssetData or
* takerAssetData fields in a 0x order.
* @param tokenAddress The ERC20 token address to encode
* @return The hex encoded assetData string
*/
function encodeERC20AssetData(tokenAddress: string): string {
const ERC20_METHOD_ABI: MethodAbi = {
constant: false,
inputs: [
{
name: 'tokenContract',
type: 'address',
},
],
name: 'ERC20Token',
outputs: [],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
};
const encodingRules: AbiEncoder.EncodingRules = { shouldOptimize: true };
const abiEncoder = new AbiEncoder.Method(ERC20_METHOD_ABI);
const args = [tokenAddress];
const assetData = abiEncoder.encode(args, encodingRules);
return assetData;
}

/**
* Creates and deploys all the contracts that are required for the latest
* version of the 0x protocol.
Expand All @@ -52,6 +23,9 @@ export async function runMigrationsAsync(
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const web3Wrapper = new Web3Wrapper(provider);

const staticDevUtils = new wrappers.DevUtilsContract('0x', provider);
const encodeERC20AssetData = staticDevUtils.encodeERC20AssetData.callAsync;

// Proxies
const erc20Proxy = await wrappers.ERC20ProxyContract.deployFrom0xArtifactAsync(
artifacts.ERC20Proxy,
Expand Down Expand Up @@ -83,7 +57,7 @@ export async function runMigrationsAsync(
);

// Exchange
const zrxAssetData = encodeERC20AssetData(zrxToken.address);
const zrxAssetData = await encodeERC20AssetData(zrxToken.address);
const exchange = await wrappers.ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
provider,
Expand Down Expand Up @@ -201,8 +175,8 @@ export async function runMigrationsAsync(
txDefaults,
artifacts,
exchange.address,
encodeERC20AssetData(zrxToken.address),
encodeERC20AssetData(etherToken.address),
await encodeERC20AssetData(zrxToken.address),
await encodeERC20AssetData(etherToken.address),
);

// OrderValidator
Expand Down

0 comments on commit 97b8c39

Please sign in to comment.