◆ Purpose

getAmount is used to calculate the amount of tokens obtained in a single swap.

getAmountsOut is used to get the amount of tokens obtained when swapping through multiple tokens, using getAmount many times.

getAmountOut🌟

◆ Input & Return value

(address factory, uint amountIn, address[] memory path) ⇒ (uint[] memory amounts)

◆ Example

amountIn(USDC) = 1000

path= [0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48(USDC), 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2(WETH), 0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE(SHIBA)]

amounts = [1000(USDC),869954971760(WETH),90266067228189303221(SHIBA)]

◆ Code and Explain

function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[0] = amountIn;
        for (uint i; i < path.length - 1; i++) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }

◆ Resources

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

https://etherscan.io/address/0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D#readContract

Screen Shot 2022-07-11 at 20.01.56.png