Query editor
/* ===================================================STAGE 2e: VELOCITYSave as dune.boc.result_velocity.Weekly velocity as defined in the paper (revision list, "Velocity andliquidity-measure definitions"): stablecoin outflows over the two weeksfrom the start of week w, divided by the balance at the start of week w.velocity_w = (out_w + out_{w+1}) / start_balance_wstart_balance_w = end-of-week balance of week w-1 (result_weekly_balances).Only weeks with a start balance of at least $1 count (active weeks).Outflows (result_stablecoin_flows) exclude flash-loan legs and transfersto itself.One row per wallet:- active_weeks, mean and median weekly velocity over 2021-2025- max_year_mean_velocity: highest calendar-year mean weekly velocity- flag_velocity: max_year_mean_velocity > 10,000 (the old yearly screen,applied to any calendar year)Reads materialized tables only.=================================================== */WITH outflow AS (SELECT wallet, week, SUM(usd) AS out_usdFROM dune.boc.result_stablecoin_flowsWHERE direction = 'out'AND category <> 'flashloan'GROUP BY 1, 2),starts AS (-- the balance at the start of week w is the end-of-week balance of w-1SELECT wallet,date_add('day', 7, week) AS week,end_usd AS start_usdFROM dune.boc.result_weekly_balancesWHERE end_usd >= 1AND date_add('day', 7, week) <= DATE '2025-12-29'),weekly AS (SELECTs.wallet,s.week,s.start_usd,(COALESCE(o1.out_usd, 0) + COALESCE(o2.out_usd, 0)) / s.start_usd AS velocityFROM starts sLEFT JOIN outflow o1 ON o1.wallet = s.wallet AND o1.week = s.weekLEFT JOIN outflow o2 ON o2.wallet = s.wallet AND o2.week = date_add('day', 7, s.week)),yearly AS (SELECT wallet, year(week) AS yr, AVG(velocity) AS mean_velocityFROM weeklyGROUP BY 1, 2)SELECTw.wallet,COUNT(*) AS active_weeks,AVG(w.velocity) AS mean_velocity,