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.ts34
1 files changed, 31 insertions, 3 deletions
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index 123584f90..e11435f1d 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -78,12 +78,19 @@ export class OrderStateUtils {
const remainingTakerTokenAmount = totalTakerTokenAmount.minus(unavailableTakerTokenAmount);
const remainingMakerTokenAmount = remainingTakerTokenAmount.times(totalMakerTokenAmount)
.dividedToIntegerBy(totalTakerTokenAmount);
- const fillableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
- const remainingFillableMakerTokenAmount = BigNumber.min(fillableMakerTokenAmount, remainingMakerTokenAmount);
+ const remainingFeeTokenAmount = remainingTakerTokenAmount.times(signedOrder.makerFee)
+ .dividedToIntegerBy(totalTakerTokenAmount);
+ 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);
+
const remainingFillableTakerTokenAmount = remainingFillableMakerTokenAmount
.times(totalTakerTokenAmount)
.dividedToIntegerBy(totalMakerTokenAmount);
- // TODO: Handle edge case where maker token is ZRX with fee
const orderRelevantState = {
makerBalance,
makerProxyAllowance,
@@ -96,6 +103,27 @@ 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);
+ }
+ const orderToFeeRatio = totalMakerAmount.dividedToIntegerBy(makerFee);
+ console.log('Order to Fee Ratio: ', orderToFeeRatio.toString());
+ let fillableTimesInMakerToken = makerTransferrable.dividedToIntegerBy(orderToFeeRatio);
+ console.log('Fillable Token Times: ', fillableTimesInMakerToken.toString());
+ const fillableTimesInFeeToken = BigNumber.min(makerFeeTransferrable, remainingMakerFee);
+ console.log('Fillable Fee Times: ', fillableTimesInFeeToken.toString());
+ if (makerTokenAddress === zrxTokenAddress) {
+ fillableTimesInMakerToken = makerTransferrable.plus(makerFeeTransferrable)
+ .dividedToIntegerBy(orderToFeeRatio.plus(new BigNumber(1)));
+
+ }
+ return BigNumber.min(fillableTimesInMakerToken.times(orderToFeeRatio),
+ fillableTimesInFeeToken.times(orderToFeeRatio));
+ }
private validateIfOrderIsValid(signedOrder: SignedOrder, orderRelevantState: OrderRelevantState): void {
const unavailableTakerTokenAmount = orderRelevantState.cancelledTakerTokenAmount.add(
orderRelevantState.filledTakerTokenAmount,