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/src | |
parent | 9133e764a504f07fd0059334abc5f31ee2c4c59c (diff) | |
download | dexon-sol-tools-cf7727debc5ae030795a876a316668e83891cdbf.tar.gz dexon-sol-tools-cf7727debc5ae030795a876a316668e83891cdbf.tar.zst dexon-sol-tools-cf7727debc5ae030795a876a316668e83891cdbf.zip |
refactor up
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/utils/order_state_utils.ts | 32 |
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); |