Query editor
-- Params:-- {{time_granularity}} -- manual list: day|week|month-- {{lookback_periods}} -- integer/text: number of periods (e.g., 12 months, 8 weeks, 30 days)WITHparams AS (SELECTCASE LOWER('{{time_granularity}}')WHEN 'week' THEN 'week'WHEN 'month' THEN 'month'ELSE 'day'END AS gran,COALESCE(TRY_CAST('{{lookback_periods}}' AS integer), 90) AS periods),window AS (SELECTgran,CASE granWHEN 'month' THEN date_add('month', -periods, now())WHEN 'week' THEN date_add('week', -periods, now())ELSE date_add('day', -periods, now())END AS start_tsFROM params),-- Zora contracts (extend as needed)zora_addresses(address) AS (VALUES(from_hex('c90e349360c43a0217cef289f231c66d4748960f')), -- BUY_SUPPLY_WITH_SWAP_ROUTER_HOOK(from_hex('45bf86430af7cd071ea23ae52325a78c8d12ad5a')), -- COIN_V3_IMPL(from_hex('7cad62748ddf516cf85bc2c05c14786d84cf861c')), -- COIN_V4_IMPL(from_hex('36853f9f48faee51bd3db15db21eb4b9038bb795')), -- CREATOR_COIN_IMPL(from_hex('d88f6bdd765313cafa5888c177c325e2c3abf2d2')), -- HOOK_UPGRADE_GATE(from_hex('777777751622c0d3258f214f9df38e35bf45baf3')), -- ZORA_FACTORY(from_hex('8ec7f068a77fa5fc1925110f82381374ba054ff2')), -- ZORA_FACTORY_IMPL(from_hex('777777c4c14b133858c3982d41dbf02509fc18d7')), -- ZORA_HOOK_REGISTRY(from_hex('c8d077444625eb300a427a6dfb2b1dbf9b159040')) -- ZORA_V4_COIN_HOOK),zora_coins(address) AS (SELECT coin AS addressFROM zora_base.zoracoinfactory_evt_coincreatedv4),all_addresses AS (SELECT address FROM zora_addressesUNION ALLSELECT address FROM zora_coins),/* ---------------- Denominators ---------------- */-- Total leaf trace gas per bucket (true trace gas without double-counting)bucket_total_leaf_trace_gas AS (SELECTCASE (SELECT gran FROM params)WHEN 'week' THEN date_trunc('week', t.block_time)WHEN 'month' THEN date_trunc('month', t.block_time)ELSE date_trunc('day', t.block_time)END AS bucket,SUM(t.gas_used) AS total_leaf_trace_gasFROM base.traces tCROSS JOIN window