I’m interested in developing a staking platform for Uniswap V3 liquidity provider NFTs. I have a few technical questions that I need help with.
Firstly, how can I assess the current value of a staked LP NFT? Secondly, what is the process to find out the total liquidity in the pool? Lastly, I want to know if these calculations can be executed within a smart contract.
I’m looking for on-chain methods rather than using external services. Any insights or examples would be greatly appreciated. Thank you for your assistance!
hey there! this sounds like a really intresting project your working on. i’ve been tinkering with uniswap v3 stuff myself and this kind of valuation is tricky but totally doable on-chain.
so you’re basically trying to build a whole staking system around the LP NFTs right? thats pretty cool! i’m curious though - are you planning to lock the actual NFTs in your contract or just use them as collateral while users keep ownership?
for the valuation part, you’ll definitely want to tap into the NonfungiblePositionManager contract since thats where all the position data lives. the tricky bit is that unlike v2 where you could just calculate based on pool shares, v3 positions have those concentrated liquidity ranges which makes the math more complex.
one thing i’m wondering about - how are you planning to handle the fee accrual? since fees in v3 dont automatically compound back into the position, you’d need to account for uncollected fees separately when calculating total value. are you thinking of including those in your valuation or treating them seperately?
also, what kind of price feeds are you considering for the underlying tokens? i mean, you said on-chain only, so i assume you’re looking at something like chainlink oracles or maybe even deriving prices from the pools themselves?
would love to hear more about your approach! are you planning to support all fee tiers or just focus on specific ones like 0.3%?
for LP NFT valuation you can call the positions() function on the NonfungiblePositionManager with the token ID. this gives you liquidity amount, tick range, and token amounts. then use pool’s slot0() for current tick and calculate position value based on current price vs your range. bit complex math but definitly possible in solidity!
You’ll need to interact with multiple contracts to get accurate valuations. The NonfungiblePositionManager contract stores the position data, but calculating actual value requires fetching current pool state from the specific V3 pool contract itself. For total pool liquidity, call the pool’s liquidity() function which returns active liquidity at current tick. However, this only shows liquidity that’s actually being used for trading at the current price range. The challenging part is converting liquidity amounts back to token quantities. You’ll need to use the tick math library functions to calculate token0 and token1 amounts based on current price and position bounds. I’ve implemented similar logic before and the precision requirements can be demanding - especially handling the sqrt price calculations without overflow. Regarding smart contract execution, everything is definitely possible on-chain. Just be mindful of gas costs since these calculations involve multiple external calls and complex mathematical operations. Consider caching frequently accessed data or batching operations where possible.