The first article of learning clip introduction Understanding pancakeswap routing

Internal function

function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1);

Sort token addresses.

function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair);

A pair of addresses can be calculated without any external calls through the v2 SDK.

function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB);

Calls getReserves on the passed token and returns the results sorted in the order of the passed arguments.

function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB);

Given some number of assets and reserves, return the number of other assets representing the equivalent value.

Used to calculate the optimal number of tokens before calling mint.

function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);

Given the number of input assets, returns the maximum output number of other assets (considering fees) for the given reserve.

Used in getAmountsOut.

function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);

Returns the minimum amount of input assets required to buy a given amount of output assets (considering fees) for a given reserve.

If you need bsc clip server +Q1569726

Used in getAmountsIn.

function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);

Given an input asset amount and an array of token addresses, calculate all subsequent maximum output tokens by calling getReserves for each pair of token addresses in the path in turn and using these to call getAmountOut.

Used to calculate the optimal amount of tokens before calling [swap .]

function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);

Given an output asset amount and an array of token addresses, compute all previous minimum input token amounts by calling getReserves for each pair of token addresses in the path in turn and calling getAmountIn with these.

Used to calculate the optimal amount of tokens before calling swap.

Leave a Comment

Your email address will not be published. Required fields are marked *