From 9818eb2835a8c06006514c44340c95c709f4aa9f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 14:45:01 +0200 Subject: Use custom contract abstraction --- src/contract.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/contract.ts (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts new file mode 100644 index 000000000..b4a54ca09 --- /dev/null +++ b/src/contract.ts @@ -0,0 +1,28 @@ +import * as Web3 from 'web3'; +import * as _ from 'lodash'; +import promisify = require('es6-promisify'); + +export class Contract implements Web3.ContractInstance { + public address: string; + public abi: Web3.ContractAbi; + private contract: A; + [name: string]: any; + constructor(web3ContractInstance: A) { + this.contract = web3ContractInstance; + this.address = web3ContractInstance.address; + this.abi = web3ContractInstance.abi; + const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); + _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { + const cbStyleFunction = web3ContractInstance[functionAbi.name]; + this[functionAbi.name] = promisify(cbStyleFunction, web3ContractInstance); + if (functionAbi.constant) { + const cbStyleCallFunction = web3ContractInstance[functionAbi.name].call; + this[functionAbi.name].call = promisify(cbStyleCallFunction, web3ContractInstance); + } else { + const cbStyleEstimateGasFunction = web3ContractInstance[functionAbi.name].estimateGas; + this[functionAbi.name].estimateGas = + promisify(cbStyleEstimateGasFunction, web3ContractInstance); + } + }); + } +} -- cgit v1.2.3 From 1ad395cf86b2006c09bdae814607c2baf9790b91 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 18:14:48 +0200 Subject: Make the functions immidiately return txHash instead of awaiting for a transaction to be mined --- src/0x.ts | 1 - src/artifacts/EtherToken.json | 2 +- src/contract.ts | 28 +++++--- src/contract_wrappers/contract_wrapper.ts | 47 ++----------- src/contract_wrappers/ether_token_wrapper.ts | 4 +- src/contract_wrappers/exchange_wrapper.ts | 76 ++++++++++------------ src/contract_wrappers/token_registry_wrapper.ts | 4 +- .../token_transfer_proxy_wrapper.ts | 4 +- src/contract_wrappers/token_wrapper.ts | 4 +- src/globals.d.ts | 20 ++---- src/types.ts | 29 +++------ src/web3_wrapper.ts | 28 ++++++++ 12 files changed, 116 insertions(+), 131 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index ba222f2c9..3cf672a1b 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -3,7 +3,6 @@ import * as BigNumber from 'bignumber.js'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; -import contract = require('truffle-contract'); import findVersions = require('find-versions'); import compareVersions = require('compare-versions'); import {Web3Wrapper} from './web3_wrapper'; diff --git a/src/artifacts/EtherToken.json b/src/artifacts/EtherToken.json index eca348530..54b5a032e 100644 --- a/src/artifacts/EtherToken.json +++ b/src/artifacts/EtherToken.json @@ -391,4 +391,4 @@ }, "schema_version": "0.0.5", "updated_at": 1503318938233 -} \ No newline at end of file +} diff --git a/src/contract.ts b/src/contract.ts index b4a54ca09..0c76571cc 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -2,27 +2,37 @@ import * as Web3 from 'web3'; import * as _ from 'lodash'; import promisify = require('es6-promisify'); -export class Contract implements Web3.ContractInstance { +export class Contract implements Web3.ContractInstance { public address: string; public abi: Web3.ContractAbi; - private contract: A; + private contract: Web3.ContractInstance; [name: string]: any; - constructor(web3ContractInstance: A) { + constructor(web3ContractInstance: Web3.ContractInstance) { this.contract = web3ContractInstance; this.address = web3ContractInstance.address; this.abi = web3ContractInstance.abi; + this.populateEvents(); + this.populateFunctions(); + } + private populateFunctions(): void { const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { - const cbStyleFunction = web3ContractInstance[functionAbi.name]; - this[functionAbi.name] = promisify(cbStyleFunction, web3ContractInstance); + const cbStyleFunction = this.contract[functionAbi.name]; + this[functionAbi.name] = promisify(cbStyleFunction, this.contract); if (functionAbi.constant) { - const cbStyleCallFunction = web3ContractInstance[functionAbi.name].call; - this[functionAbi.name].call = promisify(cbStyleCallFunction, web3ContractInstance); + const cbStyleCallFunction = this.contract[functionAbi.name].call; + this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract); } else { - const cbStyleEstimateGasFunction = web3ContractInstance[functionAbi.name].estimateGas; + const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas; this[functionAbi.name].estimateGas = - promisify(cbStyleEstimateGasFunction, web3ContractInstance); + promisify(cbStyleEstimateGasFunction, this.contract); } }); } + private populateEvents(): void { + const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === 'event'); + _.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => { + this[eventAbi.name] = this.contract[eventAbi.name]; + }); + } } diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 28df82cee..3de26148f 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; -import contract = require('truffle-contract'); +import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; -import {ZeroExError, Artifact, ContractInstance} from '../types'; +import {ZeroExError} from '../types'; import {utils} from '../utils/utils'; export class ContractWrapper { @@ -11,43 +11,10 @@ export class ContractWrapper { this._web3Wrapper = web3Wrapper; this._gasPrice = gasPrice; } - protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise { - const c = await contract(artifact); - c.defaults({ - gasPrice: this._gasPrice, - }); - const providerObj = this._web3Wrapper.getCurrentProvider(); - c.setProvider(providerObj); - - const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ? - undefined : - artifact.networks[networkIdIfExists]; - let contractAddress; - if (!_.isUndefined(address)) { - contractAddress = address; - } else if (!_.isUndefined(artifactNetworkConfigs)) { - contractAddress = artifactNetworkConfigs.address.toLowerCase(); - } - - if (!_.isUndefined(contractAddress)) { - const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress); - if (!doesContractExist) { - throw new Error(ZeroExError.ContractDoesNotExist); - } - } - - try { - const contractInstance = _.isUndefined(address) ? await c.deployed() : await c.at(address); - return contractInstance; - } catch (err) { - const errMsg = `${err}`; - if (_.includes(errMsg, 'not been deployed to detected network')) { - throw new Error(ZeroExError.ContractDoesNotExist); - } else { - utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`); - throw new Error(ZeroExError.UnhandledError); - } - } + protected async _instantiateContractIfExistsAsync(artifact: Artifact, + address?: string): Promise { + const contractInstance = + await this._web3Wrapper.getContractInstanceFromArtifactAsync(artifact, address); + return contractInstance; } } diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index 3c282510f..a2486b15e 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -71,7 +71,9 @@ export class EtherTokenWrapper extends ContractWrapper { if (!_.isUndefined(this._etherTokenContractIfExists)) { return this._etherTokenContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync((EtherTokenArtifacts as any)); + const contractInstance = await this._instantiateContractIfExistsAsync( + EtherTokenArtifacts as any as Artifact, + ); this._etherTokenContractIfExists = contractInstance as EtherTokenContract; return this._etherTokenContractIfExists; } diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index d09df236b..1196394e9 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -141,12 +141,12 @@ export class ExchangeWrapper extends ContractWrapper { * @param takerAddress The user Ethereum address who would like to fill this order. * Must be available via the supplied Web3.Provider * passed to 0x.js. - * @return The amount of the order that was filled (in taker token baseUnits). + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async fillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, - takerAddress: string): Promise { + takerAddress: string): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount); assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance); @@ -169,7 +169,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.fillOrder( + const txHash: string = await exchangeInstance.fillOrder( orderAddresses, orderValues, fillTakerTokenAmount, @@ -182,10 +182,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); - const logFillArgs = response.logs[0].args as LogFillContractEventArgs; - const filledTakerTokenAmount = new BigNumber(logFillArgs.filledTakerTokenAmount); - return filledTakerTokenAmount; + return txHash; } /** * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. @@ -201,12 +198,12 @@ export class ExchangeWrapper extends ContractWrapper { * @param takerAddress The user Ethereum address who would like to fill these * orders. Must be available via the supplied Web3.Provider * passed to 0x.js. - * @return The amount of the orders that was filled (in taker token baseUnits). + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async fillOrdersUpToAsync(signedOrders: SignedOrder[], fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, - takerAddress: string): Promise { + takerAddress: string): Promise { assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema); const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress); assert.hasAtMostOneUniqueValue(takerTokenAddresses, @@ -222,7 +219,7 @@ export class ExchangeWrapper extends ContractWrapper { signedOrder, fillTakerTokenAmount, takerAddress); } if (_.isEmpty(signedOrders)) { - return new BigNumber(0); // no-op + throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); } const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => { @@ -251,7 +248,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.fillOrdersUpTo( + const txHash = await exchangeInstance.fillOrdersUpTo( orderAddressesArray, orderValuesArray, fillTakerTokenAmount, @@ -264,13 +261,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); - let filledTakerTokenAmount = new BigNumber(0); - _.each(response.logs, log => { - filledTakerTokenAmount = filledTakerTokenAmount.plus( - (log.args as LogFillContractEventArgs).filledTakerTokenAmount); - }); - return filledTakerTokenAmount; + return txHash; } /** * Batch version of fillOrderAsync. @@ -288,11 +279,12 @@ export class ExchangeWrapper extends ContractWrapper { * @param takerAddress The user Ethereum address who would like to fill * these orders. Must be available via the supplied * Web3.Provider passed to 0x.js. + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async batchFillOrdersAsync(orderFillRequests: OrderFillRequest[], shouldThrowOnInsufficientBalanceOrAllowance: boolean, - takerAddress: string): Promise { + takerAddress: string): Promise { assert.doesConformToSchema('orderFillRequests', orderFillRequests, schemas.orderFillRequestsSchema); const exchangeContractAddresses = _.map( orderFillRequests, @@ -307,7 +299,7 @@ export class ExchangeWrapper extends ContractWrapper { orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } if (_.isEmpty(orderFillRequests)) { - return; // no-op + throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); } const orderAddressesValuesAmountsAndSignatureArray = _.map(orderFillRequests, orderFillRequest => { @@ -337,7 +329,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.batchFillOrders( + const txHash = await exchangeInstance.batchFillOrders( orderAddressesArray, orderValuesArray, fillTakerTokenAmounts, @@ -350,7 +342,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); + return txHash; } /** * Attempts to fill a specific amount of an order. If the entire amount specified cannot be filled, @@ -360,10 +352,11 @@ export class ExchangeWrapper extends ContractWrapper { * @param fillTakerTokenAmount The total amount of the takerTokens you would like to fill. * @param takerAddress The user Ethereum address who would like to fill this order. * Must be available via the supplied Web3.Provider passed to 0x.js. + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async fillOrKillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber.BigNumber, - takerAddress: string): Promise { + takerAddress: string): Promise { assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema); assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount); await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); @@ -385,7 +378,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.fillOrKillOrder( + const txHash = await exchangeInstance.fillOrKillOrder( orderAddresses, orderValues, fillTakerTokenAmount, @@ -397,7 +390,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); + return txHash; } /** * Batch version of fillOrKill. Allows a taker to specify a batch of orders that will either be atomically @@ -405,10 +398,11 @@ export class ExchangeWrapper extends ContractWrapper { * @param orderFillOrKillRequests An array of objects that conform to the OrderFillOrKillRequest interface. * @param takerAddress The user Ethereum address who would like to fill there orders. * Must be available via the supplied Web3.Provider passed to 0x.js. + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async batchFillOrKillAsync(orderFillOrKillRequests: OrderFillOrKillRequest[], - takerAddress: string): Promise { + takerAddress: string): Promise { assert.doesConformToSchema('orderFillOrKillRequests', orderFillOrKillRequests, schemas.orderFillOrKillRequestsSchema); const exchangeContractAddresses = _.map( @@ -419,7 +413,7 @@ export class ExchangeWrapper extends ContractWrapper { ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress); await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); if (_.isEmpty(orderFillOrKillRequests)) { - return; // no-op + throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); } const exchangeInstance = await this._getExchangeContractAsync(); for (const request of orderFillOrKillRequests) { @@ -452,7 +446,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.batchFillOrKillOrders( + const txHash = await exchangeInstance.batchFillOrKillOrders( orderAddresses, orderValues, fillTakerTokenAmounts, @@ -464,18 +458,18 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); + return txHash; } /** * Cancel a given fill amount of an order. Cancellations are cumulative. * @param order An object that conforms to the Order or SignedOrder interface. * The order you would like to cancel. * @param cancelTakerTokenAmount The amount (specified in taker tokens) that you would like to cancel. - * @return The amount of the order that was cancelled (in taker token baseUnits). + * @return Transaction hash. */ @decorators.contractCallErrorHandler public async cancelOrderAsync( - order: Order|SignedOrder, cancelTakerTokenAmount: BigNumber.BigNumber): Promise { + order: Order|SignedOrder, cancelTakerTokenAmount: BigNumber.BigNumber): Promise { assert.doesConformToSchema('order', order, schemas.orderSchema); assert.isBigNumber('takerTokenCancelAmount', cancelTakerTokenAmount); await assert.isSenderAddressAsync('order.maker', order.maker, this._web3Wrapper); @@ -492,7 +486,7 @@ export class ExchangeWrapper extends ContractWrapper { from: order.maker, }, ); - const response: ContractResponse = await exchangeInstance.cancelOrder( + const txHash = await exchangeInstance.cancelOrder( orderAddresses, orderValues, cancelTakerTokenAmount, @@ -501,19 +495,17 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); - const logFillArgs = response.logs[0].args as LogCancelContractEventArgs; - const cancelledTakerTokenAmount = new BigNumber(logFillArgs.cancelledTakerTokenAmount); - return cancelledTakerTokenAmount; + return txHash; } /** * Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction. * All orders must be from the same maker. * @param orderCancellationRequests An array of objects that conform to the OrderCancellationRequest * interface. + * @return Transaction hash. */ @decorators.contractCallErrorHandler - public async batchCancelOrdersAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise { + public async batchCancelOrdersAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise { assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests, schemas.orderCancellationRequestsSchema); const exchangeContractAddresses = _.map( @@ -532,7 +524,7 @@ export class ExchangeWrapper extends ContractWrapper { ); } if (_.isEmpty(orderCancellationRequests)) { - return; // no-op + throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem); } const exchangeInstance = await this._getExchangeContractAsync(); const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => { @@ -552,7 +544,7 @@ export class ExchangeWrapper extends ContractWrapper { from: maker, }, ); - const response: ContractResponse = await exchangeInstance.batchCancelOrders( + const txHash = await exchangeInstance.batchCancelOrders( orderAddresses, orderValues, cancelTakerTokenAmounts, @@ -561,7 +553,7 @@ export class ExchangeWrapper extends ContractWrapper { gas, }, ); - this._throwErrorLogsAsErrors(response.logs); + return txHash; } /** * Subscribe to an event type emitted by the Exchange smart contract @@ -730,7 +722,9 @@ export class ExchangeWrapper extends ContractWrapper { if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any)); + const contractInstance = await this._instantiateContractIfExistsAsync( + (ExchangeArtifacts as any), + ); this._exchangeContractIfExists = contractInstance as ExchangeContract; return this._exchangeContractIfExists; } diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 822e69460..1550bfa3e 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -101,7 +101,9 @@ export class TokenRegistryWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenRegistryContractIfExists)) { return this._tokenRegistryContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); + const contractInstance = await this._instantiateContractIfExistsAsync( + TokenRegistryArtifacts as any as Artifact, + ); this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; return this._tokenRegistryContractIfExists; } diff --git a/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/src/contract_wrappers/token_transfer_proxy_wrapper.ts index da17d79ff..2b4b32961 100644 --- a/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -44,7 +44,9 @@ export class TokenTransferProxyWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) { return this._tokenTransferProxyContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync((TokenTransferProxyArtifacts as any)); + const contractInstance = await this._instantiateContractIfExistsAsync( + TokenTransferProxyArtifacts as any as Artifact, + ); this._tokenTransferProxyContractIfExists = contractInstance as TokenTransferProxyContract; return this._tokenTransferProxyContractIfExists; } diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index f7070f1f4..e98744cbc 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -267,7 +267,9 @@ export class TokenWrapper extends ContractWrapper { if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this._instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); + const contractInstance = await this._instantiateContractIfExistsAsync( + TokenArtifacts as any as Artifact, tokenAddress, + ); tokenContract = contractInstance as TokenContract; this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; diff --git a/src/globals.d.ts b/src/globals.d.ts index 9230ab02d..6f5f13b4e 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -33,23 +33,11 @@ declare module '*.json' { /* tslint:enable */ } -// truffle-contract declarations -declare interface ContractInstance { - address: string; -} -declare interface ContractFactory { - setProvider: (providerObj: any) => void; - deployed: () => ContractInstance; - // Both any's are Web3.CallData, but I was unable to import it in this file - defaults: (config: any) => any; - at: (address: string) => ContractInstance; -} declare interface Artifact { - networks: {[networkId: number]: any}; -} -declare function contract(artifacts: Artifact): ContractFactory; -declare module 'truffle-contract' { - export = contract; + abi: any; + networks: {[networkId: number]: { + address: string; + }}; } // find-version declarations diff --git a/src/types.ts b/src/types.ts index 2400a9a60..9f8ba9729 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,6 +14,7 @@ export enum ZeroExError { InsufficientWEthBalanceForWithdrawal = 'INSUFFICIENT_WETH_BALANCE_FOR_WITHDRAWAL', InvalidJump = 'INVALID_JUMP', OutOfGas = 'OUT_OF_GAS', + NoNetworkId = 'NO_NETWORK_ID', } /** @@ -60,7 +61,7 @@ export interface ExchangeContract extends ContractInstance { fillOrder: { (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number, r: string, s: string, txOpts?: TxOpts): Promise; + v: number, r: string, s: string, txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, @@ -69,7 +70,7 @@ export interface ExchangeContract extends ContractInstance { batchFillOrders: { (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; + v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], shouldThrowOnInsufficientBalanceOrAllowance: boolean, @@ -78,7 +79,7 @@ export interface ExchangeContract extends ContractInstance { fillOrdersUpTo: { (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; + v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmount: BigNumber.BigNumber, shouldThrowOnInsufficientBalanceOrAllowance: boolean, @@ -86,28 +87,28 @@ export interface ExchangeContract extends ContractInstance { }; cancelOrder: { (orderAddresses: OrderAddresses, orderValues: OrderValues, cancelTakerTokenAmount: BigNumber.BigNumber, - txOpts?: TxOpts): Promise; + txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, cancelTakerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; }; batchCancelOrders: { (orderAddresses: OrderAddresses[], orderValues: OrderValues[], cancelTakerTokenAmounts: BigNumber.BigNumber[], - txOpts?: TxOpts): Promise; + txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], cancelTakerTokenAmounts: BigNumber.BigNumber[], txOpts?: TxOpts) => Promise; }; fillOrKillOrder: { (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, - v: number, r: string, s: string, txOpts?: TxOpts): Promise; + v: number, r: string, s: string, txOpts?: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, v: number, r: string, s: string, txOpts?: TxOpts) => Promise; }; batchFillOrKillOrders: { (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], - v: number[], r: string[], s: string[], txOpts: TxOpts): Promise; + v: number[], r: string[], s: string[], txOpts: TxOpts): Promise; estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; @@ -209,6 +210,7 @@ export enum ExchangeContractErrs { InsufficientRemainingFillAmount = 'INSUFFICIENT_REMAINING_FILL_AMOUNT', MultipleTakerTokensInFillUpToDisallowed = 'MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED', BatchOrdersMustHaveSameExchangeAddress = 'BATCH_ORDERS_MUST_HAVE_SAME_EXCHANGE_ADDRESS', + BatchOrdersMustHaveAtLeastOneItem = 'BATCH_ORDERS_MUST_HAVE_AT_LEAST_ONE_ITEM', } export interface ContractResponse { @@ -351,10 +353,7 @@ export type AsyncMethod = (...args: any[]) => Promise; export interface ContractInstance { address: string; -} - -export interface Artifact { - networks: {[networkId: number]: any}; + abi: Web3.ContractAbi; } export interface ContractEventEmitter { @@ -373,14 +372,6 @@ export interface ExchangeContractByAddress { [address: string]: ExchangeContract; } -export interface ContractArtifact { - networks: { - [networkId: number]: { - address: string; - }; - }; -} - export interface JSONRPCPayload { params: any[]; method: string; diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 61bac45c9..129017e7c 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -2,6 +2,8 @@ import * as _ from 'lodash'; import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); +import {ZeroExError} from './types'; +import {Contract} from './contract'; export class Web3Wrapper { private web3: Web3; @@ -41,6 +43,27 @@ export class Web3Wrapper { return undefined; } } + public async getContractInstanceFromArtifactAsync(artifact: Artifact, + address?: string): Promise { + if (_.isUndefined(address)) { + const networkIdIfExists = await this.getNetworkIdIfExistsAsync(); + if (_.isUndefined(networkIdIfExists)) { + throw new Error(ZeroExError.NoNetworkId); + } + if (_.isUndefined(artifact.networks[networkIdIfExists])) { + throw new Error(ZeroExError.ContractNotDeployedOnNetwork); + } + address = artifact.networks[networkIdIfExists].address.toLowerCase(); + } + const doesContractExist = await this.doesContractExistAtAddressAsync(address); + if (!doesContractExist) { + throw new Error(ZeroExError.ContractDoesNotExist); + } + const contractInstance = this.getContractInstance( + artifact.abi, address, + ); + return contractInstance; + } public toWei(ethAmount: BigNumber.BigNumber): BigNumber.BigNumber { const balanceWei = this.web3.toWei(ethAmount, 'ether'); return balanceWei; @@ -68,6 +91,11 @@ export class Web3Wrapper { const addresses: string[] = await promisify(this.web3.eth.getAccounts)(); return addresses; } + private getContractInstance(abi: Web3.ContractAbi, address: string): A { + const web3ContractInstance = this.web3.eth.contract(abi).at(address); + const contractInstance = new Contract(web3ContractInstance) as any as A; + return contractInstance; + } private async getNetworkAsync(): Promise { const networkId = await promisify(this.web3.version.getNetwork)(); return networkId; -- cgit v1.2.3 From 2577d8f66267e618e633483277f1afe828764797 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 18:23:12 +0200 Subject: Use Web3.ContractInstance type --- src/types.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/types.ts b/src/types.ts index 9f8ba9729..e90c6fab4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -40,7 +40,7 @@ export interface ContractEventObj { } export type CreateContractEvent = (indexFilterValues: IndexedFilterValues, subscriptionOpts: SubscriptionOpts) => ContractEventObj; -export interface ExchangeContract extends ContractInstance { +export interface ExchangeContract extends Web3.ContractInstance { isValidSignature: { call: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string, txOpts?: TxOpts) => Promise; @@ -124,7 +124,7 @@ export interface ExchangeContract extends ContractInstance { }; } -export interface TokenContract extends ContractInstance { +export interface TokenContract extends Web3.ContractInstance { Transfer: CreateContractEvent; Approval: CreateContractEvent; balanceOf: { @@ -139,7 +139,7 @@ export interface TokenContract extends ContractInstance { approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; } -export interface TokenRegistryContract extends ContractInstance { +export interface TokenRegistryContract extends Web3.ContractInstance { getTokenMetaData: { call: (address: string) => Promise; }; @@ -160,12 +160,12 @@ export interface TokenRegistryContract extends ContractInstance { }; } -export interface EtherTokenContract extends ContractInstance { +export interface EtherTokenContract extends Web3.ContractInstance { deposit: (txOpts: TxOpts) => Promise; withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise; } -export interface TokenTransferProxyContract extends ContractInstance { +export interface TokenTransferProxyContract extends Web3.ContractInstance { getAuthorizedAddresses: { call: () => Promise; }; @@ -213,10 +213,6 @@ export enum ExchangeContractErrs { BatchOrdersMustHaveAtLeastOneItem = 'BATCH_ORDERS_MUST_HAVE_AT_LEAST_ONE_ITEM', } -export interface ContractResponse { - logs: ContractEvent[]; -} - export interface ContractEvent { logIndex: number; transactionIndex: number; @@ -351,11 +347,6 @@ export interface OrderFillRequest { export type AsyncMethod = (...args: any[]) => Promise; -export interface ContractInstance { - address: string; - abi: Web3.ContractAbi; -} - export interface ContractEventEmitter { watch: (eventCallback: EventCallback) => void; stopWatchingAsync: () => Promise; -- cgit v1.2.3 From c9e490bdaec53e3a93b5da8daaaf0b1d87d9de76 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 4 Sep 2017 19:08:14 +0200 Subject: Implement zeroEx.awaitTransactionMined --- src/0x.ts | 14 ++++++++++++++ src/web3_wrapper.ts | 4 ++++ 2 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index 3cf672a1b..e92c92e1f 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -1,5 +1,6 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; +import * as Web3 from 'web3'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -248,4 +249,17 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } + public async awaitTransactionMined(txHash: string, + pollingIntervalMs: number = 500): Promise { + const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { + const intervalId = setInterval(async () => { + const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + clearInterval(intervalId); + resolve(transactionReceipt); + } + }, pollingIntervalMs); + }); + return txReceiptPromise; + } } diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 129017e7c..f3fe8a00b 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -27,6 +27,10 @@ export class Web3Wrapper { const nodeVersion = await promisify(this.web3.version.getNode)(); return nodeVersion; } + public async getTransactionReceiptAsync(txHash: string): Promise { + const transactionReceipt = await promisify(this.web3.eth.getTransactionReceipt)(txHash); + return transactionReceipt; + } public getCurrentProvider(): Web3.Provider { return this.web3.currentProvider; } -- cgit v1.2.3 From 2b547f94a44dfed029b5559b743344d5998fa3bc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 10:07:16 +0200 Subject: Change non-exhange contracts to also return txHash --- src/0x.ts | 4 +-- src/contract_wrappers/ether_token_wrapper.ts | 12 +++++--- src/contract_wrappers/exchange_wrapper.ts | 1 - src/contract_wrappers/token_wrapper.ts | 43 +++++++++++++++++++--------- src/types.ts | 10 +++---- 5 files changed, 44 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index e92c92e1f..4a1d605a2 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -249,8 +249,8 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } - public async awaitTransactionMined(txHash: string, - pollingIntervalMs: number = 500): Promise { + public async awaitTransactionMinedAsync(txHash: string, + pollingIntervalMs: number = 500): Promise { const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index a2486b15e..ba0cd05d8 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -23,8 +23,9 @@ export class EtherTokenWrapper extends ContractWrapper { * for ETH. * @param amountInWei Amount of ETH in Wei the caller wishes to deposit. * @param depositor The hex encoded user Ethereum address that would like to make the deposit. + * @return Transaction hash. */ - public async depositAsync(amountInWei: BigNumber.BigNumber, depositor: string): Promise { + public async depositAsync(amountInWei: BigNumber.BigNumber, depositor: string): Promise { assert.isBigNumber('amountInWei', amountInWei); await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper); @@ -32,18 +33,20 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit); const wethContract = await this._getEtherTokenContractAsync(); - await wethContract.deposit({ + const txHash = await wethContract.deposit({ from: depositor, value: amountInWei, }); + return txHash; } /** * Withdraw ETH to the withdrawer's address from the wrapped ETH smart contract in exchange for the * equivalent number of wrapped ETH tokens. * @param amountInWei Amount of ETH in Wei the caller wishes to withdraw. * @param withdrawer The hex encoded user Ethereum address that would like to make the withdrawl. + * @return Transaction hash. */ - public async withdrawAsync(amountInWei: BigNumber.BigNumber, withdrawer: string): Promise { + public async withdrawAsync(amountInWei: BigNumber.BigNumber, withdrawer: string): Promise { assert.isBigNumber('amountInWei', amountInWei); await assert.isSenderAddressAsync('withdrawer', withdrawer, this._web3Wrapper); @@ -52,9 +55,10 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal); const wethContract = await this._getEtherTokenContractAsync(); - await wethContract.withdraw(amountInWei, { + const txHash = await wethContract.withdraw(amountInWei, { from: withdrawer, }); + return txHash; } /** * Retrieves the Wrapped Ether token contract address diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 1196394e9..3b94bb22c 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -21,7 +21,6 @@ import { IndexedFilterValues, CreateContractEvent, ContractEventObj, - ContractResponse, OrderCancellationRequest, OrderFillRequest, LogErrorContractEventArgs, diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index e98744cbc..9c72455f1 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -60,9 +60,10 @@ export class TokenWrapper extends ContractWrapper { * for spenderAddress. * @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance. * @param amountInBaseUnits The allowance amount you would like to set. + * @return Transaction hash. */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise { + amountInBaseUnits: BigNumber.BigNumber): Promise { await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper); assert.isETHAddressHex('spenderAddress', spenderAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -74,10 +75,11 @@ export class TokenWrapper extends ContractWrapper { // TODO: Debug issue in testrpc and submit a PR, then remove this hack const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; - await tokenContract.approve(spenderAddress, amountInBaseUnits, { + const txHash = await tokenContract.approve(spenderAddress, amountInBaseUnits, { from: ownerAddress, gas, }); + return txHash; } /** * Sets the spender's allowance to an unlimited number of baseUnits on behalf of the owner address. @@ -88,12 +90,14 @@ export class TokenWrapper extends ContractWrapper { * @param ownerAddress The hex encoded user Ethereum address who would like to set an allowance * for spenderAddress. * @param spenderAddress The hex encoded user Ethereum address who will be able to spend the set allowance. + * @return Transaction hash. */ public async setUnlimitedAllowanceAsync(tokenAddress: string, ownerAddress: string, - spenderAddress: string): Promise { - await this.setAllowanceAsync( + spenderAddress: string): Promise { + const txHash = await this.setAllowanceAsync( tokenAddress, ownerAddress, spenderAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, ); + return txHash; } /** * Retrieves the owners allowance in baseUnits set to the spender's address. @@ -102,7 +106,8 @@ export class TokenWrapper extends ContractWrapper { * you would like to retrieve. * @param spenderAddress The hex encoded user Ethereum address who can spend the allowance you are fetching. */ - public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { + public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, + spenderAddress: string): Promise { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -117,7 +122,7 @@ export class TokenWrapper extends ContractWrapper { * @param tokenAddress The hex encoded contract Ethereum address where the ERC20 token is deployed. * @param ownerAddress The hex encoded user Ethereum address whose proxy contract allowance we are retrieving. */ - public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string) { + public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); @@ -132,15 +137,17 @@ export class TokenWrapper extends ContractWrapper { * @param ownerAddress The hex encoded user Ethereum address who is setting an allowance * for the Proxy contract. * @param amountInBaseUnits The allowance amount specified in baseUnits. + * @return Transaction hash. */ public async setProxyAllowanceAsync(tokenAddress: string, ownerAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise { + amountInBaseUnits: BigNumber.BigNumber): Promise { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); const proxyAddress = await this._getProxyAddressAsync(); - await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); + const txHash = await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); + return txHash; } /** * Sets the 0x proxy contract's allowance to a unlimited number of a tokens' baseUnits on behalf @@ -150,9 +157,13 @@ export class TokenWrapper extends ContractWrapper { * @param tokenAddress The hex encoded contract Ethereum address where the ERC20 token is deployed. * @param ownerAddress The hex encoded user Ethereum address who is setting an allowance * for the Proxy contract. + * @return Transaction hash. */ - public async setUnlimitedProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise { - await this.setProxyAllowanceAsync(tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + public async setUnlimitedProxyAllowanceAsync(tokenAddress: string, ownerAddress: string): Promise { + const txHash = await this.setProxyAllowanceAsync( + tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, + ); + return txHash; } /** * Transfers `amountInBaseUnits` ERC20 tokens from `fromAddress` to `toAddress`. @@ -160,9 +171,10 @@ export class TokenWrapper extends ContractWrapper { * @param fromAddress The hex encoded user Ethereum address that will send the funds. * @param toAddress The hex encoded user Ethereum address that will receive the funds. * @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer. + * @return Transaction hash. */ public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, - amountInBaseUnits: BigNumber.BigNumber): Promise { + amountInBaseUnits: BigNumber.BigNumber): Promise { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper); assert.isETHAddressHex('toAddress', toAddress); @@ -175,9 +187,10 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - await tokenContract.transfer(toAddress, amountInBaseUnits, { + const txHash = await tokenContract.transfer(toAddress, amountInBaseUnits, { from: fromAddress, }); + return txHash; } /** * Transfers `amountInBaseUnits` ERC20 tokens from `fromAddress` to `toAddress`. @@ -190,10 +203,11 @@ export class TokenWrapper extends ContractWrapper { * `fromAddress` must have set an allowance to the `senderAddress` * before this call. * @param amountInBaseUnits The amount (specified in baseUnits) of the token to transfer. + * @return Transaction hash. */ public async transferFromAsync(tokenAddress: string, fromAddress: string, toAddress: string, senderAddress: string, amountInBaseUnits: BigNumber.BigNumber): - Promise { + Promise { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('fromAddress', fromAddress); assert.isETHAddressHex('toAddress', toAddress); @@ -212,9 +226,10 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { + const txHash = await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { from: senderAddress, }); + return txHash; } /** * Subscribe to an event type emitted by the Token contract. diff --git a/src/types.ts b/src/types.ts index e90c6fab4..1aabe6e4f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -133,10 +133,10 @@ export interface TokenContract extends Web3.ContractInstance { allowance: { call: (ownerAddress: string, allowedAddress: string) => Promise; }; - transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; + transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; transferFrom: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber, - txOpts?: TxOpts) => Promise; - approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; + txOpts?: TxOpts) => Promise; + approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; } export interface TokenRegistryContract extends Web3.ContractInstance { @@ -161,8 +161,8 @@ export interface TokenRegistryContract extends Web3.ContractInstance { } export interface EtherTokenContract extends Web3.ContractInstance { - deposit: (txOpts: TxOpts) => Promise; - withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise; + deposit: (txOpts: TxOpts) => Promise; + withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise; } export interface TokenTransferProxyContract extends Web3.ContractInstance { -- cgit v1.2.3 From 96d2a55effa6666c1b8d90594ca5607dcc1bce8e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 10:29:51 +0200 Subject: Add TransationReceipt as a public exported type --- src/0x.ts | 12 +++++++++--- src/index.ts | 1 + src/types.ts | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index 4a1d605a2..86976c4ab 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -16,7 +16,7 @@ import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper'; -import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig} from './types'; +import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig, TransactionReceipt} from './types'; // Customize our BigNumber instances bigNumberConfigs.configure(); @@ -249,9 +249,15 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } + /** + * Waits for transaction to be mined and returns the transaction receipt + * @param txHash Transaction hash + * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. + * @return Web3.TransactionReceipt + */ public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 500): Promise { - const txReceiptPromise = new Promise((resolve: (receipt: Web3.TransactionReceipt) => void, reject) => { + pollingIntervalMs: number = 500): Promise { + const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { diff --git a/src/index.ts b/src/index.ts index 6d6e4484c..44bd53547 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,4 +30,5 @@ export { ContractEventArgs, Web3Provider, ZeroExConfig, + TransactionReceipt, } from './types'; diff --git a/src/types.ts b/src/types.ts index 1aabe6e4f..b65ffda73 100644 --- a/src/types.ts +++ b/src/types.ts @@ -371,3 +371,5 @@ export interface JSONRPCPayload { export interface ZeroExConfig { gasPrice?: BigNumber.BigNumber; // Gas price to use with every transaction } + +export type TransactionReceipt = Web3.TransactionReceipt; -- cgit v1.2.3 From a12df1c73a97b3ba18ab53c1b25be39b837f6240 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 11:38:28 +0200 Subject: Fix gasPrice regression --- src/0x.ts | 15 ++++++----- src/contract.ts | 34 +++++++++++++++++++++++-- src/contract_wrappers/contract_wrapper.ts | 4 +-- src/contract_wrappers/ether_token_wrapper.ts | 4 +-- src/contract_wrappers/exchange_wrapper.ts | 4 +-- src/contract_wrappers/token_registry_wrapper.ts | 4 +-- src/contract_wrappers/token_wrapper.ts | 4 +-- src/web3_wrapper.ts | 6 +++-- 8 files changed, 54 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index 86976c4ab..fd7d9b5a5 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -170,13 +170,16 @@ export class ZeroEx { // We re-assign the send method so that Web3@1.0 providers work with 0x.js (provider as any).sendAsync = (provider as any).send; } - this._web3Wrapper = new Web3Wrapper(provider); const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice; - this.token = new TokenWrapper(this._web3Wrapper, gasPrice); - this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper, gasPrice); - this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token, gasPrice); - this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper, gasPrice); - this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token, gasPrice); + const defaults = { + gasPrice, + }; + this._web3Wrapper = new Web3Wrapper(provider, defaults); + this.token = new TokenWrapper(this._web3Wrapper); + this.proxy = new TokenTransferProxyWrapper(this._web3Wrapper); + this.exchange = new ExchangeWrapper(this._web3Wrapper, this.token); + this.tokenRegistry = new TokenRegistryWrapper(this._web3Wrapper); + this.etherToken = new EtherTokenWrapper(this._web3Wrapper, this.token); } /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all diff --git a/src/contract.ts b/src/contract.ts index 0c76571cc..3592e0e71 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -6,11 +6,13 @@ export class Contract implements Web3.ContractInstance { public address: string; public abi: Web3.ContractAbi; private contract: Web3.ContractInstance; + private defaults: Partial; [name: string]: any; - constructor(web3ContractInstance: Web3.ContractInstance) { + constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial) { this.contract = web3ContractInstance; this.address = web3ContractInstance.address; this.abi = web3ContractInstance.abi; + this.defaults = defaults; this.populateEvents(); this.populateFunctions(); } @@ -18,11 +20,12 @@ export class Contract implements Web3.ContractInstance { const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { const cbStyleFunction = this.contract[functionAbi.name]; - this[functionAbi.name] = promisify(cbStyleFunction, this.contract); if (functionAbi.constant) { + this[functionAbi.name] = promisify(cbStyleFunction, this.contract); const cbStyleCallFunction = this.contract[functionAbi.name].call; this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract); } else { + this[functionAbi.name] = this.promisifyWithDefaultParams(cbStyleFunction); const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas; this[functionAbi.name].estimateGas = promisify(cbStyleEstimateGasFunction, this.contract); @@ -35,4 +38,31 @@ export class Contract implements Web3.ContractInstance { this[eventAbi.name] = this.contract[eventAbi.name]; }); } + private promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise { + const promisifiedWithDefaultParams = (...args: any[]) => { + const promise = new Promise((resolve, reject) => { + const lastArg = args[args.length - 1]; + let txData: Partial = {}; + if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) { + txData = args.pop(); + } + txData = { + ...txData, + ...this.defaults, + }; + 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; + } } diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index 3de26148f..ca19342f3 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -6,10 +6,8 @@ import {utils} from '../utils/utils'; export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; - private _gasPrice?: BigNumber.BigNumber; - constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) { + constructor(web3Wrapper: Web3Wrapper) { this._web3Wrapper = web3Wrapper; - this._gasPrice = gasPrice; } protected async _instantiateContractIfExistsAsync(artifact: Artifact, address?: string): Promise { diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index ba0cd05d8..4c19b3caa 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -13,8 +13,8 @@ import * as EtherTokenArtifacts from '../artifacts/EtherToken.json'; export class EtherTokenWrapper extends ContractWrapper { private _etherTokenContractIfExists?: EtherTokenContract; private _tokenWrapper: TokenWrapper; - constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) { - super(web3Wrapper, gasPrice); + constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) { + super(web3Wrapper); this._tokenWrapper = tokenWrapper; } /** diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 3b94bb22c..324c92062 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -72,8 +72,8 @@ export class ExchangeWrapper extends ContractWrapper { ]; return [orderAddresses, orderValues]; } - constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper, gasPrice?: BigNumber.BigNumber) { - super(web3Wrapper, gasPrice); + constructor(web3Wrapper: Web3Wrapper, tokenWrapper: TokenWrapper) { + super(web3Wrapper); this._tokenWrapper = tokenWrapper; this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this); this._exchangeLogEventEmitters = []; diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 1550bfa3e..57c9ca93d 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -11,8 +11,8 @@ import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; */ export class TokenRegistryWrapper extends ContractWrapper { private _tokenRegistryContractIfExists?: TokenRegistryContract; - constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) { - super(web3Wrapper, gasPrice); + constructor(web3Wrapper: Web3Wrapper) { + super(web3Wrapper); } /** * Retrieves all the tokens currently listed in the Token Registry smart contract diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 9c72455f1..944f0fb42 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -31,8 +31,8 @@ export class TokenWrapper extends ContractWrapper { public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; private _tokenContractsByAddress: {[address: string]: TokenContract}; private _tokenLogEventEmitters: ContractEventEmitter[]; - constructor(web3Wrapper: Web3Wrapper, gasPrice?: BigNumber.BigNumber) { - super(web3Wrapper, gasPrice); + constructor(web3Wrapper: Web3Wrapper) { + super(web3Wrapper); this._tokenContractsByAddress = {}; this._tokenLogEventEmitters = []; } diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index f3fe8a00b..a0923bef9 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -7,10 +7,12 @@ import {Contract} from './contract'; export class Web3Wrapper { private web3: Web3; + private defaults: Partial; private networkIdIfExists?: number; - constructor(provider: Web3.Provider) { + constructor(provider: Web3.Provider, defaults: Partial) { this.web3 = new Web3(); this.web3.setProvider(provider); + this.defaults = defaults; } public setProvider(provider: Web3.Provider) { delete this.networkIdIfExists; @@ -97,7 +99,7 @@ export class Web3Wrapper { } private getContractInstance(abi: Web3.ContractAbi, address: string): A { const web3ContractInstance = this.web3.eth.contract(abi).at(address); - const contractInstance = new Contract(web3ContractInstance) as any as A; + const contractInstance = new Contract(web3ContractInstance, this.defaults) as any as A; return contractInstance; } private async getNetworkAsync(): Promise { -- cgit v1.2.3 From f6a945dfe4844d243ef67042b33e9ade2fc60308 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 12:52:00 +0200 Subject: Fix the comment at awaitTransactionMinedAsync --- src/0x.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index fd7d9b5a5..e1ba796c8 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -253,10 +253,10 @@ export class ZeroEx { throw new Error(ZeroExError.InvalidSignature); } /** - * Waits for transaction to be mined and returns the transaction receipt + * Waits for a transaction to be mined and returns the transaction receipt. * @param txHash Transaction hash * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. - * @return Web3.TransactionReceipt + * @return TransactionReceipt */ public async awaitTransactionMinedAsync(txHash: string, pollingIntervalMs: number = 500): Promise { -- cgit v1.2.3 From b5c6c9196290314a875f89b88178b1be4b0db7d0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 12:52:44 +0200 Subject: Increase the default polling interval to 1000 --- src/0x.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index e1ba796c8..209b2704d 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -259,7 +259,7 @@ export class ZeroEx { * @return TransactionReceipt */ public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 500): Promise { + pollingIntervalMs: number = 1000): Promise { const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); -- cgit v1.2.3 From e05dfab1fca9eb108848c98da9dbf671a59d17f3 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:14:27 +0200 Subject: Add explaining comment --- src/contract.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index 3592e0e71..ebda31e65 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -7,6 +7,8 @@ export class Contract implements Web3.ContractInstance { public abi: Web3.ContractAbi; private contract: Web3.ContractInstance; private defaults: Partial; + // 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; -- cgit v1.2.3 From 9f12ef61b0cc8bb295b4a2bbfdf24b41c1584da2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:43:46 +0200 Subject: Rename x.call -> x.callAsync x() -> x.sendTransactionAsync() x.estimateGas() -> x.estimateGasAsync() --- src/contract.ts | 14 +- src/contract_wrappers/ether_token_wrapper.ts | 4 +- src/contract_wrappers/exchange_wrapper.ts | 42 +++--- src/contract_wrappers/token_registry_wrapper.ts | 12 +- .../token_transfer_proxy_wrapper.ts | 4 +- src/contract_wrappers/token_wrapper.ts | 17 ++- src/types.ts | 149 ++++++++++++--------- 7 files changed, 132 insertions(+), 110 deletions(-) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index ebda31e65..9dfb04446 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -21,16 +21,18 @@ export class Contract implements Web3.ContractInstance { private populateFunctions(): void { const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { - const cbStyleFunction = this.contract[functionAbi.name]; if (functionAbi.constant) { - this[functionAbi.name] = promisify(cbStyleFunction, this.contract); const cbStyleCallFunction = this.contract[functionAbi.name].call; - this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract); + this[functionAbi.name] = { + callAsync: promisify(cbStyleCallFunction, this.contract), + }; } else { - this[functionAbi.name] = this.promisifyWithDefaultParams(cbStyleFunction); + const cbStyleFunction = this.contract[functionAbi.name]; const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas; - this[functionAbi.name].estimateGas = - promisify(cbStyleEstimateGasFunction, this.contract); + this[functionAbi.name] = { + estimateGasAsync: promisify(cbStyleEstimateGasFunction, this.contract), + sendTransactionAsync: this.promisifyWithDefaultParams(cbStyleFunction), + }; } }); } diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index 4c19b3caa..d31069b22 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -33,7 +33,7 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit); const wethContract = await this._getEtherTokenContractAsync(); - const txHash = await wethContract.deposit({ + const txHash = await wethContract.deposit.sendTransactionAsync({ from: depositor, value: amountInWei, }); @@ -55,7 +55,7 @@ export class EtherTokenWrapper extends ContractWrapper { assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal); const wethContract = await this._getEtherTokenContractAsync(); - const txHash = await wethContract.withdraw(amountInWei, { + const txHash = await wethContract.withdraw.sendTransactionAsync(amountInWei, { from: withdrawer, }); return txHash; diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 324c92062..fbb2c710f 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -90,7 +90,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const exchangeContract = await this._getExchangeContractAsync(); - let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.call(orderHash); + let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.callAsync(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber unavailableTakerTokenAmount = new BigNumber(unavailableTakerTokenAmount); return unavailableTakerTokenAmount; @@ -104,7 +104,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const exchangeContract = await this._getExchangeContractAsync(); - let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHash); + let fillAmountInBaseUnits = await exchangeContract.filled.callAsync(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); return fillAmountInBaseUnits; @@ -119,7 +119,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const exchangeContract = await this._getExchangeContractAsync(); - let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHash); + let cancelledAmountInBaseUnits = await exchangeContract.cancelled.callAsync(orderHash); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); return cancelledAmountInBaseUnits; @@ -156,7 +156,7 @@ export class ExchangeWrapper extends ContractWrapper { const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); - const gas = await exchangeInstance.fillOrder.estimateGas( + const gas = await exchangeInstance.fillOrder.estimateGasAsync( orderAddresses, orderValues, fillTakerTokenAmount, @@ -168,7 +168,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const txHash: string = await exchangeInstance.fillOrder( + const txHash: string = await exchangeInstance.fillOrder.sendTransactionAsync( orderAddresses, orderValues, fillTakerTokenAmount, @@ -235,7 +235,7 @@ export class ExchangeWrapper extends ContractWrapper { ); const exchangeInstance = await this._getExchangeContractAsync(); - const gas = await exchangeInstance.fillOrdersUpTo.estimateGas( + const gas = await exchangeInstance.fillOrdersUpTo.estimateGasAsync( orderAddressesArray, orderValuesArray, fillTakerTokenAmount, @@ -247,7 +247,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const txHash = await exchangeInstance.fillOrdersUpTo( + const txHash = await exchangeInstance.fillOrdersUpTo.sendTransactionAsync( orderAddressesArray, orderValuesArray, fillTakerTokenAmount, @@ -316,7 +316,7 @@ export class ExchangeWrapper extends ContractWrapper { ); const exchangeInstance = await this._getExchangeContractAsync(); - const gas = await exchangeInstance.batchFillOrders.estimateGas( + const gas = await exchangeInstance.batchFillOrders.estimateGasAsync( orderAddressesArray, orderValuesArray, fillTakerTokenAmounts, @@ -328,7 +328,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const txHash = await exchangeInstance.batchFillOrders( + const txHash = await exchangeInstance.batchFillOrders.sendTransactionAsync( orderAddressesArray, orderValuesArray, fillTakerTokenAmounts, @@ -366,7 +366,7 @@ export class ExchangeWrapper extends ContractWrapper { const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); - const gas = await exchangeInstance.fillOrKillOrder.estimateGas( + const gas = await exchangeInstance.fillOrKillOrder.estimateGasAsync( orderAddresses, orderValues, fillTakerTokenAmount, @@ -377,7 +377,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const txHash = await exchangeInstance.fillOrKillOrder( + const txHash = await exchangeInstance.fillOrKillOrder.sendTransactionAsync( orderAddresses, orderValues, fillTakerTokenAmount, @@ -434,7 +434,7 @@ export class ExchangeWrapper extends ContractWrapper { const [orderAddresses, orderValues, fillTakerTokenAmounts, vParams, rParams, sParams] = _.unzip(orderAddressesValuesAndTakerTokenFillAmounts); - const gas = await exchangeInstance.batchFillOrKillOrders.estimateGas( + const gas = await exchangeInstance.batchFillOrKillOrders.estimateGasAsync( orderAddresses, orderValues, fillTakerTokenAmounts, @@ -445,7 +445,7 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const txHash = await exchangeInstance.batchFillOrKillOrders( + const txHash = await exchangeInstance.batchFillOrKillOrders.sendTransactionAsync( orderAddresses, orderValues, fillTakerTokenAmounts, @@ -477,7 +477,7 @@ export class ExchangeWrapper extends ContractWrapper { await this.validateCancelOrderThrowIfInvalidAsync(order, cancelTakerTokenAmount); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); - const gas = await exchangeInstance.cancelOrder.estimateGas( + const gas = await exchangeInstance.cancelOrder.estimateGasAsync( orderAddresses, orderValues, cancelTakerTokenAmount, @@ -485,7 +485,7 @@ export class ExchangeWrapper extends ContractWrapper { from: order.maker, }, ); - const txHash = await exchangeInstance.cancelOrder( + const txHash = await exchangeInstance.cancelOrder.sendTransactionAsync( orderAddresses, orderValues, cancelTakerTokenAmount, @@ -535,7 +535,7 @@ export class ExchangeWrapper extends ContractWrapper { // We use _.unzip because _.unzip doesn't type check if values have different types :'( const [orderAddresses, orderValues, cancelTakerTokenAmounts] = _.unzip(orderAddressesValuesAndTakerTokenCancelAmounts); - const gas = await exchangeInstance.batchCancelOrders.estimateGas( + const gas = await exchangeInstance.batchCancelOrders.estimateGasAsync( orderAddresses, orderValues, cancelTakerTokenAmounts, @@ -543,7 +543,7 @@ export class ExchangeWrapper extends ContractWrapper { from: maker, }, ); - const txHash = await exchangeInstance.batchCancelOrders( + const txHash = await exchangeInstance.batchCancelOrders.sendTransactionAsync( orderAddresses, orderValues, cancelTakerTokenAmounts, @@ -677,7 +677,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.isBigNumber('takerTokenAmount', takerTokenAmount); assert.isBigNumber('makerTokenAmount', makerTokenAmount); const exchangeInstance = await this._getExchangeContractAsync(); - const isRoundingError = await exchangeInstance.isRoundingError.call( + const isRoundingError = await exchangeInstance.isRoundingError.callAsync( fillTakerTokenAmount, takerTokenAmount, makerTokenAmount, ); return isRoundingError; @@ -694,7 +694,7 @@ export class ExchangeWrapper extends ContractWrapper { const exchangeInstance = await this._getExchangeContractAsync(); - const isValidSignature = await exchangeInstance.isValidSignature.call( + const isValidSignature = await exchangeInstance.isValidSignature.callAsync( signerAddressHex, dataHex, ecSignature.v, @@ -706,7 +706,7 @@ export class ExchangeWrapper extends ContractWrapper { private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise { const exchangeInstance = await this._getExchangeContractAsync(); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order); - const orderHashHex = await exchangeInstance.getOrderHash.call(orderAddresses, orderValues); + const orderHashHex = await exchangeInstance.getOrderHash.callAsync(orderAddresses, orderValues); return orderHashHex; } private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { @@ -729,7 +729,7 @@ export class ExchangeWrapper extends ContractWrapper { } private async _getZRXTokenAddressAsync(): Promise { const exchangeInstance = await this._getExchangeContractAsync(); - const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.call(); + const ZRXtokenAddress = await exchangeInstance.ZRX_TOKEN_CONTRACT.callAsync(); return ZRXtokenAddress; } } diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 57c9ca93d..79eb516fe 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -35,7 +35,7 @@ export class TokenRegistryWrapper extends ContractWrapper { */ public async getTokenAddressesAsync(): Promise { const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const addresses = await tokenRegistryContract.getTokenAddresses.call(); + const addresses = await tokenRegistryContract.getTokenAddresses.callAsync(); return addresses; } /** @@ -46,14 +46,14 @@ export class TokenRegistryWrapper extends ContractWrapper { assert.isETHAddressHex('address', address); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const metadata = await tokenRegistryContract.getTokenMetaData.call(address); + const metadata = await tokenRegistryContract.getTokenMetaData.callAsync(address); const token = this._createTokenFromMetadata(metadata); return token; } public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise { assert.isString('symbol', symbol); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.call(symbol); + const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.callAsync(symbol); if (addressIfExists === constants.NULL_ADDRESS) { return undefined; } @@ -62,7 +62,7 @@ export class TokenRegistryWrapper extends ContractWrapper { public async getTokenAddressByNameIfExistsAsync(name: string): Promise { assert.isString('name', name); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const addressIfExists = await tokenRegistryContract.getTokenAddressByName.call(name); + const addressIfExists = await tokenRegistryContract.getTokenAddressByName.callAsync(name); if (addressIfExists === constants.NULL_ADDRESS) { return undefined; } @@ -71,14 +71,14 @@ export class TokenRegistryWrapper extends ContractWrapper { public async getTokenBySymbolIfExistsAsync(symbol: string): Promise { assert.isString('symbol', symbol); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const metadata = await tokenRegistryContract.getTokenBySymbol.call(symbol); + const metadata = await tokenRegistryContract.getTokenBySymbol.callAsync(symbol); const token = this._createTokenFromMetadata(metadata); return token; } public async getTokenByNameIfExistsAsync(name: string): Promise { assert.isString('name', name); const tokenRegistryContract = await this._getTokenRegistryContractAsync(); - const metadata = await tokenRegistryContract.getTokenByName.call(name); + const metadata = await tokenRegistryContract.getTokenByName.callAsync(name); const token = this._createTokenFromMetadata(metadata); return token; } diff --git a/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/src/contract_wrappers/token_transfer_proxy_wrapper.ts index 2b4b32961..2ed198be6 100644 --- a/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -15,7 +15,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper { */ public async isAuthorizedAsync(exchangeContractAddress: string): Promise { const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync(); - const isAuthorized = await tokenTransferProxyContractInstance.authorized.call(exchangeContractAddress); + const isAuthorized = await tokenTransferProxyContractInstance.authorized.callAsync(exchangeContractAddress); return isAuthorized; } /** @@ -24,7 +24,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper { */ public async getAuthorizedAddressesAsync(): Promise { const tokenTransferProxyContractInstance = await this._getTokenTransferProxyContractAsync(); - const authorizedAddresses = await tokenTransferProxyContractInstance.getAuthorizedAddresses.call(); + const authorizedAddresses = await tokenTransferProxyContractInstance.getAuthorizedAddresses.callAsync(); return authorizedAddresses; } /** diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 944f0fb42..db1ce22b2 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -47,7 +47,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); const tokenContract = await this._getTokenContractAsync(tokenAddress); - let balance = await tokenContract.balanceOf.call(ownerAddress); + let balance = await tokenContract.balanceOf.callAsync(ownerAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber balance = new BigNumber(balance); return balance; @@ -75,7 +75,7 @@ export class TokenWrapper extends ContractWrapper { // TODO: Debug issue in testrpc and submit a PR, then remove this hack const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; - const txHash = await tokenContract.approve(spenderAddress, amountInBaseUnits, { + const txHash = await tokenContract.approve.sendTransactionAsync(spenderAddress, amountInBaseUnits, { from: ownerAddress, gas, }); @@ -112,7 +112,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); const tokenContract = await this._getTokenContractAsync(tokenAddress); - let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); + let allowanceInBaseUnits = await tokenContract.allowance.callAsync(ownerAddress, spenderAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); return allowanceInBaseUnits; @@ -187,7 +187,7 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - const txHash = await tokenContract.transfer(toAddress, amountInBaseUnits, { + const txHash = await tokenContract.transfer.sendTransactionAsync(toAddress, amountInBaseUnits, { from: fromAddress, }); return txHash; @@ -226,9 +226,12 @@ export class TokenWrapper extends ContractWrapper { throw new Error(ZeroExError.InsufficientBalanceForTransfer); } - const txHash = await tokenContract.transferFrom(fromAddress, toAddress, amountInBaseUnits, { - from: senderAddress, - }); + const txHash = await tokenContract.transferFrom.sendTransactionAsync( + fromAddress, toAddress, amountInBaseUnits, + { + from: senderAddress, + }, + ); return txHash; } /** diff --git a/src/types.ts b/src/types.ts index b65ffda73..e47f57e5e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -42,85 +42,90 @@ export type CreateContractEvent = (indexFilterValues: IndexedFilterValues, subscriptionOpts: SubscriptionOpts) => ContractEventObj; export interface ExchangeContract extends Web3.ContractInstance { isValidSignature: { - call: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string, - txOpts?: TxOpts) => Promise; + callAsync: (signerAddressHex: string, dataHex: string, v: number, r: string, s: string, + txOpts?: TxOpts) => Promise; }; LogFill: CreateContractEvent; LogCancel: CreateContractEvent; LogError: CreateContractEvent; ZRX_TOKEN_CONTRACT: { - call: () => Promise; + callAsync: () => Promise; }; getUnavailableTakerTokenAmount: { - call: (orderHash: string) => Promise; + callAsync: (orderHash: string) => Promise; }; isRoundingError: { - call: (fillTakerAmount: BigNumber.BigNumber, takerTokenAmount: BigNumber.BigNumber, - makerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; + callAsync: (fillTakerAmount: BigNumber.BigNumber, takerTokenAmount: BigNumber.BigNumber, + makerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; }; fillOrder: { - (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number, r: string, s: string, txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, - fillTakerTokenAmount: BigNumber.BigNumber, - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number, r: string, s: string, txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number, r: string, s: string, txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number, r: string, s: string, txOpts?: TxOpts) => Promise; }; batchFillOrders: { - (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], - fillTakerTokenAmounts: BigNumber.BigNumber[], - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmounts: BigNumber.BigNumber[], + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmounts: BigNumber.BigNumber[], + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; }; fillOrdersUpTo: { - (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmount: BigNumber.BigNumber, - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], - fillTakerTokenAmount: BigNumber.BigNumber, - shouldThrowOnInsufficientBalanceOrAllowance: boolean, - v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; }; cancelOrder: { - (orderAddresses: OrderAddresses, orderValues: OrderValues, cancelTakerTokenAmount: BigNumber.BigNumber, - txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, - cancelTakerTokenAmount: BigNumber.BigNumber, - txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + cancelTakerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + cancelTakerTokenAmount: BigNumber.BigNumber, + txOpts?: TxOpts) => Promise; }; batchCancelOrders: { - (orderAddresses: OrderAddresses[], orderValues: OrderValues[], cancelTakerTokenAmounts: BigNumber.BigNumber[], - txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], - cancelTakerTokenAmounts: BigNumber.BigNumber[], - txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + cancelTakerTokenAmounts: BigNumber.BigNumber[], txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + cancelTakerTokenAmounts: BigNumber.BigNumber[], + txOpts?: TxOpts) => Promise; }; fillOrKillOrder: { - (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, - v: number, r: string, s: string, txOpts?: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, - fillTakerTokenAmount: BigNumber.BigNumber, - v: number, r: string, s: string, txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + fillTakerTokenAmount: BigNumber.BigNumber, + v: number, r: string, s: string, txOpts?: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues, + fillTakerTokenAmount: BigNumber.BigNumber, + v: number, r: string, s: string, txOpts?: TxOpts) => Promise; }; batchFillOrKillOrders: { - (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillTakerTokenAmounts: BigNumber.BigNumber[], - v: number[], r: string[], s: string[], txOpts: TxOpts): Promise; - estimateGas: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], - fillTakerTokenAmounts: BigNumber.BigNumber[], - v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; + sendTransactionAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmounts: BigNumber.BigNumber[], + v: number[], r: string[], s: string[], txOpts: TxOpts) => Promise; + estimateGasAsync: (orderAddresses: OrderAddresses[], orderValues: OrderValues[], + fillTakerTokenAmounts: BigNumber.BigNumber[], + v: number[], r: string[], s: string[], txOpts?: TxOpts) => Promise; }; filled: { - call: (orderHash: string) => Promise; + callAsync: (orderHash: string) => Promise; }; cancelled: { - call: (orderHash: string) => Promise; + callAsync: (orderHash: string) => Promise; }; getOrderHash: { - call: (orderAddresses: OrderAddresses, orderValues: OrderValues) => Promise; + callAsync: (orderAddresses: OrderAddresses, orderValues: OrderValues) => Promise; }; } @@ -128,49 +133,61 @@ export interface TokenContract extends Web3.ContractInstance { Transfer: CreateContractEvent; Approval: CreateContractEvent; balanceOf: { - call: (address: string) => Promise; + callAsync: (address: string) => Promise; }; allowance: { - call: (ownerAddress: string, allowedAddress: string) => Promise; + callAsync: (ownerAddress: string, allowedAddress: string) => Promise; + }; + transfer: { + sendTransactionAsync: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, + txOpts?: TxOpts) => Promise; + }; + transferFrom: { + sendTransactionAsync: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber, + txOpts?: TxOpts) => Promise; + }; + approve: { + sendTransactionAsync: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, + txOpts?: TxOpts) => Promise; }; - transfer: (toAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; - transferFrom: (fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber, - txOpts?: TxOpts) => Promise; - approve: (proxyAddress: string, amountInBaseUnits: BigNumber.BigNumber, txOpts?: TxOpts) => Promise; } export interface TokenRegistryContract extends Web3.ContractInstance { getTokenMetaData: { - call: (address: string) => Promise; + callAsync: (address: string) => Promise; }; getTokenAddresses: { - call: () => Promise; + callAsync: () => Promise; }; getTokenAddressBySymbol: { - call: (symbol: string) => Promise; + callAsync: (symbol: string) => Promise; }; getTokenAddressByName: { - call: (name: string) => Promise; + callAsync: (name: string) => Promise; }; getTokenBySymbol: { - call: (symbol: string) => Promise; + callAsync: (symbol: string) => Promise; }; getTokenByName: { - call: (name: string) => Promise; + callAsync: (name: string) => Promise; }; } export interface EtherTokenContract extends Web3.ContractInstance { - deposit: (txOpts: TxOpts) => Promise; - withdraw: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise; + deposit: { + sendTransactionAsync: (txOpts: TxOpts) => Promise; + }; + withdraw: { + sendTransactionAsync: (amount: BigNumber.BigNumber, txOpts: TxOpts) => Promise; + }; } export interface TokenTransferProxyContract extends Web3.ContractInstance { getAuthorizedAddresses: { - call: () => Promise; + callAsync: () => Promise; }; authorized: { - call: (address: string) => Promise; + callAsync: (address: string) => Promise; }; } -- cgit v1.2.3 From 78c46d7cc98fdd1e383a22adcd66a916301e2242 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:45:32 +0200 Subject: Change the order of default overriding --- src/contract.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index 9dfb04446..26da67b62 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -51,8 +51,8 @@ export class Contract implements Web3.ContractInstance { txData = args.pop(); } txData = { - ...txData, ...this.defaults, + ...txData, }; const callback = (err: Error, data: any) => { if (_.isNull(err)) { -- cgit v1.2.3 From 92b101fac8c602e095b864fb72a241ec8c101f2b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:46:13 +0200 Subject: Remove unused code --- src/contract_wrappers/exchange_wrapper.ts | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index fbb2c710f..d4daa34a2 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -42,14 +42,6 @@ import * as ExchangeArtifacts from '../artifacts/Exchange.json'; * events of the 0x Exchange smart contract. */ export class ExchangeWrapper extends ContractWrapper { - private _exchangeContractErrCodesToMsg = { - [ExchangeContractErrCodes.ERROR_FILL_EXPIRED]: ExchangeContractErrs.OrderFillExpired, - [ExchangeContractErrCodes.ERROR_CANCEL_EXPIRED]: ExchangeContractErrs.OrderFillExpired, - [ExchangeContractErrCodes.ERROR_FILL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero, - [ExchangeContractErrCodes.ERROR_CANCEL_NO_VALUE]: ExchangeContractErrs.OrderRemainingFillAmountZero, - [ExchangeContractErrCodes.ERROR_FILL_TRUNCATION]: ExchangeContractErrs.OrderFillRoundingError, - [ExchangeContractErrCodes.ERROR_FILL_BALANCE_ALLOWANCE]: ExchangeContractErrs.FillBalanceAllowanceError, - }; private _exchangeContractIfExists?: ExchangeContract; private _exchangeLogEventEmitters: ContractEventEmitter[]; private _orderValidationUtils: OrderValidationUtils; @@ -709,14 +701,6 @@ export class ExchangeWrapper extends ContractWrapper { const orderHashHex = await exchangeInstance.getOrderHash.callAsync(orderAddresses, orderValues); return orderHashHex; } - private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { - const errEvent = _.find(logs, {event: 'LogError'}); - if (!_.isUndefined(errEvent)) { - const errCode = (errEvent.args as LogErrorContractEventArgs).errorId.toNumber(); - const errMessage = this._exchangeContractErrCodesToMsg[errCode]; - throw new Error(errMessage); - } - } private async _getExchangeContractAsync(): Promise { if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; -- cgit v1.2.3 From bc5fd316dfb7876f5e8913f7cb196b9a9e0e5ffc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:47:17 +0200 Subject: Cast to Artifat type --- src/contract_wrappers/exchange_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index d4daa34a2..2ce9b2922 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -706,7 +706,7 @@ export class ExchangeWrapper extends ContractWrapper { return this._exchangeContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync( - (ExchangeArtifacts as any), + (ExchangeArtifacts as any as Artifact), ); this._exchangeContractIfExists = contractInstance as ExchangeContract; return this._exchangeContractIfExists; -- cgit v1.2.3 From ec22097efb61d27aa73c979758bc0231cea7d61d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 13:49:47 +0200 Subject: Don't override function arguments --- src/web3_wrapper.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index a0923bef9..7b9a28a7d 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -51,6 +51,7 @@ export class Web3Wrapper { } public async getContractInstanceFromArtifactAsync(artifact: Artifact, address?: string): Promise { + let contractAddress: string; if (_.isUndefined(address)) { const networkIdIfExists = await this.getNetworkIdIfExistsAsync(); if (_.isUndefined(networkIdIfExists)) { @@ -59,14 +60,16 @@ export class Web3Wrapper { if (_.isUndefined(artifact.networks[networkIdIfExists])) { throw new Error(ZeroExError.ContractNotDeployedOnNetwork); } - address = artifact.networks[networkIdIfExists].address.toLowerCase(); + contractAddress = artifact.networks[networkIdIfExists].address.toLowerCase(); + } else { + contractAddress = address; } - const doesContractExist = await this.doesContractExistAtAddressAsync(address); + const doesContractExist = await this.doesContractExistAtAddressAsync(contractAddress); if (!doesContractExist) { throw new Error(ZeroExError.ContractDoesNotExist); } const contractInstance = this.getContractInstance( - artifact.abi, address, + artifact.abi, contractAddress, ); return contractInstance; } -- cgit v1.2.3 From ee00769be171531db725288f8d485964941af529 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 15:29:29 +0200 Subject: Use schema validation to distinguish txData argument --- src/contract.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index 26da67b62..bd5afc16c 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -1,12 +1,14 @@ import * as Web3 from 'web3'; import * as _ from 'lodash'; import promisify = require('es6-promisify'); +import {SchemaValidator, schemas} from '0x-json-schemas'; export class Contract implements Web3.ContractInstance { public address: string; public abi: Web3.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; @@ -17,6 +19,7 @@ export class Contract implements Web3.ContractInstance { this.defaults = defaults; this.populateEvents(); this.populateFunctions(); + this.validator = new SchemaValidator(); } private populateFunctions(): void { const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); @@ -47,7 +50,7 @@ export class Contract implements Web3.ContractInstance { const promise = new Promise((resolve, reject) => { const lastArg = args[args.length - 1]; let txData: Partial = {}; - if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) { + if (this.isTxData(lastArg)) { txData = args.pop(); } txData = { @@ -69,4 +72,8 @@ export class Contract implements Web3.ContractInstance { }; return promisifiedWithDefaultParams; } + private isTxData(lastArg: any): boolean { + const isValid = this.validator.isValid(lastArg, schemas.txDataSchema); + return isValid; + } } -- cgit v1.2.3 From dff63f9b89a468ab09ac1be3c0c5e8ca157f8069 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 15:34:52 +0200 Subject: Use AbiType --- src/contract.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index bd5afc16c..b9ab496b2 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -22,7 +22,7 @@ export class Contract implements Web3.ContractInstance { this.validator = new SchemaValidator(); } private populateFunctions(): void { - const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function'); + const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === Web3.AbiType.Function); _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { if (functionAbi.constant) { const cbStyleCallFunction = this.contract[functionAbi.name].call; @@ -40,7 +40,7 @@ export class Contract implements Web3.ContractInstance { }); } private populateEvents(): void { - const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === 'event'); + const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === Web3.AbiType.Event); _.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => { this[eventAbi.name] = this.contract[eventAbi.name]; }); -- cgit v1.2.3 From b0547819fd97c9bace5e4eca3fe8666ec5e40f81 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 15:44:42 +0200 Subject: Define AbiType --- src/contract.ts | 5 +++-- src/types.ts | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/contract.ts b/src/contract.ts index b9ab496b2..1aacc65dc 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -2,6 +2,7 @@ import * as Web3 from 'web3'; import * as _ from 'lodash'; import promisify = require('es6-promisify'); import {SchemaValidator, schemas} from '0x-json-schemas'; +import {AbiType} from './types'; export class Contract implements Web3.ContractInstance { public address: string; @@ -22,7 +23,7 @@ export class Contract implements Web3.ContractInstance { this.validator = new SchemaValidator(); } private populateFunctions(): void { - const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === Web3.AbiType.Function); + const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function); _.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => { if (functionAbi.constant) { const cbStyleCallFunction = this.contract[functionAbi.name].call; @@ -40,7 +41,7 @@ export class Contract implements Web3.ContractInstance { }); } private populateEvents(): void { - const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === Web3.AbiType.Event); + const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event); _.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => { this[eventAbi.name] = this.contract[eventAbi.name]; }); diff --git a/src/types.ts b/src/types.ts index e47f57e5e..ddf449c16 100644 --- a/src/types.ts +++ b/src/types.ts @@ -390,3 +390,10 @@ export interface ZeroExConfig { } export type TransactionReceipt = Web3.TransactionReceipt; + +export enum AbiType { + Function = 'function', + Constructor = 'constructor', + Event = 'event', + Fallback = 'fallback', +} -- cgit v1.2.3 From a7b2131db77b72379f0d57eaff694d5a925191cd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:45:20 +0200 Subject: Decode logs args in awaitTransactionMinedAsync --- src/0x.ts | 43 ++++++++++++++++++++-- src/contract_wrappers/ether_token_wrapper.ts | 4 +- src/contract_wrappers/exchange_wrapper.ts | 4 +- src/contract_wrappers/token_registry_wrapper.ts | 4 +- .../token_transfer_proxy_wrapper.ts | 4 +- src/contract_wrappers/token_wrapper.ts | 7 ++-- src/globals.d.ts | 15 ++++++++ src/types.ts | 13 +++++++ 8 files changed, 79 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index 209b2704d..d88683c3d 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -1,6 +1,7 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import * as Web3 from 'web3'; +import * as abiDecoder from 'abi-decoder'; import {SchemaValidator, schemas} from '0x-json-schemas'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -11,12 +12,24 @@ import {constants} from './utils/constants'; import {utils} from './utils/utils'; import {signatureUtils} from './utils/signature_utils'; import {assert} from './utils/assert'; +import {artifacts} from './artifacts'; import {ExchangeWrapper} from './contract_wrappers/exchange_wrapper'; import {TokenRegistryWrapper} from './contract_wrappers/token_registry_wrapper'; import {EtherTokenWrapper} from './contract_wrappers/ether_token_wrapper'; import {TokenWrapper} from './contract_wrappers/token_wrapper'; import {TokenTransferProxyWrapper} from './contract_wrappers/token_transfer_proxy_wrapper'; -import {ECSignature, ZeroExError, Order, SignedOrder, Web3Provider, ZeroExConfig, TransactionReceipt} from './types'; +import { + ECSignature, + ZeroExError, + Order, + SignedOrder, + Web3Provider, + ZeroExConfig, + TransactionReceipt, + DecodedLogArgs, + TransactionReceiptWithDecodedLogs, + LogWithDecodedArgs, +} from './types'; // Customize our BigNumber instances bigNumberConfigs.configure(); @@ -170,6 +183,7 @@ export class ZeroEx { // We re-assign the send method so that Web3@1.0 providers work with 0x.js (provider as any).sendAsync = (provider as any).send; } + this._registerArtifactsWithinABIDecoder(); const gasPrice = _.isUndefined(config) ? undefined : config.gasPrice; const defaults = { gasPrice, @@ -264,11 +278,34 @@ export class ZeroEx { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { - clearInterval(intervalId); - resolve(transactionReceipt); + clearInterval(intervalId); + const logsWithDecodedArgs = _.map(transactionReceipt.logs, (log: Web3.LogEntry) => { + const decodedLog = abiDecoder.decodeLogs([log])[0]; + const decodedArgs = decodedLog.events; + const args: DecodedLogArgs = {}; + _.forEach(decodedArgs, arg => { + args[arg.name] = arg.value; + }); + const logWithDecodedArgs: LogWithDecodedArgs = { + ...log, + args, + event: decodedLog.name, + }; + return logWithDecodedArgs; + }); + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + ...transactionReceipt, + logs: logsWithDecodedArgs, + }; + resolve(transactionReceiptWithDecodedLogArgs); } }, pollingIntervalMs); }); return txReceiptPromise; } + private _registerArtifactsWithinABIDecoder(): void { + for (const artifact of _.values(artifacts)) { + abiDecoder.addABI(artifact.abi); + } + } } diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index d31069b22..b86309f90 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -4,7 +4,7 @@ import {ContractWrapper} from './contract_wrapper'; import {TokenWrapper} from './token_wrapper'; import {EtherTokenContract, ZeroExError} from '../types'; import {assert} from '../utils/assert'; -import * as EtherTokenArtifacts from '../artifacts/EtherToken.json'; +import {artifacts} from '../artifacts'; /** * This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract. @@ -76,7 +76,7 @@ export class EtherTokenWrapper extends ContractWrapper { return this._etherTokenContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync( - EtherTokenArtifacts as any as Artifact, + artifacts.EtherTokenArtifact, ); this._etherTokenContractIfExists = contractInstance as EtherTokenContract; return this._etherTokenContractIfExists; diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 2ce9b2922..115bd1110 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -35,7 +35,7 @@ import {ContractWrapper} from './contract_wrapper'; import {constants} from '../utils/constants'; import {TokenWrapper} from './token_wrapper'; import {decorators} from '../utils/decorators'; -import * as ExchangeArtifacts from '../artifacts/Exchange.json'; +import {artifacts} from '../artifacts'; /** * This class includes all the functionality related to calling methods and subscribing to @@ -706,7 +706,7 @@ export class ExchangeWrapper extends ContractWrapper { return this._exchangeContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync( - (ExchangeArtifacts as any as Artifact), + artifacts.ExchangeArtifact, ); this._exchangeContractIfExists = contractInstance as ExchangeContract; return this._exchangeContractIfExists; diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 79eb516fe..528a88e06 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -4,7 +4,7 @@ import {assert} from '../utils/assert'; import {Token, TokenRegistryContract, TokenMetadata} from '../types'; import {constants} from '../utils/constants'; import {ContractWrapper} from './contract_wrapper'; -import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; +import {artifacts} from '../artifacts'; /** * This class includes all the functionality related to interacting with the 0x Token Registry smart contract. @@ -102,7 +102,7 @@ export class TokenRegistryWrapper extends ContractWrapper { return this._tokenRegistryContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync( - TokenRegistryArtifacts as any as Artifact, + artifacts.TokenRegistryArtifact, ); this._tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; return this._tokenRegistryContractIfExists; diff --git a/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/src/contract_wrappers/token_transfer_proxy_wrapper.ts index 2ed198be6..528d661d1 100644 --- a/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -1,6 +1,6 @@ import * as _ from 'lodash'; import {ContractWrapper} from './contract_wrapper'; -import * as TokenTransferProxyArtifacts from '../artifacts/TokenTransferProxy.json'; +import {artifacts} from '../artifacts'; import {TokenTransferProxyContract} from '../types'; /** @@ -45,7 +45,7 @@ export class TokenTransferProxyWrapper extends ContractWrapper { return this._tokenTransferProxyContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync( - TokenTransferProxyArtifacts as any as Artifact, + artifacts.TokenTransferProxyArtifact, ); this._tokenTransferProxyContractIfExists = contractInstance as TokenTransferProxyContract; return this._tokenTransferProxyContractIfExists; diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index db1ce22b2..f1f967286 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -7,8 +7,7 @@ import {utils} from '../utils/utils'; import {eventUtils} from '../utils/event_utils'; import {constants} from '../utils/constants'; import {ContractWrapper} from './contract_wrapper'; -import * as TokenArtifacts from '../artifacts/Token.json'; -import * as TokenTransferProxyArtifacts from '../artifacts/TokenTransferProxy.json'; +import {artifacts} from '../artifacts'; import { TokenContract, ZeroExError, @@ -286,7 +285,7 @@ export class TokenWrapper extends ContractWrapper { return tokenContract; } const contractInstance = await this._instantiateContractIfExistsAsync( - TokenArtifacts as any as Artifact, tokenAddress, + artifacts.TokenArtifact, tokenAddress, ); tokenContract = contractInstance as TokenContract; this._tokenContractsByAddress[tokenAddress] = tokenContract; @@ -296,7 +295,7 @@ export class TokenWrapper extends ContractWrapper { const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : - (TokenTransferProxyArtifacts as any).networks[networkIdIfExists]; + artifacts.TokenTransferProxyArtifact.networks[networkIdIfExists]; if (_.isUndefined(proxyNetworkConfigsIfExists)) { throw new Error(ZeroExError.ContractNotDeployedOnNetwork); } diff --git a/src/globals.d.ts b/src/globals.d.ts index 6f5f13b4e..39d0860eb 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -69,3 +69,18 @@ declare class HDWalletProvider { declare module 'truffle-hdwallet-provider' { export = HDWalletProvider; } + +// abi-decoder declarations +interface DecodedLogArg { + name: string; + value: string|BigNumber.BigNumber; +} +interface DecodedLog { + name: string; + events: DecodedLogArg[]; +} +declare module 'abi-decoder' { + import * as Web3 from 'web3'; + const addABI: (abi: Web3.AbiDefinition) => void; + const decodeLogs: (logs: Web3.LogEntry[]) => DecodedLog[]; +} diff --git a/src/types.ts b/src/types.ts index ddf449c16..9d3f77127 100644 --- a/src/types.ts +++ b/src/types.ts @@ -397,3 +397,16 @@ export enum AbiType { Event = 'event', Fallback = 'fallback', } + +export interface DecodedLogArgs { + [argName: string]: ContractEventArg; +} + +export interface LogWithDecodedArgs extends Web3.LogEntry { + args: DecodedLogArgs; + event: string; +} + +export interface TransactionReceiptWithDecodedLogs extends Web3.TransactionReceipt { + logs: LogWithDecodedArgs[]; +} -- cgit v1.2.3 From 2f97ddb7279a95ffb93ae6bbdfa77618a7f41fe1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:50:22 +0200 Subject: Fix the return types and export the required public types --- src/0x.ts | 9 +++++---- src/index.ts | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/0x.ts b/src/0x.ts index d88683c3d..0af164b1e 100644 --- a/src/0x.ts +++ b/src/0x.ts @@ -270,11 +270,12 @@ export class ZeroEx { * Waits for a transaction to be mined and returns the transaction receipt. * @param txHash Transaction hash * @param pollingIntervalMs How often (in ms) should we check if the transaction is mined. - * @return TransactionReceipt + * @return Transaction receipt with decoded log args. */ - public async awaitTransactionMinedAsync(txHash: string, - pollingIntervalMs: number = 1000): Promise { - const txReceiptPromise = new Promise((resolve: (receipt: TransactionReceipt) => void, reject) => { + public async awaitTransactionMinedAsync( + txHash: string, pollingIntervalMs: number = 1000): Promise { + const txReceiptPromise = new Promise( + (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { const intervalId = setInterval(async () => { const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { diff --git a/src/index.ts b/src/index.ts index 44bd53547..00d4730da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,5 +30,7 @@ export { ContractEventArgs, Web3Provider, ZeroExConfig, - TransactionReceipt, + TransactionReceiptWithDecodedLogs, + LogWithDecodedArgs, + DecodedLogArgs, } from './types'; -- cgit v1.2.3 From 2fd5f2781b0d0966e04d4aef2f37851b922815ee Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 5 Sep 2017 18:59:18 +0200 Subject: Add forgotten artifacts file --- src/artifacts.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/artifacts.ts (limited to 'src') diff --git a/src/artifacts.ts b/src/artifacts.ts new file mode 100644 index 000000000..0c4627337 --- /dev/null +++ b/src/artifacts.ts @@ -0,0 +1,13 @@ +import * as TokenArtifact from './artifacts/Token.json'; +import * as ExchangeArtifact from './artifacts/Exchange.json'; +import * as EtherTokenArtifact from './artifacts/EtherToken.json'; +import * as TokenRegistryArtifact from './artifacts/TokenRegistry.json'; +import * as TokenTransferProxyArtifact from './artifacts/TokenTransferProxy.json'; + +export const artifacts = { + TokenArtifact: TokenArtifact as any as Artifact, + ExchangeArtifact: ExchangeArtifact as any as Artifact, + EtherTokenArtifact: EtherTokenArtifact as any as Artifact, + TokenRegistryArtifact: TokenRegistryArtifact as any as Artifact, + TokenTransferProxyArtifact: TokenTransferProxyArtifact as any as Artifact, +}; -- cgit v1.2.3