Query editor
/** [Title] TON Daily APY (Tokamak Official Formula)** [Description]* Reuses the same historical-accurate pipeline as `dune_daily.sql`* (circulating supply & staking ratio) and adds the APY calculation* exactly like the official Tokamak dApp.** [Official dApp Formula]* 1. Fetch Total Staked (stakeOfTotal) and Total Supply (totalSupplyOfTon)* 2. Annual ROI =* (seigPerBlock * blocksPerYear ** (stakedRatio + 0.4 * (1 - stakedRatio))) / totalStaked* where seigPerBlock = 3.92 TON, blocksPerYear = 2,628,000* 3. APY =* (1 + (annualROI / compoundsPerMonth))^(compoundsPerMonth) - 1* where compoundsPerMonth = 12.16666667 (seigniorage update frequency)** Because Dune cannot call view functions directly, we reconstruct the* same total supply and total staked metrics via on-chain events* (identical to dune_daily.sql) and then apply the official formula.*/WITH-- ==========================================================-- 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 Sources] Fetch Raw Events-- ==========================================================Base_Supply AS (SELECT output_0 / 1e18 AS initial_supplyFROM tokamak_network_ethereum.TON_call_totalSupplyORDER BY call_block_time ASCLIMIT 1),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),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_TransferGROUP BY 1