I've been testing around UniswapV2 using hardhat and I always get this error when I try to add liquidity through the addLiquidity function on UniswapV2Router.
For the test, I deployed mock tokens, deployed UniswapV2Factory, then deployed Router.
here's the deployment code
const token = await ethers.getContractFactory("Token");
weth = await token.deploy('WETH', 'WETH', 6, owner.address);
mim = await token.deploy('MIM', 'MIM', 18, owner.address);
dai = await token.deploy('DAI', 'DAI', 18, owner.address);
const Factory = await ethers.getContractFactory("UniswapV2Factory");
const factory = await Factory.deploy(owner.address);
const Router = await ethers.getContractFactory("UniswapV2Router02");
const router = await Router.deploy(factory.address, weth.address);
const mim_100000000 = ethers.BigNumber.from("100000000000000000000000000");
const dai_100000000 = ethers.BigNumber.from("100000000000000000000000000");
await dai.approve(router.address, dai_100000000);
await mim.approve(router.address, mim_100000000);
await router.addLiquidity(mim.address, dai.address, mim_100000000, dai_100000000, mim_100000000, dai_100000000, owner.address, Date.now());
and it always produces this error:
Error: Transaction reverted: function call to a non-contract account
at UniswapV2Router02.getReserves (contracts/libraries/UniswapV2Library.sol:31)
at UniswapV2Router02._addLiquidity (contracts/UniswapV2Router02.sol:45)
at UniswapV2Router02.addLiquidity (contracts/UniswapV2Router02.sol:71)
at HardhatNode._mineBlockWithPendingTxs
Can someone help please?