Query editor
-- UST0-related tx fees on Plasma (TOTAL ONLY): daily sums + per-tx avg & median (USD)-- Daily aggregation with the same logic as the hourly version.-- - Excludes mints/burns-- - Fee calc: gas_used * gas_price / 1e18 (XPL), then * hourly XPL/USD-- - Per-tx USD median is computed from per-tx USD (using the matching hourly price)-- - Partial-hour guard preserved via px_hour trimming and cutoffWITH cfg AS (SELECT-- Choose your historical start date (use your original fixed start or adjust as needed)DATE '2025-09-25' AS start_date,-- Partial-hour guard: process data strictly before this hourDATE_TRUNC('hour', CURRENT_TIMESTAMP) - INTERVAL '2' HOUR AS cutoff_hour,0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb AS ust0, -- UST0 contract0x405fbc9004d857903bfd6b3357792d71a50726b0 AS xpl_price_contract, -- XPL/USD price feed18 AS xpl_decimals),-- Distinct txs that touched UST0 (exclude mints/burns)ust0_txs AS (SELECT DISTINCT evt_tx_hash AS tx_hashFROM erc20_plasma.evt_transferWHERE contract_address = (SELECT ust0 FROM cfg)AND evt_block_time >= CAST((SELECT start_date FROM cfg) AS TIMESTAMP)AND evt_block_time < (SELECT cutoff_hour FROM cfg)AND "from" <> 0x0000000000000000000000000000000000000000AND "to" <> 0x0000000000000000000000000000000000000000),-- Per-transaction TOTAL fee in XPL (no base/tip split)per_tx AS (SELECTDATE_TRUNC('day', t.block_time) AS day_utc,DATE_TRUNC('hour', t.block_time) AS hour_utc,t.hash AS tx_hash,(CAST(t.gas_used AS DOUBLE) * CAST(t.gas_price AS DOUBLE))/ POWER(10, (SELECT xpl_decimals FROM cfg)) AS fee_total_xpl_per_txFROM plasma.transactions tINNER JOIN ust0_txs uON u.tx_hash = t.hashWHERE t.success = TRUEAND t.block_time >= CAST((SELECT start_date FROM cfg) AS TIMESTAMP)AND t.block_time < (SELECT cutoff_hour FROM cfg)),-- Average hourly XPL/USD pricepx_hour_raw AS (SELECTDATE_TRUNC('hour', "timestamp") AS hour_utc,AVG(CAST(price AS DOUBLE)) AS xpl_usd_hourlyFROM prices.hourWHERE contract_address = (SELECT xpl_price_contract FROM cfg)AND "timestamp" >= CAST((SELECT start_date FROM cfg) AS TIMESTAMP)AND "timestamp" < (SELECT cutoff_hour FROM cfg)AND price IS NOT NULLGROUP BY 1),-- Optional: drop newest priced hour to avoid partial-hour artifactspx_hour AS (