2

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

3
  • Don't use the graph, the collect event table is empty on mainnet, I'm sure on Arbitrum it's even worse.
    – kfx
    Commented Sep 1, 2023 at 16:24
  • I already realized there are quite a few differences between the Ethereum and the Arbitrum „edition“ of the graph. Followed quite a few paths on the Explorer - which all lead into a dead-end.
    – Kurt
    Commented Sep 1, 2023 at 16:54
  • can you clarify if you want to calculate the total uncollected fees for a Position on the UniswapV3Pool or for an NFT on the NonFungiblePositionManager?
    – MShakeG
    Commented Feb 14 at 8:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.