From f936363440bce82f544dc50b41056e09c5bcc9fd Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 13 Nov 2017 18:09:18 -0500 Subject: Add validation for rounding error --- packages/0x.js/src/utils/order_state_utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'packages') diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts index cc4933d39..21d842a77 100644 --- a/packages/0x.js/src/utils/order_state_utils.ts +++ b/packages/0x.js/src/utils/order_state_utils.ts @@ -117,6 +117,13 @@ export class OrderStateUtils { throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance); } } + const minimumFillableTakerTokenAmountWithingNoRoundingErrorRange = signedOrder.takerTokenAmount + .times(1000) + .dividedBy(signedOrder.makerTokenAmount); + if (orderRelevantState.remainingFillableTakerTokenAmount + .lessThan(minimumFillableTakerTokenAmountWithingNoRoundingErrorRange)) { + throw new Error(ExchangeContractErrs.OrderFillRoundingError); + } // TODO Add linear function solver when maker token is ZRX #badass // Return the max amount that's fillable } -- cgit v1.2.3