I want to write a system that will exchange any ERC20 for any other ERC20 registered in the system using Uniswap I already wrote a contract for Ether swap in DAI and back with UniswapRouterV2 My question is how to create a new pair ERC20 and ERC20(may be ERC20 -> WETH -> ERC20), add liquidity to it and implement a new exchange.
For create a new pair, you need to add liquidity to this specific pool. In your case, you have two options:
- Manually: Go to Uniswap dapp, click on
Create a new pool->
Insert your token address and second token addressand click on
Add your liquidity.
- With coding: in this alternative, you can use
IUniswapV2Factorythat allow you to create a new pair between your token and another token. When you created this pair, you must to add liquidity inside its liquidity pool for allow other users to be able to swap your token inside liquidity pool. You can use
IUniswapV2Router02increase your liquidity inside the liquidity pool that you created previous. More information about this two method here: addLiquidity() and createPair().
In the end, for implementing a new exchange, you can use
swapExactTokensForTokensSupportingFeeOnTransferTokens() method (here more information about this method) inside IUniswapV2Router02 that it'll allows a user to swap your token inside your smart contract code.