diff options
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/order_watcher/remaining_fillable_calculator.ts | 23 | ||||
-rw-r--r-- | packages/0x.js/src/utils/order_state_utils.ts | 3 |
2 files changed, 15 insertions, 11 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); } } diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index 9ff26a7f1..1d8f02a18 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -82,8 +82,9 @@ export class OrderStateUtils { const transferrableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]); const transferrableFeeTokenAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]); + const isMakerTokenZRX = signedOrder.makerTokenAddress === zrxTokenAddress; const remainingFillableCalculator = new RemainingFillableCalculator(signedOrder, - zrxTokenAddress, + isMakerTokenZRX, transferrableMakerTokenAmount, transferrableFeeTokenAmount, remainingMakerTokenAmount); |