getOutputAmount method
returns list of values : 0 = outputAmount : TokenAmount 1 = nextPair : Pair
Implementation
List<dynamic> getOutputAmount(TokenAmount inputAmount) {
invariant(involvesToken(inputAmount.token),
' involves token ${inputAmount.token}');
if (reserve0.raw == BigInt.zero || reserve1.raw == BigInt.zero) {
throw InsufficientReservesError();
}
var inputReserve = reserveOf(inputAmount.token);
var outputToken = inputAmount.token == token0 ? token1 : token0;
var outputReserve = reserveOf(outputToken);
var inputAmountWithFee = inputAmount.raw * bi997;
var outputAmount = TokenAmount(
outputToken,
(inputAmountWithFee * outputReserve.raw) ~/
(inputReserve.raw * bi1000 + inputAmountWithFee),
);
if (outputAmount.raw == BigInt.zero) {
throw InsufficientInputAmountError('output not zero');
}
return [
outputAmount,
Pair(inputReserve + inputAmount, outputReserve - outputAmount)
];
}