Skip to content

TVl Calculations Incorrect for pools #74

Open

Description

@ianlapham

Conversion from here Uniswap/v3-info#186

  • In a majority of pools the TVL in terms of token0 and token1 is incorrect

Steps to Reproduce (provided by @tcpzl)

  1. 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.
  2. 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 and amount1 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)

Activity

  1. ianlapham commented on Sep 20, 2022

    @ianlapham
    ContributorAuthor

    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

  2. chinchaun commented on Sep 27, 2022

    @chinchaun

    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!

  3. shakibaei65 commented on Oct 14, 2022

    @shakibaei65

    ok aliya mr30

  4. steegecs commented on Oct 22, 2022

    @steegecs

    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.

  5. togosh commented on Jan 20, 2023

    @togosh

    Awesome work @ianlapham Are we just waiting for PR to be reviewed and merged in?

  6. journeytosilius commented on Nov 24, 2024

    @journeytosilius

    I have been trying to replicate the behavior of this repo but with a local full node, via the events for a certain pool ( mint, burn, swap, collect ) and a certain point TVL goes negative. Can somebody explain why ? Might this be due to internal transactions transferring amounts in and out of the pool that are not logged ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions