Library
#
Code#
ConstantsPRECISION = 1e18
#
Internal Functions#
sortTokensSorts token addresses.
#
getTradeInfoCalls getTradeInfo on the pool for the passed tokens, and returns the actual and virtual reserves of the pool, and the dynamic fee to be charged.
#
getReservesCalls getReserves on the pool for the passed tokens, and returns the results sorted in the order that the parameters were passed in.
#
quoteGiven some asset amount and reserves, returns an amount of the other asset representing equivalent value.
- Useful for calculating optimal token amounts before calling mint.
#
getAmountOutGiven an input asset amount and pool reserves (both actual and virtual balances), returns the maximum output amount of the other asset (accounting for fees).
- Used in getAmountsOut.
#
getAmountInReturns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given pool reserves (both acutal and virtual balances).
- Used in getAmountsIn.
#
getAmountsOutGiven an input asset amount and an array of token and corresponding pool addresses, calculates all subsequent maximum output token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountOut.
Since there are possibly multiple pools per token pair, it is required to specify the pools to be used for the swap. As such, it is a requirement that poolsPath.length = path.length - 1
.
- Useful for calculating optimal token amounts before calling swap.
#
getAmountsInGiven an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getTradeInfo for each pair of token addresses in the path in turn, and using these to call getAmountIn.
Since there are possibly multiple pools per token pair, it is required to specify the pools to be used for the swap. As such, it is a requirement that poolsPath.length = path.length - 1
.
- Useful for calculating optimal token amounts before calling swap.