Uniswap / v3-periphery

🦄 🦄 🦄 Peripheral smart contracts for interacting with Uniswap v3
https://uniswap.org
GNU General Public License v2.0
1.17k stars 1.1k forks source link

Add example for managing liquidity via NonfungiblePositionManager #163

Open smsunarto opened 3 years ago

smsunarto commented 3 years ago

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
dappdappgo commented 2 years ago

+1

JohnAtBabyDoge commented 2 years ago

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.

abhijeet-eth commented 2 years ago

Please fix this issue ASAP.