Query editor
/* ============================================================================QUERY: Lazy Summer - Monthly Churn (Official Data Source)AUTHOR: Contango Data TeamDESCRIPTION:Uses Lazy Summer's official pre-computed results tables. This ensures:- Proper USD price conversions (market prices, not hardcoded constants)- Complete vault & chain coverage (Base, Ethereum, Arbitrum, Sonic, Hyperliquid)- Consistency with Lazy Summer's own active user definitionsDATA SOURCES:- dune.lazysummer.result_user_cumulative_balance_shares_referrals(per-user, per-day deposit/withdrawal activity with USD values)- dune.lazysummer.result_tmp_2_referrals(daily aggregate metrics — used for the official active user count reference)METHODOLOGY:- Aggregates each user's net deposit flow (deposits - withdrawals) by month- Builds a dense calendar to carry forward users who hold without transacting- Computes cumulative balance per user, then compares month-over-month- Active User: cumulative net balance > ${{min_balance}}- Churned User: was Active last month, dropped to <= ${{min_balance}} this monthUSER IDENTIFIER: 'owner' column in the official results table.============================================================================ */-- =====================================================================-- 1. MONTHLY NET FLOWS PER USER (from official results table)-- =====================================================================WITH monthly_deltas AS (SELECTDATE_TRUNC('month', CAST(u.day AS DATE)) AS month,u.owner,SUM(u.deposits_usd_value - u.withdrawals_usd_value) AS net_usdFROM dune.lazysummer.result_user_cumulative_balance_shares_referrals uGROUP BY 1, 2),-- =====================================================================-- 2. DENSE MATRIX GENERATION-- =====================================================================user_starts AS (SELECT owner, MIN(month) AS first_monthFROM monthly_deltasGROUP BY 1),calendar AS (SELECT CAST(d AS DATE) AS monthFROM UNNEST(sequence(DATE('2025-01-01'),DATE_TRUNC('month', CURRENT_DATE),INTERVAL '1' MONTH)) AS t(d)),dense_matrix AS (SELECT c.month, u.ownerFROM calendar cJOIN user_starts u ON c.month >= u.first_month