aboutsummaryrefslogtreecommitdiffstats
path: root/packages/migrations/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-06-25 08:36:24 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-06-30 08:25:56 +0800
commit5f0a2953c63c31daa975b587f5c5072b6f7e418c (patch)
treefa3a7888c9ef78770575e8612a40c323fd561448 /packages/migrations/src
parent78b513c52addc16062419236c24f01bcfe191f3f (diff)
downloaddexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar.gz
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar.bz2
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar.lz
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar.xz
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.tar.zst
dexon-sol-tools-5f0a2953c63c31daa975b587f5c5072b6f7e418c.zip
Add Kovan migrations
Diffstat (limited to 'packages/migrations/src')
-rw-r--r--packages/migrations/src/1.0.0/artifacts.ts (renamed from packages/migrations/src/v1/artifacts.ts)0
-rw-r--r--packages/migrations/src/1.0.0/migration.ts (renamed from packages/migrations/src/v1/migration.ts)0
-rw-r--r--packages/migrations/src/2.0.0-beta-kovan/artifacts.ts13
-rw-r--r--packages/migrations/src/2.0.0-beta-kovan/constants.ts14
-rw-r--r--packages/migrations/src/2.0.0-beta-kovan/migration.ts91
-rw-r--r--packages/migrations/src/2.0.0/artifacts.ts (renamed from packages/migrations/src/v2/artifacts.ts)0
-rw-r--r--packages/migrations/src/2.0.0/migration.ts (renamed from packages/migrations/src/v2/migration.ts)0
-rw-r--r--packages/migrations/src/index.ts5
-rw-r--r--packages/migrations/src/migrate.ts20
9 files changed, 136 insertions, 7 deletions
diff --git a/packages/migrations/src/v1/artifacts.ts b/packages/migrations/src/1.0.0/artifacts.ts
index d0a9f735a..d0a9f735a 100644
--- a/packages/migrations/src/v1/artifacts.ts
+++ b/packages/migrations/src/1.0.0/artifacts.ts
diff --git a/packages/migrations/src/v1/migration.ts b/packages/migrations/src/1.0.0/migration.ts
index 3398537e5..3398537e5 100644
--- a/packages/migrations/src/v1/migration.ts
+++ b/packages/migrations/src/1.0.0/migration.ts
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<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 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/v2/artifacts.ts b/packages/migrations/src/2.0.0/artifacts.ts
index 31dfc5abb..31dfc5abb 100644
--- a/packages/migrations/src/v2/artifacts.ts
+++ b/packages/migrations/src/2.0.0/artifacts.ts
diff --git a/packages/migrations/src/v2/migration.ts b/packages/migrations/src/2.0.0/migration.ts
index 76a31e2a0..76a31e2a0 100644
--- a/packages/migrations/src/v2/migration.ts
+++ b/packages/migrations/src/2.0.0/migration.ts
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 => {