Hi, I'm trying to addLiquidityETH in truffle console but keeps running into ds-math-sub-underflow error. The pool pair is created at contract constructor and the wallet has more than enough for myToken and Eth. I'm running this on a ganache cli clone of mainnet. Could someone help? Thank you
// Approve and add liquidity
const IUniswapV2Pair = artifacts.require("IUniswapV2Pair");
const IUniswapV2Factory = artifacts.require("IUniswapV2Factory");
const IUniswapV2Router01 = artifacts.require("IUniswapV2Router01");
const IUniswapV2Router02 = artifacts.require("IUniswapV2Router02");
const uniswapV2Router = await IUniswapV2Router02.at('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'); //UniSwapV2Router02 address
await myToken.approve('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', //UniSwapV2Router02 address
1000,
{
from: '0xD7dfaDD73e3F87227b5D8F7860A975e92A9266A1', // accounts[0] wallet
gas: 4000000,
});
const tokenPair = await IUniswapV2Pair.at('0xa6af56Dc3F2Df62CC1922F5b47C6B8Df4B0B30A8'); //token|ETH pair in constructor
await tokenPair.approve('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', //UniSwapV2Router02 address
1000,
{
from: '0xD7dfaDD73e3F87227b5D8F7860A975e92A9266A1', // accounts[0] wallet
gas: 4000000,
});
await uniswapV2Router.addLiquidityETH(
myToken.address, // token address
1000, // token value
1, // slippage is unavoidable
1, // slippage is unavoidable
'0xD7dfaDD73e3F87227b5D8F7860A975e92A9266A1', // accounts[0] wallet
1690886616,
{
from: '0xD7dfaDD73e3F87227b5D8F7860A975e92A9266A1', // accounts[0] wallet
value: 1 //eth value
}
);
Error: Returned error: VM Exception while processing transaction: revert ds-math-sub-underflow -- Reason given: ds-math-sub-underflow.
at main (scripts/debug.js:44:48)
at processTicksAndRejections (node:internal/process/task_queues:94:5) {
data: {
'0xa4825ca1fef17a19129e39c872b8696c1884affe4f533a964381ed320130cd48': {
error: 'revert',
program_counter: 13975,
return: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001564732d6d6174682d7375622d756e646572666c6f770000000000000000000000',
reason: 'ds-math-sub-underflow'
},
stack: 'c: VM Exception while processing transaction: revert ds-math-sub-underflow\n' +
' at Function.c.fromResults (/opt/homebrew/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:4:192416)\n' +
' at A.w.processBlock (/opt/homebrew/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:50915)\n' +
' at runMicrotasks (<anonymous>)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:94:5)',
name: 'c'
},
reason: 'ds-math-sub-underflow',
hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert ds-math-sub-underflow -- Reason given: ds-math-sub-underflow.\n' +
' at Object.ErrorResponse (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/lib/errors.js:28:1)\n' +
' at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/lib/index.js:303:1\n' +
' at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1\n' +
' at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)\n' +
' at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)\n' +
' at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)\n' +
' at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)\n' +
' at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)\n' +
' at IncomingMessage.emit (node:events:381:22)\n' +
' at endReadableNT (node:internal/streams/readable:1307:12)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:81:21)'
}