I'm using my owned cloned UniswapV2 smart contracts(core+periphery) and deployed them using ganache network, so when i start testing functions, i started with createPair() function located in UniswapV2Factory and it's working fine. But when i start using uniswapV2router functions like addliquidity() or swapexactTokensForTokens() it dosent't working, and throw error message :
Returned error: VM Exception while processing transaction: revert This is my deploy file where i used addLiquidity() function located in testliquidity contract:
const { sendEther, pow } = require("./util"); const IERC20 = artifacts.require("IERC20"); const TestLiquidity = artifacts.require("TestLiquidity"); const { ethers } = require("ethers"); const TOKEN_A = "0xFDAc1a07bB190930c45113BA0119b4F9c964aAb9"; const TOKEN_B = "0x21A347769867E169AF7444fe85F4E4bdE4A9c97e"; const ROUTER = "0xeEea9fc1B8c453105258F09BCa4d06086a909c91"; const TOKEN_A_AMOUNT = pow(10, 18); const TOKEN_B_AMOUNT = pow(10, 18); module.exports = async function (deployer, networks, accounts) { const tokenA = await IERC20.at(TOKEN_A); const tokenB = await IERC20.at(TOKEN_B); await deployer.deploy(TestLiquidity) const testliquidity = await TestLiquidity.deployed() await tokenA.approve(testliquidity.address, TOKEN_A_AMOUNT); await tokenB.approve(testliquidity.address, TOKEN_B_AMOUNT); let tx = await testliquidity.addLiquidity( tokenA.address, tokenB.address, TOKEN_A_AMOUNT, TOKEN_B_AMOUNT ); }; and this is the testliquidity contract where i called the addliquidity() function:
contract TestLiquidity { address private constant ROUTER = 0xeEea9fc1B8c453105258F09BCa4d06086a909c91; event Log(string message, uint val); function addLiquidity( address _tokenA, address _tokenB, uint _amountA, uint _amountB ) external { IERC20(_tokenA).transferFrom(msg.sender, address(this), _amountA); IERC20(_tokenB).transferFrom(msg.sender, address(this), _amountB); IERC20(_tokenA).approve(ROUTER, _amountA); IERC20(_tokenB).approve(ROUTER, _amountB); (uint amountA, uint amountB, uint liquidity) = IUniswapV2Router02(ROUTER).addLiquidity( _tokenA, _tokenB, _amountA, _amountB, 1, 1, address(this), block.timestamp ); emit Log("amountA", amountA); emit Log("amountB", amountB); emit Log("liquidity", liquidity); } } and here is my ERC20 tokens contracts tokenA and tokenB which i created to add them in my liquidity pair:
contract tokenA is ERC20 { constructor() ERC20('USDC Coin', 'USDC') { uint256 n = 1000; _mint(msg.sender, n * 10**uint(decimals())); } contract tokenB is ERC20 { constructor() ERC20('WBTC Coin', 'WBTC') { uint256 n = 1000; _mint(msg.sender, n * 10**uint(decimals())); } } } I can't undestant from where the problem exactly, i'm sure the uniswapV2 contracts are correct and well deployed.