aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-08-14 09:42:09 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-08-14 09:42:09 +0800
commit88766a02c7e6688e72d5c4c69ce68028b322f154 (patch)
treefa06552a80249e7998691b64df6b3b2827f9f947 /packages/migrations/src
parent8162394797342cef268cc8072fc860326974e269 (diff)
parentfadd292ecf367e42154856509d0ea0c20b23f2f1 (diff)
downloaddexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar.gz
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar.bz2
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar.lz
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar.xz
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.tar.zst
dexon-0x-contracts-88766a02c7e6688e72d5c4c69ce68028b322f154.zip
Merge branch 'development'
Diffstat (limited to 'packages/migrations/src')
-rw-r--r--packages/migrations/src/1.0.0/artifacts.ts21
-rw-r--r--packages/migrations/src/1.0.0/migration.ts142
-rw-r--r--packages/migrations/src/2.0.0-beta-testnet/artifacts.ts13
-rw-r--r--packages/migrations/src/2.0.0-beta-testnet/migration.ts104
-rw-r--r--packages/migrations/src/2.0.0/artifacts.ts23
-rw-r--r--packages/migrations/src/2.0.0/migration.ts144
-rw-r--r--packages/migrations/src/globals.d.ts6
-rw-r--r--packages/migrations/src/index.ts3
-rw-r--r--packages/migrations/src/migrate.ts61
-rw-r--r--packages/migrations/src/monorepo_scripts/postpublish.ts8
-rw-r--r--packages/migrations/src/types.ts29
-rw-r--r--packages/migrations/src/utils/artifact_writer.ts26
-rw-r--r--packages/migrations/src/utils/constants.ts16
-rw-r--r--packages/migrations/src/utils/provider_factory.ts27
-rw-r--r--packages/migrations/src/utils/token_info.ts48
15 files changed, 671 insertions, 0 deletions
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..0a3c25ae1
--- /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 '../utils/artifact_writer';
+import { erc20TokenInfo } from '../utils/token_info';
+
+import { artifacts } from './artifacts';
+import { DummyERC20TokenContract } from './contract_wrappers/dummy_erc20_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<TxData>) => {
+ 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-testnet/artifacts.ts b/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts
new file mode 100644
index 000000000..c9a341eb3
--- /dev/null
+++ b/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts
@@ -0,0 +1,13 @@
+import { ContractArtifact } from '@0xproject/sol-compiler';
+
+import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-testnet/AssetProxyOwner.json';
+import * as ERC20Proxy from '../../artifacts/2.0.0-beta-testnet/ERC20Proxy.json';
+import * as ERC721Proxy from '../../artifacts/2.0.0-beta-testnet/ERC721Proxy.json';
+import * as Exchange from '../../artifacts/2.0.0-beta-testnet/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-testnet/migration.ts b/packages/migrations/src/2.0.0-beta-testnet/migration.ts
new file mode 100644
index 000000000..19fe5f02c
--- /dev/null
+++ b/packages/migrations/src/2.0.0-beta-testnet/migration.ts
@@ -0,0 +1,104 @@
+import { assetDataUtils } from '@0xproject/order-utils';
+import { logUtils } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { Provider, TxData } from 'ethereum-types';
+
+import { ArtifactWriter } from '../utils/artifact_writer';
+
+import { constants } from '../utils/constants';
+
+import { artifacts } from './artifacts';
+import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner';
+import { ERC20ProxyContract } from './contract_wrappers/erc20_proxy';
+import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy';
+import { ExchangeContract } from './contract_wrappers/exchange';
+
+/**
+ * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-beta-testnet' 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 runV2TestnetMigrationsAsync = async (
+ provider: Provider,
+ artifactsDir: string,
+ txDefaults: Partial<TxData>,
+) => {
+ 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 zrxAddressOnKovan = '0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570';
+ const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxAddressOnKovan);
+ const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
+ artifacts.Exchange,
+ provider,
+ txDefaults,
+ zrxAssetData,
+ );
+ artifactsWriter.saveArtifact(exchange);
+
+ let txHash;
+ // Register AssetProxies in Exchange
+ txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc20proxy.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Registering ERC20Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc721proxy.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Registering ERC721Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ // 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
+ txHash = await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Authorizing Exchange on ERC20Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ txHash = await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Authorizing Exchange on ERC721Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ // Transfer ownership of AssetProxies and Exchange to AssetProxyOwner
+ txHash = await erc20proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Transferring ownership of ERC20Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ txHash = await erc721proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Transferring ownership of ERC721Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ txHash = await exchange.transferOwnership.sendTransactionAsync(assetProxyOwner.address);
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Transferring ownership of Exchange');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+};
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..8bbd1fcd9
--- /dev/null
+++ b/packages/migrations/src/2.0.0/artifacts.ts
@@ -0,0 +1,23 @@
+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 Forwarder from '../../artifacts/2.0.0/Forwarder.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,
+ Forwarder: (Forwarder 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..f51c236de
--- /dev/null
+++ b/packages/migrations/src/2.0.0/migration.ts
@@ -0,0 +1,144 @@
+import { assetDataUtils } from '@0xproject/order-utils';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { Provider, TxData } from 'ethereum-types';
+
+import { ArtifactWriter } from '../utils/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_erc20_token';
+import { DummyERC721TokenContract } from './contract_wrappers/dummy_erc721_token';
+import { ERC20ProxyContract } from './contract_wrappers/erc20_proxy';
+import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy';
+import { ExchangeContract } from './contract_wrappers/exchange';
+import { ForwarderContract } from './contract_wrappers/forwarder';
+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<TxData>) => {
+ 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,
+ assetDataUtils.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
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await exchange.registerAssetProxy.sendTransactionAsync(erc20proxy.address),
+ );
+ await web3Wrapper.awaitTransactionSuccessAsync(
+ await exchange.registerAssetProxy.sendTransactionAsync(erc721proxy.address),
+ );
+
+ // Dummy ERC20 tokens
+ for (const token of erc20TokenInfo) {
+ const totalSupply = new BigNumber(1000000000000000000000000000);
+ // 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,
+ );
+
+ // Forwarder
+ const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
+ artifacts.Forwarder,
+ provider,
+ txDefaults,
+ exchange.address,
+ etherToken.address,
+ zrxToken.address,
+ assetDataUtils.encodeERC20AssetData(zrxToken.address),
+ assetDataUtils.encodeERC20AssetData(etherToken.address),
+ );
+ artifactsWriter.saveArtifact(forwarder);
+};
diff --git a/packages/migrations/src/globals.d.ts b/packages/migrations/src/globals.d.ts
new file mode 100644
index 000000000..94e63a32d
--- /dev/null
+++ b/packages/migrations/src/globals.d.ts
@@ -0,0 +1,6 @@
+declare module '*.json' {
+ const json: any;
+ /* tslint:disable */
+ export default json;
+ /* tslint:enable */
+}
diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts
new file mode 100644
index 000000000..188f566df
--- /dev/null
+++ b/packages/migrations/src/index.ts
@@ -0,0 +1,3 @@
+export { runV1MigrationsAsync } from './1.0.0/migration';
+export { runV2MigrationsAsync } from './2.0.0/migration';
+export { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts
new file mode 100644
index 000000000..c46d3580a
--- /dev/null
+++ b/packages/migrations/src/migrate.ts
@@ -0,0 +1,61 @@
+#!/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 './1.0.0/migration';
+import { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
+import { runV2MigrationsAsync } from './2.0.0/migration';
+
+import { providerFactory } from './utils/provider_factory';
+
+enum ContractVersions {
+ V1 = '1.0.0',
+ V2 = '2.0.0',
+ V2Testnet = '2.0.0-beta-testnet',
+}
+const args = yargs.argv;
+
+(async () => {
+ const contractsVersion = args.contractsVersion;
+ const artifactsDir = `artifacts/${contractsVersion}`;
+ let providerConfigs;
+ let provider: Provider;
+ let txDefaults;
+ switch (contractsVersion) {
+ case ContractVersions.V1:
+ providerConfigs = { shouldUseInProcessGanache: false };
+ provider = web3Factory.getRpcProvider(providerConfigs);
+ txDefaults = {
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ };
+ await runV1MigrationsAsync(provider, artifactsDir, txDefaults);
+ break;
+ case ContractVersions.V2:
+ providerConfigs = { shouldUseInProcessGanache: false };
+ provider = web3Factory.getRpcProvider(providerConfigs);
+ txDefaults = {
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ };
+ await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
+ break;
+ case ContractVersions.V2Testnet:
+ provider = await providerFactory.getLedgerProviderAsync();
+ const web3Wrapper = new Web3Wrapper(provider);
+ const accounts = await web3Wrapper.getAvailableAddressesAsync();
+ txDefaults = {
+ from: accounts[0],
+ gas: devConstants.GAS_LIMIT,
+ };
+ await runV2TestnetMigrationsAsync(provider, artifactsDir, txDefaults);
+ break;
+ default:
+ throw new Error(`Unsupported contract version: ${contractsVersion}`);
+ }
+ process.exit(0);
+})().catch(err => {
+ logUtils.log(err);
+ process.exit(1);
+});
diff --git a/packages/migrations/src/monorepo_scripts/postpublish.ts b/packages/migrations/src/monorepo_scripts/postpublish.ts
new file mode 100644
index 000000000..dcb99d0f7
--- /dev/null
+++ b/packages/migrations/src/monorepo_scripts/postpublish.ts
@@ -0,0 +1,8 @@
+import { postpublishUtils } from '@0xproject/monorepo-scripts';
+
+import * as packageJSON from '../package.json';
+import * as tsConfigJSON from '../tsconfig.json';
+
+const cwd = `${__dirname}/..`;
+// tslint:disable-next-line:no-floating-promises
+postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd);
diff --git a/packages/migrations/src/types.ts b/packages/migrations/src/types.ts
new file mode 100644
index 000000000..65f685797
--- /dev/null
+++ b/packages/migrations/src/types.ts
@@ -0,0 +1,29 @@
+import { BigNumber } from '@0xproject/utils';
+
+export interface ERC20Token {
+ address?: string;
+ name: string;
+ symbol: string;
+ decimals: BigNumber;
+ ipfsHash: string;
+ swarmHash: string;
+}
+
+export interface ERC721Token {
+ name: string;
+ symbol: string;
+}
+
+export enum ContractName {
+ TokenTransferProxy = 'TokenTransferProxy',
+ TokenRegistry = 'TokenRegistry',
+ MultiSigWalletWithTimeLock = 'MultiSigWalletWithTimeLock',
+ Exchange = 'Exchange',
+ ZRXToken = 'ZRXToken',
+ DummyToken = 'DummyToken',
+ WETH9 = 'WETH9',
+ MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress',
+ AccountLevels = 'AccountLevels',
+ EtherDelta = 'EtherDelta',
+ Arbitrage = 'Arbitrage',
+}
diff --git a/packages/migrations/src/utils/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts
new file mode 100644
index 000000000..b7522df05
--- /dev/null
+++ b/packages/migrations/src/utils/artifact_writer.ts
@@ -0,0 +1,26 @@
+import { BaseContract } from '@0xproject/base-contract';
+import { ContractArtifact } from '@0xproject/sol-compiler';
+import * as fs from 'fs';
+import * as path from 'path';
+
+export class ArtifactWriter {
+ private readonly _artifactsDir: string;
+ private readonly _networkId: number;
+ constructor(artifactsDir: string, networkId: number) {
+ this._artifactsDir = artifactsDir;
+ this._networkId = networkId;
+ }
+ // This updates the artifact file but does not update the `artifacts` module above. It will not
+ // contain the saved artifact changes.
+ public saveArtifact(contract: BaseContract): void {
+ const contractName = contract.contractName;
+ const artifactFile = path.join(this._artifactsDir, `${contractName}.json`);
+ const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFile).toString());
+ artifact.networks[this._networkId] = {
+ address: contract.address,
+ links: {},
+ constructorArgs: JSON.stringify(contract.constructorArgs),
+ };
+ fs.writeFileSync(artifactFile, JSON.stringify(artifact, null, '\t'));
+ }
+}
diff --git a/packages/migrations/src/utils/constants.ts b/packages/migrations/src/utils/constants.ts
new file mode 100644
index 000000000..4ae2ff833
--- /dev/null
+++ b/packages/migrations/src/utils/constants.ts
@@ -0,0 +1,16 @@
+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: '0xf47261b0',
+ ERC721_PROXY_ID: '0x02571792',
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ KOVAN_RPC_URL: 'https://kovan.infura.io/',
+ KOVAN_NETWORK_ID: 42,
+};
diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts
new file mode 100644
index 000000000..a0d4e436e
--- /dev/null
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -0,0 +1,27 @@
+import { LedgerEthereumClient, LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0xproject/subproviders';
+import Eth from '@ledgerhq/hw-app-eth';
+// tslint:disable:no-implicit-dependencies
+import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
+import { Provider } from 'ethereum-types';
+
+import { constants } from './constants';
+
+async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
+ const ledgerConnection = await TransportNodeHid.create();
+ const ledgerEthClient = new Eth(ledgerConnection);
+ return ledgerEthClient;
+}
+export const providerFactory = {
+ async getLedgerProviderAsync(): Promise<Provider> {
+ const provider = new Web3ProviderEngine();
+ const ledgerWalletConfigs = {
+ networkId: constants.KOVAN_NETWORK_ID,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.addProvider(new RPCSubprovider(constants.KOVAN_RPC_URL));
+ provider.start();
+ return provider;
+ },
+};
diff --git a/packages/migrations/src/utils/token_info.ts b/packages/migrations/src/utils/token_info.ts
new file mode 100644
index 000000000..7975c2174
--- /dev/null
+++ b/packages/migrations/src/utils/token_info.ts
@@ -0,0 +1,48 @@
+import { BigNumber, NULL_BYTES } from '@0xproject/utils';
+
+import { ERC20Token, ERC721Token } from '../types';
+
+export const erc20TokenInfo: ERC20Token[] = [
+ {
+ name: 'Augur Reputation Token',
+ symbol: 'REP',
+ decimals: new BigNumber(18),
+ ipfsHash: NULL_BYTES,
+ swarmHash: NULL_BYTES,
+ },
+ {
+ name: 'Digix DAO Token',
+ symbol: 'DGD',
+ decimals: new BigNumber(18),
+ ipfsHash: NULL_BYTES,
+ swarmHash: NULL_BYTES,
+ },
+ {
+ name: 'Golem Network Token',
+ symbol: 'GNT',
+ decimals: new BigNumber(18),
+ ipfsHash: NULL_BYTES,
+ swarmHash: NULL_BYTES,
+ },
+ {
+ name: 'MakerDAO',
+ symbol: 'MKR',
+ decimals: new BigNumber(18),
+ ipfsHash: NULL_BYTES,
+ swarmHash: NULL_BYTES,
+ },
+ {
+ name: 'Melon Token',
+ symbol: 'MLN',
+ decimals: new BigNumber(18),
+ ipfsHash: NULL_BYTES,
+ swarmHash: NULL_BYTES,
+ },
+];
+
+export const erc721TokenInfo: ERC721Token[] = [
+ {
+ name: 'CryptoKitties',
+ symbol: 'CK',
+ },
+];