Query editor
WITH events AS (SELECT * FROM dune.tusa3112.result_rh_tier34_strict_events),candidates AS (SELECT DISTINCT wallet FROM events),txs AS (SELECT wallet,block_time,day,block_number,tx_index,tx_hash,SUM(assigned_net_cash_usd) net_cash_usd,SUM(assigned_gas_usd) gas_usdFROM events GROUP BY 1,2,3,4,5,6),cash_timeline AS (SELECT *,SUM(net_cash_usd) OVER(PARTITION BY wallet ORDER BY block_number,tx_index,tx_hashROWS UNBOUNDED PRECEDING) cumulative_cash_usdFROM txs),cash_stats AS (SELECT wallet,GREATEST(-MIN(cumulative_cash_usd),0e0) minimum_starting_cash_usd,SUM(net_cash_usd) total_wallet_cash_net_usd,SUM(gas_usd) all_gas_usdFROM cash_timeline GROUP BY 1),self_lots AS (SELECT wallet,token,MAX_BY(symbol,block_time) symbol,block_time,block_number,tx_index,tx_hash,token_in lot_qty,buy_cost_usd lot_cost_usd,IF(buy_cost_usd>0e0,'PAID','UNPAID_SELF') lot_kindFROM eventsWHERE token IS NOT NULL AND token_in>1e-12GROUP BY 1,2,4,5,6,7,8,9,10),external_lots AS (SELECT c.wallet,tr.contract_address token,MAX_BY(tr.symbol,tr.evt_index) symbol,tr.block_time,tr.block_number,COALESCE(t.index,0) tx_index,tr.tx_hash,SUM(COALESCE(tr.amount,0e0)) lot_qty,0e0 lot_cost_usd,'EXTERNAL' lot_kindFROM candidates cJOIN tokens.transfers tr ON tr."to"=c.walletLEFT JOIN robinhood.transactions tON t.block_date=tr.block_date AND t.hash=tr.tx_hashWHERE tr.blockchain='robinhood'AND tr.block_date>=DATE '2026-06-01' AND tr.block_date<CURRENT_DATEAND tr."from"<>c.walletAND COALESCE(tr.tx_from,0x0000000000000000000000000000000000000000)<>c.walletAND LOWER(tr.token_standard)<>'native'AND tr.contract_address NOT IN (0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73,0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168)GROUP BY 1,2,4,5,6,7),all_lots0 AS (SELECT * FROM self_lotsUNION ALLSELECT * FROM external_lots),all_lots1 AS (SELECT *,SUM(lot_qty) OVER(PARTITION BY wallet,token ORDER BY block_number,tx_index,tx_hash,lot_kindROWS UNBOUNDED PRECEDING) cum_lot_endFROM all_lots0),lots AS (