Uniswap / v2-core

🦄 🦄 Core smart contracts of Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
2.89k stars 3.11k forks source link

how to get the full and right address[] path for swapExactTokensForTokens ? #165

Open lidd77 opened 2 years ago

lidd77 commented 2 years ago

hey, when I call the next function :

function swapExactTokensForTokens(
  uint amountIn,
  uint amountOutMin,
  address[] calldata path,
  address to,
  uint deadline
) external returns (uint[] memory amounts);

I need to find the full path data . As we know , there will have more than two pairs for address[] path, so how to get the right and full path result ?

ghost commented 6 months ago

Just guess the path ( pair ) with enough liquidity to trade.

For example if you want to swap USDT against ETH the pair would be

path := [USDT, WETH];

And if you want to swap USDC for ETH but you want to route the USDC-USDT pair then it would be

path := [USDC, USDT, WETH];