Clarification on Fee Tracking in Positions Management #36
-
Hi, first I would like to thank you for providing a detailed explanation of the Uniswap V3 code! I was wondering if you could help clarify a few points, I'm not sure if I understand them correctly (I'm asking these because I'm trying to calculate positions' fees accumulated during a time period, using Uniswap's hosted subgraph and the time-travel queries based on blocks):
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes. This is so because swap fees only grow up: trades are made, swap fees are taken. These variables are updated during swapping:
If I understand the question correctly, it's not different from the owed tokens calculation. If you know how lending protocols work, there's a similarity: interest must always be accrued before modifying loans. Here we must always accrue swap fees (convert them to token amounts) before updating liquidity position. Also notice these lines: I think this will answer your third question:
I don't think so. It's a conveyor:
Looks solid :) (sorry for the typos, it's a late Friday night here :) |
Beta Was this translation helpful? Give feedback.
Yes. This is so because swap fees only grow up: trades are made, swap fees are taken. These variables are updated during swapping:
https://github.com/Uniswap/v3-core/blob/main/contracts/UniswapV3Pool.sol#L760-L766
When swapping tokens, swap fees are subtracted from input amounts and counted. After a swap is done, the global fees are increased by the total swap fees accumulated during the swap.
If I understand the question correctly, it's…