aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2017-11-21 11:51:19 +0800
committerJacob Evans <jacob@dekz.net>2017-11-21 11:51:19 +0800
commitda03331015b810505cfaae1445424f61ce05c656 (patch)
treecd8cb4796882b5a76da176f2419a30cf3037cafa /packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
parent43128234bbb9715094c24c99b6a001a5290fcefd (diff)
downloaddexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar.gz
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar.bz2
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar.lz
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar.xz
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.tar.zst
dexon-0x-contracts-da03331015b810505cfaae1445424f61ce05c656.zip
Unit test edge case for ZRX and ZRX partial fill
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.ts23
1 files changed, 13 insertions, 10 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 fe373eae4..45f60ada3 100644
--- a/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
+++ b/packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts
@@ -10,12 +10,12 @@ export class RemainingFillableCalculator {
private _remainingMakerTokenAmount: BigNumber;
private _remainingMakerFeeAmount: BigNumber;
constructor(signedOrder: SignedOrder,
- zrxAddress: string,
+ isMakerTokenZRX: boolean,
transferrableMakerTokenAmount: BigNumber,
transferrableMakerFeeTokenAmount: BigNumber,
remainingMakerTokenAmount: BigNumber) {
this._signedOrder = signedOrder;
- this._isMakerTokenZRX = signedOrder.makerTokenAddress === zrxAddress;
+ this._isMakerTokenZRX = isMakerTokenZRX;
this._transferrableMakerTokenAmount = transferrableMakerTokenAmount;
this._transferrableMakerFeeTokenAmount = transferrableMakerFeeTokenAmount;
this._remainingMakerTokenAmount = remainingMakerTokenAmount;
@@ -51,18 +51,21 @@ export class RemainingFillableCalculator {
private calculatePartiallyFillableMakerTokenAmount(): BigNumber {
const orderToFeeRatio = this._signedOrder.makerTokenAmount.dividedToIntegerBy(this._signedOrder.makerFee);
- const fillableTimesInFeeToken = BigNumber.min(this._transferrableMakerFeeTokenAmount,
- this._remainingMakerFeeAmount);
- let fillableTimesInMakerToken = this._transferrableMakerTokenAmount.dividedToIntegerBy(orderToFeeRatio);
+ // Maximum number of times the Maker can fill the order, given the fees
+ const fillableTimesInFeeTokenUnits = BigNumber.min(this._transferrableMakerFeeTokenAmount,
+ this._remainingMakerFeeAmount);
+ // Maximum number of times the Maker can fill the order, given the Maker Token Balance
+ let fillableTimesInMakerTokenUnits = this._transferrableMakerTokenAmount.dividedToIntegerBy(orderToFeeRatio);
if (this._isMakerTokenZRX) {
- // when zrx == maker token transferrable maker == transfer
const totalZRXTokenPooled = this._transferrableMakerTokenAmount;
- fillableTimesInMakerToken = totalZRXTokenPooled.dividedToIntegerBy(
- orderToFeeRatio.plus(new BigNumber(1)));
+ // 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.dividedToIntegerBy(
+ orderToFeeRatio.plus(new BigNumber(1)));
}
- const partiallyFillableMakerTokenAmount = fillableTimesInMakerToken.times(orderToFeeRatio);
- const partiallyFillableFeeTokenAmount = fillableTimesInFeeToken.times(orderToFeeRatio);
+ const partiallyFillableMakerTokenAmount = fillableTimesInMakerTokenUnits.times(orderToFeeRatio);
+ const partiallyFillableFeeTokenAmount = fillableTimesInFeeTokenUnits.times(orderToFeeRatio);
return BigNumber.min(partiallyFillableMakerTokenAmount, partiallyFillableFeeTokenAmount);
}
}