diff options
author | Jacob Evans <jacob@dekz.net> | 2017-11-16 05:37:02 +0800 |
---|---|---|
committer | Jacob Evans <jacob@dekz.net> | 2017-11-16 05:37:02 +0800 |
commit | cf7727debc5ae030795a876a316668e83891cdbf (patch) | |
tree | e0aff2408cdd889e022a9ba793e25607248e72bb /packages/0x.js | |
parent | 9133e764a504f07fd0059334abc5f31ee2c4c59c (diff) | |
download | dexon-0x-contracts-cf7727debc5ae030795a876a316668e83891cdbf.tar.gz dexon-0x-contracts-cf7727debc5ae030795a876a316668e83891cdbf.tar.zst dexon-0x-contracts-cf7727debc5ae030795a876a316668e83891cdbf.zip |
refactor up
Diffstat (limited to 'packages/0x.js')
-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[]; |