Query editor
WITH ev AS (SELECT DISTINCTe.transaction_hash,e.keys[2] AS userFROM starknet.events eWHERE e.from_address = 0x05B4FF547559E1B0681E8F62A0d420f83009a6491f4927f3f158b932abff5f7fAND CARDINALITY(e.keys) >= 2),x AS (SELECTt.block_time,t.transaction_hash,t.actual_fee_amount / 1e18 AS fee,CASE WHEN t.actual_fee_unit = 'FRI' THEN 'STRK' ELSE 'ETH' END AS tkFROM starknet.transactions tWHERE t.transaction_hash IN (SELECT transaction_hash FROM ev)),prices AS (SELECTdate_trunc('day', minute) AS time,avg(price) AS pr,CASEWHEN contract_address = 0xca14007eff0db1f8135f4c25b34de49ab0d42766 THEN 'STRK'ELSE 'ETH'END AS tkFROM prices.usdWHERE minute >= TIMESTAMP '2025-01-09 00:00:00'AND blockchain = 'ethereum'AND contract_address IN (0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2, -- WETH0xca14007eff0db1f8135f4c25b34de49ab0d42766 -- STRK)GROUP BY 1, 3),user_fees AS (SELECTev.user,SUM(x.fee * p.pr) AS total_fee_usdFROM xJOIN ev ON ev.transaction_hash = x.transaction_hashJOIN prices pON date_trunc('day', x.block_time) = p.timeAND x.tk = p.tkGROUP BY ev.user)SELECTapprox_percentile(total_fee_usd, 0.5) AS "Median fees per user (USD)",SUM(total_fee_usd) AS "Total fees (USD)",COUNT(DISTINCT user) AS "Unique users"FROM user_fees;