Rename and update some artifact locations

This commit is contained in:
Alex Browne 2018-09-04 16:47:01 -04:00
parent 4ed84c5dc5
commit e456332da7
30 changed files with 102 additions and 287 deletions

6
.gitignore vendored
View File

@ -88,7 +88,7 @@ packages/0x.js/src/artifacts/
packages/order-utils/src/artifacts/ packages/order-utils/src/artifacts/
# unstable generated contract artifacts: # unstable generated contract artifacts:
packages/migrations/artifacts/2.0.0/ packages/migrations/artifacts/development/
# generated contract watcher # generated contract watcher
packages/0x.js/src/generated_contract_wrappers/ packages/0x.js/src/generated_contract_wrappers/
@ -99,9 +99,9 @@ packages/fill-scenarios/src/generated_contract_wrappers/
packages/order-watcher/src/generated_contract_wrappers/ packages/order-watcher/src/generated_contract_wrappers/
packages/order-utils/src/generated_contract_wrappers/ packages/order-utils/src/generated_contract_wrappers/
packages/migrations/src/1.0.0/contract_wrappers packages/migrations/src/1.0.0/contract_wrappers
packages/migrations/src/2.0.0-testnet/contract_wrappers
packages/migrations/src/2.0.0/contract_wrappers packages/migrations/src/2.0.0/contract_wrappers
packages/migrations/src/2.0.0-beta-testnet/contract_wrappers packages/migrations/src/development/contract_wrappers
packages/migrations/src/2.0.0-mainnet/contract_wrappers
# solc-bin in sol-compiler # solc-bin in sol-compiler
packages/sol-compiler/solc_bin/ packages/sol-compiler/solc_bin/

View File

@ -8,9 +8,8 @@ lib
/packages/order-watcher/src/generated_contract_wrappers/ /packages/order-watcher/src/generated_contract_wrappers/
/packages/order-utils/src/generated_contract_wrappers/ /packages/order-utils/src/generated_contract_wrappers/
/packages/migrations/src/1.0.0/contract_wrappers /packages/migrations/src/1.0.0/contract_wrappers
/packages/migrations/src/2.0.0-testnet/contract_wrappers
/packages/migrations/src/2.0.0/contract_wrappers /packages/migrations/src/2.0.0/contract_wrappers
/packages/migrations/src/2.0.0-beta-testnet/contract_wrappers
/packages/migrations/src/2.0.0-mainnet/contract_wrappers
/packages/0x.js/src/artifacts /packages/0x.js/src/artifacts
/packages/contracts/src/artifacts /packages/contracts/src/artifacts
/packages/contract-wrappers/src/artifacts /packages/contract-wrappers/src/artifacts
@ -20,8 +19,8 @@ lib
/packages/contract-wrappers/test/artifacts /packages/contract-wrappers/test/artifacts
/packages/order-watcher/test/artifacts /packages/order-watcher/test/artifacts
/packages/migrations/artifacts/1.0.0 /packages/migrations/artifacts/1.0.0
/packages/migrations/artifacts/2.0.0-testnet
/packages/migrations/artifacts/2.0.0 /packages/migrations/artifacts/2.0.0
/packages/migrations/artifacts/2.0.0-beta-testnet /packages/migrations/artifacts/development
/packages/migrations/artifacts/2.0.0-mainnet
package.json package.json
scripts/postpublish_utils.js scripts/postpublish_utils.js

View File

