Liquidity.test.js
Henrychang26 opened this issue · 1 comments
Henrychang26 commented
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)}`)
})
})