Query editor
with--timetime AS(with time_seq as (SELECTsequence(cast('2024-02-12 11:00' as TIMESTAMP) --Gravita Launched on Optimism, date_trunc('hour', cast(now() as TIMESTAMP)), interval '1' hour) as time)SELECTtime.time as hourFROM time_seqCROSS JOIN unnest(time) as time(time)),balance as (SELECTdate_trunc('hour', evt_block_time) as hour, max(_balance / 1e18) as amount_balancefrom gravita_optimism.ActivePool_evt_ActivePoolAssetBalanceUpdatedwhere_asset = 0x9Bcef72be871e61ED4fBbc7630889beE758eb81D -- rETH (Optimism)GROUP by 1order by 1 desc),balance_raw as (SELECTt.hour, amount_balance, count(amount_balance) over (order by t.hour) as _grpfrom time tleft join balance bon t.hour = b.hour),balance_fill as (selecthour, max(amount_balance) over (partition by _grp order by hour) as amount_balancefrom balance_raw b),-- Get the hourly token prices in USDtoken_prices as (SELECTq.hour,c.contract_address,decimals,symbol,first_value(q.price) over (partition by q.value_partition order by q.hour) as priceFROM (SELECTt.hour,contract_address,median_price as price,