aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-08-25 08:29:09 +0800
committerGitHub <noreply@github.com>2018-08-25 08:29:09 +0800
commit74ce893f520db6ae4617432975b5c9321ff5b89b (patch)
tree45853fe1c16066290834ee5827b3c269a9fb7734 /packages/order-utils/src
parent94e01be9ed5bfe2d0ace4cd0562fced889b34108 (diff)
parentcc1fac9bbee2656bdb327490de42922abfc5125a (diff)
downloaddexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar.gz
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar.bz2
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar.lz
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar.xz
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.tar.zst
dexon-sol-tools-74ce893f520db6ae4617432975b5c9321ff5b89b.zip
Merge pull request #1003 from 0xProject/feature/contracts/roundup
[contracts] Add getPartialAmountCeil and isRoundingErrorCeil
Diffstat (limited to 'packages/order-utils/src')
-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
3 files changed, 8 insertions, 8 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)