aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src
diff options
context:
space:
mode:
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.ts142
-rw-r--r--packages/migrations/src/globals.d.ts6
-rw-r--r--packages/migrations/src/index.ts4
-rw-r--r--packages/migrations/src/migrate.ts58
-rw-r--r--packages/migrations/src/migration.ts175
-rw-r--r--packages/migrations/src/monorepo_scripts/postpublish.ts8
-rw-r--r--packages/migrations/src/types.ts2
-rw-r--r--packages/migrations/src/utils/artifact_writer.ts26
-rw-r--r--packages/migrations/src/utils/constants.ts4
-rw-r--r--packages/migrations/src/utils/provider_factory.ts16
-rw-r--r--packages/migrations/src/utils/token_info.ts20
16 files changed, 221 insertions, 543 deletions
diff --git a/packages/migrations/src/1.0.0/artifacts.ts b/packages/migrations/src/1.0.0/artifacts.ts
deleted file mode 100644
index d0a9f735a..000000000
--- a/packages/migrations/src/1.0.0/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/1.0.0/migration.ts b/packages/migrations/src/1.0.0/migration.ts
deleted file mode 100644
index 0a3c25ae1..000000000
--- a/packages/migrations/src/1.0.0/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 '../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
deleted file mode 100644
index c9a341eb3..000000000
--- a/packages/migrations/src/2.0.0-beta-testnet/artifacts.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-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
deleted file mode 100644
index 19fe5f02c..000000000
--- a/packages/migrations/src/2.0.0-beta-testnet/migration.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-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
deleted file mode 100644
index 8bbd1fcd9..000000000
--- a/packages/migrations/src/2.0.0/artifacts.ts
+++ /dev/null
@@ -1,23 +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 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
deleted file mode 100644
index 0566e67e8..000000000
--- a/packages/migrations/src/2.0.0/migration.ts
+++ /dev/null
@@ -1,142 +0,0 @@
-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,
- 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
deleted file mode 100644
index 94e63a32d..000000000
--- a/packages/migrations/src/globals.d.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-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
index 188f566df..8f629a24b 100644
--- a/packages/migrations/src/index.ts
+++ b/packages/migrations/src/index.ts
@@ -1,3 +1 @@
-export { runV1MigrationsAsync } from './1.0.0/migration';
-export { runV2MigrationsAsync } from './2.0.0/migration';
-export { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
+export { runMigrationsAsync, runMigrationsOnceAsync } from './migration';
diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts
index c46d3580a..d7a76d2f8 100644
--- a/packages/migrations/src/migrate.ts
+++ b/packages/migrations/src/migrate.ts
@@ -1,59 +1,21 @@
#!/usr/bin/env node
-import { devConstants, web3Factory } from '@0xproject/dev-utils';
-import { logUtils } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { devConstants, web3Factory } from '@0x/dev-utils';
+import { logUtils } from '@0x/utils';
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;
+import { runMigrationsAsync } from './migration';
(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}`);
- }
+
+ providerConfigs = { shouldUseInProcessGanache: false };
+ provider = web3Factory.getRpcProvider(providerConfigs);
+ txDefaults = {
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ };
+ await runMigrationsAsync(provider, txDefaults);
process.exit(0);
})().catch(err => {
logUtils.log(err);
diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts
new file mode 100644
index 000000000..86c76a54b
--- /dev/null
+++ b/packages/migrations/src/migration.ts
@@ -0,0 +1,175 @@
+import * as wrappers from '@0x/abi-gen-wrappers';
+import { ContractAddresses } from '@0x/contract-addresses';
+import * as artifacts from '@0x/contract-artifacts';
+import { assetDataUtils } from '@0x/order-utils';
+import { BigNumber } from '@0x/utils';
+import { Web3Wrapper } from '@0x/web3-wrapper';
+import { Provider, TxData } from 'ethereum-types';
+import * as _ from 'lodash';
+
+import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info';
+
+/**
+ * Creates and deploys all the contracts that are required for the latest
+ * version of the 0x protocol. Custom migrations can be defined here. This will
+ * be called with the CLI 'migrate:v2' command.
+ * @param provider Web3 provider instance.
+ * @param txDefaults Default transaction values to use when deploying contracts.
+ * @returns The addresses of the contracts that were deployed.
+ */
+export async function runMigrationsAsync(provider: Provider, txDefaults: Partial<TxData>): Promise<ContractAddresses> {
+ const web3Wrapper = new Web3Wrapper(provider);
+
+ // Proxies
+ const erc20Proxy = await wrappers.ERC20ProxyContract.deployFrom0xArtifactAsync(
+ artifacts.ERC20Proxy,
+ provider,
+ txDefaults,
+ );
+ const erc721Proxy = await wrappers.ERC721ProxyContract.deployFrom0xArtifactAsync(
+ artifacts.ERC721Proxy,
+ provider,
+ txDefaults,
+ );
+
+ // ZRX
+ const zrxToken = await wrappers.ZRXTokenContract.deployFrom0xArtifactAsync(
+ artifacts.ZRXToken,
+ provider,
+ txDefaults,
+ );
+
+ // Ether token
+ const etherToken = await wrappers.WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults);
+
+ // Exchange
+ const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
+ const exchange = await wrappers.ExchangeContract.deployFrom0xArtifactAsync(
+ artifacts.Exchange,
+ provider,
+ txDefaults,
+ );
+
+ // 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 wrappers.AssetProxyOwnerContract.deployFrom0xArtifactAsync(
+ artifacts.AssetProxyOwner,
+ provider,
+ txDefaults,
+ owners,
+ [erc20Proxy.address, erc721Proxy.address],
+ confirmationsRequired,
+ secondsRequired,
+ );
+
+ 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 wrappers.DummyERC20TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC20Token,
+ provider,
+ txDefaults,
+ token.name,
+ token.symbol,
+ token.decimals,
+ totalSupply,
+ );
+ }
+
+ // ERC721
+ // tslint:disable-next-line:no-unused-variable
+ const cryptoKittieToken = await wrappers.DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Token,
+ provider,
+ txDefaults,
+ erc721TokenInfo[0].name,
+ erc721TokenInfo[0].symbol,
+ );
+
+ // Forwarder
+ const forwarder = await wrappers.ForwarderContract.deployFrom0xArtifactAsync(
+ artifacts.Forwarder,
+ provider,
+ txDefaults,
+ exchange.address,
+ assetDataUtils.encodeERC20AssetData(zrxToken.address),
+ assetDataUtils.encodeERC20AssetData(etherToken.address),
+ );
+
+ // OrderValidator
+ const orderValidator = await wrappers.OrderValidatorContract.deployFrom0xArtifactAsync(
+ artifacts.OrderValidator,
+ provider,
+ txDefaults,
+ exchange.address,
+ zrxAssetData,
+ );
+
+ return {
+ erc20Proxy: erc20Proxy.address,
+ erc721Proxy: erc721Proxy.address,
+ zrxToken: zrxToken.address,
+ etherToken: etherToken.address,
+ exchange: exchange.address,
+ assetProxyOwner: assetProxyOwner.address,
+ forwarder: forwarder.address,
+ orderValidator: orderValidator.address,
+ };
+}
+
+let _cachedContractAddresses: ContractAddresses;
+
+/**
+ * Exactly like runMigrationsAsync but will only run the migrations the first
+ * time it is called. Any subsequent calls will return the cached contract
+ * addresses.
+ * @param provider Web3 provider instance.
+ * @param txDefaults Default transaction values to use when deploying contracts.
+ * @returns The addresses of the contracts that were deployed.
+ */
+export async function runMigrationsOnceAsync(
+ provider: Provider,
+ txDefaults: Partial<TxData>,
+): Promise<ContractAddresses> {
+ if (!_.isUndefined(_cachedContractAddresses)) {
+ return _cachedContractAddresses;
+ }
+ _cachedContractAddresses = await runMigrationsAsync(provider, txDefaults);
+ return _cachedContractAddresses;
+}
diff --git a/packages/migrations/src/monorepo_scripts/postpublish.ts b/packages/migrations/src/monorepo_scripts/postpublish.ts
deleted file mode 100644
index dcb99d0f7..000000000
--- a/packages/migrations/src/monorepo_scripts/postpublish.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-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
index 65f685797..87e66f356 100644
--- a/packages/migrations/src/types.ts
+++ b/packages/migrations/src/types.ts
@@ -1,4 +1,4 @@
-import { BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0x/utils';
export interface ERC20Token {
address?: string;
diff --git a/packages/migrations/src/utils/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts
deleted file mode 100644
index b7522df05..000000000
--- a/packages/migrations/src/utils/artifact_writer.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-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
index 4ae2ff833..8b16a0520 100644
--- a/packages/migrations/src/utils/constants.ts
+++ b/packages/migrations/src/utils/constants.ts
@@ -1,4 +1,4 @@
-import { BigNumber } from '@0xproject/utils';
+import { BigNumber } from '@0x/utils';
export const constants = {
ASSET_PROXY_OWNER_OWNERS: [
@@ -13,4 +13,6 @@ export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
KOVAN_RPC_URL: 'https://kovan.infura.io/',
KOVAN_NETWORK_ID: 42,
+ MAINNET_RPC_URL: 'https://mainnet.infura.io/',
+ MAINNET_NETWORK_ID: 1,
};
diff --git a/packages/migrations/src/utils/provider_factory.ts b/packages/migrations/src/utils/provider_factory.ts
index a0d4e436e..8017b672a 100644
--- a/packages/migrations/src/utils/provider_factory.ts
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -1,4 +1,4 @@
-import { LedgerEthereumClient, LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0xproject/subproviders';
+import { LedgerEthereumClient, LedgerSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import Eth from '@ledgerhq/hw-app-eth';
// tslint:disable:no-implicit-dependencies
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
@@ -12,7 +12,7 @@ async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumC
return ledgerEthClient;
}
export const providerFactory = {
- async getLedgerProviderAsync(): Promise<Provider> {
+ async getKovanLedgerProviderAsync(): Promise<Provider> {
const provider = new Web3ProviderEngine();
const ledgerWalletConfigs = {
networkId: constants.KOVAN_NETWORK_ID,
@@ -24,4 +24,16 @@ export const providerFactory = {
provider.start();
return provider;
},
+ async getMainnetLedgerProviderAsync(): Promise<Provider> {
+ const provider = new Web3ProviderEngine();
+ const ledgerWalletConfigs = {
+ networkId: constants.MAINNET_NETWORK_ID,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.addProvider(new RPCSubprovider(constants.MAINNET_RPC_URL));
+ provider.start();
+ return provider;
+ },
};
diff --git a/packages/migrations/src/utils/token_info.ts b/packages/migrations/src/utils/token_info.ts
index 7975c2174..6e0411f60 100644
--- a/packages/migrations/src/utils/token_info.ts
+++ b/packages/migrations/src/utils/token_info.ts
@@ -1,7 +1,21 @@
-import { BigNumber, NULL_BYTES } from '@0xproject/utils';
+import { BigNumber, NULL_BYTES } from '@0x/utils';
import { ERC20Token, ERC721Token } from '../types';
+export const etherTokenByNetwork: { [networkId: number]: { address: string } } = {
+ 3: {
+ address: '0xc778417e063141139fce010982780140aa0cd5ab',
+ },
+ 4: {
+ address: '0xc778417e063141139fce010982780140aa0cd5ab',
+ },
+ 42: {
+ address: '0xd0a1e359811322d97991e03f863a0c30c2cf029c',
+ },
+ 50: {
+ address: '',
+ },
+};
export const erc20TokenInfo: ERC20Token[] = [
{
name: 'Augur Reputation Token',
@@ -42,7 +56,7 @@ export const erc20TokenInfo: ERC20Token[] = [
export const erc721TokenInfo: ERC721Token[] = [
{
- name: 'CryptoKitties',
- symbol: 'CK',
+ name: '0xen ERC721',
+ symbol: '0xen',
},
];