Query editor
WITH members(cluster_label,wallet) AS (VALUES('70ee',0x70ee363d8cf8104cb237187b58480bae3c9463e0),('7f78_a2ed',0x7f786cf396995e93cbbcf6f925d35fabdac093f1),('7f78_a2ed',0xa2ed5f97e0c374f11ccd062a22bf7e57ea12e37e)),events AS (SELECT e.wallet,e.tx_hash,e.block_time,e.day,e.block_number,e.tx_index,e.success,e.target,e.selector,e.token,e.symbol,e.token_in,e.token_out,e.token_rows,e.assigned_gas_usd,e.assigned_net_cash_usd,e.buy_cost_usd,e.proceeds_usd,e.event_classFROM dune.tusa3112.result_rh_tier34_strict_events eJOIN members m ON m.wallet=e.walletWHERE e.block_time<TIMESTAMP '2026-07-12 00:00:00 UTC'UNION ALLSELECT e.wallet,e.tx_hash,e.block_time,e.day,e.block_number,e.tx_index,e.success,e.target,e.selector,e.token,e.symbol,e.token_in,e.token_out,e.token_rows,e.assigned_gas_usd,e.assigned_net_cash_usd,e.buy_cost_usd,e.proceeds_usd,e.event_classFROM dune.tusa3112.result_rh_gmgn_survivors_oos_events eJOIN members m ON m.wallet=e.walletWHERE e.block_time>=TIMESTAMP '2026-07-12 00:00:00 UTC'),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 m.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 members m JOIN tokens.transfers tr ON tr."to"=m.walletLEFT JOIN robinhood.transactions t ON 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"<>m.walletAND COALESCE(tr.tx_from,0x0000000000000000000000000000000000000000)<>m.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 (SELECT *,cum_lot_end-lot_qty cum_lot_start,lot_cost_usd/NULLIF(lot_qty,0e0) unit_cost_usd