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.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)2
-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.ts105
-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)13
-rw-r--r--packages/migrations/src/index.ts5
-rw-r--r--packages/migrations/src/migrate.ts50
-rw-r--r--packages/migrations/src/utils/artifact_writer.ts (renamed from packages/migrations/src/artifact_writer.ts)0
-rw-r--r--packages/migrations/src/utils/constants.ts16
-rw-r--r--packages/migrations/src/utils/provider_factory.ts33
11 files changed, 214 insertions, 23 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 6e9f1dae3..0a3c25ae1 100644
--- a/packages/migrations/src/v1/migration.ts
+++ b/packages/migrations/src/1.0.0/migration.ts
@@ -2,7 +2,7 @@ import { BigNumber, NULL_BYTES } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
-import { ArtifactWriter } from '../artifact_writer';
+import { ArtifactWriter } from '../utils/artifact_writer';
import { erc20TokenInfo } from '../utils/token_info';
import { artifacts } from './artifacts';
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..b8173bac5
--- /dev/null
+++ b/packages/migrations/src/2.0.0-beta-testnet/migration.ts
@@ -0,0 +1,105 @@
+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/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-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 exchange = await ExchangeContract.deployFrom0xArtifactAsync(artifacts.Exchange, provider, txDefaults);
+ artifactsWriter.saveArtifact(exchange);
+
+ let txHash;
+ // Register AssetProxies in Exchange
+ const oldAssetProxy = constants.NULL_ADDRESS;
+ txHash = await exchange.registerAssetProxy.sendTransactionAsync(
+ constants.ERC20_PROXY_ID,
+ erc20proxy.address,
+ oldAssetProxy,
+ );
+ logUtils.log(`transactionHash: ${txHash}`);
+ logUtils.log('Registering ERC20Proxy');
+ await web3Wrapper.awaitTransactionSuccessAsync(txHash);
+
+ txHash = await exchange.registerAssetProxy.sendTransactionAsync(
+ constants.ERC721_PROXY_ID,
+ erc721proxy.address,
+ oldAssetProxy,
+ );
+ 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/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 168e47a19..75e60d3e2 100644
--- a/packages/migrations/src/v2/migration.ts
+++ b/packages/migrations/src/2.0.0/migration.ts
@@ -1,9 +1,9 @@
-import { assetProxyUtils, constants } from '@0xproject/order-utils';
+import { assetProxyUtils } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types';
-import { ArtifactWriter } from '../artifact_writer';
+import { ArtifactWriter } from '../utils/artifact_writer';
import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info';
import { artifacts } from './artifacts';
@@ -96,16 +96,11 @@ export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: str
);
// Register the Asset Proxies to the Exchange
- // HACK: These are exposed in the types package but migrations currently uses an older version
- // but we can pull the asset data id from the proxies
- const erc20ProxyId = await erc20proxy.getProxyId.callAsync();
- const erc721ProxyId = await erc721proxy.getProxyId.callAsync();
- const oldAddress = constants.NULL_ADDRESS;
await web3Wrapper.awaitTransactionSuccessAsync(
- await exchange.registerAssetProxy.sendTransactionAsync(erc20ProxyId, erc20proxy.address, oldAddress),
+ await exchange.registerAssetProxy.sendTransactionAsync(erc20proxy.address),
);
await web3Wrapper.awaitTransactionSuccessAsync(
- await exchange.registerAssetProxy.sendTransactionAsync(erc721ProxyId, erc721proxy.address, oldAddress),
+ await exchange.registerAssetProxy.sendTransactionAsync(erc721proxy.address),
);
// Dummy ERC20 tokens
diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts
index 5bf2f847d..188f566df 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 { runV2TestnetMigrationsAsync } from './2.0.0-beta-testnet/migration';
diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts
index 5f320ec78..c46d3580a 100644
--- a/packages/migrations/src/migrate.ts
+++ b/packages/migrations/src/migrate.ts
@@ -1,30 +1,58 @@
#!/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 { 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 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 {
- await runV2MigrationsAsync(provider, artifactsDir, txDefaults);
+ 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 => {
diff --git a/packages/migrations/src/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts
index 2da5a09dd..2da5a09dd 100644
--- a/packages/migrations/src/artifact_writer.ts
+++ b/packages/migrations/src/utils/artifact_writer.ts
diff --git a/packages/migrations/src/utils/constants.ts b/packages/migrations/src/utils/constants.ts
new file mode 100644
index 000000000..068122e28
--- /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: '0x08e937fa',
+ NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
+ RPC_URL: 'http://localhost:8545',
+ 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..7a217b1e0
--- /dev/null
+++ b/packages/migrations/src/utils/provider_factory.ts
@@ -0,0 +1,33 @@
+import { LedgerEthereumClient, LedgerSubprovider } 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 ProviderEngine = require('web3-provider-engine');
+import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
+
+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 ProviderEngine();
+ const ledgerWalletConfigs = {
+ networkId: constants.KOVAN_NETWORK_ID,
+ ledgerEthereumClientFactoryAsync: ledgerEthereumNodeJsClientFactoryAsync,
+ };
+ const ledgerSubprovider = new LedgerSubprovider(ledgerWalletConfigs);
+ provider.addProvider(ledgerSubprovider);
+ provider.addProvider(
+ new RpcSubprovider({
+ rpcUrl: constants.RPC_URL,
+ }),
+ );
+ provider.start();
+ return provider;
+ },
+};