【问题标题】:Error while trying to add Liquidity in uniswap pair尝试在 uniswap 对中添加流动性时出错
【发布时间】:2022-11-17 04:25:11
【问题描述】:

我正在使用 Hardhat framewrok 并使用 erc20 合约进行一些测试: 我用那个教程 fork https://hardhat.org/hardhat-network/docs/guides/forking-other-networks。 我正在尝试使用 uniswap 在主网分叉中交换两个 ERC20 令牌 我已经为代币创建了 uniswap 对,我正在尝试添加流动性。 这是我的测试代码。 我确定我为代币制定了正确的合同

require("@nomicfoundation/hardhat-chai-matchers")
const { expect } = require("chai")
const { ethers } = require("hardhat")

//https://unpkg.com/@uniswap/v2-core@1.0.0/build/IUniswapV2Pair.json
const uniswapPairAbi = require("../contracts/IUniswapV2Pair.json")

const uniswapFactoryAbi = require("../contracts/UniswapFactoryAbi.json")

const uniswapRouter02Abi = require("../contracts/IUniswapV2Router02.json")

const daiAbi = require("../contracts/DaiAbi.json")


const uniswapFactoryAddress = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"
const uniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D "
describe("Swap", function () {
   let owner
 it("Create Token, Create Pair, Swap", async function () {
       [owner, to] = await ethers.getSigners()

       const MyToken = await ethers.getContractFactory("MyToken", owner)
       const myToken = await MyToken.deploy()
       await myToken.deployed()

       const YourToken = await ethers.getContractFactory("YourToken", owner)
       const yourToken = await YourToken.deploy()
       await yourToken.deployed()

       const factory = await ethers.getContractAt(uniswapFactoryAbi, uniswapFactoryAddress)

       console.log("to ", to.address)
       const pair = await factory.createPair(myToken.address, yourToken.address)


       await expect(pair)
               .to.emit(factory, "PairCreated")
       const swapPairMTYTAddress = await factory.getPair(myToken.address, yourToken.address)

       const wapPairMTYTContract = await ethers.getContractAt(uniswapPairAbi, swapPairMTYTAddress)
       const router02Contract = await ethers.getContractAt(uniswapRouter02Abi, uniswapRouterAddress)
       
       await router02Contract.addLiquidity(myToken.address, yourToken.address,1,1,1,1, owner.address, 12)
      
 });
});

当我运行 npx hardhat test 时。我收到这样的错误。

npx hardhat test


  Swap
to  0x70997970C51812dc3A010C7d01b50e0d17dc79C8
    1) Create Token, Create Pair, Swap


  0 passing (6s)
  1 failing

  1) Swap
       Create Token, Create Pair, Swap:
     Error: network does not support ENS (operation="getResolver", network="unknown", code=UNSUPPORTED_OPERATION, version=providers/5.7.2)
      at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
      at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
      at EthersProviderWrapper.<anonymous> (node_modules\@ethersproject\providers\src.ts\base-provider.ts:1989:20)
      at step (node_modules\@ethersproject\providers\lib\base-provider.js:48:23)
      at Object.next (node_modules\@ethersproject\providers\lib\base-provider.js:29:53)
      at fulfilled (node_modules\@ethersproject\providers\lib\base-provider.js:20:58)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:528:9)
      at processTimers (node:internal/timers:502:7)

我确定 addLiquidity 之前的一切都正常工作

【问题讨论】:

    标签: token blockchain solidity hardhat uniswap


    【解决方案1】:

    const uniswap 路由器地址 = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D " 空格不应该在末尾

    【讨论】:

      【解决方案2】:

      在:

      const uniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D "
      

      地址中不能有空格或不明符号。 另外,尽量不要对您的地址进行硬编码。

      【讨论】:

        猜你喜欢
        • 2022-10-26
        • 2021-05-26
        • 1970-01-01
        • 1970-01-01
        • 2018-07-22
        • 2021-12-17
        • 2023-03-08
        • 1970-01-01
        • 2021-10-26
        相关资源
        最近更新 更多