aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/order_watcher')
-rw-r--r--packages/0x.js/src/order_watcher/event_watcher.ts7
-rw-r--r--packages/0x.js/src/order_watcher/expiration_watcher.ts17
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts68
-rw-r--r--packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts3
4 files changed, 50 insertions, 45 deletions
diff --git a/packages/0x.js/src/order_watcher/event_watcher.ts b/packages/0x.js/src/order_watcher/event_watcher.ts
index ecbab0cd5..831f19da5 100644
--- a/packages/0x.js/src/order_watcher/event_watcher.ts
+++ b/packages/0x.js/src/order_watcher/event_watcher.ts
@@ -1,6 +1,6 @@
-import * as Web3 from 'web3';
import * as _ from 'lodash';
-import {Web3Wrapper} from '../web3_wrapper';
+import * as Web3 from 'web3';
+
import {
BlockParamLiteral,
EventCallback,
@@ -8,9 +8,10 @@ import {
ZeroExError,
} from '../types';
import {AbiDecoder} from '../utils/abi_decoder';
-import {intervalUtils} from '../utils/interval_utils';
import {assert} from '../utils/assert';
+import {intervalUtils} from '../utils/interval_utils';
import {utils} from '../utils/utils';
+import {Web3Wrapper} from '../web3_wrapper';
const DEFAULT_EVENT_POLLING_INTERVAL_MS = 200;
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts
index 717edaad7..9a1bb1ca4 100644
--- a/packages/0x.js/src/order_watcher/expiration_watcher.ts
+++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts
@@ -1,10 +1,11 @@
-import * as _ from 'lodash';
import {BigNumber} from 'bignumber.js';
import {RBTree} from 'bintrees';
-import {utils} from '../utils/utils';
-import {intervalUtils} from '../utils/interval_utils';
-import {SignedOrder, ZeroExError} from '../types';
+import * as _ from 'lodash';
+
import {ZeroEx} from '../0x';
+import {SignedOrder, ZeroExError} from '../types';
+import {intervalUtils} from '../utils/interval_utils';
+import {utils} from '../utils/utils';
const DEFAULT_EXPIRATION_MARGIN_MS = 0;
const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50;
@@ -29,12 +30,12 @@ export class ExpirationWatcher {
const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs);
this.orderHashByExpirationRBTree = new RBTree(comparator);
}
- public subscribe(callbackAsync: (orderHash: string) => Promise<void>): void {
+ public subscribe(callback: (orderHash: string) => void): void {
if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) {
throw new Error(ZeroExError.SubscriptionAlreadyPresent);
}
this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
- this.pruneExpiredOrdersAsync.bind(this, callbackAsync), this.orderExpirationCheckingIntervalMs,
+ this.pruneExpiredOrders.bind(this, callback), this.orderExpirationCheckingIntervalMs,
);
}
public unsubscribe(): void {
@@ -52,7 +53,7 @@ export class ExpirationWatcher {
this.orderHashByExpirationRBTree.remove(orderHash);
delete this.expiration[orderHash];
}
- private async pruneExpiredOrdersAsync(callbackAsync: (orderHash: string) => Promise<void>): Promise<void> {
+ private pruneExpiredOrders(callback: (orderHash: string) => void): void {
const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs();
while (true) {
const hasTrakedOrders = this.orderHashByExpirationRBTree.size === 0;
@@ -70,7 +71,7 @@ export class ExpirationWatcher {
const orderHash = this.orderHashByExpirationRBTree.min();
this.orderHashByExpirationRBTree.remove(orderHash);
delete this.expiration[orderHash];
- await callbackAsync(orderHash);
+ callback(orderHash);
}
}
}
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index d02e31160..8c21c1678 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -1,42 +1,44 @@
-import * as _ from 'lodash';
import {schemas} from '@0xproject/json-schemas';
+import * as _ from 'lodash';
+
import {ZeroEx} from '../0x';
-import {EventWatcher} from './event_watcher';
-import {assert} from '../utils/assert';
-import {utils} from '../utils/utils';
import {artifacts} from '../artifacts';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {intervalUtils} from '../utils/interval_utils';
-import {OrderStateUtils} from '../utils/order_state_utils';
+import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper';
+import {TokenWrapper} from '../contract_wrappers/token_wrapper';
+import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store';
+import {OrderFilledCancelledLazyStore} from '../stores/order_filled_cancelled_lazy_store';
import {
- LogEvent,
- OrderState,
- SignedOrder,
- Web3Provider,
+ ApprovalContractEventArgs,
BlockParamLiteral,
- LogWithDecodedArgs,
ContractEventArgs,
+ ExchangeContractErrs,
+ ExchangeEvents,
+ LogCancelContractEventArgs,
+ LogEvent,
+ LogFillContractEventArgs,
+ LogWithDecodedArgs,
OnOrderStateChangeCallback,
+ OrderState,
OrderStateWatcherConfig,
- ApprovalContractEventArgs,
- TransferContractEventArgs,
- LogFillContractEventArgs,
- LogCancelContractEventArgs,
- ExchangeEvents,
+ SignedOrder,
TokenEvents,
+ TransferContractEventArgs,
+ Web3Provider,
ZeroExError,
- ExchangeContractErrs,
} from '../types';
+import {AbiDecoder} from '../utils/abi_decoder';
+import {assert} from '../utils/assert';
+import {intervalUtils} from '../utils/interval_utils';
+import {OrderStateUtils} from '../utils/order_state_utils';
+import {utils} from '../utils/utils';
import {Web3Wrapper} from '../web3_wrapper';
-import {TokenWrapper} from '../contract_wrappers/token_wrapper';
-import {ExchangeWrapper} from '../contract_wrappers/exchange_wrapper';
-import {OrderFilledCancelledLazyStore} from '../stores/order_filled_cancelled_lazy_store';
-import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store';
+
+import {EventWatcher} from './event_watcher';
import {ExpirationWatcher} from './expiration_watcher';
interface DependentOrderHashes {
[makerAddress: string]: {
- [makerToken: string]: Set<string>,
+ [makerToken: string]: Set<string>;
};
}
@@ -96,12 +98,12 @@ export class OrderStateWatcher {
* signature is verified.
* @param signedOrder The order you wish to start watching.
*/
- public async addOrderAsync(signedOrder: SignedOrder): Promise<void> {
+ public addOrder(signedOrder: SignedOrder): void {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker);
this._orderByOrderHash[orderHash] = signedOrder;
- await this.addToDependentOrderHashesAsync(signedOrder, orderHash);
+ this.addToDependentOrderHashes(signedOrder, orderHash);
const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(1000);
this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs);
}
@@ -109,7 +111,7 @@ export class OrderStateWatcher {
* Removes an order from the orderStateWatcher
* @param orderHash The orderHash of the order you wish to stop watching.
*/
- public async removeOrderAsync(orderHash: string): Promise<void> {
+ public removeOrder(orderHash: string): void {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const signedOrder = this._orderByOrderHash[orderHash];
if (_.isUndefined(signedOrder)) {
@@ -118,7 +120,7 @@ export class OrderStateWatcher {
delete this._orderByOrderHash[orderHash];
delete this._orderStateByOrderHashCache[orderHash];
const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
- const zrxTokenAddress = await exchange.getZRXTokenAddressAsync();
+ const zrxTokenAddress = exchange.getZRXTokenAddress();
this.removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
this._expirationWatcher.removeOrder(orderHash);
@@ -136,7 +138,7 @@ export class OrderStateWatcher {
}
this._callbackIfExists = callback;
this._eventWatcher.subscribe(this._onEventWatcherCallbackAsync.bind(this));
- this._expirationWatcher.subscribe(this._onOrderExpiredAsync.bind(this));
+ this._expirationWatcher.subscribe(this._onOrderExpired.bind(this));
}
/**
* Ends an orderStateWatcher subscription.
@@ -151,14 +153,14 @@ export class OrderStateWatcher {
this._eventWatcher.unsubscribe();
this._expirationWatcher.unsubscribe();
}
- private async _onOrderExpiredAsync(orderHash: string): Promise<void> {
+ private _onOrderExpired(orderHash: string): void {
const orderState: OrderState = {
isValid: false,
orderHash,
error: ExchangeContractErrs.OrderFillExpired,
};
if (!_.isUndefined(this._orderByOrderHash[orderHash])) {
- await this.removeOrderAsync(orderHash);
+ this.removeOrder(orderHash);
if (!_.isUndefined(this._callbackIfExists)) {
this._callbackIfExists(orderState);
}
@@ -240,7 +242,7 @@ export class OrderStateWatcher {
}
private async _emitRevalidateOrdersAsync(orderHashes: string[]): Promise<void> {
for (const orderHash of orderHashes) {
- const signedOrder = this._orderByOrderHash[orderHash] as SignedOrder;
+ const signedOrder = this._orderByOrderHash[orderHash];
// Most of these calls will never reach the network because the data is fetched from stores
// and only updated when cache is invalidated
const orderState = await this._orderStateUtils.getOrderStateAsync(signedOrder);
@@ -256,7 +258,7 @@ export class OrderStateWatcher {
this._callbackIfExists(orderState);
}
}
- private async addToDependentOrderHashesAsync(signedOrder: SignedOrder, orderHash: string): Promise<void> {
+ private addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): void {
if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker])) {
this._dependentOrderHashes[signedOrder.maker] = {};
}
@@ -265,7 +267,7 @@ export class OrderStateWatcher {
}
this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].add(orderHash);
const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
- const zrxTokenAddress = await exchange.getZRXTokenAddressAsync();
+ const zrxTokenAddress = exchange.getZRXTokenAddress();
if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress])) {
this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress] = new Set();
}
diff --git a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
index c77d4428c..e8601e678 100644
--- a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
+++ b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
@@ -1,6 +1,7 @@
-import {SignedOrder} from '../types';
import {BigNumber} from 'bignumber.js';
+import {SignedOrder} from '../types';
+
export class RemainingFillableCalculator {
private signedOrder: SignedOrder;
private isMakerTokenZRX: boolean;