Add Kovan migrations
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -87,8 +87,9 @@ packages/metacoin/src/contract_wrappers
|
||||
packages/fill-scenarios/src/generated_contract_wrappers/
|
||||
packages/order-watcher/src/generated_contract_wrappers/
|
||||
packages/order-utils/src/generated_contract_wrappers/
|
||||
packages/migrations/src/v1/contract_wrappers
|
||||
packages/migrations/src/v2/contract_wrappers
|
||||
packages/migrations/src/1.0.0/contract_wrappers
|
||||
packages/migrations/src/2.0.0/contract_wrappers
|
||||
packages/migrations/src/2.0.0-beta-kovan/contract_wrappers
|
||||
|
||||
# solc-bin in sol-compiler
|
||||
packages/sol-compiler/solc_bin/
|
||||
|
||||
@@ -13,25 +13,35 @@
|
||||
"pre_build": "run-s copy_artifacts generate_contract_wrappers",
|
||||
"copy_artifacts": "copyfiles 'artifacts/**/*' ./lib",
|
||||
"clean": "shx rm -rf lib src/contract_wrappers",
|
||||
"lint": "tslint --project . --exclude **/src/v2/contract_wrappers/**/* --exclude **/src/v1/contract_wrappers/**/*",
|
||||
"lint":
|
||||
"tslint --project . --exclude **/src/v2/contract_wrappers/**/* --exclude **/src/v1/contract_wrappers/**/*",
|
||||
"migrate:v1": "run-s build compile:v1 script:migrate:v1",
|
||||
"migrate:v2": "run-s build compile:v2 script:migrate:v2",
|
||||
"migrate:v2-beta-kovan": "run-s build compile:v2-beta-kovan script:migrate:v2-beta-kovan",
|
||||
"script:migrate:v1": "node ./lib/migrate.js --contracts-version 1.0.0",
|
||||
"script:migrate:v2": "node ./lib/migrate.js --contracts-version 2.0.0",
|
||||
"script:migrate:v2-beta-kovan": "node ./lib/migrate.js --contracts-version 2.0.0-beta-kovan",
|
||||
"generate_contract_wrappers": "run-p generate_contract_wrappers:*",
|
||||
"generate_contract_wrappers:v1":
|
||||
"abi-gen --abis ${npm_package_config_abis_v1} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/v1/contract_wrappers --backend ethers",
|
||||
"abi-gen --abis ${npm_package_config_abis_v1} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/1.0.0/contract_wrappers --backend ethers",
|
||||
"generate_contract_wrappers:v2":
|
||||
"abi-gen --abis ${npm_package_config_abis_v2} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/v2/contract_wrappers --backend ethers",
|
||||
"compile:v1": "sol-compiler --artifacts-dir artifacts/1.0.0 --contracts Exchange_v1,DummyERC20Token,ZRXToken,WETH9,TokenTransferProxy_v1,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,TokenRegistry",
|
||||
"compile:v2": "sol-compiler --artifacts-dir artifacts/2.0.0 --contracts AssetProxyOwner,ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator"
|
||||
"abi-gen --abis ${npm_package_config_abis_v2} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0/contract_wrappers --backend ethers",
|
||||
"generate_contract_wrappers:v2-beta-kovan":
|
||||
"abi-gen --abis ${npm_package_config_abis_v2BetaKovan} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-kovan/contract_wrappers --backend ethers",
|
||||
"compile:v1":
|
||||
"sol-compiler --artifacts-dir artifacts/1.0.0 --contracts Exchange_v1,DummyERC20Token,ZRXToken,WETH9,TokenTransferProxy_v1,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,TokenRegistry",
|
||||
"compile:v2":
|
||||
"sol-compiler --artifacts-dir artifacts/2.0.0 --contracts ERC20Token,DummyERC20Token,ERC721Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator",
|
||||
"compile:v2-beta-kovan":
|
||||
"sol-compiler --artifacts-dir artifacts/2.0.0-beta-kovan --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange"
|
||||
},
|
||||
"config": {
|
||||
"abis": {
|
||||
"v1":
|
||||
"artifacts/1.0.0/@(DummyERC20Token|TokenTransferProxy_v1|Exchange_v1|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|WETH9).json",
|
||||
"v2":
|
||||
"artifacts/2.0.0/@(ERC20Token|DummyERC20Token|ERC721Token|DummyERC721Token|ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator).json"
|
||||
"artifacts/2.0.0/@(ERC20Token|DummyERC20Token|ERC721Token|DummyERC721Token|ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator).json",
|
||||
"v2BetaKovan": "artifacts/2.0.0-beta-kovan/@(ERC20Proxy|ERC721Proxy|Exchange|AssetProxyOwner).json"
|
||||
}
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
|
||||
13
packages/migrations/src/2.0.0-beta-kovan/artifacts.ts
Normal file
13
packages/migrations/src/2.0.0-beta-kovan/artifacts.ts
Normal file
@@ -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,
|
||||
};
|
||||
14
packages/migrations/src/2.0.0-beta-kovan/constants.ts
Normal file
14
packages/migrations/src/2.0.0-beta-kovan/constants.ts
Normal file
@@ -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',
|
||||
};
|
||||
91
packages/migrations/src/2.0.0-beta-kovan/migration.ts
Normal file
91
packages/migrations/src/2.0.0-beta-kovan/migration.ts
Normal file
@@ -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),
|
||||
);
|
||||
};
|
||||
@@ -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';
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user