aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2017-12-20 13:44:08 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 22:30:25 +0800
commitcb11aec84df346d5180c7d5874859c1c34f0bf1c (patch)
treeb959a65bdcfc3e8b01dca1bc160f93a0df8a4bf9 /packages/0x.js/src/order_watcher
parent972e1675f6490bc10e8d9fd64cce2f7945cd4840 (diff)
downloaddexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.gz
dexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.zst
dexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.zip
Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors
Diffstat (limited to 'packages/0x.js/src/order_watcher')
-rw-r--r--packages/0x.js/src/order_watcher/expiration_watcher.ts56
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts10
-rw-r--r--packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts76
3 files changed, 71 insertions, 71 deletions
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts
index 91e8151fd..e71f11129 100644
--- a/packages/0x.js/src/order_watcher/expiration_watcher.ts
+++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts
@@ -14,62 +14,62 @@ const DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS = 50;
* It stores them in a min heap by expiration time and checks for expired ones every `orderExpirationCheckingIntervalMs`
*/
export class ExpirationWatcher {
- private orderHashByExpirationRBTree: RBTree<string>;
- private expiration: {[orderHash: string]: BigNumber} = {};
- private orderExpirationCheckingIntervalMs: number;
- private expirationMarginMs: number;
- private orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer;
+ private _orderHashByExpirationRBTree: RBTree<string>;
+ private _expiration: {[orderHash: string]: BigNumber} = {};
+ private _orderExpirationCheckingIntervalMs: number;
+ private _expirationMarginMs: number;
+ private _orderExpirationCheckingIntervalIdIfExists?: NodeJS.Timer;
constructor(expirationMarginIfExistsMs?: number,
orderExpirationCheckingIntervalIfExistsMs?: number) {
- this.expirationMarginMs = expirationMarginIfExistsMs ||
+ this._expirationMarginMs = expirationMarginIfExistsMs ||
DEFAULT_EXPIRATION_MARGIN_MS;
- this.orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs ||
+ this._orderExpirationCheckingIntervalMs = expirationMarginIfExistsMs ||
DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS;
- const scoreFunction = (orderHash: string) => this.expiration[orderHash].toNumber();
+ const scoreFunction = (orderHash: string) => this._expiration[orderHash].toNumber();
const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs);
- this.orderHashByExpirationRBTree = new RBTree(comparator);
+ this._orderHashByExpirationRBTree = new RBTree(comparator);
}
public subscribe(callback: (orderHash: string) => void): void {
- if (!_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) {
+ if (!_.isUndefined(this._orderExpirationCheckingIntervalIdIfExists)) {
throw new Error(ZeroExError.SubscriptionAlreadyPresent);
}
- this.orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
- this.pruneExpiredOrders.bind(this, callback), this.orderExpirationCheckingIntervalMs,
+ this._orderExpirationCheckingIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
+ this._pruneExpiredOrders.bind(this, callback), this._orderExpirationCheckingIntervalMs,
);
}
public unsubscribe(): void {
- if (_.isUndefined(this.orderExpirationCheckingIntervalIdIfExists)) {
+ if (_.isUndefined(this._orderExpirationCheckingIntervalIdIfExists)) {
throw new Error(ZeroExError.SubscriptionNotFound);
}
- intervalUtils.clearAsyncExcludingInterval(this.orderExpirationCheckingIntervalIdIfExists);
- delete this.orderExpirationCheckingIntervalIdIfExists;
+ intervalUtils.clearAsyncExcludingInterval(this._orderExpirationCheckingIntervalIdIfExists);
+ delete this._orderExpirationCheckingIntervalIdIfExists;
}
public addOrder(orderHash: string, expirationUnixTimestampMs: BigNumber): void {
- this.expiration[orderHash] = expirationUnixTimestampMs;
- this.orderHashByExpirationRBTree.insert(orderHash);
+ this._expiration[orderHash] = expirationUnixTimestampMs;
+ this._orderHashByExpirationRBTree.insert(orderHash);
}
public removeOrder(orderHash: string): void {
- this.orderHashByExpirationRBTree.remove(orderHash);
- delete this.expiration[orderHash];
+ this._orderHashByExpirationRBTree.remove(orderHash);
+ delete this._expiration[orderHash];
}
- private pruneExpiredOrders(callback: (orderHash: string) => void): void {
+ private _pruneExpiredOrders(callback: (orderHash: string) => void): void {
const currentUnixTimestampMs = utils.getCurrentUnixTimestampMs();
while (true) {
- const hasTrakedOrders = this.orderHashByExpirationRBTree.size === 0;
+ const hasTrakedOrders = this._orderHashByExpirationRBTree.size === 0;
if (hasTrakedOrders) {
break;
}
- const nextOrderHashToExpire = this.orderHashByExpirationRBTree.min();
- const hasNoExpiredOrders = this.expiration[nextOrderHashToExpire].greaterThan(
- currentUnixTimestampMs.plus(this.expirationMarginMs),
+ const nextOrderHashToExpire = this._orderHashByExpirationRBTree.min();
+ const hasNoExpiredOrders = this._expiration[nextOrderHashToExpire].greaterThan(
+ currentUnixTimestampMs.plus(this._expirationMarginMs),
);
- const isSubscriptionActive = _.isUndefined(this.orderExpirationCheckingIntervalIdIfExists);
+ const isSubscriptionActive = _.isUndefined(this._orderExpirationCheckingIntervalIdIfExists);
if (hasNoExpiredOrders || isSubscriptionActive) {
break;
}
- const orderHash = this.orderHashByExpirationRBTree.min();
- this.orderHashByExpirationRBTree.remove(orderHash);
- delete this.expiration[orderHash];
+ const orderHash = this._orderHashByExpirationRBTree.min();
+ this._orderHashByExpirationRBTree.remove(orderHash);
+ delete this._expiration[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 c4a9eb1ad..bba01eb43 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -108,7 +108,7 @@ export class OrderStateWatcher {
const orderHash = ZeroEx.getOrderHashHex(signedOrder);
assert.isValidSignature(orderHash, signedOrder.ecSignature, signedOrder.maker);
this._orderByOrderHash[orderHash] = signedOrder;
- this.addToDependentOrderHashes(signedOrder, orderHash);
+ this._addToDependentOrderHashes(signedOrder, orderHash);
const expirationUnixTimestampMs = signedOrder.expirationUnixTimestampSec.times(1000);
this._expirationWatcher.addOrder(orderHash, expirationUnixTimestampMs);
}
@@ -126,8 +126,8 @@ export class OrderStateWatcher {
delete this._orderStateByOrderHashCache[orderHash];
const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
const zrxTokenAddress = exchange.getZRXTokenAddress();
- this.removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
- this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
+ this._removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
+ this._removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
this._expirationWatcher.removeOrder(orderHash);
}
/**
@@ -294,7 +294,7 @@ export class OrderStateWatcher {
this._callbackIfExists(orderState);
}
}
- private addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): void {
+ private _addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): void {
if (_.isUndefined(this._dependentOrderHashes[signedOrder.maker])) {
this._dependentOrderHashes[signedOrder.maker] = {};
}
@@ -308,7 +308,7 @@ export class OrderStateWatcher {
}
this._dependentOrderHashes[signedOrder.maker][zrxTokenAddress].add(orderHash);
}
- private removeFromDependentOrderHashes(makerAddress: string, tokenAddress: string, orderHash: string) {
+ private _removeFromDependentOrderHashes(makerAddress: string, tokenAddress: string, orderHash: string) {
this._dependentOrderHashes[makerAddress][tokenAddress].delete(orderHash);
if (this._dependentOrderHashes[makerAddress][tokenAddress].size === 0) {
delete this._dependentOrderHashes[makerAddress][tokenAddress];
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 e8601e678..ddf3b763b 100644
--- a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
+++ b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
@@ -3,69 +3,69 @@ import {BigNumber} from 'bignumber.js';
import {SignedOrder} from '../types';
export class RemainingFillableCalculator {
- private signedOrder: SignedOrder;
- private isMakerTokenZRX: boolean;
+ private _signedOrder: SignedOrder;
+ private _isMakerTokenZRX: boolean;
// Transferrable Amount is the minimum of Approval and Balance
- private transferrableMakerTokenAmount: BigNumber;
- private transferrableMakerFeeTokenAmount: BigNumber;
- private remainingMakerTokenAmount: BigNumber;
- private remainingMakerFeeAmount: BigNumber;
+ private _transferrableMakerTokenAmount: BigNumber;
+ private _transferrableMakerFeeTokenAmount: BigNumber;
+ private _remainingMakerTokenAmount: BigNumber;
+ private _remainingMakerFeeAmount: BigNumber;
constructor(signedOrder: SignedOrder,
isMakerTokenZRX: boolean,
transferrableMakerTokenAmount: BigNumber,
transferrableMakerFeeTokenAmount: BigNumber,
remainingMakerTokenAmount: BigNumber) {
- this.signedOrder = signedOrder;
- this.isMakerTokenZRX = isMakerTokenZRX;
- this.transferrableMakerTokenAmount = transferrableMakerTokenAmount;
- this.transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
- this.remainingMakerTokenAmount = remainingMakerTokenAmount;
- this.remainingMakerFeeAmount = remainingMakerTokenAmount.times(signedOrder.makerFee)
+ this._signedOrder = signedOrder;
+ this._isMakerTokenZRX = isMakerTokenZRX;
+ this._transferrableMakerTokenAmount = transferrableMakerTokenAmount;
+ this._transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
+ this._remainingMakerTokenAmount = remainingMakerTokenAmount;
+ this._remainingMakerFeeAmount = remainingMakerTokenAmount.times(signedOrder.makerFee)
.dividedToIntegerBy(signedOrder.makerTokenAmount);
}
public computeRemainingMakerFillable(): BigNumber {
- if (this.hasSufficientFundsForFeeAndTransferAmount()) {
- return this.remainingMakerTokenAmount;
+ if (this._hasSufficientFundsForFeeAndTransferAmount()) {
+ return this._remainingMakerTokenAmount;
}
- if (this.signedOrder.makerFee.isZero()) {
- return BigNumber.min(this.remainingMakerTokenAmount, this.transferrableMakerTokenAmount);
+ if (this._signedOrder.makerFee.isZero()) {
+ return BigNumber.min(this._remainingMakerTokenAmount, this._transferrableMakerTokenAmount);
}
- return this.calculatePartiallyFillableMakerTokenAmount();
+ return this._calculatePartiallyFillableMakerTokenAmount();
}
public computeRemainingTakerFillable(): BigNumber {
- return this.computeRemainingMakerFillable().times(this.signedOrder.takerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerTokenAmount);
+ return this.computeRemainingMakerFillable().times(this._signedOrder.takerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerTokenAmount);
}
- private hasSufficientFundsForFeeAndTransferAmount(): boolean {
- if (this.isMakerTokenZRX) {
- const totalZRXTransferAmountRequired = this.remainingMakerTokenAmount.plus(this.remainingMakerFeeAmount);
- const hasSufficientFunds = this.transferrableMakerTokenAmount.greaterThanOrEqualTo(
+ private _hasSufficientFundsForFeeAndTransferAmount(): boolean {
+ if (this._isMakerTokenZRX) {
+ const totalZRXTransferAmountRequired = this._remainingMakerTokenAmount.plus(this._remainingMakerFeeAmount);
+ const hasSufficientFunds = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
totalZRXTransferAmountRequired);
return hasSufficientFunds;
} else {
- const hasSufficientFundsForTransferAmount = this.transferrableMakerTokenAmount.greaterThanOrEqualTo(
- this.remainingMakerTokenAmount);
- const hasSufficientFundsForFeeAmount = this.transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
- this.remainingMakerFeeAmount);
+ const hasSufficientFundsForTransferAmount = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
+ this._remainingMakerTokenAmount);
+ const hasSufficientFundsForFeeAmount = this._transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
+ this._remainingMakerFeeAmount);
const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount;
return hasSufficientFunds;
}
}
- private calculatePartiallyFillableMakerTokenAmount(): BigNumber {
+ private _calculatePartiallyFillableMakerTokenAmount(): BigNumber {
// Given an order for 200 wei for 2 ZRXwei fee, find 100 wei for 1 ZRXwei. Order ratio is then 100:1
- const orderToFeeRatio = this.signedOrder.makerTokenAmount.dividedBy(this.signedOrder.makerFee);
+ const orderToFeeRatio = this._signedOrder.makerTokenAmount.dividedBy(this._signedOrder.makerFee);
// The number of times the maker can fill the order, if each fill only required the transfer of a single
// baseUnit of fee tokens.
// Given 2 ZRXwei, the maximum amount of times Maker can fill this order, in terms of fees, is 2
- const fillableTimesInFeeTokenBaseUnits = BigNumber.min(this.transferrableMakerFeeTokenAmount,
- this.remainingMakerFeeAmount);
+ const fillableTimesInFeeTokenBaseUnits = BigNumber.min(this._transferrableMakerFeeTokenAmount,
+ this._remainingMakerFeeAmount);
// The number of times the Maker can fill the order, given the Maker Token Balance
// Assuming a balance of 150 wei, and an orderToFeeRatio of 100:1, maker can fill this order 1 time.
- let fillableTimesInMakerTokenUnits = this.transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
- if (this.isMakerTokenZRX) {
+ let fillableTimesInMakerTokenUnits = this._transferrableMakerTokenAmount.dividedBy(orderToFeeRatio);
+ if (this._isMakerTokenZRX) {
// If ZRX is the maker token, the Fee and the Maker amount need to be removed from the same pool;
// 200 ZRXwei for 2ZRXwei fee can only be filled once (need 202 ZRXwei)
- const totalZRXTokenPooled = this.transferrableMakerTokenAmount;
+ const totalZRXTokenPooled = this._transferrableMakerTokenAmount;
// The purchasing power here is less as the tokens are taken from the same Pool
// For every one number of fills, we have to take an extra ZRX out of the pool
fillableTimesInMakerTokenUnits = totalZRXTokenPooled.dividedBy(
@@ -75,11 +75,11 @@ export class RemainingFillableCalculator {
// When Ratio is not fully divisible there can be remainders which cannot be represented, so they are floored.
// This can result in a RoundingError being thrown by the Exchange Contract.
const partiallyFillableMakerTokenAmount = fillableTimesInMakerTokenUnits
- .times(this.signedOrder.makerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerFee);
+ .times(this._signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableFeeTokenAmount = fillableTimesInFeeTokenBaseUnits
- .times(this.signedOrder.makerTokenAmount)
- .dividedToIntegerBy(this.signedOrder.makerFee);
+ .times(this._signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerFee);
const partiallyFillableAmount = BigNumber.min(partiallyFillableMakerTokenAmount,
partiallyFillableFeeTokenAmount);
return partiallyFillableAmount;