Skip to content

TVl Calculations Incorrect for pools #74

Open
@ianlapham

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)

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