Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquidity.test.js #22

Open
Henrychang26 opened this issue Apr 25, 2023 · 1 comment
Open

Liquidity.test.js #22

Henrychang26 opened this issue Apr 25, 2023 · 1 comment

Comments

@Henrychang26
Copy link

I am getting this error when I try to test: sender doesn't have enough funds to send tx. The max upfront cost is: 1527451433449412000 and the sender's account only has: 0.

I updated some of the code, is my hardhat setup wrong?
Error starts at when transfering DAI and USDC to owner.

const { expect } = require("chai")
const { ethers } = require("hardhat")

const DAI = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
const DAI_WHALE = "0x6FF8E4DB500cBd77d1D181B8908E022E29e0Ec4A"
const USDC_WHALE = "0xc3dcB715eDeb0374E968177A3620c441344c3ED8"
const IWETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
const wethAmount = ethers.utils.parseEther("1")

describe("LiquidityExamples", () => {
  let liquidityExamples
  let accounts
  let dai
  let usdc
  let owner
  let iweth

  before(async () => {
    accounts = await ethers.getSigners()
    owner = accounts[0]
    console.log(`owner address : ${owner.address}`)
    console.log(`account[0] address : ${accounts[0].address}`)

    const LiquidityExamples = await ethers.getContractFactory(
      "LiquidityExamples"
    )
    liquidityExamples = await LiquidityExamples.deploy()
    await liquidityExamples.deployed()

    dai = await ethers.getContractAt("IERC20", DAI)
    usdc = await ethers.getContractAt("IERC20", USDC)
    iweth = await ethers.getContractAt("IWETH", IWETH)

    // Unlock DAI and USDC whales
    await network.provider.request({
      method: "hardhat_impersonateAccount",
      params: [DAI_WHALE],
    })
    await network.provider.request({
      method: "hardhat_impersonateAccount",
      params: [USDC_WHALE],
    })
    // get Signers
    const daiWhale = await ethers.getSigner(DAI_WHALE)
    const usdcWhale = await ethers.getSigner(USDC_WHALE)

    const daiBal = await dai.balanceOf(DAI_WHALE)
    const usdcBal = await usdc.balanceOf(USDC_WHALE)

    // Send DAI and USDC to accounts[0]
    const daiAmount = 10n * 10n ** 18n
    const usdcAmount = 10n * 10n ** 6n

    await dai.connect(daiWhale).transfer(owner.address, daiAmount)
    await usdc.connect(usdcWhale).transfer(owner.address, usdcAmount)

    const daiBalance = await dai.balanceOf(owner.address)
  })

  it("mintNewPosition", async () => {
    const daiAmount = 1n * 10n ** 18n
    const usdcAmount = 1n * 10n ** 6n

    await dai.connect(owner).transfer(liquidityExamples.address, daiAmount)
    await usdc.connect(owner).transfer(liquidityExamples.address, usdcAmount)

    await liquidityExamples.mintNewPosition()

    console.log(
      "DAI balance after add liquidity",
      await dai.balanceOf(accounts[0].address)
    )
    console.log(
      "USDC balance after add liquidity",
      await usdc.balanceOf(accounts[0].address)
    )
  })

  it.skip("increaseLiquidityCurrentRange", async () => {
    const daiAmount = 20n * 10n ** 18n
    const usdcAmount = 20n * 10n ** 6n

    await dai.connect(accounts[0]).approve(liquidityExamples.address, daiAmount)
    await usdc
      .connect(accounts[0])
      .approve(liquidityExamples.address, usdcAmount)

    await liquidityExamples.increaseLiquidityCurrentRange(daiAmount, usdcAmount)
  })

  it("decreaseLiquidity", async () => {
    const tokenId = await liquidityExamples.tokenId()
    const liquidity = await liquidityExamples.getLiquidity(tokenId)

    await liquidityExamples.decreaseLiquidity(liquidity)

    console.log("--- decrease liquidity ---")
    console.log(`liquidity ${liquidity}`)
    console.log(`dai ${await dai.balanceOf(liquidityExamples.address)}`)
    console.log(`usdc ${await usdc.balanceOf(liquidityExamples.address)}`)
  })

  it("collectAllFees", async () => {
    await liquidityExamples.collectAllFees()

    console.log("--- collect fees ---")
    console.log(`dai ${await dai.balanceOf(liquidityExamples.address)}`)
    console.log(`usdc ${await usdc.balanceOf(liquidityExamples.address)}`)
  })
})


@tign227
Copy link

tign227 commented Feb 18, 2024

whale don't have enough fee to send tx, plz change your code like below:

1, get whale signer
const dai_whale = await ethers.getImpersonatedSigner(DAI_WAHLE_ADDRESS);
2, transfer fee
await deployer.sendTransaction({ to: dai_whale.address, value: ethers.parseEther("500.0"), });
3. trasanfer DAI
await dai.connect(dai_whale).transfer(deployer, dai_amount);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants