Query editor
with timedelta as (select casewhen lower('{{Time Granularity}}') = 'day' then (now() - interval '1' day)when lower('{{Time Granularity}}') = 'week' then (now() - interval '7' day)when lower('{{Time Granularity}}') = 'month' then (now() - interval '30' day)end as time,casewhen lower('{{Time Granularity}}') = 'day' then 1when lower('{{Time Granularity}}') = 'week' then 7when lower('{{Time Granularity}}') = 'month' then 30end as days),tvl as (select token_address, sum(tvl_usd) as tvl_usdfrom query_1995773where blockchain = 'ethereum'and day = date_trunc('day', now())and (not {{Show V3 Only}} or version = '3')group by 1),trades as (selecttoken_address,sum(amount_usd) as volume,count(*) as swaps,count(distinct user_address) as users,sum(amount_usd * fee_percent / 100) as feesfrom (select token0_address as token_address, amount_usd, user_address, fee_percentfrom query_1988292where blockchain = 'ethereum'and swap_time >= (select time from timedelta)and (not {{Show V3 Only}} or version = '3')union allselect token1_address as token_address, amount_usd, user_address, fee_percentfrom query_1988292where blockchain = 'ethereum'and swap_time >= (select time from timedelta)and (not {{Show V3 Only}} or version = '3'))group by 1)select tvl.token_address, symbol as token_symbol, pools,tvl_usd, volume, swaps, users, fees,100 * volume / tvl_usd / (select days from timedelta) as capital_efficiency,365 * 100 * fees / tvl_usd / (select days from timedelta) as aprfrom tvlleft join tradeson tvl.token_address = trades.token_addressleft join query_1987693 tokenon tvl.token_address = token.token_addresswhere token.blockchain = 'ethereum'order by tvl_usd desc