From 52c3330487c9cb1e3fc78cda752717b684deca38 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 31 May 2017 20:10:09 +0200 Subject: Implement getUnavailableTakerAmountAsync, getFilledTakerAmountAsync and getCanceledTakerAmountAsync --- src/contract_wrappers/exchange_wrapper.ts | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 3f6eb0dab..74303cf82 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,4 +1,5 @@ import * as _ from 'lodash'; +import * as BigNumber from 'bignumber.js'; import {Web3Wrapper} from '../web3_wrapper'; import {ECSignature, ZeroExError, ExchangeContract} from '../types'; import {assert} from '../utils/assert'; @@ -37,6 +38,38 @@ export class ExchangeWrapper extends ContractWrapper { ); return isValidSignature; } + /** + * Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total + * amount that has been filled or cancelled. The remaining takerAmount can be calculated by + * subtracting the unavailable amount from the total order takerAmount. + */ + public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); + return unavailableAmountInBaseUnits; + } + /** + * Retrieve the takerAmount of an order that has already been filled. + */ + public async getFilledTakerAmountAsync(orderHashHex: string): Promise { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); + return fillAmountInBaseUnits; + } + /** + * Retrieve the takerAmount of an order that has been cancelled. + */ + public async getCanceledTakerAmountAsync(orderHashHex: string): Promise { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); + return cancelledAmountInBaseUnits; + } private async getExchangeContractAsync(): Promise { if (!_.isUndefined(this.exchangeContractIfExists)) { return this.exchangeContractIfExists; -- cgit From aade6891e834dda7e80d76740882facdb45bc014 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 1 Jun 2017 18:35:23 +0200 Subject: fix tslint error --- src/contract_wrappers/exchange_wrapper.ts | 3 ++- 1 file changed, 2 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 0822ef875..6f6380bb8 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -153,7 +153,8 @@ export class ExchangeWrapper extends ContractWrapper { ); this.throwErrorLogsAsErrors(response.logs); } - private async validateFillOrderAsync(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, senderAddress: string) { + private async validateFillOrderAsync(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, + senderAddress: string) { if (fillAmount.eq(0)) { throw new Error(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO); } -- cgit From 293ce6f4b2e495589ae3675eb293fb9948f22dbb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Jun 2017 09:39:05 +0200 Subject: Always wrap BigNumbers returned by web3 with our own version and add comment --- src/contract_wrappers/exchange_wrapper.ts | 12 +++++++++--- src/contract_wrappers/token_wrapper.ts | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/contract_wrappers') diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 8b20d2b4d..2894c5a9f 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -70,7 +70,9 @@ export class ExchangeWrapper extends ContractWrapper { assert.isValidOrderHash('orderHashHex', orderHashHex); const exchangeContract = await this.getExchangeContractAsync(); - const unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); + let unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); + // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber + unavailableAmountInBaseUnits = new BigNumber(unavailableAmountInBaseUnits); return unavailableAmountInBaseUnits; } /** @@ -80,7 +82,9 @@ export class ExchangeWrapper extends ContractWrapper { assert.isValidOrderHash('orderHashHex', orderHashHex); const exchangeContract = await this.getExchangeContractAsync(); - const fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); + let fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); + // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber + fillAmountInBaseUnits = new BigNumber(fillAmountInBaseUnits); return fillAmountInBaseUnits; } /** @@ -90,7 +94,9 @@ export class ExchangeWrapper extends ContractWrapper { assert.isValidOrderHash('orderHashHex', orderHashHex); const exchangeContract = await this.getExchangeContractAsync(); - const cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); + let cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); + // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber + cancelledAmountInBaseUnits = new BigNumber(cancelledAmountInBaseUnits); return cancelledAmountInBaseUnits; } /** diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index cedbfbdae..69bcc9024 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -28,8 +28,7 @@ export class TokenWrapper extends ContractWrapper { const tokenContract = await this.getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); - // The BigNumber instance returned by Web3 is of a much older version then our own, we therefore - // should always re-instantiate the returned BigNumber after retrieval. + // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber balance = new BigNumber(balance); return balance; } @@ -44,6 +43,7 @@ export class TokenWrapper extends ContractWrapper { const tokenContract = await this.getTokenContractAsync(tokenAddress); const proxyAddress = await this.getProxyAddressAsync(); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, proxyAddress); + // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); return allowanceInBaseUnits; } -- cgit