-
Notifications
You must be signed in to change notification settings - Fork 222
Error minting ETH-USDC 0.3% pool Uniswap v3 #21
Copy link
Copy link
Open
Description
I am using the following method to mint a Uniswap v3 position:
function mintPosition(
address token0,
address token1,
uint24 poolFee,
uint256 amount0,
uint256 amount1,
int24 rangeLeft,
int24 rangeRight) external payable override returns (
uint256 tokenId,
uint128 liquidity,
uint256 actualAmount0,
uint256 actualAmount1
)
{
// Approve the position manager
TransferHelper.safeApprove(token0, address(nonfungiblePositionManager), amount0);
TransferHelper.safeApprove(token1, address(nonfungiblePositionManager), amount1);
INonfungiblePositionManager.MintParams memory params =
INonfungiblePositionManager.MintParams({
token0: token0,
token1: token1,
fee: poolFee,
tickLower: rangeLeft,
tickUpper: rangeRight,
amount0Desired: amount0,
amount1Desired: amount1,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
});
// Note that the pool defined by token0/token1 and fee tier poolFee must already be created and initialized in order to mint
// THIS TRANSACTION FAILS WITHOUT A REASON STRING
(tokenId, liquidity, actualAmount0, actualAmount1) = nonfungiblePositionManager.mint(params);
// Create a deposit
_createDeposit(msg.sender, tokenId);
// Remove allowance and refund in both assets.
if (actualAmount0 < amount0) {
TransferHelper.safeApprove(token0, address(nonfungiblePositionManager), 0);
uint256 refund0 = amount0 - actualAmount0;
TransferHelper.safeTransfer(token0, msg.sender, refund0);
}
if (actualAmount1 < amount1) {
TransferHelper.safeApprove(token1, address(nonfungiblePositionManager), 0);
uint256 refund1 = amount1 - actualAmount1;
TransferHelper.safeTransfer(token1, msg.sender, refund1);
}
}I am able to mint a DAI-USDC 0.01% with this method. But when trying to create an ETH-USDC 0.3% pool it fails without a reason string
My test code is this:
it("Should create a new ETH-USDC 0.3% position", async function () {
const FEE = 3000;
const { contract, owner } = await loadFixture(deployUniswapPoolFixture)
const ethAmount = 10n**18n;
const usdcAmount = 3000n * 10n ** 6n;
const tickLower = -887272 // Math.ceil(baseLog(BASE, Math.sqrt(1/1400)));
const tickUpper = -tickLower // Math.ceil(baseLog(BASE, Math.sqrt(1/1200)));
await weth.connect(owner).deposit({ value: 100n * 10n ** 18n });
await weth.connect(owner).approve(contract.address, 100n * 10n ** 18n);
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [USDC_WHALE]
})
const usdcWhale = await ethers.getSigner(USDC_WHALE);
expect(await usdc.balanceOf(USDC_WHALE)).to.be.greaterThan(usdcAmount);
await usdc.connect(usdcWhale).transfer(owner.address, usdcAmount);
await usdc.connect(owner).transfer(contract.address, usdcAmount);
const newPosition = await contract.mintPosition(
MAINNET_TOKENS.ETH,
MAINNET_TOKENS.USDC,
FEE,
ethAmount,
usdcAmount,
tickLower,
tickUpper);
console.log(await dai.balanceOf(owner.address));
// expect(daiBalanceAfter).to.be.equal(0);
});And I get the following error:
Error: Transaction reverted without a reason string
at <UnrecognizedContract>.<unknown> (0xc36442b4a4522e871399cd717abdd847ab11fe88)
at UniswapPool.mintPosition (contracts/uniswap/UniswapPool.sol:95)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1802:23)
at HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:491:16)
at EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1522:18)
at HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)
at EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
Note that I'm using MIN_TICK and MAX_TICK for the range
Can you please help me to understand what is wrong with my code?
Thank you very much in advance
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels