diff options
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/deploy/migrations/migrate.ts | 104 | ||||
-rw-r--r-- | packages/contracts/package.json | 1 | ||||
-rw-r--r-- | packages/contracts/test/ts/multi_sig_with_time_lock.ts | 6 | ||||
-rw-r--r-- | packages/contracts/util/balances.ts | 2 | ||||
-rw-r--r-- | packages/contracts/util/bignumber_config.ts | 11 | ||||
-rw-r--r-- | packages/contracts/util/rpc.ts | 43 |
6 files changed, 53 insertions, 114 deletions
diff --git a/packages/contracts/deploy/migrations/migrate.ts b/packages/contracts/deploy/migrations/migrate.ts index c3d38875e..f40b7c4ba 100644 --- a/packages/contracts/deploy/migrations/migrate.ts +++ b/packages/contracts/deploy/migrations/migrate.ts @@ -11,49 +11,34 @@ import {tokenInfo} from './config/token_info'; export const migrator = { /** * Custom migrations should be defined in this function. This will be called with the CLI 'migrate' command. + * Some operations might be completed in parallel, but we don't do that on purpose. + * That way the addresses are deterministic. * @param deployer Deployer instance. */ async runMigrationsAsync(deployer: Deployer): Promise<void> { const web3Wrapper: Web3Wrapper = deployer.web3Wrapper; const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); - const independentContracts: Web3.ContractInstance[] = await Promise.all([ - deployer.deployAndSaveAsync('TokenTransferProxy'), - deployer.deployAndSaveAsync('ZRXToken'), - deployer.deployAndSaveAsync('EtherToken'), - deployer.deployAndSaveAsync('TokenRegistry'), - ]); - const [tokenTransferProxy, zrxToken, etherToken, tokenReg] = independentContracts; + const tokenTransferProxy = await deployer.deployAndSaveAsync('TokenTransferProxy'); + const zrxToken = await deployer.deployAndSaveAsync('ZRXToken'); + const etherToken = await deployer.deployAndSaveAsync('EtherToken'); + const tokenReg = await deployer.deployAndSaveAsync('TokenRegistry'); const exchangeArgs = [zrxToken.address, tokenTransferProxy.address]; const owners = [accounts[0], accounts[1]]; const confirmationsRequired = new BigNumber(2); const secondsRequired = new BigNumber(0); const multiSigArgs = [owners, confirmationsRequired, secondsRequired, tokenTransferProxy.address]; - const dependentContracts: Web3.ContractInstance[] = await Promise.all([ - deployer.deployAndSaveAsync('Exchange', exchangeArgs), - deployer.deployAndSaveAsync('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', multiSigArgs), - ]); - const [exchange, multiSig] = dependentContracts; + const exchange = await deployer.deployAndSaveAsync('Exchange', exchangeArgs); + const multiSig = await deployer.deployAndSaveAsync( + 'MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', multiSigArgs, + ); const owner = accounts[0]; await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {from: owner}); await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, {from: owner}); - - const tokensToRegister: Web3.ContractInstance[] = await Promise.all( - _.map(tokenInfo, async (token: Token): Promise<Web3.ContractInstance> => { - const totalSupply = new BigNumber(0); - const args = [ - token.name, - token.symbol, - token.decimals, - totalSupply, - ]; - return deployer.deployAsync('DummyToken', args); - }), - ); const addTokenGasEstimate = await tokenReg.addToken.estimateGasAsync( - tokensToRegister[0].address, + zrxToken.address, tokenInfo[0].name, tokenInfo[0].symbol, tokenInfo[0].decimals, @@ -61,35 +46,41 @@ export const migrator = { tokenInfo[0].swarmHash, {from: owner}, ); - const addTokenPromises = [ - tokenReg.addToken.sendTransactionAsync( - zrxToken.address, - '0x Protocol Token', - 'ZRX', - 18, - constants.NULL_BYTES, - constants.NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - tokenReg.addToken.sendTransactionAsync( - etherToken.address, - 'Ether Token', - 'WETH', - 18, - constants.NULL_BYTES, - constants.NULL_BYTES, - { - from: owner, - gas: addTokenGasEstimate, - }, - ), - ]; - const addDummyTokenPromises = _.map(tokenInfo, async (token: Token, i: number): Promise<void> => { - return tokenReg.addToken.sendTransactionAsync( - tokensToRegister[i].address, + await tokenReg.addToken.sendTransactionAsync( + zrxToken.address, + '0x Protocol Token', + 'ZRX', + 18, + constants.NULL_BYTES, + constants.NULL_BYTES, + { + from: owner, + gas: addTokenGasEstimate, + }, + ); + await tokenReg.addToken.sendTransactionAsync( + etherToken.address, + 'Ether Token', + 'WETH', + 18, + constants.NULL_BYTES, + constants.NULL_BYTES, + { + from: owner, + gas: addTokenGasEstimate, + }, + ); + for (const token of tokenInfo) { + const totalSupply = new BigNumber(0); + const args = [ + token.name, + token.symbol, + token.decimals, + totalSupply, + ]; + const dummyToken = await deployer.deployAsync('DummyToken', args); + await tokenReg.addToken.sendTransactionAsync( + dummyToken.address, token.name, token.symbol, token.decimals, @@ -100,7 +91,6 @@ export const migrator = { gas: addTokenGasEstimate, }, ); - }); - await Promise.all([...addDummyTokenPromises, ...addTokenPromises]); + } }, }; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 93f28f990..c8ccd0a3a 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -29,6 +29,7 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/contracts/README.md", "devDependencies": { + "@0xproject/dev-utils": "^0.0.1", "@0xproject/tslint-config": "^0.2.1", "@0xproject/types": "^0.1.0", "@types/bluebird": "^3.5.3", diff --git a/packages/contracts/test/ts/multi_sig_with_time_lock.ts b/packages/contracts/test/ts/multi_sig_with_time_lock.ts index 84eb21b4a..d92c5967f 100644 --- a/packages/contracts/test/ts/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/ts/multi_sig_with_time_lock.ts @@ -1,13 +1,14 @@ +import {RPC} from '@0xproject/dev-utils'; import {promisify} from '@0xproject/utils'; import {BigNumber} from 'bignumber.js'; import * as chai from 'chai'; import Web3 = require('web3'); import * as multiSigWalletJSON from '../../build/contracts/MultiSigWalletWithTimeLock.json'; +import * as truffleConf from '../../truffle.js'; import {Artifacts} from '../../util/artifacts'; import {constants} from '../../util/constants'; import {MultiSigWrapper} from '../../util/multi_sig_wrapper'; -import {RPC} from '../../util/rpc'; import {ContractInstance} from '../../util/types'; import {chaiSetup} from './utils/chai_setup'; @@ -38,7 +39,8 @@ contract('MultiSigWalletWithTimeLock', (accounts: string[]) => { const secondsTimeLocked = await multiSig.secondsTimeLocked.call(); initialSecondsTimeLocked = secondsTimeLocked.toNumber(); - rpc = new RPC(); + const rpcUrl = `http://${truffleConf.networks.development.host}:${truffleConf.networks.development.port}`; + rpc = new RPC(rpcUrl); }); describe('changeTimeLock', () => { diff --git a/packages/contracts/util/balances.ts b/packages/contracts/util/balances.ts index fce15db6d..7f5e843a5 100644 --- a/packages/contracts/util/balances.ts +++ b/packages/contracts/util/balances.ts @@ -1,7 +1,7 @@ +import {bigNumberConfigs} from '@0xproject/utils'; import {BigNumber} from 'bignumber.js'; import * as _ from 'lodash'; -import {bigNumberConfigs} from './bignumber_config'; import {BalancesByOwner, ContractInstance} from './types'; bigNumberConfigs.configure(); diff --git a/packages/contracts/util/bignumber_config.ts b/packages/contracts/util/bignumber_config.ts deleted file mode 100644 index 38f59d341..000000000 --- a/packages/contracts/util/bignumber_config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {BigNumber} from 'bignumber.js'; - -export const bigNumberConfigs = { - configure() { - // By default BigNumber's `toString` method converts to exponential notation if the value has - // more then 20 digits. We want to avoid this behavior, so we set EXPONENTIAL_AT to a high number - BigNumber.config({ - EXPONENTIAL_AT: 1000, - }); - }, -}; diff --git a/packages/contracts/util/rpc.ts b/packages/contracts/util/rpc.ts deleted file mode 100644 index 023602bd6..000000000 --- a/packages/contracts/util/rpc.ts +++ /dev/null @@ -1,43 +0,0 @@ -import 'isomorphic-fetch'; - -import * as truffleConf from '../truffle.js'; - -export class RPC { - private host: string; - private port: number; - private id: number; - constructor() { - this.host = truffleConf.networks.development.host; - this.port = truffleConf.networks.development.port; - this.id = 0; - } - public async increaseTimeAsync(time: number) { - const method = 'evm_increaseTime'; - const params = [time]; - const payload = this.toPayload(method, params); - return this.sendAsync(payload); - } - public async mineBlockAsync() { - const method = 'evm_mine'; - const payload = this.toPayload(method); - return this.sendAsync(payload); - } - private toPayload(method: string, params: any[] = []) { - const payload = JSON.stringify({ - id: this.id, - method, - params, - }); - this.id++; - return payload; - } - private async sendAsync(payload: string): Promise<any> { - const opts = { - method: 'POST', - body: payload, - }; - const response = await fetch(`http://${this.host}:${this.port}`, opts); - const responsePayload = await response.json(); - return responsePayload; - } -} |