diff options
Diffstat (limited to 'packages/contracts/src/utils')
-rw-r--r-- | packages/contracts/src/utils/constants.ts | 1 | ||||
-rw-r--r-- | packages/contracts/src/utils/erc20_wrapper.ts | 8 | ||||
-rw-r--r-- | packages/contracts/src/utils/erc721_wrapper.ts | 10 | ||||
-rw-r--r-- | packages/contracts/src/utils/exchange_wrapper.ts | 4 | ||||
-rw-r--r-- | packages/contracts/src/utils/formatters.ts | 8 | ||||
-rw-r--r-- | packages/contracts/src/utils/order_utils.ts | 6 | ||||
-rw-r--r-- | packages/contracts/src/utils/types.ts | 12 |
7 files changed, 31 insertions, 18 deletions
diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts index e45e51c04..41968f547 100644 --- a/packages/contracts/src/utils/constants.ts +++ b/packages/contracts/src/utils/constants.ts @@ -20,6 +20,7 @@ export const constants = { INVALID_OPCODE: 'invalid opcode', REVERT: 'revert', TESTRPC_NETWORK_ID: 50, + AWAIT_TRANSACTION_MINED_MS: 100, MAX_ETHERTOKEN_WITHDRAW_GAS: 43000, MAX_TOKEN_TRANSFERFROM_GAS: 80000, MAX_TOKEN_APPROVE_GAS: 60000, diff --git a/packages/contracts/src/utils/erc20_wrapper.ts b/packages/contracts/src/utils/erc20_wrapper.ts index f12571b48..0303649a5 100644 --- a/packages/contracts/src/utils/erc20_wrapper.ts +++ b/packages/contracts/src/utils/erc20_wrapper.ts @@ -23,7 +23,7 @@ export class ERC20Wrapper { } public async deployDummyTokensAsync(): Promise<DummyERC20TokenContract[]> { this._dummyTokenContracts = await Promise.all( - _.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, () => + _.times(constants.NUM_DUMMY_ERC20_TO_DEPLOY, async () => DummyERC20TokenContract.deployFrom0xArtifactAsync( artifacts.DummyERC20Token, this._provider, @@ -45,7 +45,7 @@ export class ERC20Wrapper { ); return this._proxyContract; } - public async setBalancesAndAllowancesAsync() { + public async setBalancesAndAllowancesAsync(): Promise<void> { this._validateDummyTokenContractsExistOrThrow(); this._validateProxyContractExistsOrThrow(); const setBalancePromises: Array<Promise<string>> = []; @@ -103,12 +103,12 @@ export class ERC20Wrapper { const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address); return tokenAddresses; } - private _validateDummyTokenContractsExistOrThrow() { + private _validateDummyTokenContractsExistOrThrow(): void { if (_.isUndefined(this._dummyTokenContracts)) { throw new Error('Dummy ERC20 tokens not yet deployed, please call "deployDummyTokensAsync"'); } } - private _validateProxyContractExistsOrThrow() { + private _validateProxyContractExistsOrThrow(): void { if (_.isUndefined(this._proxyContract)) { throw new Error('ERC20 proxy contract not yet deployed, please call "deployProxyAsync"'); } diff --git a/packages/contracts/src/utils/erc721_wrapper.ts b/packages/contracts/src/utils/erc721_wrapper.ts index bf8953a49..aee796e4b 100644 --- a/packages/contracts/src/utils/erc721_wrapper.ts +++ b/packages/contracts/src/utils/erc721_wrapper.ts @@ -25,7 +25,7 @@ export class ERC721Wrapper { } public async deployDummyTokensAsync(): Promise<DummyERC721TokenContract[]> { this._dummyTokenContracts = await Promise.all( - _.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, () => + _.times(constants.NUM_DUMMY_ERC721_TO_DEPLOY, async () => DummyERC721TokenContract.deployFrom0xArtifactAsync( artifacts.DummyERC721Token, this._provider, @@ -45,7 +45,7 @@ export class ERC721Wrapper { ); return this._proxyContract; } - public async setBalancesAndAllowancesAsync() { + public async setBalancesAndAllowancesAsync(): Promise<void> { this._validateDummyTokenContractsExistOrThrow(); this._validateProxyContractExistsOrThrow(); const setBalancePromises: Array<Promise<string>> = []; @@ -125,17 +125,17 @@ export class ERC721Wrapper { const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address); return tokenAddresses; } - private _validateDummyTokenContractsExistOrThrow() { + private _validateDummyTokenContractsExistOrThrow(): void { if (_.isUndefined(this._dummyTokenContracts)) { throw new Error('Dummy ERC721 tokens not yet deployed, please call "deployDummyTokensAsync"'); } } - private _validateProxyContractExistsOrThrow() { + private _validateProxyContractExistsOrThrow(): void { if (_.isUndefined(this._proxyContract)) { throw new Error('ERC721 proxy contract not yet deployed, please call "deployProxyAsync"'); } } - private _validateBalancesAndAllowancesSetOrThrow() { + private _validateBalancesAndAllowancesSetOrThrow(): void { if (_.keys(this._initialTokenIdsByOwner).length === 0) { throw new Error( 'Dummy ERC721 balances and allowances not yet set, please call "setBalancesAndAllowancesAsync"', diff --git a/packages/contracts/src/utils/exchange_wrapper.ts b/packages/contracts/src/utils/exchange_wrapper.ts index 98d5e27f9..17445ff75 100644 --- a/packages/contracts/src/utils/exchange_wrapper.ts +++ b/packages/contracts/src/utils/exchange_wrapper.ts @@ -244,8 +244,8 @@ export class ExchangeWrapper { const tx = await this._getTxWithDecodedExchangeLogsAsync(txHash); return tx; } - private async _getTxWithDecodedExchangeLogsAsync(txHash: string) { - const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash); + private async _getTxWithDecodedExchangeLogsAsync(txHash: string): Promise<TransactionReceiptWithDecodedLogs> { + const tx = await Web3Wrapper.awaitTransactionMinedAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); tx.logs = _.filter(tx.logs, log => log.address === this._exchange.address); tx.logs = _.map(tx.logs, log => this._logDecoder.decodeLogOrThrow(log)); return tx; diff --git a/packages/contracts/src/utils/formatters.ts b/packages/contracts/src/utils/formatters.ts index e706c15b5..bfa48d6f1 100644 --- a/packages/contracts/src/utils/formatters.ts +++ b/packages/contracts/src/utils/formatters.ts @@ -5,7 +5,7 @@ import { orderUtils } from './order_utils'; import { BatchCancelOrders, BatchFillOrders, MarketBuyOrders, MarketSellOrders, SignedOrder } from './types'; export const formatters = { - createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []) { + createBatchFill(signedOrders: SignedOrder[], takerAssetFillAmounts: BigNumber[] = []): BatchFillOrders { const batchFill: BatchFillOrders = { orders: [], signatures: [], @@ -21,7 +21,7 @@ export const formatters = { }); return batchFill; }, - createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber) { + createMarketSellOrders(signedOrders: SignedOrder[], takerAssetFillAmount: BigNumber): MarketSellOrders { const marketSellOrders: MarketSellOrders = { orders: [], signatures: [], @@ -34,7 +34,7 @@ export const formatters = { }); return marketSellOrders; }, - createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber) { + createMarketBuyOrders(signedOrders: SignedOrder[], makerAssetFillAmount: BigNumber): MarketBuyOrders { const marketBuyOrders: MarketBuyOrders = { orders: [], signatures: [], @@ -47,7 +47,7 @@ export const formatters = { }); return marketBuyOrders; }, - createBatchCancel(signedOrders: SignedOrder[]) { + createBatchCancel(signedOrders: SignedOrder[]): BatchCancelOrders { const batchCancel: BatchCancelOrders = { orders: [], }; diff --git a/packages/contracts/src/utils/order_utils.ts b/packages/contracts/src/utils/order_utils.ts index 7a482ad9e..8adc6b735 100644 --- a/packages/contracts/src/utils/order_utils.ts +++ b/packages/contracts/src/utils/order_utils.ts @@ -4,7 +4,7 @@ import ethUtil = require('ethereumjs-util'); import * as _ from 'lodash'; import { crypto } from './crypto'; -import { OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; +import { CancelOrder, MatchOrder, OrderStruct, SignatureType, SignedOrder, UnsignedOrder } from './types'; export const orderUtils = { createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => { @@ -15,7 +15,7 @@ export const orderUtils = { }; return fill; }, - createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber) { + createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber): CancelOrder { const cancel = { order: orderUtils.getOrderStruct(signedOrder), takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount, @@ -80,7 +80,7 @@ export const orderUtils = { const orderHashHex = `0x${orderHashBuff.toString('hex')}`; return orderHashHex; }, - createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder) { + createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder): MatchOrder { const fill = { left: orderUtils.getOrderStruct(signedOrderLeft), right: orderUtils.getOrderStruct(signedOrderRight), diff --git a/packages/contracts/src/utils/types.ts b/packages/contracts/src/utils/types.ts index 8d81adece..ef86b4f38 100644 --- a/packages/contracts/src/utils/types.ts +++ b/packages/contracts/src/utils/types.ts @@ -197,3 +197,15 @@ export interface ProxyData { tokenAddress?: string; data?: any; } + +export interface CancelOrder { + order: OrderStruct; + takerAssetCancelAmount: BigNumber; +} + +export interface MatchOrder { + left: OrderStruct; + right: OrderStruct; + leftSignature: string; + rightSignature: string; +} |