aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-21 01:13:30 +0800
committerFabio Berger <me@fabioberger.com>2018-06-21 01:13:30 +0800
commit247f8c8557a501ea5081615d9b031c9e4b7aeec7 (patch)
tree51b9a9de386d7fbe453a7fc5c1e0e827fd6ecdca /packages/order-utils
parent3ce449e16739896f81b171d130afbb5774829d64 (diff)
downloaddexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar.gz
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar.bz2
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar.lz
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar.xz
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.tar.zst
dexon-sol-tools-247f8c8557a501ea5081615d9b031c9e4b7aeec7.zip
Fix orderValidationUtils where was confusing a makerAssetAmount as a takerAssetAmount
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/order_state_utils.ts9
-rw-r--r--packages/order-utils/src/order_validation_utils.ts13
-rw-r--r--packages/order-utils/src/utils.ts7
3 files changed, 18 insertions, 11 deletions
diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts
index dbb65de59..3752fdadb 100644
--- a/packages/order-utils/src/order_state_utils.ts
+++ b/packages/order-utils/src/order_state_utils.ts
@@ -14,6 +14,7 @@ import { AbstractOrderFilledCancelledFetcher } from './abstract/abstract_order_f
import { constants } from './constants';
import { orderHashUtils } from './order_hash';
import { RemainingFillableCalculator } from './remaining_fillable_calculator';
+import { utils } from './utils';
interface SidedOrderRelevantState {
isMakerSide: boolean;
@@ -161,7 +162,13 @@ export class OrderStateUtils {
signedOrder,
signedOrder.takerAddress,
);
- const remainingFillableTakerAssetAmountGivenMakersStatus = orderRelevantMakerState.remainingFillableAssetAmount;
+ const remainingFillableTakerAssetAmountGivenMakersStatus = signedOrder.makerAssetAmount.eq(0)
+ ? new BigNumber(0)
+ : utils.getPartialAmount(
+ orderRelevantMakerState.remainingFillableAssetAmount,
+ signedOrder.makerAssetAmount,
+ signedOrder.takerAssetAmount,
+ );
// Get max fillable amount for an order, considering the takers ability to fill
isMaker = false;
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts
index fb96502f2..da5b37456 100644
--- a/packages/order-utils/src/order_validation_utils.ts
+++ b/packages/order-utils/src/order_validation_utils.ts
@@ -54,7 +54,7 @@ export class OrderValidationUtils {
senderAddress: string,
zrxAssetData: string,
): Promise<void> {
- const fillMakerTokenAmount = OrderValidationUtils._getPartialAmount(
+ const fillMakerTokenAmount = utils.getPartialAmount(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.makerAssetAmount,
@@ -75,7 +75,7 @@ export class OrderValidationUtils {
TradeSide.Taker,
TransferType.Trade,
);
- const makerFeeAmount = OrderValidationUtils._getPartialAmount(
+ const makerFeeAmount = utils.getPartialAmount(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.makerFee,
@@ -88,7 +88,7 @@ export class OrderValidationUtils {
TradeSide.Maker,
TransferType.Fee,
);
- const takerFeeAmount = OrderValidationUtils._getPartialAmount(
+ const takerFeeAmount = utils.getPartialAmount(
fillTakerAssetAmount,
signedOrder.takerAssetAmount,
signedOrder.takerFee,
@@ -116,13 +116,6 @@ export class OrderValidationUtils {
throw new Error(ExchangeContractErrs.OrderFillExpired);
}
}
- private static _getPartialAmount(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
- const fillMakerTokenAmount = numerator
- .mul(target)
- .div(denominator)
- .round(0);
- return fillMakerTokenAmount;
- }
constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) {
this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
}
diff --git a/packages/order-utils/src/utils.ts b/packages/order-utils/src/utils.ts
index 6149316f6..7aaaf0609 100644
--- a/packages/order-utils/src/utils.ts
+++ b/packages/order-utils/src/utils.ts
@@ -12,4 +12,11 @@ export const utils = {
const milisecondsInSecond = 1000;
return new BigNumber(Date.now() / milisecondsInSecond).round();
},
+ getPartialAmount(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
+ const fillMakerTokenAmount = numerator
+ .mul(target)
+ .div(denominator)
+ .round(0);
+ return fillMakerTokenAmount;
+ },
};