v3-periphery icon indicating copy to clipboard operation
v3-periphery copied to clipboard

Add example for managing liquidity via NonfungiblePositionManager

Open smsunarto opened this issue 4 years ago • 3 comments
trafficstars

A lot of teams in HackMoney hackathon (which Uniswap Grants sponsors) struggled in figuring out how to provide liquidity via NonfungiblePositionManager through a smart contract.

A simple example on the following would go a long way:

  1. Creating/initializing a new pool
  2. Providing liquidity to said pool
  3. Withdrawing liquidity

smsunarto avatar Jul 05 '21 19:07 smsunarto

+1

dappdappgo avatar Feb 13 '22 02:02 dappdappgo

The official example doesn't even compile due to a "stack too deep" error given by: (, , address token0, address token1, , , , uint128 liquidity, , , , ) = nonfungiblePositionManager.positions(tokenId);

Even if you somehow figure how to convert that to a low level call (detailed here), you still get the Pool.mint function reverting without an error.

Please help us build things for your product. Please provide one working example of adding & removing liquidity. Thanks.

EDIT: FOUND THE ISSUE!

The official example has a range of TickMath.MIN_TICK to TickMath.MAX_TICK. These are wrong! They are the theoretical limits of TickMath, not the values you should use for the pool. The tickLower and tickUpper values have to be within the range of -Pool.slot0.tick and Pool.slot0.tick, otherwise the transaction silently fails. The SDK example with "nearestUsableTick" shows a better way to calculate the values.

JohnAtBabyDoge avatar Feb 16 '22 05:02 JohnAtBabyDoge

Please fix this issue ASAP.

abhijeet-eth avatar Feb 28 '22 08:02 abhijeet-eth