calculating current K and calculate the same ratio from amountIn value
(uint amountA, uint reserveA, uint reserveB) β (uint amountB)
amountA = 1000 reserveA(WETH) = 43086702975516 reserveB(USDC) = 41997552572672937696884
β
amountB = 974721890337
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
https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L36