aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/exchange_wrapper.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-03 01:53:01 +0800
committerGitHub <noreply@github.com>2017-06-03 01:53:01 +0800
commit5925f81fe185a90efaa82dd90bd8d65d74326f11 (patch)
tree12daf7aec686c576634b2daa5a58af2831cc497d /src/contract_wrappers/exchange_wrapper.ts
parent2ff8f4ca6ed238f331cb69aaeb912a94b3df901e (diff)
parent35c9330d6246183509a3543cdf1278b9ced191e2 (diff)
downloaddexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar.gz
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar.bz2
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar.lz
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar.xz
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.tar.zst
dexon-sol-tools-5925f81fe185a90efaa82dd90bd8d65d74326f11.zip
Merge pull request #31 from 0xProject/unavailableFilledCancelled
Implement Unavailable, Filled and Cancelled
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index 4aa532bdd..cb869b498 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,
@@ -60,6 +61,44 @@ 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<BigNumber.BigNumber> {
+ assert.isValidOrderHash('orderHashHex', orderHashHex);
+
+ const exchangeContract = await this.getExchangeContractAsync();
+ 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;
+ }
+ /**
+ * Retrieve the takerAmount of an order that has already been filled.
+ */
+ public async getFilledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> {
+ assert.isValidOrderHash('orderHashHex', orderHashHex);
+
+ const exchangeContract = await this.getExchangeContractAsync();
+ 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;
+ }
+ /**
+ * Retrieve the takerAmount of an order that has been cancelled.
+ */
+ public async getCanceledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> {
+ assert.isValidOrderHash('orderHashHex', orderHashHex);
+
+ const exchangeContract = await this.getExchangeContractAsync();
+ 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;
+ }
+ /**
* Fills a signed order with a fillAmount denominated in baseUnits of the taker token.
* Since the order in which transactions are included in the next block is indeterminate, race-conditions
* could arise where a users balance or allowance changes before the fillOrder executes. Because of this,