Query editor
/* ===================================================STAGE 2a: WEEKLY STABLECOIN BALANCESSave as dune.boc.result_weekly_balances.One row per (wallet, week) for every wallet in result_linked_wallets, forweeks in 2021-2025 in which the wallet held a positive stablecoin balanceon at least one day. Weeks not in the table are zero-balance weeks.Stablecoins: every token in stablecoins_evm.balances_enriched on Ethereum(decision 8), grouped USDT / USDC / other.Forward-fill (Stage 0 check 1): the table writes rows while a balance isheld and a zero row when it drops to zero. Each row is carried forward tothe day before the token's next row (or to 2025-12-31), so any gaps arefilled with the last observed balance, zeros included. Rows before 2021are read so balances held on 2021-01-01 carry into the window.Columns per week:- max_usd: highest daily total (used for the $5M screen and forpersistence: a holding week is a week with max_usd >= $10)- avg_usd: average daily total over the 7 days, zero days included- end_usd: total on the last day of the week, also split by group- days_held: days in the week with a positive total=================================================== */WITH wallets AS (SELECT DISTINCT wallet FROM dune.boc.result_linked_wallets),rows_ AS (SELECTb.address AS wallet,b.token_address,CAST(b.day AS date) AS day,COALESCE(b.balance_usd, 0) AS balance_usdFROM stablecoins_evm.balances_enriched bINNER JOIN wallets w ON b.address = w.walletWHERE b.blockchain = 'ethereum'AND b.day < DATE '2026-01-01'),intervals AS (-- each row holds until the day before the token's next rowSELECTwallet,token_address,balance_usd,greatest(day, DATE '2021-01-01') AS start_day,least(COALESCE(date_add('day', -1, LEAD(day) OVER (PARTITION BY wallet, token_address ORDER BY day)),DATE '2025-12-31'),DATE '2025-12-31') AS end_dayFROM rows_),daily_token AS (SELECT i.wallet, i.token_address, d AS day, i.balance_usdFROM intervals iCROSS JOIN UNNEST(sequence(i.start_day, i.end_day, INTERVAL '1' DAY)) AS t(d)WHERE i.balance_usd > 0