aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorAra Kevonian <=>2018-04-09 19:49:05 +0800
committerAra Kevonian <=>2018-04-09 19:49:05 +0800
commit8d76d74a1713dcec140c8d43f9ea7612b5cc38f1 (patch)
tree92dd11f286baa3fe9ac3d840fddf82fe059f7b93 /packages/0x.js
parent073bf738ddb271b6b4158798baf4cac3cb0608e9 (diff)
downloaddexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar.gz
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar.bz2
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar.lz
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar.xz
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.tar.zst
dexon-sol-tools-8d76d74a1713dcec140c8d43f9ea7612b5cc38f1.zip
Implement `zeroEx.exchange.getOrderStateAsync`
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/CHANGELOG.md2
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts53
-rw-r--r--packages/0x.js/test/exchange_wrapper_test.ts39
3 files changed, 76 insertions, 18 deletions
diff --git a/packages/0x.js/CHANGELOG.md b/packages/0x.js/CHANGELOG.md
index c18915417..63c82ac94 100644
--- a/packages/0x.js/CHANGELOG.md
+++ b/packages/0x.js/CHANGELOG.md
@@ -4,6 +4,8 @@ Edit the package's CHANGELOG.json file only.
-->
CHANGELOG
+## v0.36.0 - TBD
+ * Add `zeroEx.exchange.getOrderStateAsync` to allow obtaining current OrderState for a signedOrder
## v0.35.0 - _April 2, 2018_
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 378ae8111..fb1877f4a 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -13,35 +13,38 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { artifacts } from '../artifacts';
+import { BalanceAndProxyAllowanceLazyStore } from '../stores/balance_proxy_allowance_lazy_store';
+import { OrderFilledCancelledLazyStore } from '../stores/order_filled_cancelled_lazy_store';
import {
- BlockRange,
- EventCallback,
- ExchangeContractErrCodes,
- ExchangeContractErrs,
- IndexedFilterValues,
- MethodOpts,
- OrderAddresses,
- OrderCancellationRequest,
- OrderFillRequest,
- OrderTransactionOpts,
- OrderValues,
- ValidateOrderFillableOpts,
+BlockRange,
+EventCallback,
+ExchangeContractErrCodes,
+ExchangeContractErrs,
+IndexedFilterValues,
+MethodOpts,
+OrderAddresses,
+OrderCancellationRequest,
+OrderFillRequest,
+OrderState,
+OrderTransactionOpts,
+OrderValues,
+ValidateOrderFillableOpts,
} from '../types';
import { assert } from '../utils/assert';
import { decorators } from '../utils/decorators';
import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
+import { OrderStateUtils } from '../utils/order_state_utils';
import { OrderValidationUtils } from '../utils/order_validation_utils';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper';
import {
- ExchangeContract,
- ExchangeContractEventArgs,
- ExchangeEvents,
- LogErrorContractEventArgs,
+ExchangeContract,
+ExchangeContractEventArgs,
+ExchangeEvents,
+LogErrorContractEventArgs,
} from './generated/exchange';
import { TokenWrapper } from './token_wrapper';
-
const SHOULD_VALIDATE_BY_DEFAULT = true;
interface ExchangeContractErrCodesToMsgs {
@@ -874,6 +877,22 @@ export class ExchangeWrapper extends ContractWrapper {
}
}
/**
+ * Gets the latest OrderState of a signedOrder
+ * @param signedOrder The signedOrder
+ */
+ public async getOrderStateAsync(signedOrder: SignedOrder): Promise<OrderState> {
+ const balanceAndProxyAllowanceLazyStore = new BalanceAndProxyAllowanceLazyStore(
+ this._tokenWrapper,
+ BlockParamLiteral.Latest,
+ );
+ const orderFilledCancelledLazyStore = new OrderFilledCancelledLazyStore(this);
+ const orderStateUtils = new OrderStateUtils(
+ balanceAndProxyAllowanceLazyStore,
+ orderFilledCancelledLazyStore,
+ );
+ return orderStateUtils.getOrderStateAsync(signedOrder);
+ }
+ /**
* Returns the ZRX token address used by the exchange contract.
* @return Address of ZRX token
*/
diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts
index cfc390bae..b6eaa2591 100644
--- a/packages/0x.js/test/exchange_wrapper_test.ts
+++ b/packages/0x.js/test/exchange_wrapper_test.ts
@@ -14,7 +14,7 @@ import {
LogCancelContractEventArgs,
LogFillContractEventArgs,
OrderCancellationRequest,
- OrderFillRequest,
+ OrderFillRequest, OrderState, OrderStateInvalid,
SignedOrder,
Token,
ZeroEx,
@@ -1156,4 +1156,41 @@ describe('ExchangeWrapper', () => {
expect(args.maker).to.be.equal(differentMakerAddress);
});
});
+ describe('#getOrderState', () => {
+ let maker: string;
+ let taker: string;
+ let makerToken: Token;
+ let takerToken: Token;
+ let signedOrder: SignedOrder;
+ let orderState: OrderState;
+ const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), constants.ZRX_DECIMALS);
+ before(async () => {
+ [, maker, taker] = userAddresses;
+ tokens = await zeroEx.tokenRegistry.getTokensAsync();
+ [makerToken, takerToken] = tokenUtils.getDummyTokens();
+ });
+ it('should report orderStateValid when order is fillable', async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerToken.address,
+ takerToken.address,
+ maker,
+ taker,
+ fillableAmount,
+ );
+ orderState = await zeroEx.exchange.getOrderStateAsync(signedOrder);
+ expect(orderState.isValid).to.be.true();
+ });
+ it('should report orderStateInvalid when maker allowance set to 0', async () => {
+ signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerToken.address,
+ takerToken.address,
+ maker,
+ taker,
+ fillableAmount,
+ );
+ await zeroEx.token.setProxyAllowanceAsync(makerToken.address, maker, new BigNumber(0));
+ orderState = await zeroEx.exchange.getOrderStateAsync(signedOrder);
+ expect(orderState.isValid).to.be.false();
+ });
+ });
}); // tslint:disable:max-file-line-count