aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-25 01:56:31 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-25 04:59:30 +0800
commit92b0efff5abaac8bea468a1b3f897d004ec9c542 (patch)
tree61e976aa42b78e7eea12f73fb2ccc4a5ad1f9ceb /packages/migrations/src
parent62431fee8e0c79a61f7ebb7677e6c88f0ae95116 (diff)
downloaddexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar.gz
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar.bz2
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar.lz
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar.xz
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.tar.zst
dexon-sol-tools-92b0efff5abaac8bea468a1b3f897d004ec9c542.zip
Migrate migrations to v2
Diffstat (limited to 'packages/migrations/src')
-rw-r--r--packages/migrations/src/index.ts3
-rw-r--r--packages/migrations/src/migrate.ts19
-rw-r--r--packages/migrations/src/types.ts18
-rw-r--r--packages/migrations/src/utils/token_info.ts11
-rw-r--r--packages/migrations/src/v1/artifacts.ts (renamed from packages/migrations/src/artifacts.ts)16
-rw-r--r--packages/migrations/src/v1/migration.ts (renamed from packages/migrations/src/migration.ts)23
-rw-r--r--packages/migrations/src/v2/artifacts.ts21
-rw-r--r--packages/migrations/src/v2/migration.ts118
8 files changed, 190 insertions, 39 deletions
diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts
index c342247a3..5bf2f847d 100644
--- a/packages/migrations/src/index.ts
+++ b/packages/migrations/src/index.ts
@@ -1 +1,2 @@
-export { runMigrationsAsync } from './migration';
+export { runV1MigrationsAsync } from './v1/migration';
+export { runV2MigrationsAsync } from './v2/migration';
diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts
index 1230f376e..49b4e897c 100644
--- a/packages/migrations/src/migrate.ts
+++ b/packages/migrations/src/migrate.ts
@@ -3,8 +3,16 @@ import { devConstants, web3Factory } from '@0xproject/dev-utils';
import { Provider } from '@0xproject/types';
import { logUtils } from '@0xproject/utils';
import * as path from 'path';
+import * as yargs from 'yargs';
-import { runMigrationsAsync } from './migration';
+import { runV1MigrationsAsync } from './v1/migration';
+import { runV2MigrationsAsync } from './v2/migration';
+
+enum ContractVersions {
+ V1 = '1.0.0',
+ V2 = '2.0.0',
+}
+const args = yargs.argv;
(async () => {
const txDefaults = {
@@ -12,8 +20,13 @@ import { runMigrationsAsync } from './migration';
};
const providerConfigs = { shouldUseInProcessGanache: false };
const provider: Provider = web3Factory.getRpcProvider(providerConfigs);
- const artifactsDir = 'artifacts/1.0.0';
- await runMigrationsAsync(provider, artifactsDir, txDefaults);
+ const contractsVersion = args.contractsVersion;
+ const artifactsDir = `artifacts/${contractsVersion}`;
+ if (contractsVersion === ContractVersions.V1) {
+ await runV1MigrationsAsync(provider, artifactsDir, txDefaults);
+ } else {
+ await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
+ }
process.exit(0);
})().catch(err => {
logUtils.log(err);
diff --git a/packages/migrations/src/types.ts b/packages/migrations/src/types.ts
index 5ece26c5d..65f685797 100644
--- a/packages/migrations/src/types.ts
+++ b/packages/migrations/src/types.ts
@@ -1,16 +1,6 @@
import { BigNumber } from '@0xproject/utils';
-export interface MultiSigConfig {
- owners: string[];
- confirmationsRequired: number;
- secondsRequired: number;
-}
-
-export interface MultiSigConfigByNetwork {
- [networkName: string]: MultiSigConfig;
-}
-
-export interface Token {
+export interface ERC20Token {
address?: string;
name: string;
symbol: string;
@@ -19,9 +9,9 @@ export interface Token {
swarmHash: string;
}
-export interface TokenInfoByNetwork {
- development: Token[];
- live: Token[];
+export interface ERC721Token {
+ name: string;
+ symbol: string;
}
export enum ContractName {
diff --git a/packages/migrations/src/utils/token_info.ts b/packages/migrations/src/utils/token_info.ts
index e72a80220..7975c2174 100644
--- a/packages/migrations/src/utils/token_info.ts
+++ b/packages/migrations/src/utils/token_info.ts
@@ -1,8 +1,8 @@
import { BigNumber, NULL_BYTES } from '@0xproject/utils';
-import { Token } from '../types';
+import { ERC20Token, ERC721Token } from '../types';
-export const tokenInfo: Token[] = [
+export const erc20TokenInfo: ERC20Token[] = [
{
name: 'Augur Reputation Token',
symbol: 'REP',
@@ -39,3 +39,10 @@ export const tokenInfo: Token[] = [
swarmHash: NULL_BYTES,
},
];
+
+export const erc721TokenInfo: ERC721Token[] = [
+ {
+ name: 'CryptoKitties',
+ symbol: 'CK',
+ },
+];
diff --git a/packages/migrations/src/artifacts.ts b/packages/migrations/src/v1/artifacts.ts
index acc267256..d0a9f735a 100644
--- a/packages/migrations/src/artifacts.ts
+++ b/packages/migrations/src/v1/artifacts.ts
@@ -1,13 +1,13 @@
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';
+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,
diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/v1/migration.ts
index e29414a57..233339244 100644
--- a/packages/migrations/src/migration.ts
+++ b/packages/migrations/src/v1/migration.ts
@@ -3,7 +3,10 @@ import { BigNumber, NULL_BYTES } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import { ArtifactWriter } from './artifact_writer';
+import { ArtifactWriter } from '../artifact_writer';
+import { ContractName } from '../types';
+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';
@@ -12,18 +15,16 @@ 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';
-import { ContractName } from './types';
-import { tokenInfo } from './utils/token_info';
/**
- * Custom migrations should be defined in this function. This will be called with the CLI 'migrate' command.
+ * 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 runMigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial<TxData>) => {
+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);
@@ -73,11 +74,11 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin
await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: owner });
const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync(
zrxToken.address,
- tokenInfo[0].name,
- tokenInfo[0].symbol,
- tokenInfo[0].decimals,
- tokenInfo[0].ipfsHash,
- tokenInfo[0].swarmHash,
+ erc20TokenInfo[0].name,
+ erc20TokenInfo[0].symbol,
+ erc20TokenInfo[0].decimals,
+ erc20TokenInfo[0].ipfsHash,
+ erc20TokenInfo[0].swarmHash,
{ from: owner },
);
const decimals = 18;
@@ -105,7 +106,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin
gas: addTokenGasEstimate,
},
);
- for (const token of tokenInfo) {
+ for (const token of erc20TokenInfo) {
const totalSupply = new BigNumber(100000000000000000000);
const dummyToken = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
artifacts.DummyERC20Token,
diff --git a/packages/migrations/src/v2/artifacts.ts b/packages/migrations/src/v2/artifacts.ts
new file mode 100644
index 000000000..3079e4d89
--- /dev/null
+++ b/packages/migrations/src/v2/artifacts.ts
@@ -0,0 +1,21 @@
+import { ContractArtifact } from '@0xproject/sol-compiler';
+
+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 MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../../artifacts/2.0.0/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.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,
+ MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress 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
new file mode 100644
index 000000000..daad1ec00
--- /dev/null
+++ b/packages/migrations/src/v2/migration.ts
@@ -0,0 +1,118 @@
+import { Provider, TxData } from '@0xproject/types';
+import { BigNumber, NULL_BYTES } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import * as _ from 'lodash';
+
+import { ArtifactWriter } from '../artifact_writer';
+import { ContractName } from '../types';
+import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info';
+
+import { artifacts } from './artifacts';
+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 { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address';
+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,
+ 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];
+
+ // TODO(leonid) use `AssetProxyOwner` after https://github.com/0xProject/0x-monorepo/pull/571 is merged
+ // ERC20 Multisig
+ const multiSigERC20 = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync(
+ artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
+ provider,
+ txDefaults,
+ owners,
+ confirmationsRequired,
+ secondsRequired,
+ erc20proxy.address,
+ );
+ artifactsWriter.saveArtifact(multiSigERC20);
+ await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner });
+ await erc20proxy.transferOwnership.sendTransactionAsync(multiSigERC20.address, { from: owner });
+
+ // ERC721 Multisig
+ const multiSigERC721 = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync(
+ artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,
+ provider,
+ txDefaults,
+ owners,
+ confirmationsRequired,
+ secondsRequired,
+ erc721proxy.address,
+ );
+ artifactsWriter.saveArtifact(multiSigERC721);
+ await erc721proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner });
+ await erc721proxy.transferOwnership.sendTransactionAsync(multiSigERC20.address, { from: owner });
+
+ // Dummy ERC20 tokens
+ for (const token of erc20TokenInfo) {
+ const totalSupply = new BigNumber(100000000000000000000);
+ const dummyErc20Token = await DummyERC20TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC20Token,
+ provider,
+ txDefaults,
+ token.name,
+ token.symbol,
+ token.decimals,
+ totalSupply,
+ );
+ }
+
+ // CK -> Token registry
+ const cryptoKittieToken = await DummyERC721TokenContract.deployFrom0xArtifactAsync(
+ artifacts.DummyERC721Token,
+ provider,
+ txDefaults,
+ erc721TokenInfo[0].name,
+ erc721TokenInfo[0].symbol,
+ );
+};