Query editor
-- What Smart Money is buying: last 7 days of swaps by the Smart Money Leaderboard wallets-- Uses query_8817293 (Smart Money Leaderboard) as the wallet listWITH sm AS (SELECT wallet_address FROM query_8817293),base_tokens AS (SELECT upper(sym) AS sym FROM (VALUES('WETH'),('ETH'),('USDC'),('USDC.e'),('USDT'),('USDT0'),('DAI'),('WBTC'),('cbBTC'),('USDbC'),('FDUSD'),('USDe'),('wstETH'),('stETH'),('weETH'),('cbETH'),('rETH'),('GHO'),('crvUSD'),('FRAX'),('PYUSD'),('USDS'),('sUSDe'),('EURC'),('EURS'),('LUSD'),('tBTC'),('renBTC')) t(sym)),t AS (SELECT d.* FROM dex.trades dJOIN sm ON sm.wallet_address = d.tx_fromWHERE d.block_time > now() - interval '7' dayAND d.blockchain IN ('ethereum','base','arbitrum')AND d.amount_usd BETWEEN 10 AND 5000000),flows AS (SELECT blockchain, token_bought_address AS token, token_bought_symbol AS symbol, tx_from AS wallet,amount_usd AS buy_usd, 0e0 AS sell_usd, block_timeFROM t WHERE upper(token_sold_symbol) IN (SELECT sym FROM base_tokens)AND upper(coalesce(token_bought_symbol,'')) NOT IN (SELECT sym FROM base_tokens)UNION ALLSELECT blockchain, token_sold_address, token_sold_symbol, tx_from,0e0, amount_usd, block_timeFROM t WHERE upper(token_bought_symbol) IN (SELECT sym FROM base_tokens)AND upper(coalesce(token_sold_symbol,'')) NOT IN (SELECT sym FROM base_tokens))SELECTcoalesce(symbol, substr(cast(token AS varchar), 1, 10)) AS symbol,blockchain,count(DISTINCT wallet) FILTER (WHERE buy_usd > 0) AS smart_buyers,count(DISTINCT wallet) FILTER (WHERE sell_usd > 0) AS smart_sellers,sum(buy_usd) - sum(sell_usd) AS net_flow_usd,sum(buy_usd) AS bought_usd,sum(sell_usd) AS sold_usd,max(block_time) AS last_trade,get_href(CASE blockchain WHEN 'ethereum' THEN 'https://dexscreener.com/ethereum/'WHEN 'base' THEN 'https://dexscreener.com/base/'ELSE 'https://dexscreener.com/arbitrum/' END || cast(token AS varchar),'chart') AS dexscreenerFROM flowsGROUP BY symbol, blockchain, tokenHAVING count(DISTINCT wallet) >= 2AND sum(buy_usd) - sum(sell_usd) > 0 -- net accumulation onlyORDER BY net_flow_usd DESCLIMIT 25