From a5a68acfec73bfcf7a5883a28948e8c3698dc955 Mon Sep 17 00:00:00 2001 From: Lawrence Forman Date: Wed, 24 Jun 2020 23:52:01 -0400 Subject: [PATCH] Add Exchange Proxy to Ganache snapshot (#2612) * `@0x/contracts-zero-ex`: Expose migration tools. * `@0x/contract-addresses`: Update ganache snapshot Exchange Proxy addresses * `@0x/migrations`: Add Exchange Proxy migration --- contracts/zero-ex/CHANGELOG.json | 9 ++ contracts/zero-ex/package.json | 4 +- contracts/zero-ex/src/artifacts.ts | 8 + contracts/zero-ex/src/index.ts | 3 + contracts/zero-ex/src/migration.ts | 130 ++++++++++++++++ contracts/zero-ex/src/wrappers.ts | 4 + .../features/simple_function_registry_test.ts | 2 +- .../test/features/token_spender_test.ts | 8 +- .../test/features/transform_erc20_test.ts | 3 +- contracts/zero-ex/test/utils/migration.ts | 140 ++---------------- contracts/zero-ex/test/zero_ex_test.ts | 3 +- contracts/zero-ex/tsconfig.json | 4 + packages/contract-addresses/CHANGELOG.json | 9 ++ packages/contract-addresses/addresses.json | 14 +- packages/migrations/CHANGELOG.json | 9 ++ packages/migrations/package.json | 1 + packages/migrations/src/migration.ts | 50 ++++++- .../test/snapshot_addresses_test.ts | 2 +- 18 files changed, 247 insertions(+), 156 deletions(-) create mode 100644 contracts/zero-ex/src/migration.ts diff --git a/contracts/zero-ex/CHANGELOG.json b/contracts/zero-ex/CHANGELOG.json index f68e6ee58d..1d8f6d8248 100644 --- a/contracts/zero-ex/CHANGELOG.json +++ b/contracts/zero-ex/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "0.2.0", + "changes": [ + { + "note": "Export migration tools", + "pr": 2612 + } + ] + }, { "timestamp": 1592969527, "version": "0.1.1", diff --git a/contracts/zero-ex/package.json b/contracts/zero-ex/package.json index edce2bae41..a2a1f39c52 100644 --- a/contracts/zero-ex/package.json +++ b/contracts/zero-ex/package.json @@ -38,7 +38,7 @@ "docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES" }, "config": { - "publicInterfaceContracts": "ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer", + "publicInterfaceContracts": "ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer,Ownable,SimpleFunctionRegistry,TransformERC20,TokenSpender", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", "abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|AllowanceTarget|Bootstrap|FillQuoteTransformer|FixinCommon|FlashWallet|FullMigration|IAllowanceTarget|IBootstrap|IERC20Transformer|IExchange|IFeature|IFlashWallet|IOwnable|ISimpleFunctionRegistry|ITestSimpleFunctionRegistryFeature|ITokenSpender|ITransformERC20|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibMigrate|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibSpenderRichErrors|LibStorage|LibTokenSpenderStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|Ownable|PayTakerTransformer|SimpleFunctionRegistry|TestCallTarget|TestDelegateCaller|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFullMigration|TestInitialMigration|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestTokenSpender|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestWeth|TestWethTransformerHost|TestZeroExFeature|TokenSpender|TransformERC20|Transformer|TransformerDeployer|WethTransformer|ZeroEx).json" }, @@ -58,7 +58,6 @@ "@0x/dev-utils": "^3.2.2", "@0x/order-utils": "^10.3.0", "@0x/sol-compiler": "^4.1.0", - "@0x/subproviders": "^6.1.0", "@0x/ts-doc-gen": "^0.0.22", "@0x/tslint-config": "^4.0.0", "@types/lodash": "4.14.104", @@ -75,6 +74,7 @@ }, "dependencies": { "@0x/base-contract": "^6.2.2", + "@0x/subproviders": "^6.1.0", "@0x/types": "^3.1.3", "@0x/typescript-typings": "^5.1.0", "@0x/utils": "^5.5.0", diff --git a/contracts/zero-ex/src/artifacts.ts b/contracts/zero-ex/src/artifacts.ts index 525dcc5da6..08dc765042 100644 --- a/contracts/zero-ex/src/artifacts.ts +++ b/contracts/zero-ex/src/artifacts.ts @@ -15,7 +15,11 @@ import * as IOwnable from '../generated-artifacts/IOwnable.json'; import * as ISimpleFunctionRegistry from '../generated-artifacts/ISimpleFunctionRegistry.json'; import * as ITokenSpender from '../generated-artifacts/ITokenSpender.json'; import * as ITransformERC20 from '../generated-artifacts/ITransformERC20.json'; +import * as Ownable from '../generated-artifacts/Ownable.json'; import * as PayTakerTransformer from '../generated-artifacts/PayTakerTransformer.json'; +import * as SimpleFunctionRegistry from '../generated-artifacts/SimpleFunctionRegistry.json'; +import * as TokenSpender from '../generated-artifacts/TokenSpender.json'; +import * as TransformERC20 from '../generated-artifacts/TransformERC20.json'; import * as WethTransformer from '../generated-artifacts/WethTransformer.json'; import * as ZeroEx from '../generated-artifacts/ZeroEx.json'; export const artifacts = { @@ -32,4 +36,8 @@ export const artifacts = { FillQuoteTransformer: FillQuoteTransformer as ContractArtifact, PayTakerTransformer: PayTakerTransformer as ContractArtifact, WethTransformer: WethTransformer as ContractArtifact, + Ownable: Ownable as ContractArtifact, + SimpleFunctionRegistry: SimpleFunctionRegistry as ContractArtifact, + TransformERC20: TransformERC20 as ContractArtifact, + TokenSpender: TokenSpender as ContractArtifact, }; diff --git a/contracts/zero-ex/src/index.ts b/contracts/zero-ex/src/index.ts index 84c5247934..ccb90806f8 100644 --- a/contracts/zero-ex/src/index.ts +++ b/contracts/zero-ex/src/index.ts @@ -41,3 +41,6 @@ export { TupleDataItem, StateMutability, } from 'ethereum-types'; + +export * from './nonce_utils'; +export * from './migration'; diff --git a/contracts/zero-ex/src/migration.ts b/contracts/zero-ex/src/migration.ts new file mode 100644 index 0000000000..7b8f7b490d --- /dev/null +++ b/contracts/zero-ex/src/migration.ts @@ -0,0 +1,130 @@ +import { BaseContract } from '@0x/base-contract'; +import { SupportedProvider } from '@0x/subproviders'; +import { TxData } from 'ethereum-types'; +import * as _ from 'lodash'; + +import { artifacts } from './artifacts'; +import { + FullMigrationContract, + InitialMigrationContract, + OwnableContract, + SimpleFunctionRegistryContract, + TokenSpenderContract, + TransformERC20Contract, + ZeroExContract, +} from './wrappers'; + +// tslint:disable: completed-docs + +export interface BootstrapFeatures { + registry: SimpleFunctionRegistryContract; + ownable: OwnableContract; +} + +export async function deployBootstrapFeaturesAsync( + provider: SupportedProvider, + txDefaults: Partial, + features: Partial = {}, +): Promise { + return { + registry: + features.registry || + (await SimpleFunctionRegistryContract.deployFrom0xArtifactAsync( + artifacts.SimpleFunctionRegistry, + provider, + txDefaults, + artifacts, + )), + ownable: + features.ownable || + (await OwnableContract.deployFrom0xArtifactAsync(artifacts.Ownable, provider, txDefaults, artifacts)), + }; +} + +export async function initialMigrateAsync( + owner: string, + provider: SupportedProvider, + txDefaults: Partial, + features: Partial = {}, +): Promise { + const _features = await deployBootstrapFeaturesAsync(provider, txDefaults, features); + const migrator = await InitialMigrationContract.deployFrom0xArtifactAsync( + artifacts.InitialMigration, + provider, + txDefaults, + artifacts, + txDefaults.from as string, + ); + const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features)); + const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {}); + await deployCall.awaitTransactionSuccessAsync(); + return zeroEx; +} + +export interface FullFeatures extends BootstrapFeatures { + tokenSpender: TokenSpenderContract; + transformERC20: TransformERC20Contract; +} + +export interface FullMigrationOpts { + transformerDeployer: string; +} + +export async function deployFullFeaturesAsync( + provider: SupportedProvider, + txDefaults: Partial, + features: Partial = {}, +): Promise { + return { + ...(await deployBootstrapFeaturesAsync(provider, txDefaults)), + tokenSpender: + features.tokenSpender || + (await TokenSpenderContract.deployFrom0xArtifactAsync( + artifacts.TokenSpender, + provider, + txDefaults, + artifacts, + )), + transformERC20: + features.transformERC20 || + (await TransformERC20Contract.deployFrom0xArtifactAsync( + artifacts.TransformERC20, + provider, + txDefaults, + artifacts, + )), + }; +} + +export async function fullMigrateAsync( + owner: string, + provider: SupportedProvider, + txDefaults: Partial, + features: Partial = {}, + opts: Partial = {}, +): Promise { + const _features = await deployFullFeaturesAsync(provider, txDefaults, features); + const migrator = await FullMigrationContract.deployFrom0xArtifactAsync( + artifacts.FullMigration, + provider, + txDefaults, + artifacts, + txDefaults.from as string, + ); + const _opts = { + transformerDeployer: txDefaults.from as string, + ...opts, + }; + const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features), _opts); + const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {}); + await deployCall.awaitTransactionSuccessAsync(); + return zeroEx; +} + +// tslint:disable:space-before-function-parent one-line +export function toFeatureAdddresses( + features: T, +): { [name in keyof T]: string } { + // TS can't figure this out. + return _.mapValues(features, (c: BaseContract) => c.address) as any; +} diff --git a/contracts/zero-ex/src/wrappers.ts b/contracts/zero-ex/src/wrappers.ts index 1778a3cc18..2ced75edec 100644 --- a/contracts/zero-ex/src/wrappers.ts +++ b/contracts/zero-ex/src/wrappers.ts @@ -13,6 +13,10 @@ export * from '../generated-wrappers/i_simple_function_registry'; export * from '../generated-wrappers/i_token_spender'; export * from '../generated-wrappers/i_transform_erc20'; export * from '../generated-wrappers/initial_migration'; +export * from '../generated-wrappers/ownable'; export * from '../generated-wrappers/pay_taker_transformer'; +export * from '../generated-wrappers/simple_function_registry'; +export * from '../generated-wrappers/token_spender'; +export * from '../generated-wrappers/transform_erc20'; export * from '../generated-wrappers/weth_transformer'; export * from '../generated-wrappers/zero_ex'; diff --git a/contracts/zero-ex/test/features/simple_function_registry_test.ts b/contracts/zero-ex/test/features/simple_function_registry_test.ts index 60670b03b8..4f4f06fd5f 100644 --- a/contracts/zero-ex/test/features/simple_function_registry_test.ts +++ b/contracts/zero-ex/test/features/simple_function_registry_test.ts @@ -1,6 +1,7 @@ import { blockchainTests, constants, expect, randomAddress, verifyEventsFromLogs } from '@0x/contracts-test-utils'; import { BigNumber, hexUtils, OwnableRevertErrors, ZeroExRevertErrors } from '@0x/utils'; +import { ZeroExContract } from '../../src/wrappers'; import { artifacts } from '../artifacts'; import { initialMigrateAsync } from '../utils/migration'; import { @@ -9,7 +10,6 @@ import { ITestSimpleFunctionRegistryFeatureContract, TestSimpleFunctionRegistryFeatureImpl1Contract, TestSimpleFunctionRegistryFeatureImpl2Contract, - ZeroExContract, } from '../wrappers'; blockchainTests.resets('SimpleFunctionRegistry feature', env => { diff --git a/contracts/zero-ex/test/features/token_spender_test.ts b/contracts/zero-ex/test/features/token_spender_test.ts index 13470fd8e9..3d3b626aaf 100644 --- a/contracts/zero-ex/test/features/token_spender_test.ts +++ b/contracts/zero-ex/test/features/token_spender_test.ts @@ -7,15 +7,11 @@ import { } from '@0x/contracts-test-utils'; import { BigNumber, hexUtils, StringRevertError, ZeroExRevertErrors } from '@0x/utils'; +import { TokenSpenderContract, ZeroExContract } from '../../src/wrappers'; import { artifacts } from '../artifacts'; import { abis } from '../utils/abis'; import { fullMigrateAsync } from '../utils/migration'; -import { - TestTokenSpenderERC20TokenContract, - TestTokenSpenderERC20TokenEvents, - TokenSpenderContract, - ZeroExContract, -} from '../wrappers'; +import { TestTokenSpenderERC20TokenContract, TestTokenSpenderERC20TokenEvents } from '../wrappers'; blockchainTests.resets('TokenSpender feature', env => { let zeroEx: ZeroExContract; diff --git a/contracts/zero-ex/test/features/transform_erc20_test.ts b/contracts/zero-ex/test/features/transform_erc20_test.ts index 57f0364cc5..10732448a7 100644 --- a/contracts/zero-ex/test/features/transform_erc20_test.ts +++ b/contracts/zero-ex/test/features/transform_erc20_test.ts @@ -11,6 +11,7 @@ import { import { ETH_TOKEN_ADDRESS } from '@0x/order-utils'; import { AbiEncoder, hexUtils, OwnableRevertErrors, ZeroExRevertErrors } from '@0x/utils'; +import { TransformERC20Contract, ZeroExContract } from '../../src/wrappers'; import { artifacts } from '../artifacts'; import { abis } from '../utils/abis'; import { fullMigrateAsync } from '../utils/migration'; @@ -20,9 +21,7 @@ import { TestMintableERC20TokenContract, TestMintTokenERC20TransformerContract, TestMintTokenERC20TransformerEvents, - TransformERC20Contract, TransformERC20Events, - ZeroExContract, } from '../wrappers'; blockchainTests.resets('TransformERC20 feature', env => { diff --git a/contracts/zero-ex/test/utils/migration.ts b/contracts/zero-ex/test/utils/migration.ts index 1345b004e7..4b70ec0aa0 100644 --- a/contracts/zero-ex/test/utils/migration.ts +++ b/contracts/zero-ex/test/utils/migration.ts @@ -1,130 +1,10 @@ -import { BaseContract } from '@0x/base-contract'; -import { SupportedProvider } from '@0x/subproviders'; -import { TxData } from 'ethereum-types'; -import * as _ from 'lodash'; - -import { artifacts } from '../artifacts'; -import { - FullMigrationContract, - InitialMigrationContract, - OwnableContract, - SimpleFunctionRegistryContract, - TokenSpenderContract, - TransformERC20Contract, - ZeroExContract, -} from '../wrappers'; - -// tslint:disable: completed-docs - -export interface BootstrapFeatures { - registry: SimpleFunctionRegistryContract; - ownable: OwnableContract; -} - -export async function deployBootstrapFeaturesAsync( - provider: SupportedProvider, - txDefaults: Partial, - features: Partial = {}, -): Promise { - return { - registry: - features.registry || - (await SimpleFunctionRegistryContract.deployFrom0xArtifactAsync( - artifacts.SimpleFunctionRegistry, - provider, - txDefaults, - artifacts, - )), - ownable: - features.ownable || - (await OwnableContract.deployFrom0xArtifactAsync(artifacts.Ownable, provider, txDefaults, artifacts)), - }; -} - -export async function initialMigrateAsync( - owner: string, - provider: SupportedProvider, - txDefaults: Partial, - features: Partial = {}, -): Promise { - const _features = await deployBootstrapFeaturesAsync(provider, txDefaults, features); - const migrator = await InitialMigrationContract.deployFrom0xArtifactAsync( - artifacts.InitialMigration, - provider, - txDefaults, - artifacts, - txDefaults.from as string, - ); - const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features)); - const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {}); - await deployCall.awaitTransactionSuccessAsync(); - return zeroEx; -} - -export interface FullFeatures extends BootstrapFeatures { - tokenSpender: TokenSpenderContract; - transformERC20: TransformERC20Contract; -} - -export interface FullMigrationOpts { - transformerDeployer: string; -} - -export async function deployFullFeaturesAsync( - provider: SupportedProvider, - txDefaults: Partial, - features: Partial = {}, -): Promise { - return { - ...(await deployBootstrapFeaturesAsync(provider, txDefaults)), - tokenSpender: - features.tokenSpender || - (await TokenSpenderContract.deployFrom0xArtifactAsync( - artifacts.TokenSpender, - provider, - txDefaults, - artifacts, - )), - transformERC20: - features.transformERC20 || - (await TransformERC20Contract.deployFrom0xArtifactAsync( - artifacts.TransformERC20, - provider, - txDefaults, - artifacts, - )), - }; -} - -export async function fullMigrateAsync( - owner: string, - provider: SupportedProvider, - txDefaults: Partial, - features: Partial = {}, - opts: Partial = {}, -): Promise { - const _features = await deployFullFeaturesAsync(provider, txDefaults, features); - const migrator = await FullMigrationContract.deployFrom0xArtifactAsync( - artifacts.FullMigration, - provider, - txDefaults, - artifacts, - txDefaults.from as string, - ); - const _opts = { - transformerDeployer: txDefaults.from as string, - ...opts, - }; - const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features), _opts); - const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {}); - await deployCall.awaitTransactionSuccessAsync(); - return zeroEx; -} - -// tslint:disable:space-before-function-parent one-line -export function toFeatureAdddresses( - features: T, -): { [name in keyof T]: string } { - // TS can't figure this out. - return _.mapValues(features, (c: BaseContract) => c.address) as any; -} +export { + BootstrapFeatures, + deployBootstrapFeaturesAsync, + deployFullFeaturesAsync, + initialMigrateAsync, + fullMigrateAsync, + toFeatureAdddresses, + FullMigrationOpts, + FullFeatures, +} from '../../src/migration'; diff --git a/contracts/zero-ex/test/zero_ex_test.ts b/contracts/zero-ex/test/zero_ex_test.ts index cd9ed8460c..ade1ab2b94 100644 --- a/contracts/zero-ex/test/zero_ex_test.ts +++ b/contracts/zero-ex/test/zero_ex_test.ts @@ -1,6 +1,8 @@ import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils'; import { BigNumber, ZeroExRevertErrors } from '@0x/utils'; +import { ZeroExContract } from '../src/wrappers'; + import { artifacts } from './artifacts'; import { initialMigrateAsync } from './utils/migration'; import { @@ -9,7 +11,6 @@ import { ISimpleFunctionRegistryContract, TestZeroExFeatureContract, TestZeroExFeatureEvents, - ZeroExContract, } from './wrappers'; blockchainTests.resets('ZeroEx contract', env => { diff --git a/contracts/zero-ex/tsconfig.json b/contracts/zero-ex/tsconfig.json index 9c690c0edb..069b291215 100644 --- a/contracts/zero-ex/tsconfig.json +++ b/contracts/zero-ex/tsconfig.json @@ -13,7 +13,11 @@ "generated-artifacts/ITokenSpender.json", "generated-artifacts/ITransformERC20.json", "generated-artifacts/InitialMigration.json", + "generated-artifacts/Ownable.json", "generated-artifacts/PayTakerTransformer.json", + "generated-artifacts/SimpleFunctionRegistry.json", + "generated-artifacts/TokenSpender.json", + "generated-artifacts/TransformERC20.json", "generated-artifacts/WethTransformer.json", "generated-artifacts/ZeroEx.json", "test/generated-artifacts/AffiliateFeeTransformer.json", diff --git a/packages/contract-addresses/CHANGELOG.json b/packages/contract-addresses/CHANGELOG.json index 4a0bc39ac3..e3b4c661da 100644 --- a/packages/contract-addresses/CHANGELOG.json +++ b/packages/contract-addresses/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "4.11.0", + "changes": [ + { + "note": "Update ganache snapshot Exchange Proxy addresses", + "pr": 2612 + } + ] + }, { "version": "4.10.0", "changes": [ diff --git a/packages/contract-addresses/addresses.json b/packages/contract-addresses/addresses.json index 027fdaed17..373ab42e37 100644 --- a/packages/contract-addresses/addresses.json +++ b/packages/contract-addresses/addresses.json @@ -209,14 +209,14 @@ "maximumGasPrice": "0x0000000000000000000000000000000000000000", "dexForwarderBridge": "0x0000000000000000000000000000000000000000", "multiBridge": "0x0000000000000000000000000000000000000000", - "exchangeProxyGovernor": "0x618f9c67ce7bf1a50afa1e7e0238422601b0ff6e", - "exchangeProxy": "0xdef1c0ded9bec7f1a1670819833240f027b25eff", - "exchangeProxyAllowanceTarget": "0xf740b67da229f2f10bcbd38a7979992fcc71b8eb", - "exchangeProxyTransformerDeployer": "0x80a36559ab9a497fb658325ed771a584eb0f13da", + "exchangeProxyGovernor": "0x0000000000000000000000000000000000000000", + "exchangeProxy": "0x4b8ce0fa221284de4aaa09be3e7bf6193444b786", + "exchangeProxyAllowanceTarget": "0xd6724bf180441a89d08ea3aeded2c995180b9a04", + "exchangeProxyTransformerDeployer": "0x5409ed021d9299bf6814279a6a1411a7e866a631", "transformers": { - "wethTransformer": "0x7bab5f7299e1ca123bb44eb71e6c89be7e558cc8", - "payTakerTransformer": "0xe8c07a119452b55eee2f999478aab97f3656d841", - "fillQuoteTransformer": "0x9b81a08ef144e7aa4925f7fd77da1e1b3990e59a" + "wethTransformer": "0xb125995f5a4766c451cd8c34c4f5cac89b724571", + "payTakerTransformer": "0x10a736a7b223f1fe1050264249d1abb975741e75", + "fillQuoteTransformer": "0x33def1aa867be09809f3a01ce41d5ec1888846c9" } } } diff --git a/packages/migrations/CHANGELOG.json b/packages/migrations/CHANGELOG.json index d7d96125b2..09022f57c1 100644 --- a/packages/migrations/CHANGELOG.json +++ b/packages/migrations/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "6.4.0", + "changes": [ + { + "note": "Add Exchange Proxy migration.", + "pr": 2612 + } + ] + }, { "version": "6.3.0", "changes": [ diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 6d559fa35e..ec9b96bb87 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -83,6 +83,7 @@ "@0x/contracts-multisig": "^4.1.6", "@0x/contracts-staking": "^2.0.13", "@0x/contracts-utils": "^4.5.0", + "@0x/contracts-zero-ex": "^0.1.1", "@0x/sol-compiler": "^4.1.0", "@0x/subproviders": "^6.1.0", "@0x/typescript-typings": "^5.1.0", diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index ebd106fcee..a7c44badc6 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -29,6 +29,14 @@ import { TestStakingContract, ZrxVaultContract, } from '@0x/contracts-staking'; +import { + artifacts as exchangeProxyArtifacts, + FillQuoteTransformerContract, + fullMigrateAsync as fullMigrateExchangeProxyAsync, + ITokenSpenderContract, + PayTakerTransformerContract, + WethTransformerContract, +} from '@0x/contracts-zero-ex'; import { Web3ProviderEngine } from '@0x/subproviders'; import { BigNumber, providerUtils } from '@0x/utils'; import { SupportedProvider, TxData } from 'ethereum-types'; @@ -47,6 +55,7 @@ const allArtifacts = { ...forwarderArtifacts, ...stakingArtifacts, ...erc20BridgeSamplerArtifacts, + ...exchangeProxyArtifacts, }; const { NULL_ADDRESS } = constants; @@ -292,6 +301,35 @@ export async function runMigrationsAsync( devUtils.address, ); + // Exchange Proxy ////////////////////////////////////////////////////////// + + const exchangeProxy = await fullMigrateExchangeProxyAsync(txDefaults.from, provider, txDefaults); + const allowanceTargetAddress = await new ITokenSpenderContract(exchangeProxy.address, provider, txDefaults) + .getAllowanceTarget() + .callAsync(); + + // Deploy transformers. + const fillQuoteTransformer = await FillQuoteTransformerContract.deployFrom0xArtifactAsync( + exchangeProxyArtifacts.FillQuoteTransformer, + provider, + txDefaults, + allArtifacts, + exchange.address, + ); + const payTakerTransformer = await PayTakerTransformerContract.deployFrom0xArtifactAsync( + exchangeProxyArtifacts.PayTakerTransformer, + provider, + txDefaults, + allArtifacts, + ); + const wethTransformer = await WethTransformerContract.deployFrom0xArtifactAsync( + exchangeProxyArtifacts.WethTransformer, + provider, + txDefaults, + allArtifacts, + etherToken.address, + ); + const contractAddresses = { erc20Proxy: erc20Proxy.address, erc721Proxy: erc721Proxy.address, @@ -327,13 +365,13 @@ export async function runMigrationsAsync( dexForwarderBridge: NULL_ADDRESS, multiBridge: NULL_ADDRESS, exchangeProxyGovernor: NULL_ADDRESS, - exchangeProxy: NULL_ADDRESS, - exchangeProxyAllowanceTarget: NULL_ADDRESS, - exchangeProxyTransformerDeployer: NULL_ADDRESS, + exchangeProxy: exchangeProxy.address, + exchangeProxyAllowanceTarget: allowanceTargetAddress, + exchangeProxyTransformerDeployer: txDefaults.from, transformers: { - wethTransformer: NULL_ADDRESS, - payTakerTransformer: NULL_ADDRESS, - fillQuoteTransformer: NULL_ADDRESS, + wethTransformer: wethTransformer.address, + payTakerTransformer: payTakerTransformer.address, + fillQuoteTransformer: fillQuoteTransformer.address, }, }; return contractAddresses; diff --git a/packages/migrations/test/snapshot_addresses_test.ts b/packages/migrations/test/snapshot_addresses_test.ts index 9d7a4e330e..d86c689328 100644 --- a/packages/migrations/test/snapshot_addresses_test.ts +++ b/packages/migrations/test/snapshot_addresses_test.ts @@ -19,6 +19,6 @@ describe('addresses', () => { }; const migrationAddresses = await runMigrationsAsync(provider, txDefaults); const expectedAddresses = getContractAddressesForChainOrThrow(ChainId.Ganache); - expect(migrationAddresses).to.include(expectedAddresses); + expect(migrationAddresses).to.deep.eq(expectedAddresses); }); });