balancer / dune-spellbook

SQL views for Dune Analytics
Other
7 stars 11 forks source link

fix eth:EPOCH/WETH pool's liquidity #54

Closed mendesfabio closed 11 months ago

mendesfabio commented 11 months ago

Pibbles (Discord) reached out reporting EPOCH/WETH pool TVL is understimated on Dune

hi - can someone explain how the dune table: balancer_v2_ethereum.liquidity is calculated/updated? i'm assuming that the table gets updated on daily basis and is lagging behind but just want to make sure for reference, i'm looking at this balancer pool: https://app.balancer.fi/#/ethereum/pool/0x82b8c7c6fb62d09cfd004309c1f353fb1a926edc000200000000000000000626 the site says there should be about 1.2m TVL but the table seems to be understating it (historical values too)

I quickly investigated the problem and answered him

the TVL is calculated as usual - in this case (ETH balance price) + (EPOCH balance price). It seems the problem is EPOCH isn't available on prices.usd (Dune's price feed from Coinpaprika) so we fallback to dex.prices which estimates tokens prices based on trades from DEXs. If you query dex.prices for EPOCH you will notice we only get 8 results - there's a price for today that makes sense but last entry before it is from weeks ago and that's the price our spell has been using for the past days =/ I think dex.prices hasn't been registering prices for EPOCH because they have threshold of >5 trades in a hour - see: https://github.com/duneanalytics/spellbook/blob/main/models/dex/dex_prices.sql#L65

If we estimated this pool's TVL based on weights and WETH price that would not be a problem. It also made me think we shouldn't fill prices if there's too much days without one. After fix is implemented/merged, get back to this guy on Discord.

viniabussafi commented 11 months ago

As this query shows, https://github.com/duneanalytics/spellbook/pull/4960 successfully handles this issue. Once it's reviewed and merged, we should be safe against pricing issues on weighted pool's TVL. image image

mendesfabio commented 11 months ago

could you compare your query vs balancer.liquidity for this pool? I'm curious what the results look like now and what happened to balancer.liquidity after trades happened last week

viniabussafi commented 11 months ago

given the limitations on prices for the EPOCH token, the 'new' calculation for liquidity (on the open PR) is much more up-to-date and precise, following the fluctuations shown on the frontend image

mendesfabio commented 11 months ago

yea, agreed, was just wondering how balancer.liquidity responded to last trades. let's keep this issue open as a reminder to get back to Pibbles on Discord once PR is merged.

viniabussafi commented 11 months ago

PR merged and issue fixed