From 3a7bb97ad1182eb9c718797bda8dca5eb5d7f9cd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 3 Oct 2018 16:21:17 -0700 Subject: Remove artifacts from migrations package and update contract-wrappers accordingly --- packages/migrations/src/1.0.0/artifacts.ts | 21 --- packages/migrations/src/1.0.0/migration.ts | 142 ----------------- packages/migrations/src/2.0.0/artifacts.ts | 25 --- packages/migrations/src/2.0.0/migration.ts | 150 ------------------ packages/migrations/src/index.ts | 3 +- packages/migrations/src/migrate.ts | 39 +---- packages/migrations/src/migration.ts | 192 +++++++++++++++++++++++ packages/migrations/src/utils/artifact_writer.ts | 26 --- 8 files changed, 201 insertions(+), 397 deletions(-) delete mode 100644 packages/migrations/src/1.0.0/artifacts.ts delete mode 100644 packages/migrations/src/1.0.0/migration.ts delete mode 100644 packages/migrations/src/2.0.0/artifacts.ts delete mode 100644 packages/migrations/src/2.0.0/migration.ts create mode 100644 packages/migrations/src/migration.ts delete mode 100644 packages/migrations/src/utils/artifact_writer.ts (limited to 'packages/migrations/src') diff --git a/packages/migrations/src/1.0.0/artifacts.ts b/packages/migrations/src/1.0.0/artifacts.ts deleted file mode 100644 index f5226e174..000000000 --- a/packages/migrations/src/1.0.0/artifacts.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -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, - DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - EtherToken: (EtherToken as any) as ContractArtifact, - TokenRegistry: (TokenRegistry as any) as ContractArtifact, - TokenTransferProxy: (TokenTransferProxy as any) as ContractArtifact, - MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, - MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, -}; diff --git a/packages/migrations/src/1.0.0/migration.ts b/packages/migrations/src/1.0.0/migration.ts deleted file mode 100644 index 0a3c25ae1..000000000 --- a/packages/migrations/src/1.0.0/migration.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { BigNumber, NULL_BYTES } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Provider, TxData } from 'ethereum-types'; - -import { ArtifactWriter } from '../utils/artifact_writer'; -import { erc20TokenInfo } from '../utils/token_info'; - -import { artifacts } from './artifacts'; -import { DummyERC20TokenContract } from './contract_wrappers/dummy_erc20_token'; -import { Exchange_v1Contract } from './contract_wrappers/exchange_v1'; -import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; -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'; - -/** - * 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 runV1MigrationsAsync = async (provider: Provider, artifactsDir: string, txDefaults: Partial) => { - const web3Wrapper = new Web3Wrapper(provider); - const networkId = await web3Wrapper.getNetworkIdAsync(); - const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); - const tokenTransferProxy = await TokenTransferProxy_v1Contract.deployFrom0xArtifactAsync( - artifacts.TokenTransferProxy, - provider, - txDefaults, - ); - artifactsWriter.saveArtifact(tokenTransferProxy); - const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); - artifactsWriter.saveArtifact(zrxToken); - - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); - artifactsWriter.saveArtifact(etherToken); - const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync( - artifacts.TokenRegistry, - provider, - txDefaults, - ); - artifactsWriter.saveArtifact(tokenReg); - - const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); - const owners = [accounts[0], accounts[1]]; - const confirmationsRequired = new BigNumber(2); - const secondsRequired = new BigNumber(0); - const exchange = await Exchange_v1Contract.deployFrom0xArtifactAsync( - artifacts.Exchange, - provider, - txDefaults, - zrxToken.address, - tokenTransferProxy.address, - ); - artifactsWriter.saveArtifact(exchange); - const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( - artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, - provider, - txDefaults, - owners, - confirmationsRequired, - secondsRequired, - tokenTransferProxy.address, - ); - artifactsWriter.saveArtifact(multiSig); - - const owner = accounts[0]; - - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: owner }), - ); - const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync( - zrxToken.address, - erc20TokenInfo[0].name, - erc20TokenInfo[0].symbol, - erc20TokenInfo[0].decimals, - erc20TokenInfo[0].ipfsHash, - erc20TokenInfo[0].swarmHash, - { from: owner }, - ); - const decimals = 18; - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - zrxToken.address, - '0x Protocol Token', - 'ZRX', - decimals, - NULL_BYTES, - NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - etherToken.address, - 'Ether Token', - 'WETH', - decimals, - NULL_BYTES, - NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - for (const token of erc20TokenInfo) { - const totalSupply = new BigNumber(100000000000000000000); - const dummyToken = await DummyERC20TokenContract.deployFrom0xArtifactAsync( - artifacts.DummyERC20Token, - provider, - txDefaults, - token.name, - token.symbol, - token.decimals, - totalSupply, - ); - await web3Wrapper.awaitTransactionSuccessAsync( - await tokenReg.addToken.sendTransactionAsync( - dummyToken.address, - token.name, - token.symbol, - token.decimals, - token.ipfsHash, - token.swarmHash, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ); - } -}; diff --git a/packages/migrations/src/2.0.0/artifacts.ts b/packages/migrations/src/2.0.0/artifacts.ts deleted file mode 100644 index e96c555d6..000000000 --- a/packages/migrations/src/2.0.0/artifacts.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -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 ERC721Proxy from '../../artifacts/2.0.0/ERC721Proxy.json'; -import * as Exchange from '../../artifacts/2.0.0/Exchange.json'; -import * as Forwarder from '../../artifacts/2.0.0/Forwarder.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 = { - ZRX: (ZRX as any) as ContractArtifact, - DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, - DummyERC721Token: (DummyERC721Token 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, - ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, - Forwarder: (Forwarder as any) as ContractArtifact, - OrderValidator: (OrderValidator as any) as ContractArtifact, -}; diff --git a/packages/migrations/src/2.0.0/migration.ts b/packages/migrations/src/2.0.0/migration.ts deleted file mode 100644 index 1c30fb9ec..000000000 --- a/packages/migrations/src/2.0.0/migration.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { assetDataUtils } from '@0xproject/order-utils'; -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import { Provider, TxData } from 'ethereum-types'; - -import { ArtifactWriter } from '../utils/artifact_writer'; -import { erc20TokenInfo, erc721TokenInfo } from '../utils/token_info'; - -import { artifacts } from './artifacts'; -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 { 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'; -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) => { - 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 zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); - const exchange = await ExchangeContract.deployFrom0xArtifactAsync(artifacts.Exchange, provider, txDefaults); - 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]; - - // AssetProxyOwner - const assetProxyOwner = await AssetProxyOwnerContract.deployFrom0xArtifactAsync( - artifacts.AssetProxyOwner, - provider, - txDefaults, - owners, - [erc20proxy.address, erc721proxy.address], - confirmationsRequired, - secondsRequired, - ); - artifactsWriter.saveArtifact(assetProxyOwner); - - await web3Wrapper.awaitTransactionSuccessAsync( - await erc20proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { - from: owner, - }), - ); - 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( - artifacts.Forwarder, - provider, - txDefaults, - exchange.address, - assetDataUtils.encodeERC20AssetData(zrxToken.address), - assetDataUtils.encodeERC20AssetData(etherToken.address), - ); - artifactsWriter.saveArtifact(forwarder); - - // OrderValidator - const orderValidator = await OrderValidatorContract.deployFrom0xArtifactAsync( - artifacts.OrderValidator, - provider, - txDefaults, - exchange.address, - zrxAssetData, - ); - artifactsWriter.saveArtifact(orderValidator); -}; diff --git a/packages/migrations/src/index.ts b/packages/migrations/src/index.ts index 5354b3501..fc68f5f65 100644 --- a/packages/migrations/src/index.ts +++ b/packages/migrations/src/index.ts @@ -1,2 +1 @@ -export { runV1MigrationsAsync } from './1.0.0/migration'; -export { runV2MigrationsAsync } from './2.0.0/migration'; +export { runMigrationsAsync, getContractAddresses } from './migration'; diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 338832feb..27f36ba34 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -2,43 +2,20 @@ import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { logUtils } from '@0xproject/utils'; import { Provider } from 'ethereum-types'; -import * as yargs from 'yargs'; -import { runV1MigrationsAsync } from './1.0.0/migration'; -import { runV2MigrationsAsync } from './2.0.0/migration'; - -enum ContractVersions { - V1 = '1.0.0', - V2 = '2.0.0', -} -const args = yargs.argv; +import { runMigrationsAsync } from './migration'; (async () => { - const contractsVersion = args.contractsVersion; - const artifactsDir = `artifacts/${contractsVersion}`; 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; - default: - throw new Error(`Unsupported contract version: ${contractsVersion}`); - } + + providerConfigs = { shouldUseInProcessGanache: false }; + provider = web3Factory.getRpcProvider(providerConfigs); + txDefaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + }; + await runMigrationsAsync(provider, txDefaults); process.exit(0); })().catch(err => { logUtils.log(err); diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts new file mode 100644 index 000000000..a22c34a23 --- /dev/null +++ b/packages/migrations/src/migration.ts @@ -0,0 +1,192 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; +import { assetDataUtils } from '@0xproject/order-utils'; +import { ContractAddresses } from '@0xproject/types'; +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TxData } from 'ethereum-types'; +import * as _ from 'lodash'; + +import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info'; + +interface MigrationsResult { + erc20Proxy: wrappers.ERC20ProxyContract; + erc721Proxy: wrappers.ERC721ProxyContract; + zrxToken: wrappers.ZRXTokenContract; + etherToken: wrappers.WETH9Contract; + exchange: wrappers.ExchangeContract; + assetProxyOwner: wrappers.AssetProxyOwnerContract; + forwarder: wrappers.ForwarderContract; + orderValidator: wrappers.OrderValidatorContract; +} + +let _cachedMigrationsResult: MigrationsResult | undefined; +let _cachedContractAddresses: ContractAddresses | undefined; + +/** + * 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 txDefaults Default transaction values to use when deploying contracts. + */ +export async function runMigrationsAsync(provider: Provider, txDefaults: Partial): Promise { + const web3Wrapper = new Web3Wrapper(provider); + + // Proxies + const erc20Proxy = await wrappers.ERC20ProxyContract.deployFrom0xArtifactAsync( + artifacts.ERC20Proxy, + provider, + txDefaults, + ); + const erc721Proxy = await wrappers.ERC721ProxyContract.deployFrom0xArtifactAsync( + artifacts.ERC721Proxy, + provider, + txDefaults, + ); + + // ZRX + const zrxToken = await wrappers.ZRXTokenContract.deployFrom0xArtifactAsync( + artifacts.ZRXToken, + provider, + txDefaults, + ); + + // Ether token + const etherToken = await wrappers.WETH9Contract.deployFrom0xArtifactAsync(artifacts.WETH9, provider, txDefaults); + + // Exchange + const zrxAssetData = assetDataUtils.encodeERC20AssetData(zrxToken.address); + const exchange = await wrappers.ExchangeContract.deployFrom0xArtifactAsync( + artifacts.Exchange, + provider, + txDefaults, + zrxAssetData, + ); + + // 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]; + + // AssetProxyOwner + const assetProxyOwner = await wrappers.AssetProxyOwnerContract.deployFrom0xArtifactAsync( + artifacts.AssetProxyOwner, + provider, + txDefaults, + owners, + [erc20Proxy.address, erc721Proxy.address], + confirmationsRequired, + secondsRequired, + ); + + await web3Wrapper.awaitTransactionSuccessAsync( + await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { + from: owner, + }), + ); + 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 wrappers.DummyERC20TokenContract.deployFrom0xArtifactAsync( + artifacts.DummyERC20Token, + provider, + txDefaults, + token.name, + token.symbol, + token.decimals, + totalSupply, + ); + } + + // ERC721 + // tslint:disable-next-line:no-unused-variable + const cryptoKittieToken = await wrappers.DummyERC721TokenContract.deployFrom0xArtifactAsync( + artifacts.DummyERC721Token, + provider, + txDefaults, + erc721TokenInfo[0].name, + erc721TokenInfo[0].symbol, + ); + + // Forwarder + const forwarder = await wrappers.ForwarderContract.deployFrom0xArtifactAsync( + artifacts.Forwarder, + provider, + txDefaults, + exchange.address, + assetDataUtils.encodeERC20AssetData(zrxToken.address), + assetDataUtils.encodeERC20AssetData(etherToken.address), + ); + + // OrderValidator + const orderValidator = await wrappers.OrderValidatorContract.deployFrom0xArtifactAsync( + artifacts.OrderValidator, + provider, + txDefaults, + exchange.address, + zrxAssetData, + ); + + const migrationsResult = { + erc20Proxy, + erc721Proxy, + zrxToken, + etherToken, + exchange, + assetProxyOwner, + forwarder, + orderValidator, + }; + _cachedMigrationsResult = migrationsResult; + return migrationsResult; +} + +export function getContractAddresses(): ContractAddresses { + if (!_.isUndefined(_cachedContractAddresses)) { + return _cachedContractAddresses; + } + if (_.isUndefined(_cachedMigrationsResult)) { + throw new Error( + 'Migrations have not been run! You need to call runMigrationsAsync before getContractAddresses', + ); + } + const contractAddresses = { + erc20Proxy: _cachedMigrationsResult.erc20Proxy.address, + erc721Proxy: _cachedMigrationsResult.erc721Proxy.address, + zrxToken: _cachedMigrationsResult.zrxToken.address, + etherToken: _cachedMigrationsResult.etherToken.address, + exchange: _cachedMigrationsResult.exchange.address, + assetProxyOwner: _cachedMigrationsResult.assetProxyOwner.address, + forwarder: _cachedMigrationsResult.forwarder.address, + orderValidator: _cachedMigrationsResult.orderValidator.address, + }; + _cachedContractAddresses = contractAddresses; + return contractAddresses; +} diff --git a/packages/migrations/src/utils/artifact_writer.ts b/packages/migrations/src/utils/artifact_writer.ts deleted file mode 100644 index ea9c7952d..000000000 --- a/packages/migrations/src/utils/artifact_writer.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { BaseContract } from '@0xproject/base-contract'; -import { ContractArtifact } from 'ethereum-types'; -import * as fs from 'fs'; -import * as path from 'path'; - -export class ArtifactWriter { - private readonly _artifactsDir: string; - private readonly _networkId: number; - constructor(artifactsDir: string, networkId: number) { - this._artifactsDir = artifactsDir; - this._networkId = networkId; - } - // This updates the artifact file but does not update the `artifacts` module above. It will not - // contain the saved artifact changes. - public saveArtifact(contract: BaseContract): void { - const contractName = contract.contractName; - const artifactFile = path.join(this._artifactsDir, `${contractName}.json`); - const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFile).toString()); - artifact.networks[this._networkId] = { - address: contract.address, - links: {}, - constructorArgs: JSON.stringify(contract.constructorArgs), - }; - fs.writeFileSync(artifactFile, JSON.stringify(artifact, null, '\t')); - } -} -- cgit v1.2.3