@ -12,7 +12,7 @@
"types": "lib/src/index.d.ts", "types": "lib/src/index.d.ts",
"scripts": { "scripts": {
"build": "yarn pre_build && tsc -b", "build": "yarn pre_build && tsc -b",
"pre_build": "run-s update_artifacts_v2_beta update_artifacts_v2 generate_contract_wrappers copy_artifacts", "pre_build": "run-s update_artifacts generate_contract_wrappers copy_artifacts",
"generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token|ZRXToken|ERC20Token|ERC721Token|WETH9|ERC20Proxy|ERC721Proxy|Forwarder|OrderValidator).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers", "generate_contract_wrappers": "abi-gen --abis 'src/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token|ZRXToken|ERC20Token|ERC721Token|WETH9|ERC20Proxy|ERC721Proxy|Forwarder|OrderValidator).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers",
"lint": "tslint --project . --exclude **/src/contract_wrappers/**/* --exclude **/lib/**/*", "lint": "tslint --project . --exclude **/src/contract_wrappers/**/* --exclude **/lib/**/*",
"test:circleci": "run-s test:coverage", "test:circleci": "run-s test:coverage",
@ -20,8 +20,7 @@
"rebuild_and_test": "run-s build test", "rebuild_and_test": "run-s build test",
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"update_artifacts_v2_beta": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json src/artifacts; done;", "update_artifacts": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;",
"update_artifacts_v2": "for i in ${npm_package_config_contracts_v2}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;",
"copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts", "copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts",
"clean": "shx rm -rf _bundles lib test_temp test/artifacts src/contract_wrappers/generated src/artifacts generated_docs", "clean": "shx rm -rf _bundles lib test_temp test/artifacts src/contract_wrappers/generated src/artifacts generated_docs",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit", "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",

View File

@ -1,5 +1,5 @@
{ {
"artifactsDir": "../migrations/artifacts/2.0.0", "artifactsDir": "../migrations/artifacts/development",
"contractsDir": "src/", "contractsDir": "src/",
"compilerSettings": { "compilerSettings": {
"optimizer": { "optimizer": {

View File

@ -7,7 +7,7 @@
"scripts": { "scripts": {
"build": "yarn pre_build && tsc -b", "build": "yarn pre_build && tsc -b",
"pre_build": "run-s update_artifacts generate_contract_wrappers", "pre_build": "run-s update_artifacts generate_contract_wrappers",
"update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json lib/artifacts; done;", "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json lib/artifacts; done;",
"generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", "generate_contract_wrappers": "abi-gen --abis 'lib/artifacts/@(Exchange|DummyERC20Token|DummyERC721Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "copy_monorepo_scripts": "copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts",
"clean": "shx rm -rf lib src/generated_contract_wrappers", "clean": "shx rm -rf lib src/generated_contract_wrappers",

View File

@ -11,7 +11,7 @@
"build": "yarn pre_build && tsc -b", "build": "yarn pre_build && tsc -b",
"pre_build": "run-s compile:v2 copy_artifacts generate_contract_wrappers", "pre_build": "run-s compile:v2 copy_artifacts generate_contract_wrappers",
"copy_artifacts": "copyfiles 'artifacts/**/*' ./lib", "copy_artifacts": "copyfiles 'artifacts/**/*' ./lib",
"clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0/contract_wrappers src/2.0.0-beta-testnet/contract_wrappers src/2.0.0-mainnet/contract_wrappers artifacts/2.0.0", "clean": "shx rm -rf lib src/1.0.0/contract_wrappers src/2.0.0-testnet/contract_wrappers src/2.0.0/contract_wrappers src/development/contract_wrappers artifacts/development",
"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:v1": "run-s build compile:v1 script:migrate:v1",
"migrate:v2": "run-s build compile:v2 script:migrate:v2", "migrate:v2": "run-s build compile:v2 script:migrate:v2",
@ -27,16 +27,13 @@
"generate_contract_wrappers:v2-beta-testnet": "abi-gen --abis ${npm_package_config_abis_v2BetaTestnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-testnet/contract_wrappers --backend ethers", "generate_contract_wrappers:v2-beta-testnet": "abi-gen --abis ${npm_package_config_abis_v2BetaTestnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-beta-testnet/contract_wrappers --backend ethers",
"generate_contract_wrappers:v2-mainnet": "abi-gen --abis ${npm_package_config_abis_v2Mainnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-mainnet/contract_wrappers --backend ethers", "generate_contract_wrappers:v2-mainnet": "abi-gen --abis ${npm_package_config_abis_v2Mainnet} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/2.0.0-mainnet/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: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,Forwarder,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,ZRXToken,WETH9,IWallet,IValidator,OrderValidator",
"compile:v2-beta-testnet": "sol-compiler --artifacts-dir artifacts/2.0.0-beta-testnet --contracts AssetProxyOwner,DummyERC20Token,DummyERC721Token,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,IWallet,IValidator,ERC20Token,ERC721Token,OrderValidator,ZRXToken",
"compile:v2-mainnet": "sol-compiler --artifacts-dir artifacts/2.0.0-mainnet --contracts AssetProxyOwner,ERC20Proxy,ERC721Proxy,Exchange,Forwarder,OrderValidator"
}, },
"config": { "config": {
"abis": { "abis": {
"v1": "artifacts/1.0.0/@(DummyERC20Token|TokenTransferProxy_v1|Exchange_v1|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|WETH9).json", "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|Forwarder|AssetProxyOwner|ZRXToken|WETH9|IWallet|IValidator|OrderValidator).json", "v2Testnet": "artifacts/2.0.0-testnet/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json",
"v2BetaTestnet": "artifacts/2.0.0-beta-testnet/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json", "v2": "artifacts/2.0.0/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json",
"v2Mainnet": "artifacts/2.0.0-mainnet/@(AssetProxyOwner|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|OrderValidator).json" "development": "artifacts/development/@(DummyERC721Token|DummyERC20Token|ERC20Token|ERC721Token|ERC20Proxy|ERC721Proxy|Exchange|Forwarder|AssetProxyOwner|IWallet|IValidator|OrderValidator|ZRXToken).json"
} }
}, },
"license": "Apache-2.0", "license": "Apache-2.0",

View File

@ -1,23 +0,0 @@
import { ContractArtifact } from 'ethereum-types';
import * as AssetProxyOwner from '../../artifacts/2.0.0-beta-testnet/AssetProxyOwner.json';
import * as DummyERC20Token from '../../artifacts/2.0.0-beta-testnet/DummyERC20Token.json';
import * as DummyERC721Token from '../../artifacts/2.0.0-beta-testnet/DummyERC721Token.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';
import * as Forwarder from '../../artifacts/2.0.0-beta-testnet/Forwarder.json';
import * as OrderValidator from '../../artifacts/2.0.0-beta-testnet/OrderValidator.json';
import * as ZRXToken from '../../artifacts/2.0.0-beta-testnet/ZRXToken.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,
DummyERC721Token: (DummyERC721Token as any) as ContractArtifact,
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
ZRX: (ZRXToken as any) as ContractArtifact,
};

View File

@ -1,17 +0,0 @@
import { ContractArtifact } from 'ethereum-types';
import * as AssetProxyOwner from '../../artifacts/2.0.0-mainnet/AssetProxyOwner.json';
import * as ERC20Proxy from '../../artifacts/2.0.0-mainnet/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/2.0.0-mainnet/ERC721Proxy.json';
import * as Exchange from '../../artifacts/2.0.0-mainnet/Exchange.json';
import * as Forwarder from '../../artifacts/2.0.0-mainnet/Forwarder.json';
import * as OrderValidator from '../../artifacts/2.0.0-mainnet/OrderValidator.json';
export const artifacts = {
AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
};

View File

@ -1,122 +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 { artifacts } from './artifacts';
import { constants } from './constants';
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';
import { ForwarderContract } from './contract_wrappers/forwarder';
import { OrderValidatorContract } from './contract_wrappers/order_validator';
/**
* Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-mainnet' 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 runV2MainnetMigrationsAsync = 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
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 assetProxies = [erc20proxy.address, erc721proxy.address];
const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync(
artifacts.AssetProxyOwner,
provider,
txDefaults,
constants.ASSET_PROXY_OWNER_OWNERS,
assetProxies,
constants.ASSET_PROXY_OWNER_REQUIRED_CONFIRMATIONS,
constants.ASSET_PROXY_OWNER_SECONDS_TIMELOCKED,
);
artifactsWriter.saveArtifact(assetProxyOwner);
// Deploy Forwarder
const zrxAssetData = assetDataUtils.encodeERC20AssetData(constants.ZRX_ADDRESS);
const wethAssetData = assetDataUtils.encodeERC20AssetData(constants.WETH_ADDRESS);
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder,
provider,
txDefaults,
exchange.address,
zrxAssetData,
wethAssetData,
);
artifactsWriter.saveArtifact(forwarder);
// Deploy OrderValidator
const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
artifacts.OrderValidator,
provider,
txDefaults,
exchange.address,
zrxAssetData,
);
artifactsWriter.saveArtifact(orderValidator);
// 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);
};

View File

@ -0,0 +1,23 @@
import { ContractArtifact } from 'ethereum-types';
import * as AssetProxyOwner from '../../artifacts/2.0.0-testnet/AssetProxyOwner.json';
import * as DummyERC20Token from '../../artifacts/2.0.0-testnet/DummyERC20Token.json';
import * as DummyERC721Token from '../../artifacts/2.0.0-testnet/DummyERC721Token.json';
import * as ERC20Proxy from '../../artifacts/2.0.0-testnet/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/2.0.0-testnet/ERC721Proxy.json';
import * as Exchange from '../../artifacts/2.0.0-testnet/Exchange.json';
import * as Forwarder from '../../artifacts/2.0.0-testnet/Forwarder.json';
import * as OrderValidator from '../../artifacts/2.0.0-testnet/OrderValidator.json';
import * as ZRXToken from '../../artifacts/2.0.0-testnet/ZRXToken.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,
DummyERC721Token: (DummyERC721Token as any) as ContractArtifact,
DummyERC20Token: (DummyERC20Token as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact,
ZRX: (ZRXToken as any) as ContractArtifact,
};

View File

@ -1,25 +1,17 @@
import { ContractArtifact } from 'ethereum-types'; import { ContractArtifact } from 'ethereum-types';
import * as AssetProxyOwner from '../../artifacts/2.0.0/AssetProxyOwner.json'; 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 ERC20Proxy from '../../artifacts/2.0.0/ERC20Proxy.json';
import * as ERC721Proxy from '../../artifacts/2.0.0/ERC721Proxy.json'; import * as ERC721Proxy from '../../artifacts/2.0.0/ERC721Proxy.json';
import * as Exchange from '../../artifacts/2.0.0/Exchange.json'; import * as Exchange from '../../artifacts/2.0.0/Exchange.json';
import * as Forwarder from '../../artifacts/2.0.0/Forwarder.json'; import * as Forwarder from '../../artifacts/2.0.0/Forwarder.json';
import * as OrderValidator from '../../artifacts/2.0.0/OrderValidator.json'; import * as OrderValidator from '../../artifacts/2.0.0/OrderValidator.json';
import * as WETH9 from '../../artifacts/2.0.0/WETH9.json';
import * as ZRX from '../../artifacts/2.0.0/ZRXToken.json';
export const artifacts = { 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, AssetProxyOwner: (AssetProxyOwner as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact,
WETH9: (WETH9 as any) as ContractArtifact,
ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, ERC20Proxy: (ERC20Proxy as any) as ContractArtifact,
ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, ERC721Proxy: (ERC721Proxy as any) as ContractArtifact,
Exchange: (Exchange as any) as ContractArtifact,
Forwarder: (Forwarder as any) as ContractArtifact, Forwarder: (Forwarder as any) as ContractArtifact,
OrderValidator: (OrderValidator as any) as ContractArtifact, OrderValidator: (OrderValidator as any) as ContractArtifact,
}; };

View File

@ -1,37 +1,37 @@
import { assetDataUtils } from '@0xproject/order-utils'; import { assetDataUtils } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils'; import { logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider, TxData } from 'ethereum-types'; import { Provider, TxData } from 'ethereum-types';
import { ArtifactWriter } from '../utils/artifact_writer'; import { ArtifactWriter } from '../utils/artifact_writer';
import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info';
import { artifacts } from './artifacts'; import { artifacts } from './artifacts';
import { constants } from './constants';
import { AssetProxyOwnerContract } from './contract_wrappers/asset_proxy_owner'; 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 { ERC20ProxyContract } from './contract_wrappers/erc20_proxy';
import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy'; import { ERC721ProxyContract } from './contract_wrappers/erc721_proxy';
import { ExchangeContract } from './contract_wrappers/exchange'; import { ExchangeContract } from './contract_wrappers/exchange';
import { ForwarderContract } from './contract_wrappers/forwarder'; import { ForwarderContract } from './contract_wrappers/forwarder';
import { OrderValidatorContract } from './contract_wrappers/order_validator'; import { OrderValidatorContract } from './contract_wrappers/order_validator';
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. * Custom migrations should be defined in this function. This will be called with the CLI 'migrate:v2-mainnet' command.
* Migrations could be written to run in parallel, but if you want contract addresses to be created deterministically, * 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. * the migration should be written to run synchronously.
* @param provider Web3 provider instance. * @param provider Web3 provider instance.
* @param artifactsDir The directory with compiler artifact files. * @param artifactsDir The directory with compiler artifact files.
* @param txDefaults Default transaction values to use when deploying contracts. * @param txDefaults Default transaction values to use when deploying contracts.
*/ */
export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial<TxData>) => { export const runV2MainnetMigrationsAsync = async (
provider: Provider,
artifactsDir: string,
txDefaults: Partial<TxData>,
) => {
const web3Wrapper = new Web3Wrapper(provider); const web3Wrapper = new Web3Wrapper(provider);
const networkId = await web3Wrapper.getNetworkIdAsync(); const networkId = await web3Wrapper.getNetworkIdAsync();
const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); const artifactsWriter = new ArtifactWriter(artifactsDir, networkId);
// Proxies // Deploy AssetProxies
const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults); const erc20proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(artifacts.ERC20Proxy, provider, txDefaults);
artifactsWriter.saveArtifact(erc20proxy); artifactsWriter.saveArtifact(erc20proxy);
const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync( const erc721proxy = await ERC721ProxyContract.deployFrom0xArtifactAsync(
@ -41,109 +41,49 @@ export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: str
); );
artifactsWriter.saveArtifact(erc721proxy); artifactsWriter.saveArtifact(erc721proxy);
// ZRX // Deploy Exchange
const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); const exchange = await ExchangeContract.deployFrom0xArtifactAsync(artifacts.Exchange, provider, txDefaults);
artifactsWriter.saveArtifact(zrxToken);
// Ether token
const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults);
artifactsWriter.saveArtifact(etherToken);
// Exchange
const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address);
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
artifacts.Exchange,
provider,
txDefaults,
zrxAssetData,
);
artifactsWriter.saveArtifact(exchange); artifactsWriter.saveArtifact(exchange);
// Multisigs let txHash;
const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); // Register AssetProxies in Exchange
const owners = [accounts[0], accounts[1]]; txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc20proxy.address);
const confirmationsRequired = new BigNumber(2); logUtils.log(`transactionHash: ${txHash}`);
const secondsRequired = new BigNumber(0); logUtils.log('Registering ERC20Proxy');
const owner = accounts[0]; await web3Wrapper.awaitTransactionSuccessAsync(txHash);
// AssetProxyOwner txHash = await exchange.registerAssetProxy.sendTransactionAsync(erc721proxy.address);
logUtils.log(`transactionHash: ${txHash}`);
logUtils.log('Registering ERC721Proxy');
await web3Wrapper.awaitTransactionSuccessAsync(txHash);
// Deploy AssetProxyOwner
const assetProxies = [erc20proxy.address, erc721proxy.address];
const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync(
artifacts.AssetProxyOwner, artifacts.AssetProxyOwner,
provider, provider,
txDefaults, txDefaults,
owners, constants.ASSET_PROXY_OWNER_OWNERS,
[erc20proxy.address, erc721proxy.address], assetProxies,
confirmationsRequired, constants.ASSET_PROXY_OWNER_REQUIRED_CONFIRMATIONS,
secondsRequired, constants.ASSET_PROXY_OWNER_SECONDS_TIMELOCKED,
); );
artifactsWriter.saveArtifact(assetProxyOwner); artifactsWriter.saveArtifact(assetProxyOwner);
await web3Wrapper.awaitTransactionSuccessAsync( // Deploy Forwarder
await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { const zrxAssetData = assetDataUtils.encodeERC20AssetData(constants.ZRX_ADDRESS);
from: owner, const wethAssetData = assetDataUtils.encodeERC20AssetData(constants.WETH_ADDRESS);
}),
);
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( const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
artifacts.Forwarder, artifacts.Forwarder,
provider, provider,
txDefaults, txDefaults,
exchange.address, exchange.address,
assetDataUtils.encodeERC20AssetData(zrxToken.address), zrxAssetData,
assetDataUtils.encodeERC20AssetData(etherToken.address), wethAssetData,
); );
artifactsWriter.saveArtifact(forwarder); artifactsWriter.saveArtifact(forwarder);
// OrderValidator // Deploy OrderValidator
const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync( const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync(
artifacts.OrderValidator, artifacts.OrderValidator,
provider, provider,
@ -152,4 +92,31 @@ export const runV2MigrationsAsync = async (provider: Provider, artifactsDir: str
zrxAssetData, zrxAssetData,
); );
artifactsWriter.saveArtifact(orderValidator); artifactsWriter.saveArtifact(orderValidator);
// 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);
}; };

