Query editor
-- Dune Query: smart_money (DYNAMIC — behavior-based wallet identification)-- Schedule: Daily at 06:00 UTC-- Output: day, token, smart_wallets_buying, total_bought_usd-- Target: dune_smart_money table in ClickHouse---- Approach:-- 1. Identify wallets with >$1M perp volume on GMX (best on-chain coverage) in 90 days-- 2. Supplement with Dune-labeled fund/institutional addresses-- 3. Track what tokens these wallets buy on spot DEXes-- 4. Filter out stablecoins and wrapped ETH/BTC (not interesting signals)---- Limitation: HyperLiquid/dYdX are off-chain — their traders won't appear here.-- The GMX-based identification captures on-chain perp smart money only.WITHsmart_wallets_from_trading AS (SELECTtrader AS walletFROM perpetual.tradesWHERE block_date >= date_add('day', -90, current_date)GROUP BY traderHAVING SUM(volume_usd) > 1000000AND COUNT(*) >= 10),labeled_wallets AS (SELECT DISTINCT address AS walletFROM labels.addressesWHERE category IN ('fund', 'institution', 'smart_money','Fund', 'Institutional')AND blockchain IN ('ethereum', 'arbitrum', 'optimism', 'base')),all_smart_wallets AS (SELECT wallet FROM smart_wallets_from_tradingUNIONSELECT wallet FROM labeled_wallets),spot_buys AS (SELECTDATE_TRUNC('day', t.block_time) AS day,t.token_bought_symbol AS token,t.taker AS wallet,t.amount_usdFROM dex.trades tINNER JOIN all_smart_wallets swON t.taker = sw.walletWHERE t.block_date >= date_add('day', -2, current_date)AND t.amount_usd > 100AND t.token_bought_symbol IS NOT NULLAND t.token_bought_symbol NOT IN ('USDC', 'USDT', 'DAI', 'FRAX', 'LUSD', 'USDD','TUSD', 'BUSD', 'USDP', 'GUSD', 'crvUSD', 'GHO','WETH', 'WBTC', 'wstETH', 'stETH', 'cbETH', 'rETH'))SELECTCAST(day AS DATE) AS day,token,CAST(COUNT(DISTINCT wallet) AS TINYINT) AS smart_wallets_buying,SUM(amount_usd) AS total_bought_usdFROM spot_buys