Query editor
WITH-- 1) your asset lookup table (with symbol and decimals):asset_meta(asset, symbol, decimals) AS (VALUES('TON', 'TON', 9),('0:0E464861AD78ACFD7C4B0007F2C53C8D71E3572ED687709E45857C69349F31B0','stXP',9)),-- 2) generate a calendar of dates (last 30 days through today):days AS (SELECT CAST(d AS date) AS day_dateFROM UNNEST(sequence(date_add('day', -30, current_date),current_date,INTERVAL '1' DAY)) AS t(d)),-- 3) for each asset + date, pick that day’s last raw balance (if any):history_per_day AS (SELECTCAST(block_time AS date) AS day_date,asset,max_by(amount, block_time) AS amount_rawFROM ton.balances_historyWHEREaddress = UPPER('0:b1a9175805f1097dc452c510555188c9fc19160bb45efa1d56b10116c8f9460e')AND asset IN (SELECT asset FROM asset_meta)GROUP BY CAST(block_time AS date), asset),-- 4) build one row per asset × day, and carry forward the most recent day that had a changeasset_day_rollup AS (SELECTm.asset,m.symbol,m.decimals,d.day_date,-- look, for each (asset, day_date), back to the greatest day_date ≤ currentmax(hpd.day_date)OVER (PARTITION BY m.assetORDER BY d.day_dateROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS last_txn_dayFROM days dCROSS JOIN asset_meta mLEFT JOIN history_per_day hpdON hpd.asset = m.assetAND hpd.day_date = d.day_date)-- 5) join back to get that day’s raw amount, then scale by decimals