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 (with pool_init as (select pool, t1.symbol as token0_symb, token, t1.decimals as token0_dec, tokenidfrom curvefi_optimism.poolsleft join (select contract_address, decimals, symbol from tokens.erc20 where blockchain = 'optimism') t1 on t1.contract_address = tokenwhere pool = 0x061b87122ed14b9526a813209c8a59a633257bab --susd/usdc/usdt/dai)select * from (selectevt_block_time, buy.token0_symb as buy_symbol, (swap.tokens_bought / pow(10,buy.token0_dec)) * 1.00 as amount0, sell.token0_symb as sell_symbol, (swap.tokens_sold / pow(10,sell.token0_dec)) * -1.00 as amount1, swap.evt_tx_hashfrom curvefi_optimism.MetaPoolSwap_evt_TokenExchange swapleft join pool_init sell on swap.contract_address = sell.pool and swap.sold_id = sell.tokenidleft join pool_init buy on swap.contract_address = buy.pool and swap.bought_id = buy.tokenidwhere swap.sold_id = 0 or swap.bought_id = 0and evt_block_time > timestamp'2024-05-01'`)where sell_symbol 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 / 1e6,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 (0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85, 0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9)and evt_block_date >= timestamp'2024-03-06')group by hour_normalized)-----------------------Abstraction------------------------, trades_normalized as (