diff options
-rw-r--r-- | packages/0x.js/src/utils/order_state_utils.ts | 32 | ||||
-rw-r--r-- | packages/0x.js/test/order_state_watcher_test.ts | 2 |
2 files changed, 17 insertions, 17 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); diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts index 9d432a713..7be552e7a 100644 --- a/packages/0x.js/test/order_state_watcher_test.ts +++ b/packages/0x.js/test/order_state_watcher_test.ts @@ -32,7 +32,7 @@ chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(); -describe('OrderStateWatcher', () => { +describe.only('OrderStateWatcher', () => { let web3: Web3; let zeroEx: ZeroEx; let tokens: Token[]; |