Query editor
------------------DIMS---------------With time_table as (SELECT date_add('hour', step, day) AS hourFROM unnest(SEQUENCE(CAST('2024-05-01' AS TIMESTAMP), current_date, INTERVAL '1' day)) AS t(day)----- generate a sequence (this will create the number of rows necessary for each day)CROSS JOIN (SELECT * FROM unnest(SEQUENCE(1, 24, 1)) AS t(step))), time_table_12h as (select hour from time_tablewhere (extract(HOUR FROM hour) in (0, 12)))---------------Facts-----------------, curve_trades as (select block_time, amount_usd, if(token_sold_symbol = 'sUSD', token_bought_amount, token_sold_amount) as amount, 'susd/3crv' as poolfrom curvefi.tradeswhere (token_sold_symbol = 'sUSD' or token_bought_symbol = 'sUSD')and blockchain = 'optimism'and block_date > timestamp'2024-05-01'and project_contract_address in (0x061b87122ed14b9526a813209c8a59a633257bab)and amount_usd is not null), balance_deltas as (select hour_normalized, sum(if(contract_address = 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9, amount / 1e18,0)) as susd, sum(if(contract_address = 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85, amount / 1e18,0)) as usdcfrom (selectcase when extract(HOUR FROM evt_block_time) >= 0 and extract(HOUR FROM evt_block_time) < 12 then date_trunc('day', evt_block_time)else date_trunc('day', evt_block_time) + interval '12' hour end as hour_normalized, contract_address, case when to = 0xbC26519f936A90E78fe2C9aA2A03CC208f041234 then value else value * -1.00 end as amountfrom erc20_optimism.evt_transferwhere to = 0xbC26519f936A90E78fe2C9aA2A03CC208f041234 or "from" = 0xbC26519f936A90E78fe2C9aA2A03CC208f041234and contract_address in (0x1337BedC9D22ecbe766dF105c9623922A27963EC, 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9)and evt_block_date >= timestamp'2024-03-06')group by hour_normalized)-----------------------Abstraction------------------------, trades_normalized as (selectcase when extract(HOUR FROM block_time) >= 0 and extract(HOUR FROM block_time) < 12 then date_trunc('day', block_time)else date_trunc('day', block_time) + interval '12' hour end as hour_normalized, amount_usd, amount, amount_usd / amount as peg, poolfrom curve_trades), time_table_final as (select hour, pool from time_table_12hcross join (select distinct pool from trades_normalized))