Fix var name and use floor instead of .round(0, ROUND_DOWN)

This commit is contained in:
Steve Klebanoff 2018-12-21 16:29:53 -08:00
parent c8c8219c05
commit 26977f6408

View File

@ -36,16 +36,14 @@ export const buyQuoteCalculator = {
if (remainingFillAmount.gt(constants.ZERO_AMOUNT)) { if (remainingFillAmount.gt(constants.ZERO_AMOUNT)) {
// We needed the amount they requested to buy, plus the amount for slippage // We needed the amount they requested to buy, plus the amount for slippage
const totalAmountRequested = assetBuyAmount.plus(slippageBufferAmount); const totalAmountRequested = assetBuyAmount.plus(slippageBufferAmount);
const amountUnableToFill = totalAmountRequested.minus(remainingFillAmount); const amountAbleToFill = totalAmountRequested.minus(remainingFillAmount);
// multiplerNeededWithSlippage represents what we need to multiply the assetBuyAmount by // multiplierNeededWithSlippage represents what we need to multiply the assetBuyAmount by
// in order to get the total amount needed considering slippage // in order to get the total amount needed considering slippage
// i.e. if slippagePercent was 0.2 (20%), multiplerNeededWithSlippage would be 1.2 // i.e. if slippagePercent was 0.2 (20%), multiplierNeededWithSlippage would be 1.2
const multiplerNeededWithSlippage = new BigNumber(1).plus(slippagePercentage); const multiplierNeededWithSlippage = new BigNumber(1).plus(slippagePercentage);
// Given amountAvailableToFillConsideringSlippage * multiplerNeededWithSlippage = amountUnableToFill // Given amountAvailableToFillConsideringSlippage * multiplierNeededWithSlippage = amountAbleToFill
// We divide amountUnableToFill by multiplerNeededWithSlippage to determine amountAvailableToFillConsideringSlippage // We divide amountUnableToFill by multiplierNeededWithSlippage to determine amountAvailableToFillConsideringSlippage
const amountAvailableToFillConsideringSlippage = amountUnableToFill const amountAvailableToFillConsideringSlippage = amountAbleToFill.div(multiplierNeededWithSlippage).floor();
.div(multiplerNeededWithSlippage)
.round(0, BigNumber.ROUND_DOWN);
throw new InsufficientAssetLiquidityError(amountAvailableToFillConsideringSlippage); throw new InsufficientAssetLiquidityError(amountAvailableToFillConsideringSlippage);
} }