Query editor
/* DEFI APP ($HOME): Monthly Retention — Hybrid Staking + Activity ModelACTIVE USER DEFINITION:A user is "Active" in a given month if they meet AT LEAST ONE of:1. Has a cumulative staked HOME balance >= ${{min_usd_balance}} in the MFD contract2. Sent HOME tokens cross-chain via OFT (user is actively moving assets)3. Received HOME tokens cross-chain via OFT (user is receiving assets)DATA LIMITATIONS:- MFD staking is Base-only (Ethereum, Arbitrum, Solana not captured)- Staked tokens are locked 3–12 months — churn is mechanically suppressed during lock period.Near-zero churn = high capital commitment, not necessarily daily engagement.- OFT events (OFTSent / OFTReceived) use standard LayerZero column names ('from', 'to').Verify in Dune Data Explorer if column errors occur.- USD conversion uses live prices.usd, falling back to $0.03 if unavailable.*/WITH monthly_prices AS (-- Use actual market prices for HOME on Base (avoids hardcoded constant)-- Falls back to $0.03 in monthly_deltas if no price data exists for a given monthSELECTDATE_TRUNC('month', minute) AS month_bucket,AVG(price) AS avg_priceFROM prices.usdWHERE symbol = 'HOME'AND blockchain = 'base'GROUP BY 1),raw_stakes AS (-- 1. Users Locking Tokens (Positive Token Delta)SELECTDATE_TRUNC('month', evt_block_time) as month_bucket,"user" as user_address,CAST(amount AS DOUBLE) / 1e18 as token_deltaFROM defiapp_base.mfdbase_evt_lockedUNION ALL-- 2. Users Withdrawing Tokens (Negative Token Delta)SELECTDATE_TRUNC('month', evt_block_time) as month_bucket,"user" as user_address,-(CAST(amount AS DOUBLE) / 1e18) as token_deltaFROM defiapp_base.mfdbase_evt_withdrawn),-- Aggregate Raw Tokens FIRST, then apply USD conversionmonthly_deltas AS (SELECTr.month_bucket,r.user_address,-- Use live market price; fall back to $0.03 if prices.usd has no data for that monthSUM(r.token_delta) * COALESCE(MAX(p.avg_price), 0.03) AS monthly_change_usdFROM raw_stakes rLEFT JOIN monthly_prices p ON r.month_bucket = p.month_bucketGROUP BY 1, 2),-- Monthly Calendar: starts April 2025 (MFD contract deployment on Base)