aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-08-25 09:54:15 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-08-25 09:54:15 +0800
commitd652deea232417bbef223bde46d8c12e9922b277 (patch)
treef40e28c1231fa6646aae3354f3e58d98fa000e14 /packages/order-utils
parent6b866d60533c7e46446bfb69639b07affd1aeb17 (diff)
parentf938c989e3e07161de20dd865baf59eecdde872d (diff)
downloaddexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar.gz
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar.bz2
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar.lz
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar.xz
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.tar.zst
dexon-sol-tools-d652deea232417bbef223bde46d8c12e9922b277.zip
Merge branch 'fix/contracts/robustMatching' of github.com:0xProject/0x.js into fix/contracts/robustMatching
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/order_state_utils.ts4
-rw-r--r--packages/order-utils/src/order_validation_utils.ts10
-rw-r--r--packages/order-utils/src/utils.ts2
-rw-r--r--packages/order-utils/test/order_validation_utils_test.ts12
4 files changed, 14 insertions, 14 deletions
diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts
index a0e24acf0..8398776aa 100644
--- a/packages/order-utils/src/order_state_utils.ts
+++ b/packages/order-utils/src/order_state_utils.ts
@@ -81,7 +81,7 @@ export class OrderStateUtils {
const remainingTakerAssetAmount = signedOrder.takerAssetAmount.minus(
sidedOrderRelevantState.filledTakerAssetAmount,
);
- const isRoundingError = OrderValidationUtils.isRoundingError(
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(
remainingTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.makerAssetAmount,
@@ -191,7 +191,7 @@ export class OrderStateUtils {
);
const remainingFillableTakerAssetAmountGivenMakersStatus = signedOrder.makerAssetAmount.eq(0)
? new BigNumber(0)
- : utils.getPartialAmount(
+ : utils.getPartialAmountFloor(
orderRelevantMakerState.remainingFillableAssetAmount,
signedOrder.makerAssetAmount,
signedOrder.takerAssetAmount,
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts
index 972e6f6d6..8227fb07c 100644
--- a/packages/order-utils/src/order_validation_utils.ts
+++ b/packages/order-utils/src/order_validation_utils.ts
@@ -24,7 +24,7 @@ export class OrderValidationUtils {
* @param denominator Denominator value. When used to check an order, pass in `order.takerAssetAmount`
* @param target Target value. When used to check an order, pass in `order.makerAssetAmount`
*/
- public static isRoundingError(numerator: BigNumber, denominator: BigNumber, target: BigNumber): boolean {
+ public static isRoundingErrorFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): boolean {
// Solidity's mulmod() in JS
// Source: https://solidity.readthedocs.io/en/latest/units-and-global-variables.html#mathematical-and-cryptographic-functions
if (denominator.eq(0)) {
@@ -58,7 +58,7 @@ export class OrderValidationUtils {
zrxAssetData: string,
): Promise<void> {
try {
- const fillMakerTokenAmount = utils.getPartialAmount(
+ const fillMakerTokenAmount = utils.getPartialAmountFloor(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.makerAssetAmount,
@@ -79,7 +79,7 @@ export class OrderValidationUtils {
TradeSide.Taker,
TransferType.Trade,
);
- const makerFeeAmount = utils.getPartialAmount(
+ const makerFeeAmount = utils.getPartialAmountFloor(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.makerFee,
@@ -92,7 +92,7 @@ export class OrderValidationUtils {
TradeSide.Maker,
TransferType.Fee,
);
- const takerFeeAmount = utils.getPartialAmount(
+ const takerFeeAmount = utils.getPartialAmountFloor(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.takerFee,
@@ -218,7 +218,7 @@ export class OrderValidationUtils {
zrxAssetData,
);
- const wouldRoundingErrorOccur = OrderValidationUtils.isRoundingError(
+ const wouldRoundingErrorOccur = OrderValidationUtils.isRoundingErrorFloor(
desiredFillTakerTokenAmount,
signedOrder.takerAssetAmount,
signedOrder.makerAssetAmount,
diff --git a/packages/order-utils/src/utils.ts b/packages/order-utils/src/utils.ts
index 7aaaf0609..0ff05e8ed 100644
--- a/packages/order-utils/src/utils.ts
+++ b/packages/order-utils/src/utils.ts
@@ -12,7 +12,7 @@ export const utils = {
const milisecondsInSecond = 1000;
return new BigNumber(Date.now() / milisecondsInSecond).round();
},
- getPartialAmount(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
+ getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
const fillMakerTokenAmount = numerator
.mul(target)
.div(denominator)
diff --git a/packages/order-utils/test/order_validation_utils_test.ts b/packages/order-utils/test/order_validation_utils_test.ts
index d3ff867d7..d3133c0a6 100644
--- a/packages/order-utils/test/order_validation_utils_test.ts
+++ b/packages/order-utils/test/order_validation_utils_test.ts
@@ -16,7 +16,7 @@ describe('OrderValidationUtils', () => {
const denominator = new BigNumber(999);
const target = new BigNumber(50);
// rounding error = ((20*50/999) - floor(20*50/999)) / (20*50/999) = 0.1%
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.false();
});
@@ -25,7 +25,7 @@ describe('OrderValidationUtils', () => {
const denominator = new BigNumber(9991);
const target = new BigNumber(500);
// rounding error = ((20*500/9991) - floor(20*500/9991)) / (20*500/9991) = 0.09%
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.false();
});
@@ -34,7 +34,7 @@ describe('OrderValidationUtils', () => {
const denominator = new BigNumber(9989);
const target = new BigNumber(500);
// rounding error = ((20*500/9989) - floor(20*500/9989)) / (20*500/9989) = 0.011%
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.true();
});
@@ -43,7 +43,7 @@ describe('OrderValidationUtils', () => {
const denominator = new BigNumber(7);
const target = new BigNumber(10);
// rounding error = ((3*10/7) - floor(3*10/7)) / (3*10/7) = 6.67%
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.true();
});
@@ -52,7 +52,7 @@ describe('OrderValidationUtils', () => {
const denominator = new BigNumber(2);
const target = new BigNumber(10);
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.false();
});
@@ -63,7 +63,7 @@ describe('OrderValidationUtils', () => {
const target = new BigNumber(105762562);
// rounding error = ((76564*105762562/676373677) - floor(76564*105762562/676373677)) /
// (76564*105762562/676373677) = 0.0007%
- const isRoundingError = OrderValidationUtils.isRoundingError(numerator, denominator, target);
+ const isRoundingError = OrderValidationUtils.isRoundingErrorFloor(numerator, denominator, target);
expect(isRoundingError).to.be.false();
});
});