addLiquidity() 函数在本地 ganache 实例上的 UniswapV2 上失败?
addLiquidity() 函数在 ganache 的本地开发实例上没有任何原因地恢复,您知道为什么会发生这种情况吗?
一些背景:
- 我已经分叉了 UniswapV2Factory 和 UniswapV2Router02 并部署在 ganache 上。
- 我创建了 2 个 ERC20 代币,并为它们创建了一对(通过factory.createPair())。
- 将两个 ERC20 代币铸造到我的地址。
- 我已经批准了路由器合约地址的代币金额(通过 erc20.approve() 函数)
这就是我调用 addLiquidity 函数的方式
const blockNumber = await web3.eth.getBlockNumber();
const block = await web3.eth.getBlock(blockNumber);
const timestamp = block.timestamp + 300;
await router.addLiquidity(
ERC20_TOKEN_1_ADDRESS,
ERC20_TOKEN_2_ADDRESS,
web3.utils.toWei('1', 'ether'),
web3.utils.toWei('1', 'ether'),
web3.utils.toWei('0.001', 'ether'),
web3.utils.toWei('0.001', 'ether'),
OWNER_ADDRESS,
timestamp,
{ gas: 4000000 }
)
addLiquidity() function reverts without any reason on local development instance of ganache, any ideas why this might be happening?
Some background:
- I have forked the UniswapV2Factory and UniswapV2Router02 and deployed on ganache.
- I have created 2 ERC20 tokens, and created a pair (via factory.createPair()) for them.
- Minted both ERC20 tokens to my address.
- I have approved token amounts to the router contract address (via erc20.approve() function)
This is how I am calling the addLiquidity Function
const blockNumber = await web3.eth.getBlockNumber();
const block = await web3.eth.getBlock(blockNumber);
const timestamp = block.timestamp + 300;
await router.addLiquidity(
ERC20_TOKEN_1_ADDRESS,
ERC20_TOKEN_2_ADDRESS,
web3.utils.toWei('1', 'ether'),
web3.utils.toWei('1', 'ether'),
web3.utils.toWei('0.001', 'ether'),
web3.utils.toWei('0.001', 'ether'),
OWNER_ADDRESS,
timestamp,
{ gas: 4000000 }
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论