aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/asset-buyer/src/utils')
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts10
-rw-r--r--packages/asset-buyer/src/utils/order_provider_response_processor.ts7
-rw-r--r--packages/asset-buyer/src/utils/order_utils.ts28
3 files changed, 21 insertions, 24 deletions
diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
index fcded6ab1..9205678e7 100644
--- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts
+++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
@@ -22,7 +22,7 @@ export const buyQuoteCalculator = {
const remainingFillableMakerAssetAmounts = ordersAndFillableAmounts.remainingFillableMakerAssetAmounts;
const feeOrders = feeOrdersAndFillableAmounts.orders;
const remainingFillableFeeAmounts = feeOrdersAndFillableAmounts.remainingFillableMakerAssetAmounts;
- const slippageBufferAmount = assetBuyAmount.mul(slippagePercentage).round();
+ const slippageBufferAmount = assetBuyAmount.multipliedBy(slippagePercentage).integerValue();
// find the orders that cover the desired assetBuyAmount (with slippage)
const {
resultOrders,
@@ -43,7 +43,7 @@ export const buyQuoteCalculator = {
const multiplierNeededWithSlippage = new BigNumber(1).plus(slippagePercentage);
// Given amountAvailableToFillConsideringSlippage * multiplierNeededWithSlippage = amountAbleToFill
// We divide amountUnableToFill by multiplierNeededWithSlippage to determine amountAvailableToFillConsideringSlippage
- const amountAvailableToFillConsideringSlippage = amountAbleToFill.div(multiplierNeededWithSlippage).floor();
+ const amountAvailableToFillConsideringSlippage = amountAbleToFill.div(multiplierNeededWithSlippage).integerValue(BigNumber.ROUND_FLOOR);
throw new InsufficientAssetLiquidityError(amountAvailableToFillConsideringSlippage);
}
@@ -131,7 +131,7 @@ function calculateQuoteInfo(
zrxEthAmount = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
}
// eth amount needed to buy the affiliate fee
- const affiliateFeeEthAmount = assetEthAmount.mul(feePercentage).ceil();
+ const affiliateFeeEthAmount = assetEthAmount.multipliedBy(feePercentage).integerValue(BigNumber.ROUND_CEIL);
// eth amount needed for fees is the sum of affiliate fee and zrx fee
const feeEthAmount = affiliateFeeEthAmount.plus(zrxEthAmount);
// eth amount needed in total is the sum of the amount needed for the asset and the amount needed for fees
@@ -168,9 +168,9 @@ function findEthAmountNeededToBuyZrx(
order,
makerFillAmount,
);
- const extraFeeAmount = remainingFillableMakerAssetAmount.greaterThanOrEqualTo(adjustedMakerFillAmount)
+ const extraFeeAmount = remainingFillableMakerAssetAmount.isGreaterThanOrEqualTo(adjustedMakerFillAmount)
? constants.ZERO_AMOUNT
- : adjustedMakerFillAmount.sub(makerFillAmount);
+ : adjustedMakerFillAmount.minus(makerFillAmount);
return {
totalEthAmount: totalEthAmount.plus(takerFillAmount),
remainingZrxBuyAmount: BigNumber.max(
diff --git a/packages/asset-buyer/src/utils/order_provider_response_processor.ts b/packages/asset-buyer/src/utils/order_provider_response_processor.ts
index 4244d196c..f08cd6150 100644
--- a/packages/asset-buyer/src/utils/order_provider_response_processor.ts
+++ b/packages/asset-buyer/src/utils/order_provider_response_processor.ts
@@ -109,11 +109,8 @@ function getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain(
return accOrders;
}
// if the order IS fillable, add the order and calculate the remaining fillable amount
- const transferrableAssetAmount = BigNumber.min([traderInfo.makerAllowance, traderInfo.makerBalance]);
- const transferrableFeeAssetAmount = BigNumber.min([
- traderInfo.makerZrxAllowance,
- traderInfo.makerZrxBalance,
- ]);
+ const transferrableAssetAmount = BigNumber.min(traderInfo.makerAllowance, traderInfo.makerBalance);
+ const transferrableFeeAssetAmount = BigNumber.min(traderInfo.makerZrxAllowance, traderInfo.makerZrxBalance);
const remainingTakerAssetAmount = order.takerAssetAmount.minus(orderInfo.orderTakerAssetFilledAmount);
const remainingMakerAssetAmount = orderUtils.getRemainingMakerAmount(order, remainingTakerAssetAmount);
const remainingFillableCalculator = new RemainingFillableCalculator(
diff --git a/packages/asset-buyer/src/utils/order_utils.ts b/packages/asset-buyer/src/utils/order_utils.ts
index 1cc2cf95f..3ea3cafd3 100644
--- a/packages/asset-buyer/src/utils/order_utils.ts
+++ b/packages/asset-buyer/src/utils/order_utils.ts
@@ -9,8 +9,8 @@ export const orderUtils = {
},
willOrderExpire(order: SignedOrder, secondsFromNow: number): boolean {
const millisecondsInSecond = 1000;
- const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round();
- return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.plus(secondsFromNow));
+ const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).integerValue();
+ return order.expirationTimeSeconds.isLessThan(currentUnixTimestampSec.plus(secondsFromNow));
},
isOpenOrder(order: SignedOrder): boolean {
return order.takerAddress === constants.NULL_ADDRESS;
@@ -20,43 +20,43 @@ export const orderUtils = {
const remainingMakerAmount = remainingTakerAmount
.times(order.makerAssetAmount)
.div(order.takerAssetAmount)
- .floor();
+ .integerValue(BigNumber.ROUND_FLOOR);
return remainingMakerAmount;
},
// given a desired amount of makerAsset, calculate how much takerAsset is required to fill that amount
getTakerFillAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber {
// Round up because exchange rate favors Maker
const takerFillAmount = makerFillAmount
- .mul(order.takerAssetAmount)
+ .multipliedBy(order.takerAssetAmount)
.div(order.makerAssetAmount)
- .ceil();
+ .integerValue(BigNumber.ROUND_CEIL);
return takerFillAmount;
},
// given a desired amount of takerAsset to fill, calculate how much fee is required by the taker to fill that amount
getTakerFeeAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber {
// Round down because Taker fee rate favors Taker
const takerFeeAmount = takerFillAmount
- .mul(order.takerFee)
+ .multipliedBy(order.takerFee)
.div(order.takerAssetAmount)
- .floor();
+ .integerValue(BigNumber.ROUND_FLOOR);
return takerFeeAmount;
},
// given a desired amount of takerAsset to fill, calculate how much makerAsset will be filled
getMakerFillAmount(order: SignedOrder, takerFillAmount: BigNumber): BigNumber {
// Round down because exchange rate favors Maker
const makerFillAmount = takerFillAmount
- .mul(order.makerAssetAmount)
+ .multipliedBy(order.makerAssetAmount)
.div(order.takerAssetAmount)
- .floor();
+ .integerValue(BigNumber.ROUND_FLOOR);
return makerFillAmount;
},
// given a desired amount of makerAsset, calculate how much fee is required by the maker to fill that amount
getMakerFeeAmount(order: SignedOrder, makerFillAmount: BigNumber): BigNumber {
// Round down because Maker fee rate favors Maker
const makerFeeAmount = makerFillAmount
- .mul(order.makerFee)
+ .multipliedBy(order.makerFee)
.div(order.makerAssetAmount)
- .floor();
+ .integerValue(BigNumber.ROUND_FLOOR);
return makerFeeAmount;
},
// given a desired amount of ZRX from a fee order, calculate how much takerAsset is required to fill that amount
@@ -64,9 +64,9 @@ export const orderUtils = {
getTakerFillAmountForFeeOrder(order: SignedOrder, makerFillAmount: BigNumber): [BigNumber, BigNumber] {
// For each unit of TakerAsset we buy (MakerAsset - TakerFee)
const adjustedTakerFillAmount = makerFillAmount
- .mul(order.takerAssetAmount)
- .div(order.makerAssetAmount.sub(order.takerFee))
- .ceil();
+ .multipliedBy(order.takerAssetAmount)
+ .div(order.makerAssetAmount.minus(order.takerFee))
+ .integerValue(BigNumber.ROUND_CEIL);
// The amount that we buy will be greater than makerFillAmount, since we buy some amount for fees.
const adjustedMakerFillAmount = orderUtils.getMakerFillAmount(order, adjustedTakerFillAmount);
return [adjustedTakerFillAmount, adjustedMakerFillAmount];