From 42c61ecda5c29018b5984fb377eb9a3ba5cb1c86 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 21 Jun 2017 17:48:03 +0200 Subject: Return filledAmount from fillOrderAsync --- src/contract_wrappers/exchange_wrapper.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 6d42dc110..1044362a2 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -27,6 +27,7 @@ import { OrderCancellationRequest, OrderFillRequest, LogErrorContractEventArgs, + LogFillContractEventArgs, } from '../types'; import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; @@ -144,10 +145,11 @@ export class ExchangeWrapper extends ContractWrapper { * 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 (in taker tokens baseUnits) that was filled. */ @decorators.contractCallErrorHandler public async fillOrderAsync(signedOrder: SignedOrder, takerTokenFillAmount: BigNumber.BigNumber, - shouldCheckTransfer: boolean, takerAddress: string): Promise { + shouldCheckTransfer: boolean, takerAddress: string): Promise { assert.doesConformToSchema('signedOrder', signedOrder, signedOrderSchema); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); @@ -184,6 +186,9 @@ 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; } /** * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. -- cgit v1.2.3 From 7b471858fa78d6f4f7116c198490a83f6e1ddd35 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 22 Jun 2017 00:16:15 +0200 Subject: Fix return comment --- src/contract_wrappers/exchange_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 1044362a2..f47e7a5ac 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -145,7 +145,7 @@ export class ExchangeWrapper extends ContractWrapper { * 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 (in taker tokens baseUnits) that was filled. + * @return The amount of the order that was filled (in taker token baseUnits). */ @decorators.contractCallErrorHandler public async fillOrderAsync(signedOrder: SignedOrder, takerTokenFillAmount: BigNumber.BigNumber, -- cgit v1.2.3 From 0dbad86d239cc1afb9df3c805a7567180b458b36 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 22 Jun 2017 13:41:07 +0200 Subject: Return cancelledAmount from cancelOrderAsync --- src/contract_wrappers/exchange_wrapper.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index f47e7a5ac..92c18e3e0 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -28,6 +28,7 @@ import { OrderFillRequest, LogErrorContractEventArgs, LogFillContractEventArgs, + LogCancelContractEventArgs, } from '../types'; import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; @@ -443,10 +444,11 @@ export class ExchangeWrapper extends ContractWrapper { * @param order An object that conforms to the Order or SignedOrder interface. * The order you would like to cancel. * @param takerTokenCancelAmount The amount (specified in taker tokens) that you would like to cancel. + * @returns The amount of the order that was cancelled (in taker token baseUnits). */ @decorators.contractCallErrorHandler public async cancelOrderAsync( - order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise { + order: Order|SignedOrder, takerTokenCancelAmount: BigNumber.BigNumber): Promise { assert.doesConformToSchema('order', order, orderSchema); assert.isBigNumber('takerTokenCancelAmount', takerTokenCancelAmount); await assert.isSenderAddressAsync('order.maker', order.maker, this._web3Wrapper); @@ -473,6 +475,9 @@ export class ExchangeWrapper extends ContractWrapper { }, ); this._throwErrorLogsAsErrors(response.logs); + const logFillArgs = response.logs[0].args as LogCancelContractEventArgs; + const cancelledAmount = new BigNumber(logFillArgs.cancelledValueT); + return cancelledAmount; } /** * Batch version of cancelOrderAsync. Atomically cancels multiple orders in a single transaction. -- cgit v1.2.3 From 9c2a332b699e7bad85a284a69c8cd6cca31bc519 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 22 Jun 2017 14:12:17 +0200 Subject: Return filledTakerTokenAmount from fillOrdersUpToAsync --- src/contract_wrappers/exchange_wrapper.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 92c18e3e0..30cdbd101 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,6 +1,7 @@ import map = require('lodash/map'); import isEmpty = require('lodash/isEmpty'); import find = require('lodash/find'); +import each = require('lodash/each'); import isUndefined = require('lodash/isUndefined'); import unzip = require('lodash/unzip'); import * as BigNumber from 'bignumber.js'; @@ -204,10 +205,11 @@ export class ExchangeWrapper extends ContractWrapper { * some cannot be filled. * @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). */ @decorators.contractCallErrorHandler public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber, - shouldCheckTransfer: boolean, takerAddress: string): Promise { + shouldCheckTransfer: boolean, takerAddress: string): Promise { const takerTokenAddresses = map(signedOrders, signedOrder => signedOrder.takerTokenAddress); assert.hasAtMostOneUniqueValue(takerTokenAddresses, ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED); @@ -220,7 +222,7 @@ export class ExchangeWrapper extends ContractWrapper { signedOrder, takerTokenFillAmount, takerAddress); } if (isEmpty(signedOrders)) { - return; // no-op + return new BigNumber(0); // no-op } const orderAddressesValuesAndSignatureArray = map(signedOrders, signedOrder => { @@ -263,6 +265,11 @@ export class ExchangeWrapper extends ContractWrapper { }, ); this._throwErrorLogsAsErrors(response.logs); + let filledTakerTokenAmount = new BigNumber(0); + const filledAmounts = each(response.logs, log => { + filledTakerTokenAmount = filledTakerTokenAmount.plus((log.args as LogFillContractEventArgs).filledValueT); + }); + return filledTakerTokenAmount; } /** * Batch version of fillOrderAsync. @@ -444,7 +451,7 @@ export class ExchangeWrapper extends ContractWrapper { * @param order An object that conforms to the Order or SignedOrder interface. * The order you would like to cancel. * @param takerTokenCancelAmount The amount (specified in taker tokens) that you would like to cancel. - * @returns The amount of the order that was cancelled (in taker token baseUnits). + * @return The amount of the order that was cancelled (in taker token baseUnits). */ @decorators.contractCallErrorHandler public async cancelOrderAsync( -- cgit v1.2.3