aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/utils')
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts32
1 files changed, 16 insertions, 16 deletions
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index c68eaf85d..4c1bef64e 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -83,10 +83,18 @@ export class OrderStateUtils {
const transferrableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
const transferrableFeeTokenAmount = BigNumber.min([makerFeeProxyAllowance, makerFeeBalance]);
- const remainingFillableMakerTokenAmount = this.calculateFillableMakerTokenAmount(
- transferrableMakerTokenAmount, transferrableFeeTokenAmount, remainingMakerTokenAmount,
- remainingFeeTokenAmount, totalMakerTokenAmount, signedOrder.makerFee, signedOrder.makerTokenAddress,
- zrxTokenAddress);
+ let remainingFillableMakerTokenAmount;
+ if (signedOrder.makerFee.isZero() ||
+ (transferrableFeeTokenAmount.greaterThanOrEqualTo(signedOrder.makerFee) &&
+ transferrableMakerTokenAmount.greaterThanOrEqualTo(remainingMakerTokenAmount) &&
+ signedOrder.makerTokenAddress !== zrxTokenAddress)) {
+ remainingFillableMakerTokenAmount = transferrableMakerTokenAmount;
+ } else {
+ remainingFillableMakerTokenAmount = this.calculatePartiallyFillableMakerTokenAmount(
+ transferrableMakerTokenAmount, transferrableFeeTokenAmount, remainingMakerTokenAmount,
+ remainingFeeTokenAmount, totalMakerTokenAmount, signedOrder.makerFee, signedOrder.makerTokenAddress,
+ zrxTokenAddress);
+ }
const remainingFillableTakerTokenAmount = remainingFillableMakerTokenAmount
.times(totalTakerTokenAmount)
@@ -103,18 +111,10 @@ export class OrderStateUtils {
};
return orderRelevantState;
}
- private calculateFillableMakerTokenAmount(makerTransferrable: BigNumber, makerFeeTransferrable: BigNumber,
- remainingMakerAmount: BigNumber, remainingMakerFee: BigNumber,
- totalMakerAmount: BigNumber, makerFee: BigNumber,
- makerTokenAddress: string, zrxTokenAddress: string): BigNumber {
- if (makerFee.isZero()) {
- return BigNumber.min(makerTransferrable, remainingMakerAmount);
- }
- if (makerFeeTransferrable.greaterThanOrEqualTo(makerFee) &&
- makerTransferrable.greaterThanOrEqualTo(remainingMakerAmount) &&
- makerTokenAddress !== zrxTokenAddress) {
- return BigNumber.min(makerTransferrable, remainingMakerAmount);
- }
+ private calculatePartiallyFillableMakerTokenAmount(makerTransferrable: BigNumber, makerFeeTransferrable: BigNumber,
+ remainingMakerAmount: BigNumber, remainingMakerFee: BigNumber,
+ totalMakerAmount: BigNumber, makerFee: BigNumber,
+ makerTokenAddress: string, zrxTokenAddress: string): BigNumber {
const orderToFeeRatio = totalMakerAmount.dividedToIntegerBy(makerFee);
let fillableTimesInMakerToken = makerTransferrable.dividedToIntegerBy(orderToFeeRatio);
const fillableTimesInFeeToken = BigNumber.min(makerFeeTransferrable, remainingMakerFee);