From 638c4ca36811a3b304c3f9cda98ca394c12a2937 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 18 Nov 2019 12:55:30 -0800 Subject: [PATCH] temp --- .../migrations/src/test_contract_configs.ts | 23 +- packages/migrations/src/testnet_migrations.ts | 228 +++--------------- 2 files changed, 46 insertions(+), 205 deletions(-) diff --git a/packages/migrations/src/test_contract_configs.ts b/packages/migrations/src/test_contract_configs.ts index b3f21d7d91..941ac42499 100644 --- a/packages/migrations/src/test_contract_configs.ts +++ b/packages/migrations/src/test_contract_configs.ts @@ -22,16 +22,19 @@ import { getTimelockRegistrationsAsync } from './utils/timelocks'; const INFURA_PROJECT_ID = ''; const networkIdToRpcUrl = { - 1: `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`, + 1: `http://localhost:8545`, 3: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`, 4: `https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}`, 42: `https://kovan.infura.io/v3/${INFURA_PROJECT_ID}`, }; // tslint:disable:custom-no-magic-numbers -async function testContractConfigsAsync(provider: SupportedProvider): Promise { +export async function testContractConfigsAsync(provider: SupportedProvider): Promise { const web3Wrapper = new Web3Wrapper(provider); - const chainId = await web3Wrapper.getChainIdAsync(); + let chainId = await web3Wrapper.getChainIdAsync(); + if (chainId === 1337) { + chainId = 1; + } const addresses = getContractAddressesForChainOrThrow(chainId); const configs = getConfigsByChainId(chainId); @@ -382,13 +385,13 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise { - for (const rpcUrl of Object.values(networkIdToRpcUrl)) { - const provider = new Web3ProviderEngine(); - provider.addProvider(new EmptyWalletSubprovider()); - provider.addProvider(new RPCSubprovider(rpcUrl)); - providerUtils.startProviderEngine(provider); - await testContractConfigsAsync(provider); - } + // for (const rpcUrl of Object.values(networkIdToRpcUrl)) { + // const provider = new Web3ProviderEngine(); + // provider.addProvider(new EmptyWalletSubprovider()); + // provider.addProvider(new RPCSubprovider(rpcUrl)); + // providerUtils.startProviderEngine(provider); + // await testContractConfigsAsync(provider); + // } })().catch(err => { logUtils.log(err); process.exit(1); diff --git a/packages/migrations/src/testnet_migrations.ts b/packages/migrations/src/testnet_migrations.ts index e99f898768..7a8e9034d8 100644 --- a/packages/migrations/src/testnet_migrations.ts +++ b/packages/migrations/src/testnet_migrations.ts @@ -21,9 +21,12 @@ import { ZrxVaultContract, } from '@0x/contracts-staking'; import { IAuthorizableContract, IOwnableContract } from '@0x/contracts-utils'; +import { EmptyWalletSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders'; import { AbiEncoder, BigNumber, logUtils, providerUtils } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; import { LogWithDecodedArgs, SupportedProvider, TxData } from 'ethereum-types'; +import { testContractConfigsAsync } from './test_contract_configs'; import { getConfigsByChainId } from './utils/configs_by_chain'; import { constants } from './utils/constants'; import { providerFactory } from './utils/provider_factory'; @@ -51,210 +54,45 @@ async function submitAndExecuteTransactionAsync( */ export async function runMigrationsAsync(supportedProvider: SupportedProvider, txDefaults: TxData): Promise { const provider = providerUtils.standardizeOrThrow(supportedProvider); - const chainId = new BigNumber(await providerUtils.getChainIdAsync(provider)); - const deployedAddresses = getContractAddressesForChainOrThrow(chainId.toNumber()); - const configs = getConfigsByChainId(chainId.toNumber()); + const web3Wrapper = new Web3Wrapper(provider); + let chainId = await web3Wrapper.getChainIdAsync(); + if (chainId === 1337) { + chainId = 1; + } - // NOTE: This must be deployed before running these migrations, since its address is hard coded in the - // staking logic contract. - const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults); - - const stakingLogic = await StakingContract.deployFrom0xArtifactAsync( - stakingArtifacts.Staking, - provider, - txDefaults, - stakingArtifacts, - ); - - const exchange = await ExchangeContract.deployFrom0xArtifactAsync( - exchangeArtifacts.Exchange, - provider, - txDefaults, - exchangeArtifacts, - chainId, - ); - - const stakingProxy = await StakingProxyContract.deployFrom0xArtifactAsync( - stakingArtifacts.StakingProxy, - provider, - txDefaults, - stakingArtifacts, - stakingLogic.address, - ); - - const erc20BridgeProxy = await ERC20BridgeProxyContract.deployFrom0xArtifactAsync( - assetProxyArtifacts.ERC20BridgeProxy, - provider, - txDefaults, - assetProxyArtifacts, - ); + const deployedAddresses = getContractAddressesForChainOrThrow(chainId); - await UniswapBridgeContract.deployFrom0xArtifactAsync( - assetProxyArtifacts.UniswapBridge, - provider, - txDefaults, - assetProxyArtifacts, - ); + await web3Wrapper.increaseTimeAsync(15 * 24 * 60 * 60); + await web3Wrapper.mineBlockAsync(); - await Eth2DaiBridgeContract.deployFrom0xArtifactAsync( - assetProxyArtifacts.Eth2DaiBridge, - provider, - txDefaults, - assetProxyArtifacts, - ); - - const authorizableInterface = new IAuthorizableContract(constants.NULL_ADDRESS, provider, txDefaults); - const ownableInterface = new IOwnableContract(constants.NULL_ADDRESS, provider, txDefaults); - - const customTimeLocks = await getTimelockRegistrationsAsync(provider); - - const governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync( - multisigArtifacts.ZeroExGovernor, - provider, - txDefaults, - multisigArtifacts, - customTimeLocks.map(timeLockInfo => timeLockInfo.functionSelector), - customTimeLocks.map(timeLockInfo => timeLockInfo.destination), - customTimeLocks.map(timeLockInfo => timeLockInfo.secondsTimeLocked), - configs.zeroExGovernor.owners, - configs.zeroExGovernor.required, - configs.zeroExGovernor.secondsTimeLocked, - ); - - logUtils.log('Configuring Exchange...'); - await exchange.setProtocolFeeCollectorAddress(stakingProxy.address).awaitTransactionSuccessAsync(); - await exchange.setProtocolFeeMultiplier(new BigNumber(150000)).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(deployedAddresses.erc20Proxy).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(deployedAddresses.erc721Proxy).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(deployedAddresses.erc1155Proxy).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(deployedAddresses.multiAssetProxy).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(deployedAddresses.staticCallProxy).awaitTransactionSuccessAsync(); - await exchange.registerAssetProxy(erc20BridgeProxy.address).awaitTransactionSuccessAsync(); + const apo = new ZeroExGovernorContract(deployedAddresses.assetProxyOwner, provider, txDefaults); + const governor = new ZeroExGovernorContract(deployedAddresses.zeroExGovernor, provider, txDefaults); + const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults); + const exchange = new ExchangeContract(deployedAddresses.exchange, provider, txDefaults); + const stakingProxy = new StakingProxyContract(deployedAddresses.stakingProxy, provider, txDefaults); + + await apo.executeTransaction(new BigNumber(6)).awaitTransactionSuccessAsync(); + await apo.executeTransaction(new BigNumber(7)).awaitTransactionSuccessAsync(); + await apo.executeTransaction(new BigNumber(8)).awaitTransactionSuccessAsync(); + await apo.executeTransaction(new BigNumber(9)).awaitTransactionSuccessAsync(); + await apo.executeTransaction(new BigNumber(10)).awaitTransactionSuccessAsync(); await exchange.transferOwnership(governor.address).awaitTransactionSuccessAsync(); - logUtils.log('Exchange configured!'); - - logUtils.log('Configuring ERC20BridgeProxy...'); - await erc20BridgeProxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync(); - await erc20BridgeProxy.addAuthorizedAddress(deployedAddresses.multiAssetProxy).awaitTransactionSuccessAsync(); - await erc20BridgeProxy.transferOwnership(governor.address).awaitTransactionSuccessAsync(); - logUtils.log('ERC20BridgeProxy configured!'); - - logUtils.log('Configuring ZrxVault...'); - await zrxVault.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(); - await zrxVault.setStakingProxy(stakingProxy.address).awaitTransactionSuccessAsync(); - await zrxVault.removeAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(); - await zrxVault.addAuthorizedAddress(governor.address).awaitTransactionSuccessAsync(); - await zrxVault.transferOwnership(governor.address).awaitTransactionSuccessAsync(); - logUtils.log('ZrxVault configured!'); - - logUtils.log('Configuring StakingProxy...'); - await stakingProxy.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(); - const staking = new StakingContract(stakingProxy.address, provider, txDefaults); - await staking.addExchangeAddress(exchange.address).awaitTransactionSuccessAsync(); - await stakingProxy.removeAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync(); - await stakingProxy.addAuthorizedAddress(governor.address).awaitTransactionSuccessAsync(); await stakingProxy.transferOwnership(governor.address).awaitTransactionSuccessAsync(); - logUtils.log('StakingProxy configured!'); - - logUtils.log('Transfering ownership of 2.0 contracts...'); - const oldAssetProxyOwner = new ZeroExGovernorContract(deployedAddresses.assetProxyOwner, provider, txDefaults); - await submitAndExecuteTransactionAsync( - oldAssetProxyOwner, - deployedAddresses.exchangeV2, // Exchange 2.1 address - ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(), - ); - await submitAndExecuteTransactionAsync( - oldAssetProxyOwner, - deployedAddresses.erc20Proxy, - ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(), - ); - await submitAndExecuteTransactionAsync( - oldAssetProxyOwner, - deployedAddresses.erc721Proxy, - ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(), - ); - await submitAndExecuteTransactionAsync( - oldAssetProxyOwner, - deployedAddresses.erc1155Proxy, - ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(), - ); - await submitAndExecuteTransactionAsync( - oldAssetProxyOwner, - deployedAddresses.multiAssetProxy, - ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(), - ); - logUtils.log('Ownership transferred!'); - - const functionCalls = [ - // AssetProxy configs - { - destination: deployedAddresses.erc20Proxy, - data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(), - }, - { - destination: deployedAddresses.erc20Proxy, - data: authorizableInterface.addAuthorizedAddress(zrxVault.address).getABIEncodedTransactionData(), - }, - { - destination: deployedAddresses.erc721Proxy, - data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(), - }, - { - destination: deployedAddresses.erc1155Proxy, - data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(), - }, - { - destination: deployedAddresses.multiAssetProxy, - data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(), - }, - { - destination: deployedAddresses.multiAssetProxy, - data: exchange.registerAssetProxy(erc20BridgeProxy.address).getABIEncodedTransactionData(), - }, - ]; - - const batchTransactionEncoder = AbiEncoder.create('(bytes[],address[],uint256[])'); - const batchTransactionData = batchTransactionEncoder.encode([ - functionCalls.map(item => item.data), - functionCalls.map(item => item.destination), - functionCalls.map(() => constants.ZERO_AMOUNT), - ]); - await submitAndExecuteTransactionAsync(governor, governor.address, batchTransactionData); - - const devUtils = await DevUtilsContract.deployFrom0xArtifactAsync( - devUtilsArtifacts.DevUtils, - provider, - txDefaults, - devUtilsArtifacts, - exchange.address, - ); - - await CoordinatorContract.deployFrom0xArtifactAsync( - coordinatorArtifacts.Coordinator, - provider, - txDefaults, - coordinatorArtifacts, - exchange.address, - chainId, - ); + await zrxVault.transferOwnership(governor.address).awaitTransactionSuccessAsync(); + await governor.executeTransaction(new BigNumber(3)).awaitTransactionSuccessAsync(); - const wethAssetData = await devUtils.encodeERC20AssetData(deployedAddresses.etherToken).callAsync(); - const forwarder = await ForwarderContract.deployFrom0xArtifactAsync( - forwarderArtifacts.Forwarder, - provider, - txDefaults, - forwarderArtifacts, - exchange.address, - wethAssetData, - ); - await forwarder.approveMakerAssetProxy(deployedAddresses.etherToken).awaitTransactionSuccessAsync(); + await testContractConfigsAsync(provider); } (async () => { - const networkId = 1; - const rpcUrl = 'https://mainnet.infura.io/v3/'; - const provider = await providerFactory.getLedgerProviderAsync(networkId, rpcUrl); - await runMigrationsAsync(provider, { from: '0x3b39078f2a3e1512eecc8d6792fdc7f33e1cd2cf', gasPrice: 10000000001 }); + const provider = new Web3ProviderEngine(); + provider.addProvider(new RPCSubprovider('http://127.0.0.1:8545', 600000)); + providerUtils.startProviderEngine(provider); + await runMigrationsAsync(provider, { + from: '0x3b39078f2a3e1512eecc8d6792fdc7f33e1cd2cf', + gasPrice: 20000000000, + gas: 2000000, + }); })().catch(err => { logUtils.log(err); process.exit(1);