v3-subgraph
v3-subgraph copied to clipboard
TVl Calculations Incorrect for pools
Conversion from here https://github.com/Uniswap/v3-info/issues/186
- In a majority of
pools
the TVL in terms oftoken0
andtoken1
is incorrect
Steps to Reproduce (provided by @tcpzl)
- Go to the homepage of v3-info. We can find that the USDC/ETH and WBTC/ETH are the two most popular pools (highest TVL). Then click into the page of pool.
- Copy the contract address of the pool, then find it on etherscan. We can find the actual contracts: https://etherscan.io/address/0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8, and https://etherscan.io/address/0xcbcdf9626bc03e24f779434178a73a0b4bad62ed. However, the TVLs of ETH are not as the same as they are on etherscan. Unfortunately, there is a large gap
Current Production State
- The current production v3 subgraph can be found here
- The subgraph deployed code at that endpoint can be found in the pricing-hotfix branch
Possible cause for error
- I'm confident that the reason for this issue is that we are currently not tracking
Collect
events on pools correctly in this version of the subgraph. This means that as people collect fees - we dont subtract the collected amounst from the pool tvl. This would lead to the described issues
Solution*
- tracking these collect events would most likely solve the issue
- you can see in this branch we track the collect events - but dont handle TVL in the logic
- we should use those
amount0
andamount1
values and subtract them from the pool TVL - Issue syncing this change - the current v3 subgraph in this state will take multiple weeks to sync from scratch, however, for this change, a standard graft wont work because for TVL we need to track all events ever (not just new ones)
- proposed solution: add some complex logic where we "reset" the tvl only for transactions within a certain block range (this will fix current tvl errors) - to do this could call balanceOf on the pool contracts
- then, add tracking for Collect events in a handleCollect event handler
- then sync with a graft sync (can have @ianlapham review pr and try sync)
UPDATE:
This bug is fixed in this PR: https://github.com/Uniswap/v3-subgraph/pull/100/files Subgraph deployed and synced here: https://thegraph.com/hosted-service/subgraph/ianlapham/v3-minimal
Needed to wait aout 5 weeks for subgraph to sync, but once tested can merge this into main. NOTE: this involves several schema changes
Hey @ianlapham, is it safe to use the Subgraph (v3-minimal), or do I have to wait around 5 weeks to get it synced with your changes?
Thanks for fixing this!
ok aliya mr30
I tried correcting for this in my Uniswap V3 subgraph, and when I include the subtraction of tokens from a pool on the Collect
event, I get negative token values.
This happened on my subgraph, and from this branch -- > https://github.com/Uniswap/v3-subgraph/tree/mainnet-2.0
The only change I made on this branch was including the Collect handler in the subgraph.yaml.
Awesome work @ianlapham Are we just waiting for PR to be reviewed and merged in?