I am trying to add Liquidity to a locally deployed pancakeswap instance. When calling addLiquidity I get:
ProviderError: Error: VM Exception while processing transaction: reverted with reason string 'ds-math-sub-underflow'
I've tried everything on: UniswapV2 addLiquidity revert ds-math-sub-underflow, as well as any other post I could find.
My Code:
async function main() {
const { deployer } = await getNamedAccounts();
const PancakeFactory = await hre.ethers.getContract("PancakeFactory");
const PancakeRouter = await hre.ethers.getContract("PancakeRouter");
const routerAddress = PancakeRouter.address;
const Token1 = await ethers.getContractFactory("Token");
const token1 = await Token1.deploy("Token", "TKN", 9999999999);
const Token2 = await ethers.getContractFactory("Token2");
const token2 = await Token2.deploy("Token2", "TKN2", 88888888);
const tx = await PancakeFactory.createPair(token1.address, token2.address);
var pairAddress = await PancakeFactory.getPair(
token1.address,
token2.address
);
await token1.transfer(pairAddress, 200);
await token2.transfer(pairAddress, 200);
var addr1Balance = await token1.balanceOf(deployer);
var addr2Balance = await token2.balanceOf(deployer);
await token1.approve(routerAddress, 100);
await token2.approve(routerAddress, 100);
var t1addr = token1.address;
var t2addr = token2.address;
console.log(`
*****************************
Deployer: ${deployer}
Factory: ${PancakeFactory.address}
Router: ${routerAddress}
Token: ${token1.address}
Token2: ${token2.address}
T1Bal: ${addr1Balance.toString()}
T2Bal: ${addr2Balance.toString()}
Pair: ${pairAddress}
*****************************
`);
var deadline = Math.floor(Date.now() / 1000) + 60 * 10;
const addLiquidityResult = await PancakeRouter.addLiquidity(
t1addr,
t2addr,
10,
10,
10,
10,
deployer,
deadline
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
Thanks in advance for any assistance.
TNAR