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

Commit

Permalink
Pass in WETH address into Forwarder constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
abandeali1 committed Nov 30, 2019
1 parent 6beedba commit 84b660d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
35 changes: 3 additions & 32 deletions packages/migrations/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,12 @@ import { ExchangeContract } from '@0x/contracts-exchange';
import { ForwarderContract } from '@0x/contracts-exchange-forwarder';
import { StakingProxyContract, TestStakingContract, ZrxVaultContract } from '@0x/contracts-staking';
import { Web3ProviderEngine } from '@0x/subproviders';
import { AbiEncoder, BigNumber, providerUtils } from '@0x/utils';
import { MethodAbi, SupportedProvider, TxData } from 'ethereum-types';
import { BigNumber, providerUtils } from '@0x/utils';
import { SupportedProvider, TxData } from 'ethereum-types';

import { constants } from './utils/constants';
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 @@ -272,7 +243,7 @@ export async function runMigrationsAsync(
txDefaults,
artifacts,
exchange.address,
encodeERC20AssetData(etherToken.address),
etherToken.address,
);

const contractAddresses = {
Expand Down
5 changes: 2 additions & 3 deletions packages/migrations/src/testnet_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export async function runMigrationsAsync(supportedProvider: SupportedProvider, t
]);
await submitAndExecuteTransactionAsync(governor, governor.address, batchTransactionData);

const devUtils = await DevUtilsContract.deployFrom0xArtifactAsync(
await DevUtilsContract.deployFrom0xArtifactAsync(
devUtilsArtifacts.DevUtils,
provider,
txDefaults,
Expand All @@ -238,14 +238,13 @@ export async function runMigrationsAsync(supportedProvider: SupportedProvider, t
chainId,
);

const wethAssetData = await devUtils.encodeERC20AssetData(deployedAddresses.etherToken).callAsync();
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
forwarderArtifacts.Forwarder,
provider,
txDefaults,
forwarderArtifacts,
exchange.address,
wethAssetData,
deployedAddresses.etherToken,
);
await forwarder.approveMakerAssetProxy(deployedAddresses.etherToken).awaitTransactionSuccessAsync();
}
Expand Down

0 comments on commit 84b660d

Please sign in to comment.