I'm trying to get the amount of each token currently held in a liquidity pool position on Uniswap V3 (in Pyhton) based on the token ID of the NFT. I was able to get info about the position by calling :
contract = web3.eth.contract(address=addr_uni_nft_pos,abi=abi_uni_pos)
contract.functions.positions(nft_token_id).call()
from which I'm getting:
{'nonce': 0,
'operator': '0x0000000000000000000000000000000000000000',
'token0': '0x4d224452801ACEd8B2F0aebE155379bb5D594381',
'token1': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
'fee': 3000,
'tickLower': -56700,
'tickUpper': -55740,
'liquidity': 0,
'feeGrowthInside0LastX128': 115792089237316195423570985008687907853246859851719844967496612553656335272574,
'feeGrowthInside1LastX128': 115792089237316195423570985008687907853269894723013691862125737150933929444085,
'tokensOwed0': 0,
'tokensOwed1': 0}
However I want to get the total amount (deposited + rewards) of each token currently held on the pool, independently if the position is or not on range. Is there a way to do this? I was thinking in simply looking at the minting event of the NFT itself, but surely there is a simpler way.
Thanks in advance.
Best Answer
I wrote a function that perform a static call passing the maximum collectable value in other to see how much is pending to be collected.
For
amount0Max
andamount1Max
you can use this:This function will return to you the uncollected fees :)
The number of
token0
andtoken1
can be retrieved through these functions:The price lower and price upper can be retrieved through this:
Till i know unfortunatelly we only have V3-SDK on npm so you will have plenty work writing anything.