Library
#
CodeInternal Functions
#
sortTokensfunction sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1);
Sorts token addresses.
#
pairForfunction pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair);
Calculates the address for a pair without making any external calls via the v2 SDK.
#
getReservesfunction getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB);
Calls getReserves on the pair for the passed tokens, and returns the results sorted in the order that the parameters were passed in.
#
quotefunction quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB);
Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.
- Useful for calculating optimal token amounts before calling mint.
#
getAmountOutfunction getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);
Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.
- Used in getAmountsOut.
#
getAmountInfunction getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);
Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.
- Used in getAmountsIn.
#
getAmountsOutfunction getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);
Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountOut.
- Useful for calculating optimal token amounts before calling swap.
#
getAmountsInfunction getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);
Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountIn.
- Useful for calculating optimal token amounts before calling swap.