Query editor
-- Computes the TVL, lp token total supply and lp token price of a uniswap pool over time-- Parameters-- {{token_a}} - either token of the desired uni pool-- {{token_b}} - other token of the desired uni pool-- {{start}} - date as of which the analysis should run-- {{blockchain}} - the blockchain to evaluate this for-- Given that we might not have records every day in the source data (e.g. not every day the lp supply may change),-- but still want to visualize development on a per day basis, we create an auxiliary table with one record per-- day between `start` and `now`with date_range as (select t.dayfromunnest(sequence(date(timestamp '{{start}}'),date(now()))) t (day) --noqa: AL01),-- select the pool with the largest latest kpool as (selectpair AS contract_address,token0,token1from uniswap_v2_{{blockchain}}.UniswapV2Factory_evt_PairCreatedwhere pair = {{pool}}),-- per day lp token total supply changes of the uniswap pool by looking at burn/mint eventslp_supply_delta as (selectdate(evt_block_time) as "day",sum(case when "from" = 0x0000000000000000000000000000000000000000 then value else -value end) as deltafrom erc20_{{blockchain}}.evt_transferwherecontract_address = (select contract_address from pool)and ("from" = 0x0000000000000000000000000000000000000000 or "to" = 0x0000000000000000000000000000000000000000)group by date(evt_block_time)),-- per day lp token total supply by summing up all deltas (may have missing records for some days)lp_total_supply_incomplete as (selectday,sum(delta) over (order by day) as total_lpfrom lp_supply_delta),-- performance optimisation: reduce the total range of the join below to the last value before the start periodlp_total_supply_start as (select max(day) as "start"from lp_total_supply_incompletewhere day <= date(timestamp '{{start}}')),-- lp token total supply without date gapslp_total_supply as (selectday,