I want to write a python script, that keeps track of the fees earned by my UniSwap V3 positions on Arbitrum and stores daily snapshots in a database. I’ve read quite a few threads here, but could not really find the right track yet. It would be lovely to have the one simple query, but as far as I found out calculation seems quite complicated. I'm not interested in just unclaimed fees for a position, but am looking for the all-time amount (claimed and unclaimed). Querying TheGraph or directly accessing the smart contract via web3 would both be fine.
Edit:
Quite a few hours of research and testing later, I am convinced, that it's not really straightforward to extract the sum of all claimed fees plus pending fees. I could not find an according function in either of the smart contracts. BUT it is still possible. One could query the Arbiscan API and filter out matching transactions. But in the meantime my little project evolved and I'm fine now with only tracking the uncollected fees. I found a few very helpful links on my way, which I want to share:
Trying to make sense of Uniswap v3 fees (feeGrowthInside0LastX128, feeGrowthGlobal0X128)
https://gist.github.com/Lucas-Kohorst/3b2727eaa60edebc27b21c7195261865
https://blog.uniswap.org/uniswap-v3-math-primer-2#calculating-uncollected-fees-in-a-position
Kurt
Position
on theUniswapV3Pool
or for an NFT on theNonFungiblePositionManager
?