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

Commit

Permalink
remove dependency on @0x/order-utils from @0x/migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
xianny committed Sep 5, 2019
1 parent 7eae251 commit 3bb5446
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/migrations/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "4.3.2",
"changes": [
{
"note": "Removed dependency on @0x/order-utils",
"pr": 2096
}
]
},
{
"timestamp": 1567521715,
"version": "4.3.1",
Expand Down
1 change: 0 additions & 1 deletion packages/migrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 34 additions & 6 deletions packages/migrations/src/migration.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3bb5446

Please sign in to comment.