aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2017-11-15 07:15:54 +0800
committerGitHub <noreply@github.com>2017-11-15 07:15:54 +0800
commitc019280e852eaaa7a3b554d520a5bd3e6b4c3940 (patch)
tree75bf5180448148c66b295f63aa30bf258e3a05dd /packages/0x.js/src
parentff0b0ae1ab87f174862e167484bb601c700066be (diff)
parentdcfe8bae1cf0dfa483ad0a3e8800dcb2b38940c7 (diff)
downloaddexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar.gz
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar.bz2
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar.lz
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar.xz
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.tar.zst
dexon-sol-tools-c019280e852eaaa7a3b554d520a5bd3e6b4c3940.zip
Merge pull request #219 from 0xProject/feature/rounding-validation
Rounding validation
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/types.ts1
-rw-r--r--packages/0x.js/src/utils/order_state_utils.ts13
2 files changed, 14 insertions, 0 deletions
diff --git a/packages/0x.js/src/types.ts b/packages/0x.js/src/types.ts
index 11b5d8569..71089f9a1 100644
--- a/packages/0x.js/src/types.ts
+++ b/packages/0x.js/src/types.ts
@@ -490,6 +490,7 @@ export interface OrderRelevantState {
filledTakerTokenAmount: BigNumber;
cancelledTakerTokenAmount: BigNumber;
remainingFillableMakerTokenAmount: BigNumber;
+ remainingFillableTakerTokenAmount: BigNumber;
}
export interface OrderStateValid {
diff --git a/packages/0x.js/src/utils/order_state_utils.ts b/packages/0x.js/src/utils/order_state_utils.ts
index a1ee7577d..123584f90 100644
--- a/packages/0x.js/src/utils/order_state_utils.ts
+++ b/packages/0x.js/src/utils/order_state_utils.ts
@@ -18,6 +18,8 @@ import {constants} from '../utils/constants';
import {OrderFilledCancelledLazyStore} from '../stores/order_filled_cancelled_lazy_store';
import {BalanceAndProxyAllowanceLazyStore} from '../stores/balance_proxy_allowance_lazy_store';
+const ACCEPTABLE_RELATIVE_ROUNDING_ERROR = 0.0001;
+
export class OrderStateUtils {
private balanceAndProxyAllowanceLazyStore: BalanceAndProxyAllowanceLazyStore;
private orderFilledCancelledLazyStore: OrderFilledCancelledLazyStore;
@@ -78,6 +80,9 @@ export class OrderStateUtils {
.dividedToIntegerBy(totalTakerTokenAmount);
const fillableMakerTokenAmount = BigNumber.min([makerProxyAllowance, makerBalance]);
const remainingFillableMakerTokenAmount = BigNumber.min(fillableMakerTokenAmount, remainingMakerTokenAmount);
+ const remainingFillableTakerTokenAmount = remainingFillableMakerTokenAmount
+ .times(totalTakerTokenAmount)
+ .dividedToIntegerBy(totalMakerTokenAmount);
// TODO: Handle edge case where maker token is ZRX with fee
const orderRelevantState = {
makerBalance,
@@ -87,6 +92,7 @@ export class OrderStateUtils {
filledTakerTokenAmount,
cancelledTakerTokenAmount,
remainingFillableMakerTokenAmount,
+ remainingFillableTakerTokenAmount,
};
return orderRelevantState;
}
@@ -113,6 +119,13 @@ export class OrderStateUtils {
throw new Error(ExchangeContractErrs.InsufficientMakerFeeAllowance);
}
}
+ const minFillableTakerTokenAmountWithinNoRoundingErrorRange = signedOrder.takerTokenAmount
+ .dividedBy(ACCEPTABLE_RELATIVE_ROUNDING_ERROR)
+ .dividedBy(signedOrder.makerTokenAmount);
+ if (orderRelevantState.remainingFillableTakerTokenAmount
+ .lessThan(minFillableTakerTokenAmountWithinNoRoundingErrorRange)) {
+ throw new Error(ExchangeContractErrs.OrderFillRoundingError);
+ }
// TODO Add linear function solver when maker token is ZRX #badass
// Return the max amount that's fillable
}