From 3d58b38e4e8565e7ee10e4d6c9f57cd745957ab4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 7 May 2018 22:11:09 +0200 Subject: Remove deployer from metacoin and contract tests --- packages/base-contract/src/index.ts | 32 ++++++++++ packages/contract_templates/contract.handlebars | 36 +++++++++++ packages/contract_templates/partials/tx.handlebars | 4 +- packages/contracts/package.json | 2 +- packages/contracts/test/ether_token.ts | 8 ++- packages/contracts/test/exchange/core.ts | 62 +++++++++++++----- packages/contracts/test/exchange/helpers.ts | 61 ++++++++++++++---- packages/contracts/test/exchange/wrapper.ts | 58 +++++++++++------ .../contracts/test/multi_sig_with_time_lock.ts | 28 ++++---- ...i_sig_with_time_lock_except_remove_auth_addr.ts | 41 ++++++------ packages/contracts/test/token_registry.ts | 7 +- .../contracts/test/token_transfer_proxy/auth.ts | 12 ++-- .../test/token_transfer_proxy/transfer_from.ts | 24 ++++--- packages/contracts/test/tutorials/arbitrage.ts | 74 ++++++++++++++++------ .../contracts/test/unlimited_allowance_token.ts | 15 +++-- packages/contracts/test/utils/deployer.ts | 18 ------ packages/contracts/test/utils/web3_wrapper.ts | 6 +- packages/contracts/test/zrx_token.ts | 7 +- packages/contracts/util/artifacts.ts | 46 ++++++++------ packages/contracts/util/constants.ts | 10 +-- packages/deployer/README.md | 3 +- packages/deployer/src/compiler.ts | 16 ++++- packages/metacoin/src/global.d.ts | 4 ++ packages/metacoin/test/metacoin_test.ts | 11 ++-- packages/metacoin/test/utils/config.ts | 4 ++ packages/metacoin/test/utils/deployer.ts | 17 ----- .../typescript-typings/types/ethers/index.d.ts | 1 + packages/website/md/docs/deployer/installation.md | 3 +- 28 files changed, 406 insertions(+), 204 deletions(-) delete mode 100644 packages/contracts/test/utils/deployer.ts create mode 100644 packages/metacoin/src/global.d.ts delete mode 100644 packages/metacoin/test/utils/deployer.ts diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index e95b18db6..c362a882b 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -1,6 +1,7 @@ import { AbiDefinition, AbiType, + ConstructorAbi, ContractAbi, DataItem, MethodAbi, @@ -37,9 +38,40 @@ export class BaseContract { protected static _bigNumberToString(type: string, value: any): any { return _.isObject(value) && value.isBigNumber ? value.toString() : value; } + protected static _lookupConstructorAbi(abi: ContractAbi): ConstructorAbi { + const constructorAbiIfExists = _.find( + abi, + (abiDefinition: AbiDefinition) => abiDefinition.type === AbiType.Constructor, + ) as ConstructorAbi | undefined; + if (!_.isUndefined(constructorAbiIfExists)) { + return constructorAbiIfExists; + } else { + return { + type: AbiType.Constructor, + stateMutability: 'nonpayable', + payable: false, + inputs: [], + }; + } + } protected static _bnToBigNumber(type: string, value: any): any { return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; } + protected static async _applyDefaultsToDeployTxDataAsync>( + txData: T, + defaults: Partial, + estimateGasAsync?: (txData: T) => Promise, + ): Promise { + const txDataWithDefaults: TxData = { + ...defaults, + ...(txData as any), + }; + if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { + const estimatedGas = await estimateGasAsync(txData); + txDataWithDefaults.gas = estimatedGas; + } + return txDataWithDefaults; + } protected async _applyDefaultsToTxDataAsync>( txData: T, estimateGasAsync?: (txData: T) => Promise, diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index cf51dad90..a2fb29cfc 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -7,6 +7,7 @@ import { BaseContract } from '@0xproject/base-contract'; import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types'; import { BigNumber, classUtils, promisify } from '@0xproject/utils'; +import { ContractArtifact } from '@0xproject/deployer'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethers from 'ethers'; import * as _ from 'lodash'; @@ -39,6 +40,41 @@ export class {{contractName}}Contract extends BaseContract { {{> tx contractName=../contractName}} {{/this.constant}} {{/each}} + public static async deploy0xArtifactAsync( + artifact: ContractArtifact, + provider: Provider, + defaults: Partial, + {{> typed_params inputs=ctor.inputs}} + ): Promise<{{contractName}}Contract> { + const bytecode = artifact.compilerOutput.evm.bytecode.object; + const abi = artifact.compilerOutput.abi; + return {{contractName}}Contract.deployAsync(bytecode, abi, provider, defaults, {{> params inputs=ctor.inputs}}); + } + public static async deployAsync( + bytecode: string, + abi: ContractAbi, + provider: Provider, + defaults: Partial, + {{> typed_params inputs=ctor.inputs}} + ): Promise<{{contractName}}Contract> { + const constructorAbi = BaseContract._lookupConstructorAbi(abi); + [{{> params inputs=ctor.inputs}}] = BaseContract._formatABIDataItemList( + constructorAbi.inputs, + [{{> params inputs=ctor.inputs}}], + BaseContract._bigNumberToString, + ); + const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}}); + const web3Wrapper = new Web3Wrapper(provider); + const txDataWithDefaults = await BaseContract._applyDefaultsToDeployTxDataAsync( + txData, + defaults, + web3Wrapper.estimateGasAsync.bind(web3Wrapper), + ); + const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults); + const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash); + const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, defaults); + return contractInstance; + } constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial) { super(abi, address, provider, defaults); classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index 1bdf80c42..feefd3870 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -33,7 +33,7 @@ public {{this.tsName}} = { ): Promise { const self = this as any as {{contractName}}Contract; const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; - [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this)); + [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString); const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; @@ -51,7 +51,7 @@ public {{this.tsName}} = { ): string { const self = this as any as {{contractName}}Contract; const inputAbi = self._lookupAbi('{{this.functionSignature}}').inputs; - [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self)); + [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString); const abiEncodedTransactionData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index c47518f17..6c91b0ade 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -26,7 +26,7 @@ "test:circleci": "yarn test:coverage" }, "config": { - "abis": "../migrations/artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels).json" + "abis": "../migrations/artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels|WETH9|MaliciousToken).json" }, "repository": { "type": "git", diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 4023abad0..a3ede5df0 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -4,12 +4,14 @@ import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import { WETH9Contract } from '../src/contract_wrappers/generated/weth9'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -24,7 +26,7 @@ describe('EtherToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; - const etherToken = await deployer.deployAsync(ContractName.EtherToken); + const etherToken = await WETH9Contract.deploy0xArtifactAsync(artifacts.EtherToken, provider, defaults); etherTokenAddress = etherToken.address; zeroEx = new ZeroEx(provider, { gasPrice, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 689b11062..a94e6cf51 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -13,7 +13,9 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; +import { MaliciousTokenContract } from '../../src/contract_wrappers/generated/malicious_token'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; @@ -21,8 +23,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -54,25 +56,47 @@ describe('Exchange', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); maker = accounts[0]; [tokenOwner, taker, feeRecipient] = accounts; - const [repInstance, dgdInstance, zrxInstance] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + [rep, dgd, zrx] = await Promise.all([ + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider); - dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider); - zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider); - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + defaults, ); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, zrx.address, tokenTransferProxy.address, - ]); - exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); + ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); zeroEx = new ZeroEx(provider, { exchangeContractAddress: exchange.address, @@ -689,7 +713,11 @@ describe('Exchange', () => { it('should throw if getBalance or getAllowance attempts to change state and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { - const maliciousToken = await deployer.deployAsync(ContractName.MaliciousToken); + const maliciousToken = await MaliciousTokenContract.deploy0xArtifactAsync( + artifacts.MaliciousToken, + provider, + defaults, + ); await maliciousToken.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker, }); diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 8fc30c0b5..888d5ab2e 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -11,13 +11,18 @@ import { LogErrorContractEventArgs, LogFillContractEventArgs, } from '../../src/contract_wrappers/generated/exchange'; + +import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; +import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry'; +import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -35,19 +40,53 @@ describe('Exchange', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [maker, feeRecipient] = accounts; - const tokenRegistry = await deployer.deployAsync(ContractName.TokenRegistry); - const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); + const tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync( + artifacts.TokenRegistry, + provider, + defaults, + ); + const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + defaults, + ); const [rep, dgd, zrx] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + const exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, zrx.address, tokenTransferProxy.address, - ]); - const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); - await tokenTransferProxy.addAuthorizedAddress(exchange.address, { from: accounts[0] }); + ); + await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); exchangeWrapper = new ExchangeWrapper(exchange, zeroEx); const defaultOrderParams = { diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index c658dca79..6e55edabb 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -15,14 +15,15 @@ import { } from '../../src/contract_wrappers/generated/exchange'; import { TokenRegistryContract } from '../../src/contract_wrappers/generated/token_registry'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -54,27 +55,48 @@ describe('Exchange', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); tokenOwner = accounts[0]; [maker, taker, feeRecipient] = accounts; - const [repInstance, dgdInstance, zrxInstance] = await Promise.all([ - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), - deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS), + [rep, dgd, zrx] = await Promise.all([ + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), + DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ), ]); - rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider); - dgd = new DummyTokenContract(dgdInstance.abi, dgdInstance.address, provider); - zrx = new DummyTokenContract(zrxInstance.abi, zrxInstance.address, provider); - const tokenRegistryInstance = await deployer.deployAsync(ContractName.TokenRegistry); - tokenRegistry = new TokenRegistryContract(tokenRegistryInstance.abi, tokenRegistryInstance.address, provider); - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + defaults, ); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, zrx.address, tokenTransferProxy.address, - ]); - exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); + ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); exWrapper = new ExchangeWrapper(exchange, zeroEx); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 5cc744713..d3d478868 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -14,10 +14,10 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper'; import { ContractName, SubmissionContractEventArgs } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; -const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLockArtifact.compilerOutput.abi; +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; + +const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -47,15 +47,13 @@ describe('MultiSigWalletWithTimeLock', () => { describe('changeTimeLock', () => { describe('initially non-time-locked', async () => { before('deploy a wallet', async () => { - const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLock, + provider, + defaults, owners, SIGNATURES_REQUIRED, - 0, - ]); - multiSig = new MultiSigWalletWithTimeLockContract( - multiSigInstance.abi, - multiSigInstance.address, - provider, + new BigNumber(0), ); multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); @@ -144,15 +142,13 @@ describe('MultiSigWalletWithTimeLock', () => { }); describe('initially time-locked', async () => { before('deploy a wallet', async () => { - const multiSigInstance = await deployer.deployAsync(ContractName.MultiSigWalletWithTimeLock, [ + multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLock, + provider, + defaults, owners, SIGNATURES_REQUIRED, SECONDS_TIME_LOCKED, - ]); - multiSig = new MultiSigWalletWithTimeLockContract( - multiSigInstance.abi, - multiSigInstance.address, - provider, ); multiSigWrapper = new MultiSigWrapper((multiSig as any) as MultiSigWalletContract); diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index 06fa30d96..e8f970d64 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -1,6 +1,6 @@ import { LogWithDecodedArgs, ZeroEx } from '0x.js'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; -import { AbiDecoder } from '@0xproject/utils'; +import { AbiDecoder, BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; import * as Web3 from 'web3'; @@ -15,11 +15,11 @@ import { MultiSigWrapper } from '../util/multi_sig_wrapper'; import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; -const PROXY_ABI = artifacts.TokenTransferProxyArtifact.compilerOutput.abi; + +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +const PROXY_ABI = artifacts.TokenTransferProxy.compilerOutput.abi; const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI = - artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact.compilerOutput.abi; + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.compilerOutput.abi; chaiSetup.configure(); const expect = chai.expect; @@ -29,8 +29,8 @@ const abiDecoder = new AbiDecoder([MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_A describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { const zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID }); let owners: string[]; - const requiredApprovals = 2; - const SECONDS_TIME_LOCKED = 1000000; + const requiredApprovals = new BigNumber(2); + const SECONDS_TIME_LOCKED = new BigNumber(1000000); // initialize fake addresses let authorizedAddress: string; @@ -46,23 +46,22 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { owners = [accounts[0], accounts[1]]; [authorizedAddress, unauthorizedAddress] = accounts; const initialOwner = accounts[0]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + defaults, ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, { from: initialOwner, }); - const multiSigInstance = await deployer.deployAsync( - ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, - [owners, requiredApprovals, SECONDS_TIME_LOCKED, tokenTransferProxy.address], - ); - multiSig = new MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract( - multiSigInstance.abi, - multiSigInstance.address, + multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deploy0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, + defaults, + owners, + requiredApprovals, + SECONDS_TIME_LOCKED, + tokenTransferProxy.address, ); await tokenTransferProxy.transferOwnership.sendTransactionAsync(multiSig.address, { from: initialOwner, @@ -110,7 +109,11 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { }); it('should throw if tx destination is not the tokenTransferProxy', async () => { - const invalidTokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); + const invalidTokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + defaults, + ); const invalidDestination = invalidTokenTransferProxy.address; const dataParams: TransactionDataParams = { name: 'removeAuthorizedAddress', diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 4c404176b..fbd7f130d 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -8,13 +8,13 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import { TokenRegistryContract } from '../src/contract_wrappers/generated/token_registry'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { TokenRegWrapper } from '../util/token_registry_wrapper'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -29,8 +29,7 @@ describe('TokenRegistry', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; notOwner = accounts[1]; - const tokenRegInstance = await deployer.deployAsync(ContractName.TokenRegistry); - tokenReg = new TokenRegistryContract(tokenRegInstance.abi, tokenRegInstance.address, provider); + tokenReg = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); tokenRegWrapper = new TokenRegWrapper(tokenReg); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 885ff3bc1..78ef78beb 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -4,11 +4,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -23,11 +24,10 @@ describe('TokenTransferProxy', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; notOwner = accounts[1]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + defaults, ); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index dff1a0cfb..79189415f 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -6,12 +6,13 @@ import * as Web3 from 'web3'; import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -31,15 +32,20 @@ describe('TokenTransferProxy', () => { before(async () => { accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = notAuthorized = accounts[0]; - const tokenTransferProxyInstance = await deployer.deployAsync(ContractName.TokenTransferProxy); - tokenTransferProxy = new TokenTransferProxyContract( - tokenTransferProxyInstance.abi, - tokenTransferProxyInstance.address, + tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, provider, + defaults, + ); + rep = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - const repInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - rep = new DummyTokenContract(repInstance.abi, repInstance.address, provider); - dmyBalances = new Balances([rep], [accounts[0], accounts[1]]); await Promise.all([ rep.approve.sendTransactionAsync(tokenTransferProxy.address, INIT_ALLOW, { diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index ad83bbca3..f28120883 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -6,9 +6,13 @@ import * as chai from 'chai'; import ethUtil = require('ethereumjs-util'); import * as Web3 from 'web3'; +import { AccountLevelsContract } from '../../src/contract_wrappers/generated/account_levels'; import { ArbitrageContract } from '../../src/contract_wrappers/generated/arbitrage'; +import { DummyTokenContract } from '../../src/contract_wrappers/generated/dummy_token'; import { EtherDeltaContract } from '../../src/contract_wrappers/generated/ether_delta'; import { ExchangeContract } from '../../src/contract_wrappers/generated/exchange'; +import { TokenTransferProxyContract } from '../../src/contract_wrappers/generated/token_transfer_proxy'; +import { artifacts } from '../../util/artifacts'; import { Balances } from '../../util/balances'; import { constants } from '../../util/constants'; import { crypto } from '../../util/crypto'; @@ -16,8 +20,8 @@ import { ExchangeWrapper } from '../../util/exchange_wrapper'; import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { deployer } from '../utils/deployer'; -import { provider, web3Wrapper } from '../utils/web3_wrapper'; + +import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -54,33 +58,61 @@ describe('Arbitrage', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [coinbase, maker, edMaker, edFrontRunner] = accounts; - weth = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - zrx = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - const accountLevels = await deployer.deployAsync(ContractName.AccountLevels); + weth = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + zrx = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); + const accountLevels = await AccountLevelsContract.deploy0xArtifactAsync( + artifacts.AccountLevels, + provider, + defaults, + ); const edAdminAddress = accounts[0]; - const edMakerFee = 0; - const edTakerFee = 0; - const edFeeRebate = 0; - const etherDeltaInstance = await deployer.deployAsync(ContractName.EtherDelta, [ + const edMakerFee = new BigNumber(0); + const edTakerFee = new BigNumber(0); + const edFeeRebate = new BigNumber(0); + etherDelta = await EtherDeltaContract.deploy0xArtifactAsync( + artifacts.EtherDelta, + provider, + defaults, edAdminAddress, feeRecipient, accountLevels.address, edMakerFee, edTakerFee, edFeeRebate, - ]); - etherDelta = new EtherDeltaContract(etherDeltaInstance.abi, etherDeltaInstance.address, provider); - const tokenTransferProxy = await deployer.deployAsync(ContractName.TokenTransferProxy); - const exchangeInstance = await deployer.deployAsync(ContractName.Exchange, [ + ); + const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + defaults, + ); + const exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, zrx.address, tokenTransferProxy.address, - ]); - await tokenTransferProxy.addAuthorizedAddress(exchangeInstance.address, { from: accounts[0] }); + ); + await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: accounts[0] }); zeroEx = new ZeroEx(provider, { - exchangeContractAddress: exchangeInstance.address, + exchangeContractAddress: exchange.address, networkId: constants.TESTRPC_NETWORK_ID, }); - const exchange = new ExchangeContract(exchangeInstance.abi, exchangeInstance.address, provider); exWrapper = new ExchangeWrapper(exchange, zeroEx); makerTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); @@ -97,12 +129,14 @@ describe('Arbitrage', () => { takerFee: new BigNumber(0), }; orderFactory = new OrderFactory(zeroEx, defaultOrderParams); - const arbitrageInstance = await deployer.deployAsync(ContractName.Arbitrage, [ + arbitrage = await ArbitrageContract.deploy0xArtifactAsync( + artifacts.Arbitrage, + provider, + defaults, exchange.address, etherDelta.address, tokenTransferProxy.address, - ]); - arbitrage = new ArbitrageContract(arbitrageInstance.abi, arbitrageInstance.address, provider); + ); // Enable arbitrage and withdrawals of tokens await arbitrage.setAllowances.sendTransactionAsync(weth.address, { from: coinbase }); await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 618bda72d..a541c495f 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -6,12 +6,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { DummyTokenContract } from '../src/contract_wrappers/generated/dummy_token'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -33,8 +33,15 @@ describe('UnlimitedAllowanceToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - const tokenInstance = await deployer.deployAsync(ContractName.DummyToken, constants.DUMMY_TOKEN_ARGS); - token = new DummyTokenContract(tokenInstance.abi, tokenInstance.address, provider); + token = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + constants.DUMMY_TOKEN_NAME, + constants.DUMMY_TOKEN_SYMBOL, + constants.DUMMY_TOKEN_DECIMALS, + constants.DUMMY_TOKEN_TOTAL_SUPPLY, + ); await token.mint.sendTransactionAsync(MAX_MINT_VALUE, { from: owner }); tokenAddress = token.address; }); diff --git a/packages/contracts/test/utils/deployer.ts b/packages/contracts/test/utils/deployer.ts deleted file mode 100644 index 2f0951475..000000000 --- a/packages/contracts/test/utils/deployer.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Deployer } from '@0xproject/deployer'; -import { devConstants } from '@0xproject/dev-utils'; -import * as path from 'path'; - -import { constants } from '../../util/constants'; - -import { web3 } from './web3_wrapper'; - -const deployerOpts = { - provider: web3.currentProvider, - artifactsDir: path.resolve('lib', 'src', 'artifacts'), - networkId: constants.TESTRPC_NETWORK_ID, - defaults: { - gas: devConstants.GAS_ESTIMATE, - }, -}; - -export const deployer = new Deployer(deployerOpts); diff --git a/packages/contracts/test/utils/web3_wrapper.ts b/packages/contracts/test/utils/web3_wrapper.ts index dd6f198c4..4b2a8ed60 100644 --- a/packages/contracts/test/utils/web3_wrapper.ts +++ b/packages/contracts/test/utils/web3_wrapper.ts @@ -1,7 +1,11 @@ -import { web3Factory } from '@0xproject/dev-utils'; +import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +export const defaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, + gas: devConstants.GAS_ESTIMATE, +}; const providerConfigs = { shouldUseInProcessGanache: true }; export const web3 = web3Factory.create(providerConfigs); export const provider = web3.currentProvider; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index b01615b39..0ad3d86b7 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -6,12 +6,12 @@ import * as chai from 'chai'; import * as Web3 from 'web3'; import { ZRXTokenContract } from '../src/contract_wrappers/generated/zrx_token'; +import { artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -34,8 +34,7 @@ describe('ZRXToken', () => { zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); - const zrxInstance = await deployer.deployAsync(ContractName.ZRXToken); - zrx = new ZRXTokenContract(zrxInstance.abi, zrxInstance.address, provider); + zrx = await ZRXTokenContract.deploy0xArtifactAsync(artifacts.ZRX, provider, defaults); zrxAddress = zrx.address; MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index a1d6e5060..226df6c58 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -1,25 +1,31 @@ import { ContractArtifact } from '@0xproject/deployer'; -import * as DummyTokenArtifact from '../src/artifacts/DummyToken.json'; -import * as ExchangeArtifact from '../src/artifacts/Exchange.json'; -import * as MaliciousTokenArtifact from '../src/artifacts/MaliciousToken.json'; -import * as MultiSigWalletWithTimeLockArtifact from '../src/artifacts/MultiSigWalletWithTimeLock.json'; -import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact from '../src/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; -import * as TokenArtifact from '../src/artifacts/Token.json'; -import * as TokenRegistryArtifact from '../src/artifacts/TokenRegistry.json'; -import * as TokenTransferProxyArtifact from '../src/artifacts/TokenTransferProxy.json'; -import * as EtherTokenArtifact from '../src/artifacts/WETH9.json'; -import * as ZRXArtifact from '../src/artifacts/ZRXToken.json'; +import * as AccountLevels from '../src/artifacts/AccountLevels.json'; +import * as Arbitrage from '../src/artifacts/Arbitrage.json'; +import * as DummyToken from '../src/artifacts/DummyToken.json'; +import * as EtherDelta from '../src/artifacts/EtherDelta.json'; +import * as Exchange from '../src/artifacts/Exchange.json'; +import * as MaliciousToken from '../src/artifacts/MaliciousToken.json'; +import * as MultiSigWalletWithTimeLock from '../src/artifacts/MultiSigWalletWithTimeLock.json'; +import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../src/artifacts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; +import * as Token from '../src/artifacts/Token.json'; +import * as TokenRegistry from '../src/artifacts/TokenRegistry.json'; +import * as TokenTransferProxy from '../src/artifacts/TokenTransferProxy.json'; +import * as EtherToken from '../src/artifacts/WETH9.json'; +import * as ZRX from '../src/artifacts/ZRXToken.json'; export const artifacts = { - ZRXArtifact: (ZRXArtifact as any) as ContractArtifact, - DummyTokenArtifact: (DummyTokenArtifact as any) as ContractArtifact, - TokenArtifact: (TokenArtifact as any) as ContractArtifact, - ExchangeArtifact: (ExchangeArtifact as any) as ContractArtifact, - EtherTokenArtifact: (EtherTokenArtifact as any) as ContractArtifact, - TokenRegistryArtifact: (TokenRegistryArtifact as any) as ContractArtifact, - MaliciousTokenArtifact: (MaliciousTokenArtifact as any) as ContractArtifact, - TokenTransferProxyArtifact: (TokenTransferProxyArtifact as any) as ContractArtifact, - MultiSigWalletWithTimeLockArtifact: (MultiSigWalletWithTimeLockArtifact as any) as ContractArtifact, - MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressArtifact as any) as ContractArtifact, + AccountLevels: (AccountLevels as any) as ContractArtifact, + Arbitrage: (Arbitrage as any) as ContractArtifact, + EtherDelta: (EtherDelta as any) as ContractArtifact, + ZRX: (ZRX as any) as ContractArtifact, + DummyToken: (DummyToken as any) as ContractArtifact, + Token: (Token as any) as ContractArtifact, + Exchange: (Exchange as any) as ContractArtifact, + EtherToken: (EtherToken as any) as ContractArtifact, + TokenRegistry: (TokenRegistry as any) as ContractArtifact, + MaliciousToken: (MaliciousToken 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/contracts/util/constants.ts b/packages/contracts/util/constants.ts index d1152e683..d287986b7 100644 --- a/packages/contracts/util/constants.ts +++ b/packages/contracts/util/constants.ts @@ -1,7 +1,4 @@ -const DUMMY_TOKEN_NAME = ''; -const DUMMY_TOKEN_SYMBOL = ''; -const DUMMY_TOKEN_DECIMALS = 18; -const DUMMY_TOKEN_TOTAL_SUPPLY = 0; +import { BigNumber } from '@0xproject/utils'; export const constants = { INVALID_OPCODE: 'invalid opcode', @@ -10,5 +7,8 @@ export const constants = { MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, - DUMMY_TOKEN_ARGS: [DUMMY_TOKEN_NAME, DUMMY_TOKEN_SYMBOL, DUMMY_TOKEN_DECIMALS, DUMMY_TOKEN_TOTAL_SUPPLY], + DUMMY_TOKEN_NAME: '', + DUMMY_TOKEN_SYMBOL: '', + DUMMY_TOKEN_DECIMALS: new BigNumber(18), + DUMMY_TOKEN_TOTAL_SUPPLY: new BigNumber(0), }; diff --git a/packages/deployer/README.md b/packages/deployer/README.md index ef0ddd59d..4c7de2cb0 100644 --- a/packages/deployer/README.md +++ b/packages/deployer/README.md @@ -29,13 +29,12 @@ If your project is in [TypeScript](https://www.typescriptlang.org/), add the fol **Import** ```typescript -import { Deployer, Compiler } from '@0xproject/deployer'; +import { Compiler } from '@0xproject/deployer'; ``` or ```javascript -var Deployer = require('@0xproject/deployer').Deployer; var Compiler = require('@0xproject/deployer').Compiler; ``` diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index e81df3c0a..efb30091b 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -134,7 +134,7 @@ export class Compiler { const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings); const didSourceChange = currentArtifact.sourceTreeHashHex !== sourceTreeHashHex; - shouldCompile = isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; + shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; } if (!shouldCompile) { return; @@ -203,6 +203,20 @@ export class Compiler { }. Please make sure your contract has the same name as it's file name`, ); } + if (!_.isUndefined(compiledData.evm)) { + if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) { + compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object); + } + if ( + !_.isUndefined(compiledData.evm.deployedBytecode) && + !_.isUndefined(compiledData.evm.deployedBytecode.object) + ) { + compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix( + compiledData.evm.deployedBytecode.object, + ); + } + } + const sourceCodes = _.mapValues( compiled.sources, (_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source, diff --git a/packages/metacoin/src/global.d.ts b/packages/metacoin/src/global.d.ts new file mode 100644 index 000000000..783b92913 --- /dev/null +++ b/packages/metacoin/src/global.d.ts @@ -0,0 +1,4 @@ +declare module '*.json' { + const value: any; + export default value; +} diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts index 51830d1ef..6fe751d12 100644 --- a/packages/metacoin/test/metacoin_test.ts +++ b/packages/metacoin/test/metacoin_test.ts @@ -1,15 +1,19 @@ +import { ContractArtifact } from '@0xproject/deployer'; import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; +import * as MetacoinArtifact from '../artifacts/Metacoin.json'; import { MetacoinContract, TransferContractEventArgs } from '../src/contract_wrappers/metacoin'; import { chaiSetup } from './utils/chai_setup'; -import { deployer } from './utils/deployer'; +import { config } from './utils/config'; import { provider, web3Wrapper } from './utils/web3_wrapper'; +const artifact: ContractArtifact = MetacoinArtifact as any; + chaiSetup.configure(); const { expect } = chai; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); @@ -19,9 +23,8 @@ describe('Metacoin', () => { const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS; const INITIAL_BALANCE = new BigNumber(10000); before(async () => { - const metacoinInstance = await deployer.deployAsync('Metacoin'); - web3Wrapper.abiDecoder.addABI(metacoinInstance.abi); - metacoin = new MetacoinContract(metacoinInstance.abi, metacoinInstance.address, provider); + metacoin = await MetacoinContract.deploy0xArtifactAsync(artifact, provider, config.defaults); + web3Wrapper.abiDecoder.addABI(metacoin.abi); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); diff --git a/packages/metacoin/test/utils/config.ts b/packages/metacoin/test/utils/config.ts index d3a830754..8ae6d39a2 100644 --- a/packages/metacoin/test/utils/config.ts +++ b/packages/metacoin/test/utils/config.ts @@ -1,3 +1,4 @@ +import { devConstants } from '@0xproject/dev-utils'; import * as path from 'path'; export const config = { @@ -5,5 +6,8 @@ export const config = { artifactsDir: path.resolve(__dirname, '../../artifacts'), contractsDir: path.resolve(__dirname, '../../contracts'), ganacheLogFile: 'ganache.log', + defaults: { + from: devConstants.TESTRPC_FIRST_ADDRESS, + }, mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', }; diff --git a/packages/metacoin/test/utils/deployer.ts b/packages/metacoin/test/utils/deployer.ts deleted file mode 100644 index 5a631fa0a..000000000 --- a/packages/metacoin/test/utils/deployer.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Deployer } from '@0xproject/deployer'; -import { devConstants } from '@0xproject/dev-utils'; -import * as path from 'path'; - -import { config } from './config'; -import { web3Wrapper } from './web3_wrapper'; - -const deployerOpts = { - provider: web3Wrapper.getProvider(), - artifactsDir: config.artifactsDir, - networkId: config.networkId, - defaults: { - from: devConstants.TESTRPC_FIRST_ADDRESS, - }, -}; - -export const deployer = new Deployer(deployerOpts); diff --git a/packages/typescript-typings/types/ethers/index.d.ts b/packages/typescript-typings/types/ethers/index.d.ts index 7e04c7dd1..4fec07504 100644 --- a/packages/typescript-typings/types/ethers/index.d.ts +++ b/packages/typescript-typings/types/ethers/index.d.ts @@ -26,6 +26,7 @@ declare module 'ethers' { constructor(abi: any); } export class Contract { + public static getDeployTransaction(bytecode: string, abi: any, ...args: any[]): any; constructor(address: string, abi: any, provider: any); } } diff --git a/packages/website/md/docs/deployer/installation.md b/packages/website/md/docs/deployer/installation.md index c02dbadc6..5a9cc0cd0 100644 --- a/packages/website/md/docs/deployer/installation.md +++ b/packages/website/md/docs/deployer/installation.md @@ -13,12 +13,11 @@ yarn add @0xproject/deployer **Import** ```typescript -import { Deployer, Compiler } from '@0xproject/deployer'; +import { Compiler } from '@0xproject/deployer'; ``` or ```javascript -var Deployer = require('@0xproject/deployer').Deployer; var Compiler = require('@0xproject/deployer').Compiler; ``` -- cgit v1.2.3 From 422e5a19d4dc0461bdaecd9133bb8f19ac99baa6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 10:45:31 +0200 Subject: Configure migrations with a compiler.json --- packages/migrations/compiler.json | 20 ++++++++++++++++++++ packages/migrations/package.json | 7 ++----- packages/migrations/src/migrate.ts | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 packages/migrations/compiler.json diff --git a/packages/migrations/compiler.json b/packages/migrations/compiler.json new file mode 100644 index 000000000..0d126f4b6 --- /dev/null +++ b/packages/migrations/compiler.json @@ -0,0 +1,20 @@ +{ + "artifactsDir": "artifacts/1.0.0", + "contractsDir": "../contracts/src/contracts", + "contracts": [ + "Exchange", + "DummyToken", + "ZRXToken", + "Token", + "WETH9", + "TokenTransferProxy", + "MultiSigWallet", + "MultiSigWalletWithTimeLock", + "MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress", + "MaliciousToken", + "TokenRegistry", + "Arbitrage", + "EtherDelta", + "AccountLevels" + ] +} diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 8c85aa337..e548d7365 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -11,11 +11,8 @@ "lint": "tslint --project . 'src/**/*.ts'", "migrate": "run-s build compile script:migrate", "script:migrate": "node ./lib/migrate.js", - "copy_artifacts": "copyfiles 'src/artifacts/**/*' ./lib", - "compile": "node ../deployer/lib/src/cli.js compile --contracts ${npm_package_config_contracts} --contracts-dir ../contracts/src/contracts --artifacts-dir src/artifacts" - }, - "config": { - "contracts": "Exchange,DummyToken,ZRXToken,Token,WETH9,TokenTransferProxy,MultiSigWallet,MultiSigWalletWithTimeLock,MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress,MaliciousToken,TokenRegistry,Arbitrage,EtherDelta,AccountLevels" + "copy_artifacts": "copyfiles 'artifacts/1.0.0/**/*' ./lib", + "compile": "node ../deployer/lib/src/cli.js compile" }, "license": "Apache-2.0", "devDependencies": { diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 76dcbd847..014c4b1fe 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -9,7 +9,7 @@ import { runMigrationsAsync } from './migration'; (async () => { const deployerOpts = { jsonrpcUrl: 'http://localhost:8545', - artifactsDir: path.resolve('src', 'artifacts'), + artifactsDir: path.resolve('artifacts', '1.0.0'), networkId: 50, defaults: { gas: devConstants.GAS_ESTIMATE, -- cgit v1.2.3 From f9d80adaeeec827a8c2c81507d68d11e2681dcf3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 14:52:00 +0200 Subject: Remove deployer from 0x.js and migrations --- .gitignore | 1 + packages/0x.js/test/global_hooks.ts | 15 ++++-- packages/0x.js/test/utils/deployer.ts | 18 ------- packages/base-contract/src/index.ts | 11 +++- packages/contract_templates/contract.handlebars | 5 +- packages/migrations/package.json | 8 +++ packages/migrations/src/artifacts.ts | 55 ++++++++++++++++++++ packages/migrations/src/migrate.ts | 22 ++++---- packages/migrations/src/migration.ts | 68 +++++++++++++++++++------ packages/migrations/src/types.ts | 4 +- packages/migrations/src/utils/token_info.ts | 12 ++--- 11 files changed, 161 insertions(+), 58 deletions(-) delete mode 100644 packages/0x.js/test/utils/deployer.ts create mode 100644 packages/migrations/src/artifacts.ts diff --git a/.gitignore b/.gitignore index 7fed1959e..dd2dd582c 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ packages/migrations/artifacts/1.0.0 packages/0x.js/src/contract_wrappers/generated/ packages/contracts/src/contract_wrappers/generated/ packages/metacoin/src/contract_wrappers +packages/migrations/src/contract_wrappers # solc-bin in deployer packages/deployer/solc_bin/ diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index e3c986524..4aa9824e1 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -1,7 +1,16 @@ +import { devConstants } from '@0xproject/dev-utils'; import { runMigrationsAsync } from '@0xproject/migrations'; +import * as path from 'path'; -import { deployer } from './utils/deployer'; +import { constants } from './utils/constants'; +import { provider } from './utils/web3_wrapper'; -before('migrate contracts', async () => { - await runMigrationsAsync(deployer); +before('migrate contracts', async function() { + this.timeout(20000); + const defaults = { + gas: devConstants.GAS_ESTIMATE, + from: devConstants.TESTRPC_FIRST_ADDRESS, + }; + const artifactsDir = path.resolve('test', 'artifacts'); + await runMigrationsAsync(provider, artifactsDir, defaults); }); diff --git a/packages/0x.js/test/utils/deployer.ts b/packages/0x.js/test/utils/deployer.ts deleted file mode 100644 index b092322e2..000000000 --- a/packages/0x.js/test/utils/deployer.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Deployer } from '@0xproject/deployer'; -import { devConstants } from '@0xproject/dev-utils'; -import * as path from 'path'; - -import { constants } from './constants'; - -import { provider } from './web3_wrapper'; - -const artifactsDir = path.resolve('test', 'artifacts'); -const deployerOpts = { - artifactsDir, - provider, - networkId: constants.TESTRPC_NETWORK_ID, - defaults: { - gas: devConstants.GAS_ESTIMATE, - }, -}; -export const deployer = new Deployer(deployerOpts); diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index c362a882b..57d720795 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -25,6 +25,8 @@ export class BaseContract { protected _web3Wrapper: Web3Wrapper; public abi: ContractAbi; public address: string; + public contractName: string; + public constructorArgs: any[] = []; protected static _formatABIDataItemList( abis: DataItem[], values: any[], @@ -114,7 +116,14 @@ export class BaseContract { }) as MethodAbi; return methodAbi; } - constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial) { + constructor( + contractName: string, + abi: ContractAbi, + address: string, + provider: Provider, + defaults?: Partial, + ) { + this.contractName = contractName; this._web3Wrapper = new Web3Wrapper(provider, defaults); this.abi = abi; this.address = address; diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index a2fb29cfc..8d0f4e184 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -71,12 +71,15 @@ export class {{contractName}}Contract extends BaseContract { web3Wrapper.estimateGasAsync.bind(web3Wrapper), ); const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults); + console.log(`transactionHash: ${txHash}`); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash); + console.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`); const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, defaults); + contractInstance.constructorArgs = [{{> params inputs=ctor.inputs}}]; return contractInstance; } constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial) { - super(abi, address, provider, defaults); + super("{{contractName}}", abi, address, provider, defaults); classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']); } } // tslint:disable:max-file-line-count diff --git a/packages/migrations/package.json b/packages/migrations/package.json index e548d7365..a03ec1bdd 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -6,17 +6,24 @@ "types": "lib/index.d.ts", "scripts": { "build:watch": "tsc -w", + "prebuild": "run-s clean compile copy_artifacts generate_contract_wrappers", + "copy_artifacts": "copyfiles -u 4 'artifacts/1.0.0/**/*' ./lib/src/artifacts", "build": "tsc", "clean": "shx rm -rf lib", "lint": "tslint --project . 'src/**/*.ts'", "migrate": "run-s build compile script:migrate", "script:migrate": "node ./lib/migrate.js", "copy_artifacts": "copyfiles 'artifacts/1.0.0/**/*' ./lib", + "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers && prettier --write 'src/contract_wrappers/**.ts'", "compile": "node ../deployer/lib/src/cli.js compile" }, + "config": { + "abis": "artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels|WETH9|MaliciousToken).json" + }, "license": "Apache-2.0", "devDependencies": { "@0xproject/dev-utils": "^0.4.1", + "@0xproject/types": "^0.6.3", "@0xproject/tslint-config": "^0.4.17", "npm-run-all": "^4.1.2", "shx": "^0.2.2", @@ -25,6 +32,7 @@ }, "dependencies": { "@0xproject/deployer": "^0.4.3", + "@0xproject/base-contract": "^0.3.1", "@0xproject/utils": "^0.6.1", "@0xproject/web3-wrapper": "^0.6.3", "lodash": "^4.17.4" diff --git a/packages/migrations/src/artifacts.ts b/packages/migrations/src/artifacts.ts new file mode 100644 index 000000000..c240c3155 --- /dev/null +++ b/packages/migrations/src/artifacts.ts @@ -0,0 +1,55 @@ +import { BaseContract } from '@0xproject/base-contract'; +import { ContractArtifact } from '@0xproject/deployer'; +import * as fs from 'fs'; +import * as path from 'path'; + +import * as AccountLevels from '../artifacts/1.0.0/AccountLevels.json'; +import * as Arbitrage from '../artifacts/1.0.0/Arbitrage.json'; +import * as DummyToken from '../artifacts/1.0.0/DummyToken.json'; +import * as EtherDelta from '../artifacts/1.0.0/EtherDelta.json'; +import * as Exchange from '../artifacts/1.0.0/Exchange.json'; +import * as MaliciousToken from '../artifacts/1.0.0/MaliciousToken.json'; +import * as MultiSigWalletWithTimeLock from '../artifacts/1.0.0/MultiSigWalletWithTimeLock.json'; +import * as MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress from '../artifacts/1.0.0/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.json'; +import * as Token from '../artifacts/1.0.0/Token.json'; +import * as TokenRegistry from '../artifacts/1.0.0/TokenRegistry.json'; +import * as TokenTransferProxy from '../artifacts/1.0.0/TokenTransferProxy.json'; +import * as EtherToken from '../artifacts/1.0.0/WETH9.json'; +import * as ZRX from '../artifacts/1.0.0/ZRXToken.json'; + +export const artifacts = { + AccountLevels: (AccountLevels as any) as ContractArtifact, + Arbitrage: (Arbitrage as any) as ContractArtifact, + EtherDelta: (EtherDelta as any) as ContractArtifact, + ZRX: (ZRX as any) as ContractArtifact, + DummyToken: (DummyToken as any) as ContractArtifact, + Token: (Token as any) as ContractArtifact, + Exchange: (Exchange as any) as ContractArtifact, + EtherToken: (EtherToken as any) as ContractArtifact, + TokenRegistry: (TokenRegistry as any) as ContractArtifact, + MaliciousToken: (MaliciousToken as any) as ContractArtifact, + TokenTransferProxy: (TokenTransferProxy as any) as ContractArtifact, + MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, + MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, +}; + +const ARTIFACTS_DIR = '../artifacts/1.0.0'; +export class ArtifactWriter { + private _artifactsDir: string; + private _networkId: number; + constructor(artifactsDir: string, networkId: number) { + this._artifactsDir = artifactsDir; + this._networkId = networkId; + } + 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, 2)); + } +} diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 014c4b1fe..ab5a7bb0b 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -1,24 +1,22 @@ #!/usr/bin/env node import { Deployer } from '@0xproject/deployer'; -import { devConstants } from '@0xproject/dev-utils'; +import { devConstants, web3Factory } from '@0xproject/dev-utils'; +import { Provider } from '@0xproject/types'; import { logUtils } from '@0xproject/utils'; import * as path from 'path'; import { runMigrationsAsync } from './migration'; (async () => { - const deployerOpts = { - jsonrpcUrl: 'http://localhost:8545', - artifactsDir: path.resolve('artifacts', '1.0.0'), - networkId: 50, - defaults: { - gas: devConstants.GAS_ESTIMATE, - }, + const defaults = { + from: devConstants.TESTRPC_FIRST_ADDRESS, }; - - const deployer = new Deployer(deployerOpts); - - await runMigrationsAsync(deployer); + const providerConfigs = { shouldUseInProcessGanache: false }; + const web3 = web3Factory.create(providerConfigs); + const provider = web3.currentProvider; + const artifactsDir = 'artifacts/1.0.0'; + await runMigrationsAsync(provider, artifactsDir, defaults); + process.exit(0); })().catch(err => { logUtils.log(err); process.exit(1); diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 6313efcff..54ba6e535 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -1,8 +1,16 @@ -import { Deployer } from '@0xproject/deployer'; +import { Provider, TxData } from '@0xproject/types'; import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; +import { artifacts, ArtifactWriter } from './artifacts'; +import { DummyTokenContract } from './contract_wrappers/dummy_token'; +import { ExchangeContract } from './contract_wrappers/exchange'; +import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; +import { TokenRegistryContract } from './contract_wrappers/token_registry'; +import { TokenTransferProxyContract } from './contract_wrappers/token_transfer_proxy'; +import { WETH9Contract } from './contract_wrappers/weth9'; +import { ZRXTokenContract } from './contract_wrappers/zrx_token'; import { ContractName } from './types'; import { tokenInfo } from './utils/token_info'; @@ -12,25 +20,46 @@ import { tokenInfo } from './utils/token_info'; * the migration should be written to run synchronously. * @param deployer Deployer instance. */ -export const runMigrationsAsync = async (deployer: Deployer) => { - const web3Wrapper: Web3Wrapper = deployer.web3Wrapper; - const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); +export const runMigrationsAsync = async (provider: Provider, artifactsDir: string, defaults: Partial) => { + const web3Wrapper = new Web3Wrapper(provider); + const networkId = await web3Wrapper.getNetworkIdAsync(); + const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); + const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + artifacts.TokenTransferProxy, + provider, + defaults, + ); + artifactsWriter.saveArtifact(tokenTransferProxy); + const zrxToken = await ZRXTokenContract.deploy0xArtifactAsync(artifacts.ZRX, provider, defaults); + artifactsWriter.saveArtifact(zrxToken); - const tokenTransferProxy = await deployer.deployAndSaveAsync(ContractName.TokenTransferProxy); - const zrxToken = await deployer.deployAndSaveAsync(ContractName.ZRXToken); - const etherToken = await deployer.deployAndSaveAsync(ContractName.WETH9); - const tokenReg = await deployer.deployAndSaveAsync(ContractName.TokenRegistry); + const etherToken = await WETH9Contract.deploy0xArtifactAsync(artifacts.EtherToken, provider, defaults); + artifactsWriter.saveArtifact(etherToken); + const tokenReg = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + artifactsWriter.saveArtifact(tokenReg); - const exchangeArgs = [zrxToken.address, tokenTransferProxy.address]; + const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); const owners = [accounts[0], accounts[1]]; const confirmationsRequired = new BigNumber(2); const secondsRequired = new BigNumber(0); - const multiSigArgs = [owners, confirmationsRequired, secondsRequired, tokenTransferProxy.address]; - const exchange = await deployer.deployAndSaveAsync(ContractName.Exchange, exchangeArgs); - const multiSig = await deployer.deployAndSaveAsync( - ContractName.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, - multiSigArgs, + const exchange = await ExchangeContract.deploy0xArtifactAsync( + artifacts.Exchange, + provider, + defaults, + zrxToken.address, + tokenTransferProxy.address, + ); + artifactsWriter.saveArtifact(exchange); + const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deploy0xArtifactAsync( + artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, + provider, + defaults, + owners, + confirmationsRequired, + secondsRequired, + tokenTransferProxy.address, ); + artifactsWriter.saveArtifact(multiSig); const owner = accounts[0]; await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, { from: owner }); @@ -70,8 +99,15 @@ export const runMigrationsAsync = async (deployer: Deployer) => { ); for (const token of tokenInfo) { const totalSupply = new BigNumber(100000000000000000000); - const args = [token.name, token.symbol, token.decimals, totalSupply]; - const dummyToken = await deployer.deployAsync(ContractName.DummyToken, args); + const dummyToken = await DummyTokenContract.deploy0xArtifactAsync( + artifacts.DummyToken, + provider, + defaults, + token.name, + token.symbol, + token.decimals, + totalSupply, + ); await tokenReg.addToken.sendTransactionAsync( dummyToken.address, token.name, diff --git a/packages/migrations/src/types.ts b/packages/migrations/src/types.ts index 1887bfd96..21daf47f0 100644 --- a/packages/migrations/src/types.ts +++ b/packages/migrations/src/types.ts @@ -1,3 +1,5 @@ +import { BigNumber } from '@0xproject/utils'; + export interface MultiSigConfig { owners: string[]; confirmationsRequired: number; @@ -12,7 +14,7 @@ export interface Token { address?: string; name: string; symbol: string; - decimals: number; + decimals: BigNumber; ipfsHash: string; swarmHash: string; } diff --git a/packages/migrations/src/utils/token_info.ts b/packages/migrations/src/utils/token_info.ts index 968665c7d..e72a80220 100644 --- a/packages/migrations/src/utils/token_info.ts +++ b/packages/migrations/src/utils/token_info.ts @@ -1,4 +1,4 @@ -import { NULL_BYTES } from '@0xproject/utils'; +import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Token } from '../types'; @@ -6,35 +6,35 @@ export const tokenInfo: Token[] = [ { name: 'Augur Reputation Token', symbol: 'REP', - decimals: 18, + decimals: new BigNumber(18), ipfsHash: NULL_BYTES, swarmHash: NULL_BYTES, }, { name: 'Digix DAO Token', symbol: 'DGD', - decimals: 18, + decimals: new BigNumber(18), ipfsHash: NULL_BYTES, swarmHash: NULL_BYTES, }, { name: 'Golem Network Token', symbol: 'GNT', - decimals: 18, + decimals: new BigNumber(18), ipfsHash: NULL_BYTES, swarmHash: NULL_BYTES, }, { name: 'MakerDAO', symbol: 'MKR', - decimals: 18, + decimals: new BigNumber(18), ipfsHash: NULL_BYTES, swarmHash: NULL_BYTES, }, { name: 'Melon Token', symbol: 'MLN', - decimals: 18, + decimals: new BigNumber(18), ipfsHash: NULL_BYTES, swarmHash: NULL_BYTES, }, -- cgit v1.2.3 From 96037aed5231aa9344e5037aa6cff3d01f4abdae Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 15:13:24 +0200 Subject: Remove deployer --- .prettierignore | 1 + packages/deployer/src/cli.ts | 126 ++------------- packages/deployer/src/commands.ts | 14 -- packages/deployer/src/deployer.ts | 223 -------------------------- packages/deployer/src/index.ts | 1 - packages/deployer/src/utils/contract.ts | 80 --------- packages/deployer/src/utils/error_reporter.ts | 18 --- packages/deployer/src/utils/types.ts | 27 ---- packages/deployer/test/deployer_test.ts | 74 --------- packages/migrations/src/migrate.ts | 1 - 10 files changed, 16 insertions(+), 549 deletions(-) delete mode 100644 packages/deployer/src/commands.ts delete mode 100644 packages/deployer/src/deployer.ts delete mode 100644 packages/deployer/src/utils/contract.ts delete mode 100644 packages/deployer/src/utils/error_reporter.ts delete mode 100644 packages/deployer/test/deployer_test.ts diff --git a/.prettierignore b/.prettierignore index f12fdf870..093bc4d11 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,6 @@ lib .nyc_output +/packages/0x.js/test/artifacts /packages/contracts/src/artifacts /packages/metacoin/artifacts /packages/migrations/artifacts/1.0.0 diff --git a/packages/deployer/src/cli.ts b/packages/deployer/src/cli.ts index 8c89cf382..2412b8d34 100644 --- a/packages/deployer/src/cli.ts +++ b/packages/deployer/src/cli.ts @@ -8,130 +8,34 @@ import * as path from 'path'; import * as Web3 from 'web3'; import * as yargs from 'yargs'; -import { commands } from './commands'; +import { Compiler } from './compiler'; import { constants } from './utils/constants'; -import { consoleReporter } from './utils/error_reporter'; -import { CliOptions, CompilerOptions, DeployerOptions } from './utils/types'; +import { CompilerOptions } from './utils/types'; -const DEFAULT_CONTRACTS_DIR = path.resolve('src/contracts'); -const DEFAULT_ARTIFACTS_DIR = path.resolve('src/artifacts'); -const DEFAULT_NETWORK_ID = 50; -const DEFAULT_JSONRPC_URL = 'http://localhost:8545'; -const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString(); const DEFAULT_CONTRACTS_LIST = '*'; const SEPARATOR = ','; -/** - * Compiles all contracts with options passed in through CLI. - * @param argv Instance of process.argv provided by yargs. - */ -async function onCompileCommandAsync(argv: CliOptions): Promise { - const opts: CompilerOptions = { - contractsDir: argv.contractsDir, - artifactsDir: argv.artifactsDir, - contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), - }; - await commands.compileAsync(opts); -} -/** - * Deploys a single contract with provided name and args. - * @param argv Instance of process.argv provided by yargs. - */ -async function onDeployCommandAsync(argv: CliOptions): Promise { - const url = argv.jsonrpcUrl; - const provider = new Web3.providers.HttpProvider(url); - const web3Wrapper = new Web3Wrapper(provider); - const networkId = await web3Wrapper.getNetworkIdAsync(); - const compilerOpts: CompilerOptions = { - contractsDir: argv.contractsDir, - artifactsDir: argv.artifactsDir, - contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), - }; - await commands.compileAsync(compilerOpts); - - const defaults = { - gasPrice: new BigNumber(argv.gasPrice), - from: argv.account, - }; - const deployerOpts: DeployerOptions = { - artifactsDir: argv.artifactsDir || DEFAULT_ARTIFACTS_DIR, - jsonrpcUrl: argv.jsonrpcUrl, - networkId, - defaults, - }; - const deployerArgsString = argv.constructorArgs as string; - const deployerArgs = deployerArgsString.split(SEPARATOR); - await commands.deployAsync(argv.contract as string, deployerArgs, deployerOpts); -} -/** - * Adds additional required options for when the user is calling the deploy command. - * @param yargsInstance yargs instance provided in builder function callback. - */ -function deployCommandBuilder(yargsInstance: any) { - return yargsInstance - .option('network-id', { - type: 'number', - default: DEFAULT_NETWORK_ID, - description: 'mainnet=1, kovan=42, testrpc=50', - }) - .option('contract', { - type: 'string', - description: 'name of contract to deploy, excluding .sol extension', - }) - .option('constructor-args', { - type: 'string', - description: 'comma separated list of constructor args to deploy contract with', - }) - .option('jsonrpc-url', { - type: 'string', - default: DEFAULT_JSONRPC_URL, - description: 'url of JSON RPC', - }) - .option('account', { +(async () => { + const argv = yargs + .option('contracts-dir', { type: 'string', - description: 'account to use for deploying contracts', + description: 'path of contracts directory to compile', }) - .option('gas-price', { + .option('artifacts-dir', { type: 'string', - default: DEFAULT_GAS_PRICE, - description: 'gasPrice to be used for transactions', + description: 'path to write contracts artifacts to', }) - .demandOption(['contract', 'args', 'account']) - .help().argv; -} - -/** - * Adds additional required options for when the user is calling the compile command. - * @param yargsInstance yargs instance provided in builder function callback. - */ -function compileCommandBuilder(yargsInstance: any) { - return yargsInstance .option('contracts', { type: 'string', default: DEFAULT_CONTRACTS_LIST, description: 'comma separated list of contracts to compile', }) .help().argv; -} - -(() => { - const identityCommandBuilder = _.identity; - return yargs - .option('contracts-dir', { - type: 'string', - description: 'path of contracts directory to compile', - }) - .option('artifacts-dir', { - type: 'string', - description: 'path to write contracts artifacts to', - }) - .demandCommand(1) - .command('compile', 'compile contracts', compileCommandBuilder, consoleReporter(onCompileCommandAsync)) - .command( - 'deploy', - 'deploy a single contract with provided arguments', - deployCommandBuilder, - consoleReporter(onDeployCommandAsync), - ) - .help().argv; + const opts: CompilerOptions = { + contractsDir: argv.contractsDir, + artifactsDir: argv.artifactsDir, + contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), + }; + const compiler = new Compiler(opts); + await compiler.compileAsync(); })(); diff --git a/packages/deployer/src/commands.ts b/packages/deployer/src/commands.ts deleted file mode 100644 index 8e544a60b..000000000 --- a/packages/deployer/src/commands.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Compiler } from './compiler'; -import { Deployer } from './deployer'; -import { CompilerOptions, DeployerOptions } from './utils/types'; - -export const commands = { - async compileAsync(opts: CompilerOptions): Promise { - const compiler = new Compiler(opts); - await compiler.compileAsync(); - }, - async deployAsync(contractName: string, args: any[], opts: DeployerOptions): Promise { - const deployer = new Deployer(opts); - await deployer.deployAndSaveAsync(contractName, args); - }, -}; diff --git a/packages/deployer/src/deployer.ts b/packages/deployer/src/deployer.ts deleted file mode 100644 index c8c3a9a06..000000000 --- a/packages/deployer/src/deployer.ts +++ /dev/null @@ -1,223 +0,0 @@ -import { AbiType, ConstructorAbi, ContractAbi, Provider, TxData } from '@0xproject/types'; -import { logUtils } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import * as _ from 'lodash'; -import * as solc from 'solc'; -import * as Web3 from 'web3'; - -import { Contract } from './utils/contract'; -import { encoder } from './utils/encoder'; -import { fsWrapper } from './utils/fs_wrapper'; -import { - ContractArtifact, - ContractNetworkData, - DeployerOptions, - ProviderDeployerOptions, - UrlDeployerOptions, -} from './utils/types'; -import { utils } from './utils/utils'; - -// Gas added to gas estimate to make sure there is sufficient gas for deployment. -const EXTRA_GAS = 200000; - -/** - * The Deployer facilitates deploying Solidity smart contracts to the blockchain. - * It can be used to build custom migration scripts. - */ -export class Deployer { - public web3Wrapper: Web3Wrapper; - private _artifactsDir: string; - private _networkId: number; - private _defaults: Partial; - /** - * Gets data for current version stored in artifact. - * @param contractArtifact The contract artifact. - * @return Version specific contract data. - */ - private static _getContractCompilerOutputFromArtifactIfExists( - contractArtifact: ContractArtifact, - ): solc.StandardContractOutput { - const compilerOutputIfExists = contractArtifact.compilerOutput; - if (_.isUndefined(compilerOutputIfExists)) { - throw new Error(`Compiler output not found in artifact for contract: ${contractArtifact.contractName}`); - } - return compilerOutputIfExists; - } - /** - * Instantiate a new instance of the Deployer class. - * @param opts Deployer options, including either an RPC url or Provider instance. - * @returns A Deployer instance - */ - constructor(opts: DeployerOptions) { - this._artifactsDir = opts.artifactsDir; - this._networkId = opts.networkId; - this._defaults = opts.defaults; - let provider: Provider; - if (_.isUndefined((opts as ProviderDeployerOptions).provider)) { - const jsonrpcUrl = (opts as UrlDeployerOptions).jsonrpcUrl; - if (_.isUndefined(jsonrpcUrl)) { - throw new Error(`Deployer options don't contain provider nor jsonrpcUrl. Please pass one of them`); - } - provider = new Web3.providers.HttpProvider(jsonrpcUrl); - } else { - provider = (opts as ProviderDeployerOptions).provider; - } - this.web3Wrapper = new Web3Wrapper(provider, this._defaults); - } - /** - * Loads a contract's corresponding artifacts and deploys it with the supplied constructor arguments. - * @param contractName Name of the contract to deploy. Must match name of an artifact in supplied artifacts directory. - * @param args Array of contract constructor arguments. - * @return Deployed contract instance. - */ - public async deployAsync(contractName: string, args: any[] = []): Promise { - const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName); - const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists); - const data = compilerOutput.evm.bytecode.object; - const from = await this._getFromAddressAsync(); - const gas = await this._getAllowableGasEstimateAsync(data); - const txData = { - gasPrice: this._defaults.gasPrice, - from, - data, - gas, - }; - if (_.isUndefined(compilerOutput.abi)) { - throw new Error(`ABI not found in ${contractName} artifacts`); - } - const abi = compilerOutput.abi; - const constructorAbi = _.find(abi, { type: AbiType.Constructor }) as ConstructorAbi; - const constructorArgs = _.isUndefined(constructorAbi) ? [] : constructorAbi.inputs; - if (constructorArgs.length !== args.length) { - const constructorSignature = `constructor(${_.map(constructorArgs, arg => `${arg.type} ${arg.name}`).join( - ', ', - )})`; - throw new Error( - `${contractName} expects ${constructorArgs.length} constructor params: ${constructorSignature}. Got ${ - args.length - }`, - ); - } - const web3ContractInstance = await this._deployFromAbiAsync(abi, args, txData); - logUtils.log(`${contractName}.sol successfully deployed at ${web3ContractInstance.address}`); - const contractInstance = new Contract(web3ContractInstance, this._defaults); - return contractInstance; - } - /** - * Loads a contract's artifact, deploys it with supplied constructor arguments, and saves the updated data - * back to the artifact file. - * @param contractName Name of the contract to deploy. Must match name of an artifact in artifacts directory. - * @param args Array of contract constructor arguments. - * @return Deployed contract instance. - */ - public async deployAndSaveAsync(contractName: string, args: any[] = []): Promise { - const contractInstance = await this.deployAsync(contractName, args); - await this._saveContractDataToArtifactAsync(contractName, contractInstance.address, args); - return contractInstance; - } - /** - * Deploys a contract given its ABI, arguments, and transaction data. - * @param abi ABI of contract to deploy. - * @param args Constructor arguments to use in deployment. - * @param txData Tx options used for deployment. - * @return Promise that resolves to a web3 contract instance. - */ - private async _deployFromAbiAsync(abi: ContractAbi, args: any[], txData: TxData): Promise { - const contract: Web3.Contract = this.web3Wrapper.getContractFromAbi(abi); - const deployPromise = new Promise((resolve, reject) => { - /** - * Contract is inferred as 'any' because TypeScript - * is not able to read 'new' from the Contract interface - */ - (contract as any).new(...args, txData, (err: Error, res: any): any => { - if (err) { - reject(err); - } else if (_.isUndefined(res.address) && !_.isUndefined(res.transactionHash)) { - logUtils.log(`transactionHash: ${res.transactionHash}`); - } else { - resolve(res); - } - }); - }); - return deployPromise; - } - /** - * Updates a contract artifact's address and encoded constructor arguments. - * @param contractName Name of contract. Must match an existing artifact. - * @param contractAddress Contract address to save to artifact. - * @param args Contract constructor arguments that will be encoded and saved to artifact. - */ - private async _saveContractDataToArtifactAsync( - contractName: string, - contractAddress: string, - args: any[], - ): Promise { - const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName); - const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists); - if (_.isUndefined(compilerOutput.abi)) { - throw new Error(`ABI not found in ${contractName} artifacts`); - } - const abi = compilerOutput.abi; - const encodedConstructorArgs = encoder.encodeConstructorArgsFromAbi(args, abi); - const newContractData: ContractNetworkData = { - address: contractAddress, - links: {}, - constructorArgs: encodedConstructorArgs, - }; - const newArtifact = { - ...contractArtifactIfExists, - networks: { - ...contractArtifactIfExists.networks, - [this._networkId]: newContractData, - }, - }; - const artifactString = utils.stringifyWithFormatting(newArtifact); - const artifactPath = `${this._artifactsDir}/${contractName}.json`; - await fsWrapper.writeFileAsync(artifactPath, artifactString); - } - /** - * Loads a contract artifact, if it exists. - * @param contractName Name of the contract, without the extension. - * @return The contract artifact. - */ - private _loadContractArtifactIfExists(contractName: string): ContractArtifact { - const artifactPath = `${this._artifactsDir}/${contractName}.json`; - try { - const contractArtifact: ContractArtifact = require(artifactPath); - return contractArtifact; - } catch (err) { - throw new Error(`Artifact not found for contract: ${contractName} at ${artifactPath}`); - } - } - /** - * Gets the address to use for sending a transaction. - * @return The default from address. If not specified, returns the first address accessible by web3. - */ - private async _getFromAddressAsync(): Promise { - let from: string; - if (_.isUndefined(this._defaults.from)) { - const accounts = await this.web3Wrapper.getAvailableAddressesAsync(); - from = accounts[0]; - } else { - from = this._defaults.from; - } - return from; - } - /** - * Estimates the gas required for a transaction. - * If gas would be over the block gas limit, the max allowable gas is returned instead. - * @param data Bytecode to estimate gas for. - * @return Gas estimate for transaction data. - */ - private async _getAllowableGasEstimateAsync(data: string): Promise { - const block = await this.web3Wrapper.getBlockAsync('latest'); - let gas: number; - try { - const gasEstimate: number = await this.web3Wrapper.estimateGasAsync({ data }); - gas = Math.min(gasEstimate + EXTRA_GAS, block.gasLimit); - } catch (err) { - gas = block.gasLimit; - } - return gas; - } -} diff --git a/packages/deployer/src/index.ts b/packages/deployer/src/index.ts index 31a75677b..4b4c51de2 100644 --- a/packages/deployer/src/index.ts +++ b/packages/deployer/src/index.ts @@ -1,3 +1,2 @@ -export { Deployer } from './deployer'; export { Compiler } from './compiler'; export { ContractArtifact, ContractNetworks } from './utils/types'; diff --git a/packages/deployer/src/utils/contract.ts b/packages/deployer/src/utils/contract.ts deleted file mode 100644 index e8dd5218a..000000000 --- a/packages/deployer/src/utils/contract.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { schemas, SchemaValidator } from '@0xproject/json-schemas'; -import { AbiType, ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types'; -import { promisify } from '@0xproject/utils'; -import * as _ from 'lodash'; -import * as Web3 from 'web3'; - -export class Contract implements Web3.ContractInstance { - public address: string; - public abi: ContractAbi; - private _contract: Web3.ContractInstance; - private _defaults: Partial; - private _validator: SchemaValidator; - // This class instance is going to be populated with functions and events depending on the ABI - // and we don't know their types in advance - [name: string]: any; - constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { - this._contract = web3ContractInstance; - this.address = web3ContractInstance.address; - this.abi = web3ContractInstance.abi; - this._defaults = defaults; - this._populateEvents(); - this._populateFunctions(); - this._validator = new SchemaValidator(); - } - private _populateFunctions(): void { - const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function) as FunctionAbi[]; - _.forEach(functionsAbi, (functionAbi: MethodAbi) => { - if (functionAbi.constant) { - const cbStyleCallFunction = this._contract[functionAbi.name].call; - this[functionAbi.name] = promisify(cbStyleCallFunction, this._contract); - this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract); - } else { - const cbStyleFunction = this._contract[functionAbi.name]; - const cbStyleCallFunction = this._contract[functionAbi.name].call; - const cbStyleEstimateGasFunction = this._contract[functionAbi.name].estimateGas; - this[functionAbi.name] = this._promisifyWithDefaultParams(cbStyleFunction); - this[functionAbi.name].estimateGasAsync = promisify(cbStyleEstimateGasFunction); - this[functionAbi.name].sendTransactionAsync = this._promisifyWithDefaultParams(cbStyleFunction); - this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract); - } - }); - } - private _populateEvents(): void { - const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event) as EventAbi[]; - _.forEach(eventsAbi, (eventAbi: EventAbi) => { - this[eventAbi.name] = this._contract[eventAbi.name]; - }); - } - private _promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise { - const promisifiedWithDefaultParams = async (...args: any[]) => { - const promise = new Promise((resolve, reject) => { - const lastArg = args[args.length - 1]; - let txData: Partial = {}; - if (this._isTxData(lastArg)) { - txData = args.pop(); - } - txData = { - ...this._defaults, - ...txData, - }; - const callback = (err: Error, data: any) => { - if (_.isNull(err)) { - resolve(data); - } else { - reject(err); - } - }; - args.push(txData); - args.push(callback); - fn.apply(this._contract, args); - }); - return promise; - }; - return promisifiedWithDefaultParams; - } - private _isTxData(lastArg: any): boolean { - const isValid = this._validator.isValid(lastArg, schemas.txDataSchema); - return isValid; - } -} diff --git a/packages/deployer/src/utils/error_reporter.ts b/packages/deployer/src/utils/error_reporter.ts deleted file mode 100644 index 4e73307f0..000000000 --- a/packages/deployer/src/utils/error_reporter.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { logUtils } from '@0xproject/utils'; - -/** - * Makes an async function no-throw printing errors to the console - * @param asyncFn async function to wrap - * @return Wrapped version of the passed function - */ -export function consoleReporter(asyncFn: (arg: T) => Promise): (arg: T) => Promise { - const noThrowFnAsync = async (arg: T) => { - try { - const result = await asyncFn(arg); - return result; - } catch (err) { - logUtils.log(`${err}`); - } - }; - return noThrowFnAsync; -} diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts index 19c27df67..b12a11b79 100644 --- a/packages/deployer/src/utils/types.ts +++ b/packages/deployer/src/utils/types.ts @@ -50,17 +50,6 @@ export interface SolcErrors { [key: string]: boolean; } -export interface CliOptions extends yargs.Arguments { - artifactsDir: string; - contractsDir: string; - jsonrpcUrl: string; - networkId: number; - gasPrice: string; - account?: string; - contract?: string; - args?: string; -} - export interface CompilerOptions { contractsDir?: string; artifactsDir?: string; @@ -68,22 +57,6 @@ export interface CompilerOptions { contracts?: string[] | '*'; } -export interface BaseDeployerOptions { - artifactsDir: string; - networkId: number; - defaults: Partial; -} - -export interface ProviderDeployerOptions extends BaseDeployerOptions { - provider: Provider; -} - -export interface UrlDeployerOptions extends BaseDeployerOptions { - jsonrpcUrl: string; -} - -export type DeployerOptions = UrlDeployerOptions | ProviderDeployerOptions; - export interface ContractSourceData { [contractName: string]: ContractSpecificSourceData; } diff --git a/packages/deployer/test/deployer_test.ts b/packages/deployer/test/deployer_test.ts deleted file mode 100644 index a8abc6454..000000000 --- a/packages/deployer/test/deployer_test.ts +++ /dev/null @@ -1,74 +0,0 @@ -import * as chai from 'chai'; -import 'mocha'; - -import { Compiler } from '../src/compiler'; -import { Deployer } from '../src/deployer'; -import { fsWrapper } from '../src/utils/fs_wrapper'; -import { CompilerOptions, ContractArtifact, ContractNetworkData, DoneCallback } from '../src/utils/types'; - -import { constructor_args, exchange_binary } from './fixtures/exchange_bin'; -import { constants } from './util/constants'; -import { provider } from './util/provider'; - -const expect = chai.expect; - -describe('#Deployer', () => { - const artifactsDir = `${__dirname}/fixtures/artifacts`; - const contractsDir = `${__dirname}/fixtures/contracts`; - const exchangeArtifactPath = `${artifactsDir}/Exchange.json`; - const compilerOpts: CompilerOptions = { - artifactsDir, - contractsDir, - contracts: constants.contracts, - }; - const compiler = new Compiler(compilerOpts); - const deployerOpts = { - artifactsDir, - networkId: constants.networkId, - provider, - defaults: { - gasPrice: constants.gasPrice, - }, - }; - const deployer = new Deployer(deployerOpts); - beforeEach(function(done: DoneCallback) { - this.timeout(constants.timeoutMs); - (async () => { - if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) { - await fsWrapper.removeFileAsync(exchangeArtifactPath); - } - await compiler.compileAsync(); - done(); - })().catch(done); - }); - describe('#deployAsync', () => { - it('should deploy the Exchange contract without updating the Exchange artifact', async () => { - const exchangeConstructorArgs = [constants.zrxTokenAddress, constants.tokenTransferProxyAddress]; - const exchangeContractInstance = await deployer.deployAsync('Exchange', exchangeConstructorArgs); - const opts = { - encoding: 'utf8', - }; - const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); - const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); - const exchangeContractData: ContractNetworkData = exchangeArtifact.networks[constants.networkId]; - const exchangeAddress = exchangeContractInstance.address; - expect(exchangeAddress).to.not.equal(undefined); - expect(exchangeContractData).to.equal(undefined); - }); - }); - describe('#deployAndSaveAsync', () => { - it('should save the correct contract address and constructor arguments to the Exchange artifact', async () => { - const exchangeConstructorArgs = [constants.zrxTokenAddress, constants.tokenTransferProxyAddress]; - const exchangeContractInstance = await deployer.deployAndSaveAsync('Exchange', exchangeConstructorArgs); - const opts = { - encoding: 'utf8', - }; - const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); - const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); - const exchangeContractData: ContractNetworkData = exchangeArtifact.networks[constants.networkId]; - const exchangeAddress = exchangeContractInstance.address; - expect(exchangeAddress).to.be.equal(exchangeContractData.address); - expect(constructor_args).to.be.equal(exchangeContractData.constructorArgs); - }); - }); -}); diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index ab5a7bb0b..58d39734e 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -1,5 +1,4 @@ #!/usr/bin/env node -import { Deployer } from '@0xproject/deployer'; import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Provider } from '@0xproject/types'; import { logUtils } from '@0xproject/utils'; -- cgit v1.2.3 From a6f72de09d7b2c9738b78d2097baa9906838fbe9 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 15:42:07 +0200 Subject: Rename deployer to sol-compiler --- .circleci/config.yml | 16 +- .gitignore | 4 +- README.md | 4 +- packages/0x.js/package.json | 6 +- packages/0x.js/test/global_hooks.ts | 2 +- packages/abi-gen/src/index.ts | 2 +- packages/contract_templates/contract.handlebars | 2 +- packages/contracts/package.json | 4 +- packages/contracts/util/artifacts.ts | 2 +- packages/deployer/.npmignore | 7 - packages/deployer/CHANGELOG.json | 151 ------ packages/deployer/CHANGELOG.md | 60 -- packages/deployer/README.md | 103 ---- packages/deployer/coverage/.gitkeep | 0 packages/deployer/package.json | 92 ---- packages/deployer/solc_bin/.gitkeep | 0 packages/deployer/src/cli.ts | 41 -- packages/deployer/src/compiler.ts | 276 ---------- packages/deployer/src/globals.d.ts | 6 - packages/deployer/src/index.ts | 2 - .../deployer/src/monorepo_scripts/postpublish.ts | 8 - .../deployer/src/monorepo_scripts/stage_docs.ts | 8 - packages/deployer/src/solc/bin_paths.ts | 20 - packages/deployer/src/utils/compiler.ts | 107 ---- packages/deployer/src/utils/constants.ts | 5 - packages/deployer/src/utils/encoder.ts | 18 - packages/deployer/src/utils/fs_wrapper.ts | 12 - packages/deployer/src/utils/types.ts | 79 --- packages/deployer/src/utils/utils.ts | 8 - packages/deployer/test/compiler_test.ts | 44 -- packages/deployer/test/compiler_utils_test.ts | 83 --- .../deployer/test/fixtures/contracts/Exchange.sol | 603 --------------------- .../test/fixtures/contracts/TokenTransferProxy.sol | 115 ---- .../test/fixtures/contracts/base/SafeMath.sol | 41 -- .../test/fixtures/contracts/base/Token.sol | 38 -- packages/deployer/test/fixtures/exchange_bin.ts | 4 - packages/deployer/test/util/constants.ts | 11 - packages/deployer/test/util/provider.ts | 9 - packages/deployer/tsconfig.json | 8 - packages/deployer/tslint.json | 3 - packages/metacoin/package.json | 4 +- packages/metacoin/test/metacoin_test.ts | 2 +- packages/migrations/package.json | 4 +- packages/migrations/src/artifacts.ts | 2 +- packages/migrations/src/migration.ts | 4 +- .../src/find_unused_dependencies.ts | 2 +- packages/monorepo-scripts/src/publish.ts | 2 +- packages/sol-compiler/.npmignore | 7 + packages/sol-compiler/CHANGELOG.json | 151 ++++++ packages/sol-compiler/CHANGELOG.md | 60 ++ packages/sol-compiler/README.md | 103 ++++ packages/sol-compiler/package.json | 92 ++++ packages/sol-compiler/src/cli.ts | 41 ++ packages/sol-compiler/src/compiler.ts | 276 ++++++++++ packages/sol-compiler/src/globals.d.ts | 6 + packages/sol-compiler/src/index.ts | 2 + .../src/monorepo_scripts/postpublish.ts | 8 + .../src/monorepo_scripts/stage_docs.ts | 8 + packages/sol-compiler/src/solc/bin_paths.ts | 20 + packages/sol-compiler/src/utils/compiler.ts | 107 ++++ packages/sol-compiler/src/utils/constants.ts | 5 + packages/sol-compiler/src/utils/encoder.ts | 18 + packages/sol-compiler/src/utils/fs_wrapper.ts | 12 + packages/sol-compiler/src/utils/types.ts | 79 +++ packages/sol-compiler/src/utils/utils.ts | 8 + packages/sol-compiler/test/compiler_test.ts | 44 ++ packages/sol-compiler/test/compiler_utils_test.ts | 83 +++ .../test/fixtures/contracts/Exchange.sol | 603 +++++++++++++++++++++ .../test/fixtures/contracts/TokenTransferProxy.sol | 115 ++++ .../test/fixtures/contracts/base/SafeMath.sol | 41 ++ .../test/fixtures/contracts/base/Token.sol | 38 ++ .../sol-compiler/test/fixtures/exchange_bin.ts | 4 + packages/sol-compiler/test/util/constants.ts | 11 + packages/sol-compiler/test/util/provider.ts | 9 + packages/sol-compiler/tsconfig.json | 8 + packages/sol-compiler/tslint.json | 3 + packages/sol-cov/package.json | 4 +- packages/website/md/docs/deployer/installation.md | 23 - packages/website/md/docs/deployer/introduction.md | 18 - packages/website/md/docs/deployer/usage.md | 56 -- .../website/md/docs/sol-compiler/installation.md | 23 + .../website/md/docs/sol-compiler/introduction.md | 13 + packages/website/md/docs/sol-compiler/usage.md | 24 + packages/website/translations/chinese.json | 2 +- packages/website/translations/english.json | 2 +- packages/website/translations/korean.json | 2 +- packages/website/translations/russian.json | 2 +- packages/website/translations/spanish.json | 2 +- packages/website/ts/components/top_bar/top_bar.tsx | 16 +- .../ts/containers/deployer_documentation.ts | 102 ---- .../ts/containers/sol_compiler_documentation.ts | 99 ++++ .../ts/containers/subproviders_documentation.ts | 2 +- packages/website/ts/index.tsx | 9 +- .../website/ts/pages/documentation/doc_page.tsx | 2 +- packages/website/ts/types.ts | 6 +- yarn.lock | 4 +- 96 files changed, 2180 insertions(+), 2217 deletions(-) delete mode 100644 packages/deployer/.npmignore delete mode 100644 packages/deployer/CHANGELOG.json delete mode 100644 packages/deployer/CHANGELOG.md delete mode 100644 packages/deployer/README.md delete mode 100644 packages/deployer/coverage/.gitkeep delete mode 100644 packages/deployer/package.json delete mode 100644 packages/deployer/solc_bin/.gitkeep delete mode 100644 packages/deployer/src/cli.ts delete mode 100644 packages/deployer/src/compiler.ts delete mode 100644 packages/deployer/src/globals.d.ts delete mode 100644 packages/deployer/src/index.ts delete mode 100644 packages/deployer/src/monorepo_scripts/postpublish.ts delete mode 100644 packages/deployer/src/monorepo_scripts/stage_docs.ts delete mode 100644 packages/deployer/src/solc/bin_paths.ts delete mode 100644 packages/deployer/src/utils/compiler.ts delete mode 100644 packages/deployer/src/utils/constants.ts delete mode 100644 packages/deployer/src/utils/encoder.ts delete mode 100644 packages/deployer/src/utils/fs_wrapper.ts delete mode 100644 packages/deployer/src/utils/types.ts delete mode 100644 packages/deployer/src/utils/utils.ts delete mode 100644 packages/deployer/test/compiler_test.ts delete mode 100644 packages/deployer/test/compiler_utils_test.ts delete mode 100644 packages/deployer/test/fixtures/contracts/Exchange.sol delete mode 100644 packages/deployer/test/fixtures/contracts/TokenTransferProxy.sol delete mode 100644 packages/deployer/test/fixtures/contracts/base/SafeMath.sol delete mode 100644 packages/deployer/test/fixtures/contracts/base/Token.sol delete mode 100644 packages/deployer/test/fixtures/exchange_bin.ts delete mode 100644 packages/deployer/test/util/constants.ts delete mode 100644 packages/deployer/test/util/provider.ts delete mode 100644 packages/deployer/tsconfig.json delete mode 100644 packages/deployer/tslint.json create mode 100644 packages/sol-compiler/.npmignore create mode 100644 packages/sol-compiler/CHANGELOG.json create mode 100644 packages/sol-compiler/CHANGELOG.md create mode 100644 packages/sol-compiler/README.md create mode 100644 packages/sol-compiler/package.json create mode 100644 packages/sol-compiler/src/cli.ts create mode 100644 packages/sol-compiler/src/compiler.ts create mode 100644 packages/sol-compiler/src/globals.d.ts create mode 100644 packages/sol-compiler/src/index.ts create mode 100644 packages/sol-compiler/src/monorepo_scripts/postpublish.ts create mode 100644 packages/sol-compiler/src/monorepo_scripts/stage_docs.ts create mode 100644 packages/sol-compiler/src/solc/bin_paths.ts create mode 100644 packages/sol-compiler/src/utils/compiler.ts create mode 100644 packages/sol-compiler/src/utils/constants.ts create mode 100644 packages/sol-compiler/src/utils/encoder.ts create mode 100644 packages/sol-compiler/src/utils/fs_wrapper.ts create mode 100644 packages/sol-compiler/src/utils/types.ts create mode 100644 packages/sol-compiler/src/utils/utils.ts create mode 100644 packages/sol-compiler/test/compiler_test.ts create mode 100644 packages/sol-compiler/test/compiler_utils_test.ts create mode 100644 packages/sol-compiler/test/fixtures/contracts/Exchange.sol create mode 100644 packages/sol-compiler/test/fixtures/contracts/TokenTransferProxy.sol create mode 100644 packages/sol-compiler/test/fixtures/contracts/base/SafeMath.sol create mode 100644 packages/sol-compiler/test/fixtures/contracts/base/Token.sol create mode 100644 packages/sol-compiler/test/fixtures/exchange_bin.ts create mode 100644 packages/sol-compiler/test/util/constants.ts create mode 100644 packages/sol-compiler/test/util/provider.ts create mode 100644 packages/sol-compiler/tsconfig.json create mode 100644 packages/sol-compiler/tslint.json delete mode 100644 packages/website/md/docs/deployer/installation.md delete mode 100644 packages/website/md/docs/deployer/introduction.md delete mode 100644 packages/website/md/docs/deployer/usage.md create mode 100644 packages/website/md/docs/sol-compiler/installation.md create mode 100644 packages/website/md/docs/sol-compiler/introduction.md create mode 100644 packages/website/md/docs/sol-compiler/usage.md delete mode 100644 packages/website/ts/containers/deployer_documentation.ts create mode 100644 packages/website/ts/containers/sol_compiler_documentation.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 0398705b0..dbd8b2926 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,7 +70,7 @@ jobs: key: coverage-contracts-{{ .Environment.CIRCLE_SHA1 }} paths: - ~/repo/packages/contracts/coverage/lcov.info - test-deployer: + test-sol-compiler: docker: - image: circleci/node:6.12 working_directory: ~/repo @@ -82,11 +82,11 @@ jobs: name: testrpc command: npm run testrpc -- --db testrpc_snapshot background: true - - run: yarn lerna:run --scope @0xproject/deployer test:circleci + - run: yarn lerna:run --scope @0xproject/sol-compiler test:circleci - save_cache: - key: coverage-deployer-{{ .Environment.CIRCLE_SHA1 }} + key: coverage-sol-compiler-{{ .Environment.CIRCLE_SHA1 }} paths: - - ~/repo/packages/deployer/coverage/lcov.info + - ~/repo/packages/sol-compiler/coverage/lcov.info test-rest: docker: - image: circleci/node:6.12 @@ -99,7 +99,7 @@ jobs: name: testrpc command: npm run testrpc -- --db testrpc_snapshot background: true - - run: yarn lerna:run --ignore contracts --ignore 0x.js --ignore @0xproject/deployer test:circleci + - run: yarn lerna:run --ignore contracts --ignore 0x.js --ignore @0xproject/sol-compiler test:circleci - save_cache: key: coverage-assert-{{ .Environment.CIRCLE_SHA1 }} paths: @@ -177,7 +177,7 @@ jobs: - coverage-sol-cov-{{ .Environment.CIRCLE_SHA1 }} - restore_cache: keys: - - coverage-deployer-{{ .Environment.CIRCLE_SHA1 }} + - coverage-sol-compiler-{{ .Environment.CIRCLE_SHA1 }} - restore_cache: keys: - coverage-0xjs-{{ .Environment.CIRCLE_SHA1 }} @@ -199,7 +199,7 @@ workflows: - test-contracts: requires: - build - - test-deployer: + - test-sol-compiler: requires: - build - test-rest: @@ -214,6 +214,6 @@ workflows: - submit-coverage: requires: - test-0xjs - - test-deployer + - test-sol-compiler - test-rest - test-contracts diff --git a/.gitignore b/.gitignore index dd2dd582c..89418ec02 100644 --- a/.gitignore +++ b/.gitignore @@ -85,8 +85,8 @@ packages/contracts/src/contract_wrappers/generated/ packages/metacoin/src/contract_wrappers packages/migrations/src/contract_wrappers -# solc-bin in deployer -packages/deployer/solc_bin/ +# solc-bin in sol-compiler +packages/sol-compiler/solc_bin/ # Monorepo scripts packages/*/scripts/ diff --git a/README.md b/README.md index 23cec4cbf..fcb7e8884 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This repository is a monorepo including the 0x protocol smart contracts and nume | [`@0xproject/assert`](/packages/assert) | [![npm](https://img.shields.io/npm/v/@0xproject/assert.svg)](https://www.npmjs.com/package/@0xproject/assert) | Type and schema assertions used by our packages | | [`@0xproject/base-contract`](/packages/base-contract) | [![npm](https://img.shields.io/npm/v/@0xproject/base-contract.svg)](https://www.npmjs.com/package/@0xproject/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts | | [`@0xproject/connect`](/packages/connect) | [![npm](https://img.shields.io/npm/v/@0xproject/connect.svg)](https://www.npmjs.com/package/@0xproject/connect) | A Javascript library for interacting with the Standard Relayer API | -| [`@0xproject/deployer`](/packages/deployer) | [![npm](https://img.shields.io/npm/v/@0xproject/deployer.svg)](https://www.npmjs.com/package/@0xproject/deployer) | Solidity project compiler and deployer framework | +| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-compiler.svg)](https://www.npmjs.com/package/@0xproject/sol-compiler) | Solidity project compiler framework | | [`@0xproject/dev-utils`](/packages/dev-utils) | [![npm](https://img.shields.io/npm/v/@0xproject/dev-utils.svg)](https://www.npmjs.com/package/@0xproject/dev-utils) | Dev utils to be shared across 0x projects and packages | | [`@0xproject/json-schemas`](/packages/json-schemas) | [![npm](https://img.shields.io/npm/v/@0xproject/json-schemas.svg)](https://www.npmjs.com/package/@0xproject/json-schemas) | 0x-related json schemas | | [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts | @@ -56,7 +56,7 @@ Dedicated documentation pages: * [0x Connect](https://0xproject.com/docs/connect) * [Smart contracts](https://0xproject.com/docs/contracts) * [Subproviders](https://0xproject.com/docs/subproviders) -* [Deployer](https://0xproject.com/docs/deployer) +* [Sol Compiler](https://0xproject.com/docs/sol-compiler) * [Web3-wrapper](https://0xproject.com/docs/web3-wrapper) * [JSON-schemas](https://0xproject.com/docs/json-schemas) * [Sol-cov](https://0xproject.com/docs/sol-cov) diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index a23e01938..8403d89cb 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -21,10 +21,9 @@ "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "update_artifacts": "for i in ${npm_package_config_contracts}; do copyfiles -u 4 ../migrations/artifacts/1.0.0/$i.json test/artifacts; done;", "clean": "shx rm -rf _bundles lib test_temp scripts", "build:umd:prod": "NODE_ENV=production webpack", - "build:commonjs": "tsc && yarn update_artifacts && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "build:commonjs": "tsc && copyfiles -u 2 './src/compact_artifacts/**/*.json' ./lib/src/compact_artifacts && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "test:commonjs": "run-s build:commonjs run_mocha", "run_mocha": "mocha lib/test/**/*_test.js lib/test/global_hooks.js --timeout 10000 --bail --exit", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", @@ -34,7 +33,6 @@ }, "config": { "compact_artifacts": "Exchange DummyToken ZRXToken Token EtherToken TokenTransferProxy TokenRegistry", - "contracts": "Exchange DummyToken ZRXToken Token WETH9 TokenTransferProxy MultiSigWallet MultiSigWalletWithTimeLock MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress MaliciousToken TokenRegistry Arbitrage EtherDelta AccountLevels", "postpublish": { "assets": [ "packages/0x.js/_bundles/index.js", @@ -61,7 +59,7 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0xproject/deployer": "^0.4.3", + "@0xproject/sol-compiler": "^0.4.3", "@0xproject/dev-utils": "^0.4.1", "@0xproject/migrations": "^0.0.5", "@0xproject/monorepo-scripts": "^0.1.19", diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index 4aa9824e1..3d2f1c608 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -11,6 +11,6 @@ before('migrate contracts', async function() { gas: devConstants.GAS_ESTIMATE, from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const artifactsDir = path.resolve('test', 'artifacts'); + const artifactsDir = '../migrations/artifacts/1.0.0'; await runMigrationsAsync(provider, artifactsDir, defaults); }); diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 7125171b9..a280f2e63 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -114,7 +114,7 @@ for (const abiFileName of abiFileNames) { if (_.isUndefined(ABI)) { logUtils.log(`${chalk.red(`ABI not found in ${abiFileName}.`)}`); logUtils.log( - `Please make sure your ABI file is either an array with ABI entries or a truffle artifact or 0x deployer artifact`, + `Please make sure your ABI file is either an array with ABI entries or a truffle artifact or 0x sol-compiler artifact`, ); process.exit(1); } diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 8d0f4e184..63dc4780d 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -7,7 +7,7 @@ import { BaseContract } from '@0xproject/base-contract'; import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types'; import { BigNumber, classUtils, promisify } from '@0xproject/utils'; -import { ContractArtifact } from '@0xproject/deployer'; +import { ContractArtifact } from '@0xproject/sol-compiler'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethers from 'ethers'; import * as _ from 'lodash'; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 6c91b0ade..7efcd58a0 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -16,7 +16,7 @@ "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", "run_mocha": "mocha 'lib/test/**/*.js' --timeout 100000 --bail --exit", "compile:comment": "Yarn workspaces do not link binaries correctly so we need to reference them directly https://github.com/yarnpkg/yarn/issues/3846", - "compile": "node ../deployer/lib/src/cli.js compile", + "compile": "node ../sol-compiler/lib/src/cli.js", "clean": "shx rm -rf ./lib", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", "lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'", @@ -60,7 +60,7 @@ }, "dependencies": { "0x.js": "^0.37.2", - "@0xproject/deployer": "^0.4.3", + "@0xproject/sol-compiler": "^0.4.3", "@0xproject/types": "^0.6.3", "@0xproject/typescript-typings": "^0.3.1", "@0xproject/utils": "^0.6.1", diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index 226df6c58..8511b0082 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -1,4 +1,4 @@ -import { ContractArtifact } from '@0xproject/deployer'; +import { ContractArtifact } from '@0xproject/sol-compiler'; import * as AccountLevels from '../src/artifacts/AccountLevels.json'; import * as Arbitrage from '../src/artifacts/Arbitrage.json'; diff --git a/packages/deployer/.npmignore b/packages/deployer/.npmignore deleted file mode 100644 index 44df80fad..000000000 --- a/packages/deployer/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -.* -yarn-error.log -/src/ -/scripts/ -test/ -tsconfig.json -/lib/src/monorepo_scripts/ diff --git a/packages/deployer/CHANGELOG.json b/packages/deployer/CHANGELOG.json deleted file mode 100644 index 3f18ae121..000000000 --- a/packages/deployer/CHANGELOG.json +++ /dev/null @@ -1,151 +0,0 @@ -[ - { - "timestamp": 1525477860, - "version": "0.4.3", - "changes": [ - { - "note": "Dependencies updated" - } - ] - }, - { - "version": "0.4.2", - "changes": [ - { - "note": "Add support for solidity 0.4.23", - "pr": 545 - } - ], - "timestamp": 1525428773 - }, - { - "version": "0.4.1", - "changes": [ - { - "note": "Add support for solidity 0.4.22", - "pr": 531 - } - ], - "timestamp": 1524044013 - }, - { - "version": "0.4.0", - "changes": [ - { - "note": "Changed the config key `web3Provider` to `provider` to be consistent with other tools", - "pr": 501 - } - ], - "timestamp": 1523462196 - }, - { - "version": "0.3.5", - "changes": [ - { - "note": "Don't try to write contract artifact if an error occured", - "pr": 485 - } - ], - "timestamp": 1522673609 - }, - { - "version": "0.3.4", - "changes": [ - { - "note": "Create solc_bin directory if does not exist before attempting to compile", - "pr": 491 - } - ], - "timestamp": 1522658513 - }, - { - "version": "0.3.1", - "changes": [ - { - "note": "Add TS types for `yargs`" - } - ], - "timestamp": 1521298800 - }, - { - "version": "0.3.0", - "changes": [ - { - "note": "Add support for Solidity 0.4.20 and 0.4.21" - }, - { - "note": "Replace `jsonrpcPort` config with `jsonrpcUrl`", - "pr": 426 - }, - { - "note": "Replace `jsonrpc-port` CLI option with `jsonrpc-url`", - "pr": 426 - }, - { - "note": "Export the `Compiler`", - "pr": 426 - }, - { - "note": "Load solc from remote source instead of having it locally", - "pr": 426 - }, - { - "note": - "Add `bytecode`, `runtime_bytecode`, `source_map`, `source_map_runtime` and `sources` fields to artifacts", - "pr": 426 - }, - { - "note": "Remove 0x-specific `migrate` command", - "pr": 426 - }, - { - "note": - "Allow deployer to accept a provider instead of port and host. This makes it possible to run it with in-process ganache-core", - "pr": 426 - }, - { - "note": "Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package", - "pr": 452 - }, - { - "note": "Add `#!/usr/bin/env node` pragma above `cli.ts` script to fix command-line error." - } - ], - "timestamp": 1521298800 - }, - { - "version": "0.2.0", - "changes": [ - { - "note": "Check dependencies when determining if contracts should be recompiled", - "pr": 408 - }, - { - "note": - "Improve an error message for when deployer is supplied with an incorrect number of constructor arguments", - "pr": 419 - } - ], - "timestamp": 1520089200 - }, - { - "version": "0.1.0", - "changes": [ - { - "note": "Add the ability to pass in specific contracts to compile in CLI", - "pr": 400 - } - ], - "timestamp": 1518706800 - }, - { - "version": "0.0.8", - "changes": [ - { - "note": "Fix publishing issue where .npmignore was not properly excluding undesired content", - "pr": 389 - } - ], - "timestamp": 1518102000 - } -] diff --git a/packages/deployer/CHANGELOG.md b/packages/deployer/CHANGELOG.md deleted file mode 100644 index 4eb0ed453..000000000 --- a/packages/deployer/CHANGELOG.md +++ /dev/null @@ -1,60 +0,0 @@ - - -CHANGELOG - -## v0.4.3 - _May 5, 2018_ - - * Dependencies updated - -## v0.4.2 - _May 4, 2018_ - - * Add support for solidity 0.4.23 (#545) - -## v0.4.1 - _April 18, 2018_ - - * Add support for solidity 0.4.22 (#531) - -## v0.4.0 - _April 11, 2018_ - - * Changed the config key `web3Provider` to `provider` to be consistent with other tools (#501) - -## v0.3.5 - _April 2, 2018_ - - * Don't try to write contract artifact if an error occured (#485) - -## v0.3.4 - _April 2, 2018_ - - * Create solc_bin directory if does not exist before attempting to compile (#491) - -## v0.3.1 - _March 17, 2018_ - - * Add TS types for `yargs` - -## v0.3.0 - _March 17, 2018_ - - * Add support for Solidity 0.4.20 and 0.4.21 - * Replace `jsonrpcPort` config with `jsonrpcUrl` (#426) - * Replace `jsonrpc-port` CLI option with `jsonrpc-url` (#426) - * Export the `Compiler` (#426) - * Load solc from remote source instead of having it locally (#426) - * Add `bytecode`, `runtime_bytecode`, `source_map`, `source_map_runtime` and `sources` fields to artifacts (#426) - * Remove 0x-specific `migrate` command (#426) - * Allow deployer to accept a provider instead of port and host. This makes it possible to run it with in-process ganache-core (#426) - * Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package (#452) - * Add `#!/usr/bin/env node` pragma above `cli.ts` script to fix command-line error. - -## v0.2.0 - _March 3, 2018_ - - * Check dependencies when determining if contracts should be recompiled (#408) - * Improve an error message for when deployer is supplied with an incorrect number of constructor arguments (#419) - -## v0.1.0 - _February 15, 2018_ - - * Add the ability to pass in specific contracts to compile in CLI (#400) - -## v0.0.8 - _February 8, 2018_ - - * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/deployer/README.md b/packages/deployer/README.md deleted file mode 100644 index 4c7de2cb0..000000000 --- a/packages/deployer/README.md +++ /dev/null @@ -1,103 +0,0 @@ -## @0xproject/deployer - -This repository contains a CLI tool that facilitates compiling and deployment of smart contracts. - -### Read the [Documentation](https://0xproject.com/docs/deployer). - -## Installation - -#### CLI Installation - -```bash -yarn global add @0xproject/deployer -``` - -#### API Installation - -```bash -yarn add @0xproject/deployer -``` - -If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: - -```json -"compilerOptions": { - "typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"], -} -``` - -**Import** - -```typescript -import { Compiler } from '@0xproject/deployer'; -``` - -or - -```javascript -var Compiler = require('@0xproject/deployer').Compiler; -``` - -## Contributing - -We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. - -Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. - -### Install dependencies - -If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: - -```bash -yarn config set workspaces-experimental true -``` - -Then install dependencies - -```bash -yarn install -``` - -### Build - -If this is your **first** time building this package, you must first build **all** packages within the monorepo. This is because packages that depend on other packages located inside this monorepo are symlinked when run from **within** the monorepo. This allows you to make changes across multiple packages without first publishing dependent packages to NPM. To build all packages, run the following from the monorepo root directory: - -```bash -yarn lerna:rebuild -``` - -Or continuously rebuild on change: - -```bash -yarn dev -``` - -You can also build this specific package by running the following from within its directory: - -```bash -yarn build -``` - -or continuously rebuild on change: - -```bash -yarn build:watch -``` - -### Clean - -```bash -yarn clean -``` - -### Lint - -```bash -yarn lint -``` - -### Run Tests - -```bash -yarn test -``` diff --git a/packages/deployer/coverage/.gitkeep b/packages/deployer/coverage/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/deployer/package.json b/packages/deployer/package.json deleted file mode 100644 index 73bcd52f1..000000000 --- a/packages/deployer/package.json +++ /dev/null @@ -1,92 +0,0 @@ -{ - "name": "@0xproject/deployer", - "version": "0.4.3", - "description": "Smart contract deployer of 0x protocol", - "main": "lib/src/index.js", - "types": "lib/src/index.d.ts", - "scripts": { - "build:watch": "tsc -w", - "build": "yarn clean && copyfiles 'test/fixtures/contracts/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", - "test": "run-s build run_mocha", - "run_mocha": "mocha lib/test/*_test.js --bail --exit", - "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", - "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", - "compile": "npm run build; node lib/src/cli.js compile", - "clean": "shx rm -rf lib scripts", - "migrate": "npm run build; node lib/src/cli.js migrate", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", - "test:circleci": "yarn test:coverage", - "docs:stage": "yarn build && node ./scripts/stage_docs.js", - "manual:postpublish": "yarn build; node ./scripts/postpublish.js", - "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", - "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" - }, - "config": { - "postpublish": { - "assets": [], - "docPublishConfigs": { - "extraFileIncludes": [ - "../types/src/index.ts" - ], - "s3BucketPath": "s3://doc-jsons/deployer/", - "s3StagingBucketPath": "s3://staging-doc-jsons/deployer/" - } - } - }, - "bin": { - "0x-deployer": "lib/src/cli.js" - }, - "repository": { - "type": "git", - "url": "https://github.com/0xProject/0x-monorepo.git" - }, - "author": "Amir Bandeali", - "license": "Apache-2.0", - "bugs": { - "url": "https://github.com/0xProject/0x-monorepo/issues" - }, - "homepage": "https://github.com/0xProject/0x-monorepo/packages/deployer/README.md", - "devDependencies": { - "@0xproject/dev-utils": "^0.4.1", - "@0xproject/monorepo-scripts": "^0.1.19", - "@0xproject/tslint-config": "^0.4.17", - "@types/require-from-string": "^1.2.0", - "@types/semver": "^5.5.0", - "chai": "^4.0.1", - "chai-as-promised": "^7.1.0", - "copyfiles": "^1.2.0", - "dirty-chai": "^2.0.1", - "mocha": "^4.0.1", - "npm-run-all": "^4.1.2", - "nyc": "^11.0.1", - "shx": "^0.2.2", - "tslint": "5.8.0", - "typedoc": "0xProject/typedoc", - "types-bn": "^0.0.1", - "typescript": "2.7.1", - "web3-typescript-typings": "^0.10.2", - "zeppelin-solidity": "1.8.0" - }, - "dependencies": { - "@0xproject/json-schemas": "^0.7.23", - "@0xproject/sol-resolver": "^0.0.4", - "@0xproject/types": "^0.6.3", - "@0xproject/typescript-typings": "^0.3.1", - "@0xproject/utils": "^0.6.1", - "@0xproject/web3-wrapper": "^0.6.3", - "@types/yargs": "^11.0.0", - "chalk": "^2.3.0", - "ethereumjs-util": "^5.1.1", - "isomorphic-fetch": "^2.2.1", - "lodash": "^4.17.4", - "require-from-string": "^2.0.1", - "semver": "^5.5.0", - "solc": "^0.4.23", - "web3": "^0.20.0", - "web3-eth-abi": "^1.0.0-beta.24", - "yargs": "^10.0.3" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/deployer/solc_bin/.gitkeep b/packages/deployer/solc_bin/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/deployer/src/cli.ts b/packages/deployer/src/cli.ts deleted file mode 100644 index 2412b8d34..000000000 --- a/packages/deployer/src/cli.ts +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env node -// We need the above pragma since this script will be run as a command-line tool. - -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; -import * as _ from 'lodash'; -import * as path from 'path'; -import * as Web3 from 'web3'; -import * as yargs from 'yargs'; - -import { Compiler } from './compiler'; -import { constants } from './utils/constants'; -import { CompilerOptions } from './utils/types'; - -const DEFAULT_CONTRACTS_LIST = '*'; -const SEPARATOR = ','; - -(async () => { - const argv = yargs - .option('contracts-dir', { - type: 'string', - description: 'path of contracts directory to compile', - }) - .option('artifacts-dir', { - type: 'string', - description: 'path to write contracts artifacts to', - }) - .option('contracts', { - type: 'string', - default: DEFAULT_CONTRACTS_LIST, - description: 'comma separated list of contracts to compile', - }) - .help().argv; - const opts: CompilerOptions = { - contractsDir: argv.contractsDir, - artifactsDir: argv.artifactsDir, - contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), - }; - const compiler = new Compiler(opts); - await compiler.compileAsync(); -})(); diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts deleted file mode 100644 index efb30091b..000000000 --- a/packages/deployer/src/compiler.ts +++ /dev/null @@ -1,276 +0,0 @@ -import { - ContractSource, - ContractSources, - EnumerableResolver, - FallthroughResolver, - FSResolver, - NameResolver, - NPMResolver, - RelativeFSResolver, - Resolver, - URLResolver, -} from '@0xproject/sol-resolver'; -import { ContractAbi } from '@0xproject/types'; -import { logUtils, promisify } from '@0xproject/utils'; -import chalk from 'chalk'; -import * as ethUtil from 'ethereumjs-util'; -import * as fs from 'fs'; -import 'isomorphic-fetch'; -import * as _ from 'lodash'; -import * as path from 'path'; -import * as requireFromString from 'require-from-string'; -import * as semver from 'semver'; -import solc = require('solc'); - -import { binPaths } from './solc/bin_paths'; -import { - createDirIfDoesNotExistAsync, - getContractArtifactIfExistsAsync, - getNormalizedErrMsg, - parseDependencies, - parseSolidityVersionRange, -} from './utils/compiler'; -import { constants } from './utils/constants'; -import { fsWrapper } from './utils/fs_wrapper'; -import { - CompilerOptions, - ContractArtifact, - ContractNetworkData, - ContractNetworks, - ContractSourceData, - ContractSpecificSourceData, - ContractVersionData, -} from './utils/types'; -import { utils } from './utils/utils'; - -type TYPE_ALL_FILES_IDENTIFIER = '*'; -const ALL_CONTRACTS_IDENTIFIER = '*'; -const ALL_FILES_IDENTIFIER = '*'; -const SOLC_BIN_DIR = path.join(__dirname, '..', '..', 'solc_bin'); -const DEFAULT_CONTRACTS_DIR = path.resolve('contracts'); -const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts'); -// Solc compiler settings cannot be configured from the commandline. -// If you need this configured, please create a `compiler.json` config file -// with your desired configurations. -const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = { - optimizer: { - enabled: false, - }, - outputSelection: { - [ALL_FILES_IDENTIFIER]: { - [ALL_CONTRACTS_IDENTIFIER]: ['abi', 'evm.bytecode.object'], - }, - }, -}; -const CONFIG_FILE = 'compiler.json'; - -/** - * The Compiler facilitates compiling Solidity smart contracts and saves the results - * to artifact files. - */ -export class Compiler { - private _resolver: Resolver; - private _nameResolver: NameResolver; - private _contractsDir: string; - private _compilerSettings: solc.CompilerSettings; - private _artifactsDir: string; - private _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER; - /** - * Instantiates a new instance of the Compiler class. - * @return An instance of the Compiler class. - */ - constructor(opts: CompilerOptions) { - // TODO: Look for config file in parent directories if not found in current directory - const config: CompilerOptions = fs.existsSync(CONFIG_FILE) - ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString()) - : {}; - this._contractsDir = opts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR; - this._compilerSettings = opts.compilerSettings || config.compilerSettings || DEFAULT_COMPILER_SETTINGS; - this._artifactsDir = opts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR; - this._specifiedContracts = opts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER; - this._nameResolver = new NameResolver(path.resolve(this._contractsDir)); - const resolver = new FallthroughResolver(); - resolver.appendResolver(new URLResolver()); - const packagePath = path.resolve(''); - resolver.appendResolver(new NPMResolver(packagePath)); - resolver.appendResolver(new RelativeFSResolver(this._contractsDir)); - resolver.appendResolver(new FSResolver()); - resolver.appendResolver(this._nameResolver); - this._resolver = resolver; - } - /** - * Compiles selected Solidity files found in `contractsDir` and writes JSON artifacts to `artifactsDir`. - */ - public async compileAsync(): Promise { - await createDirIfDoesNotExistAsync(this._artifactsDir); - await createDirIfDoesNotExistAsync(SOLC_BIN_DIR); - let contractNamesToCompile: string[] = []; - if (this._specifiedContracts === ALL_CONTRACTS_IDENTIFIER) { - const allContracts = this._nameResolver.getAll(); - contractNamesToCompile = _.map(allContracts, contractSource => - path.basename(contractSource.path, constants.SOLIDITY_FILE_EXTENSION), - ); - } else { - contractNamesToCompile = this._specifiedContracts; - } - for (const contractNameToCompile of contractNamesToCompile) { - await this._compileContractAsync(contractNameToCompile); - } - } - /** - * Compiles contract and saves artifact to artifactsDir. - * @param fileName Name of contract with '.sol' extension. - */ - private async _compileContractAsync(contractName: string): Promise { - const contractSource = this._resolver.resolve(contractName); - const absoluteContractPath = path.join(this._contractsDir, contractSource.path); - const currentArtifactIfExists = await getContractArtifactIfExistsAsync(this._artifactsDir, contractName); - const sourceTreeHashHex = `0x${this._getSourceTreeHash(absoluteContractPath).toString('hex')}`; - let shouldCompile = false; - if (_.isUndefined(currentArtifactIfExists)) { - shouldCompile = true; - } else { - const currentArtifact = currentArtifactIfExists as ContractArtifact; - const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; - const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings); - const didSourceChange = currentArtifact.sourceTreeHashHex !== sourceTreeHashHex; - shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; - } - if (!shouldCompile) { - return; - } - const solcVersionRange = parseSolidityVersionRange(contractSource.source); - const availableCompilerVersions = _.keys(binPaths); - const solcVersion = semver.maxSatisfying(availableCompilerVersions, solcVersionRange); - const fullSolcVersion = binPaths[solcVersion]; - const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion); - let solcjs: string; - const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename); - if (isCompilerAvailableLocally) { - solcjs = fs.readFileSync(compilerBinFilename).toString(); - } else { - logUtils.log(`Downloading ${fullSolcVersion}...`); - const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`; - const response = await fetch(url); - if (response.status !== 200) { - throw new Error(`Failed to load ${fullSolcVersion}`); - } - solcjs = await response.text(); - fs.writeFileSync(compilerBinFilename, solcjs); - } - const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename)); - - logUtils.log(`Compiling ${contractName} with Solidity v${solcVersion}...`); - const source = contractSource.source; - const standardInput: solc.StandardInput = { - language: 'Solidity', - sources: { - [contractSource.path]: { - content: contractSource.source, - }, - }, - settings: this._compilerSettings, - }; - const compiled: solc.StandardOutput = JSON.parse( - solcInstance.compileStandardWrapper(JSON.stringify(standardInput), importPath => { - const sourceCodeIfExists = this._resolver.resolve(importPath); - return { contents: sourceCodeIfExists.source }; - }), - ); - - if (!_.isUndefined(compiled.errors)) { - const SOLIDITY_WARNING = 'warning'; - const errors = _.filter(compiled.errors, entry => entry.severity !== SOLIDITY_WARNING); - const warnings = _.filter(compiled.errors, entry => entry.severity === SOLIDITY_WARNING); - if (!_.isEmpty(errors)) { - errors.forEach(error => { - const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message); - logUtils.log(chalk.red(normalizedErrMsg)); - }); - process.exit(1); - } else { - warnings.forEach(warning => { - const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message); - logUtils.log(chalk.yellow(normalizedWarningMsg)); - }); - } - } - const compiledData = compiled.contracts[contractSource.path][contractName]; - if (_.isUndefined(compiledData)) { - throw new Error( - `Contract ${contractName} not found in ${ - contractSource.path - }. Please make sure your contract has the same name as it's file name`, - ); - } - if (!_.isUndefined(compiledData.evm)) { - if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) { - compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object); - } - if ( - !_.isUndefined(compiledData.evm.deployedBytecode) && - !_.isUndefined(compiledData.evm.deployedBytecode.object) - ) { - compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix( - compiledData.evm.deployedBytecode.object, - ); - } - } - - const sourceCodes = _.mapValues( - compiled.sources, - (_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source, - ); - const contractVersion: ContractVersionData = { - compilerOutput: compiledData, - sources: compiled.sources, - sourceCodes, - sourceTreeHashHex, - compiler: { - name: 'solc', - version: solcVersion, - settings: this._compilerSettings, - }, - }; - - let newArtifact: ContractArtifact; - if (!_.isUndefined(currentArtifactIfExists)) { - const currentArtifact = currentArtifactIfExists as ContractArtifact; - newArtifact = { - ...currentArtifact, - ...contractVersion, - }; - } else { - newArtifact = { - schemaVersion: constants.LATEST_ARTIFACT_VERSION, - contractName, - ...contractVersion, - networks: {}, - }; - } - - const artifactString = utils.stringifyWithFormatting(newArtifact); - const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; - await fsWrapper.writeFileAsync(currentArtifactPath, artifactString); - logUtils.log(`${contractName} artifact saved!`); - } - /** - * Gets the source tree hash for a file and its dependencies. - * @param fileName Name of contract file. - */ - private _getSourceTreeHash(importPath: string): Buffer { - const contractSource = this._resolver.resolve(importPath); - const dependencies = parseDependencies(contractSource); - const sourceHash = ethUtil.sha3(contractSource.source); - if (dependencies.length === 0) { - return sourceHash; - } else { - const dependencySourceTreeHashes = _.map(dependencies, (dependency: string) => - this._getSourceTreeHash(dependency), - ); - const sourceTreeHashesBuffer = Buffer.concat([sourceHash, ...dependencySourceTreeHashes]); - const sourceTreeHash = ethUtil.sha3(sourceTreeHashesBuffer); - return sourceTreeHash; - } - } -} diff --git a/packages/deployer/src/globals.d.ts b/packages/deployer/src/globals.d.ts deleted file mode 100644 index 94e63a32d..000000000 --- a/packages/deployer/src/globals.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module '*.json' { - const json: any; - /* tslint:disable */ - export default json; - /* tslint:enable */ -} diff --git a/packages/deployer/src/index.ts b/packages/deployer/src/index.ts deleted file mode 100644 index 4b4c51de2..000000000 --- a/packages/deployer/src/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { Compiler } from './compiler'; -export { ContractArtifact, ContractNetworks } from './utils/types'; diff --git a/packages/deployer/src/monorepo_scripts/postpublish.ts b/packages/deployer/src/monorepo_scripts/postpublish.ts deleted file mode 100644 index dcb99d0f7..000000000 --- a/packages/deployer/src/monorepo_scripts/postpublish.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { postpublishUtils } from '@0xproject/monorepo-scripts'; - -import * as packageJSON from '../package.json'; -import * as tsConfigJSON from '../tsconfig.json'; - -const cwd = `${__dirname}/..`; -// tslint:disable-next-line:no-floating-promises -postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/deployer/src/monorepo_scripts/stage_docs.ts b/packages/deployer/src/monorepo_scripts/stage_docs.ts deleted file mode 100644 index e732ac8eb..000000000 --- a/packages/deployer/src/monorepo_scripts/stage_docs.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { postpublishUtils } from '@0xproject/monorepo-scripts'; - -import * as packageJSON from '../package.json'; -import * as tsConfigJSON from '../tsconfig.json'; - -const cwd = `${__dirname}/..`; -// tslint:disable-next-line:no-floating-promises -postpublishUtils.publishDocsToStagingAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/deployer/src/solc/bin_paths.ts b/packages/deployer/src/solc/bin_paths.ts deleted file mode 100644 index 1b5e8c6f1..000000000 --- a/packages/deployer/src/solc/bin_paths.ts +++ /dev/null @@ -1,20 +0,0 @@ -export interface BinaryPaths { - [key: string]: string; -} - -export const binPaths: BinaryPaths = { - '0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js', - '0.4.11': 'soljson-v0.4.11+commit.68ef5810.js', - '0.4.12': 'soljson-v0.4.12+commit.194ff033.js', - '0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js', - '0.4.14': 'soljson-v0.4.14+commit.c2215d46.js', - '0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js', - '0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js', - '0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js', - '0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js', - '0.4.19': 'soljson-v0.4.19+commit.c4cbbb05.js', - '0.4.20': 'soljson-v0.4.20+commit.3155dd80.js', - '0.4.21': 'soljson-v0.4.21+commit.dfe3193c.js', - '0.4.22': 'soljson-v0.4.22+commit.4cb486ee.js', - '0.4.23': 'soljson-v0.4.23+commit.124ca40d.js', -}; diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts deleted file mode 100644 index c571b2581..000000000 --- a/packages/deployer/src/utils/compiler.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { ContractSource, ContractSources } from '@0xproject/sol-resolver'; -import { logUtils } from '@0xproject/utils'; -import * as _ from 'lodash'; -import * as path from 'path'; -import * as solc from 'solc'; - -import { constants } from './constants'; -import { fsWrapper } from './fs_wrapper'; -import { ContractArtifact } from './types'; - -/** - * Gets contract data on network or returns if an artifact does not exist. - * @param artifactsDir Path to the artifacts directory. - * @param contractName Name of contract. - * @return Contract data on network or undefined. - */ -export async function getContractArtifactIfExistsAsync( - artifactsDir: string, - contractName: string, -): Promise { - let contractArtifact; - const currentArtifactPath = `${artifactsDir}/${contractName}.json`; - try { - const opts = { - encoding: 'utf8', - }; - const contractArtifactString = await fsWrapper.readFileAsync(currentArtifactPath, opts); - contractArtifact = JSON.parse(contractArtifactString); - return contractArtifact; - } catch (err) { - logUtils.log(`Artifact for ${contractName} does not exist`); - return undefined; - } -} - -/** - * Creates a directory if it does not already exist. - * @param artifactsDir Path to the directory. - */ -export async function createDirIfDoesNotExistAsync(dirPath: string): Promise { - if (!fsWrapper.doesPathExistSync(dirPath)) { - logUtils.log(`Creating directory at ${dirPath}...`); - await fsWrapper.mkdirAsync(dirPath); - } -} - -/** - * Searches Solidity source code for compiler version range. - * @param source Source code of contract. - * @return Solc compiler version range. - */ -export function parseSolidityVersionRange(source: string): string { - const SOLIDITY_VERSION_RANGE_REGEX = /pragma\s+solidity\s+(.*);/; - const solcVersionRangeMatch = source.match(SOLIDITY_VERSION_RANGE_REGEX); - if (_.isNull(solcVersionRangeMatch)) { - throw new Error('Could not find Solidity version range in source'); - } - const solcVersionRange = solcVersionRangeMatch[1]; - return solcVersionRange; -} - -/** - * Normalizes the path found in the error message. - * Example: converts 'base/Token.sol:6:46: Warning: Unused local variable' - * to 'Token.sol:6:46: Warning: Unused local variable' - * This is used to prevent logging the same error multiple times. - * @param errMsg An error message from the compiled output. - * @return The error message with directories truncated from the contract path. - */ -export function getNormalizedErrMsg(errMsg: string): string { - const SOLIDITY_FILE_EXTENSION_REGEX = /(.*\.sol)/; - const errPathMatch = errMsg.match(SOLIDITY_FILE_EXTENSION_REGEX); - if (_.isNull(errPathMatch)) { - throw new Error('Could not find a path in error message'); - } - const errPath = errPathMatch[0]; - const baseContract = path.basename(errPath); - const normalizedErrMsg = errMsg.replace(errPath, baseContract); - return normalizedErrMsg; -} - -/** - * Parses the contract source code and extracts the dendencies - * @param source Contract source code - * @return List of dependendencies - */ -export function parseDependencies(contractSource: ContractSource): string[] { - // TODO: Use a proper parser - const source = contractSource.source; - const IMPORT_REGEX = /(import\s)/; - const DEPENDENCY_PATH_REGEX = /"([^"]+)"/; // Source: https://github.com/BlockChainCompany/soljitsu/blob/master/lib/shared.js - const dependencies: string[] = []; - const lines = source.split('\n'); - _.forEach(lines, line => { - if (!_.isNull(line.match(IMPORT_REGEX))) { - const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX); - if (!_.isNull(dependencyMatch)) { - let dependencyPath = dependencyMatch[1]; - if (dependencyPath.startsWith('.')) { - dependencyPath = path.join(path.dirname(contractSource.path), dependencyPath); - } - dependencies.push(dependencyPath); - } - } - }); - return dependencies; -} diff --git a/packages/deployer/src/utils/constants.ts b/packages/deployer/src/utils/constants.ts deleted file mode 100644 index df2ddb3b2..000000000 --- a/packages/deployer/src/utils/constants.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const constants = { - SOLIDITY_FILE_EXTENSION: '.sol', - BASE_COMPILER_URL: 'https://ethereum.github.io/solc-bin/bin/', - LATEST_ARTIFACT_VERSION: '2.0.0', -}; diff --git a/packages/deployer/src/utils/encoder.ts b/packages/deployer/src/utils/encoder.ts deleted file mode 100644 index 806efbbca..000000000 --- a/packages/deployer/src/utils/encoder.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types'; -import * as _ from 'lodash'; -import * as web3Abi from 'web3-eth-abi'; - -export const encoder = { - encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string { - const constructorTypes: string[] = []; - _.each(abi, (element: AbiDefinition) => { - if (element.type === AbiType.Constructor) { - _.each(element.inputs, (input: DataItem) => { - constructorTypes.push(input.type); - }); - } - }); - const encodedParameters = web3Abi.encodeParameters(constructorTypes, args); - return encodedParameters; - }, -}; diff --git a/packages/deployer/src/utils/fs_wrapper.ts b/packages/deployer/src/utils/fs_wrapper.ts deleted file mode 100644 index e02c83f27..000000000 --- a/packages/deployer/src/utils/fs_wrapper.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { promisify } from '@0xproject/utils'; -import * as fs from 'fs'; - -export const fsWrapper = { - readdirAsync: promisify(fs.readdir), - readFileAsync: promisify(fs.readFile), - writeFileAsync: promisify(fs.writeFile), - mkdirAsync: promisify(fs.mkdir), - doesPathExistSync: fs.existsSync, - rmdirSync: fs.rmdirSync, - removeFileAsync: promisify(fs.unlink), -}; diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts deleted file mode 100644 index b12a11b79..000000000 --- a/packages/deployer/src/utils/types.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { ContractAbi, Provider, TxData } from '@0xproject/types'; -import * as solc from 'solc'; -import * as Web3 from 'web3'; -import * as yargs from 'yargs'; - -export enum AbiType { - Function = 'function', - Constructor = 'constructor', - Event = 'event', - Fallback = 'fallback', -} - -export interface ContractArtifact extends ContractVersionData { - schemaVersion: string; - contractName: string; - networks: ContractNetworks; -} - -export interface ContractVersionData { - compiler: { - name: 'solc'; - version: string; - settings: solc.CompilerSettings; - }; - sources: { - [sourceName: string]: { - id: number; - }; - }; - sourceCodes: { - [sourceName: string]: string; - }; - sourceTreeHashHex: string; - compilerOutput: solc.StandardContractOutput; -} - -export interface ContractNetworks { - [networkId: number]: ContractNetworkData; -} - -export interface ContractNetworkData { - address: string; - links: { - [linkName: string]: string; - }; - constructorArgs: string; -} - -export interface SolcErrors { - [key: string]: boolean; -} - -export interface CompilerOptions { - contractsDir?: string; - artifactsDir?: string; - compilerSettings?: solc.CompilerSettings; - contracts?: string[] | '*'; -} - -export interface ContractSourceData { - [contractName: string]: ContractSpecificSourceData; -} - -export interface ContractSpecificSourceData { - solcVersionRange: string; - sourceHash: Buffer; - sourceTreeHash: Buffer; -} - -export interface Token { - address?: string; - name: string; - symbol: string; - decimals: number; - ipfsHash: string; - swarmHash: string; -} - -export type DoneCallback = (err?: Error) => void; diff --git a/packages/deployer/src/utils/utils.ts b/packages/deployer/src/utils/utils.ts deleted file mode 100644 index 9b1e59f9d..000000000 --- a/packages/deployer/src/utils/utils.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const utils = { - stringifyWithFormatting(obj: any): string { - const jsonReplacer: null = null; - const numberOfJsonSpaces = 4; - const stringifiedObj = JSON.stringify(obj, jsonReplacer, numberOfJsonSpaces); - return stringifiedObj; - }, -}; diff --git a/packages/deployer/test/compiler_test.ts b/packages/deployer/test/compiler_test.ts deleted file mode 100644 index 9baf433d4..000000000 --- a/packages/deployer/test/compiler_test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as chai from 'chai'; -import 'mocha'; - -import { Compiler } from '../src/compiler'; -import { fsWrapper } from '../src/utils/fs_wrapper'; -import { CompilerOptions, ContractArtifact, ContractNetworkData, DoneCallback } from '../src/utils/types'; - -import { exchange_binary } from './fixtures/exchange_bin'; -import { constants } from './util/constants'; - -const expect = chai.expect; - -describe('#Compiler', function() { - this.timeout(constants.timeoutMs); - const artifactsDir = `${__dirname}/fixtures/artifacts`; - const contractsDir = `${__dirname}/fixtures/contracts`; - const exchangeArtifactPath = `${artifactsDir}/Exchange.json`; - const compilerOpts: CompilerOptions = { - artifactsDir, - contractsDir, - contracts: constants.contracts, - }; - const compiler = new Compiler(compilerOpts); - beforeEach((done: DoneCallback) => { - (async () => { - if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) { - await fsWrapper.removeFileAsync(exchangeArtifactPath); - } - await compiler.compileAsync(); - done(); - })().catch(done); - }); - it('should create an Exchange artifact with the correct unlinked binary', async () => { - const opts = { - encoding: 'utf8', - }; - const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); - const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); - // The last 43 bytes of the binaries are metadata which may not be equivalent - const unlinkedBinaryWithoutMetadata = exchangeArtifact.compilerOutput.evm.bytecode.object.slice(0, -86); - const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -86); - expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata); - }); -}); diff --git a/packages/deployer/test/compiler_utils_test.ts b/packages/deployer/test/compiler_utils_test.ts deleted file mode 100644 index 393f6d3f3..000000000 --- a/packages/deployer/test/compiler_utils_test.ts +++ /dev/null @@ -1,83 +0,0 @@ -import * as chai from 'chai'; -import * as dirtyChai from 'dirty-chai'; -import * as _ from 'lodash'; -import 'mocha'; - -import { - createDirIfDoesNotExistAsync, - getNormalizedErrMsg, - parseDependencies, - parseSolidityVersionRange, -} from '../src/utils/compiler'; -import { fsWrapper } from '../src/utils/fs_wrapper'; - -chai.use(dirtyChai); -const expect = chai.expect; - -describe('Compiler utils', () => { - describe('#getNormalizedErrorMessage', () => { - it('normalizes the error message', () => { - const errMsg = 'base/Token.sol:6:46: Warning: Unused local variable'; - const normalizedErrMsg = getNormalizedErrMsg(errMsg); - expect(normalizedErrMsg).to.be.equal('Token.sol:6:46: Warning: Unused local variable'); - }); - }); - describe('#createDirIfDoesNotExistAsync', () => { - it('creates artifacts dir', async () => { - const artifactsDir = `${__dirname}/artifacts`; - expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false(); - await createDirIfDoesNotExistAsync(artifactsDir); - expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.true(); - fsWrapper.rmdirSync(artifactsDir); - expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false(); - }); - }); - describe('#parseSolidityVersionRange', () => { - it('correctly parses the version range', () => { - expect(parseSolidityVersionRange('pragma solidity ^0.0.1;')).to.be.equal('^0.0.1'); - expect(parseSolidityVersionRange('\npragma solidity 0.0.1;')).to.be.equal('0.0.1'); - expect(parseSolidityVersionRange('pragma solidity <=1.0.1;')).to.be.equal('<=1.0.1'); - expect(parseSolidityVersionRange('pragma solidity ~1.0.1;')).to.be.equal('~1.0.1'); - }); - // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser - it.skip('correctly parses the version range with comments', () => { - expect(parseSolidityVersionRange('// pragma solidity ~1.0.1;\npragma solidity ~1.0.2;')).to.be.equal( - '~1.0.2', - ); - }); - }); - describe('#parseDependencies', () => { - it('correctly parses Exchange dependencies', async () => { - const path = `${__dirname}/fixtures/contracts/Exchange.sol`; - const source = await fsWrapper.readFileAsync(path, { - encoding: 'utf8', - }); - const dependencies = parseDependencies({ source, path }); - const expectedDependencies = [ - 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol', - 'packages/deployer/lib/test/fixtures/contracts/TokenTransferProxy.sol', - 'packages/deployer/lib/test/fixtures/contracts/base/SafeMath.sol', - ]; - _.each(expectedDependencies, expectedDepdency => { - const foundDependency = _.find(dependencies, dependency => _.endsWith(dependency, expectedDepdency)); - expect(foundDependency, `${expectedDepdency} not found`).to.not.be.undefined(); - }); - }); - it('correctly parses TokenTransferProxy dependencies', async () => { - const path = `${__dirname}/fixtures/contracts/TokenTransferProxy.sol`; - const source = await fsWrapper.readFileAsync(path, { - encoding: 'utf8', - }); - expect(parseDependencies({ source, path })).to.be.deep.equal([ - 'zeppelin-solidity/contracts/ownership/Ownable.sol', - 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol', - ]); - }); - // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser - it.skip('correctly parses commented out dependencies', async () => { - const path = ''; - const source = `// import "./TokenTransferProxy.sol";`; - expect(parseDependencies({ path, source })).to.be.deep.equal([]); - }); - }); -}); diff --git a/packages/deployer/test/fixtures/contracts/Exchange.sol b/packages/deployer/test/fixtures/contracts/Exchange.sol deleted file mode 100644 index e3725335b..000000000 --- a/packages/deployer/test/fixtures/contracts/Exchange.sol +++ /dev/null @@ -1,603 +0,0 @@ -/* - - Copyright 2018 ZeroEx Intl. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -pragma solidity ^0.4.14; - -import {ERC20 as Token} from "zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; - -import "./TokenTransferProxy.sol"; -import "./base/SafeMath.sol"; - -/// @title Exchange - Facilitates exchange of ERC20 tokens. -/// @author Amir Bandeali - , Will Warren - -contract Exchange is SafeMath { - - // Error Codes - enum Errors { - ORDER_EXPIRED, // Order has already expired - ORDER_FULLY_FILLED_OR_CANCELLED, // Order has already been fully filled or cancelled - ROUNDING_ERROR_TOO_LARGE, // Rounding error too large - INSUFFICIENT_BALANCE_OR_ALLOWANCE // Insufficient balance or allowance for token transfer - } - - string constant public VERSION = "1.0.0"; - uint16 constant public EXTERNAL_QUERY_GAS_LIMIT = 4999; // Changes to state require at least 5000 gas - - address public ZRX_TOKEN_CONTRACT; - address public TOKEN_TRANSFER_PROXY_CONTRACT; - - // Mappings of orderHash => amounts of takerTokenAmount filled or cancelled. - mapping (bytes32 => uint) public filled; - mapping (bytes32 => uint) public cancelled; - - event LogFill( - address indexed maker, - address taker, - address indexed feeRecipient, - address makerToken, - address takerToken, - uint filledMakerTokenAmount, - uint filledTakerTokenAmount, - uint paidMakerFee, - uint paidTakerFee, - bytes32 indexed tokens, // keccak256(makerToken, takerToken), allows subscribing to a token pair - bytes32 orderHash - ); - - event LogCancel( - address indexed maker, - address indexed feeRecipient, - address makerToken, - address takerToken, - uint cancelledMakerTokenAmount, - uint cancelledTakerTokenAmount, - bytes32 indexed tokens, - bytes32 orderHash - ); - - event LogError(uint8 indexed errorId, bytes32 indexed orderHash); - - struct Order { - address maker; - address taker; - address makerToken; - address takerToken; - address feeRecipient; - uint makerTokenAmount; - uint takerTokenAmount; - uint makerFee; - uint takerFee; - uint expirationTimestampInSec; - bytes32 orderHash; - } - - function Exchange(address _zrxToken, address _tokenTransferProxy) { - ZRX_TOKEN_CONTRACT = _zrxToken; - TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy; - } - - /* - * Core exchange functions - */ - - /// @dev Fills the input order. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. - /// @param fillTakerTokenAmount Desired amount of takerToken to fill. - /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfer will fail before attempting. - /// @param v ECDSA signature parameter v. - /// @param r ECDSA signature parameters r. - /// @param s ECDSA signature parameters s. - /// @return Total amount of takerToken filled in trade. - function fillOrder( - address[5] orderAddresses, - uint[6] orderValues, - uint fillTakerTokenAmount, - bool shouldThrowOnInsufficientBalanceOrAllowance, - uint8 v, - bytes32 r, - bytes32 s) - public - returns (uint filledTakerTokenAmount) - { - Order memory order = Order({ - maker: orderAddresses[0], - taker: orderAddresses[1], - makerToken: orderAddresses[2], - takerToken: orderAddresses[3], - feeRecipient: orderAddresses[4], - makerTokenAmount: orderValues[0], - takerTokenAmount: orderValues[1], - makerFee: orderValues[2], - takerFee: orderValues[3], - expirationTimestampInSec: orderValues[4], - orderHash: getOrderHash(orderAddresses, orderValues) - }); - - require(order.taker == address(0) || order.taker == msg.sender); - require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && fillTakerTokenAmount > 0); - require(isValidSignature( - order.maker, - order.orderHash, - v, - r, - s - )); - - if (block.timestamp >= order.expirationTimestampInSec) { - LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash); - return 0; - } - - uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash)); - filledTakerTokenAmount = min256(fillTakerTokenAmount, remainingTakerTokenAmount); - if (filledTakerTokenAmount == 0) { - LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash); - return 0; - } - - if (isRoundingError(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount)) { - LogError(uint8(Errors.ROUNDING_ERROR_TOO_LARGE), order.orderHash); - return 0; - } - - if (!shouldThrowOnInsufficientBalanceOrAllowance && !isTransferable(order, filledTakerTokenAmount)) { - LogError(uint8(Errors.INSUFFICIENT_BALANCE_OR_ALLOWANCE), order.orderHash); - return 0; - } - - uint filledMakerTokenAmount = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount); - uint paidMakerFee; - uint paidTakerFee; - filled[order.orderHash] = safeAdd(filled[order.orderHash], filledTakerTokenAmount); - require(transferViaTokenTransferProxy( - order.makerToken, - order.maker, - msg.sender, - filledMakerTokenAmount - )); - require(transferViaTokenTransferProxy( - order.takerToken, - msg.sender, - order.maker, - filledTakerTokenAmount - )); - if (order.feeRecipient != address(0)) { - if (order.makerFee > 0) { - paidMakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerFee); - require(transferViaTokenTransferProxy( - ZRX_TOKEN_CONTRACT, - order.maker, - order.feeRecipient, - paidMakerFee - )); - } - if (order.takerFee > 0) { - paidTakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.takerFee); - require(transferViaTokenTransferProxy( - ZRX_TOKEN_CONTRACT, - msg.sender, - order.feeRecipient, - paidTakerFee - )); - } - } - - LogFill( - order.maker, - msg.sender, - order.feeRecipient, - order.makerToken, - order.takerToken, - filledMakerTokenAmount, - filledTakerTokenAmount, - paidMakerFee, - paidTakerFee, - keccak256(order.makerToken, order.takerToken), - order.orderHash - ); - return filledTakerTokenAmount; - } - - /// @dev Cancels the input order. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. - /// @param cancelTakerTokenAmount Desired amount of takerToken to cancel in order. - /// @return Amount of takerToken cancelled. - function cancelOrder( - address[5] orderAddresses, - uint[6] orderValues, - uint cancelTakerTokenAmount) - public - returns (uint) - { - Order memory order = Order({ - maker: orderAddresses[0], - taker: orderAddresses[1], - makerToken: orderAddresses[2], - takerToken: orderAddresses[3], - feeRecipient: orderAddresses[4], - makerTokenAmount: orderValues[0], - takerTokenAmount: orderValues[1], - makerFee: orderValues[2], - takerFee: orderValues[3], - expirationTimestampInSec: orderValues[4], - orderHash: getOrderHash(orderAddresses, orderValues) - }); - - require(order.maker == msg.sender); - require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && cancelTakerTokenAmount > 0); - - if (block.timestamp >= order.expirationTimestampInSec) { - LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash); - return 0; - } - - uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash)); - uint cancelledTakerTokenAmount = min256(cancelTakerTokenAmount, remainingTakerTokenAmount); - if (cancelledTakerTokenAmount == 0) { - LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash); - return 0; - } - - cancelled[order.orderHash] = safeAdd(cancelled[order.orderHash], cancelledTakerTokenAmount); - - LogCancel( - order.maker, - order.feeRecipient, - order.makerToken, - order.takerToken, - getPartialAmount(cancelledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount), - cancelledTakerTokenAmount, - keccak256(order.makerToken, order.takerToken), - order.orderHash - ); - return cancelledTakerTokenAmount; - } - - /* - * Wrapper functions - */ - - /// @dev Fills an order with specified parameters and ECDSA signature, throws if specified amount not filled entirely. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. - /// @param fillTakerTokenAmount Desired amount of takerToken to fill. - /// @param v ECDSA signature parameter v. - /// @param r ECDSA signature parameters r. - /// @param s ECDSA signature parameters s. - function fillOrKillOrder( - address[5] orderAddresses, - uint[6] orderValues, - uint fillTakerTokenAmount, - uint8 v, - bytes32 r, - bytes32 s) - public - { - require(fillOrder( - orderAddresses, - orderValues, - fillTakerTokenAmount, - false, - v, - r, - s - ) == fillTakerTokenAmount); - } - - /// @dev Synchronously executes multiple fill orders in a single transaction. - /// @param orderAddresses Array of address arrays containing individual order addresses. - /// @param orderValues Array of uint arrays containing individual order values. - /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. - /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. - /// @param v Array ECDSA signature v parameters. - /// @param r Array of ECDSA signature r parameters. - /// @param s Array of ECDSA signature s parameters. - function batchFillOrders( - address[5][] orderAddresses, - uint[6][] orderValues, - uint[] fillTakerTokenAmounts, - bool shouldThrowOnInsufficientBalanceOrAllowance, - uint8[] v, - bytes32[] r, - bytes32[] s) - public - { - for (uint i = 0; i < orderAddresses.length; i++) { - fillOrder( - orderAddresses[i], - orderValues[i], - fillTakerTokenAmounts[i], - shouldThrowOnInsufficientBalanceOrAllowance, - v[i], - r[i], - s[i] - ); - } - } - - /// @dev Synchronously executes multiple fillOrKill orders in a single transaction. - /// @param orderAddresses Array of address arrays containing individual order addresses. - /// @param orderValues Array of uint arrays containing individual order values. - /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. - /// @param v Array ECDSA signature v parameters. - /// @param r Array of ECDSA signature r parameters. - /// @param s Array of ECDSA signature s parameters. - function batchFillOrKillOrders( - address[5][] orderAddresses, - uint[6][] orderValues, - uint[] fillTakerTokenAmounts, - uint8[] v, - bytes32[] r, - bytes32[] s) - public - { - for (uint i = 0; i < orderAddresses.length; i++) { - fillOrKillOrder( - orderAddresses[i], - orderValues[i], - fillTakerTokenAmounts[i], - v[i], - r[i], - s[i] - ); - } - } - - /// @dev Synchronously executes multiple fill orders in a single transaction until total fillTakerTokenAmount filled. - /// @param orderAddresses Array of address arrays containing individual order addresses. - /// @param orderValues Array of uint arrays containing individual order values. - /// @param fillTakerTokenAmount Desired total amount of takerToken to fill in orders. - /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. - /// @param v Array ECDSA signature v parameters. - /// @param r Array of ECDSA signature r parameters. - /// @param s Array of ECDSA signature s parameters. - /// @return Total amount of fillTakerTokenAmount filled in orders. - function fillOrdersUpTo( - address[5][] orderAddresses, - uint[6][] orderValues, - uint fillTakerTokenAmount, - bool shouldThrowOnInsufficientBalanceOrAllowance, - uint8[] v, - bytes32[] r, - bytes32[] s) - public - returns (uint) - { - uint filledTakerTokenAmount = 0; - for (uint i = 0; i < orderAddresses.length; i++) { - require(orderAddresses[i][3] == orderAddresses[0][3]); // takerToken must be the same for each order - filledTakerTokenAmount = safeAdd(filledTakerTokenAmount, fillOrder( - orderAddresses[i], - orderValues[i], - safeSub(fillTakerTokenAmount, filledTakerTokenAmount), - shouldThrowOnInsufficientBalanceOrAllowance, - v[i], - r[i], - s[i] - )); - if (filledTakerTokenAmount == fillTakerTokenAmount) break; - } - return filledTakerTokenAmount; - } - - /// @dev Synchronously cancels multiple orders in a single transaction. - /// @param orderAddresses Array of address arrays containing individual order addresses. - /// @param orderValues Array of uint arrays containing individual order values. - /// @param cancelTakerTokenAmounts Array of desired amounts of takerToken to cancel in orders. - function batchCancelOrders( - address[5][] orderAddresses, - uint[6][] orderValues, - uint[] cancelTakerTokenAmounts) - public - { - for (uint i = 0; i < orderAddresses.length; i++) { - cancelOrder( - orderAddresses[i], - orderValues[i], - cancelTakerTokenAmounts[i] - ); - } - } - - /* - * Constant public functions - */ - - /// @dev Calculates Keccak-256 hash of order with specified parameters. - /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. - /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. - /// @return Keccak-256 hash of order. - function getOrderHash(address[5] orderAddresses, uint[6] orderValues) - public - constant - returns (bytes32) - { - return keccak256( - address(this), - orderAddresses[0], // maker - orderAddresses[1], // taker - orderAddresses[2], // makerToken - orderAddresses[3], // takerToken - orderAddresses[4], // feeRecipient - orderValues[0], // makerTokenAmount - orderValues[1], // takerTokenAmount - orderValues[2], // makerFee - orderValues[3], // takerFee - orderValues[4], // expirationTimestampInSec - orderValues[5] // salt - ); - } - - /// @dev Verifies that an order signature is valid. - /// @param signer address of signer. - /// @param hash Signed Keccak-256 hash. - /// @param v ECDSA signature parameter v. - /// @param r ECDSA signature parameters r. - /// @param s ECDSA signature parameters s. - /// @return Validity of order signature. - function isValidSignature( - address signer, - bytes32 hash, - uint8 v, - bytes32 r, - bytes32 s) - public - constant - returns (bool) - { - return signer == ecrecover( - keccak256("\x19Ethereum Signed Message:\n32", hash), - v, - r, - s - ); - } - - /// @dev Checks if rounding error > 0.1%. - /// @param numerator Numerator. - /// @param denominator Denominator. - /// @param target Value to multiply with numerator/denominator. - /// @return Rounding error is present. - function isRoundingError(uint numerator, uint denominator, uint target) - public - constant - returns (bool) - { - uint remainder = mulmod(target, numerator, denominator); - if (remainder == 0) return false; // No rounding error. - - uint errPercentageTimes1000000 = safeDiv( - safeMul(remainder, 1000000), - safeMul(numerator, target) - ); - return errPercentageTimes1000000 > 1000; - } - - /// @dev Calculates partial value given a numerator and denominator. - /// @param numerator Numerator. - /// @param denominator Denominator. - /// @param target Value to calculate partial of. - /// @return Partial value of target. - function getPartialAmount(uint numerator, uint denominator, uint target) - public - constant - returns (uint) - { - return safeDiv(safeMul(numerator, target), denominator); - } - - /// @dev Calculates the sum of values already filled and cancelled for a given order. - /// @param orderHash The Keccak-256 hash of the given order. - /// @return Sum of values already filled and cancelled. - function getUnavailableTakerTokenAmount(bytes32 orderHash) - public - constant - returns (uint) - { - return safeAdd(filled[orderHash], cancelled[orderHash]); - } - - - /* - * Internal functions - */ - - /// @dev Transfers a token using TokenTransferProxy transferFrom function. - /// @param token Address of token to transferFrom. - /// @param from Address transfering token. - /// @param to Address receiving token. - /// @param value Amount of token to transfer. - /// @return Success of token transfer. - function transferViaTokenTransferProxy( - address token, - address from, - address to, - uint value) - internal - returns (bool) - { - return TokenTransferProxy(TOKEN_TRANSFER_PROXY_CONTRACT).transferFrom(token, from, to, value); - } - - /// @dev Checks if any order transfers will fail. - /// @param order Order struct of params that will be checked. - /// @param fillTakerTokenAmount Desired amount of takerToken to fill. - /// @return Predicted result of transfers. - function isTransferable(Order order, uint fillTakerTokenAmount) - internal - constant // The called token contracts may attempt to change state, but will not be able to due to gas limits on getBalance and getAllowance. - returns (bool) - { - address taker = msg.sender; - uint fillMakerTokenAmount = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount); - - if (order.feeRecipient != address(0)) { - bool isMakerTokenZRX = order.makerToken == ZRX_TOKEN_CONTRACT; - bool isTakerTokenZRX = order.takerToken == ZRX_TOKEN_CONTRACT; - uint paidMakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerFee); - uint paidTakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.takerFee); - uint requiredMakerZRX = isMakerTokenZRX ? safeAdd(fillMakerTokenAmount, paidMakerFee) : paidMakerFee; - uint requiredTakerZRX = isTakerTokenZRX ? safeAdd(fillTakerTokenAmount, paidTakerFee) : paidTakerFee; - - if ( getBalance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX - || getAllowance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX - || getBalance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX - || getAllowance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX - ) return false; - - if (!isMakerTokenZRX && ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount // Don't double check makerToken if ZRX - || getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount) - ) return false; - if (!isTakerTokenZRX && ( getBalance(order.takerToken, taker) < fillTakerTokenAmount // Don't double check takerToken if ZRX - || getAllowance(order.takerToken, taker) < fillTakerTokenAmount) - ) return false; - } else if ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount - || getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount - || getBalance(order.takerToken, taker) < fillTakerTokenAmount - || getAllowance(order.takerToken, taker) < fillTakerTokenAmount - ) return false; - - return true; - } - - /// @dev Get token balance of an address. - /// @param token Address of token. - /// @param owner Address of owner. - /// @return Token balance of owner. - function getBalance(address token, address owner) - internal - constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit. - returns (uint) - { - return Token(token).balanceOf.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner); // Limit gas to prevent reentrancy - } - - /// @dev Get allowance of token given to TokenTransferProxy by an address. - /// @param token Address of token. - /// @param owner Address of owner. - /// @return Allowance of token given to TokenTransferProxy by owner. - function getAllowance(address token, address owner) - internal - constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit. - returns (uint) - { - return Token(token).allowance.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner, TOKEN_TRANSFER_PROXY_CONTRACT); // Limit gas to prevent reentrancy - } -} diff --git a/packages/deployer/test/fixtures/contracts/TokenTransferProxy.sol b/packages/deployer/test/fixtures/contracts/TokenTransferProxy.sol deleted file mode 100644 index 44570d459..000000000 --- a/packages/deployer/test/fixtures/contracts/TokenTransferProxy.sol +++ /dev/null @@ -1,115 +0,0 @@ -/* - - Copyright 2018 ZeroEx Intl. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -pragma solidity ^0.4.14; - -import { Ownable } from "zeppelin-solidity/contracts/ownership/Ownable.sol"; -import { ERC20 as Token } from "zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; - -/// @title TokenTransferProxy - Transfers tokens on behalf of contracts that have been approved via decentralized governance. -/// @author Amir Bandeali - , Will Warren - -contract TokenTransferProxy is Ownable { - - /// @dev Only authorized addresses can invoke functions with this modifier. - modifier onlyAuthorized { - require(authorized[msg.sender]); - _; - } - - modifier targetAuthorized(address target) { - require(authorized[target]); - _; - } - - modifier targetNotAuthorized(address target) { - require(!authorized[target]); - _; - } - - mapping (address => bool) public authorized; - address[] public authorities; - - event LogAuthorizedAddressAdded(address indexed target, address indexed caller); - event LogAuthorizedAddressRemoved(address indexed target, address indexed caller); - - /* - * Public functions - */ - - /// @dev Authorizes an address. - /// @param target Address to authorize. - function addAuthorizedAddress(address target) - public - onlyOwner - targetNotAuthorized(target) - { - authorized[target] = true; - authorities.push(target); - LogAuthorizedAddressAdded(target, msg.sender); - } - - /// @dev Removes authorizion of an address. - /// @param target Address to remove authorization from. - function removeAuthorizedAddress(address target) - public - onlyOwner - targetAuthorized(target) - { - delete authorized[target]; - for (uint i = 0; i < authorities.length; i++) { - if (authorities[i] == target) { - authorities[i] = authorities[authorities.length - 1]; - authorities.length -= 1; - break; - } - } - LogAuthorizedAddressRemoved(target, msg.sender); - } - - /// @dev Calls into ERC20 Token contract, invoking transferFrom. - /// @param token Address of token to transfer. - /// @param from Address to transfer token from. - /// @param to Address to transfer token to. - /// @param value Amount of token to transfer. - /// @return Success of transfer. - function transferFrom( - address token, - address from, - address to, - uint value) - public - onlyAuthorized - returns (bool) - { - return Token(token).transferFrom(from, to, value); - } - - /* - * Public constant functions - */ - - /// @dev Gets all authorized addresses. - /// @return Array of authorized addresses. - function getAuthorizedAddresses() - public - constant - returns (address[]) - { - return authorities; - } -} diff --git a/packages/deployer/test/fixtures/contracts/base/SafeMath.sol b/packages/deployer/test/fixtures/contracts/base/SafeMath.sol deleted file mode 100644 index 92ce11cde..000000000 --- a/packages/deployer/test/fixtures/contracts/base/SafeMath.sol +++ /dev/null @@ -1,41 +0,0 @@ -pragma solidity ^0.4.14; - -contract SafeMath { - function safeMul(uint a, uint b) internal constant returns (uint256) { - uint c = a * b; - assert(a == 0 || c / a == b); - return c; - } - - function safeDiv(uint a, uint b) internal constant returns (uint256) { - uint c = a / b; - return c; - } - - function safeSub(uint a, uint b) internal constant returns (uint256) { - assert(b <= a); - return a - b; - } - - function safeAdd(uint a, uint b) internal constant returns (uint256) { - uint c = a + b; - assert(c >= a); - return c; - } - - function max64(uint64 a, uint64 b) internal constant returns (uint64) { - return a >= b ? a : b; - } - - function min64(uint64 a, uint64 b) internal constant returns (uint64) { - return a < b ? a : b; - } - - function max256(uint256 a, uint256 b) internal constant returns (uint256) { - return a >= b ? a : b; - } - - function min256(uint256 a, uint256 b) internal constant returns (uint256) { - return a < b ? a : b; - } -} diff --git a/packages/deployer/test/fixtures/contracts/base/Token.sol b/packages/deployer/test/fixtures/contracts/base/Token.sol deleted file mode 100644 index 483010d7d..000000000 --- a/packages/deployer/test/fixtures/contracts/base/Token.sol +++ /dev/null @@ -1,38 +0,0 @@ -pragma solidity ^0.4.14; - -contract Token { - - /// @return total amount of tokens - function totalSupply() constant returns (uint supply) {} - - /// @param _owner The address from which the balance will be retrieved - /// @return The balance - function balanceOf(address _owner) constant returns (uint balance) {} - - /// @notice send `_value` token to `_to` from `msg.sender` - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transfer(address _to, uint _value) returns (bool success) {} - - /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` - /// @param _from The address of the sender - /// @param _to The address of the recipient - /// @param _value The amount of token to be transferred - /// @return Whether the transfer was successful or not - function transferFrom(address _from, address _to, uint _value) returns (bool success) {} - - /// @notice `msg.sender` approves `_addr` to spend `_value` tokens - /// @param _spender The address of the account able to transfer the tokens - /// @param _value The amount of wei to be approved for transfer - /// @return Whether the approval was successful or not - function approve(address _spender, uint _value) returns (bool success) {} - - /// @param _owner The address of the account owning tokens - /// @param _spender The address of the account able to transfer the tokens - /// @return Amount of remaining tokens allowed to spent - function allowance(address _owner, address _spender) constant returns (uint remaining) {} - - event Transfer(address indexed _from, address indexed _to, uint _value); - event Approval(address indexed _owner, address indexed _spender, uint _value); -} diff --git a/packages/deployer/test/fixtures/exchange_bin.ts b/packages/deployer/test/fixtures/exchange_bin.ts deleted file mode 100644 index 914e76bf5..000000000 --- a/packages/deployer/test/fixtures/exchange_bin.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const constructor_args = - '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f4980000000000000000000000008da0d80f5007ef1e431dd2127178d224e32c2ef4'; -export const exchange_binary = - '608060405234801561001057600080fd5b50604051604080612d998339810180604052810190808051906020019092919080519060200190929190505050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050612cca806100cf6000396000f3006080604052600436106100fc576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806314df96ee14610101578063288cdc911461015a5780632ac126221461019f578063363349be146101e4578063394c21e7146103f85780633b30ba59146104975780634f150787146104ee578063741bcc931461071b5780637e9abb50146107cf5780638163681e1461081457806398024a8b146108a6578063add1cbc5146108fb578063b7b2c7d614610952578063baa0181d14610b8b578063bc61394a14610cef578063cfc4d0ec14610dc3578063f06bbf7514610e60578063ffa1ad7414610e93575b600080fd5b34801561010d57600080fd5b50610140600480360381019080803590602001909291908035906020019092919080359060200190929190505050610f23565b604051808215151515815260200191505060405180910390f35b34801561016657600080fd5b506101896004803603810190808035600019169060200190929190505050610f7b565b6040518082815260200191505060405180910390f35b3480156101ab57600080fd5b506101ce6004803603810190808035600019169060200190929190505050610f93565b6040518082815260200191505060405180910390f35b3480156101f057600080fd5b506103e260048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b8282101561027257848483905060a00201600580602002604051908101604052809291908260056020028082843782019150505050508152602001906001019061022d565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156102f157848483905060c0020160068060200260405190810160405280929190826006602002808284378201915050505050815260200190600101906102ac565b5050505050919291929080359060200190929190803515159060200190929190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290505050610fab565b6040518082815260200191505060405180910390f35b34801561040457600080fd5b506104816004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190505050611110565b6040518082815260200191505060405180910390f35b3480156104a357600080fd5b506104ac6115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104fa57600080fd5b5061071960048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b8282101561057c57848483905060a002016005806020026040519081016040528092919082600560200280828437820191505050505081526020019060010190610537565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156105fb57848483905060c0020160068060200260405190810160405280929190826006602002808284378201915050505050815260200190600101906105b6565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061161d565b005b34801561072757600080fd5b506107cd6004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190803560ff169060200190929190803560001916906020019092919080356000191690602001909291905050506116da565b005b3480156107db57600080fd5b506107fe60048036038101908080356000191690602001909291905050506116ff565b6040518082815260200191505060405180910390f35b34801561082057600080fd5b5061088c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035600019169060200190929190803560ff16906020019092919080356000191690602001909291908035600019169060200190929190505050611748565b604051808215151515815260200191505060405180910390f35b3480156108b257600080fd5b506108e5600480360381019080803590602001909291908035906020019092919080359060200190929190505050611849565b6040518082815260200191505060405180910390f35b34801561090757600080fd5b50610910611867565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561095e57600080fd5b50610b8960048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156109e057848483905060a00201600580602002604051908101604052809291908260056020028082843782019150505050508152602001906001019061099b565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610a5f57848483905060c002016006806020026040519081016040528092919082600660200280828437820191505050505081526020019060010190610a1a565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080351515906020019092919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061188d565b005b348015610b9757600080fd5b50610ced60048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610c1957848483905060a002016005806020026040519081016040528092919082600560200280828437820191505050505081526020019060010190610bd4565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610c9857848483905060c002016006806020026040519081016040528092919082600660200280828437820191505050505081526020019060010190610c53565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061194d565b005b348015610cfb57600080fd5b50610dad6004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190803515159060200190929190803560ff169060200190929190803560001916906020019092919080356000191690602001909291905050506119c0565b6040518082815260200191505060405180910390f35b348015610dcf57600080fd5b50610e426004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c00190600680602002604051908101604052809291908260066020028082843782019150505050509192919290505050612160565b60405180826000191660001916815260200191505060405180910390f35b348015610e6c57600080fd5b50610e7561240b565b604051808261ffff1661ffff16815260200191505060405180910390f35b348015610e9f57600080fd5b50610ea8612411565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610ee8578082015181840152602081019050610ecd565b50505050905090810190601f168015610f155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600080600084801515610f3257fe5b86850991506000821415610f495760009250610f72565b610f68610f5983620f424061244a565b610f63888761244a565b61247d565b90506103e8811192505b50509392505050565b60026020528060005260406000206000915090505481565b60036020528060005260406000206000915090505481565b6000806000809150600090505b895181101561110057896000815181101515610fd057fe5b906020019060200201516003600581101515610fe857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff168a8281518110151561101157fe5b90602001906020020151600360058110151561102957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1614151561105057600080fd5b6110e4826110df8c8481518110151561106557fe5b906020019060200201518c8581518110151561107d57fe5b906020019060200201516110918d88612498565b8c8c888151811015156110a057fe5b906020019060200201518c898151811015156110b857fe5b906020019060200201518c8a8151811015156110d057fe5b906020019060200201516119c0565b6124b1565b9150878214156110f357611100565b8080600101915050610fb8565b8192505050979650505050505050565b600061111a612bd2565b6000806101606040519081016040528088600060058110151561113957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200188600160058110151561116857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200188600260058110151561119757fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018860036005811015156111c657fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018860046005811015156111f557fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200187600060068110151561122457fe5b6020020151815260200187600160068110151561123d57fe5b6020020151815260200187600260068110151561125657fe5b6020020151815260200187600360068110151561126f57fe5b6020020151815260200187600460068110151561128857fe5b6020020151815260200161129c8989612160565b6000191681525092503373ffffffffffffffffffffffffffffffffffffffff16836000015173ffffffffffffffffffffffffffffffffffffffff161415156112e357600080fd5b60008360a001511180156112fb575060008360c00151115b80156113075750600085115b151561131257600080fd5b8261012001514210151561136f57826101400151600019166000600381111561133757fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a3600093506115ee565b61138a8360c001516113858561014001516116ff565b612498565b915061139685836124cf565b905060008114156113f05782610140015160001916600160038111156113b857fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a3600093506115ee565b61141a600360008561014001516000191660001916815260200190815260200160002054826124b1565b60036000856101400151600019166000191681526020019081526020016000208190555082604001518360600151604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140192505050604051809103902060001916836080015173ffffffffffffffffffffffffffffffffffffffff16846000015173ffffffffffffffffffffffffffffffffffffffff167f67d66f160bc93d925d05dae1794c90d2d6d6688b29b84ff069398a9b0458713186604001518760600151611552878a60c001518b60a00151611849565b878a6101400151604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200183815260200182600019166000191681526020019550505050505060405180910390a48093505b5050509392505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008090505b86518110156116d1576116c4878281518110151561163d57fe5b90602001906020020151878381518110151561165557fe5b90602001906020020151878481518110151561166d57fe5b90602001906020020151878581518110151561168557fe5b90602001906020020151878681518110151561169d57fe5b9060200190602002015187878151811015156116b557fe5b906020019060200201516116da565b8080600101915050611623565b50505050505050565b836116eb87878760008888886119c0565b1415156116f757600080fd5b505050505050565b600061174160026000846000191660001916815260200190815260200160002054600360008560001916600019168152602001908152602001600020546124b1565b9050919050565b600060018560405180807f19457468657265756d205369676e6564204d6573736167653a0a333200000000815250601c0182600019166000191681526020019150506040518091039020858585604051600081526020016040526040518085600019166000191681526020018460ff1660ff1681526020018360001916600019168152602001826000191660001916815260200194505050505060206040516020810390808403906000865af1158015611806573d6000803e3d6000fd5b5050506020604051035173ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614905095945050505050565b600061185e611858858461244a565b8461247d565b90509392505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008090505b87518110156119435761193588828151811015156118ad57fe5b9060200190602002015188838151811015156118c557fe5b9060200190602002015188848151811015156118dd57fe5b906020019060200201518888868151811015156118f657fe5b90602001906020020151888781518110151561190e57fe5b90602001906020020151888881518110151561192657fe5b906020019060200201516119c0565b508080600101915050611893565b5050505050505050565b60008090505b83518110156119ba576119ac848281518110151561196d57fe5b90602001906020020151848381518110151561198557fe5b90602001906020020151848481518110151561199d57fe5b90602001906020020151611110565b508080600101915050611953565b50505050565b60006119ca612bd2565b600080600080610160604051908101604052808e60006005811015156119ec57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6001600581101515611a1b57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6002600581101515611a4a57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6003600581101515611a7957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6004600581101515611aa857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018d6000600681101515611ad757fe5b602002015181526020018d6001600681101515611af057fe5b602002015181526020018d6002600681101515611b0957fe5b602002015181526020018d6003600681101515611b2257fe5b602002015181526020018d6004600681101515611b3b57fe5b60200201518152602001611b4f8f8f612160565b600019168152509450600073ffffffffffffffffffffffffffffffffffffffff16856020015173ffffffffffffffffffffffffffffffffffffffff161480611bc657503373ffffffffffffffffffffffffffffffffffffffff16856020015173ffffffffffffffffffffffffffffffffffffffff16145b1515611bd157600080fd5b60008560a00151118015611be9575060008560c00151115b8015611bf5575060008b115b1515611c0057600080fd5b611c1685600001518661014001518b8b8b611748565b1515611c2157600080fd5b84610120015142101515611c7e578461014001516000191660006003811115611c4657fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611c998560c00151611c948761014001516116ff565b612498565b9350611ca58b856124cf565b95506000861415611cff578461014001516000191660016003811115611cc757fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611d12868660c001518760a00151610f23565b15611d66578461014001516000191660026003811115611d2e57fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b89158015611d7b5750611d7985876124e8565b155b15611dce5784610140015160001916600380811115611d9657fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611de1868660c001518760a00151611849565b9250611e0d600260008761014001516000191660001916815260200190815260200160002054876124b1565b600260008761014001516000191660001916815260200190815260200160002081905550611e45856040015186600001513386612838565b1515611e5057600080fd5b611e64856060015133876000015189612838565b1515611e6f57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff16856080015173ffffffffffffffffffffffffffffffffffffffff16141515611f6e5760008560e001511115611f0c57611ec9868660c001518760e00151611849565b9150611f006000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168660000151876080015185612838565b1515611f0b57600080fd5b5b60008561010001511115611f6d57611f2e868660c00151876101000151611849565b9050611f616000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1633876080015184612838565b1515611f6c57600080fd5b5b5b84604001518560600151604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140192505050604051809103902060001916856080015173ffffffffffffffffffffffffffffffffffffffff16866000015173ffffffffffffffffffffffffffffffffffffffff167f0d0b9391970d9a25552f37d436d2aae2925e2bfe1b2a923754bada030c498cb33389604001518a60600151898d8a8a8f6101400151604051808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200186815260200185815260200184815260200183815260200182600019166000191681526020019850505050505050505060405180910390a48595505b5050505050979650505050505050565b60003083600060058110151561217257fe5b602002015184600160058110151561218657fe5b602002015185600260058110151561219a57fe5b60200201518660036005811015156121ae57fe5b60200201518760046005811015156121c257fe5b60200201518760006006811015156121d657fe5b60200201518860016006811015156121ea57fe5b60200201518960026006811015156121fe57fe5b60200201518a600360068110151561221257fe5b60200201518b600460068110151561222657fe5b60200201518c600560068110151561223a57fe5b6020020151604051808d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018781526020018681526020018581526020018481526020018381526020018281526020019c505050505050505050505050506040518091039020905092915050565b61138781565b6040805190810160405280600581526020017f312e302e3000000000000000000000000000000000000000000000000000000081525081565b6000808284029050600084148061246b575082848281151561246857fe5b04145b151561247357fe5b8091505092915050565b600080828481151561248b57fe5b0490508091505092915050565b60008282111515156124a657fe5b818303905092915050565b60008082840190508381101515156124c557fe5b8091505092915050565b60008183106124de57816124e0565b825b905092915050565b600080600080600080600080600033975061250c8a8c60c001518d60a00151611849565b9650600073ffffffffffffffffffffffffffffffffffffffff168b6080015173ffffffffffffffffffffffffffffffffffffffff161415156127b9576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168b6040015173ffffffffffffffffffffffffffffffffffffffff161495506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168b6060015173ffffffffffffffffffffffffffffffffffffffff161494506126078a8c60c001518d60e00151611849565b935061261d8a8c60c001518d6101000151611849565b92508561262a5783612635565b61263487856124b1565b5b915084612642578261264d565b61264c8a846124b1565b5b90508161267f6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168d600001516129ac565b10806126b85750816126b66000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168d60000151612a94565b105b806126ec5750806126ea6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168a6129ac565b105b8061272057508061271e6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168a612a94565b105b1561272e576000985061282a565b8515801561276757508661274a8c604001518d600001516129ac565b10806127665750866127648c604001518d60000151612a94565b105b5b15612775576000985061282a565b841580156127a657508961278d8c606001518a6129ac565b10806127a55750896127a38c606001518a612a94565b105b5b156127b4576000985061282a565b612825565b866127cc8c604001518d600001516129ac565b10806127e85750866127e68c604001518d60000151612a94565b105b806127ff5750896127fd8c606001518a6129ac565b105b806128165750896128148c606001518a612a94565b105b15612824576000985061282a565b5b600198505b505050505050505092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166315dacbea868686866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001945050505050602060405180830381600087803b15801561296757600080fd5b505af115801561297b573d6000803e3d6000fd5b505050506040513d602081101561299157600080fd5b81019080805190602001909291905050509050949350505050565b60008273ffffffffffffffffffffffffffffffffffffffff166370a0823161138761ffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600088803b158015612a5057600080fd5b5087f1158015612a64573d6000803e3d6000fd5b50505050506040513d6020811015612a7b57600080fd5b8101908080519060200190929190505050905092915050565b60008273ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e61138761ffff1684600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050602060405180830381600088803b158015612b8e57600080fd5b5087f1158015612ba2573d6000803e3d6000fd5b50505050506040513d6020811015612bb957600080fd5b8101908080519060200190929190505050905092915050565b61016060405190810160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081526020016000815260200160008152602001600081526020016000801916815250905600a165627a7a72305820f91599ebd80f85632ef190bb5e1a738e7288d68a2cf9dcc6b579d76b892dcf6f0029'; diff --git a/packages/deployer/test/util/constants.ts b/packages/deployer/test/util/constants.ts deleted file mode 100644 index 88d6db550..000000000 --- a/packages/deployer/test/util/constants.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BigNumber } from '@0xproject/utils'; - -export const constants = { - networkId: 0, - optimizerEnabled: false, - gasPrice: new BigNumber(20000000000), - timeoutMs: 30000, - zrxTokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498', - tokenTransferProxyAddress: '0x8da0d80f5007ef1e431dd2127178d224e32c2ef4', - contracts: '*' as '*', -}; diff --git a/packages/deployer/test/util/provider.ts b/packages/deployer/test/util/provider.ts deleted file mode 100644 index e0fcb362a..000000000 --- a/packages/deployer/test/util/provider.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { web3Factory } from '@0xproject/dev-utils'; -import { Provider } from '@0xproject/types'; -import * as Web3 from 'web3'; - -const providerConfigs = { shouldUseInProcessGanache: true }; -const web3Instance = web3Factory.create(providerConfigs); -const provider: Provider = web3Instance.currentProvider; - -export { provider }; diff --git a/packages/deployer/tsconfig.json b/packages/deployer/tsconfig.json deleted file mode 100644 index 63cbc75c3..000000000 --- a/packages/deployer/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "strictFunctionTypes": false - }, - "include": ["./src/**/*", "./test/**/*"] -} diff --git a/packages/deployer/tslint.json b/packages/deployer/tslint.json deleted file mode 100644 index ffaefe83a..000000000 --- a/packages/deployer/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["@0xproject/tslint-config"] -} diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json index 17aad0aaf..77099534d 100644 --- a/packages/metacoin/package.json +++ b/packages/metacoin/package.json @@ -18,14 +18,14 @@ "coverage:report:html": "istanbul report html && open coverage/index.html", "coverage:report:lcov": "istanbul report lcov", "test:circleci": "yarn test:coverage", - "compile": "node ../deployer/lib/src/cli.js compile" + "compile": "node ../sol-compiler/lib/src/cli.js compile" }, "author": "", "license": "Apache-2.0", "dependencies": { "@0xproject/abi-gen": "^0.2.13", "@0xproject/base-contract": "^0.3.1", - "@0xproject/deployer": "^0.4.3", + "@0xproject/sol-compiler": "^0.4.3", "@0xproject/sol-cov": "^0.0.10", "@0xproject/subproviders": "^0.10.1", "@0xproject/tslint-config": "^0.4.17", diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts index 6fe751d12..830551968 100644 --- a/packages/metacoin/test/metacoin_test.ts +++ b/packages/metacoin/test/metacoin_test.ts @@ -1,4 +1,4 @@ -import { ContractArtifact } from '@0xproject/deployer'; +import { ContractArtifact } from '@0xproject/sol-compiler'; import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; diff --git a/packages/migrations/package.json b/packages/migrations/package.json index a03ec1bdd..a8a30aa47 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -15,7 +15,7 @@ "script:migrate": "node ./lib/migrate.js", "copy_artifacts": "copyfiles 'artifacts/1.0.0/**/*' ./lib", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers && prettier --write 'src/contract_wrappers/**.ts'", - "compile": "node ../deployer/lib/src/cli.js compile" + "compile": "node ../sol-compiler/lib/src/cli.js compile" }, "config": { "abis": "artifacts/1.0.0/@(DummyToken|TokenTransferProxy|Exchange|TokenRegistry|MultiSigWallet|MultiSigWalletWithTimeLock|MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress|TokenRegistry|ZRXToken|Arbitrage|EtherDelta|AccountLevels|WETH9|MaliciousToken).json" @@ -31,7 +31,7 @@ "typescript": "2.7.1" }, "dependencies": { - "@0xproject/deployer": "^0.4.3", + "@0xproject/sol-compiler": "^0.4.3", "@0xproject/base-contract": "^0.3.1", "@0xproject/utils": "^0.6.1", "@0xproject/web3-wrapper": "^0.6.3", diff --git a/packages/migrations/src/artifacts.ts b/packages/migrations/src/artifacts.ts index c240c3155..0d3eb68a8 100644 --- a/packages/migrations/src/artifacts.ts +++ b/packages/migrations/src/artifacts.ts @@ -1,5 +1,5 @@ import { BaseContract } from '@0xproject/base-contract'; -import { ContractArtifact } from '@0xproject/deployer'; +import { ContractArtifact } from '@0xproject/sol-compiler'; import * as fs from 'fs'; import * as path from 'path'; diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 54ba6e535..047a875ed 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -18,7 +18,9 @@ import { tokenInfo } from './utils/token_info'; * Custom migrations should be defined in this function. This will be called with the CLI 'migrate' 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 deployer Deployer instance. + * @param provider Provider instance. + * @param artifactsDir The directory with artifact files. + * @param defaults Default transaction values to use. */ export const runMigrationsAsync = async (provider: Provider, artifactsDir: string, defaults: Partial) => { const web3Wrapper = new Web3Wrapper(provider); diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index bfc38044c..df303f6ce 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -10,7 +10,7 @@ import { constants } from './constants'; import { utils } from './utils'; // For some reason, `depcheck` hangs on some packages. Add them here. -const IGNORE_PACKAGES = ['@0xproject/deployer']; +const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; (async () => { utils.log('*** NOTE: Not all deps listed here are actually not required. ***'); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index e37e1d232..2011dc393 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -32,7 +32,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { contracts: 'contracts', connect: 'connect', 'json-schemas': 'json-schemas', - deployer: 'deployer', + 'sol-compiler': 'sol-compiler', 'sol-cov': 'sol-cov', subproviders: 'subproviders', 'order-utils': 'order-utils', diff --git a/packages/sol-compiler/.npmignore b/packages/sol-compiler/.npmignore new file mode 100644 index 000000000..44df80fad --- /dev/null +++ b/packages/sol-compiler/.npmignore @@ -0,0 +1,7 @@ +.* +yarn-error.log +/src/ +/scripts/ +test/ +tsconfig.json +/lib/src/monorepo_scripts/ diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json new file mode 100644 index 000000000..3f18ae121 --- /dev/null +++ b/packages/sol-compiler/CHANGELOG.json @@ -0,0 +1,151 @@ +[ + { + "timestamp": 1525477860, + "version": "0.4.3", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "version": "0.4.2", + "changes": [ + { + "note": "Add support for solidity 0.4.23", + "pr": 545 + } + ], + "timestamp": 1525428773 + }, + { + "version": "0.4.1", + "changes": [ + { + "note": "Add support for solidity 0.4.22", + "pr": 531 + } + ], + "timestamp": 1524044013 + }, + { + "version": "0.4.0", + "changes": [ + { + "note": "Changed the config key `web3Provider` to `provider` to be consistent with other tools", + "pr": 501 + } + ], + "timestamp": 1523462196 + }, + { + "version": "0.3.5", + "changes": [ + { + "note": "Don't try to write contract artifact if an error occured", + "pr": 485 + } + ], + "timestamp": 1522673609 + }, + { + "version": "0.3.4", + "changes": [ + { + "note": "Create solc_bin directory if does not exist before attempting to compile", + "pr": 491 + } + ], + "timestamp": 1522658513 + }, + { + "version": "0.3.1", + "changes": [ + { + "note": "Add TS types for `yargs`" + } + ], + "timestamp": 1521298800 + }, + { + "version": "0.3.0", + "changes": [ + { + "note": "Add support for Solidity 0.4.20 and 0.4.21" + }, + { + "note": "Replace `jsonrpcPort` config with `jsonrpcUrl`", + "pr": 426 + }, + { + "note": "Replace `jsonrpc-port` CLI option with `jsonrpc-url`", + "pr": 426 + }, + { + "note": "Export the `Compiler`", + "pr": 426 + }, + { + "note": "Load solc from remote source instead of having it locally", + "pr": 426 + }, + { + "note": + "Add `bytecode`, `runtime_bytecode`, `source_map`, `source_map_runtime` and `sources` fields to artifacts", + "pr": 426 + }, + { + "note": "Remove 0x-specific `migrate` command", + "pr": 426 + }, + { + "note": + "Allow deployer to accept a provider instead of port and host. This makes it possible to run it with in-process ganache-core", + "pr": 426 + }, + { + "note": "Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package", + "pr": 452 + }, + { + "note": "Add `#!/usr/bin/env node` pragma above `cli.ts` script to fix command-line error." + } + ], + "timestamp": 1521298800 + }, + { + "version": "0.2.0", + "changes": [ + { + "note": "Check dependencies when determining if contracts should be recompiled", + "pr": 408 + }, + { + "note": + "Improve an error message for when deployer is supplied with an incorrect number of constructor arguments", + "pr": 419 + } + ], + "timestamp": 1520089200 + }, + { + "version": "0.1.0", + "changes": [ + { + "note": "Add the ability to pass in specific contracts to compile in CLI", + "pr": 400 + } + ], + "timestamp": 1518706800 + }, + { + "version": "0.0.8", + "changes": [ + { + "note": "Fix publishing issue where .npmignore was not properly excluding undesired content", + "pr": 389 + } + ], + "timestamp": 1518102000 + } +] diff --git a/packages/sol-compiler/CHANGELOG.md b/packages/sol-compiler/CHANGELOG.md new file mode 100644 index 000000000..4eb0ed453 --- /dev/null +++ b/packages/sol-compiler/CHANGELOG.md @@ -0,0 +1,60 @@ + + +CHANGELOG + +## v0.4.3 - _May 5, 2018_ + + * Dependencies updated + +## v0.4.2 - _May 4, 2018_ + + * Add support for solidity 0.4.23 (#545) + +## v0.4.1 - _April 18, 2018_ + + * Add support for solidity 0.4.22 (#531) + +## v0.4.0 - _April 11, 2018_ + + * Changed the config key `web3Provider` to `provider` to be consistent with other tools (#501) + +## v0.3.5 - _April 2, 2018_ + + * Don't try to write contract artifact if an error occured (#485) + +## v0.3.4 - _April 2, 2018_ + + * Create solc_bin directory if does not exist before attempting to compile (#491) + +## v0.3.1 - _March 17, 2018_ + + * Add TS types for `yargs` + +## v0.3.0 - _March 17, 2018_ + + * Add support for Solidity 0.4.20 and 0.4.21 + * Replace `jsonrpcPort` config with `jsonrpcUrl` (#426) + * Replace `jsonrpc-port` CLI option with `jsonrpc-url` (#426) + * Export the `Compiler` (#426) + * Load solc from remote source instead of having it locally (#426) + * Add `bytecode`, `runtime_bytecode`, `source_map`, `source_map_runtime` and `sources` fields to artifacts (#426) + * Remove 0x-specific `migrate` command (#426) + * Allow deployer to accept a provider instead of port and host. This makes it possible to run it with in-process ganache-core (#426) + * Consolidate all `console.log` calls into `logUtils` in the `@0xproject/utils` package (#452) + * Add `#!/usr/bin/env node` pragma above `cli.ts` script to fix command-line error. + +## v0.2.0 - _March 3, 2018_ + + * Check dependencies when determining if contracts should be recompiled (#408) + * Improve an error message for when deployer is supplied with an incorrect number of constructor arguments (#419) + +## v0.1.0 - _February 15, 2018_ + + * Add the ability to pass in specific contracts to compile in CLI (#400) + +## v0.0.8 - _February 8, 2018_ + + * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/sol-compiler/README.md b/packages/sol-compiler/README.md new file mode 100644 index 000000000..bb8175952 --- /dev/null +++ b/packages/sol-compiler/README.md @@ -0,0 +1,103 @@ +## @0xproject/sol-compiler + +This repository contains a CLI tool that facilitates compiling smart contracts. + +### Read the [Documentation](https://0xproject.com/docs/sol-compiler). + +## Installation + +#### CLI Installation + +```bash +yarn global add @0xproject/sol-compiler +``` + +#### API Installation + +```bash +yarn add @0xproject/sol-compiler +``` + +If your project is in [TypeScript](https://www.typescriptlang.org/), add the following to your `tsconfig.json`: + +```json +"compilerOptions": { + "typeRoots": ["node_modules/@0xproject/typescript-typings/types", "node_modules/@types"], +} +``` + +**Import** + +```typescript +import { Compiler } from '@0xproject/sol-compiler'; +``` + +or + +```javascript +var Compiler = require('@0xproject/sol-compiler').Compiler; +``` + +## Contributing + +We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. + +Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. + +### Install dependencies + +If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: + +```bash +yarn config set workspaces-experimental true +``` + +Then install dependencies + +```bash +yarn install +``` + +### Build + +If this is your **first** time building this package, you must first build **all** packages within the monorepo. This is because packages that depend on other packages located inside this monorepo are symlinked when run from **within** the monorepo. This allows you to make changes across multiple packages without first publishing dependent packages to NPM. To build all packages, run the following from the monorepo root directory: + +```bash +yarn lerna:rebuild +``` + +Or continuously rebuild on change: + +```bash +yarn dev +``` + +You can also build this specific package by running the following from within its directory: + +```bash +yarn build +``` + +or continuously rebuild on change: + +```bash +yarn build:watch +``` + +### Clean + +```bash +yarn clean +``` + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json new file mode 100644 index 000000000..8c2a10783 --- /dev/null +++ b/packages/sol-compiler/package.json @@ -0,0 +1,92 @@ +{ + "name": "@0xproject/sol-compiler", + "version": "0.4.3", + "description": "Solidity compiler wrapper and artifactor", + "main": "lib/src/index.js", + "types": "lib/src/index.d.ts", + "scripts": { + "build:watch": "tsc -w", + "build": "yarn clean && copyfiles 'test/fixtures/contracts/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", + "test": "run-s build run_mocha", + "run_mocha": "mocha lib/test/*_test.js --bail --exit", + "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", + "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", + "compile": "npm run build; node lib/src/cli.js compile", + "clean": "shx rm -rf lib scripts", + "migrate": "npm run build; node lib/src/cli.js migrate", + "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "test:circleci": "yarn test:coverage", + "docs:stage": "yarn build && node ./scripts/stage_docs.js", + "manual:postpublish": "yarn build; node ./scripts/postpublish.js", + "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", + "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" + }, + "config": { + "postpublish": { + "assets": [], + "docPublishConfigs": { + "extraFileIncludes": [ + "../types/src/index.ts" + ], + "s3BucketPath": "s3://doc-jsons/sol-compiler/", + "s3StagingBucketPath": "s3://staging-doc-jsons/sol-compiler/" + } + } + }, + "bin": { + "sol-compiler": "lib/src/cli.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "author": "Amir Bandeali", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-compiler/README.md", + "devDependencies": { + "@0xproject/dev-utils": "^0.4.1", + "@0xproject/monorepo-scripts": "^0.1.19", + "@0xproject/tslint-config": "^0.4.17", + "@types/require-from-string": "^1.2.0", + "@types/semver": "^5.5.0", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "copyfiles": "^1.2.0", + "dirty-chai": "^2.0.1", + "mocha": "^4.0.1", + "npm-run-all": "^4.1.2", + "nyc": "^11.0.1", + "shx": "^0.2.2", + "tslint": "5.8.0", + "typedoc": "0xProject/typedoc", + "types-bn": "^0.0.1", + "typescript": "2.7.1", + "web3-typescript-typings": "^0.10.2", + "zeppelin-solidity": "1.8.0" + }, + "dependencies": { + "@0xproject/json-schemas": "^0.7.23", + "@0xproject/sol-resolver": "^0.0.4", + "@0xproject/types": "^0.6.3", + "@0xproject/typescript-typings": "^0.3.1", + "@0xproject/utils": "^0.6.1", + "@0xproject/web3-wrapper": "^0.6.3", + "@types/yargs": "^11.0.0", + "chalk": "^2.3.0", + "ethereumjs-util": "^5.1.1", + "isomorphic-fetch": "^2.2.1", + "lodash": "^4.17.4", + "require-from-string": "^2.0.1", + "semver": "^5.5.0", + "solc": "^0.4.23", + "web3": "^0.20.0", + "web3-eth-abi": "^1.0.0-beta.24", + "yargs": "^10.0.3" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/sol-compiler/src/cli.ts b/packages/sol-compiler/src/cli.ts new file mode 100644 index 000000000..2412b8d34 --- /dev/null +++ b/packages/sol-compiler/src/cli.ts @@ -0,0 +1,41 @@ +#!/usr/bin/env node +// We need the above pragma since this script will be run as a command-line tool. + +import { BigNumber } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as _ from 'lodash'; +import * as path from 'path'; +import * as Web3 from 'web3'; +import * as yargs from 'yargs'; + +import { Compiler } from './compiler'; +import { constants } from './utils/constants'; +import { CompilerOptions } from './utils/types'; + +const DEFAULT_CONTRACTS_LIST = '*'; +const SEPARATOR = ','; + +(async () => { + const argv = yargs + .option('contracts-dir', { + type: 'string', + description: 'path of contracts directory to compile', + }) + .option('artifacts-dir', { + type: 'string', + description: 'path to write contracts artifacts to', + }) + .option('contracts', { + type: 'string', + default: DEFAULT_CONTRACTS_LIST, + description: 'comma separated list of contracts to compile', + }) + .help().argv; + const opts: CompilerOptions = { + contractsDir: argv.contractsDir, + artifactsDir: argv.artifactsDir, + contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), + }; + const compiler = new Compiler(opts); + await compiler.compileAsync(); +})(); diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts new file mode 100644 index 000000000..efb30091b --- /dev/null +++ b/packages/sol-compiler/src/compiler.ts @@ -0,0 +1,276 @@ +import { + ContractSource, + ContractSources, + EnumerableResolver, + FallthroughResolver, + FSResolver, + NameResolver, + NPMResolver, + RelativeFSResolver, + Resolver, + URLResolver, +} from '@0xproject/sol-resolver'; +import { ContractAbi } from '@0xproject/types'; +import { logUtils, promisify } from '@0xproject/utils'; +import chalk from 'chalk'; +import * as ethUtil from 'ethereumjs-util'; +import * as fs from 'fs'; +import 'isomorphic-fetch'; +import * as _ from 'lodash'; +import * as path from 'path'; +import * as requireFromString from 'require-from-string'; +import * as semver from 'semver'; +import solc = require('solc'); + +import { binPaths } from './solc/bin_paths'; +import { + createDirIfDoesNotExistAsync, + getContractArtifactIfExistsAsync, + getNormalizedErrMsg, + parseDependencies, + parseSolidityVersionRange, +} from './utils/compiler'; +import { constants } from './utils/constants'; +import { fsWrapper } from './utils/fs_wrapper'; +import { + CompilerOptions, + ContractArtifact, + ContractNetworkData, + ContractNetworks, + ContractSourceData, + ContractSpecificSourceData, + ContractVersionData, +} from './utils/types'; +import { utils } from './utils/utils'; + +type TYPE_ALL_FILES_IDENTIFIER = '*'; +const ALL_CONTRACTS_IDENTIFIER = '*'; +const ALL_FILES_IDENTIFIER = '*'; +const SOLC_BIN_DIR = path.join(__dirname, '..', '..', 'solc_bin'); +const DEFAULT_CONTRACTS_DIR = path.resolve('contracts'); +const DEFAULT_ARTIFACTS_DIR = path.resolve('artifacts'); +// Solc compiler settings cannot be configured from the commandline. +// If you need this configured, please create a `compiler.json` config file +// with your desired configurations. +const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = { + optimizer: { + enabled: false, + }, + outputSelection: { + [ALL_FILES_IDENTIFIER]: { + [ALL_CONTRACTS_IDENTIFIER]: ['abi', 'evm.bytecode.object'], + }, + }, +}; +const CONFIG_FILE = 'compiler.json'; + +/** + * The Compiler facilitates compiling Solidity smart contracts and saves the results + * to artifact files. + */ +export class Compiler { + private _resolver: Resolver; + private _nameResolver: NameResolver; + private _contractsDir: string; + private _compilerSettings: solc.CompilerSettings; + private _artifactsDir: string; + private _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER; + /** + * Instantiates a new instance of the Compiler class. + * @return An instance of the Compiler class. + */ + constructor(opts: CompilerOptions) { + // TODO: Look for config file in parent directories if not found in current directory + const config: CompilerOptions = fs.existsSync(CONFIG_FILE) + ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString()) + : {}; + this._contractsDir = opts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR; + this._compilerSettings = opts.compilerSettings || config.compilerSettings || DEFAULT_COMPILER_SETTINGS; + this._artifactsDir = opts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR; + this._specifiedContracts = opts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER; + this._nameResolver = new NameResolver(path.resolve(this._contractsDir)); + const resolver = new FallthroughResolver(); + resolver.appendResolver(new URLResolver()); + const packagePath = path.resolve(''); + resolver.appendResolver(new NPMResolver(packagePath)); + resolver.appendResolver(new RelativeFSResolver(this._contractsDir)); + resolver.appendResolver(new FSResolver()); + resolver.appendResolver(this._nameResolver); + this._resolver = resolver; + } + /** + * Compiles selected Solidity files found in `contractsDir` and writes JSON artifacts to `artifactsDir`. + */ + public async compileAsync(): Promise { + await createDirIfDoesNotExistAsync(this._artifactsDir); + await createDirIfDoesNotExistAsync(SOLC_BIN_DIR); + let contractNamesToCompile: string[] = []; + if (this._specifiedContracts === ALL_CONTRACTS_IDENTIFIER) { + const allContracts = this._nameResolver.getAll(); + contractNamesToCompile = _.map(allContracts, contractSource => + path.basename(contractSource.path, constants.SOLIDITY_FILE_EXTENSION), + ); + } else { + contractNamesToCompile = this._specifiedContracts; + } + for (const contractNameToCompile of contractNamesToCompile) { + await this._compileContractAsync(contractNameToCompile); + } + } + /** + * Compiles contract and saves artifact to artifactsDir. + * @param fileName Name of contract with '.sol' extension. + */ + private async _compileContractAsync(contractName: string): Promise { + const contractSource = this._resolver.resolve(contractName); + const absoluteContractPath = path.join(this._contractsDir, contractSource.path); + const currentArtifactIfExists = await getContractArtifactIfExistsAsync(this._artifactsDir, contractName); + const sourceTreeHashHex = `0x${this._getSourceTreeHash(absoluteContractPath).toString('hex')}`; + let shouldCompile = false; + if (_.isUndefined(currentArtifactIfExists)) { + shouldCompile = true; + } else { + const currentArtifact = currentArtifactIfExists as ContractArtifact; + const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION; + const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings); + const didSourceChange = currentArtifact.sourceTreeHashHex !== sourceTreeHashHex; + shouldCompile = !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange; + } + if (!shouldCompile) { + return; + } + const solcVersionRange = parseSolidityVersionRange(contractSource.source); + const availableCompilerVersions = _.keys(binPaths); + const solcVersion = semver.maxSatisfying(availableCompilerVersions, solcVersionRange); + const fullSolcVersion = binPaths[solcVersion]; + const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion); + let solcjs: string; + const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename); + if (isCompilerAvailableLocally) { + solcjs = fs.readFileSync(compilerBinFilename).toString(); + } else { + logUtils.log(`Downloading ${fullSolcVersion}...`); + const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`; + const response = await fetch(url); + if (response.status !== 200) { + throw new Error(`Failed to load ${fullSolcVersion}`); + } + solcjs = await response.text(); + fs.writeFileSync(compilerBinFilename, solcjs); + } + const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename)); + + logUtils.log(`Compiling ${contractName} with Solidity v${solcVersion}...`); + const source = contractSource.source; + const standardInput: solc.StandardInput = { + language: 'Solidity', + sources: { + [contractSource.path]: { + content: contractSource.source, + }, + }, + settings: this._compilerSettings, + }; + const compiled: solc.StandardOutput = JSON.parse( + solcInstance.compileStandardWrapper(JSON.stringify(standardInput), importPath => { + const sourceCodeIfExists = this._resolver.resolve(importPath); + return { contents: sourceCodeIfExists.source }; + }), + ); + + if (!_.isUndefined(compiled.errors)) { + const SOLIDITY_WARNING = 'warning'; + const errors = _.filter(compiled.errors, entry => entry.severity !== SOLIDITY_WARNING); + const warnings = _.filter(compiled.errors, entry => entry.severity === SOLIDITY_WARNING); + if (!_.isEmpty(errors)) { + errors.forEach(error => { + const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message); + logUtils.log(chalk.red(normalizedErrMsg)); + }); + process.exit(1); + } else { + warnings.forEach(warning => { + const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message); + logUtils.log(chalk.yellow(normalizedWarningMsg)); + }); + } + } + const compiledData = compiled.contracts[contractSource.path][contractName]; + if (_.isUndefined(compiledData)) { + throw new Error( + `Contract ${contractName} not found in ${ + contractSource.path + }. Please make sure your contract has the same name as it's file name`, + ); + } + if (!_.isUndefined(compiledData.evm)) { + if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) { + compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object); + } + if ( + !_.isUndefined(compiledData.evm.deployedBytecode) && + !_.isUndefined(compiledData.evm.deployedBytecode.object) + ) { + compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix( + compiledData.evm.deployedBytecode.object, + ); + } + } + + const sourceCodes = _.mapValues( + compiled.sources, + (_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source, + ); + const contractVersion: ContractVersionData = { + compilerOutput: compiledData, + sources: compiled.sources, + sourceCodes, + sourceTreeHashHex, + compiler: { + name: 'solc', + version: solcVersion, + settings: this._compilerSettings, + }, + }; + + let newArtifact: ContractArtifact; + if (!_.isUndefined(currentArtifactIfExists)) { + const currentArtifact = currentArtifactIfExists as ContractArtifact; + newArtifact = { + ...currentArtifact, + ...contractVersion, + }; + } else { + newArtifact = { + schemaVersion: constants.LATEST_ARTIFACT_VERSION, + contractName, + ...contractVersion, + networks: {}, + }; + } + + const artifactString = utils.stringifyWithFormatting(newArtifact); + const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; + await fsWrapper.writeFileAsync(currentArtifactPath, artifactString); + logUtils.log(`${contractName} artifact saved!`); + } + /** + * Gets the source tree hash for a file and its dependencies. + * @param fileName Name of contract file. + */ + private _getSourceTreeHash(importPath: string): Buffer { + const contractSource = this._resolver.resolve(importPath); + const dependencies = parseDependencies(contractSource); + const sourceHash = ethUtil.sha3(contractSource.source); + if (dependencies.length === 0) { + return sourceHash; + } else { + const dependencySourceTreeHashes = _.map(dependencies, (dependency: string) => + this._getSourceTreeHash(dependency), + ); + const sourceTreeHashesBuffer = Buffer.concat([sourceHash, ...dependencySourceTreeHashes]); + const sourceTreeHash = ethUtil.sha3(sourceTreeHashesBuffer); + return sourceTreeHash; + } + } +} diff --git a/packages/sol-compiler/src/globals.d.ts b/packages/sol-compiler/src/globals.d.ts new file mode 100644 index 000000000..94e63a32d --- /dev/null +++ b/packages/sol-compiler/src/globals.d.ts @@ -0,0 +1,6 @@ +declare module '*.json' { + const json: any; + /* tslint:disable */ + export default json; + /* tslint:enable */ +} diff --git a/packages/sol-compiler/src/index.ts b/packages/sol-compiler/src/index.ts new file mode 100644 index 000000000..4b4c51de2 --- /dev/null +++ b/packages/sol-compiler/src/index.ts @@ -0,0 +1,2 @@ +export { Compiler } from './compiler'; +export { ContractArtifact, ContractNetworks } from './utils/types'; diff --git a/packages/sol-compiler/src/monorepo_scripts/postpublish.ts b/packages/sol-compiler/src/monorepo_scripts/postpublish.ts new file mode 100644 index 000000000..dcb99d0f7 --- /dev/null +++ b/packages/sol-compiler/src/monorepo_scripts/postpublish.ts @@ -0,0 +1,8 @@ +import { postpublishUtils } from '@0xproject/monorepo-scripts'; + +import * as packageJSON from '../package.json'; +import * as tsConfigJSON from '../tsconfig.json'; + +const cwd = `${__dirname}/..`; +// tslint:disable-next-line:no-floating-promises +postpublishUtils.runAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/sol-compiler/src/monorepo_scripts/stage_docs.ts b/packages/sol-compiler/src/monorepo_scripts/stage_docs.ts new file mode 100644 index 000000000..e732ac8eb --- /dev/null +++ b/packages/sol-compiler/src/monorepo_scripts/stage_docs.ts @@ -0,0 +1,8 @@ +import { postpublishUtils } from '@0xproject/monorepo-scripts'; + +import * as packageJSON from '../package.json'; +import * as tsConfigJSON from '../tsconfig.json'; + +const cwd = `${__dirname}/..`; +// tslint:disable-next-line:no-floating-promises +postpublishUtils.publishDocsToStagingAsync(packageJSON, tsConfigJSON, cwd); diff --git a/packages/sol-compiler/src/solc/bin_paths.ts b/packages/sol-compiler/src/solc/bin_paths.ts new file mode 100644 index 000000000..1b5e8c6f1 --- /dev/null +++ b/packages/sol-compiler/src/solc/bin_paths.ts @@ -0,0 +1,20 @@ +export interface BinaryPaths { + [key: string]: string; +} + +export const binPaths: BinaryPaths = { + '0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js', + '0.4.11': 'soljson-v0.4.11+commit.68ef5810.js', + '0.4.12': 'soljson-v0.4.12+commit.194ff033.js', + '0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js', + '0.4.14': 'soljson-v0.4.14+commit.c2215d46.js', + '0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js', + '0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js', + '0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js', + '0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js', + '0.4.19': 'soljson-v0.4.19+commit.c4cbbb05.js', + '0.4.20': 'soljson-v0.4.20+commit.3155dd80.js', + '0.4.21': 'soljson-v0.4.21+commit.dfe3193c.js', + '0.4.22': 'soljson-v0.4.22+commit.4cb486ee.js', + '0.4.23': 'soljson-v0.4.23+commit.124ca40d.js', +}; diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts new file mode 100644 index 000000000..c571b2581 --- /dev/null +++ b/packages/sol-compiler/src/utils/compiler.ts @@ -0,0 +1,107 @@ +import { ContractSource, ContractSources } from '@0xproject/sol-resolver'; +import { logUtils } from '@0xproject/utils'; +import * as _ from 'lodash'; +import * as path from 'path'; +import * as solc from 'solc'; + +import { constants } from './constants'; +import { fsWrapper } from './fs_wrapper'; +import { ContractArtifact } from './types'; + +/** + * Gets contract data on network or returns if an artifact does not exist. + * @param artifactsDir Path to the artifacts directory. + * @param contractName Name of contract. + * @return Contract data on network or undefined. + */ +export async function getContractArtifactIfExistsAsync( + artifactsDir: string, + contractName: string, +): Promise { + let contractArtifact; + const currentArtifactPath = `${artifactsDir}/${contractName}.json`; + try { + const opts = { + encoding: 'utf8', + }; + const contractArtifactString = await fsWrapper.readFileAsync(currentArtifactPath, opts); + contractArtifact = JSON.parse(contractArtifactString); + return contractArtifact; + } catch (err) { + logUtils.log(`Artifact for ${contractName} does not exist`); + return undefined; + } +} + +/** + * Creates a directory if it does not already exist. + * @param artifactsDir Path to the directory. + */ +export async function createDirIfDoesNotExistAsync(dirPath: string): Promise { + if (!fsWrapper.doesPathExistSync(dirPath)) { + logUtils.log(`Creating directory at ${dirPath}...`); + await fsWrapper.mkdirAsync(dirPath); + } +} + +/** + * Searches Solidity source code for compiler version range. + * @param source Source code of contract. + * @return Solc compiler version range. + */ +export function parseSolidityVersionRange(source: string): string { + const SOLIDITY_VERSION_RANGE_REGEX = /pragma\s+solidity\s+(.*);/; + const solcVersionRangeMatch = source.match(SOLIDITY_VERSION_RANGE_REGEX); + if (_.isNull(solcVersionRangeMatch)) { + throw new Error('Could not find Solidity version range in source'); + } + const solcVersionRange = solcVersionRangeMatch[1]; + return solcVersionRange; +} + +/** + * Normalizes the path found in the error message. + * Example: converts 'base/Token.sol:6:46: Warning: Unused local variable' + * to 'Token.sol:6:46: Warning: Unused local variable' + * This is used to prevent logging the same error multiple times. + * @param errMsg An error message from the compiled output. + * @return The error message with directories truncated from the contract path. + */ +export function getNormalizedErrMsg(errMsg: string): string { + const SOLIDITY_FILE_EXTENSION_REGEX = /(.*\.sol)/; + const errPathMatch = errMsg.match(SOLIDITY_FILE_EXTENSION_REGEX); + if (_.isNull(errPathMatch)) { + throw new Error('Could not find a path in error message'); + } + const errPath = errPathMatch[0]; + const baseContract = path.basename(errPath); + const normalizedErrMsg = errMsg.replace(errPath, baseContract); + return normalizedErrMsg; +} + +/** + * Parses the contract source code and extracts the dendencies + * @param source Contract source code + * @return List of dependendencies + */ +export function parseDependencies(contractSource: ContractSource): string[] { + // TODO: Use a proper parser + const source = contractSource.source; + const IMPORT_REGEX = /(import\s)/; + const DEPENDENCY_PATH_REGEX = /"([^"]+)"/; // Source: https://github.com/BlockChainCompany/soljitsu/blob/master/lib/shared.js + const dependencies: string[] = []; + const lines = source.split('\n'); + _.forEach(lines, line => { + if (!_.isNull(line.match(IMPORT_REGEX))) { + const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX); + if (!_.isNull(dependencyMatch)) { + let dependencyPath = dependencyMatch[1]; + if (dependencyPath.startsWith('.')) { + dependencyPath = path.join(path.dirname(contractSource.path), dependencyPath); + } + dependencies.push(dependencyPath); + } + } + }); + return dependencies; +} diff --git a/packages/sol-compiler/src/utils/constants.ts b/packages/sol-compiler/src/utils/constants.ts new file mode 100644 index 000000000..df2ddb3b2 --- /dev/null +++ b/packages/sol-compiler/src/utils/constants.ts @@ -0,0 +1,5 @@ +export const constants = { + SOLIDITY_FILE_EXTENSION: '.sol', + BASE_COMPILER_URL: 'https://ethereum.github.io/solc-bin/bin/', + LATEST_ARTIFACT_VERSION: '2.0.0', +}; diff --git a/packages/sol-compiler/src/utils/encoder.ts b/packages/sol-compiler/src/utils/encoder.ts new file mode 100644 index 000000000..806efbbca --- /dev/null +++ b/packages/sol-compiler/src/utils/encoder.ts @@ -0,0 +1,18 @@ +import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types'; +import * as _ from 'lodash'; +import * as web3Abi from 'web3-eth-abi'; + +export const encoder = { + encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string { + const constructorTypes: string[] = []; + _.each(abi, (element: AbiDefinition) => { + if (element.type === AbiType.Constructor) { + _.each(element.inputs, (input: DataItem) => { + constructorTypes.push(input.type); + }); + } + }); + const encodedParameters = web3Abi.encodeParameters(constructorTypes, args); + return encodedParameters; + }, +}; diff --git a/packages/sol-compiler/src/utils/fs_wrapper.ts b/packages/sol-compiler/src/utils/fs_wrapper.ts new file mode 100644 index 000000000..e02c83f27 --- /dev/null +++ b/packages/sol-compiler/src/utils/fs_wrapper.ts @@ -0,0 +1,12 @@ +import { promisify } from '@0xproject/utils'; +import * as fs from 'fs'; + +export const fsWrapper = { + readdirAsync: promisify(fs.readdir), + readFileAsync: promisify(fs.readFile), + writeFileAsync: promisify(fs.writeFile), + mkdirAsync: promisify(fs.mkdir), + doesPathExistSync: fs.existsSync, + rmdirSync: fs.rmdirSync, + removeFileAsync: promisify(fs.unlink), +}; diff --git a/packages/sol-compiler/src/utils/types.ts b/packages/sol-compiler/src/utils/types.ts new file mode 100644 index 000000000..b12a11b79 --- /dev/null +++ b/packages/sol-compiler/src/utils/types.ts @@ -0,0 +1,79 @@ +import { ContractAbi, Provider, TxData } from '@0xproject/types'; +import * as solc from 'solc'; +import * as Web3 from 'web3'; +import * as yargs from 'yargs'; + +export enum AbiType { + Function = 'function', + Constructor = 'constructor', + Event = 'event', + Fallback = 'fallback', +} + +export interface ContractArtifact extends ContractVersionData { + schemaVersion: string; + contractName: string; + networks: ContractNetworks; +} + +export interface ContractVersionData { + compiler: { + name: 'solc'; + version: string; + settings: solc.CompilerSettings; + }; + sources: { + [sourceName: string]: { + id: number; + }; + }; + sourceCodes: { + [sourceName: string]: string; + }; + sourceTreeHashHex: string; + compilerOutput: solc.StandardContractOutput; +} + +export interface ContractNetworks { + [networkId: number]: ContractNetworkData; +} + +export interface ContractNetworkData { + address: string; + links: { + [linkName: string]: string; + }; + constructorArgs: string; +} + +export interface SolcErrors { + [key: string]: boolean; +} + +export interface CompilerOptions { + contractsDir?: string; + artifactsDir?: string; + compilerSettings?: solc.CompilerSettings; + contracts?: string[] | '*'; +} + +export interface ContractSourceData { + [contractName: string]: ContractSpecificSourceData; +} + +export interface ContractSpecificSourceData { + solcVersionRange: string; + sourceHash: Buffer; + sourceTreeHash: Buffer; +} + +export interface Token { + address?: string; + name: string; + symbol: string; + decimals: number; + ipfsHash: string; + swarmHash: string; +} + +export type DoneCallback = (err?: Error) => void; diff --git a/packages/sol-compiler/src/utils/utils.ts b/packages/sol-compiler/src/utils/utils.ts new file mode 100644 index 000000000..9b1e59f9d --- /dev/null +++ b/packages/sol-compiler/src/utils/utils.ts @@ -0,0 +1,8 @@ +export const utils = { + stringifyWithFormatting(obj: any): string { + const jsonReplacer: null = null; + const numberOfJsonSpaces = 4; + const stringifiedObj = JSON.stringify(obj, jsonReplacer, numberOfJsonSpaces); + return stringifiedObj; + }, +}; diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts new file mode 100644 index 000000000..9baf433d4 --- /dev/null +++ b/packages/sol-compiler/test/compiler_test.ts @@ -0,0 +1,44 @@ +import * as chai from 'chai'; +import 'mocha'; + +import { Compiler } from '../src/compiler'; +import { fsWrapper } from '../src/utils/fs_wrapper'; +import { CompilerOptions, ContractArtifact, ContractNetworkData, DoneCallback } from '../src/utils/types'; + +import { exchange_binary } from './fixtures/exchange_bin'; +import { constants } from './util/constants'; + +const expect = chai.expect; + +describe('#Compiler', function() { + this.timeout(constants.timeoutMs); + const artifactsDir = `${__dirname}/fixtures/artifacts`; + const contractsDir = `${__dirname}/fixtures/contracts`; + const exchangeArtifactPath = `${artifactsDir}/Exchange.json`; + const compilerOpts: CompilerOptions = { + artifactsDir, + contractsDir, + contracts: constants.contracts, + }; + const compiler = new Compiler(compilerOpts); + beforeEach((done: DoneCallback) => { + (async () => { + if (fsWrapper.doesPathExistSync(exchangeArtifactPath)) { + await fsWrapper.removeFileAsync(exchangeArtifactPath); + } + await compiler.compileAsync(); + done(); + })().catch(done); + }); + it('should create an Exchange artifact with the correct unlinked binary', async () => { + const opts = { + encoding: 'utf8', + }; + const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); + const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); + // The last 43 bytes of the binaries are metadata which may not be equivalent + const unlinkedBinaryWithoutMetadata = exchangeArtifact.compilerOutput.evm.bytecode.object.slice(0, -86); + const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -86); + expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata); + }); +}); diff --git a/packages/sol-compiler/test/compiler_utils_test.ts b/packages/sol-compiler/test/compiler_utils_test.ts new file mode 100644 index 000000000..4fe7b994e --- /dev/null +++ b/packages/sol-compiler/test/compiler_utils_test.ts @@ -0,0 +1,83 @@ +import * as chai from 'chai'; +import * as dirtyChai from 'dirty-chai'; +import * as _ from 'lodash'; +import 'mocha'; + +import { + createDirIfDoesNotExistAsync, + getNormalizedErrMsg, + parseDependencies, + parseSolidityVersionRange, +} from '../src/utils/compiler'; +import { fsWrapper } from '../src/utils/fs_wrapper'; + +chai.use(dirtyChai); +const expect = chai.expect; + +describe('Compiler utils', () => { + describe('#getNormalizedErrorMessage', () => { + it('normalizes the error message', () => { + const errMsg = 'base/Token.sol:6:46: Warning: Unused local variable'; + const normalizedErrMsg = getNormalizedErrMsg(errMsg); + expect(normalizedErrMsg).to.be.equal('Token.sol:6:46: Warning: Unused local variable'); + }); + }); + describe('#createDirIfDoesNotExistAsync', () => { + it('creates artifacts dir', async () => { + const artifactsDir = `${__dirname}/artifacts`; + expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false(); + await createDirIfDoesNotExistAsync(artifactsDir); + expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.true(); + fsWrapper.rmdirSync(artifactsDir); + expect(fsWrapper.doesPathExistSync(artifactsDir)).to.be.false(); + }); + }); + describe('#parseSolidityVersionRange', () => { + it('correctly parses the version range', () => { + expect(parseSolidityVersionRange('pragma solidity ^0.0.1;')).to.be.equal('^0.0.1'); + expect(parseSolidityVersionRange('\npragma solidity 0.0.1;')).to.be.equal('0.0.1'); + expect(parseSolidityVersionRange('pragma solidity <=1.0.1;')).to.be.equal('<=1.0.1'); + expect(parseSolidityVersionRange('pragma solidity ~1.0.1;')).to.be.equal('~1.0.1'); + }); + // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser + it.skip('correctly parses the version range with comments', () => { + expect(parseSolidityVersionRange('// pragma solidity ~1.0.1;\npragma solidity ~1.0.2;')).to.be.equal( + '~1.0.2', + ); + }); + }); + describe('#parseDependencies', () => { + it('correctly parses Exchange dependencies', async () => { + const path = `${__dirname}/fixtures/contracts/Exchange.sol`; + const source = await fsWrapper.readFileAsync(path, { + encoding: 'utf8', + }); + const dependencies = parseDependencies({ source, path }); + const expectedDependencies = [ + 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol', + 'packages/sol-compiler/lib/test/fixtures/contracts/TokenTransferProxy.sol', + 'packages/sol-compiler/lib/test/fixtures/contracts/base/SafeMath.sol', + ]; + _.each(expectedDependencies, expectedDepdency => { + const foundDependency = _.find(dependencies, dependency => _.endsWith(dependency, expectedDepdency)); + expect(foundDependency, `${expectedDepdency} not found`).to.not.be.undefined(); + }); + }); + it('correctly parses TokenTransferProxy dependencies', async () => { + const path = `${__dirname}/fixtures/contracts/TokenTransferProxy.sol`; + const source = await fsWrapper.readFileAsync(path, { + encoding: 'utf8', + }); + expect(parseDependencies({ source, path })).to.be.deep.equal([ + 'zeppelin-solidity/contracts/ownership/Ownable.sol', + 'zeppelin-solidity/contracts/token/ERC20/ERC20.sol', + ]); + }); + // TODO: For now that doesn't work. This will work after we switch to a grammar-based parser + it.skip('correctly parses commented out dependencies', async () => { + const path = ''; + const source = `// import "./TokenTransferProxy.sol";`; + expect(parseDependencies({ path, source })).to.be.deep.equal([]); + }); + }); +}); diff --git a/packages/sol-compiler/test/fixtures/contracts/Exchange.sol b/packages/sol-compiler/test/fixtures/contracts/Exchange.sol new file mode 100644 index 000000000..e3725335b --- /dev/null +++ b/packages/sol-compiler/test/fixtures/contracts/Exchange.sol @@ -0,0 +1,603 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.14; + +import {ERC20 as Token} from "zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; + +import "./TokenTransferProxy.sol"; +import "./base/SafeMath.sol"; + +/// @title Exchange - Facilitates exchange of ERC20 tokens. +/// @author Amir Bandeali - , Will Warren - +contract Exchange is SafeMath { + + // Error Codes + enum Errors { + ORDER_EXPIRED, // Order has already expired + ORDER_FULLY_FILLED_OR_CANCELLED, // Order has already been fully filled or cancelled + ROUNDING_ERROR_TOO_LARGE, // Rounding error too large + INSUFFICIENT_BALANCE_OR_ALLOWANCE // Insufficient balance or allowance for token transfer + } + + string constant public VERSION = "1.0.0"; + uint16 constant public EXTERNAL_QUERY_GAS_LIMIT = 4999; // Changes to state require at least 5000 gas + + address public ZRX_TOKEN_CONTRACT; + address public TOKEN_TRANSFER_PROXY_CONTRACT; + + // Mappings of orderHash => amounts of takerTokenAmount filled or cancelled. + mapping (bytes32 => uint) public filled; + mapping (bytes32 => uint) public cancelled; + + event LogFill( + address indexed maker, + address taker, + address indexed feeRecipient, + address makerToken, + address takerToken, + uint filledMakerTokenAmount, + uint filledTakerTokenAmount, + uint paidMakerFee, + uint paidTakerFee, + bytes32 indexed tokens, // keccak256(makerToken, takerToken), allows subscribing to a token pair + bytes32 orderHash + ); + + event LogCancel( + address indexed maker, + address indexed feeRecipient, + address makerToken, + address takerToken, + uint cancelledMakerTokenAmount, + uint cancelledTakerTokenAmount, + bytes32 indexed tokens, + bytes32 orderHash + ); + + event LogError(uint8 indexed errorId, bytes32 indexed orderHash); + + struct Order { + address maker; + address taker; + address makerToken; + address takerToken; + address feeRecipient; + uint makerTokenAmount; + uint takerTokenAmount; + uint makerFee; + uint takerFee; + uint expirationTimestampInSec; + bytes32 orderHash; + } + + function Exchange(address _zrxToken, address _tokenTransferProxy) { + ZRX_TOKEN_CONTRACT = _zrxToken; + TOKEN_TRANSFER_PROXY_CONTRACT = _tokenTransferProxy; + } + + /* + * Core exchange functions + */ + + /// @dev Fills the input order. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param fillTakerTokenAmount Desired amount of takerToken to fill. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfer will fail before attempting. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + /// @return Total amount of takerToken filled in trade. + function fillOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint fillTakerTokenAmount, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8 v, + bytes32 r, + bytes32 s) + public + returns (uint filledTakerTokenAmount) + { + Order memory order = Order({ + maker: orderAddresses[0], + taker: orderAddresses[1], + makerToken: orderAddresses[2], + takerToken: orderAddresses[3], + feeRecipient: orderAddresses[4], + makerTokenAmount: orderValues[0], + takerTokenAmount: orderValues[1], + makerFee: orderValues[2], + takerFee: orderValues[3], + expirationTimestampInSec: orderValues[4], + orderHash: getOrderHash(orderAddresses, orderValues) + }); + + require(order.taker == address(0) || order.taker == msg.sender); + require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && fillTakerTokenAmount > 0); + require(isValidSignature( + order.maker, + order.orderHash, + v, + r, + s + )); + + if (block.timestamp >= order.expirationTimestampInSec) { + LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash); + return 0; + } + + uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash)); + filledTakerTokenAmount = min256(fillTakerTokenAmount, remainingTakerTokenAmount); + if (filledTakerTokenAmount == 0) { + LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash); + return 0; + } + + if (isRoundingError(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount)) { + LogError(uint8(Errors.ROUNDING_ERROR_TOO_LARGE), order.orderHash); + return 0; + } + + if (!shouldThrowOnInsufficientBalanceOrAllowance && !isTransferable(order, filledTakerTokenAmount)) { + LogError(uint8(Errors.INSUFFICIENT_BALANCE_OR_ALLOWANCE), order.orderHash); + return 0; + } + + uint filledMakerTokenAmount = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount); + uint paidMakerFee; + uint paidTakerFee; + filled[order.orderHash] = safeAdd(filled[order.orderHash], filledTakerTokenAmount); + require(transferViaTokenTransferProxy( + order.makerToken, + order.maker, + msg.sender, + filledMakerTokenAmount + )); + require(transferViaTokenTransferProxy( + order.takerToken, + msg.sender, + order.maker, + filledTakerTokenAmount + )); + if (order.feeRecipient != address(0)) { + if (order.makerFee > 0) { + paidMakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.makerFee); + require(transferViaTokenTransferProxy( + ZRX_TOKEN_CONTRACT, + order.maker, + order.feeRecipient, + paidMakerFee + )); + } + if (order.takerFee > 0) { + paidTakerFee = getPartialAmount(filledTakerTokenAmount, order.takerTokenAmount, order.takerFee); + require(transferViaTokenTransferProxy( + ZRX_TOKEN_CONTRACT, + msg.sender, + order.feeRecipient, + paidTakerFee + )); + } + } + + LogFill( + order.maker, + msg.sender, + order.feeRecipient, + order.makerToken, + order.takerToken, + filledMakerTokenAmount, + filledTakerTokenAmount, + paidMakerFee, + paidTakerFee, + keccak256(order.makerToken, order.takerToken), + order.orderHash + ); + return filledTakerTokenAmount; + } + + /// @dev Cancels the input order. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param cancelTakerTokenAmount Desired amount of takerToken to cancel in order. + /// @return Amount of takerToken cancelled. + function cancelOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint cancelTakerTokenAmount) + public + returns (uint) + { + Order memory order = Order({ + maker: orderAddresses[0], + taker: orderAddresses[1], + makerToken: orderAddresses[2], + takerToken: orderAddresses[3], + feeRecipient: orderAddresses[4], + makerTokenAmount: orderValues[0], + takerTokenAmount: orderValues[1], + makerFee: orderValues[2], + takerFee: orderValues[3], + expirationTimestampInSec: orderValues[4], + orderHash: getOrderHash(orderAddresses, orderValues) + }); + + require(order.maker == msg.sender); + require(order.makerTokenAmount > 0 && order.takerTokenAmount > 0 && cancelTakerTokenAmount > 0); + + if (block.timestamp >= order.expirationTimestampInSec) { + LogError(uint8(Errors.ORDER_EXPIRED), order.orderHash); + return 0; + } + + uint remainingTakerTokenAmount = safeSub(order.takerTokenAmount, getUnavailableTakerTokenAmount(order.orderHash)); + uint cancelledTakerTokenAmount = min256(cancelTakerTokenAmount, remainingTakerTokenAmount); + if (cancelledTakerTokenAmount == 0) { + LogError(uint8(Errors.ORDER_FULLY_FILLED_OR_CANCELLED), order.orderHash); + return 0; + } + + cancelled[order.orderHash] = safeAdd(cancelled[order.orderHash], cancelledTakerTokenAmount); + + LogCancel( + order.maker, + order.feeRecipient, + order.makerToken, + order.takerToken, + getPartialAmount(cancelledTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount), + cancelledTakerTokenAmount, + keccak256(order.makerToken, order.takerToken), + order.orderHash + ); + return cancelledTakerTokenAmount; + } + + /* + * Wrapper functions + */ + + /// @dev Fills an order with specified parameters and ECDSA signature, throws if specified amount not filled entirely. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param fillTakerTokenAmount Desired amount of takerToken to fill. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + function fillOrKillOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint fillTakerTokenAmount, + uint8 v, + bytes32 r, + bytes32 s) + public + { + require(fillOrder( + orderAddresses, + orderValues, + fillTakerTokenAmount, + false, + v, + r, + s + ) == fillTakerTokenAmount); + } + + /// @dev Synchronously executes multiple fill orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + function batchFillOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] fillTakerTokenAmounts, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8[] v, + bytes32[] r, + bytes32[] s) + public + { + for (uint i = 0; i < orderAddresses.length; i++) { + fillOrder( + orderAddresses[i], + orderValues[i], + fillTakerTokenAmounts[i], + shouldThrowOnInsufficientBalanceOrAllowance, + v[i], + r[i], + s[i] + ); + } + } + + /// @dev Synchronously executes multiple fillOrKill orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + function batchFillOrKillOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] fillTakerTokenAmounts, + uint8[] v, + bytes32[] r, + bytes32[] s) + public + { + for (uint i = 0; i < orderAddresses.length; i++) { + fillOrKillOrder( + orderAddresses[i], + orderValues[i], + fillTakerTokenAmounts[i], + v[i], + r[i], + s[i] + ); + } + } + + /// @dev Synchronously executes multiple fill orders in a single transaction until total fillTakerTokenAmount filled. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmount Desired total amount of takerToken to fill in orders. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + /// @return Total amount of fillTakerTokenAmount filled in orders. + function fillOrdersUpTo( + address[5][] orderAddresses, + uint[6][] orderValues, + uint fillTakerTokenAmount, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8[] v, + bytes32[] r, + bytes32[] s) + public + returns (uint) + { + uint filledTakerTokenAmount = 0; + for (uint i = 0; i < orderAddresses.length; i++) { + require(orderAddresses[i][3] == orderAddresses[0][3]); // takerToken must be the same for each order + filledTakerTokenAmount = safeAdd(filledTakerTokenAmount, fillOrder( + orderAddresses[i], + orderValues[i], + safeSub(fillTakerTokenAmount, filledTakerTokenAmount), + shouldThrowOnInsufficientBalanceOrAllowance, + v[i], + r[i], + s[i] + )); + if (filledTakerTokenAmount == fillTakerTokenAmount) break; + } + return filledTakerTokenAmount; + } + + /// @dev Synchronously cancels multiple orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param cancelTakerTokenAmounts Array of desired amounts of takerToken to cancel in orders. + function batchCancelOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] cancelTakerTokenAmounts) + public + { + for (uint i = 0; i < orderAddresses.length; i++) { + cancelOrder( + orderAddresses[i], + orderValues[i], + cancelTakerTokenAmounts[i] + ); + } + } + + /* + * Constant public functions + */ + + /// @dev Calculates Keccak-256 hash of order with specified parameters. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @return Keccak-256 hash of order. + function getOrderHash(address[5] orderAddresses, uint[6] orderValues) + public + constant + returns (bytes32) + { + return keccak256( + address(this), + orderAddresses[0], // maker + orderAddresses[1], // taker + orderAddresses[2], // makerToken + orderAddresses[3], // takerToken + orderAddresses[4], // feeRecipient + orderValues[0], // makerTokenAmount + orderValues[1], // takerTokenAmount + orderValues[2], // makerFee + orderValues[3], // takerFee + orderValues[4], // expirationTimestampInSec + orderValues[5] // salt + ); + } + + /// @dev Verifies that an order signature is valid. + /// @param signer address of signer. + /// @param hash Signed Keccak-256 hash. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + /// @return Validity of order signature. + function isValidSignature( + address signer, + bytes32 hash, + uint8 v, + bytes32 r, + bytes32 s) + public + constant + returns (bool) + { + return signer == ecrecover( + keccak256("\x19Ethereum Signed Message:\n32", hash), + v, + r, + s + ); + } + + /// @dev Checks if rounding error > 0.1%. + /// @param numerator Numerator. + /// @param denominator Denominator. + /// @param target Value to multiply with numerator/denominator. + /// @return Rounding error is present. + function isRoundingError(uint numerator, uint denominator, uint target) + public + constant + returns (bool) + { + uint remainder = mulmod(target, numerator, denominator); + if (remainder == 0) return false; // No rounding error. + + uint errPercentageTimes1000000 = safeDiv( + safeMul(remainder, 1000000), + safeMul(numerator, target) + ); + return errPercentageTimes1000000 > 1000; + } + + /// @dev Calculates partial value given a numerator and denominator. + /// @param numerator Numerator. + /// @param denominator Denominator. + /// @param target Value to calculate partial of. + /// @return Partial value of target. + function getPartialAmount(uint numerator, uint denominator, uint target) + public + constant + returns (uint) + { + return safeDiv(safeMul(numerator, target), denominator); + } + + /// @dev Calculates the sum of values already filled and cancelled for a given order. + /// @param orderHash The Keccak-256 hash of the given order. + /// @return Sum of values already filled and cancelled. + function getUnavailableTakerTokenAmount(bytes32 orderHash) + public + constant + returns (uint) + { + return safeAdd(filled[orderHash], cancelled[orderHash]); + } + + + /* + * Internal functions + */ + + /// @dev Transfers a token using TokenTransferProxy transferFrom function. + /// @param token Address of token to transferFrom. + /// @param from Address transfering token. + /// @param to Address receiving token. + /// @param value Amount of token to transfer. + /// @return Success of token transfer. + function transferViaTokenTransferProxy( + address token, + address from, + address to, + uint value) + internal + returns (bool) + { + return TokenTransferProxy(TOKEN_TRANSFER_PROXY_CONTRACT).transferFrom(token, from, to, value); + } + + /// @dev Checks if any order transfers will fail. + /// @param order Order struct of params that will be checked. + /// @param fillTakerTokenAmount Desired amount of takerToken to fill. + /// @return Predicted result of transfers. + function isTransferable(Order order, uint fillTakerTokenAmount) + internal + constant // The called token contracts may attempt to change state, but will not be able to due to gas limits on getBalance and getAllowance. + returns (bool) + { + address taker = msg.sender; + uint fillMakerTokenAmount = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerTokenAmount); + + if (order.feeRecipient != address(0)) { + bool isMakerTokenZRX = order.makerToken == ZRX_TOKEN_CONTRACT; + bool isTakerTokenZRX = order.takerToken == ZRX_TOKEN_CONTRACT; + uint paidMakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.makerFee); + uint paidTakerFee = getPartialAmount(fillTakerTokenAmount, order.takerTokenAmount, order.takerFee); + uint requiredMakerZRX = isMakerTokenZRX ? safeAdd(fillMakerTokenAmount, paidMakerFee) : paidMakerFee; + uint requiredTakerZRX = isTakerTokenZRX ? safeAdd(fillTakerTokenAmount, paidTakerFee) : paidTakerFee; + + if ( getBalance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX + || getAllowance(ZRX_TOKEN_CONTRACT, order.maker) < requiredMakerZRX + || getBalance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX + || getAllowance(ZRX_TOKEN_CONTRACT, taker) < requiredTakerZRX + ) return false; + + if (!isMakerTokenZRX && ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount // Don't double check makerToken if ZRX + || getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount) + ) return false; + if (!isTakerTokenZRX && ( getBalance(order.takerToken, taker) < fillTakerTokenAmount // Don't double check takerToken if ZRX + || getAllowance(order.takerToken, taker) < fillTakerTokenAmount) + ) return false; + } else if ( getBalance(order.makerToken, order.maker) < fillMakerTokenAmount + || getAllowance(order.makerToken, order.maker) < fillMakerTokenAmount + || getBalance(order.takerToken, taker) < fillTakerTokenAmount + || getAllowance(order.takerToken, taker) < fillTakerTokenAmount + ) return false; + + return true; + } + + /// @dev Get token balance of an address. + /// @param token Address of token. + /// @param owner Address of owner. + /// @return Token balance of owner. + function getBalance(address token, address owner) + internal + constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit. + returns (uint) + { + return Token(token).balanceOf.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner); // Limit gas to prevent reentrancy + } + + /// @dev Get allowance of token given to TokenTransferProxy by an address. + /// @param token Address of token. + /// @param owner Address of owner. + /// @return Allowance of token given to TokenTransferProxy by owner. + function getAllowance(address token, address owner) + internal + constant // The called token contract may attempt to change state, but will not be able to due to an added gas limit. + returns (uint) + { + return Token(token).allowance.gas(EXTERNAL_QUERY_GAS_LIMIT)(owner, TOKEN_TRANSFER_PROXY_CONTRACT); // Limit gas to prevent reentrancy + } +} diff --git a/packages/sol-compiler/test/fixtures/contracts/TokenTransferProxy.sol b/packages/sol-compiler/test/fixtures/contracts/TokenTransferProxy.sol new file mode 100644 index 000000000..44570d459 --- /dev/null +++ b/packages/sol-compiler/test/fixtures/contracts/TokenTransferProxy.sol @@ -0,0 +1,115 @@ +/* + + Copyright 2018 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity ^0.4.14; + +import { Ownable } from "zeppelin-solidity/contracts/ownership/Ownable.sol"; +import { ERC20 as Token } from "zeppelin-solidity/contracts/token/ERC20/ERC20.sol"; + +/// @title TokenTransferProxy - Transfers tokens on behalf of contracts that have been approved via decentralized governance. +/// @author Amir Bandeali - , Will Warren - +contract TokenTransferProxy is Ownable { + + /// @dev Only authorized addresses can invoke functions with this modifier. + modifier onlyAuthorized { + require(authorized[msg.sender]); + _; + } + + modifier targetAuthorized(address target) { + require(authorized[target]); + _; + } + + modifier targetNotAuthorized(address target) { + require(!authorized[target]); + _; + } + + mapping (address => bool) public authorized; + address[] public authorities; + + event LogAuthorizedAddressAdded(address indexed target, address indexed caller); + event LogAuthorizedAddressRemoved(address indexed target, address indexed caller); + + /* + * Public functions + */ + + /// @dev Authorizes an address. + /// @param target Address to authorize. + function addAuthorizedAddress(address target) + public + onlyOwner + targetNotAuthorized(target) + { + authorized[target] = true; + authorities.push(target); + LogAuthorizedAddressAdded(target, msg.sender); + } + + /// @dev Removes authorizion of an address. + /// @param target Address to remove authorization from. + function removeAuthorizedAddress(address target) + public + onlyOwner + targetAuthorized(target) + { + delete authorized[target]; + for (uint i = 0; i < authorities.length; i++) { + if (authorities[i] == target) { + authorities[i] = authorities[authorities.length - 1]; + authorities.length -= 1; + break; + } + } + LogAuthorizedAddressRemoved(target, msg.sender); + } + + /// @dev Calls into ERC20 Token contract, invoking transferFrom. + /// @param token Address of token to transfer. + /// @param from Address to transfer token from. + /// @param to Address to transfer token to. + /// @param value Amount of token to transfer. + /// @return Success of transfer. + function transferFrom( + address token, + address from, + address to, + uint value) + public + onlyAuthorized + returns (bool) + { + return Token(token).transferFrom(from, to, value); + } + + /* + * Public constant functions + */ + + /// @dev Gets all authorized addresses. + /// @return Array of authorized addresses. + function getAuthorizedAddresses() + public + constant + returns (address[]) + { + return authorities; + } +} diff --git a/packages/sol-compiler/test/fixtures/contracts/base/SafeMath.sol b/packages/sol-compiler/test/fixtures/contracts/base/SafeMath.sol new file mode 100644 index 000000000..92ce11cde --- /dev/null +++ b/packages/sol-compiler/test/fixtures/contracts/base/SafeMath.sol @@ -0,0 +1,41 @@ +pragma solidity ^0.4.14; + +contract SafeMath { + function safeMul(uint a, uint b) internal constant returns (uint256) { + uint c = a * b; + assert(a == 0 || c / a == b); + return c; + } + + function safeDiv(uint a, uint b) internal constant returns (uint256) { + uint c = a / b; + return c; + } + + function safeSub(uint a, uint b) internal constant returns (uint256) { + assert(b <= a); + return a - b; + } + + function safeAdd(uint a, uint b) internal constant returns (uint256) { + uint c = a + b; + assert(c >= a); + return c; + } + + function max64(uint64 a, uint64 b) internal constant returns (uint64) { + return a >= b ? a : b; + } + + function min64(uint64 a, uint64 b) internal constant returns (uint64) { + return a < b ? a : b; + } + + function max256(uint256 a, uint256 b) internal constant returns (uint256) { + return a >= b ? a : b; + } + + function min256(uint256 a, uint256 b) internal constant returns (uint256) { + return a < b ? a : b; + } +} diff --git a/packages/sol-compiler/test/fixtures/contracts/base/Token.sol b/packages/sol-compiler/test/fixtures/contracts/base/Token.sol new file mode 100644 index 000000000..483010d7d --- /dev/null +++ b/packages/sol-compiler/test/fixtures/contracts/base/Token.sol @@ -0,0 +1,38 @@ +pragma solidity ^0.4.14; + +contract Token { + + /// @return total amount of tokens + function totalSupply() constant returns (uint supply) {} + + /// @param _owner The address from which the balance will be retrieved + /// @return The balance + function balanceOf(address _owner) constant returns (uint balance) {} + + /// @notice send `_value` token to `_to` from `msg.sender` + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transfer(address _to, uint _value) returns (bool success) {} + + /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` + /// @param _from The address of the sender + /// @param _to The address of the recipient + /// @param _value The amount of token to be transferred + /// @return Whether the transfer was successful or not + function transferFrom(address _from, address _to, uint _value) returns (bool success) {} + + /// @notice `msg.sender` approves `_addr` to spend `_value` tokens + /// @param _spender The address of the account able to transfer the tokens + /// @param _value The amount of wei to be approved for transfer + /// @return Whether the approval was successful or not + function approve(address _spender, uint _value) returns (bool success) {} + + /// @param _owner The address of the account owning tokens + /// @param _spender The address of the account able to transfer the tokens + /// @return Amount of remaining tokens allowed to spent + function allowance(address _owner, address _spender) constant returns (uint remaining) {} + + event Transfer(address indexed _from, address indexed _to, uint _value); + event Approval(address indexed _owner, address indexed _spender, uint _value); +} diff --git a/packages/sol-compiler/test/fixtures/exchange_bin.ts b/packages/sol-compiler/test/fixtures/exchange_bin.ts new file mode 100644 index 000000000..914e76bf5 --- /dev/null +++ b/packages/sol-compiler/test/fixtures/exchange_bin.ts @@ -0,0 +1,4 @@ +export const constructor_args = + '0x000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f4980000000000000000000000008da0d80f5007ef1e431dd2127178d224e32c2ef4'; +export const exchange_binary = + '608060405234801561001057600080fd5b50604051604080612d998339810180604052810190808051906020019092919080519060200190929190505050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050612cca806100cf6000396000f3006080604052600436106100fc576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806314df96ee14610101578063288cdc911461015a5780632ac126221461019f578063363349be146101e4578063394c21e7146103f85780633b30ba59146104975780634f150787146104ee578063741bcc931461071b5780637e9abb50146107cf5780638163681e1461081457806398024a8b146108a6578063add1cbc5146108fb578063b7b2c7d614610952578063baa0181d14610b8b578063bc61394a14610cef578063cfc4d0ec14610dc3578063f06bbf7514610e60578063ffa1ad7414610e93575b600080fd5b34801561010d57600080fd5b50610140600480360381019080803590602001909291908035906020019092919080359060200190929190505050610f23565b604051808215151515815260200191505060405180910390f35b34801561016657600080fd5b506101896004803603810190808035600019169060200190929190505050610f7b565b6040518082815260200191505060405180910390f35b3480156101ab57600080fd5b506101ce6004803603810190808035600019169060200190929190505050610f93565b6040518082815260200191505060405180910390f35b3480156101f057600080fd5b506103e260048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b8282101561027257848483905060a00201600580602002604051908101604052809291908260056020028082843782019150505050508152602001906001019061022d565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156102f157848483905060c0020160068060200260405190810160405280929190826006602002808284378201915050505050815260200190600101906102ac565b5050505050919291929080359060200190929190803515159060200190929190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290505050610fab565b6040518082815260200191505060405180910390f35b34801561040457600080fd5b506104816004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190505050611110565b6040518082815260200191505060405180910390f35b3480156104a357600080fd5b506104ac6115f8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156104fa57600080fd5b5061071960048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b8282101561057c57848483905060a002016005806020026040519081016040528092919082600560200280828437820191505050505081526020019060010190610537565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156105fb57848483905060c0020160068060200260405190810160405280929190826006602002808284378201915050505050815260200190600101906105b6565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061161d565b005b34801561072757600080fd5b506107cd6004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190803560ff169060200190929190803560001916906020019092919080356000191690602001909291905050506116da565b005b3480156107db57600080fd5b506107fe60048036038101908080356000191690602001909291905050506116ff565b6040518082815260200191505060405180910390f35b34801561082057600080fd5b5061088c600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035600019169060200190929190803560ff16906020019092919080356000191690602001909291908035600019169060200190929190505050611748565b604051808215151515815260200191505060405180910390f35b3480156108b257600080fd5b506108e5600480360381019080803590602001909291908035906020019092919080359060200190929190505050611849565b6040518082815260200191505060405180910390f35b34801561090757600080fd5b50610910611867565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561095e57600080fd5b50610b8960048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b828210156109e057848483905060a00201600580602002604051908101604052809291908260056020028082843782019150505050508152602001906001019061099b565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610a5f57848483905060c002016006806020026040519081016040528092919082600660200280828437820191505050505081526020019060010190610a1a565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929080351515906020019092919080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509192919290803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061188d565b005b348015610b9757600080fd5b50610ced60048036038101908080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610c1957848483905060a002016005806020026040519081016040528092919082600560200280828437820191505050505081526020019060010190610bd4565b5050505050919291929080359060200190820180359060200190808060200260200160405190810160405280939291908181526020016000905b82821015610c9857848483905060c002016006806020026040519081016040528092919082600660200280828437820191505050505081526020019060010190610c53565b505050505091929192908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919291929050505061194d565b005b348015610cfb57600080fd5b50610dad6004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c0019060068060200260405190810160405280929190826006602002808284378201915050505050919291929080359060200190929190803515159060200190929190803560ff169060200190929190803560001916906020019092919080356000191690602001909291905050506119c0565b6040518082815260200191505060405180910390f35b348015610dcf57600080fd5b50610e426004803603810190808060a001906005806020026040519081016040528092919082600560200280828437820191505050505091929192908060c00190600680602002604051908101604052809291908260066020028082843782019150505050509192919290505050612160565b60405180826000191660001916815260200191505060405180910390f35b348015610e6c57600080fd5b50610e7561240b565b604051808261ffff1661ffff16815260200191505060405180910390f35b348015610e9f57600080fd5b50610ea8612411565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610ee8578082015181840152602081019050610ecd565b50505050905090810190601f168015610f155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b600080600084801515610f3257fe5b86850991506000821415610f495760009250610f72565b610f68610f5983620f424061244a565b610f63888761244a565b61247d565b90506103e8811192505b50509392505050565b60026020528060005260406000206000915090505481565b60036020528060005260406000206000915090505481565b6000806000809150600090505b895181101561110057896000815181101515610fd057fe5b906020019060200201516003600581101515610fe857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff168a8281518110151561101157fe5b90602001906020020151600360058110151561102957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1614151561105057600080fd5b6110e4826110df8c8481518110151561106557fe5b906020019060200201518c8581518110151561107d57fe5b906020019060200201516110918d88612498565b8c8c888151811015156110a057fe5b906020019060200201518c898151811015156110b857fe5b906020019060200201518c8a8151811015156110d057fe5b906020019060200201516119c0565b6124b1565b9150878214156110f357611100565b8080600101915050610fb8565b8192505050979650505050505050565b600061111a612bd2565b6000806101606040519081016040528088600060058110151561113957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200188600160058110151561116857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200188600260058110151561119757fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018860036005811015156111c657fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018860046005811015156111f557fe5b602002015173ffffffffffffffffffffffffffffffffffffffff16815260200187600060068110151561122457fe5b6020020151815260200187600160068110151561123d57fe5b6020020151815260200187600260068110151561125657fe5b6020020151815260200187600360068110151561126f57fe5b6020020151815260200187600460068110151561128857fe5b6020020151815260200161129c8989612160565b6000191681525092503373ffffffffffffffffffffffffffffffffffffffff16836000015173ffffffffffffffffffffffffffffffffffffffff161415156112e357600080fd5b60008360a001511180156112fb575060008360c00151115b80156113075750600085115b151561131257600080fd5b8261012001514210151561136f57826101400151600019166000600381111561133757fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a3600093506115ee565b61138a8360c001516113858561014001516116ff565b612498565b915061139685836124cf565b905060008114156113f05782610140015160001916600160038111156113b857fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a3600093506115ee565b61141a600360008561014001516000191660001916815260200190815260200160002054826124b1565b60036000856101400151600019166000191681526020019081526020016000208190555082604001518360600151604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140192505050604051809103902060001916836080015173ffffffffffffffffffffffffffffffffffffffff16846000015173ffffffffffffffffffffffffffffffffffffffff167f67d66f160bc93d925d05dae1794c90d2d6d6688b29b84ff069398a9b0458713186604001518760600151611552878a60c001518b60a00151611849565b878a6101400151604051808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200184815260200183815260200182600019166000191681526020019550505050505060405180910390a48093505b5050509392505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008090505b86518110156116d1576116c4878281518110151561163d57fe5b90602001906020020151878381518110151561165557fe5b90602001906020020151878481518110151561166d57fe5b90602001906020020151878581518110151561168557fe5b90602001906020020151878681518110151561169d57fe5b9060200190602002015187878151811015156116b557fe5b906020019060200201516116da565b8080600101915050611623565b50505050505050565b836116eb87878760008888886119c0565b1415156116f757600080fd5b505050505050565b600061174160026000846000191660001916815260200190815260200160002054600360008560001916600019168152602001908152602001600020546124b1565b9050919050565b600060018560405180807f19457468657265756d205369676e6564204d6573736167653a0a333200000000815250601c0182600019166000191681526020019150506040518091039020858585604051600081526020016040526040518085600019166000191681526020018460ff1660ff1681526020018360001916600019168152602001826000191660001916815260200194505050505060206040516020810390808403906000865af1158015611806573d6000803e3d6000fd5b5050506020604051035173ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614905095945050505050565b600061185e611858858461244a565b8461247d565b90509392505050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008090505b87518110156119435761193588828151811015156118ad57fe5b9060200190602002015188838151811015156118c557fe5b9060200190602002015188848151811015156118dd57fe5b906020019060200201518888868151811015156118f657fe5b90602001906020020151888781518110151561190e57fe5b90602001906020020151888881518110151561192657fe5b906020019060200201516119c0565b508080600101915050611893565b5050505050505050565b60008090505b83518110156119ba576119ac848281518110151561196d57fe5b90602001906020020151848381518110151561198557fe5b90602001906020020151848481518110151561199d57fe5b90602001906020020151611110565b508080600101915050611953565b50505050565b60006119ca612bd2565b600080600080610160604051908101604052808e60006005811015156119ec57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6001600581101515611a1b57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6002600581101515611a4a57fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6003600581101515611a7957fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018e6004600581101515611aa857fe5b602002015173ffffffffffffffffffffffffffffffffffffffff1681526020018d6000600681101515611ad757fe5b602002015181526020018d6001600681101515611af057fe5b602002015181526020018d6002600681101515611b0957fe5b602002015181526020018d6003600681101515611b2257fe5b602002015181526020018d6004600681101515611b3b57fe5b60200201518152602001611b4f8f8f612160565b600019168152509450600073ffffffffffffffffffffffffffffffffffffffff16856020015173ffffffffffffffffffffffffffffffffffffffff161480611bc657503373ffffffffffffffffffffffffffffffffffffffff16856020015173ffffffffffffffffffffffffffffffffffffffff16145b1515611bd157600080fd5b60008560a00151118015611be9575060008560c00151115b8015611bf5575060008b115b1515611c0057600080fd5b611c1685600001518661014001518b8b8b611748565b1515611c2157600080fd5b84610120015142101515611c7e578461014001516000191660006003811115611c4657fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611c998560c00151611c948761014001516116ff565b612498565b9350611ca58b856124cf565b95506000861415611cff578461014001516000191660016003811115611cc757fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611d12868660c001518760a00151610f23565b15611d66578461014001516000191660026003811115611d2e57fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b89158015611d7b5750611d7985876124e8565b155b15611dce5784610140015160001916600380811115611d9657fe5b60ff167f36d86c59e00bd73dc19ba3adfe068e4b64ac7e92be35546adeddf1b956a87e9060405160405180910390a360009550612150565b611de1868660c001518760a00151611849565b9250611e0d600260008761014001516000191660001916815260200190815260200160002054876124b1565b600260008761014001516000191660001916815260200190815260200160002081905550611e45856040015186600001513386612838565b1515611e5057600080fd5b611e64856060015133876000015189612838565b1515611e6f57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff16856080015173ffffffffffffffffffffffffffffffffffffffff16141515611f6e5760008560e001511115611f0c57611ec9868660c001518760e00151611849565b9150611f006000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168660000151876080015185612838565b1515611f0b57600080fd5b5b60008561010001511115611f6d57611f2e868660c00151876101000151611849565b9050611f616000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1633876080015184612838565b1515611f6c57600080fd5b5b5b84604001518560600151604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c0100000000000000000000000002815260140192505050604051809103902060001916856080015173ffffffffffffffffffffffffffffffffffffffff16866000015173ffffffffffffffffffffffffffffffffffffffff167f0d0b9391970d9a25552f37d436d2aae2925e2bfe1b2a923754bada030c498cb33389604001518a60600151898d8a8a8f6101400151604051808973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200186815260200185815260200184815260200183815260200182600019166000191681526020019850505050505050505060405180910390a48595505b5050505050979650505050505050565b60003083600060058110151561217257fe5b602002015184600160058110151561218657fe5b602002015185600260058110151561219a57fe5b60200201518660036005811015156121ae57fe5b60200201518760046005811015156121c257fe5b60200201518760006006811015156121d657fe5b60200201518860016006811015156121ea57fe5b60200201518960026006811015156121fe57fe5b60200201518a600360068110151561221257fe5b60200201518b600460068110151561222657fe5b60200201518c600560068110151561223a57fe5b6020020151604051808d73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018c73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018a73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018973ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c010000000000000000000000000281526014018781526020018681526020018581526020018481526020018381526020018281526020019c505050505050505050505050506040518091039020905092915050565b61138781565b6040805190810160405280600581526020017f312e302e3000000000000000000000000000000000000000000000000000000081525081565b6000808284029050600084148061246b575082848281151561246857fe5b04145b151561247357fe5b8091505092915050565b600080828481151561248b57fe5b0490508091505092915050565b60008282111515156124a657fe5b818303905092915050565b60008082840190508381101515156124c557fe5b8091505092915050565b60008183106124de57816124e0565b825b905092915050565b600080600080600080600080600033975061250c8a8c60c001518d60a00151611849565b9650600073ffffffffffffffffffffffffffffffffffffffff168b6080015173ffffffffffffffffffffffffffffffffffffffff161415156127b9576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168b6040015173ffffffffffffffffffffffffffffffffffffffff161495506000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168b6060015173ffffffffffffffffffffffffffffffffffffffff161494506126078a8c60c001518d60e00151611849565b935061261d8a8c60c001518d6101000151611849565b92508561262a5783612635565b61263487856124b1565b5b915084612642578261264d565b61264c8a846124b1565b5b90508161267f6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168d600001516129ac565b10806126b85750816126b66000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168d60000151612a94565b105b806126ec5750806126ea6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168a6129ac565b105b8061272057508061271e6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168a612a94565b105b1561272e576000985061282a565b8515801561276757508661274a8c604001518d600001516129ac565b10806127665750866127648c604001518d60000151612a94565b105b5b15612775576000985061282a565b841580156127a657508961278d8c606001518a6129ac565b10806127a55750896127a38c606001518a612a94565b105b5b156127b4576000985061282a565b612825565b866127cc8c604001518d600001516129ac565b10806127e85750866127e68c604001518d60000151612a94565b105b806127ff5750896127fd8c606001518a6129ac565b105b806128165750896128148c606001518a612a94565b105b15612824576000985061282a565b5b600198505b505050505050505092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166315dacbea868686866040518563ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001828152602001945050505050602060405180830381600087803b15801561296757600080fd5b505af115801561297b573d6000803e3d6000fd5b505050506040513d602081101561299157600080fd5b81019080805190602001909291905050509050949350505050565b60008273ffffffffffffffffffffffffffffffffffffffff166370a0823161138761ffff16846040518363ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001915050602060405180830381600088803b158015612a5057600080fd5b5087f1158015612a64573d6000803e3d6000fd5b50505050506040513d6020811015612a7b57600080fd5b8101908080519060200190929190505050905092915050565b60008273ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e61138761ffff1684600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050602060405180830381600088803b158015612b8e57600080fd5b5087f1158015612ba2573d6000803e3d6000fd5b50505050506040513d6020811015612bb957600080fd5b8101908080519060200190929190505050905092915050565b61016060405190810160405280600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081526020016000815260200160008152602001600081526020016000801916815250905600a165627a7a72305820f91599ebd80f85632ef190bb5e1a738e7288d68a2cf9dcc6b579d76b892dcf6f0029'; diff --git a/packages/sol-compiler/test/util/constants.ts b/packages/sol-compiler/test/util/constants.ts new file mode 100644 index 000000000..88d6db550 --- /dev/null +++ b/packages/sol-compiler/test/util/constants.ts @@ -0,0 +1,11 @@ +import { BigNumber } from '@0xproject/utils'; + +export const constants = { + networkId: 0, + optimizerEnabled: false, + gasPrice: new BigNumber(20000000000), + timeoutMs: 30000, + zrxTokenAddress: '0xe41d2489571d322189246dafa5ebde1f4699f498', + tokenTransferProxyAddress: '0x8da0d80f5007ef1e431dd2127178d224e32c2ef4', + contracts: '*' as '*', +}; diff --git a/packages/sol-compiler/test/util/provider.ts b/packages/sol-compiler/test/util/provider.ts new file mode 100644 index 000000000..e0fcb362a --- /dev/null +++ b/packages/sol-compiler/test/util/provider.ts @@ -0,0 +1,9 @@ +import { web3Factory } from '@0xproject/dev-utils'; +import { Provider } from '@0xproject/types'; +import * as Web3 from 'web3'; + +const providerConfigs = { shouldUseInProcessGanache: true }; +const web3Instance = web3Factory.create(providerConfigs); +const provider: Provider = web3Instance.currentProvider; + +export { provider }; diff --git a/packages/sol-compiler/tsconfig.json b/packages/sol-compiler/tsconfig.json new file mode 100644 index 000000000..63cbc75c3 --- /dev/null +++ b/packages/sol-compiler/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { + "outDir": "lib", + "strictFunctionTypes": false + }, + "include": ["./src/**/*", "./test/**/*"] +} diff --git a/packages/sol-compiler/tslint.json b/packages/sol-compiler/tslint.json new file mode 100644 index 000000000..ffaefe83a --- /dev/null +++ b/packages/sol-compiler/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": ["@0xproject/tslint-config"] +} diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index 425b561a6..68937f507 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -14,7 +14,7 @@ "run_mocha": "mocha lib/test/**/*_test.js --exit", "clean": "shx rm -rf lib scripts", "build": "copyfiles 'test/fixtures/**/*' ./lib && tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", - "compile_test": "node ../deployer/lib/src/cli.js compile", + "compile_test": "node ../sol-compiler/lib/src/cli.js compile", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", "docs:stage": "yarn build && node ./scripts/stage_docs.js", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", @@ -54,7 +54,7 @@ "solidity-parser-antlr": "^0.2.8" }, "devDependencies": { - "@0xproject/deployer": "^0.3.5", + "@0xproject/sol-compiler": "^0.3.5", "@0xproject/monorepo-scripts": "^0.1.19", "@0xproject/tslint-config": "^0.4.17", "@types/istanbul": "^0.4.29", diff --git a/packages/website/md/docs/deployer/installation.md b/packages/website/md/docs/deployer/installation.md deleted file mode 100644 index 5a9cc0cd0..000000000 --- a/packages/website/md/docs/deployer/installation.md +++ /dev/null @@ -1,23 +0,0 @@ -#### CLI Installation - -```bash -yarn global add @0xproject/deployer -``` - -#### API Installation - -```bash -yarn add @0xproject/deployer -``` - -**Import** - -```typescript -import { Compiler } from '@0xproject/deployer'; -``` - -or - -```javascript -var Compiler = require('@0xproject/deployer').Compiler; -``` diff --git a/packages/website/md/docs/deployer/introduction.md b/packages/website/md/docs/deployer/introduction.md deleted file mode 100644 index 7ebd26a3c..000000000 --- a/packages/website/md/docs/deployer/introduction.md +++ /dev/null @@ -1,18 +0,0 @@ -Welcome to the [Deployer](https://github.com/0xProject/0x-monorepo/tree/development/packages/deployer) documentation! Deployer is a tool for compiling and deploying Solidity smart contracts with ease. - -It serves a similar purpose as parts of the [Truffle framework](http://truffleframework.com/), but with the UNIX philosophy in mind: Make each program do one thing well. This tool is for intermediate to advanced Solidity developers that require greater configurability and reliability. - -Deployer has the following advantages over Truffle: - -* Deploy each smart contract with a specific version of Solidity. -* Improved artifact files: - * Properly segregated artifacts to support storing different versions of smart contract deployed on different networks. - * Storage of constructor args, source maps and paths to all requisite source files. - * An easy to maintain codebase: TypeScript + Single repo. - * Allows you to specify the deployer RPC address. - * Supports Solidity version ranges - contract compiled with latest Solidity version that satisfies the range. - * Migrations that work with `async/await`. - * Migrations that can be written synchronously in order to guarentee deterministic contract addresses. - * No race conditions when running migrations. - -Deployer can be used as a command-line tool or as an imported module. diff --git a/packages/website/md/docs/deployer/usage.md b/packages/website/md/docs/deployer/usage.md deleted file mode 100644 index 295af55e1..000000000 --- a/packages/website/md/docs/deployer/usage.md +++ /dev/null @@ -1,56 +0,0 @@ -#### CLI Usage - -```bash -$ 0x-deployer --help -0x-deployer [command] - -Commands: - 0x-deployer compile compile contracts - 0x-deployer deploy deploy a single contract with provided arguments - -Options: - --version Show version number [boolean] - --contracts-dir path of contracts directory to compile [string] [default: - "/path/to/contracts"] - --network-id mainnet=1, kovan=42, testrpc=50 [number] [default: 50] - --should-optimize enable optimizer [boolean] [default: false] - --artifacts-dir path to write contracts artifacts to [string] [default: - "/path/to/artifacts"] - --jsonrpc-port port connected to JSON RPC [number] [default: 8545] - --gas-price gasPrice to be used for transactions - [string] [default: "2000000000"] - --account account to use for deploying contracts [string] - --contracts comma separated list of contracts to compile - [string] [default: "*"] - --help Show help [boolean] -``` - -#### API Usage - -##### Migrations - -You can write migration scripts (similar to `truffle migrate`), that deploys multiple contracts and configures them. Below you'll find a simple example of such a script to help you get started. - -```typescript -import { Deployer } from '@0xproject/deployer'; -import * as path from 'path'; - -const deployerOpts = { - artifactsDir: path.resolve('src', 'artifacts'), - jsonrpcUrl: 'http://localhost:8545', - networkId: 50, - defaults: { - gas: 1000000, - }, -}; - -const deployer = new Deployer(deployerOpts); - -(async () => { - const etherToken = await deployer.deployAndSaveAsync('WETH9'); -})().catch(console.log); -``` - -**Tip:** Be sure to start an Ethereum node at the supplied `jsonrpcUrl`. We recommend testing with [Ganache-cli](https://github.com/trufflesuite/ganache-cli) - -A more sophisticated example can be found [here](https://github.com/0xProject/0x-monorepo/tree/development/packages/contracts/migrations) diff --git a/packages/website/md/docs/sol-compiler/installation.md b/packages/website/md/docs/sol-compiler/installation.md new file mode 100644 index 000000000..9c8561d9b --- /dev/null +++ b/packages/website/md/docs/sol-compiler/installation.md @@ -0,0 +1,23 @@ +#### CLI Installation + +```bash +yarn global add @0xproject/sol-compiler +``` + +#### API Installation + +```bash +yarn add @0xproject/sol-compiler +``` + +**Import** + +```typescript +import { Compiler } from '@0xproject/sol-compiler'; +``` + +or + +```javascript +var Compiler = require('@0xproject/sol-compiler').Compiler; +``` diff --git a/packages/website/md/docs/sol-compiler/introduction.md b/packages/website/md/docs/sol-compiler/introduction.md new file mode 100644 index 000000000..aa1939006 --- /dev/null +++ b/packages/website/md/docs/sol-compiler/introduction.md @@ -0,0 +1,13 @@ +Welcome to the [sol-compiler](https://github.com/0xProject/0x-monorepo/tree/development/packages/sol-compiler) documentation! Sol-compiler is a tool for compiling Solidity smart contracts and generating artifacts with ease. + +It serves a similar purpose as parts of the [Truffle framework](http://truffleframework.com/), but with the UNIX philosophy in mind: Make each program do one thing well. This tool is for intermediate to advanced Solidity developers that require greater configurability and reliability. + +Sol-compiler has the following advantages over Truffle: + +* Compile each smart contract with a specific version of Solidity. +* Improved artifact files: + * Storage of constructor args, source maps and paths to all requisite source files. + * An easy to maintain codebase: TypeScript + Single repo. + * Supports Solidity version ranges - contract compiled with latest Solidity version that satisfies the range. + +Sol-compiler can be used as a command-line tool or as an imported module. diff --git a/packages/website/md/docs/sol-compiler/usage.md b/packages/website/md/docs/sol-compiler/usage.md new file mode 100644 index 000000000..79c9b32ba --- /dev/null +++ b/packages/website/md/docs/sol-compiler/usage.md @@ -0,0 +1,24 @@ +#### CLI Usage + +```bash +$ sol-compiler +Options: + --version Show version number [boolean] + --contracts-dir path of contracts directory to compile [string] + --artifacts-dir path to write contracts artifacts to [string] + --contracts comma separated list of contracts to compile + [string] [default: "*"] + --help Show help [boolean] +``` + +#### API Usage + +```typescript +import { Compiler } from '@0xproject/sol-compiler'; + +const compiler = new Compiler(); + +(async () => { + await compiler.compileAllAsync(); +})().catch(console.log); +``` diff --git a/packages/website/translations/chinese.json b/packages/website/translations/chinese.json index d37b1abdf..966457a93 100644 --- a/packages/website/translations/chinese.json +++ b/packages/website/translations/chinese.json @@ -56,7 +56,7 @@ "ABOUT": "关于我们", "CAREERS": "人才招聘", "CONTACT": "联系方式", - "DEPLOYER": "Deployer", + "SOL_COMPILER": "Solidity Compiler", "JSON_SCHEMAS": "JSON Schemas", "SOL_COV": "Solidity Coverage", "SUBPROVIDERS": "Subproviders", diff --git a/packages/website/translations/english.json b/packages/website/translations/english.json index 8d7485e9a..f3acea3be 100644 --- a/packages/website/translations/english.json +++ b/packages/website/translations/english.json @@ -57,7 +57,7 @@ "ABOUT": "about", "CAREERS": "careers", "CONTACT": "contact", - "DEPLOYER": "Deployer", + "SOL_COMPILER": "Solidity Compiler", "JSON_SCHEMAS": "JSON Schemas", "SOL_COV": "Solidity Coverage", "SUBPROVIDERS": "Subproviders", diff --git a/packages/website/translations/korean.json b/packages/website/translations/korean.json index 028476d2c..7414207f7 100644 --- a/packages/website/translations/korean.json +++ b/packages/website/translations/korean.json @@ -56,7 +56,7 @@ "ABOUT": "기업 정보", "CAREERS": "채용", "CONTACT": "문의", - "DEPLOYER": "Deployer", + "SOL_COMPILER": "Solidity Compiler", "JSON_SCHEMAS": "JSON Schemas", "SOL_COV": "Solidity Coverage", "SUBPROVIDERS": "Subproviders", diff --git a/packages/website/translations/russian.json b/packages/website/translations/russian.json index 9254ab1c0..75ab02a27 100644 --- a/packages/website/translations/russian.json +++ b/packages/website/translations/russian.json @@ -56,7 +56,7 @@ "ABOUT": "Kоманда", "CAREERS": "Карьера", "CONTACT": "Связаться с нами", - "DEPLOYER": "Deployer", + "SOL_COMPILER": "Solidity Compiler", "JSON_SCHEMAS": "JSON Schemas", "SOL_COV": "Solidity Coverage", "SUBPROVIDERS": "Subproviders", diff --git a/packages/website/translations/spanish.json b/packages/website/translations/spanish.json index eb8f4035c..8f537ea40 100644 --- a/packages/website/translations/spanish.json +++ b/packages/website/translations/spanish.json @@ -57,7 +57,7 @@ "ABOUT": "equipo", "CAREERS": "empleo", "CONTACT": "contacto", - "DEPLOYER": "Deployer", + "SOL_COMPILER": "Solidity Compiler", "JSON_SCHEMAS": "JSON Schemas", "SOL_COV": "Solidity Coverage", "SUBPROVIDERS": "Subproviders", diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index 2502bea6d..23130853c 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -149,10 +149,10 @@ export class TopBar extends React.Component { primaryText={this.props.translate.get(Key.OrderUtils, Deco.CapWords)} /> , - + , @@ -328,10 +328,10 @@ export class TopBar extends React.Component { )} - {!this._isViewingDeployerDocs() && ( - + {!this._isViewingSolCompilerDocs() && ( + - {this.props.translate.get(Key.Deployer, Deco.Cap)}{' '} + {this.props.translate.get(Key.SolCompiler, Deco.Cap)}{' '} {this.props.translate.get(Key.Docs, Deco.Cap)} @@ -476,8 +476,8 @@ export class TopBar extends React.Component { _.includes(this.props.location.pathname, WebsiteLegacyPaths.Web3Wrapper) ); } - private _isViewingDeployerDocs() { - return _.includes(this.props.location.pathname, WebsitePaths.Deployer); + private _isViewingSolCompilerDocs() { + return _.includes(this.props.location.pathname, WebsitePaths.SolCompiler); } private _isViewingJsonSchemasDocs() { return _.includes(this.props.location.pathname, WebsitePaths.JSONSchemas); @@ -498,7 +498,7 @@ export class TopBar extends React.Component { this._isViewingFAQ() || this._isViewingSmartContractsDocs() || this._isViewingWeb3WrapperDocs() || - this._isViewingDeployerDocs() || + this._isViewingSolCompilerDocs() || this._isViewingJsonSchemasDocs() || this._isViewingSolCovDocs() || this._isViewingSubprovidersDocs() || diff --git a/packages/website/ts/containers/deployer_documentation.ts b/packages/website/ts/containers/deployer_documentation.ts deleted file mode 100644 index e20cc195b..000000000 --- a/packages/website/ts/containers/deployer_documentation.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { constants as docConstants, DocsInfo, DocsInfoConfig, SupportedDocJson } from '@0xproject/react-docs'; -import * as _ from 'lodash'; -import * as React from 'react'; -import { connect } from 'react-redux'; -import { Dispatch } from 'redux'; -import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page'; -import { Dispatcher } from 'ts/redux/dispatcher'; -import { State } from 'ts/redux/reducer'; -import { DocPackages, Environments, WebsitePaths } from 'ts/types'; -import { configs } from 'ts/utils/configs'; -import { constants } from 'ts/utils/constants'; -import { Translate } from 'ts/utils/translate'; - -/* tslint:disable:no-var-requires */ -const IntroMarkdown = require('md/docs/deployer/introduction'); -const InstallationMarkdown = require('md/docs/deployer/installation'); -const UsageMarkdown = require('md/docs/deployer/usage'); -/* tslint:enable:no-var-requires */ - -const docSections = { - introduction: 'introduction', - installation: 'installation', - usage: 'usage', - compiler: 'compiler', - deployer: 'deployer', - types: docConstants.TYPES_SECTION_NAME, -}; - -const docsInfoConfig: DocsInfoConfig = { - id: DocPackages.Deployer, - type: SupportedDocJson.TypeDoc, - displayName: 'Deployer', - packageUrl: 'https://github.com/0xProject/0x-monorepo', - menu: { - introduction: [docSections.introduction], - install: [docSections.installation], - usage: [docSections.usage], - compiler: [docSections.compiler], - deployer: [docSections.deployer], - types: [docSections.types], - }, - sectionNameToMarkdown: { - [docSections.introduction]: IntroMarkdown, - [docSections.installation]: InstallationMarkdown, - [docSections.usage]: UsageMarkdown, - }, - sectionNameToModulePath: { - [docSections.compiler]: ['"deployer/src/compiler"'], - [docSections.deployer]: ['"deployer/src/deployer"'], - [docSections.types]: ['"deployer/src/utils/types"', '"types/src/index"'], - }, - menuSubsectionToVersionWhenIntroduced: {}, - sections: docSections, - visibleConstructors: [docSections.compiler, docSections.deployer], - typeConfigs: { - // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is - // currently no way to extract the re-exported types from index.ts via TypeDoc :( - publicTypes: [ - 'CompilerOptions', - 'DeployerOptions', - 'BaseDeployerOptions', - 'UrlDeployerOptions', - 'ProviderDeployerOptions', - 'TxData', - ], - typeNameToExternalLink: { - Web3: constants.URL_WEB3_DOCS, - BigNumber: constants.URL_BIGNUMBERJS_GITHUB, - ContractInstance: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L98', - }, - typeNameToPrefix: { - ContractInstance: 'Web3', - }, - }, -}; -const docsInfo = new DocsInfo(docsInfoConfig); - -interface ConnectedState { - docsVersion: string; - availableDocVersions: string[]; - docsInfo: DocsInfo; - translate: Translate; -} - -interface ConnectedDispatch { - dispatcher: Dispatcher; -} - -const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({ - docsVersion: state.docsVersion, - availableDocVersions: state.availableDocVersions, - translate: state.translate, - docsInfo, -}); - -const mapDispatchToProps = (dispatch: Dispatch): ConnectedDispatch => ({ - dispatcher: new Dispatcher(dispatch), -}); - -export const Documentation: React.ComponentClass = connect(mapStateToProps, mapDispatchToProps)( - DocPageComponent, -); diff --git a/packages/website/ts/containers/sol_compiler_documentation.ts b/packages/website/ts/containers/sol_compiler_documentation.ts new file mode 100644 index 000000000..0cf595645 --- /dev/null +++ b/packages/website/ts/containers/sol_compiler_documentation.ts @@ -0,0 +1,99 @@ +import { constants as docConstants, DocsInfo, DocsInfoConfig, SupportedDocJson } from '@0xproject/react-docs'; +import * as _ from 'lodash'; +import * as React from 'react'; +import { connect } from 'react-redux'; +import { Dispatch } from 'redux'; +import { DocPage as DocPageComponent, DocPageProps } from 'ts/pages/documentation/doc_page'; +import { Dispatcher } from 'ts/redux/dispatcher'; +import { State } from 'ts/redux/reducer'; +import { DocPackages, Environments, WebsitePaths } from 'ts/types'; +import { configs } from 'ts/utils/configs'; +import { constants } from 'ts/utils/constants'; +import { Translate } from 'ts/utils/translate'; + +/* tslint:disable:no-var-requires */ +const IntroMarkdown = require('md/docs/sol-compiler/introduction'); +const InstallationMarkdown = require('md/docs/sol-compiler/installation'); +const UsageMarkdown = require('md/docs/sol-compiler/usage'); +/* tslint:enable:no-var-requires */ + +const docSections = { + introduction: 'introduction', + installation: 'installation', + usage: 'usage', + compiler: 'compiler', + types: docConstants.TYPES_SECTION_NAME, +}; + +const docsInfoConfig: DocsInfoConfig = { + id: DocPackages.SolCompiler, + type: SupportedDocJson.TypeDoc, + displayName: 'Sol Compiler', + packageUrl: 'https://github.com/0xProject/0x-monorepo', + menu: { + introduction: [docSections.introduction], + install: [docSections.installation], + usage: [docSections.usage], + compiler: [docSections.compiler], + types: [docSections.types], + }, + sectionNameToMarkdown: { + [docSections.introduction]: IntroMarkdown, + [docSections.installation]: InstallationMarkdown, + [docSections.usage]: UsageMarkdown, + }, + sectionNameToModulePath: { + [docSections.compiler]: ['"sol-compiler/src/compiler"'], + [docSections.types]: ['"sol-compiler/src/utils/types"', '"types/src/index"'], + }, + menuSubsectionToVersionWhenIntroduced: {}, + sections: docSections, + visibleConstructors: [docSections.compiler], + typeConfigs: { + // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is + // currently no way to extract the re-exported types from index.ts via TypeDoc :( + publicTypes: [ + 'CompilerOptions', + 'DeployerOptions', + 'BaseDeployerOptions', + 'UrlDeployerOptions', + 'ProviderDeployerOptions', + 'TxData', + ], + typeNameToExternalLink: { + Web3: constants.URL_WEB3_DOCS, + BigNumber: constants.URL_BIGNUMBERJS_GITHUB, + ContractInstance: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L98', + }, + typeNameToPrefix: { + ContractInstance: 'Web3', + }, + }, +}; +const docsInfo = new DocsInfo(docsInfoConfig); + +interface ConnectedState { + docsVersion: string; + availableDocVersions: string[]; + docsInfo: DocsInfo; + translate: Translate; +} + +interface ConnectedDispatch { + dispatcher: Dispatcher; +} + +const mapStateToProps = (state: State, ownProps: DocPageProps): ConnectedState => ({ + docsVersion: state.docsVersion, + availableDocVersions: state.availableDocVersions, + translate: state.translate, + docsInfo, +}); + +const mapDispatchToProps = (dispatch: Dispatch): ConnectedDispatch => ({ + dispatcher: new Dispatcher(dispatch), +}); + +export const Documentation: React.ComponentClass = connect(mapStateToProps, mapDispatchToProps)( + DocPageComponent, +); diff --git a/packages/website/ts/containers/subproviders_documentation.ts b/packages/website/ts/containers/subproviders_documentation.ts index a14d06a3f..2178baea8 100644 --- a/packages/website/ts/containers/subproviders_documentation.ts +++ b/packages/website/ts/containers/subproviders_documentation.ts @@ -74,7 +74,7 @@ const docsInfoConfig: DocsInfoConfig = { [docSections.redundantRPCSubprovider]: ['"subproviders/src/subproviders/redundant_rpc"'], [docSections.ganacheSubprovider]: ['"subproviders/src/subproviders/ganache"'], [docSections.nonceTrackerSubprovider]: ['"subproviders/src/subproviders/nonce_tracker"'], - [docSections.types]: ['"deployer/src/utils/types"', '"types/src/index"', '"subproviders/src/types"'], + [docSections.types]: ['"sol-compiler/src/utils/types"', '"types/src/index"', '"subproviders/src/types"'], }, menuSubsectionToVersionWhenIntroduced: {}, sections: docSections, diff --git a/packages/website/ts/index.tsx b/packages/website/ts/index.tsx index 1b1255214..2688d0259 100644 --- a/packages/website/ts/index.tsx +++ b/packages/website/ts/index.tsx @@ -54,8 +54,8 @@ const LazyConnectDocumentation = createLazyComponent('Documentation', async () = const LazyWeb3WrapperDocumentation = createLazyComponent('Documentation', async () => System.import(/* webpackChunkName: "web3WrapperDocs" */ 'ts/containers/web3_wrapper_documentation'), ); -const LazyDeployerDocumentation = createLazyComponent('Documentation', async () => - System.import(/* webpackChunkName: "deployerDocs" */ 'ts/containers/deployer_documentation'), +const LazySolCompilerDocumentation = createLazyComponent('Documentation', async () => + System.import(/* webpackChunkName: "solCompilerDocs" */ 'ts/containers/sol_compiler_documentation'), ); const LazyJSONSchemasDocumentation = createLazyComponent('Documentation', async () => System.import(/* webpackChunkName: "jsonSchemasDocs" */ 'ts/containers/json_schemas_documentation'), @@ -91,7 +91,10 @@ render( - + Date: Tue, 8 May 2018 16:02:04 +0200 Subject: Fix linter issues --- packages/0x.js/package.json | 2 +- packages/abi-gen/package.json | 2 +- packages/assert/package.json | 2 +- packages/base-contract/src/index.ts | 3 +- packages/connect/package.json | 2 +- packages/contract_templates/contract.handlebars | 10 ++-- packages/contracts/package.json | 5 +- packages/contracts/test/ether_token.ts | 2 +- packages/contracts/test/exchange/core.ts | 12 ++-- packages/contracts/test/exchange/helpers.ts | 12 ++-- packages/contracts/test/exchange/wrapper.ts | 16 +++-- .../contracts/test/multi_sig_with_time_lock.ts | 4 +- ...i_sig_with_time_lock_except_remove_auth_addr.ts | 6 +- packages/contracts/test/token_registry.ts | 2 +- .../contracts/test/token_transfer_proxy/auth.ts | 2 +- .../test/token_transfer_proxy/transfer_from.ts | 4 +- packages/contracts/test/tutorials/arbitrage.ts | 38 ++++++------ .../contracts/test/unlimited_allowance_token.ts | 2 +- packages/contracts/test/zrx_token.ts | 2 +- packages/dev-utils/package.json | 2 +- packages/dev-utils/src/coverage.ts | 3 +- packages/json-schemas/package.json | 2 +- packages/metacoin/test/metacoin_test.ts | 4 +- packages/metacoin/test/utils/coverage.ts | 2 +- packages/migrations/package.json | 3 +- packages/migrations/src/artifacts.ts | 1 - packages/migrations/src/migration.ts | 20 +++---- packages/monorepo-scripts/package.json | 2 +- packages/react-docs-example/package.json | 2 +- packages/react-docs/package.json | 2 +- packages/react-shared/package.json | 2 +- packages/sol-compiler/coverage/.gitkeep | 0 packages/sol-compiler/package.json | 2 +- packages/sol-compiler/src/cli.ts | 7 ++- packages/sol-compiler/test/compiler_test.ts | 2 +- packages/sol-cov/package.json | 5 +- packages/sol-cov/src/collect_contract_data.ts | 2 +- packages/sol-cov/src/coverage_manager.ts | 11 ++-- packages/sol-cov/src/coverage_subprovider.ts | 10 +--- .../sol-cov/test/collect_contracts_data_test.ts | 3 +- packages/subproviders/package.json | 2 +- packages/testnet-faucets/package.json | 2 +- packages/tslint-config/package.json | 2 +- packages/types/package.json | 2 +- .../typescript-typings/types/ethers/index.d.ts | 4 +- packages/utils/package.json | 2 +- packages/web3-wrapper/package.json | 2 +- packages/website/md/docs/sol_cov/usage.md | 2 +- yarn.lock | 69 +--------------------- 49 files changed, 119 insertions(+), 183 deletions(-) create mode 100644 packages/sol-compiler/coverage/.gitkeep diff --git a/packages/0x.js/package.json b/packages/0x.js/package.json index 8403d89cb..dafd8af88 100644 --- a/packages/0x.js/package.json +++ b/packages/0x.js/package.json @@ -16,7 +16,7 @@ "prebuild": "run-s clean generate_contract_wrappers", "build": "run-p build:umd:prod build:commonjs; exit 0;", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis 'src/compact_artifacts/@(Exchange|Token|TokenTransferProxy|EtherToken|TokenRegistry|DummyToken).json' --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "test:circleci": "run-s test:coverage", "test": "run-s clean test:commonjs", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json index 0ee7e1979..82184a596 100644 --- a/packages/abi-gen/package.json +++ b/packages/abi-gen/package.json @@ -6,7 +6,7 @@ "types": "lib/index.d.ts", "scripts": { "build:watch": "tsc -w", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "clean": "shx rm -rf lib scripts", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "manual:postpublish": "yarn build; node ./scripts/postpublish.js" diff --git a/packages/assert/package.json b/packages/assert/package.json index e02e018ae..f86bbb33f 100644 --- a/packages/assert/package.json +++ b/packages/assert/package.json @@ -8,7 +8,7 @@ "build:watch": "tsc -w", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib test_temp scripts", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "run_mocha": "mocha lib/test/**/*_test.js --exit", "prepublishOnly": "run-p build", "test": "run-s clean build run_mocha", diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 57d720795..8558bceea 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -48,12 +48,13 @@ export class BaseContract { if (!_.isUndefined(constructorAbiIfExists)) { return constructorAbiIfExists; } else { - return { + const defaultConstructorAbi: ConstructorAbi = { type: AbiType.Constructor, stateMutability: 'nonpayable', payable: false, inputs: [], }; + return defaultConstructorAbi; } } protected static _bnToBigNumber(type: string, value: any): any { diff --git a/packages/connect/package.json b/packages/connect/package.json index efc61178f..2930de98e 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -16,7 +16,7 @@ "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib test_temp scripts", "copy_test_fixtures": "copyfiles -u 2 './test/fixtures/**/*.json' ./lib/test/fixtures", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "run_mocha": "mocha lib/test/**/*_test.js --exit", "test": "run-s clean build copy_test_fixtures run_mocha", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 63dc4780d..af9f15c69 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -5,9 +5,9 @@ // tslint:disable:no-consecutive-blank-lines // tslint:disable-next-line:no-unused-variable import { BaseContract } from '@0xproject/base-contract'; -import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types'; -import { BigNumber, classUtils, promisify } from '@0xproject/utils'; import { ContractArtifact } from '@0xproject/sol-compiler'; +import { BlockParam, BlockParamLiteral, CallData, ContractAbi, DataItem, MethodAbi, Provider, TxData, TxDataPayable } from '@0xproject/types'; +import { BigNumber, classUtils, logUtils, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as ethers from 'ethers'; import * as _ from 'lodash'; @@ -40,7 +40,7 @@ export class {{contractName}}Contract extends BaseContract { {{> tx contractName=../contractName}} {{/this.constant}} {{/each}} - public static async deploy0xArtifactAsync( + public static async deployFrom0xArtifactAsync( artifact: ContractArtifact, provider: Provider, defaults: Partial, @@ -71,9 +71,9 @@ export class {{contractName}}Contract extends BaseContract { web3Wrapper.estimateGasAsync.bind(web3Wrapper), ); const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults); - console.log(`transactionHash: ${txHash}`); + logUtils.log(`transactionHash: ${txHash}`); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash); - console.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`); + logUtils.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`); const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, defaults); contractInstance.constructorArgs = [{{> params inputs=ctor.inputs}}]; return contractInstance; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 7efcd58a0..9e082a6de 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -19,7 +19,7 @@ "compile": "node ../sol-compiler/lib/src/cli.js", "clean": "shx rm -rf ./lib", "generate_contract_wrappers": "node ../abi-gen/lib/index.js --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output src/contract_wrappers/generated --backend ethers && prettier --write 'src/contract_wrappers/generated/**.ts'", - "lint": "tslint --project . 'migrations/**/*.ts' 'test/**/*.ts' 'util/**/*.ts' 'deploy/**/*.ts'", + "lint": "tslint --project .", "coverage:report:text": "istanbul report text", "coverage:report:html": "istanbul report html && open coverage/index.html", "coverage:report:lcov": "istanbul report lcov", @@ -60,6 +60,7 @@ }, "dependencies": { "0x.js": "^0.37.2", + "@0xproject/base-contract": "^0.3.1", "@0xproject/sol-compiler": "^0.4.3", "@0xproject/types": "^0.6.3", "@0xproject/typescript-typings": "^0.3.1", @@ -68,7 +69,7 @@ "bn.js": "^4.11.8", "ethereumjs-abi": "^0.6.4", "ethereumjs-util": "^5.1.1", - "ethers-contracts": "^2.2.1", + "ethers": "^3.0.15", "lodash": "^4.17.4", "web3": "^0.20.0" } diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index a3ede5df0..a25e4ebba 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -26,7 +26,7 @@ describe('EtherToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; - const etherToken = await WETH9Contract.deploy0xArtifactAsync(artifacts.EtherToken, provider, defaults); + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, defaults); etherTokenAddress = etherToken.address; zeroEx = new ZeroEx(provider, { gasPrice, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index a94e6cf51..1a404c410 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -57,7 +57,7 @@ describe('Exchange', () => { maker = accounts[0]; [tokenOwner, taker, feeRecipient] = accounts; [rep, dgd, zrx] = await Promise.all([ - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -66,7 +66,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -75,7 +75,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -85,12 +85,12 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), ]); - tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); - exchange = await ExchangeContract.deploy0xArtifactAsync( + exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, @@ -713,7 +713,7 @@ describe('Exchange', () => { it('should throw if getBalance or getAllowance attempts to change state and \ shouldThrowOnInsufficientBalanceOrAllowance = false', async () => { - const maliciousToken = await MaliciousTokenContract.deploy0xArtifactAsync( + const maliciousToken = await MaliciousTokenContract.deployFrom0xArtifactAsync( artifacts.MaliciousToken, provider, defaults, diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 888d5ab2e..8835412de 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -40,18 +40,18 @@ describe('Exchange', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [maker, feeRecipient] = accounts; - const tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync( + const tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( artifacts.TokenRegistry, provider, defaults, ); - const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); const [rep, dgd, zrx] = await Promise.all([ - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -60,7 +60,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -69,7 +69,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -79,7 +79,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), ]); - const exchange = await ExchangeContract.deploy0xArtifactAsync( + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 6e55edabb..1c80189ab 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -56,7 +56,7 @@ describe('Exchange', () => { tokenOwner = accounts[0]; [maker, taker, feeRecipient] = accounts; [rep, dgd, zrx] = await Promise.all([ - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -65,7 +65,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -74,7 +74,7 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), - DummyTokenContract.deploy0xArtifactAsync( + DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -84,13 +84,17 @@ describe('Exchange', () => { constants.DUMMY_TOKEN_TOTAL_SUPPLY, ), ]); - tokenRegistry = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); - tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( + artifacts.TokenRegistry, + provider, + defaults, + ); + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); - exchange = await ExchangeContract.deploy0xArtifactAsync( + exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index d3d478868..361d87ff7 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -47,7 +47,7 @@ describe('MultiSigWalletWithTimeLock', () => { describe('changeTimeLock', () => { describe('initially non-time-locked', async () => { before('deploy a wallet', async () => { - multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync( + multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, provider, defaults, @@ -142,7 +142,7 @@ describe('MultiSigWalletWithTimeLock', () => { }); describe('initially time-locked', async () => { before('deploy a wallet', async () => { - multiSig = await MultiSigWalletWithTimeLockContract.deploy0xArtifactAsync( + multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, provider, defaults, diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index e8f970d64..ba23889b3 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -46,7 +46,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { owners = [accounts[0], accounts[1]]; [authorizedAddress, unauthorizedAddress] = accounts; const initialOwner = accounts[0]; - tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, @@ -54,7 +54,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, { from: initialOwner, }); - multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deploy0xArtifactAsync( + multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, defaults, @@ -109,7 +109,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { }); it('should throw if tx destination is not the tokenTransferProxy', async () => { - const invalidTokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + const invalidTokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index fbd7f130d..363631385 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -29,7 +29,7 @@ describe('TokenRegistry', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; notOwner = accounts[1]; - tokenReg = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); tokenRegWrapper = new TokenRegWrapper(tokenReg); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 78ef78beb..6baadab61 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -24,7 +24,7 @@ describe('TokenTransferProxy', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = address = accounts[0]; notOwner = accounts[1]; - tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index 79189415f..92573caf7 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -32,12 +32,12 @@ describe('TokenTransferProxy', () => { before(async () => { accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = notAuthorized = accounts[0]; - tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); - rep = await DummyTokenContract.deploy0xArtifactAsync( + rep = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index f28120883..43dbd2989 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -40,8 +40,8 @@ describe('Arbitrage', () => { const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18); - let weth: Web3.ContractInstance; - let zrx: Web3.ContractInstance; + let weth: DummyTokenContract; + let zrx: DummyTokenContract; let arbitrage: ArbitrageContract; let etherDelta: EtherDeltaContract; @@ -58,7 +58,7 @@ describe('Arbitrage', () => { before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); [coinbase, maker, edMaker, edFrontRunner] = accounts; - weth = await DummyTokenContract.deploy0xArtifactAsync( + weth = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -67,7 +67,7 @@ describe('Arbitrage', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - zrx = await DummyTokenContract.deploy0xArtifactAsync( + zrx = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, @@ -76,7 +76,7 @@ describe('Arbitrage', () => { constants.DUMMY_TOKEN_DECIMALS, constants.DUMMY_TOKEN_TOTAL_SUPPLY, ); - const accountLevels = await AccountLevelsContract.deploy0xArtifactAsync( + const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync( artifacts.AccountLevels, provider, defaults, @@ -85,7 +85,7 @@ describe('Arbitrage', () => { const edMakerFee = new BigNumber(0); const edTakerFee = new BigNumber(0); const edFeeRebate = new BigNumber(0); - etherDelta = await EtherDeltaContract.deploy0xArtifactAsync( + etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync( artifacts.EtherDelta, provider, defaults, @@ -96,12 +96,12 @@ describe('Arbitrage', () => { edTakerFee, edFeeRebate, ); - const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); - const exchange = await ExchangeContract.deploy0xArtifactAsync( + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, @@ -129,7 +129,7 @@ describe('Arbitrage', () => { takerFee: new BigNumber(0), }; orderFactory = new OrderFactory(zeroEx, defaultOrderParams); - arbitrage = await ArbitrageContract.deploy0xArtifactAsync( + arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync( artifacts.Arbitrage, provider, defaults, @@ -142,26 +142,26 @@ describe('Arbitrage', () => { await arbitrage.setAllowances.sendTransactionAsync(zrx.address, { from: coinbase }); // Give some tokens to arbitrage contract - await weth.setBalance(arbitrage.address, takerTokenAmount, { from: coinbase }); + await weth.setBalance.sendTransactionAsync(arbitrage.address, takerTokenAmount, { from: coinbase }); // Fund the maker on exchange side - await zrx.setBalance(maker, makerTokenAmount, { from: coinbase }); + await zrx.setBalance.sendTransactionAsync(maker, makerTokenAmount, { from: coinbase }); // Set the allowance for the maker on Exchange side - await zrx.approve(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker }); + await zrx.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: maker }); amountGive = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18); // Fund the maker on EtherDelta side - await weth.setBalance(edMaker, amountGive, { from: coinbase }); + await weth.setBalance.sendTransactionAsync(edMaker, amountGive, { from: coinbase }); // Set the allowance for the maker on EtherDelta side - await weth.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker }); + await weth.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edMaker }); // Deposit maker funds into EtherDelta await etherDelta.depositToken.sendTransactionAsync(weth.address, amountGive, { from: edMaker }); amountGet = makerTokenAmount; // Fund the front runner on EtherDelta side - await zrx.setBalance(edFrontRunner, amountGet, { from: coinbase }); + await zrx.setBalance.sendTransactionAsync(edFrontRunner, amountGet, { from: coinbase }); // Set the allowance for the front-runner on EtherDelta side - await zrx.approve(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner }); + await zrx.approve.sendTransactionAsync(etherDelta.address, INITIAL_ALLOWANCE, { from: edFrontRunner }); // Deposit front runner funds into EtherDelta await etherDelta.depositToken.sendTransactionAsync(zrx.address, amountGet, { from: edFrontRunner }); }); @@ -228,11 +228,11 @@ describe('Arbitrage', () => { from: coinbase, }); const res = await zeroEx.awaitTransactionMinedAsync(txHash); - const postBalance = await weth.balanceOf(arbitrage.address); + const postBalance = await weth.balanceOf.callAsync(arbitrage.address); expect(postBalance).to.be.bignumber.equal(amountGive); }); it('should fail and revert if front-runned', async () => { - const preBalance = await weth.balanceOf(arbitrage.address); + const preBalance = await weth.balanceOf.callAsync(arbitrage.address); // Front-running transaction await etherDelta.trade.sendTransactionAsync( tokenGet, @@ -252,7 +252,7 @@ describe('Arbitrage', () => { await expect( arbitrage.makeAtomicTrade.sendTransactionAsync(addresses, values, v, r, s, { from: coinbase }), ).to.be.rejectedWith(constants.REVERT); - const postBalance = await weth.balanceOf(arbitrage.address); + const postBalance = await weth.balanceOf.callAsync(arbitrage.address); expect(preBalance).to.be.bignumber.equal(postBalance); }); }); diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index a541c495f..546958cfd 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -33,7 +33,7 @@ describe('UnlimitedAllowanceToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; spender = accounts[1]; - token = await DummyTokenContract.deploy0xArtifactAsync( + token = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index 0ad3d86b7..dcba5ab1a 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -34,7 +34,7 @@ describe('ZRXToken', () => { zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); - zrx = await ZRXTokenContract.deploy0xArtifactAsync(artifacts.ZRX, provider, defaults); + zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, defaults); zrxAddress = zrx.address; MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index 0422794ff..67b448024 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -13,7 +13,7 @@ "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "clean": "shx rm -rf lib scripts", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "manual:postpublish": "yarn build; node ./scripts/postpublish.js" }, "license": "Apache-2.0", diff --git a/packages/dev-utils/src/coverage.ts b/packages/dev-utils/src/coverage.ts index 743573874..6f7640835 100644 --- a/packages/dev-utils/src/coverage.ts +++ b/packages/dev-utils/src/coverage.ts @@ -15,8 +15,7 @@ export const coverage = { _getCoverageSubprovider(): CoverageSubprovider { const artifactsPath = '../migrations/artifacts/1.0.0'; const contractsPath = 'src/contracts'; - const networkId = 50; const defaultFromAddress = constants.TESTRPC_FIRST_ADDRESS; - return new CoverageSubprovider(artifactsPath, contractsPath, networkId, defaultFromAddress); + return new CoverageSubprovider(artifactsPath, contractsPath, defaultFromAddress); }, }; diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index f67f653f0..9da9da2b7 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -6,7 +6,7 @@ "types": "lib/src/index.d.ts", "scripts": { "build:watch": "tsc -w", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "test": "run-s clean build run_mocha", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts index 830551968..a31ce1779 100644 --- a/packages/metacoin/test/metacoin_test.ts +++ b/packages/metacoin/test/metacoin_test.ts @@ -1,5 +1,5 @@ -import { ContractArtifact } from '@0xproject/sol-compiler'; import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils'; +import { ContractArtifact } from '@0xproject/sol-compiler'; import { LogWithDecodedArgs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -23,7 +23,7 @@ describe('Metacoin', () => { const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS; const INITIAL_BALANCE = new BigNumber(10000); before(async () => { - metacoin = await MetacoinContract.deploy0xArtifactAsync(artifact, provider, config.defaults); + metacoin = await MetacoinContract.deployFrom0xArtifactAsync(artifact, provider, config.defaults); web3Wrapper.abiDecoder.addABI(metacoin.abi); }); beforeEach(async () => { diff --git a/packages/metacoin/test/utils/coverage.ts b/packages/metacoin/test/utils/coverage.ts index 6b249384f..debd544ed 100644 --- a/packages/metacoin/test/utils/coverage.ts +++ b/packages/metacoin/test/utils/coverage.ts @@ -15,6 +15,6 @@ export const coverage = { }, _getCoverageSubprovider(): CoverageSubprovider { const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - return new CoverageSubprovider(config.artifactsDir, config.contractsDir, config.networkId, defaultFromAddress); + return new CoverageSubprovider(config.artifactsDir, config.contractsDir, defaultFromAddress); }, }; diff --git a/packages/migrations/package.json b/packages/migrations/package.json index a8a30aa47..be17614b4 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -10,7 +10,7 @@ "copy_artifacts": "copyfiles -u 4 'artifacts/1.0.0/**/*' ./lib/src/artifacts", "build": "tsc", "clean": "shx rm -rf lib", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "migrate": "run-s build compile script:migrate", "script:migrate": "node ./lib/migrate.js", "copy_artifacts": "copyfiles 'artifacts/1.0.0/**/*' ./lib", @@ -35,6 +35,7 @@ "@0xproject/base-contract": "^0.3.1", "@0xproject/utils": "^0.6.1", "@0xproject/web3-wrapper": "^0.6.3", + "ethers": "^3.0.15", "lodash": "^4.17.4" }, "publishConfig": { diff --git a/packages/migrations/src/artifacts.ts b/packages/migrations/src/artifacts.ts index 0d3eb68a8..f8913fe52 100644 --- a/packages/migrations/src/artifacts.ts +++ b/packages/migrations/src/artifacts.ts @@ -33,7 +33,6 @@ export const artifacts = { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, }; -const ARTIFACTS_DIR = '../artifacts/1.0.0'; export class ArtifactWriter { private _artifactsDir: string; private _networkId: number; diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 047a875ed..5b49b9282 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -18,33 +18,33 @@ import { tokenInfo } from './utils/token_info'; * Custom migrations should be defined in this function. This will be called with the CLI 'migrate' 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 Provider instance. - * @param artifactsDir The directory with artifact files. - * @param defaults Default transaction values to use. + * @param provider Web3 provider instance. + * @param artifactsDir The directory with compiler artifact files. + * @param defaults Default transaction values to use when deploying contracts. */ export const runMigrationsAsync = async (provider: Provider, artifactsDir: string, defaults: Partial) => { const web3Wrapper = new Web3Wrapper(provider); const networkId = await web3Wrapper.getNetworkIdAsync(); const artifactsWriter = new ArtifactWriter(artifactsDir, networkId); - const tokenTransferProxy = await TokenTransferProxyContract.deploy0xArtifactAsync( + const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, defaults, ); artifactsWriter.saveArtifact(tokenTransferProxy); - const zrxToken = await ZRXTokenContract.deploy0xArtifactAsync(artifacts.ZRX, provider, defaults); + const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, defaults); artifactsWriter.saveArtifact(zrxToken); - const etherToken = await WETH9Contract.deploy0xArtifactAsync(artifacts.EtherToken, provider, defaults); + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, defaults); artifactsWriter.saveArtifact(etherToken); - const tokenReg = await TokenRegistryContract.deploy0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); 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 ExchangeContract.deploy0xArtifactAsync( + const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, defaults, @@ -52,7 +52,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin tokenTransferProxy.address, ); artifactsWriter.saveArtifact(exchange); - const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deploy0xArtifactAsync( + const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, defaults, @@ -101,7 +101,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin ); for (const token of tokenInfo) { const totalSupply = new BigNumber(100000000000000000000); - const dummyToken = await DummyTokenContract.deploy0xArtifactAsync( + const dummyToken = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, defaults, diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index a6b6f2d15..859c23149 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -6,7 +6,7 @@ "types": "lib/index.d.ts", "scripts": { "build:watch": "tsc -w", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "clean": "shx rm -rf lib", "build": "tsc", "test:publish": "run-s build script:publish", diff --git a/packages/react-docs-example/package.json b/packages/react-docs-example/package.json index ec46957d2..b6b6c6c7d 100644 --- a/packages/react-docs-example/package.json +++ b/packages/react-docs-example/package.json @@ -4,7 +4,7 @@ "version": "0.0.11", "description": "An example app using react-docs", "scripts": { - "lint": "tslint --project . 'ts/**/*.ts' 'ts/**/*.tsx'", + "lint": "tslint --project .", "build": "tsc", "build:example": "NODE_ENV=production webpack", "build:watch": "tsc -w", diff --git a/packages/react-docs/package.json b/packages/react-docs/package.json index fd4b7c676..ca9ae610e 100644 --- a/packages/react-docs/package.json +++ b/packages/react-docs/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "lint": "tslint --project . 'src/**/*.ts' 'src/**/*.tsx'", + "lint": "tslint --project .", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "build:watch": "tsc -w", "clean": "shx rm -rf lib scripts", diff --git a/packages/react-shared/package.json b/packages/react-shared/package.json index ce5001985..b9a46376c 100644 --- a/packages/react-shared/package.json +++ b/packages/react-shared/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "lint": "tslint --project . 'src/**/*.ts' 'src/**/*.tsx'", + "lint": "tslint --project .", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "build:watch": "tsc -w", "clean": "shx rm -rf lib scripts", diff --git a/packages/sol-compiler/coverage/.gitkeep b/packages/sol-compiler/coverage/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json index 8c2a10783..745760cd0 100644 --- a/packages/sol-compiler/package.json +++ b/packages/sol-compiler/package.json @@ -14,7 +14,7 @@ "compile": "npm run build; node lib/src/cli.js compile", "clean": "shx rm -rf lib scripts", "migrate": "npm run build; node lib/src/cli.js migrate", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "test:circleci": "yarn test:coverage", "docs:stage": "yarn build && node ./scripts/stage_docs.js", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", diff --git a/packages/sol-compiler/src/cli.ts b/packages/sol-compiler/src/cli.ts index 2412b8d34..90b4949bc 100644 --- a/packages/sol-compiler/src/cli.ts +++ b/packages/sol-compiler/src/cli.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node // We need the above pragma since this script will be run as a command-line tool. -import { BigNumber } from '@0xproject/utils'; +import { BigNumber, logUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; import * as path from 'path'; @@ -38,4 +38,7 @@ const SEPARATOR = ','; }; const compiler = new Compiler(opts); await compiler.compileAsync(); -})(); +})().catch(err => { + logUtils.log(err); + process.exit(1); +}); diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts index 9baf433d4..7ccaeef07 100644 --- a/packages/sol-compiler/test/compiler_test.ts +++ b/packages/sol-compiler/test/compiler_test.ts @@ -37,7 +37,7 @@ describe('#Compiler', function() { const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts); const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); // The last 43 bytes of the binaries are metadata which may not be equivalent - const unlinkedBinaryWithoutMetadata = exchangeArtifact.compilerOutput.evm.bytecode.object.slice(0, -86); + const unlinkedBinaryWithoutMetadata = exchangeArtifact.compilerOutput.evm.bytecode.object.slice(2, -86); const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -86); expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata); }); diff --git a/packages/sol-cov/package.json b/packages/sol-cov/package.json index 68937f507..f57a317de 100644 --- a/packages/sol-cov/package.json +++ b/packages/sol-cov/package.json @@ -6,7 +6,7 @@ "types": "lib/src/index.d.ts", "scripts": { "build:watch": "tsc -w", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "test": "run-s clean build compile_test run_mocha", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", @@ -54,10 +54,9 @@ "solidity-parser-antlr": "^0.2.8" }, "devDependencies": { - "@0xproject/sol-compiler": "^0.3.5", "@0xproject/monorepo-scripts": "^0.1.19", "@0xproject/tslint-config": "^0.4.17", - "@types/istanbul": "^0.4.29", + "@types/istanbul": "^0.4.30", "@types/mocha": "^2.2.42", "@types/node": "^8.0.53", "chai": "^4.0.1", diff --git a/packages/sol-cov/src/collect_contract_data.ts b/packages/sol-cov/src/collect_contract_data.ts index bb20e98be..2c2a12835 100644 --- a/packages/sol-cov/src/collect_contract_data.ts +++ b/packages/sol-cov/src/collect_contract_data.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { ContractData } from './types'; -export const collectContractsData = (artifactsPath: string, sourcesPath: string, networkId: number) => { +export const collectContractsData = (artifactsPath: string, sourcesPath: string) => { const artifactsGlob = `${artifactsPath}/**/*.json`; const artifactFileNames = glob.sync(artifactsGlob, { absolute: true }); const contractsData: ContractData[] = []; diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts index 6a57d07c9..bf580025b 100644 --- a/packages/sol-cov/src/coverage_manager.ts +++ b/packages/sol-cov/src/coverage_manager.ts @@ -1,3 +1,4 @@ +import { addHexPrefix } from 'ethereumjs-util'; import * as fs from 'fs'; import { Collector } from 'istanbul'; import * as _ from 'lodash'; @@ -36,12 +37,11 @@ export class CoverageManager { constructor( artifactsPath: string, sourcesPath: string, - networkId: number, getContractCodeAsync: (address: string) => Promise, ) { this._getContractCodeAsync = getContractCodeAsync; this._sourcesPath = sourcesPath; - this._contractsData = collectContractsData(artifactsPath, this._sourcesPath, networkId); + this._contractsData = collectContractsData(artifactsPath, this._sourcesPath); } public appendTraceInfo(traceInfo: TraceInfo): void { this._traceInfos.push(traceInfo); @@ -134,7 +134,7 @@ export class CoverageManager { if (traceInfo.address !== constants.NEW_CONTRACT) { // Runtime transaction let runtimeBytecode = (traceInfo as TraceInfoExistingContract).runtimeBytecode; - runtimeBytecode = utils.removeHexPrefix(runtimeBytecode); + runtimeBytecode = addHexPrefix(runtimeBytecode); const contractData = _.find(this._contractsData, { runtimeBytecode }) as ContractData; if (_.isUndefined(contractData)) { throw new Error(`Transaction to an unknown address: ${traceInfo.address}`); @@ -159,7 +159,7 @@ export class CoverageManager { } else { // Contract creation transaction let bytecode = (traceInfo as TraceInfoNewContract).bytecode; - bytecode = utils.removeHexPrefix(bytecode); + bytecode = addHexPrefix(bytecode); const contractData = _.find(this._contractsData, contractDataCandidate => bytecode.startsWith(contractDataCandidate.bytecode), ) as ContractData; @@ -185,7 +185,6 @@ export class CoverageManager { } } } - // TODO: Remove any cast as soon as https://github.com/DefinitelyTyped/DefinitelyTyped/pull/24233 gets merged - return (collector as any).getFinalCoverage(); + return collector.getFinalCoverage(); } } diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts index 6504d5a46..b08291afb 100644 --- a/packages/sol-cov/src/coverage_subprovider.ts +++ b/packages/sol-cov/src/coverage_subprovider.ts @@ -28,19 +28,13 @@ export class CoverageSubprovider extends Subprovider { * Instantiates a CoverageSubprovider instance * @param artifactsPath Path to the smart contract artifacts * @param sourcesPath Path to the smart contract source files - * @param networkId network id * @param defaultFromAddress default from address to use when sending transactions */ - constructor(artifactsPath: string, sourcesPath: string, networkId: number, defaultFromAddress: string) { + constructor(artifactsPath: string, sourcesPath: string, defaultFromAddress: string) { super(); this._lock = new Lock(); this._defaultFromAddress = defaultFromAddress; - this._coverageManager = new CoverageManager( - artifactsPath, - sourcesPath, - networkId, - this._getContractCodeAsync.bind(this), - ); + this._coverageManager = new CoverageManager(artifactsPath, sourcesPath, this._getContractCodeAsync.bind(this)); } /** * Write the test coverage results to a file in Istanbul format. diff --git a/packages/sol-cov/test/collect_contracts_data_test.ts b/packages/sol-cov/test/collect_contracts_data_test.ts index 943a4a878..c7c1dfe32 100644 --- a/packages/sol-cov/test/collect_contracts_data_test.ts +++ b/packages/sol-cov/test/collect_contracts_data_test.ts @@ -12,8 +12,7 @@ describe('Collect contracts data', () => { it('correctly collects contracts data', () => { const artifactsPath = path.resolve(__dirname, 'fixtures/artifacts'); const sourcesPath = path.resolve(__dirname, 'fixtures/contracts'); - const networkId = 50; - const contractsData = collectContractsData(artifactsPath, sourcesPath, networkId); + const contractsData = collectContractsData(artifactsPath, sourcesPath); _.forEach(contractsData, contractData => { expect(contractData).to.have.keys([ 'sourceCodes', diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index 238c8417a..92377f118 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -8,7 +8,7 @@ "build:watch": "tsc -w", "clean": "shx rm -rf lib scripts", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", + "lint": "tslint --project .", "run_mocha_unit": "mocha lib/test/unit/**/*_test.js --timeout 10000 --bail --exit", "run_mocha_integration": "mocha lib/test/integration/**/*_test.js --timeout 10000 --bail --exit", "test": "npm run test:unit", diff --git a/packages/testnet-faucets/package.json b/packages/testnet-faucets/package.json index 481770310..198c0b2f7 100644 --- a/packages/testnet-faucets/package.json +++ b/packages/testnet-faucets/package.json @@ -9,7 +9,7 @@ "build": "node ../../node_modules/gulp/bin/gulp.js build", "dev": "node ../../node_modules/gulp/bin/gulp.js run", "start": "node ./bin/server.js", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "clean": "shx rm -rf bin" }, "author": "Fabio Berger", diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index 92235f6a1..a5b34a35e 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -7,7 +7,7 @@ "build:watch": "tsc -w", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib scripts", - "lint": "tslint --project . 'rules/**/*.ts'", + "lint": "tslint --project .", "manual:postpublish": "yarn build; node ./scripts/postpublish.js" }, "repository": { diff --git a/packages/types/package.json b/packages/types/package.json index 0971f424e..973d5b8d0 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -8,7 +8,7 @@ "build:watch": "tsc -w", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib scripts", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "manual:postpublish": "yarn build; node ./scripts/postpublish.js" }, "license": "Apache-2.0", diff --git a/packages/typescript-typings/types/ethers/index.d.ts b/packages/typescript-typings/types/ethers/index.d.ts index 4fec07504..addf85613 100644 --- a/packages/typescript-typings/types/ethers/index.d.ts +++ b/packages/typescript-typings/types/ethers/index.d.ts @@ -1,4 +1,6 @@ declare module 'ethers' { + import { TxData } from '@0xproject/types'; + export interface TransactionDescription { name: string; signature: string; @@ -26,7 +28,7 @@ declare module 'ethers' { constructor(abi: any); } export class Contract { - public static getDeployTransaction(bytecode: string, abi: any, ...args: any[]): any; + public static getDeployTransaction(bytecode: string, abi: any, ...args: any[]): Partial; constructor(address: string, abi: any, provider: any); } } diff --git a/packages/utils/package.json b/packages/utils/package.json index 496ea1fb0..0924aefc3 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -8,7 +8,7 @@ "build:watch": "tsc -w", "build": "tsc && copyfiles -u 2 './lib/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib scripts", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "manual:postpublish": "yarn build; node ./scripts/postpublish.js" }, "license": "Apache-2.0", diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json index 3ee9631cc..bc38df00d 100644 --- a/packages/web3-wrapper/package.json +++ b/packages/web3-wrapper/package.json @@ -8,7 +8,7 @@ "build:watch": "tsc -w", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "clean": "shx rm -rf lib scripts", - "lint": "tslint --project . 'src/**/*.ts'", + "lint": "tslint --project .", "test": "run-s clean build run_mocha", "test:circleci": "yarn test:coverage", "run_mocha": "mocha lib/test/**/*_test.js --bail --exit", diff --git a/packages/website/md/docs/sol_cov/usage.md b/packages/website/md/docs/sol_cov/usage.md index ea1982d97..63a88f595 100644 --- a/packages/website/md/docs/sol_cov/usage.md +++ b/packages/website/md/docs/sol_cov/usage.md @@ -12,7 +12,7 @@ const contractsPath = 'src/contracts'; const networkId = 50; // Some calls might not have `from` address specified. Nevertheless - transactions need to be submitted from an address with at least some funds. defaultFromAddress is the address that will be used to submit those calls as transactions from. const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; -const coverageSubprovider = new CoverageSubprovider(artifactsPath, contractsPath, networkId, defaultFromAddress); +const coverageSubprovider = new CoverageSubprovider(artifactsPath, contractsPath, defaultFromAddress); provider.addProvider(coverageSubprovider); ``` diff --git a/yarn.lock b/yarn.lock index e36eb5c62..c7f096e59 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,25 +6,6 @@ version "0.3.9" resolved "https://registry.yarnpkg.com/8fold-marked/-/8fold-marked-0.3.9.tgz#bb89c645612f8ccfaffac1ca6e3c11f168c9cf59" -"@0xproject/sol-compiler@^0.3.5": - version "0.3.5" - resolved "https://registry.yarnpkg.com/@0xproject/sol-compiler/-/deployer-0.3.5.tgz#3b4144ac62cfbbe4fc7174cbf92f29594f411973" - dependencies: - "@0xproject/json-schemas" "^0.7.19" - "@0xproject/types" "^0.5.0" - "@0xproject/typescript-typings" "^0.0.3" - "@0xproject/utils" "^0.5.0" - "@0xproject/web3-wrapper" "^0.5.0" - ethereumjs-util "^5.1.1" - isomorphic-fetch "^2.2.1" - lodash "^4.17.4" - require-from-string "^2.0.1" - semver "^5.5.0" - solc "^0.4.18" - web3 "^0.20.0" - web3-eth-abi "^1.0.0-beta.24" - yargs "^10.0.3" - "@0xproject/tslint-config@0.4.13": version "0.4.13" resolved "https://registry.yarnpkg.com/@0xproject/tslint-config/-/tslint-config-0.4.13.tgz#98c71c5ae5e80315a23eda0134cc9f6f4438cac2" @@ -47,37 +28,6 @@ "@0xproject/types" "^0.5.0" bignumber.js "~4.1.0" -"@0xproject/typescript-typings@^0.2.0": - version "0.2.0" - resolved "https://registry.yarnpkg.com/@0xproject/typescript-typings/-/typescript-typings-0.2.0.tgz#53590e6866fde0f0bd3584b83e1211dabe9cd530" - dependencies: - "@0xproject/types" "^0.6.1" - bignumber.js "~4.1.0" - -"@0xproject/utils@^0.5.0": - version "0.5.2" - resolved "https://registry.yarnpkg.com/@0xproject/utils/-/utils-0.5.2.tgz#02ce0a920437db0a15d059e8c6c70fa33e9c3860" - dependencies: - "@0xproject/types" "^0.6.1" - "@0xproject/typescript-typings" "^0.2.0" - "@types/node" "^8.0.53" - bignumber.js "~4.1.0" - ethers-contracts "^2.2.1" - js-sha3 "^0.7.0" - lodash "^4.17.4" - web3 "^0.20.0" - -"@0xproject/web3-wrapper@^0.5.0": - version "0.5.0" - resolved "https://registry.yarnpkg.com/@0xproject/web3-wrapper/-/web3-wrapper-0.5.0.tgz#99a1acea60a5c3163ac0be28f4c0577c3d43dec4" - dependencies: - "@0xproject/types" "^0.5.0" - "@0xproject/typescript-typings" "^0.0.3" - "@0xproject/utils" "^0.5.0" - ethers-contracts "^2.2.1" - lodash "^4.17.4" - web3 "^0.20.0" - "@ledgerhq/hw-app-eth@^4.3.0": version "4.7.3" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-eth/-/hw-app-eth-4.7.3.tgz#d352e19658ae296532e522c53c8ec2a1a77b64e5" @@ -204,7 +154,7 @@ version "4.6.2" resolved "https://registry.yarnpkg.com/@types/history/-/history-4.6.2.tgz#12cfaba693ba20f114ed5765467ff25fdf67ddb0" -"@types/istanbul@^0.4.29": +"@types/istanbul@^0.4.30": version "0.4.30" resolved "https://registry.yarnpkg.com/@types/istanbul/-/istanbul-0.4.30.tgz#073159320ab3296b2cfeb481f756a1f8f4c9c8e4" @@ -3787,21 +3737,6 @@ ethereumjs-wallet@~0.6.0: utf8 "^2.1.1" uuid "^2.0.1" -ethers-contracts@^2.2.1: - version "2.2.1" - resolved "https://registry.yarnpkg.com/ethers-contracts/-/ethers-contracts-2.2.1.tgz#e2bf5dd5e157313ba454b50c646c8472fcd0a8b3" - dependencies: - ethers-utils "^2.1.0" - -ethers-utils@^2.1.0: - version "2.1.11" - resolved "https://registry.yarnpkg.com/ethers-utils/-/ethers-utils-2.1.11.tgz#b27535ca3226118be300211c39c896b1e5e21641" - dependencies: - bn.js "^4.4.0" - hash.js "^1.0.0" - js-sha3 "0.5.7" - xmlhttprequest "1.8.0" - ethers@^3.0.15: version "3.0.15" resolved "https://registry.yarnpkg.com/ethers/-/ethers-3.0.15.tgz#7cdea4e23025681f69f575bf481b227315e0e7ab" @@ -9763,7 +9698,7 @@ solc@0.4.18: semver "^5.3.0" yargs "^4.7.1" -solc@^0.4.18, solc@^0.4.2: +solc@^0.4.2: version "0.4.21" resolved "https://registry.yarnpkg.com/solc/-/solc-0.4.21.tgz#6a7ecd505bfa0fc268330d5de6b9ae65c8c68264" dependencies: -- cgit v1.2.3 From ebc296ea3150672c6998fcbdefbbb18433030719 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 14:44:10 +0200 Subject: Add a HACK comment --- packages/0x.js/test/global_hooks.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index 3d2f1c608..9d9d06918 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -6,6 +6,8 @@ import { constants } from './utils/constants'; import { provider } from './utils/web3_wrapper'; before('migrate contracts', async function() { + // HACK: Since the migrations take longer then our global mocha timeout limit + // we manually increase it for this before hook. this.timeout(20000); const defaults = { gas: devConstants.GAS_ESTIMATE, -- cgit v1.2.3 From 7eb9444458f8c86cbc9c7be47879802c52ece57a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:02:32 +0200 Subject: Remove _applyDefaultsToDeployTxDataAsync --- packages/base-contract/src/index.ts | 23 ++++------------------ packages/contract_templates/contract.handlebars | 2 +- .../partials/callAsync.handlebars | 5 +++-- packages/contract_templates/partials/tx.handlebars | 8 +++++--- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 8558bceea..2b39029d5 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -60,37 +60,22 @@ export class BaseContract { protected static _bnToBigNumber(type: string, value: any): any { return _.isObject(value) && value._bn ? new BigNumber(value.toString()) : value; } - protected static async _applyDefaultsToDeployTxDataAsync>( + protected static async _applyDefaultsToTxDataAsync>( txData: T, defaults: Partial, estimateGasAsync?: (txData: T) => Promise, - ): Promise { - const txDataWithDefaults: TxData = { - ...defaults, - ...(txData as any), - }; - if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { - const estimatedGas = await estimateGasAsync(txData); - txDataWithDefaults.gas = estimatedGas; - } - return txDataWithDefaults; - } - protected async _applyDefaultsToTxDataAsync>( - txData: T, - estimateGasAsync?: (txData: T) => Promise, ): Promise { // Gas amount sourced with the following priorities: // 1. Optional param passed in to public method call // 2. Global config passed in at library instantiation // 3. Gas estimate calculation + safety margin const removeUndefinedProperties = _.pickBy; - const txDataWithDefaults = ({ - to: this.address, - ...removeUndefinedProperties(this._web3Wrapper.getContractDefaults()), + const txDataWithDefaults: TxData = { + ...removeUndefinedProperties(defaults), ...removeUndefinedProperties(txData as any), // HACK: TS can't prove that T is spreadable. // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged - } as any) as TxData; + } as any; if (_.isUndefined(txDataWithDefaults.gas) && !_.isUndefined(estimateGasAsync)) { const estimatedGas = await estimateGasAsync(txData); txDataWithDefaults.gas = estimatedGas; diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index af9f15c69..0f6151690 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -65,7 +65,7 @@ export class {{contractName}}Contract extends BaseContract { ); const txData = ethers.Contract.getDeployTransaction(bytecode, abi, {{> params inputs=ctor.inputs}}); const web3Wrapper = new Web3Wrapper(provider); - const txDataWithDefaults = await BaseContract._applyDefaultsToDeployTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( txData, defaults, web3Wrapper.estimateGasAsync.bind(web3Wrapper), diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 58fb2f09c..904936173 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -12,10 +12,11 @@ async callAsync( {{> params inputs=inputs}} ) as ethers.CallDescription; const encodedData = ethersFunction.data; - const callDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { data: encodedData, - } + }, + this._web3Wrapper.getContractDefaults(), ) const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); let resultArray = ethersFunction.parse(rawCallResult); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index feefd3870..f72078a4e 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -14,11 +14,12 @@ public {{this.tsName}} = { const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; - const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { ...txData, data: encodedData, }, + this._web3Wrapper.getContractDefaults(), self.{{this.tsName}}.estimateGasAsync.bind( self, {{> params inputs=inputs}} @@ -37,11 +38,12 @@ public {{this.tsName}} = { const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').functions.{{this.name}}( {{> params inputs=inputs}} ).data; - const txDataWithDefaults = await self._applyDefaultsToTxDataAsync( + const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { ...txData, data: encodedData, - } + }, + this._web3Wrapper.getContractDefaults(), ); const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; -- cgit v1.2.3 From 97831e370255d8631e6f46f79f95fd30ddce36ac Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:03:42 +0200 Subject: Improve a comment --- README.md | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index fcb7e8884..de77e980e 100644 --- a/README.md +++ b/README.md @@ -17,27 +17,27 @@ This repository is a monorepo including the 0x protocol smart contracts and nume ### Published Packages -| Package | Version | Description | -| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | -| [`0x.js`](/packages/0x.js) | [![npm](https://img.shields.io/npm/v/0x.js.svg)](https://www.npmjs.com/package/0x.js) | A Javascript library for interacting with the 0x protocol | -| [`@0xproject/abi-gen`](/packages/abi-gen) | [![npm](https://img.shields.io/npm/v/@0xproject/abi-gen.svg)](https://www.npmjs.com/package/@0xproject/abi-gen) | Tool to generate TS wrappers from smart contract ABIs | -| [`@0xproject/assert`](/packages/assert) | [![npm](https://img.shields.io/npm/v/@0xproject/assert.svg)](https://www.npmjs.com/package/@0xproject/assert) | Type and schema assertions used by our packages | -| [`@0xproject/base-contract`](/packages/base-contract) | [![npm](https://img.shields.io/npm/v/@0xproject/base-contract.svg)](https://www.npmjs.com/package/@0xproject/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts | -| [`@0xproject/connect`](/packages/connect) | [![npm](https://img.shields.io/npm/v/@0xproject/connect.svg)](https://www.npmjs.com/package/@0xproject/connect) | A Javascript library for interacting with the Standard Relayer API | -| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-compiler.svg)](https://www.npmjs.com/package/@0xproject/sol-compiler) | Solidity project compiler framework | -| [`@0xproject/dev-utils`](/packages/dev-utils) | [![npm](https://img.shields.io/npm/v/@0xproject/dev-utils.svg)](https://www.npmjs.com/package/@0xproject/dev-utils) | Dev utils to be shared across 0x projects and packages | -| [`@0xproject/json-schemas`](/packages/json-schemas) | [![npm](https://img.shields.io/npm/v/@0xproject/json-schemas.svg)](https://www.npmjs.com/package/@0xproject/json-schemas) | 0x-related json schemas | -| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts | -| [`@0xproject/react-docs`](/packages/react-docs) | [![npm](https://img.shields.io/npm/v/@0xproject/react-docs.svg)](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON | -| [`@0xproject/react-shared`](/packages/react-shared) | [![npm](https://img.shields.io/npm/v/@0xproject/react-shared.svg)](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components | -| [`@0xproject/sra-report`](/packages/sra-report) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-report.svg)](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance | -| [`@0xproject/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-cov.svg)](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool | -| [`@0xproject/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0xproject/subproviders.svg)](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) | -| [`@0xproject/tslint-config`](/packages/tslint-config) | [![npm](https://img.shields.io/npm/v/@0xproject/tslint-config.svg)](https://www.npmjs.com/package/@0xproject/tslint-config) | Custom 0x development TSLint rules | -| [`@0xproject/types`](/packages/types) | [![npm](https://img.shields.io/npm/v/@0xproject/types.svg)](https://www.npmjs.com/package/@0xproject/types) | Shared type declarations | -| [`@0xproject/typescript-typings`](/packages/typescript-typings) | [![npm](https://img.shields.io/npm/v/@0xproject/typescript-typings.svg)](https://www.npmjs.com/package/@0xproject/typescript-typings) | Repository of types for external packages | -| [`@0xproject/utils`](/packages/utils) | [![npm](https://img.shields.io/npm/v/@0xproject/utils.svg)](https://www.npmjs.com/package/@0xproject/utils) | Shared utilities | -| [`@0xproject/web3-wrapper`](/packages/web3-wrapper) | [![npm](https://img.shields.io/npm/v/@0xproject/web3-wrapper.svg)](https://www.npmjs.com/package/@0xproject/web3-wrapper) | Web3 wrapper | +| Package | Version | Description | +| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | +| [`0x.js`](/packages/0x.js) | [![npm](https://img.shields.io/npm/v/0x.js.svg)](https://www.npmjs.com/package/0x.js) | A Javascript library for interacting with the 0x protocol | +| [`@0xproject/abi-gen`](/packages/abi-gen) | [![npm](https://img.shields.io/npm/v/@0xproject/abi-gen.svg)](https://www.npmjs.com/package/@0xproject/abi-gen) | Tool to generate TS wrappers from smart contract ABIs | +| [`@0xproject/assert`](/packages/assert) | [![npm](https://img.shields.io/npm/v/@0xproject/assert.svg)](https://www.npmjs.com/package/@0xproject/assert) | Type and schema assertions used by our packages | +| [`@0xproject/base-contract`](/packages/base-contract) | [![npm](https://img.shields.io/npm/v/@0xproject/base-contract.svg)](https://www.npmjs.com/package/@0xproject/base-contract) | BaseContract used by auto-generated `abi-gen` wrapper contracts | +| [`@0xproject/connect`](/packages/connect) | [![npm](https://img.shields.io/npm/v/@0xproject/connect.svg)](https://www.npmjs.com/package/@0xproject/connect) | A Javascript library for interacting with the Standard Relayer API | +| [`@0xproject/sol-compiler`](/packages/sol-compiler) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-compiler.svg)](https://www.npmjs.com/package/@0xproject/sol-compiler) | A thin wrapper around Solc.js that outputs artifacts, resolves imports, only re-compiles when needed, and other niceties. | +| [`@0xproject/dev-utils`](/packages/dev-utils) | [![npm](https://img.shields.io/npm/v/@0xproject/dev-utils.svg)](https://www.npmjs.com/package/@0xproject/dev-utils) | Dev utils to be shared across 0x projects and packages | +| [`@0xproject/json-schemas`](/packages/json-schemas) | [![npm](https://img.shields.io/npm/v/@0xproject/json-schemas.svg)](https://www.npmjs.com/package/@0xproject/json-schemas) | 0x-related json schemas | +| [`@0xproject/monorepo-scripts`](/packages/monorepo-scripts) | [![npm](https://img.shields.io/npm/v/@0xproject/monorepo-scripts.svg)](https://www.npmjs.com/package/@0xproject/monorepo-scripts) | Monorepo scripts | +| [`@0xproject/react-docs`](/packages/react-docs) | [![npm](https://img.shields.io/npm/v/@0xproject/react-docs.svg)](https://www.npmjs.com/package/@0xproject/react-docs) | React documentation component for rendering TypeDoc & Doxity generated JSON | +| [`@0xproject/react-shared`](/packages/react-shared) | [![npm](https://img.shields.io/npm/v/@0xproject/react-shared.svg)](https://www.npmjs.com/package/@0xproject/react-shared) | 0x shared react components | +| [`@0xproject/sra-report`](/packages/sra-report) | [![npm](https://img.shields.io/npm/v/@0xproject/sra-report.svg)](https://www.npmjs.com/package/@0xproject/sra-report) | Generate reports for standard relayer API compliance | +| [`@0xproject/sol-cov`](/packages/sol-cov) | [![npm](https://img.shields.io/npm/v/@0xproject/sol-cov.svg)](https://www.npmjs.com/package/@0xproject/sol-cov) | Solidity test coverage tool | +| [`@0xproject/subproviders`](/packages/subproviders) | [![npm](https://img.shields.io/npm/v/@0xproject/subproviders.svg)](https://www.npmjs.com/package/@0xproject/subproviders) | Useful web3 subproviders (e.g LedgerSubprovider) | +| [`@0xproject/tslint-config`](/packages/tslint-config) | [![npm](https://img.shields.io/npm/v/@0xproject/tslint-config.svg)](https://www.npmjs.com/package/@0xproject/tslint-config) | Custom 0x development TSLint rules | +| [`@0xproject/types`](/packages/types) | [![npm](https://img.shields.io/npm/v/@0xproject/types.svg)](https://www.npmjs.com/package/@0xproject/types) | Shared type declarations | +| [`@0xproject/typescript-typings`](/packages/typescript-typings) | [![npm](https://img.shields.io/npm/v/@0xproject/typescript-typings.svg)](https://www.npmjs.com/package/@0xproject/typescript-typings) | Repository of types for external packages | +| [`@0xproject/utils`](/packages/utils) | [![npm](https://img.shields.io/npm/v/@0xproject/utils.svg)](https://www.npmjs.com/package/@0xproject/utils) | Shared utilities | +| [`@0xproject/web3-wrapper`](/packages/web3-wrapper) | [![npm](https://img.shields.io/npm/v/@0xproject/web3-wrapper.svg)](https://www.npmjs.com/package/@0xproject/web3-wrapper) | Web3 wrapper | ### Private Packages -- cgit v1.2.3 From 1dec6a442ed4bbc50a33c78fa5c47147a58f3ae1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:06:35 +0200 Subject: Put ARTIFACTS_VERSION in a config --- packages/0x.js/test/global_hooks.ts | 2 +- packages/0x.js/test/utils/constants.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index 9d9d06918..b722ec6d9 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -13,6 +13,6 @@ before('migrate contracts', async function() { gas: devConstants.GAS_ESTIMATE, from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const artifactsDir = '../migrations/artifacts/1.0.0'; + const artifactsDir = `../migrations/artifacts/${constants.ARTIFACTS_VERSION}`; await runMigrationsAsync(provider, artifactsDir, defaults); }); diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts index cf030259c..cf5da464c 100644 --- a/packages/0x.js/test/utils/constants.ts +++ b/packages/0x.js/test/utils/constants.ts @@ -6,4 +6,5 @@ export const constants = { KOVAN_RPC_URL: 'https://kovan.infura.io/', ROPSTEN_RPC_URL: 'https://ropsten.infura.io/', ZRX_DECIMALS: 18, + ARTIFACTS_VERSION: '1.0.0', }; -- cgit v1.2.3 From 62f1430a2c53cb983c28f156bd0dd6409821ad5a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:07:16 +0200 Subject: Add a comment --- packages/base-contract/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 2b39029d5..8da3c2e71 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -48,6 +48,8 @@ export class BaseContract { if (!_.isUndefined(constructorAbiIfExists)) { return constructorAbiIfExists; } else { + // If the constructor is not explicitly defined, it won't be included in the ABI. It is + // still callable however, so we construct what the ABI would look like were it to exist. const defaultConstructorAbi: ConstructorAbi = { type: AbiType.Constructor, stateMutability: 'nonpayable', -- cgit v1.2.3 From a5fea3b9c3a004b5e2740a9a2d70eb3170aa6b73 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:09:33 +0200 Subject: Add a check for compiler output --- packages/0x.js/test/global_hooks.ts | 2 +- packages/0x.js/test/utils/constants.ts | 1 - packages/contract_templates/contract.handlebars | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index b722ec6d9..3e6731add 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -13,6 +13,6 @@ before('migrate contracts', async function() { gas: devConstants.GAS_ESTIMATE, from: devConstants.TESTRPC_FIRST_ADDRESS, }; - const artifactsDir = `../migrations/artifacts/${constants.ARTIFACTS_VERSION}`; + const artifactsDir = `../migrations/artifacts/1.0.0`; await runMigrationsAsync(provider, artifactsDir, defaults); }); diff --git a/packages/0x.js/test/utils/constants.ts b/packages/0x.js/test/utils/constants.ts index cf5da464c..cf030259c 100644 --- a/packages/0x.js/test/utils/constants.ts +++ b/packages/0x.js/test/utils/constants.ts @@ -6,5 +6,4 @@ export const constants = { KOVAN_RPC_URL: 'https://kovan.infura.io/', ROPSTEN_RPC_URL: 'https://ropsten.infura.io/', ZRX_DECIMALS: 18, - ARTIFACTS_VERSION: '1.0.0', }; diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 0f6151690..1fa9508f5 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -46,6 +46,9 @@ export class {{contractName}}Contract extends BaseContract { defaults: Partial, {{> typed_params inputs=ctor.inputs}} ): Promise<{{contractName}}Contract> { + if (_.isUndefined(artifact.compilerOutput)) { + throw new Error('Compiler output not found in the artifact file'); + } const bytecode = artifact.compilerOutput.evm.bytecode.object; const abi = artifact.compilerOutput.abi; return {{contractName}}Contract.deployAsync(bytecode, abi, provider, defaults, {{> params inputs=ctor.inputs}}); -- cgit v1.2.3 From 1055ca6d4435c0a9b325586e4c7af3458eff273a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:18:33 +0200 Subject: Add a legacy endpoint for the deployer --- packages/website/ts/index.tsx | 4 ++++ packages/website/ts/types.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/packages/website/ts/index.tsx b/packages/website/ts/index.tsx index 2688d0259..49bcdeaac 100644 --- a/packages/website/ts/index.tsx +++ b/packages/website/ts/index.tsx @@ -126,6 +126,10 @@ render( path={`${WebsiteLegacyPaths.Web3Wrapper}/:version?`} component={LazyWeb3WrapperDocumentation} /> + diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index 51a3bcba6..58929a0c6 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -344,6 +344,7 @@ export enum Docs { export enum WebsiteLegacyPaths { ZeroExJs = '/docs/0xjs', Web3Wrapper = '/docs/web3_wrapper', + Deployer = '/docs/deployer', } export enum WebsitePaths { -- cgit v1.2.3 From f854f3ee2bd74bbb61ed465099168b4d391f92c8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:20:00 +0200 Subject: Remove unused deployer docs configs --- packages/0x.js/src/0x.ts | 4 ++-- packages/0x.js/test/global_hooks.ts | 4 ++-- packages/0x.js/test/utils/fill_scenarios.ts | 1 - packages/base-contract/src/index.ts | 8 +++---- packages/contract_templates/contract.handlebars | 14 ++++++------ packages/contracts/test/ether_token.ts | 4 ++-- packages/contracts/test/exchange/core.ts | 14 ++++++------ packages/contracts/test/exchange/helpers.ts | 14 ++++++------ packages/contracts/test/exchange/wrapper.ts | 14 ++++++------ .../contracts/test/multi_sig_with_time_lock.ts | 6 ++--- ...i_sig_with_time_lock_except_remove_auth_addr.ts | 8 +++---- packages/contracts/test/token_registry.ts | 4 ++-- .../contracts/test/token_transfer_proxy/auth.ts | 4 ++-- .../test/token_transfer_proxy/transfer_from.ts | 6 ++--- packages/contracts/test/tutorials/arbitrage.ts | 16 ++++++------- .../contracts/test/unlimited_allowance_token.ts | 4 ++-- packages/contracts/test/utils/web3_wrapper.ts | 2 +- packages/contracts/test/zrx_token.ts | 4 ++-- packages/metacoin/test/metacoin_test.ts | 2 +- packages/migrations/package.json | 1 + packages/migrations/src/artifact_writer.ts | 26 ++++++++++++++++++++++ packages/migrations/src/artifacts.ts | 23 ------------------- packages/migrations/src/migrate.ts | 2 +- packages/migrations/src/migration.ts | 22 ++++++++++-------- packages/monorepo-scripts/src/publish.ts | 2 +- packages/monorepo-scripts/src/test_installation.ts | 2 +- packages/sol-compiler/src/utils/utils.ts | 4 +--- packages/sol-cov/src/coverage_manager.ts | 4 +--- packages/web3-wrapper/src/web3_wrapper.ts | 10 ++++----- .../ts/containers/sol_compiler_documentation.ts | 21 ++++------------- 30 files changed, 120 insertions(+), 130 deletions(-) create mode 100644 packages/migrations/src/artifact_writer.ts diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 78f9f6beb..f603ad644 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -144,10 +144,10 @@ export class ZeroEx { ]); const artifactJSONs = _.values(artifacts); const abiArrays = _.map(artifactJSONs, artifact => artifact.abi); - const defaults = { + const txDefaults = { gasPrice: config.gasPrice, }; - this._web3Wrapper = new Web3Wrapper(provider, defaults); + this._web3Wrapper = new Web3Wrapper(provider, txDefaults); _.forEach(abiArrays, abi => { this._web3Wrapper.abiDecoder.addABI(abi); }); diff --git a/packages/0x.js/test/global_hooks.ts b/packages/0x.js/test/global_hooks.ts index 3e6731add..88f202761 100644 --- a/packages/0x.js/test/global_hooks.ts +++ b/packages/0x.js/test/global_hooks.ts @@ -9,10 +9,10 @@ before('migrate contracts', async function() { // HACK: Since the migrations take longer then our global mocha timeout limit // we manually increase it for this before hook. this.timeout(20000); - const defaults = { + const txDefaults = { gas: devConstants.GAS_ESTIMATE, from: devConstants.TESTRPC_FIRST_ADDRESS, }; const artifactsDir = `../migrations/artifacts/1.0.0`; - await runMigrationsAsync(provider, artifactsDir, defaults); + await runMigrationsAsync(provider, artifactsDir, txDefaults); }); diff --git a/packages/0x.js/test/utils/fill_scenarios.ts b/packages/0x.js/test/utils/fill_scenarios.ts index 5a82a56d2..7f28c8af3 100644 --- a/packages/0x.js/test/utils/fill_scenarios.ts +++ b/packages/0x.js/test/utils/fill_scenarios.ts @@ -35,7 +35,6 @@ export class FillScenarios { const web3Wrapper = (this._zeroEx as any)._web3Wrapper as Web3Wrapper; for (const token of this._tokens) { if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') { - const defaults = {}; const dummyToken = new DummyTokenContract( artifacts.DummyTokenArtifact.abi, token.address, diff --git a/packages/base-contract/src/index.ts b/packages/base-contract/src/index.ts index 8da3c2e71..f9298f413 100644 --- a/packages/base-contract/src/index.ts +++ b/packages/base-contract/src/index.ts @@ -64,7 +64,7 @@ export class BaseContract { } protected static async _applyDefaultsToTxDataAsync>( txData: T, - defaults: Partial, + txDefaults: Partial, estimateGasAsync?: (txData: T) => Promise, ): Promise { // Gas amount sourced with the following priorities: @@ -73,7 +73,7 @@ export class BaseContract { // 3. Gas estimate calculation + safety margin const removeUndefinedProperties = _.pickBy; const txDataWithDefaults: TxData = { - ...removeUndefinedProperties(defaults), + ...removeUndefinedProperties(txDefaults), ...removeUndefinedProperties(txData as any), // HACK: TS can't prove that T is spreadable. // Awaiting https://github.com/Microsoft/TypeScript/pull/13288 to be merged @@ -109,10 +109,10 @@ export class BaseContract { abi: ContractAbi, address: string, provider: Provider, - defaults?: Partial, + txDefaults?: Partial, ) { this.contractName = contractName; - this._web3Wrapper = new Web3Wrapper(provider, defaults); + this._web3Wrapper = new Web3Wrapper(provider, txDefaults); this.abi = abi; this.address = address; const methodAbis = this.abi.filter( diff --git a/packages/contract_templates/contract.handlebars b/packages/contract_templates/contract.handlebars index 1fa9508f5..ed11ac8d2 100644 --- a/packages/contract_templates/contract.handlebars +++ b/packages/contract_templates/contract.handlebars @@ -43,7 +43,7 @@ export class {{contractName}}Contract extends BaseContract { public static async deployFrom0xArtifactAsync( artifact: ContractArtifact, provider: Provider, - defaults: Partial, + txDefaults: Partial, {{> typed_params inputs=ctor.inputs}} ): Promise<{{contractName}}Contract> { if (_.isUndefined(artifact.compilerOutput)) { @@ -51,13 +51,13 @@ export class {{contractName}}Contract extends BaseContract { } const bytecode = artifact.compilerOutput.evm.bytecode.object; const abi = artifact.compilerOutput.abi; - return {{contractName}}Contract.deployAsync(bytecode, abi, provider, defaults, {{> params inputs=ctor.inputs}}); + return {{contractName}}Contract.deployAsync(bytecode, abi, provider, txDefaults, {{> params inputs=ctor.inputs}}); } public static async deployAsync( bytecode: string, abi: ContractAbi, provider: Provider, - defaults: Partial, + txDefaults: Partial, {{> typed_params inputs=ctor.inputs}} ): Promise<{{contractName}}Contract> { const constructorAbi = BaseContract._lookupConstructorAbi(abi); @@ -70,19 +70,19 @@ export class {{contractName}}Contract extends BaseContract { const web3Wrapper = new Web3Wrapper(provider); const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( txData, - defaults, + txDefaults, web3Wrapper.estimateGasAsync.bind(web3Wrapper), ); const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults); logUtils.log(`transactionHash: ${txHash}`); const txReceipt = await web3Wrapper.awaitTransactionMinedAsync(txHash); logUtils.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`); - const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, defaults); + const contractInstance = new {{contractName}}Contract(abi, txReceipt.contractAddress as string, provider, txDefaults); contractInstance.constructorArgs = [{{> params inputs=ctor.inputs}}]; return contractInstance; } - constructor(abi: ContractAbi, address: string, provider: Provider, defaults?: Partial) { - super("{{contractName}}", abi, address, provider, defaults); + constructor(abi: ContractAbi, address: string, provider: Provider, txDefaults?: Partial) { + super("{{contractName}}", abi, address, provider, txDefaults); classUtils.bindAll(this, ['_ethersInterfacesByFunctionSignature', 'address', 'abi', '_web3Wrapper']); } } // tslint:disable:max-file-line-count diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index a25e4ebba..da84b8b97 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -11,7 +11,7 @@ import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -26,7 +26,7 @@ describe('EtherToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, defaults); + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); etherTokenAddress = etherToken.address; zeroEx = new ZeroEx(provider, { gasPrice, diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 1a404c410..3d7a7a174 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -24,7 +24,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -60,7 +60,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -69,7 +69,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -78,7 +78,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -88,12 +88,12 @@ describe('Exchange', () => { tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrx.address, tokenTransferProxy.address, ); @@ -716,7 +716,7 @@ describe('Exchange', () => { const maliciousToken = await MaliciousTokenContract.deployFrom0xArtifactAsync( artifacts.MaliciousToken, provider, - defaults, + txDefaults, ); await maliciousToken.approve.sendTransactionAsync(tokenTransferProxy.address, INITIAL_ALLOWANCE, { from: taker, diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 8835412de..112f9782c 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -22,7 +22,7 @@ import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -43,18 +43,18 @@ describe('Exchange', () => { const tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( artifacts.TokenRegistry, provider, - defaults, + txDefaults, ); const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); const [rep, dgd, zrx] = await Promise.all([ DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -63,7 +63,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -72,7 +72,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -82,7 +82,7 @@ describe('Exchange', () => { const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrx.address, tokenTransferProxy.address, ); diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index 1c80189ab..a8d97f552 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -23,7 +23,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -59,7 +59,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -68,7 +68,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -77,7 +77,7 @@ describe('Exchange', () => { DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -87,17 +87,17 @@ describe('Exchange', () => { tokenRegistry = await TokenRegistryContract.deployFrom0xArtifactAsync( artifacts.TokenRegistry, provider, - defaults, + txDefaults, ); tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrx.address, tokenTransferProxy.address, ); diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 361d87ff7..1a22a4011 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -15,7 +15,7 @@ import { ContractName, SubmissionContractEventArgs } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi; chaiSetup.configure(); @@ -50,7 +50,7 @@ describe('MultiSigWalletWithTimeLock', () => { multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, provider, - defaults, + txDefaults, owners, SIGNATURES_REQUIRED, new BigNumber(0), @@ -145,7 +145,7 @@ describe('MultiSigWalletWithTimeLock', () => { multiSig = await MultiSigWalletWithTimeLockContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLock, provider, - defaults, + txDefaults, owners, SIGNATURES_REQUIRED, SECONDS_TIME_LOCKED, diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index ba23889b3..0ea212f7b 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -16,7 +16,7 @@ import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; const PROXY_ABI = artifacts.TokenTransferProxy.compilerOutput.abi; const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI = artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.compilerOutput.abi; @@ -49,7 +49,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); await tokenTransferProxy.addAuthorizedAddress.sendTransactionAsync(authorizedAddress, { from: initialOwner, @@ -57,7 +57,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, - defaults, + txDefaults, owners, requiredApprovals, SECONDS_TIME_LOCKED, @@ -112,7 +112,7 @@ describe('MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress', () => { const invalidTokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); const invalidDestination = invalidTokenTransferProxy.address; const dataParams: TransactionDataParams = { diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 363631385..7f45284af 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -14,7 +14,7 @@ import { TokenRegWrapper } from '../util/token_registry_wrapper'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -29,7 +29,7 @@ describe('TokenRegistry', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); owner = accounts[0]; notOwner = accounts[1]; - tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, txDefaults); tokenRegWrapper = new TokenRegWrapper(tokenReg); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 6baadab61..47f07e2a8 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -9,7 +9,7 @@ import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -27,7 +27,7 @@ describe('TokenTransferProxy', () => { tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); }); beforeEach(async () => { diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index 92573caf7..5a3071a33 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -12,7 +12,7 @@ import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -35,12 +35,12 @@ describe('TokenTransferProxy', () => { tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); rep = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 43dbd2989..89062d4dc 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -21,7 +21,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { defaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -61,7 +61,7 @@ describe('Arbitrage', () => { weth = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -70,7 +70,7 @@ describe('Arbitrage', () => { zrx = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, @@ -79,7 +79,7 @@ describe('Arbitrage', () => { const accountLevels = await AccountLevelsContract.deployFrom0xArtifactAsync( artifacts.AccountLevels, provider, - defaults, + txDefaults, ); const edAdminAddress = accounts[0]; const edMakerFee = new BigNumber(0); @@ -88,7 +88,7 @@ describe('Arbitrage', () => { etherDelta = await EtherDeltaContract.deployFrom0xArtifactAsync( artifacts.EtherDelta, provider, - defaults, + txDefaults, edAdminAddress, feeRecipient, accountLevels.address, @@ -99,12 +99,12 @@ describe('Arbitrage', () => { const tokenTransferProxy = await TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrx.address, tokenTransferProxy.address, ); @@ -132,7 +132,7 @@ describe('Arbitrage', () => { arbitrage = await ArbitrageContract.deployFrom0xArtifactAsync( artifacts.Arbitrage, provider, - defaults, + txDefaults, exchange.address, etherDelta.address, tokenTransferProxy.address, diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 546958cfd..860efa73c 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -11,7 +11,7 @@ import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -36,7 +36,7 @@ describe('UnlimitedAllowanceToken', () => { token = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, constants.DUMMY_TOKEN_NAME, constants.DUMMY_TOKEN_SYMBOL, constants.DUMMY_TOKEN_DECIMALS, diff --git a/packages/contracts/test/utils/web3_wrapper.ts b/packages/contracts/test/utils/web3_wrapper.ts index 4b2a8ed60..ed1c488a2 100644 --- a/packages/contracts/test/utils/web3_wrapper.ts +++ b/packages/contracts/test/utils/web3_wrapper.ts @@ -2,7 +2,7 @@ import { devConstants, web3Factory } from '@0xproject/dev-utils'; import { Provider } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; -export const defaults = { +export const txDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, gas: devConstants.GAS_ESTIMATE, }; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index dcba5ab1a..dda15783f 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -11,7 +11,7 @@ import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { defaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -34,7 +34,7 @@ describe('ZRXToken', () => { zeroEx = new ZeroEx(provider, { networkId: constants.TESTRPC_NETWORK_ID, }); - zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, defaults); + zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); zrxAddress = zrx.address; MAX_UINT = zeroEx.token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; }); diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts index a31ce1779..8369632c2 100644 --- a/packages/metacoin/test/metacoin_test.ts +++ b/packages/metacoin/test/metacoin_test.ts @@ -23,7 +23,7 @@ describe('Metacoin', () => { const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS; const INITIAL_BALANCE = new BigNumber(10000); before(async () => { - metacoin = await MetacoinContract.deployFrom0xArtifactAsync(artifact, provider, config.defaults); + metacoin = await MetacoinContract.deployFrom0xArtifactAsync(artifact, provider, config.txDefaults); web3Wrapper.abiDecoder.addABI(metacoin.abi); }); beforeEach(async () => { diff --git a/packages/migrations/package.json b/packages/migrations/package.json index be17614b4..0723c5d88 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -33,6 +33,7 @@ "dependencies": { "@0xproject/sol-compiler": "^0.4.3", "@0xproject/base-contract": "^0.3.1", + "@0xproject/typescript-typings": "^0.3.1", "@0xproject/utils": "^0.6.1", "@0xproject/web3-wrapper": "^0.6.3", "ethers": "^3.0.15", diff --git a/packages/migrations/src/artifact_writer.ts b/packages/migrations/src/artifact_writer.ts new file mode 100644 index 000000000..2da5a09dd --- /dev/null +++ b/packages/migrations/src/artifact_writer.ts @@ -0,0 +1,26 @@ +import { BaseContract } from '@0xproject/base-contract'; +import { ContractArtifact } from '@0xproject/sol-compiler'; +import * as fs from 'fs'; +import * as path from 'path'; + +export class ArtifactWriter { + private _artifactsDir: string; + private _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')); + } +} diff --git a/packages/migrations/src/artifacts.ts b/packages/migrations/src/artifacts.ts index f8913fe52..42eb1c33e 100644 --- a/packages/migrations/src/artifacts.ts +++ b/packages/migrations/src/artifacts.ts @@ -1,7 +1,4 @@ -import { BaseContract } from '@0xproject/base-contract'; import { ContractArtifact } from '@0xproject/sol-compiler'; -import * as fs from 'fs'; -import * as path from 'path'; import * as AccountLevels from '../artifacts/1.0.0/AccountLevels.json'; import * as Arbitrage from '../artifacts/1.0.0/Arbitrage.json'; @@ -32,23 +29,3 @@ export const artifacts = { MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: (MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress as any) as ContractArtifact, }; - -export class ArtifactWriter { - private _artifactsDir: string; - private _networkId: number; - constructor(artifactsDir: string, networkId: number) { - this._artifactsDir = artifactsDir; - this._networkId = networkId; - } - 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, 2)); - } -} diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index 58d39734e..fe3daed98 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -14,7 +14,7 @@ import { runMigrationsAsync } from './migration'; const web3 = web3Factory.create(providerConfigs); const provider = web3.currentProvider; const artifactsDir = 'artifacts/1.0.0'; - await runMigrationsAsync(provider, artifactsDir, defaults); + await runMigrationsAsync(provider, artifactsDir, txDefaults); process.exit(0); })().catch(err => { logUtils.log(err); diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 5b49b9282..2e38b59ae 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -20,24 +20,28 @@ import { tokenInfo } from './utils/token_info'; * the migration should be written to run synchronously. * @param provider Web3 provider instance. * @param artifactsDir The directory with compiler artifact files. - * @param defaults Default transaction values to use when deploying contracts. + * @param txDefaults Default transaction values to use when deploying contracts. */ -export const runMigrationsAsync = async (provider: Provider, artifactsDir: string, defaults: Partial) => { +export const runMigrationsAsync = 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 TokenTransferProxyContract.deployFrom0xArtifactAsync( artifacts.TokenTransferProxy, provider, - defaults, + txDefaults, ); artifactsWriter.saveArtifact(tokenTransferProxy); - const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, defaults); + const zrxToken = await ZRXTokenContract.deployFrom0xArtifactAsync(artifacts.ZRX, provider, txDefaults); artifactsWriter.saveArtifact(zrxToken); - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, defaults); + const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); artifactsWriter.saveArtifact(etherToken); - const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync(artifacts.TokenRegistry, provider, defaults); + const tokenReg = await TokenRegistryContract.deployFrom0xArtifactAsync( + artifacts.TokenRegistry, + provider, + txDefaults, + ); artifactsWriter.saveArtifact(tokenReg); const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync(); @@ -47,7 +51,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin const exchange = await ExchangeContract.deployFrom0xArtifactAsync( artifacts.Exchange, provider, - defaults, + txDefaults, zrxToken.address, tokenTransferProxy.address, ); @@ -55,7 +59,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin const multiSig = await MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract.deployFrom0xArtifactAsync( artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress, provider, - defaults, + txDefaults, owners, confirmationsRequired, secondsRequired, @@ -104,7 +108,7 @@ export const runMigrationsAsync = async (provider: Provider, artifactsDir: strin const dummyToken = await DummyTokenContract.deployFrom0xArtifactAsync( artifacts.DummyToken, provider, - defaults, + txDefaults, token.name, token.symbol, token.decimals, diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 2011dc393..a5be40014 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -214,7 +214,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } // Save updated CHANGELOG.json - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, 4)); + fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 78e0f0929..e84221f9d 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -46,7 +46,7 @@ import { utils } from './utils'; include: ['index.ts'], }; const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); - fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, 4)); + fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, '\t')); utils.log(`Compiling ${packageName}`); const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); await execAsync(tscBinaryPath, { cwd: testDirectory }); diff --git a/packages/sol-compiler/src/utils/utils.ts b/packages/sol-compiler/src/utils/utils.ts index 9b1e59f9d..4f2de2caa 100644 --- a/packages/sol-compiler/src/utils/utils.ts +++ b/packages/sol-compiler/src/utils/utils.ts @@ -1,8 +1,6 @@ export const utils = { stringifyWithFormatting(obj: any): string { - const jsonReplacer: null = null; - const numberOfJsonSpaces = 4; - const stringifiedObj = JSON.stringify(obj, jsonReplacer, numberOfJsonSpaces); + const stringifiedObj = JSON.stringify(obj, null, '\t'); return stringifiedObj; }, }; diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts index bf580025b..f50f010b9 100644 --- a/packages/sol-cov/src/coverage_manager.ts +++ b/packages/sol-cov/src/coverage_manager.ts @@ -48,9 +48,7 @@ export class CoverageManager { } public async writeCoverageAsync(): Promise { const finalCoverage = await this._computeCoverageAsync(); - const jsonReplacer: null = null; - const numberOfJsonSpaces = 4; - const stringifiedCoverage = JSON.stringify(finalCoverage, jsonReplacer, numberOfJsonSpaces); + const stringifiedCoverage = JSON.stringify(finalCoverage, null, '\t'); fs.writeFileSync('coverage/coverage.json', stringifiedCoverage); } private _getSingleFileCoverageForTrace( diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 5e6ff3239..82e6ef4f9 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -29,7 +29,7 @@ export class Web3Wrapper { public isZeroExWeb3Wrapper = true; public abiDecoder: AbiDecoder; private _web3: Web3; - private _defaults: Partial; + private _txDefaults: Partial; private _jsonRpcRequestId: number; /** * Check if an address is a valid Ethereum address @@ -83,10 +83,10 @@ export class Web3Wrapper { * Instantiates a new Web3Wrapper. * @param provider The Web3 provider instance you would like the Web3Wrapper to use for interacting with * the backing Ethereum node. - * @param defaults Override TxData defaults sent with RPC requests to the backing Ethereum node. + * @param txDefaults Override TxData defaults sent with RPC requests to the backing Ethereum node. * @return An instance of the Web3Wrapper class. */ - constructor(provider: Provider, defaults?: Partial) { + constructor(provider: Provider, txDefaults?: Partial) { if (_.isUndefined((provider as any).sendAsync)) { // Web3@1.0 provider doesn't support synchronous http requests, // so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x` @@ -96,7 +96,7 @@ export class Web3Wrapper { this.abiDecoder = new AbiDecoder([]); this._web3 = new Web3(); this._web3.setProvider(provider); - this._defaults = defaults || {}; + this._txDefaults = txDefaults || {}; this._jsonRpcRequestId = 0; } /** @@ -104,7 +104,7 @@ export class Web3Wrapper { * @return TxData defaults (e.g gas, gasPrice, nonce, etc...) */ public getContractDefaults(): Partial { - return this._defaults; + return this._txDefaults; } /** * Retrieve the Web3 provider diff --git a/packages/website/ts/containers/sol_compiler_documentation.ts b/packages/website/ts/containers/sol_compiler_documentation.ts index 0cf595645..2f6486146 100644 --- a/packages/website/ts/containers/sol_compiler_documentation.ts +++ b/packages/website/ts/containers/sol_compiler_documentation.ts @@ -28,7 +28,7 @@ const docSections = { const docsInfoConfig: DocsInfoConfig = { id: DocPackages.SolCompiler, type: SupportedDocJson.TypeDoc, - displayName: 'Sol Compiler', + displayName: 'Solidity Compiler', packageUrl: 'https://github.com/0xProject/0x-monorepo', menu: { introduction: [docSections.introduction], @@ -52,22 +52,9 @@ const docsInfoConfig: DocsInfoConfig = { typeConfigs: { // Note: This needs to be kept in sync with the types exported in index.ts. Unfortunately there is // currently no way to extract the re-exported types from index.ts via TypeDoc :( - publicTypes: [ - 'CompilerOptions', - 'DeployerOptions', - 'BaseDeployerOptions', - 'UrlDeployerOptions', - 'ProviderDeployerOptions', - 'TxData', - ], - typeNameToExternalLink: { - Web3: constants.URL_WEB3_DOCS, - BigNumber: constants.URL_BIGNUMBERJS_GITHUB, - ContractInstance: 'https://github.com/0xProject/web3-typescript-typings/blob/f5bcb96/index.d.ts#L98', - }, - typeNameToPrefix: { - ContractInstance: 'Web3', - }, + publicTypes: ['CompilerOptions'], + typeNameToExternalLink: {}, + typeNameToPrefix: {}, }, }; const docsInfo = new DocsInfo(docsInfoConfig); -- cgit v1.2.3 From 2e1c2d9dfeca4439435fdf1ed58504142963585a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 16:57:51 +0200 Subject: Fix templates --- packages/contract_templates/partials/callAsync.handlebars | 2 +- packages/contract_templates/partials/tx.handlebars | 4 ++-- packages/metacoin/test/utils/config.ts | 2 +- packages/migrations/src/migrate.ts | 2 +- packages/migrations/src/migration.ts | 3 ++- packages/sol-compiler/solc_bin/.gitkeep | 0 packages/website/ts/components/top_bar/top_bar.tsx | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 packages/sol-compiler/solc_bin/.gitkeep diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 904936173..71c43eb18 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -16,7 +16,7 @@ async callAsync( { data: encodedData, }, - this._web3Wrapper.getContractDefaults(), + self._web3Wrapper.getContractDefaults(), ) const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock); let resultArray = ethersFunction.parse(rawCallResult); diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index f72078a4e..23bafd869 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -19,7 +19,7 @@ public {{this.tsName}} = { ...txData, data: encodedData, }, - this._web3Wrapper.getContractDefaults(), + self._web3Wrapper.getContractDefaults(), self.{{this.tsName}}.estimateGasAsync.bind( self, {{> params inputs=inputs}} @@ -43,7 +43,7 @@ public {{this.tsName}} = { ...txData, data: encodedData, }, - this._web3Wrapper.getContractDefaults(), + self._web3Wrapper.getContractDefaults(), ); const gas = await self._web3Wrapper.estimateGasAsync(txDataWithDefaults); return gas; diff --git a/packages/metacoin/test/utils/config.ts b/packages/metacoin/test/utils/config.ts index 8ae6d39a2..389edb388 100644 --- a/packages/metacoin/test/utils/config.ts +++ b/packages/metacoin/test/utils/config.ts @@ -6,7 +6,7 @@ export const config = { artifactsDir: path.resolve(__dirname, '../../artifacts'), contractsDir: path.resolve(__dirname, '../../contracts'), ganacheLogFile: 'ganache.log', - defaults: { + txDefaults: { from: devConstants.TESTRPC_FIRST_ADDRESS, }, mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', diff --git a/packages/migrations/src/migrate.ts b/packages/migrations/src/migrate.ts index fe3daed98..b00ba698f 100644 --- a/packages/migrations/src/migrate.ts +++ b/packages/migrations/src/migrate.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import { runMigrationsAsync } from './migration'; (async () => { - const defaults = { + const txDefaults = { from: devConstants.TESTRPC_FIRST_ADDRESS, }; const providerConfigs = { shouldUseInProcessGanache: false }; diff --git a/packages/migrations/src/migration.ts b/packages/migrations/src/migration.ts index 2e38b59ae..96973fb62 100644 --- a/packages/migrations/src/migration.ts +++ b/packages/migrations/src/migration.ts @@ -3,7 +3,8 @@ import { BigNumber, NULL_BYTES } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; -import { artifacts, ArtifactWriter } from './artifacts'; +import { ArtifactWriter } from './artifact_writer'; +import { artifacts } from './artifacts'; import { DummyTokenContract } from './contract_wrappers/dummy_token'; import { ExchangeContract } from './contract_wrappers/exchange'; import { MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddressContract } from './contract_wrappers/multi_sig_wallet_with_time_lock_except_remove_authorized_address'; diff --git a/packages/sol-compiler/solc_bin/.gitkeep b/packages/sol-compiler/solc_bin/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/website/ts/components/top_bar/top_bar.tsx b/packages/website/ts/components/top_bar/top_bar.tsx index 23130853c..5a1b50310 100644 --- a/packages/website/ts/components/top_bar/top_bar.tsx +++ b/packages/website/ts/components/top_bar/top_bar.tsx @@ -390,7 +390,7 @@ export class TopBar extends React.Component { (!this._isViewing0xjsDocs() && !this._isViewingSmartContractsDocs() && !this._isViewingWeb3WrapperDocs() && - !this._isViewingDeployerDocs() && + !this._isViewingSolCompilerDocs() && !this._isViewingJsonSchemasDocs() && !this._isViewingSolCovDocs() && !this._isViewingSubprovidersDocs() && -- cgit v1.2.3 From e972ed8456b4e98af649b0e7878693322ed94a90 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 18:12:34 +0200 Subject: Fix linter errors --- packages/contracts/test/ether_token.ts | 2 +- packages/contracts/test/exchange/core.ts | 2 +- packages/contracts/test/exchange/helpers.ts | 2 +- packages/contracts/test/exchange/wrapper.ts | 2 +- packages/contracts/test/multi_sig_with_time_lock.ts | 2 +- .../contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts | 2 +- packages/contracts/test/token_registry.ts | 2 +- packages/contracts/test/token_transfer_proxy/auth.ts | 2 +- packages/contracts/test/token_transfer_proxy/transfer_from.ts | 2 +- packages/contracts/test/tutorials/arbitrage.ts | 2 +- packages/contracts/test/unlimited_allowance_token.ts | 2 +- packages/contracts/test/zrx_token.ts | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index da84b8b97..f80f2159e 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -11,7 +11,7 @@ import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts index 3d7a7a174..e40b564c6 100644 --- a/packages/contracts/test/exchange/core.ts +++ b/packages/contracts/test/exchange/core.ts @@ -24,7 +24,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/exchange/helpers.ts b/packages/contracts/test/exchange/helpers.ts index 112f9782c..441c1bc28 100644 --- a/packages/contracts/test/exchange/helpers.ts +++ b/packages/contracts/test/exchange/helpers.ts @@ -22,7 +22,7 @@ import { OrderFactory } from '../../util/order_factory'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/exchange/wrapper.ts b/packages/contracts/test/exchange/wrapper.ts index a8d97f552..57ccd05bd 100644 --- a/packages/contracts/test/exchange/wrapper.ts +++ b/packages/contracts/test/exchange/wrapper.ts @@ -23,7 +23,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/multi_sig_with_time_lock.ts b/packages/contracts/test/multi_sig_with_time_lock.ts index 1a22a4011..01bc0ec90 100644 --- a/packages/contracts/test/multi_sig_with_time_lock.ts +++ b/packages/contracts/test/multi_sig_with_time_lock.ts @@ -15,7 +15,7 @@ import { ContractName, SubmissionContractEventArgs } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; const MULTI_SIG_ABI = artifacts.MultiSigWalletWithTimeLock.compilerOutput.abi; chaiSetup.configure(); diff --git a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts index 0ea212f7b..1c2ddea87 100644 --- a/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts +++ b/packages/contracts/test/multi_sig_with_time_lock_except_remove_auth_addr.ts @@ -16,7 +16,7 @@ import { ContractName, SubmissionContractEventArgs, TransactionDataParams } from import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; const PROXY_ABI = artifacts.TokenTransferProxy.compilerOutput.abi; const MUTISIG_WALLET_WITH_TIME_LOCK_EXCEPT_REMOVE_AUTHORIZED_ADDRESS_ABI = artifacts.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.compilerOutput.abi; diff --git a/packages/contracts/test/token_registry.ts b/packages/contracts/test/token_registry.ts index 7f45284af..8b7c3048d 100644 --- a/packages/contracts/test/token_registry.ts +++ b/packages/contracts/test/token_registry.ts @@ -14,7 +14,7 @@ import { TokenRegWrapper } from '../util/token_registry_wrapper'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/token_transfer_proxy/auth.ts b/packages/contracts/test/token_transfer_proxy/auth.ts index 47f07e2a8..97e8d0c2e 100644 --- a/packages/contracts/test/token_transfer_proxy/auth.ts +++ b/packages/contracts/test/token_transfer_proxy/auth.ts @@ -9,7 +9,7 @@ import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/token_transfer_proxy/transfer_from.ts b/packages/contracts/test/token_transfer_proxy/transfer_from.ts index 5a3071a33..c31d8a1cb 100644 --- a/packages/contracts/test/token_transfer_proxy/transfer_from.ts +++ b/packages/contracts/test/token_transfer_proxy/transfer_from.ts @@ -12,7 +12,7 @@ import { constants } from '../../util/constants'; import { ContractName } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/tutorials/arbitrage.ts b/packages/contracts/test/tutorials/arbitrage.ts index 89062d4dc..aa86ecd43 100644 --- a/packages/contracts/test/tutorials/arbitrage.ts +++ b/packages/contracts/test/tutorials/arbitrage.ts @@ -21,7 +21,7 @@ import { OrderFactory } from '../../util/order_factory'; import { BalancesByOwner, ContractName, ExchangeContractErrs } from '../../util/types'; import { chaiSetup } from '../utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from '../utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from '../utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index 860efa73c..da2e5fb5b 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -11,7 +11,7 @@ import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; diff --git a/packages/contracts/test/zrx_token.ts b/packages/contracts/test/zrx_token.ts index dda15783f..0056ed4b5 100644 --- a/packages/contracts/test/zrx_token.ts +++ b/packages/contracts/test/zrx_token.ts @@ -11,7 +11,7 @@ import { constants } from '../util/constants'; import { ContractName } from '../util/types'; import { chaiSetup } from './utils/chai_setup'; -import { txDefaults, provider, web3Wrapper } from './utils/web3_wrapper'; +import { provider, txDefaults, web3Wrapper } from './utils/web3_wrapper'; chaiSetup.configure(); const expect = chai.expect; -- cgit v1.2.3 From 1137abfd33f8f5a4deb9f55b21f45afd1b3d0b42 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 18:26:44 +0200 Subject: Fix a bug in compiler config precedence --- packages/sol-compiler/src/cli.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/sol-compiler/src/cli.ts b/packages/sol-compiler/src/cli.ts index 90b4949bc..71bb80c7d 100644 --- a/packages/sol-compiler/src/cli.ts +++ b/packages/sol-compiler/src/cli.ts @@ -27,14 +27,16 @@ const SEPARATOR = ','; }) .option('contracts', { type: 'string', - default: DEFAULT_CONTRACTS_LIST, description: 'comma separated list of contracts to compile', }) .help().argv; + const contracts = _.isUndefined(argv.contracts) + ? undefined + : argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR); const opts: CompilerOptions = { contractsDir: argv.contractsDir, artifactsDir: argv.artifactsDir, - contracts: argv.contracts === DEFAULT_CONTRACTS_LIST ? DEFAULT_CONTRACTS_LIST : argv.contracts.split(SEPARATOR), + contracts, }; const compiler = new Compiler(opts); await compiler.compileAsync(); -- cgit v1.2.3 From c093aab350dfbd86972d6388c3923ec60fc4501a Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 11 May 2018 11:59:08 +0200 Subject: Fix ganache subprovider config --- packages/contract_templates/partials/callAsync.handlebars | 1 + packages/contract_templates/partials/tx.handlebars | 2 ++ packages/dev-utils/src/web3_factory.ts | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/contract_templates/partials/callAsync.handlebars b/packages/contract_templates/partials/callAsync.handlebars index 71c43eb18..99fda80e1 100644 --- a/packages/contract_templates/partials/callAsync.handlebars +++ b/packages/contract_templates/partials/callAsync.handlebars @@ -14,6 +14,7 @@ async callAsync( const encodedData = ethersFunction.data; const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { + to: self.address, data: encodedData, }, self._web3Wrapper.getContractDefaults(), diff --git a/packages/contract_templates/partials/tx.handlebars b/packages/contract_templates/partials/tx.handlebars index 23bafd869..e297d05e6 100644 --- a/packages/contract_templates/partials/tx.handlebars +++ b/packages/contract_templates/partials/tx.handlebars @@ -16,6 +16,7 @@ public {{this.tsName}} = { ).data; const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { + to: self.address, ...txData, data: encodedData, }, @@ -40,6 +41,7 @@ public {{this.tsName}} = { ).data; const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync( { + to: self.address, ...txData, data: encodedData, }, diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts index 68348d671..4cd343c44 100644 --- a/packages/dev-utils/src/web3_factory.ts +++ b/packages/dev-utils/src/web3_factory.ts @@ -60,9 +60,9 @@ export const web3Factory = { provider.addProvider( new GanacheSubprovider({ logger, - verbose: env.parseBoolean(EnvVars.SolidityCoverage), + verbose: env.parseBoolean(EnvVars.VerboseGanache), port: 8545, - networkId: 50, + network_id: 50, mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', }), ); -- cgit v1.2.3