Query editor
/** [Title] TON Circulating Supply & Staking Ratio (Fixed Cumulative History)** [Description]* Calculates the Daily Circulating Supply and Staking Ratio with EXACT historical accuracy.** [Key Fix for Accuracy]* To ensure the DAO Vault Balance and Cumulative Burns are correct,* this query calculates cumulative sums from the GENESIS of the contracts (Block ~10M),* and ONLY filters for the display period (Block 18.7M+) at the very end.** [Logic]* 1. Total Supply: Initial + Seigniorage - Cumulative Burns (calculated from day 1).* 2. DAO Vault Balance: Cumulative Net Flow (In - Out) calculated from day 1.* 3. Staked Amount: sWTON Event tracking (Factor * Balance).* 4. Circulating = Total Supply - DAO Vault Balance - Staked Amount.*/WITH-- ==========================================================-- 1. [Structure] Define Time Spine (Entire History)-- ==========================================================-- Seigniorage 시작 시점부터 현재까지의 모든 날짜를 뼈대로 만듭니다.Time_Spine AS (SELECTDATE_TRUNC('day', time) as block_date,MAX(number) as max_block_numberFROM ethereum.blocksWHERE number >= 10837698 -- Genesis of SeigniorageGROUP BY 1),-- ==========================================================-- 2. [Data Source] Fetch Raw Events-- ==========================================================-- 2.1 Initial SupplyBase_Supply AS (SELECT output_0/1e18 as initial_supplyFROM tokamak_network_ethereum.TON_call_totalSupplyORDER BY call_block_time ASC LIMIT 1),-- 2.2 Daily Burns (Transfer to Zero Address)Daily_Burns AS (SELECTDATE_TRUNC('day', evt_block_time) as block_date,SUM(value/1e18) as burned_amountFROM tokamak_network_ethereum.TON_evt_TransferWHERE "to" = 0x0000000000000000000000000000000000000001GROUP BY 1),-- 2.3 Daily DAO Vault Flow (In - Out)Daily_Vault_Net AS (SELECTDATE_TRUNC('day', evt_block_time) as block_date,SUM(CASE WHEN "to" = 0x2520CD65BAa2cEEe9E6Ad6EBD3F45490C42dd303 THEN value/1e18 ELSE 0 END) -SUM(CASE WHEN "from" = 0x2520CD65BAa2cEEe9E6Ad6EBD3F45490C42dd303 THEN value/1e18 ELSE 0 END) as net_changeFROM tokamak_network_ethereum.TON_evt_Transfer-- No WHERE clause on block number here to catch ALL historyGROUP BY 1),