Query editor
-- Latest 30 completed reward epochs, represented by canonical epoch-advancement events.-- The event's epoch is the NEW epoch; its reward/storage flow belongs to epoch - 1.-- A current-day epoch-end event is complete and is included. The 45-day partition-- filter is a bounded lookback; data-quality columns expose short/missing coverage.-- Source: MystenLabs/sui sui_system_state_inner.move and storage_fund.move.WITH parsed AS (SELECT from_unixtime(cast(timestamp_ms AS double) / 1000) epoch_end_time,try_cast(json_extract_scalar(event_json, '$.epoch') AS bigint) new_epoch,try_cast(json_extract_scalar(event_json, '$.reference_gas_price') AS bigint) next_epoch_rgp_mist,try_cast(json_extract_scalar(event_json, '$.stake_subsidy_amount') AS bigint) subsidy_mist,try_cast(json_extract_scalar(event_json, '$.total_gas_fees') AS bigint) computation_mist,try_cast(json_extract_scalar(event_json, '$.total_stake_rewards_distributed') AS bigint) rewards_mist,try_cast(json_extract_scalar(event_json, '$.storage_fund_reinvestment') AS bigint) reinvestment_mist,try_cast(json_extract_scalar(event_json, '$.leftover_storage_fund_inflow') AS bigint) leftover_mist,try_cast(json_extract_scalar(event_json, '$.storage_charge') AS bigint) storage_charge_mist,try_cast(json_extract_scalar(event_json, '$.storage_rebate') AS bigint) storage_rebate_mist,try_cast(json_extract_scalar(event_json, '$.storage_fund_balance') AS bigint) fund_balance_mist,_ingested_atFROM sui.eventsWHERE date >= current_date - INTERVAL '45' DAYAND date <= current_dateAND event_type = '0x3::sui_system_state_inner::SystemEpochInfoEvent'), dedup_ranked AS (SELECT *, count(*) OVER (PARTITION BY new_epoch) copies,row_number() OVER (PARTITION BY new_epoch ORDER BY _ingested_at DESC, epoch_end_time DESC) copy_rankFROM parsed), with_previous AS (SELECT *, lag(epoch_end_time) OVER (ORDER BY new_epoch) epoch_start_time,lag(new_epoch) OVER (ORDER BY new_epoch) previous_event_epoch,lag(fund_balance_mist) OVER (ORDER BY new_epoch) previous_fund_balance_mist,row_number() OVER (ORDER BY new_epoch DESC) recency_rankFROM dedup_rankedWHERE copy_rank = 1 AND new_epoch IS NOT NULL), epochs AS (SELECT *, new_epoch - 1 completed_epoch,cast(computation_mist AS double) / nullif(rewards_mist, 0) fee_share,storage_charge_mist - storage_rebate_mist net_storage_mistFROM with_previousWHERE recency_rank <= 30), metrics AS (-- Expand eight metrics only AFTER the canonical events have been reduced to-- thirty rows. This avoids rescanning the events table once per table row.SELECT m.metric_order, m.metric, m.unit,avg(m.metric_value) mean_value, min(m.metric_value) min_value, max(m.metric_value) max_value,count(*) epoch_count, min(completed_epoch) first_completed_epoch,max(completed_epoch) last_completed_epoch,min(epoch_start_time) period_start_utc, max(epoch_end_time) period_end_utc,min(next_epoch_rgp_mist) min_next_epoch_rgp_mist,max(next_epoch_rgp_mist) max_next_epoch_rgp_mist,count_if(copies <> 1) duplicate_epoch_count,count_if(previous_event_epoch <> new_epoch - 1 OR epoch_start_time IS NULL) missing_predecessor_count,count_if(subsidy_mist IS NULL OR computation_mist IS NULL OR rewards_mist IS NULLOR reinvestment_mist IS NULL OR leftover_mist IS NULLOR storage_charge_mist IS NULL OR storage_rebate_mist IS NULLOR fund_balance_mist IS NULL) incomplete_epoch_count,max(abs(subsidy_mist + computation_mist - rewards_mist - reinvestment_mist - leftover_mist)) max_reward_reconciliation_error_mist,max(abs(fund_balance_mist - previous_fund_balance_mist- net_storage_mist - reinvestment_mist - leftover_mist)) max_fund_reconciliation_error_mist,cast(sum(computation_mist) AS double) / nullif(sum(rewards_mist), 0) period_fee_shareFROM epochs