Query editor
with time_series as (with series as (SELECT date_add('hour', step, day) AS timeFROM unnest(SEQUENCE(CAST('2023-04-10 00:00' AS TIMESTAMP), current_date, INTERVAL '1' day)) AS t(day)CROSS JOIN (SELECT * FROM unnest(SEQUENCE(1, 1440, 1)) AS t(step)))select time from seriesWHERE time between CAST('2023-04-18 13:00' as TIMESTAMP) AND NOW() -- INTERVAL '1' hour)),total_swETH as (with minted as (SELECT evt_block_time as "time", CAST(value as INT256) as amount from swell_v3_ethereum.swETH_evt_TransferWHERE "from" = 0x0000000000000000000000000000000000000000),burned as (SELECT evt_block_time as "time", COALESCE(-(CAST(swETHBurned as INT256)), CAST(0 as INT256)) as amount from swell_v3_ethereum.swETH_evt_ETHWithdrawn),total as (SELECT time, amount/1e18 as amount from mintedunion ALLSELECT time, amount/1e18 as amount from burned)SELECT time, amount from total),swETHTotal as (SELECTDATE_TRUNC('hour', t.time) as time,--ROW_NUMBER () OVER(PARTITION BY DATE_TRUNC('hour', t.time) order by t.time desc) as rn,(sum(t.amount) OVER (ORDER BY t.time ASC RANGE UNBOUNDED PRECEDING)) as swETHTotalAmountFROM total_swETH t),joins as (select t.time, s.swETHTotalAmount, 3 as auxfrom time_series tLEFT JOIN swETHTotal s on t.time = s.timegroup by 1,2,3),grp as (select *,count (swETHTotalAmount) OVER (PARTITION by aux ORDER BY time) as "grp_swETHTotalAmount"from joins),grp_results as (select time,FIRST_VALUE ("swETHTotalAmount") OVER (PARTITION by "grp_swETHTotalAmount" ORDER BY time) as "swETHTotalAmount"from grp)select s.time, s."swETHTotalAmount", COALESCE(e."stETHHoldings_ETH_value", 0) as "stETHHoldings_ETH_value", COALESCE(e.wethHoldings, 0) as wethHoldings, p.ethPriceUSD, (p.ethPriceUSD * r."rate" * s."swETHTotalAmount") as swETH_ValuationUSD, (COALESCE(e."stETHHoldings_ETH_value", 0) + COALESCE(e."wethHoldings", 0) + COALESCE(e."totaL_stETH_unclaimed_ETH_value", 0)) * p.ethPriceUSD as vault_ValuationUSD