aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/0x.js.ts8
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts33
-rw-r--r--src/types.ts9
-rw-r--r--src/utils/assert.ts4
-rw-r--r--src/utils/utils.ts4
5 files changed, 54 insertions, 4 deletions
diff --git a/src/0x.js.ts b/src/0x.js.ts
index a613d5f48..2bced325f 100644
--- a/src/0x.js.ts
+++ b/src/0x.js.ts
@@ -70,10 +70,10 @@ export class ZeroEx {
return salt;
}
/** Checks if order hash is valid */
- public static isValidOrderHash(orderHash: string): boolean {
- assert.isString('orderHash', orderHash);
- const isValid = /^0x[0-9A-F]{64}$/i.test(orderHash);
- return isValid;
+ public static isValidOrderHash(orderHashHex: string): boolean {
+ assert.isString('orderHashHex', orderHashHex);
+ const isValidOrderHash = utils.isValidOrderHash(orderHashHex);
+ return isValidOrderHash;
}
/**
* A unit amount is defined as the amount of a token above the specified decimal places (integer part).
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index eace55f4d..8b20d2b4d 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,
@@ -61,6 +62,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<BigNumber.BigNumber> {
+ 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<BigNumber.BigNumber> {
+ 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<BigNumber.BigNumber> {
+ assert.isValidOrderHash('orderHashHex', orderHashHex);
+
+ const exchangeContract = await this.getExchangeContractAsync();
+ const cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex);
+ return cancelledAmountInBaseUnits;
+ }
+ /**
* Fills a signed order with a fillAmount denominated in baseUnits of the taker token. The caller can
* decide whether they want the call to throw if the balance/allowance checks fail by setting
* shouldCheckTransfer to false. If set to true, the call will fail without throwing, preserving gas costs.
diff --git a/src/types.ts b/src/types.ts
index f80f98dc4..29f7e0ee4 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -34,12 +34,21 @@ export type OrderValues = [BigNumber.BigNumber, BigNumber.BigNumber, BigNumber.B
export interface ExchangeContract {
isValidSignature: any;
+ getUnavailableValueT: {
+ call: (orderHash: string) => BigNumber.BigNumber;
+ };
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;
};
+ filled: {
+ call: (orderHash: string) => BigNumber.BigNumber;
+ };
+ cancelled: {
+ call: (orderHash: string) => BigNumber.BigNumber;
+ };
}
export interface TokenContract {
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index aeed1c6dc..406f2b149 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -2,6 +2,7 @@ import * as _ from 'lodash';
import * as BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
import {SchemaValidator} from './schema_validator';
+import {utils} from './utils';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
@@ -27,6 +28,9 @@ export const assert = {
isNumber(variableName: string, value: number): void {
this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
},
+ isValidOrderHash(variableName: string, value: string): void {
+ this.assert(utils.isValidOrderHash(value), this.typeAssertionMessage(variableName, 'orderHash', value));
+ },
isBoolean(variableName: string, value: boolean): void {
this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
},
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index 336eaf7bb..e6840a624 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -18,4 +18,8 @@ export const utils = {
isParityNode(nodeVersion: string): boolean {
return _.includes(nodeVersion, 'Parity');
},
+ isValidOrderHash(orderHashHex: string) {
+ const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex);
+ return isValid;
+ },
};