minimumAmountOut method
Get the minimum amount that must be received from this trade for the given slippage tolerance @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade
Implementation
CurrencyAmount minimumAmountOut(Percent slippageTolerance) {
invariant(!(slippageTolerance.denominator < ZERO), 'SLIPPAGE_TOLERANCE');
invariant(!(slippageTolerance.numerator < ZERO), 'SLIPPAGE_TOLERANCE');
final outputAmountFraction = Fraction(outputAmount.raw);
if (tradeType == TradeType.EXACT_OUTPUT) {
return outputAmount;
} else {
final slippageAdjustedAmountOut = Fraction(ONE)
.add(slippageTolerance)
.invert()
.multiply(outputAmountFraction)
.quotient();
return outputAmount is TokenAmount
? TokenAmount(
(outputAmount as TokenAmount).token, slippageAdjustedAmountOut)
: CurrencyAmount.ether(
slippageAdjustedAmountOut,
);
}
}