aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts')
-rw-r--r--packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts59
1 files changed, 34 insertions, 25 deletions
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 ddf3b763b..2200be0cb 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,6 @@
-import {BigNumber} from 'bignumber.js';
+import { BigNumber } from 'bignumber.js';
-import {SignedOrder} from '../types';
+import { SignedOrder } from '../types';
export class RemainingFillableCalculator {
private _signedOrder: SignedOrder;
@@ -10,18 +10,21 @@ export class RemainingFillableCalculator {
private _transferrableMakerFeeTokenAmount: BigNumber;
private _remainingMakerTokenAmount: BigNumber;
private _remainingMakerFeeAmount: BigNumber;
- constructor(signedOrder: SignedOrder,
- isMakerTokenZRX: boolean,
- transferrableMakerTokenAmount: BigNumber,
- transferrableMakerFeeTokenAmount: BigNumber,
- remainingMakerTokenAmount: 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)
- .dividedToIntegerBy(signedOrder.makerTokenAmount);
+ this._remainingMakerFeeAmount = remainingMakerTokenAmount
+ .times(signedOrder.makerFee)
+ .dividedToIntegerBy(signedOrder.makerTokenAmount);
}
public computeRemainingMakerFillable(): BigNumber {
if (this._hasSufficientFundsForFeeAndTransferAmount()) {
@@ -33,20 +36,24 @@ export class RemainingFillableCalculator {
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(
- totalZRXTransferAmountRequired);
+ totalZRXTransferAmountRequired,
+ );
return hasSufficientFunds;
} else {
const hasSufficientFundsForTransferAmount = this._transferrableMakerTokenAmount.greaterThanOrEqualTo(
- this._remainingMakerTokenAmount);
+ this._remainingMakerTokenAmount,
+ );
const hasSufficientFundsForFeeAmount = this._transferrableMakerFeeTokenAmount.greaterThanOrEqualTo(
- this._remainingMakerFeeAmount);
+ this._remainingMakerFeeAmount,
+ );
const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount;
return hasSufficientFunds;
}
@@ -57,8 +64,10 @@ export class RemainingFillableCalculator {
// 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);
@@ -68,20 +77,20 @@ export class RemainingFillableCalculator {
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(
- orderToFeeRatio.plus(new BigNumber(1)));
-
+ fillableTimesInMakerTokenUnits = totalZRXTokenPooled.dividedBy(orderToFeeRatio.plus(new BigNumber(1)));
}
// 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);
- const partiallyFillableAmount = BigNumber.min(partiallyFillableMakerTokenAmount,
- partiallyFillableFeeTokenAmount);
+ .times(this._signedOrder.makerTokenAmount)
+ .dividedToIntegerBy(this._signedOrder.makerFee);
+ const partiallyFillableAmount = BigNumber.min(
+ partiallyFillableMakerTokenAmount,
+ partiallyFillableFeeTokenAmount,
+ );
return partiallyFillableAmount;
}
}