Query editor
with events as (select *from query_3862587 -- Davos Provider Events (Linea)),daily_agg as (select date_trunc('day', a.evt_block_time) as "date", a.collateral_address, sum(case when event = 'deposit' then amount else -amount end) as sharesfrom events agroup by 1, 2),days as (with days_seq as (select sequence(date('2024-05-02'), date_trunc('day', cast(now() as timestamp)), interval '1' day) as day)select days.day as "date"from days_seqcross join unnest(day) as days(day) -- Unnesting sequence of days),daily_fillers as (select d."date", p.collateral_addressfrom days dcross join (select distinct collateral_address from query_3845337 where blockchain = 'linea' -- Davos Vaults and Collateral List) p),balance_data as (select f."date", f.collateral_address, coalesce(d.shares, 0) as shares,sum(coalesce(d.shares, 0)) over (partition by f.collateral_address order by f."date") as token_shares_collateralfrom daily_fillers fleft join daily_agg d on f."date" = d."date" and f.collateral_address = d.collateral_address),prices as (select token, time as "date", price, decimals, symbolfrom query_3865870 -- Davos Collateral Prices (Linea)where time >= cast('2024-05-02' as timestamp) -- start fetching),final as (select b."date", b.collateral_address, b.shares, p.symbol, p.price, p.price/weth.price as eth_ratio, b.token_shares_collateral as token_shares_collateral_per_symbol,b.token_shares_collateral*p.price/weth.price as token_eth_collateral_per_symbol, b.token_shares_collateral*p.price as token_usd_collateral_per_symbol,(sum(b.token_shares_collateral*(p.price/weth.price)) over(partition by b.date)) as token_eth_collateral,(sum(b.token_shares_collateral*p.price) over(partition by b.date)) as token_usd_collateralfrom balance_data bjoin prices p on p.date = b."date" and b.collateral_address = p.tokenjoin prices weth on weth."date" = b."date" and weth.token = 0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f -- wETH),done as (select *,casewhen token_usd_collateral/lag(token_usd_collateral,1) over (partition by symbol order by "date") - 1 < 0.0001 then 0else token_usd_collateral/lag(token_usd_collateral,1) over (partition by symbol order by "date") - 1end as change_1d, token_usd_collateral/lag(token_usd_collateral,7) over (partition by symbol order by "date") - 1 as change_7dfrom final where token_eth_collateral is not null)select "date" as time, symbol, price, eth_ratio, token_shares_collateral_per_symbol, token_eth_collateral_per_symbol,token_usd_collateral_per_symbol, token_eth_collateral, token_usd_collateral, change_1d as change_1D, change_7d as change_7Dfrom donewhere token_usd_collateral > 0and token_eth_collateral > 0