diff --git a/packages/migrations/CHANGELOG.json b/packages/migrations/CHANGELOG.json index 9072d612e5..846ef7a098 100644 --- a/packages/migrations/CHANGELOG.json +++ b/packages/migrations/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "4.3.2", + "changes": [ + { + "note": "Removed dependency on @0x/order-utils", + "pr": 2096 + } + ] + }, { "timestamp": 1567521715, "version": "4.3.1", diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 3e9b18de06..e55896c48f 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -59,7 +59,6 @@ "@0x/base-contract": "^5.3.3", "@0x/contract-addresses": "^3.1.0", "@0x/contract-artifacts": "^2.2.1", - "@0x/order-utils": "^8.3.1", "@0x/sol-compiler": "^3.1.14", "@0x/subproviders": "^5.0.3", "@0x/typescript-typings": "^4.2.5", diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index b6ca254959..ff17c3d0cb 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -1,15 +1,43 @@ import * as wrappers from '@0x/abi-gen-wrappers'; import { ContractAddresses } from '@0x/contract-addresses'; import * as artifacts from '@0x/contract-artifacts'; -import { assetDataUtils } from '@0x/order-utils'; import { Web3ProviderEngine } from '@0x/subproviders'; -import { BigNumber, providerUtils } from '@0x/utils'; +import { AbiEncoder, BigNumber, providerUtils } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { SupportedProvider, TxData } from 'ethereum-types'; +import { MethodAbi, 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. @@ -55,7 +83,7 @@ export async function runMigrationsAsync( ); // Exchange - const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); + const zrxAssetData = encodeERC20AssetData(zrxToken.address); const exchange = await wrappers.ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, @@ -173,8 +201,8 @@ export async function runMigrationsAsync( txDefaults, artifacts, exchange.address, - assetDataUtils.encodeERC20AssetData(zrxToken.address), - assetDataUtils.encodeERC20AssetData(etherToken.address), + encodeERC20AssetData(zrxToken.address), + encodeERC20AssetData(etherToken.address), ); // OrderValidator