◆ Purpose

retrun amounts of pool

◆ Input & Return value

(address factory, address tokenA, address tokenB) ⇒ (uint reserveA, uint reserveB)

◆ Example

facotry = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f

tokenA(USDC) = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48

tokenB(WETH) = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

reserveA = 51224550843936

reserveB = 44552339419344963088195

◆ Code and Explain

function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
				// sortToken returns(token0, token1)
        // this code says "token1 doesn't need!"
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
    }

◆ Resources

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

https://docs.uniswap.org/protocol/V2/reference/smart-contracts/factory#:~:text=Address,was built from commit 8160750.

https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48