Query editor
/* ============================================================================KPI · Top row — protocol revenue and Ink Foundation share, 7d / 30d / all-time----------------------------------------------------------------------------Rows: Total, Tsunami, Calamari (counters read row 1 = Total).Accrual basis (fees when charged) unless the column says "received".7d / 30d = the last 7 / 30 UTC calendar days including today.Foundation share = revenue x {{foundation_share_pct}}%.========================================================================== */WITH daily AS (SELECT day, protocol,sum(computed_revenue_usd) AS rev_usd,sum(computed_revenue_eth) AS rev_eth,sum(received_in_treasury_usd) AS recv_usd,sum(received_in_treasury_eth) AS recv_ethFROM query_9105610WHERE protocol IN ('Tsunami', 'Calamari')GROUP BY 1, 2),w AS ( -- GROUPING SETS gives per-protocol rows and the Total in one pass (a UNION would run the whole chain twice)SELECT coalesce(protocol, 'Total') AS protocol,sum(CASE WHEN day >= date_trunc('day', now()) - INTERVAL '6' DAY THEN rev_usd END) AS rev_7d_usd,sum(CASE WHEN day >= date_trunc('day', now()) - INTERVAL '29' DAY THEN rev_usd END) AS rev_30d_usd,sum(rev_usd) AS rev_all_usd,sum(CASE WHEN day >= date_trunc('day', now()) - INTERVAL '6' DAY THEN rev_eth END) AS rev_7d_eth,sum(CASE WHEN day >= date_trunc('day', now()) - INTERVAL '29' DAY THEN rev_eth END) AS rev_30d_eth,sum(rev_eth) AS rev_all_eth,sum(recv_usd) AS recv_all_usd,sum(recv_eth) AS recv_all_ethFROM dailyGROUP BY GROUPING SETS ((protocol), ()))SELECT protocol,round(rev_7d_usd, 2) AS protocol_revenue_7d_usd,round(rev_30d_usd, 2) AS protocol_revenue_30d_usd,round(rev_all_usd, 2) AS protocol_revenue_all_time_usd,round(rev_7d_usd * {{foundation_share_pct}} / 100.0, 2) AS foundation_share_7d_usd,round(rev_30d_usd * {{foundation_share_pct}} / 100.0, 2) AS foundation_share_30d_usd,round(rev_all_usd * {{foundation_share_pct}} / 100.0, 2) AS foundation_share_all_time_usd,round(rev_7d_eth, 4) AS protocol_revenue_7d_eth,round(rev_30d_eth, 4) AS protocol_revenue_30d_eth,round(rev_all_eth, 4) AS protocol_revenue_all_time_eth,round(rev_all_eth * {{foundation_share_pct}} / 100.0, 4) AS foundation_share_all_time_eth,round(recv_all_usd, 2) AS received_in_treasury_all_time_usd,round(recv_all_usd * {{foundation_share_pct}} / 100.0, 2) AS foundation_share_cash_basis_all_time_usd,-- accrued minus received (treasury reconciliation): fees charged but not yet swept to the treasuryround((rev_all_usd - recv_all_usd) * {{foundation_share_pct}} / 100.0, 2) AS foundation_share_not_yet_swept_usd,round(rev_all_eth - recv_all_eth, 4) AS not_yet_received_ethFROM wORDER BY CASE protocol WHEN 'Total' THEN 0 WHEN 'Tsunami' THEN 1 ELSE 2 END