Query editor
with events as (select *from query_3829482 -- Inception Vaults Event (flashWithdraw, Deposit, Withdraw)),daily_agg as (select date_trunc('day', a.evt_block_time) as "date", a.token_address, sum(case event when 'deposit' then amount else -amount end) as sharesfrom events agroup by 1,2),days as (with days_seq as (select sequence((date('2023-12-26')), date_trunc('day', cast(now() as timestamp)), interval '1' day) as day)select days.day as datefrom days_seqcross join unnest(day) as days(day) --this is just doing explode like in spark sql),daily_fillers as (select *from days dcross join (select distinct token_address from query_3823368 -- Inception Asset/Vaults address list) p),balance_data as (select f."date", f.token_address, d.shares, sum(d.shares) over (partition by f.token_address order by f."date") as token_shares_restakedfrom daily_fillers fleft join daily_agg d on f."date" = d."date"and f.token_address = d.token_address),prices as (select token, "date", price, decimals, symbolfrom query_3917735where "date" >= cast('2023-12-26' as timestamp) -- start fetchingunion allselect 0xf073bAC22DAb7FaF4a3Dd6c6189a70D54110525C as token, p."date", p.price, 18 as decimals, 'inETH' as symbolfrom query_3917735 pwhere p.token = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -- WETHand p."date" >= cast('2023-12-26' as timestamp) -- start fetching),final as (select b."date", b.token_address, b.shares, p.symbol, p.price, p.price/weth.price as eth_ratio, b.token_shares_restaked as token_shares_restaked_per_symbol,b.token_shares_restaked*p.price/weth.price as token_eth_restaked_per_symbol, b.token_shares_restaked*p.price as token_usd_restaked_per_symbol,(sum(b.token_shares_restaked*(p.price/weth.price)) over(partition by b.date)) as token_eth_restaked,(sum(b.token_shares_restaked*p.price) over(partition by b.date)) as token_usd_restakedfrom balance_data bjoin prices p on p.date = b."date" and b.token_address = p.tokenjoin prices weth on weth."date" = b."date" and weth.token = 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2),done as (select *,casewhen token_usd_restaked/lag(token_usd_restaked,1) over (partition by symbol order by "date") - 1 < 0.0001 then 0else token_usd_restaked/lag(token_usd_restaked,1) over (partition by symbol order by "date") - 1end as change_1d, token_usd_restaked/lag(token_usd_restaked,7) over (partition by symbol order by "date") - 1 as change_7dfrom final where token_eth_restaked is not null