◆ Purpose

to swap tokens

◆ Input & Return value

(uint[] memory amounts, address[] memory path, address _to) ⇒ none

◆ Example

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

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

to = 0xED98485593D5865E892f823e1f66FB99fE64F639

this value from getAmountsOut

◆ Code and Explain

function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
        for (uint i; i < path.length - 1; i++) {
            (address input, address output) = (path[i], path[i + 1]);
            (address token0,) = UniswapV2Library.sortTokens(input, output);
            uint amountOut = amounts[i + 1];
            (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
            address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
            IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap(
                amount0Out, amount1Out, to, new bytes(0)
            );
        }
    }

◆ Resources

https://github.com/Uniswap/v2-periphery/blob/master/contracts/UniswapV2Router02.sol#L212