β—† Purpose

calculating current K and calculate the same ratio from amountIn value

β—† Input & Return value

(uint amountA, uint reserveA, uint reserveB) β‡’ (uint amountB)

β—† Example

amountA = 1000 reserveA(WETH) = 43086702975516 reserveB(USDC) = 41997552572672937696884

β‡’

Screen Shot 2022-06-30 at 18.50.55.png

amountB = 974721890337

β—† Code and Explain

function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
        require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }

amountB = amountA.mul(reserveB) / reserveA; Β  πŸ‘‡ amountB.mul(reserveA) = amountA.mul(reserveB)

a : b = A : B Β  πŸ‘‡ a * B = b * A

1 : 2 = 50 : 100 Β  πŸ‘‡ 1 * 100 = 2 * 50

β—† Resources

https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L36