aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts6
-rw-r--r--packages/0x.js/test/order_state_watcher_test.ts28
2 files changed, 32 insertions, 2 deletions
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index 69e749952..d1b2feb43 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -110,7 +110,13 @@ export class OrderStateUtils {
if (makerFee.isZero()) {
return BigNumber.min(makerTransferrable, remainingMakerAmount);
}
+ if (makerFeeTransferrable.greaterThanOrEqualTo(makerFee) &&
+ makerTransferrable.greaterThanOrEqualTo(remainingMakerAmount) &&
+ makerTokenAddress !== zrxTokenAddress) {
+ return BigNumber.min(makerTransferrable, remainingMakerAmount);
+ }
const orderToFeeRatio = totalMakerAmount.dividedToIntegerBy(makerFee);
+ console.log('order to fee ratio: ', orderToFeeRatio.toString());
let fillableTimesInMakerToken = makerTransferrable.dividedToIntegerBy(orderToFeeRatio);
const fillableTimesInFeeToken = BigNumber.min(makerFeeTransferrable, remainingMakerFee);
if (makerTokenAddress === zrxTokenAddress) {
diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts
index ac77ce4d7..fef7b5d13 100644
--- a/packages/0x.js/test/order_state_watcher_test.ts
+++ b/packages/0x.js/test/order_state_watcher_test.ts
@@ -335,8 +335,8 @@ describe('OrderStateWatcher', () => {
const remainingFeeAmount = ZeroEx.toBaseUnitAmount(new BigNumber(3), 18);
const transferFeeAmount = makerFee.sub(remainingFeeAmount);
- const remainingTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18);
- const transferTokenAmount = makerFee.sub(remainingFeeAmount);
+ const remainingTokenAmount = ZeroEx.toBaseUnitAmount(new BigNumber(4), 18);
+ const transferTokenAmount = makerFee.sub(remainingTokenAmount);
zeroEx.orderStateWatcher.addOrder(signedOrder);
const callback = reportCallbackErrors(done)((orderState: OrderState) => {
@@ -352,6 +352,30 @@ describe('OrderStateWatcher', () => {
makerToken.address, maker, ZeroEx.NULL_ADDRESS, transferTokenAmount);
})().catch(done);
});
+ it('should calculate full amount when all available and non-divisible', (done: DoneCallback) => {
+ (async () => {
+ const takerFee = ZeroEx.toBaseUnitAmount(new BigNumber(0), 18);
+ const makerFee = ZeroEx.toBaseUnitAmount(new BigNumber(2), 18);
+ const feeRecipient = taker;
+ signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync(
+ makerToken.address, takerToken.address, makerFee, takerFee, maker,
+ taker, fillableAmount, feeRecipient);
+
+ const makerBalance = await zeroEx.token.getBalanceAsync(makerToken.address, maker);
+ zeroEx.orderStateWatcher.addOrder(signedOrder);
+
+ const callback = reportCallbackErrors(done)((orderState: OrderState) => {
+ const validOrderState = orderState as OrderStateValid;
+ const orderRelevantState = validOrderState.orderRelevantState;
+ expect(orderRelevantState.remainingFillableMakerTokenAmount).to.be.bignumber.equal(
+ fillableAmount);
+ done();
+ });
+ zeroEx.orderStateWatcher.subscribe(callback);
+ await zeroEx.token.setProxyAllowanceAsync(
+ makerToken.address, maker, ZeroEx.toBaseUnitAmount(new BigNumber(100), 18));
+ })().catch(done);
+ });
});
it('should emit orderStateInvalid when watched order cancelled', (done: DoneCallback) => {
(async () => {