diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-08 06:38:05 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-07-11 15:30:14 +0800 |
commit | b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed (patch) | |
tree | 2effc5d3f3335d59265c9f3a321bbc841ef2eafd /src | |
parent | 5a8297649fdebd1eb65255db3e6666ecccfb138a (diff) | |
download | dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar.gz dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar.bz2 dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar.lz dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar.xz dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.tar.zst dexon-sol-tools-b774a9f91ca1200ef9cef1b6fb0d3396df5d59ed.zip |
Migrate fillOrder
Diffstat (limited to 'src')
-rw-r--r-- | src/artifacts/exchange/Exchange_v1.json | 8 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 43 | ||||
-rw-r--r-- | src/types.ts | 13 |
3 files changed, 35 insertions, 29 deletions
diff --git a/src/artifacts/exchange/Exchange_v1.json b/src/artifacts/exchange/Exchange_v1.json index 3962a62a3..8a724a2de 100644 --- a/src/artifacts/exchange/Exchange_v1.json +++ b/src/artifacts/exchange/Exchange_v1.json @@ -229,11 +229,11 @@ "type": "uint256[6]" }, { - "name": "fillValueT", + "name": "fillTakerTokenAmount", "type": "uint256" }, { - "name": "shouldCheckTransfer", + "name": "shouldThrowOnInsufficientBalanceOrAllowance", "type": "bool" }, { @@ -249,10 +249,10 @@ "type": "bytes32" } ], - "name": "fill", + "name": "fillOrder", "outputs": [ { - "name": "filledValueT", + "name": "filledTakerTokenAmount", "type": "uint256" } ], diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 861d9cf2c..95420cbff 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -150,32 +150,35 @@ export class ExchangeWrapper extends ContractWrapper { * we allow you to specify `shouldCheckTransfer`. If true, the smart contract will not throw if the parties * do not have sufficient balances/allowances, preserving gas costs. Setting it to false forgoes this check * and causes the smart contract to throw (using all the gas supplied) instead. - * @param signedOrder An object that conforms to the SignedOrder interface. - * @param takerTokenFillAmount The amount of the order (in taker tokens baseUnits) that you wish to fill. - * @param shouldCheckTransfer Whether or not you wish for the contract call to throw if upon - * execution the tokens cannot be transferred. - * @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). + * @param signedOrder An object that conforms to the SignedOrder interface. + * @param fillTakerTokenAmount The amount of the order (in taker tokens baseUnits) that + * you wish to fill. + * @param shouldThrowOnInsufficientBalanceOrAllowance Whether or not you wish for the contract call to throw + * if upon execution the tokens cannot be transferred. + * @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). */ @decorators.contractCallErrorHandler - public async fillOrderAsync(signedOrder: SignedOrder, takerTokenFillAmount: BigNumber.BigNumber, - shouldCheckTransfer: boolean, takerAddress: string): Promise<BigNumber.BigNumber> { + public async fillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + takerAddress: string): Promise<BigNumber.BigNumber> { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); - assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); - assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); + assert.isBigNumber('fillTakerTokenAmount', fillTakerTokenAmount); + assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance); await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); const exchangeInstance = await this._getExchangeContractAsync(signedOrder.exchangeContractAddress); - await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, takerTokenFillAmount, takerAddress); + await this._validateFillOrderAndThrowIfInvalidAsync(signedOrder, fillTakerTokenAmount, takerAddress); const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder); - const gas = await exchangeInstance.fill.estimateGas( + const gas = await exchangeInstance.fillOrder.estimateGas( orderAddresses, orderValues, - takerTokenFillAmount, - shouldCheckTransfer, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, signedOrder.ecSignature.v, signedOrder.ecSignature.r, signedOrder.ecSignature.s, @@ -183,11 +186,11 @@ export class ExchangeWrapper extends ContractWrapper { from: takerAddress, }, ); - const response: ContractResponse = await exchangeInstance.fill( + const response: ContractResponse = await exchangeInstance.fillOrder( orderAddresses, orderValues, - takerTokenFillAmount, - shouldCheckTransfer, + fillTakerTokenAmount, + shouldThrowOnInsufficientBalanceOrAllowance, signedOrder.ecSignature.v, signedOrder.ecSignature.r, signedOrder.ecSignature.s, @@ -198,8 +201,8 @@ export class ExchangeWrapper extends ContractWrapper { ); this._throwErrorLogsAsErrors(response.logs); const logFillArgs = response.logs[0].args as LogFillContractEventArgs; - const filledAmount = new BigNumber(logFillArgs.filledValueT); - return filledAmount; + const filledTakerTokenAmount = new BigNumber(logFillArgs.filledValueT); + return filledTakerTokenAmount; } /** * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. diff --git a/src/types.ts b/src/types.ts index 029640f64..bf5a0281a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -71,11 +71,14 @@ export interface ExchangeContract extends ContractInstance { call: (takerTokenAmount: BigNumber.BigNumber, fillTakerAmount: BigNumber.BigNumber, makerTokenAmount: BigNumber.BigNumber, txOpts?: TxOpts) => Promise<boolean>; }; - fill: { - (orderAddresses: OrderAddresses, orderValues: OrderValues, fillAmount: BigNumber.BigNumber, - shouldCheckTransfer: boolean, v: number, r: string, s: string, txOpts?: TxOpts): ContractResponse; - estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, fillAmount: BigNumber.BigNumber, - shouldCheckTransfer: boolean, v: number, r: string, s: string, txOpts?: TxOpts) => number; + fillOrder: { + (orderAddresses: OrderAddresses, orderValues: OrderValues, fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number, r: string, s: string, txOpts?: TxOpts): ContractResponse; + estimateGas: (orderAddresses: OrderAddresses, orderValues: OrderValues, + fillTakerTokenAmount: BigNumber.BigNumber, + shouldThrowOnInsufficientBalanceOrAllowance: boolean, + v: number, r: string, s: string, txOpts?: TxOpts) => number; }; batchFill: { (orderAddresses: OrderAddresses[], orderValues: OrderValues[], fillAmounts: BigNumber.BigNumber[], |