Query editor
WITH-- ===== Protocol fees from events =====trades_a AS (SELECTvarbinary_to_uint256(data[15]) * DECIMAL '0.000001' AS actual_fee,transaction_hash,block_timeFROM starknet.eventsWHERE from_address = 0x062da0780fae50d68cecaa5a051606dc21217ba290969b302db4dd99d2e9b470AND keys[1] = 0x02e0a012a863e6b614014d113e7285b06e30d2999e42e6e03ba2ef6158b0a8f1AND block_time >= TIMESTAMP '2025-09-01'),trades_b AS (SELECTvarbinary_to_uint256(data[16]) * DECIMAL '0.000001' AS actual_fee,transaction_hash,block_timeFROM starknet.eventsWHERE from_address = 0x062da0780fae50d68cecaa5a051606dc21217ba290969b302db4dd99d2e9b470AND keys[1] = 0x02e0a012a863e6b614014d113e7285b06e30d2999e42e6e03ba2ef6158b0a8f1AND block_time >= TIMESTAMP '2025-09-01'),-- Union of trade events only (for per-trade metrics)trades AS (SELECT * FROM trades_aUNION ALLSELECT * FROM trades_b),-- Daily average fee per trade (trade events only)trades_daily AS (SELECTdate_trunc('day', block_time) AS day,COUNT(*)/2 AS daily_trade_count, --divide by 2 since the trades tabletrades are for the two sidesAVG(actual_fee) AS daily_avg_fee_per_tradeFROM tradesGROUP BY 1),liquidations AS (SELECTvarbinary_to_uint256(data[9]) * DECIMAL '0.000001' AS actual_fee,transaction_hash,block_timeFROM starknet.eventsWHERE from_address = 0x062da0780fae50d68cecaa5a051606dc21217ba290969b302db4dd99d2e9b470AND keys[1] = 0x0320efd552d992294b62e23bcfa29f7703b7b899c22eb04973d36655afd06ddfAND block_time >= TIMESTAMP '2025-09-01'),events AS (SELECT * FROM tradesUNION ALLSELECT * FROM liquidations),fees_daily AS (SELECTdate_trunc('day', block_time) AS day,SUM(actual_fee) AS daily_protocol_feesFROM eventsGROUP BY 1),