View File

@ -9,9 +9,9 @@
"types": "lib/src/index.d.ts", "types": "lib/src/index.d.ts",
"scripts": { "scripts": {
"build": "yarn pre_build && tsc -b", "build": "yarn pre_build && tsc -b",
"pre_build": "run-s update_artifacts_v2_beta generate_contract_wrappers", "pre_build": "run-s update_artifacts generate_contract_wrappers",
"generate_contract_wrappers": "abi-gen --abis 'lib/src/artifacts/@(Exchange|IWallet|IValidator|DummyERC20Token|ERC20Proxy|ERC20Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers", "generate_contract_wrappers": "abi-gen --abis 'lib/src/artifacts/@(Exchange|IWallet|IValidator|DummyERC20Token|ERC20Proxy|ERC20Token).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/generated_contract_wrappers --backend ethers",
"update_artifacts_v2_beta": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json lib/src/artifacts; done;", "update_artifacts": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json lib/src/artifacts; done;",
"test": "yarn run_mocha", "test": "yarn run_mocha",
"rebuild_and_test": "run-s build test", "rebuild_and_test": "run-s build test",
"test:circleci": "yarn test:coverage", "test:circleci": "yarn test:coverage",

View File

@ -22,7 +22,7 @@
"test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov",
"coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info",
"copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts", "copy_artifacts": "copyfiles -u 2 './src/artifacts/**/*.json' ./lib/src/artifacts",
"update_artifacts": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0-beta-testnet/$i.json src/artifacts; done;", "update_artifacts": "for i in ${npm_package_config_contracts_v2_beta}; do copyfiles -u 4 ../migrations/artifacts/2.0.0/$i.json src/artifacts; done;",
"clean": "shx rm -rf _bundles lib test_temp test/artifacts src/generated_contract_wrappers generated_docs", "clean": "shx rm -rf _bundles lib test_temp test/artifacts src/generated_contract_wrappers generated_docs",
"run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit", "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit",
"docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES" "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"