addLiquidity() 函数在本地 ganache 实例上的 UniswapV2 上失败?

发布于 2025-01-08 23:55:40 字数 835 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文