Query editor
/** [Title] TON Circulating Supply, Price & Valuation (Fixed History)** [Description]* Calculates Daily Circulating Supply, Staking Ratio, and USD Valuation with EXACT historical accuracy.** [Logic]* 1. Total Supply & DAO Vault: Cumulative sums calculated from GENESIS (Block ~10M) to ensure accuracy.* 2. Circulating Supply = Total Supply - DAO Vault - Staked Amount.* 3. USD Valuation = Circulating Supply * Daily TON Price.** [Reference]* - Price Source: prices.day (Contract: 0x2be5...)* - Display Filter: Shows data from Block 18,700,000 onwards (approx. Dec 2023).*/WITH-- ==========================================================-- 0. [Price] Daily TON Price-- ==========================================================TON_Price AS (SELECTDATE(timestamp) as price_date,priceFROM prices.dayWHEREcontract_address = 0x2be5e8c109e2197D077D13A82dAead6a9b3433C5AND timestamp >= NOW() - INTERVAL '3' YEAR -- 넉넉하게 3년치 가져옴),-- ==========================================================-- 1. [Structure] Define Time Spine (Entire History)-- ==========================================================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 BurnsDaily_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),