aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-23 15:47:03 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-10-24 23:31:59 +0800
commitfbe34663da84ee798bb39bfd2144ff16a712413e (patch)
tree639d8f1be89964bee017823c76711de960b9c64f /src
parent9d0ccdfdcc2ce962d76c406b83b15e520a971eae (diff)
downloaddexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar.gz
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar.bz2
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar.lz
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar.xz
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.tar.zst
dexon-sol-tools-fbe34663da84ee798bb39bfd2144ff16a712413e.zip
Fix the rounding of makerFillAmount and correctly validate partial fees
Diffstat (limited to 'src')
-rw-r--r--src/utils/order_validation_utils.ts43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index 1d9aac884..b7eae7e2f 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -27,13 +27,22 @@ export class OrderValidationUtils {
if (!_.isUndefined(expectedFillTakerTokenAmount)) {
fillTakerTokenAmount = expectedFillTakerTokenAmount;
}
- const fillMakerTokenAmount = this.getFillMakerTokenAmount(signedOrder, fillTakerTokenAmount);
+ const fillMakerTokenAmount = this.getPartialAmount(
+ fillTakerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.makerTokenAmount,
+ );
await exchangeTradeEmulator.transferFromAsync(
signedOrder.makerTokenAddress, signedOrder.maker, signedOrder.taker, fillMakerTokenAmount,
TradeSide.Maker, TransferType.Trade,
);
+ const makerFeeAmount = this.getPartialAmount(
+ fillTakerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.makerFee,
+ );
await exchangeTradeEmulator.transferFromAsync(
- zrxTokenAddress, signedOrder.maker, signedOrder.feeRecipient, signedOrder.makerFee,
+ zrxTokenAddress, signedOrder.maker, signedOrder.feeRecipient, makerFeeAmount,
TradeSide.Maker, TransferType.Fee,
);
}
@@ -100,7 +109,11 @@ export class OrderValidationUtils {
public async validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator, signedOrder: SignedOrder,
fillTakerTokenAmount: BigNumber.BigNumber, senderAddress: string, zrxTokenAddress: string): Promise<void> {
- const fillMakerTokenAmount = this.getFillMakerTokenAmount(signedOrder, fillTakerTokenAmount);
+ const fillMakerTokenAmount = this.getPartialAmount(
+ fillTakerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.makerTokenAmount,
+ );
await exchangeTradeEmulator.transferFromAsync(
signedOrder.makerTokenAddress, signedOrder.maker, senderAddress, fillMakerTokenAmount,
TradeSide.Maker, TransferType.Trade,
@@ -109,12 +122,22 @@ export class OrderValidationUtils {
signedOrder.takerTokenAddress, senderAddress, signedOrder.maker, fillTakerTokenAmount,
TradeSide.Taker, TransferType.Trade,
);
+ const makerFeeAmount = this.getPartialAmount(
+ fillTakerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.makerFee,
+ );
await exchangeTradeEmulator.transferFromAsync(
- zrxTokenAddress, signedOrder.maker, signedOrder.feeRecipient, signedOrder.makerFee, TradeSide.Maker,
+ zrxTokenAddress, signedOrder.maker, signedOrder.feeRecipient, makerFeeAmount, TradeSide.Maker,
TransferType.Fee,
);
+ const takerFeeAmount = this.getPartialAmount(
+ fillTakerTokenAmount,
+ signedOrder.takerTokenAmount,
+ signedOrder.takerFee,
+ );
await exchangeTradeEmulator.transferFromAsync(
- zrxTokenAddress, senderAddress, signedOrder.feeRecipient, signedOrder.takerFee, TradeSide.Taker,
+ zrxTokenAddress, senderAddress, signedOrder.feeRecipient, takerFeeAmount, TradeSide.Taker,
TransferType.Fee,
);
}
@@ -131,10 +154,12 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.OrderFillExpired);
}
}
- private getFillMakerTokenAmount(signedOrder: Order,
- fillTakerTokenAmount: BigNumber.BigNumber): BigNumber.BigNumber {
- const exchangeRate = signedOrder.takerTokenAmount.div(signedOrder.makerTokenAmount);
- const fillMakerTokenAmount = fillTakerTokenAmount.div(exchangeRate);
+ private getPartialAmount(numerator: BigNumber.BigNumber, denominator: BigNumber.BigNumber,
+ target: BigNumber.BigNumber): BigNumber.BigNumber {
+ const fillMakerTokenAmount = numerator
+ .mul(target)
+ .div(denominator)
+ .round(0);
return fillMakerTokenAmount;
}
}