Query editor
/*MIT LicenseCopyright (c) 2025 Berry_BearPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.Follow me on X: https://x.com/DeFi_Berry_Bear*//*Updated Dune query: support for multiple emission stages (three-stage schedule).- Stage 1: initial emission (until 2025-05-13)- Stage 2: first reduction (2025-05-14 .. 2025-09-11)- Stage 3: second reduction (from 2025-09-12)The query computes a weighted average daily emission per calendar monthwhen a month intersects multiple emission stages (pro-rata by days).All original logic for staked/unstaked and flow calculations is preserved.*/WITH-- emission schedule with explicit date ranges and daily emission valuesemission_schedule AS (SELECT DATE '2020-01-01' AS start_date, DATE '2025-05-13' AS end_date, 102926.0 AS daily_emission UNION ALLSELECT DATE '2025-05-14' AS start_date, DATE '2025-09-11' AS end_date, 30636.27 AS daily_emission UNION ALLSELECT DATE '2025-09-12' AS start_date, NULL AS end_date, 8750.0 AS daily_emission),-- calendar: last 12 months (month granularity)calendar AS (SELECT monthFROM UNNEST(SEQUENCE(DATE_TRUNC('month', CURRENT_DATE - INTERVAL '12' MONTH),DATE_TRUNC('month', CURRENT_DATE),INTERVAL '1' MONTH)) AS t(month)),-- join calendar with emission schedule and calculate overlap daysemission_overlap AS (SELECTc.month,es.daily_emission,-- month start and endDATE_TRUNC('month', c.month) AS month_start,date_add('day', -1, date_add('month', 1, DATE_TRUNC('month', c.month))) AS month_end,-- compute overlap daysGREATEST(0,date_diff(