From 5f0a2953c63c31daa975b587f5c5072b6f7e418c Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Sun, 24 Jun 2018 17:36:24 -0700 Subject: Add Kovan migrations --- packages/migrations/src/1.0.0/artifacts.ts | 21 +++ packages/migrations/src/1.0.0/migration.ts | 142 +++++++++++++++++++++ .../migrations/src/2.0.0-beta-kovan/artifacts.ts | 13 ++ .../migrations/src/2.0.0-beta-kovan/constants.ts | 14 ++ .../migrations/src/2.0.0-beta-kovan/migration.ts | 91 +++++++++++++ packages/migrations/src/2.0.0/artifacts.ts | 21 +++ packages/migrations/src/2.0.0/migration.ts | 135 ++++++++++++++++++++ packages/migrations/src/index.ts | 5 +- packages/migrations/src/migrate.ts | 20 ++- packages/migrations/src/v1/artifacts.ts | 21 --- packages/migrations/src/v1/migration.ts | 142 --------------------- packages/migrations/src/v2/artifacts.ts | 21 --- packages/migrations/src/v2/migration.ts | 135 -------------------- 13 files changed, 455 insertions(+), 326 deletions(-) create mode 100644 packages/migrations/src/1.0.0/artifacts.ts create mode 100644 packages/migrations/src/1.0.0/migration.ts create mode 100644 packages/migrations/src/2.0.0-beta-kovan/artifacts.ts create mode 100644 packages/migrations/src/2.0.0-beta-kovan/constants.ts create mode 100644 packages/migrations/src/2.0.0-beta-kovan/migration.ts create mode 100644 packages/migrations/src/2.0.0/artifacts.ts create mode 100644 packages/migrations/src/2.0.0/migration.ts delete mode 100644 packages/migrations/src/v1/artifacts.ts delete mode 100644 packages/migrations/src/v1/migration.ts delete mode 100644 packages/migrations/src/v2/artifacts.ts delete mode 100644 packages/migrations/src/v2/migration.ts (limited to 'packages/migrations/src') diff --git a/packages/migrations/src/1.0.0/artifacts.ts b/packages/migrations/src/1.0.0/artifacts.ts new file mode 100644 index 000000000..d0a9f735a --- /dev/null +++ b/packages/migrations/src/1.0.0/artifacts.ts @@ -0,0 +1,21 @@ +import { ContractArtifact } from '@0xproject/sol-compiler'; + +import * as DummyERC20Token from '../../artifacts/1.0.0/DummyERC20Token.json'; +import * as Exchange from '../../artifacts/1.0.0/Exchange_v1.json'; +import * as MultiSigWalletWithTimeLock from '../../artifacts/1.0.0/MultiSigWalletWithTimeLock.json'; +import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../../artifacts/1.0.0/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; +import * as TokenRegistry from '../../artifacts/1.0.0/TokenRegistry.json'; +import * as TokenTransferProxy from '../../artifacts/1.0.0/TokenTransferProxy_v1.json'; +import * as EtherToken from '../../artifacts/1.0.0/WETH9.json'; +import * as ZRX from '../../artifacts/1.0.0/ZRXToken.json'; + +export const artifacts = { + ZRX: (ZRX as any) as ContractArtifact, + DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, + Exchange: (Exchange as any) as ContractArtifact, + EtherToken: (EtherToken as any) as ContractArtifact, + TokenRegistry: (TokenRegistry as any) as ContractArtifact, + TokenTransferProxy: (TokenTransferProxy as any) as ContractArtifact, + MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, + MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, +}; diff --git a/packages/migrations/src/1.0.0/migration.ts b/packages/migrations/src/1.0.0/migration.ts new file mode 100644 index 000000000..3398537e5 --- /dev/null +++ b/packages/migrations/src/1.0.0/migration.ts @@ -0,0 +1,142 @@ +import { BigNumber, NULL_BYTES } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; + +import { ArtifactWriter } from '../artifact_writer'; +import { erc20TokenInfo } from '../utils/token_info'; + +import { artifacts } from './artifacts'; +import { DummyERC20TokenContract } from './contract_wrappers/dummy_e_r_c20_token'; +import { Exchange_v1Contract } from './contract_wrappers/exchange_v1'; +import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; +import { TokenRegistryContract } from './contract_wrappers/token_registry'; +import { TokenTransferProxy_v1Contract } from './contract_wrappers/tokentransferproxy_v1'; +import { WETH9Contract } from './contract_wrappers/weth9'; +import { ZRXTokenContract } from './contract_wrappers/zrx_token'; + +/** + * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v1' command. + * Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, + * the migration should be written to run synchronously. + * @param provider Web3 provider instance. + * @param artifactsDir The directory with compiler artifact files. + * @param txDefaults Default transaction values to use when deploying contracts. + */ +export const runV1MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial) => { + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); + const tokenTransferProxy = await TokenTransferProxy_v1Contract.deployFrom0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + txDefaults, + ); + artifactsWriter.saveArtifact(tokenTransferProxy); + const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); + artifactsWriter.saveArtifact(zrxToken); + + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); + artifactsWriter.saveArtifact(etherToken); + const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync( + artifacts.TokenRegistry, + provider, + txDefaults, + ); + artifactsWriter.saveArtifact(tokenReg); + + const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); + const owners = [accounts[0], accounts[1]]; + const confirmationsRequired = new BigNumber(2); + const secondsRequired = new BigNumber(0); + const exchange = await Exchange_v1Contract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, + zrxToken.address, + tokenTransferProxy.address, + ); + artifactsWriter.saveArtifact(exchange); + const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, + provider, + txDefaults, + owners, + confirmationsRequired, + secondsRequired, + tokenTransferProxy.address, + ); + artifactsWriter.saveArtifact(multiSig); + + const owner = accounts[0]; + + await web3Wrapper.awaitTransactionSuccessAsync( + await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: owner }), + ); + const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync( + zrxToken.address, + erc20TokenInfo[0].name, + erc20TokenInfo[0].symbol, + erc20TokenInfo[0].decimals, + erc20TokenInfo[0].ipfsHash, + erc20TokenInfo[0].swarmHash, + { from: owner }, + ); + const decimals = 18; + await web3Wrapper.awaitTransactionSuccessAsync( + await tokenReg.addToken.sendTransactionAsync( + zrxToken.address, + '0x Protocol Token', + 'ZRX', + decimals, + NULL_BYTES, + NULL_BYTES, + { + from: owner, + gas: addTokenGasEstimate, + }, + ), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await tokenReg.addToken.sendTransactionAsync( + etherToken.address, + 'Ether Token', + 'WETH', + decimals, + NULL_BYTES, + NULL_BYTES, + { + from: owner, + gas: addTokenGasEstimate, + }, + ), + ); + for (const token of erc20TokenInfo) { + const totalSupply = new BigNumber(100000000000000000000); + const dummyToken = await DummyERC20TokenContract.deployFrom0xArtifactAsync( + artifacts.DummyERC20Token, + provider, + txDefaults, + token.name, + token.symbol, + token.decimals, + totalSupply, + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await tokenReg.addToken.sendTransactionAsync( + dummyToken.address, + token.name, + token.symbol, + token.decimals, + token.ipfsHash, + token.swarmHash, + { + from: owner, + gas: addTokenGasEstimate, + }, + ), + ); + } +}; diff --git a/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts b/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts new file mode 100644 index 000000000..5e7bb2de7 --- /dev/null +++ b/packages/migrations/src/2.0.0-beta-kovan/artifacts.ts @@ -0,0 +1,13 @@ +import { ContractArtifact } from '@0xproject/sol-compiler'; + +import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-kovan/AssetProxyOwner.json'; +import * as ERC20Proxy from '../../artifacts/2.0.0-beta-kovan/ERC20Proxy.json'; +import * as ERC721Proxy from '../../artifacts/2.0.0-beta-kovan/ERC721Proxy.json'; +import * as Exchange from '../../artifacts/2.0.0-beta-kovan/Exchange.json'; + +export const artifacts = { + AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact, + Exchange: (Exchange as any) as ContractArtifact, + ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, + ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, +}; diff --git a/packages/migrations/src/2.0.0-beta-kovan/constants.ts b/packages/migrations/src/2.0.0-beta-kovan/constants.ts new file mode 100644 index 000000000..e4fc8339d --- /dev/null +++ b/packages/migrations/src/2.0.0-beta-kovan/constants.ts @@ -0,0 +1,14 @@ +import { BigNumber } from '@0xproject/utils'; + +export const constants = { + ASSET_PROXY_OWNER_OWNERS: [ + '0x9df8137872ac09a8fee71d0da5c7539923fb9bf0', + '0xcf34d44db312d188789f43a63d11cf2bebb4da15', + '0x73fd50f2a6beac9cdac9fe87ef68a18edc415831', + ], + ASSET_PROXY_OWNER_TIMELOCK: new BigNumber(0), + ASSET_PROXY_OWNER_CONFIRMATIONS: new BigNumber(1), + ERC20_PROXY_ID: new BigNumber(0), + ERC721_PROXY_ID: new BigNumber(1), + NULL_ADDRESS: '0x0000000000000000000000000000000000000000', +}; diff --git a/packages/migrations/src/2.0.0-beta-kovan/migration.ts b/packages/migrations/src/2.0.0-beta-kovan/migration.ts new file mode 100644 index 000000000..bc0cbe090 --- /dev/null +++ b/packages/migrations/src/2.0.0-beta-kovan/migration.ts @@ -0,0 +1,91 @@ +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; + +import { ArtifactWriter } from '../artifact_writer'; + +import { artifacts } from './artifacts'; +import { constants } from './constants'; +import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner'; +import { ERC20ProxyContract } from './contract_wrappers/e_r_c20_proxy'; +import { ERC721ProxyContract } from './contract_wrappers/e_r_c721_proxy'; +import { ExchangeContract } from './contract_wrappers/exchange'; + +/** + * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2' command. + * Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, + * the migration should be written to run synchronously. + * @param provider Web3 provider instance. + * @param artifactsDir The directory with compiler artifact files. + * @param txDefaults Default transaction values to use when deploying contracts. + */ +export const runV2BetaKovanMigrationsAsync = async ( + provider: Provider, + artifactsDir: string, + txDefaults: Partial, +) => { + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); + + // Deploy AssetProxies + const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults); + artifactsWriter.saveArtifact(erc20proxy); + const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync( + artifacts.ERC721Proxy, + provider, + txDefaults, + ); + artifactsWriter.saveArtifact(erc721proxy); + + // Deploy Exchange + const exchange = await ExchangeContract.deployFrom0xArtifactAsync(artifacts.Exchange, provider, txDefaults); + artifactsWriter.saveArtifact(exchange); + + // Register AssetProxies in Exchange + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.registerAssetProxy.sendTransactionAsync( + constants.ERC20_PROXY_ID, + erc20proxy.address, + constants.NULL_ADDRESS, + ), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.registerAssetProxy.sendTransactionAsync( + constants.ERC721_PROXY_ID, + erc721proxy.address, + constants.NULL_ADDRESS, + ), + ); + + // Deploy AssetProxyOwner + const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( + artifacts.AssetProxyOwner, + provider, + txDefaults, + constants.ASSET_PROXY_OWNER_OWNERS, + [erc20proxy.address, erc721proxy.address], + constants.ASSET_PROXY_OWNER_CONFIRMATIONS, + constants.ASSET_PROXY_OWNER_TIMELOCK, + ); + artifactsWriter.saveArtifact(assetProxyOwner); + + // Authorize Exchange contracts to call AssetProxies + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address), + ); + + // Transfer ownership of AssetProxies and Exchange to AssetProxyOwner + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc721proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.transferOwnership.sendTransactionAsync(assetProxyOwner.address), + ); +}; diff --git a/packages/migrations/src/2.0.0/artifacts.ts b/packages/migrations/src/2.0.0/artifacts.ts new file mode 100644 index 000000000..31dfc5abb --- /dev/null +++ b/packages/migrations/src/2.0.0/artifacts.ts @@ -0,0 +1,21 @@ +import { ContractArtifact } from '@0xproject/sol-compiler'; + +import * as AssetProxyOwner from '../../artifacts/2.0.0/AssetProxyOwner.json'; +import * as DummyERC20Token from '../../artifacts/2.0.0/DummyERC20Token.json'; +import * as DummyERC721Token from '../../artifacts/2.0.0/DummyERC721Token.json'; +import * as ERC20Proxy from '../../artifacts/2.0.0/ERC20Proxy.json'; +import * as ERC721Proxy from '../../artifacts/2.0.0/ERC721Proxy.json'; +import * as Exchange from '../../artifacts/2.0.0/Exchange.json'; +import * as WETH9 from '../../artifacts/2.0.0/WETH9.json'; +import * as ZRX from '../../artifacts/2.0.0/ZRXToken.json'; + +export const artifacts = { + ZRX: (ZRX as any) as ContractArtifact, + DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, + DummyERC721Token: (DummyERC721Token as any) as ContractArtifact, + AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact, + Exchange: (Exchange as any) as ContractArtifact, + WETH9: (WETH9 as any) as ContractArtifact, + ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, + ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, +}; diff --git a/packages/migrations/src/2.0.0/migration.ts b/packages/migrations/src/2.0.0/migration.ts new file mode 100644 index 000000000..76a31e2a0 --- /dev/null +++ b/packages/migrations/src/2.0.0/migration.ts @@ -0,0 +1,135 @@ +import { assetProxyUtils, constants } from '@0xproject/order-utils'; +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; + +import { ArtifactWriter } from '../artifact_writer'; +import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info'; + +import { artifacts } from './artifacts'; +import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner'; +import { DummyERC20TokenContract } from './contract_wrappers/dummy_e_r_c20_token'; +import { DummyERC721TokenContract } from './contract_wrappers/dummy_e_r_c721_token'; +import { ERC20ProxyContract } from './contract_wrappers/e_r_c20_proxy'; +import { ERC721ProxyContract } from './contract_wrappers/e_r_c721_proxy'; +import { ExchangeContract } from './contract_wrappers/exchange'; +import { WETH9Contract } from './contract_wrappers/weth9'; +import { ZRXTokenContract } from './contract_wrappers/zrx_token'; + +/** + * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2' command. + * Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, + * the migration should be written to run synchronously. + * @param provider Web3 provider instance. + * @param artifactsDir The directory with compiler artifact files. + * @param txDefaults Default transaction values to use when deploying contracts. + */ +export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial) => { + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); + + // Proxies + const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults); + artifactsWriter.saveArtifact(erc20proxy); + const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync( + artifacts.ERC721Proxy, + provider, + txDefaults, + ); + artifactsWriter.saveArtifact(erc721proxy); + + // ZRX + const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); + artifactsWriter.saveArtifact(zrxToken); + + // Ether token + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults); + artifactsWriter.saveArtifact(etherToken); + + // Exchange + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, + assetProxyUtils.encodeERC20AssetData(zrxToken.address), + ); + artifactsWriter.saveArtifact(exchange); + + // Multisigs + const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); + const owners = [accounts[0], accounts[1]]; + const confirmationsRequired = new BigNumber(2); + const secondsRequired = new BigNumber(0); + const owner = accounts[0]; + + // AssetProxyOwner + const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( + artifacts.AssetProxyOwner, + provider, + txDefaults, + owners, + [erc20proxy.address, erc721proxy.address], + confirmationsRequired, + secondsRequired, + ); + artifactsWriter.saveArtifact(assetProxyOwner); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { + from: owner, + }), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await erc721proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { + from: owner, + }), + ); + + // Register the Asset Proxies to the Exchange + // HACK: These are exposed in the types package but migrations currently uses an older version + // but we can pull the asset data id from the proxies + const erc20ProxyId = await erc20proxy.getProxyId.callAsync(); + const erc721ProxyId = await erc721proxy.getProxyId.callAsync(); + const oldAddress = constants.NULL_ADDRESS; + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.registerAssetProxy.sendTransactionAsync(erc20ProxyId, erc20proxy.address, oldAddress), + ); + await web3Wrapper.awaitTransactionSuccessAsync( + await exchange.registerAssetProxy.sendTransactionAsync(erc721ProxyId, erc721proxy.address, oldAddress), + ); + + // Dummy ERC20 tokens + for (const token of erc20TokenInfo) { + const totalSupply = new BigNumber(100000000000000000000); + // tslint:disable-next-line:no-unused-variable + const dummyErc20Token = await DummyERC20TokenContract.deployFrom0xArtifactAsync( + artifacts.DummyERC20Token, + provider, + txDefaults, + token.name, + token.symbol, + token.decimals, + totalSupply, + ); + } + + // ERC721 + // tslint:disable-next-line:no-unused-variable + const cryptoKittieToken = await DummyERC721TokenContract.deployFrom0xArtifactAsync( + artifacts.DummyERC721Token, + provider, + txDefaults, + erc721TokenInfo[0].name, + erc721TokenInfo[0].symbol, + ); +}; diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts index 5bf2f847d..bb4b1f1e2 100644 --- a/packages/migrations/src/index.ts +++ b/packages/migrations/src/index.ts @@ -1,2 +1,3 @@ -export { runV1MigrationsAsync } from './v1/migration'; -export { runV2MigrationsAsync } from './v2/migration'; +export { runV1MigrationsAsync } from './1.0.0/migration'; +export { runV2MigrationsAsync } from './2.0.0/migration'; +export { runV2BetaKovanMigrationsAsync } from './2.0.0-beta-kovan/migration'; diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 5f320ec78..35e086382 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -1,30 +1,40 @@ #!/usr/bin/env node import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { logUtils } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider } from 'ethereum-types'; import * as yargs from 'yargs'; -import { runV1MigrationsAsync } from './v1/migration'; -import { runV2MigrationsAsync } from './v2/migration'; +import { runV1MigrationsAsync } from './1.0.0/migration'; +import { runV2BetaKovanMigrationsAsync } from './2.0.0-beta-kovan/migration'; +import { runV2MigrationsAsync } from './2.0.0/migration'; enum ContractVersions { V1 = '1.0.0', V2 = '2.0.0', + V2BetaKovan = '2.0.0-beta-kovan', } const args = yargs.argv; (async () => { + const providerConfigs = { shouldUseInProcessGanache: false }; + const provider: Provider = web3Factory.getRpcProvider(providerConfigs); const txDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const providerConfigs = { shouldUseInProcessGanache: false }; - const provider: Provider = web3Factory.getRpcProvider(providerConfigs); const contractsVersion = args.contractsVersion; const artifactsDir = `artifacts/${contractsVersion}`; if (contractsVersion === ContractVersions.V1) { await runV1MigrationsAsync(provider, artifactsDir, txDefaults); - } else { + } else if (contractsVersion === ContractVersions.V2) { await runV2MigrationsAsync(provider, artifactsDir, txDefaults); + } else { + const web3Wrapper = new Web3Wrapper(provider); + const accounts = await web3Wrapper.getAvailableAddressesAsync(); + const kovanTxDefaults = { + from: accounts[0], + }; + await runV2BetaKovanMigrationsAsync(provider, artifactsDir, kovanTxDefaults); } process.exit(0); })().catch(err => { diff --git a/packages/migrations/src/v1/artifacts.ts b/packages/migrations/src/v1/artifacts.ts deleted file mode 100644 index d0a9f735a..000000000 --- a/packages/migrations/src/v1/artifacts.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ContractArtifact } from '@0xproject/sol-compiler'; - -import * as DummyERC20Token from '../../artifacts/1.0.0/DummyERC20Token.json'; -import * as Exchange from '../../artifacts/1.0.0/Exchange_v1.json'; -import * as MultiSigWalletWithTimeLock from '../../artifacts/1.0.0/MultiSigWalletWithTimeLock.json'; -import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../../artifacts/1.0.0/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; -import * as TokenRegistry from '../../artifacts/1.0.0/TokenRegistry.json'; -import * as TokenTransferProxy from '../../artifacts/1.0.0/TokenTransferProxy_v1.json'; -import * as EtherToken from '../../artifacts/1.0.0/WETH9.json'; -import * as ZRX from '../../artifacts/1.0.0/ZRXToken.json'; - -export const artifacts = { - ZRX: (ZRX as any) as ContractArtifact, - DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - EtherToken: (EtherToken as any) as ContractArtifact, - TokenRegistry: (TokenRegistry as any) as ContractArtifact, - TokenTransferProxy: (TokenTransferProxy as any) as ContractArtifact, - MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, - MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, -}; diff --git a/packages/migrations/src/v1/migration.ts b/packages/migrations/src/v1/migration.ts deleted file mode 100644 index 3398537e5..000000000 --- a/packages/migrations/src/v1/migration.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { BigNumber, NULL_BYTES } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Provider, TxData } from 'ethereum-types'; - -import { ArtifactWriter } from '../artifact_writer'; -import { erc20TokenInfo } from '../utils/token_info'; - -import { artifacts } from './artifacts'; -import { DummyERC20TokenContract } from './contract_wrappers/dummy_e_r_c20_token'; -import { Exchange_v1Contract } from './contract_wrappers/exchange_v1'; -import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; -import { TokenRegistryContract } from './contract_wrappers/token_registry'; -import { TokenTransferProxy_v1Contract } from './contract_wrappers/tokentransferproxy_v1'; -import { WETH9Contract } from './contract_wrappers/weth9'; -import { ZRXTokenContract } from './contract_wrappers/zrx_token'; - -/** - * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v1' command. - * Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, - * the migration should be written to run synchronously. - * @param provider Web3 provider instance. - * @param artifactsDir The directory with compiler artifact files. - * @param txDefaults Default transaction values to use when deploying contracts. - */ -export const runV1MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial) => { - const web3Wrapper = new Web3Wrapper(provider); - const networkId = await web3Wrapper.getNetworkIdAsync(); - const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); - const tokenTransferProxy = await TokenTransferProxy_v1Contract.deployFrom0xArtifactAsync( - artifacts.TokenTransferProxy, - provider, - txDefaults, - ); - artifactsWriter.saveArtifact(tokenTransferProxy); - const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); - artifactsWriter.saveArtifact(zrxToken); - - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); - artifactsWriter.saveArtifact(etherToken); - const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync( - artifacts.TokenRegistry, - provider, - txDefaults, - ); - artifactsWriter.saveArtifact(tokenReg); - - const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); - const owners = [accounts[0], accounts[1]]; - const confirmationsRequired = new BigNumber(2); - const secondsRequired = new BigNumber(0); - const exchange = await Exchange_v1Contract.deployFrom0xArtifactAsync( - artifacts.Exchange, - provider, - txDefaults, - zrxToken.address, - tokenTransferProxy.address, - ); - artifactsWriter.saveArtifact(exchange); - const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( - artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, - provider, - txDefaults, - owners, - confirmationsRequired, - secondsRequired, - tokenTransferProxy.address, - ); - artifactsWriter.saveArtifact(multiSig); - - const owner = accounts[0]; - - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: owner }), - ); - const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync( - zrxToken.address, - erc20TokenInfo[0].name, - erc20TokenInfo[0].symbol, - erc20TokenInfo[0].decimals, - erc20TokenInfo[0].ipfsHash, - erc20TokenInfo[0].swarmHash, - { from: owner }, - ); - const decimals = 18; - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - zrxToken.address, - '0x Protocol Token', - 'ZRX', - decimals, - NULL_BYTES, - NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - etherToken.address, - 'Ether Token', - 'WETH', - decimals, - NULL_BYTES, - NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - for (const token of erc20TokenInfo) { - const totalSupply = new BigNumber(100000000000000000000); - const dummyToken = await DummyERC20TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC20Token, - provider, - txDefaults, - token.name, - token.symbol, - token.decimals, - totalSupply, - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - dummyToken.address, - token.name, - token.symbol, - token.decimals, - token.ipfsHash, - token.swarmHash, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - } -}; diff --git a/packages/migrations/src/v2/artifacts.ts b/packages/migrations/src/v2/artifacts.ts deleted file mode 100644 index 31dfc5abb..000000000 --- a/packages/migrations/src/v2/artifacts.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ContractArtifact } from '@0xproject/sol-compiler'; - -import * as AssetProxyOwner from '../../artifacts/2.0.0/AssetProxyOwner.json'; -import * as DummyERC20Token from '../../artifacts/2.0.0/DummyERC20Token.json'; -import * as DummyERC721Token from '../../artifacts/2.0.0/DummyERC721Token.json'; -import * as ERC20Proxy from '../../artifacts/2.0.0/ERC20Proxy.json'; -import * as ERC721Proxy from '../../artifacts/2.0.0/ERC721Proxy.json'; -import * as Exchange from '../../artifacts/2.0.0/Exchange.json'; -import * as WETH9 from '../../artifacts/2.0.0/WETH9.json'; -import * as ZRX from '../../artifacts/2.0.0/ZRXToken.json'; - -export const artifacts = { - ZRX: (ZRX as any) as ContractArtifact, - DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, - DummyERC721Token: (DummyERC721Token as any) as ContractArtifact, - AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - WETH9: (WETH9 as any) as ContractArtifact, - ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, - ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, -}; diff --git a/packages/migrations/src/v2/migration.ts b/packages/migrations/src/v2/migration.ts deleted file mode 100644 index 76a31e2a0..000000000 --- a/packages/migrations/src/v2/migration.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { assetProxyUtils, constants } from '@0xproject/order-utils'; -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Provider, TxData } from 'ethereum-types'; - -import { ArtifactWriter } from '../artifact_writer'; -import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info'; - -import { artifacts } from './artifacts'; -import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner'; -import { DummyERC20TokenContract } from './contract_wrappers/dummy_e_r_c20_token'; -import { DummyERC721TokenContract } from './contract_wrappers/dummy_e_r_c721_token'; -import { ERC20ProxyContract } from './contract_wrappers/e_r_c20_proxy'; -import { ERC721ProxyContract } from './contract_wrappers/e_r_c721_proxy'; -import { ExchangeContract } from './contract_wrappers/exchange'; -import { WETH9Contract } from './contract_wrappers/weth9'; -import { ZRXTokenContract } from './contract_wrappers/zrx_token'; - -/** - * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2' command. - * Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, - * the migration should be written to run synchronously. - * @param provider Web3 provider instance. - * @param artifactsDir The directory with compiler artifact files. - * @param txDefaults Default transaction values to use when deploying contracts. - */ -export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial) => { - const web3Wrapper = new Web3Wrapper(provider); - const networkId = await web3Wrapper.getNetworkIdAsync(); - const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); - - // Proxies - const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults); - artifactsWriter.saveArtifact(erc20proxy); - const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync( - artifacts.ERC721Proxy, - provider, - txDefaults, - ); - artifactsWriter.saveArtifact(erc721proxy); - - // ZRX - const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); - artifactsWriter.saveArtifact(zrxToken); - - // Ether token - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults); - artifactsWriter.saveArtifact(etherToken); - - // Exchange - const exchange = await ExchangeContract.deployFrom0xArtifactAsync( - artifacts.Exchange, - provider, - txDefaults, - assetProxyUtils.encodeERC20AssetData(zrxToken.address), - ); - artifactsWriter.saveArtifact(exchange); - - // Multisigs - const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); - const owners = [accounts[0], accounts[1]]; - const confirmationsRequired = new BigNumber(2); - const secondsRequired = new BigNumber(0); - const owner = accounts[0]; - - // AssetProxyOwner - const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.AssetProxyOwner, - provider, - txDefaults, - owners, - [erc20proxy.address, erc721proxy.address], - confirmationsRequired, - secondsRequired, - ); - artifactsWriter.saveArtifact(assetProxyOwner); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await erc721proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, { - from: owner, - }), - ); - - // Register the Asset Proxies to the Exchange - // HACK: These are exposed in the types package but migrations currently uses an older version - // but we can pull the asset data id from the proxies - const erc20ProxyId = await erc20proxy.getProxyId.callAsync(); - const erc721ProxyId = await erc721proxy.getProxyId.callAsync(); - const oldAddress = constants.NULL_ADDRESS; - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc20ProxyId, erc20proxy.address, oldAddress), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await exchange.registerAssetProxy.sendTransactionAsync(erc721ProxyId, erc721proxy.address, oldAddress), - ); - - // Dummy ERC20 tokens - for (const token of erc20TokenInfo) { - const totalSupply = new BigNumber(100000000000000000000); - // tslint:disable-next-line:no-unused-variable - const dummyErc20Token = await DummyERC20TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC20Token, - provider, - txDefaults, - token.name, - token.symbol, - token.decimals, - totalSupply, - ); - } - - // ERC721 - // tslint:disable-next-line:no-unused-variable - const cryptoKittieToken = await DummyERC721TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC721Token, - provider, - txDefaults, - erc721TokenInfo[0].name, - erc721TokenInfo[0].symbol, - ); -}; -- cgit v1.2.3