Query editor
WITH wallets(label,wallet) AS (VALUES('7f78',0x7f786cf396995e93cbbcf6f925d35fabdac093f1),('a2ed',0xa2ed5f97e0c374f11ccd062a22bf7e57ea12e37e),('e957',0xe957a99f5134e7129c30ff87c173b536a38188f2)),per_token AS (SELECT w.label,e.wallet,e.token,MIN(IF(e.event_class='PAID_BUY',e.block_time,NULL)) first_buy,MAX(IF(e.event_class='PAID_BUY',e.block_time,NULL)) last_buy,MIN(IF(e.event_class='CASH_SELL',e.block_time,NULL)) first_sell,MAX(IF(e.event_class='CASH_SELL',e.block_time,NULL)) last_sell,COUNT(DISTINCT IF(e.event_class='PAID_BUY',e.tx_hash,NULL)) buy_txs,COUNT(DISTINCT IF(e.event_class='CASH_SELL',e.tx_hash,NULL)) sell_txs,SUM(IF(e.event_class='PAID_BUY',e.buy_cost_usd,0e0)) buy_cost_usd,SUM(IF(e.event_class='CASH_SELL',e.proceeds_usd,0e0)) proceeds_usd,SUM(e.assigned_gas_usd) gas_usdFROM wallets w JOIN dune.tusa3112.result_rh_tier34_strict_events eON e.wallet=w.walletWHERE e.token IS NOT NULLGROUP BY 1,2,3),roundtrips AS (SELECT *,DATE_DIFF('second',first_buy,first_sell) first_exit_sec,DATE_DIFF('second',first_buy,last_sell) full_exit_sec,DATE_DIFF('second',first_buy,last_buy) add_window_sec,proceeds_usd-buy_cost_usd-gas_usd net_usd,(proceeds_usd-buy_cost_usd-gas_usd)/NULLIF(buy_cost_usd,0e0) roiFROM per_tokenWHERE first_buy IS NOT NULL)SELECT label,COUNT(*) bought_tokens,COUNT_IF(first_sell IS NOT NULL) exited_tokens,COUNT_IF(sell_txs>1) multi_sell_tokens,COUNT_IF(buy_txs>1) multi_buy_tokens,APPROX_PERCENTILE(buy_cost_usd,0.1) buy_cost_p10,APPROX_PERCENTILE(buy_cost_usd,0.5) buy_cost_p50,APPROX_PERCENTILE(buy_cost_usd,0.9) buy_cost_p90,APPROX_PERCENTILE(first_exit_sec,0.1) first_exit_sec_p10,APPROX_PERCENTILE(first_exit_sec,0.5) first_exit_sec_p50,APPROX_PERCENTILE(first_exit_sec,0.9) first_exit_sec_p90,APPROX_PERCENTILE(full_exit_sec,0.1) full_exit_sec_p10,APPROX_PERCENTILE(full_exit_sec,0.5) full_exit_sec_p50,APPROX_PERCENTILE(full_exit_sec,0.9) full_exit_sec_p90,APPROX_PERCENTILE(add_window_sec,0.5) add_window_sec_p50,APPROX_PERCENTILE(roi,0.1) roi_p10,APPROX_PERCENTILE(roi,0.5) roi_p50,APPROX_PERCENTILE(roi,0.9) roi_p90,COUNT_IF(roi>0e0) profitable_tokens,COUNT_IF(roi>=0.2) roi_ge_20pct,COUNT_IF(roi<=-0.2) roi_le_minus20pct,CORR(CAST(first_exit_sec AS DOUBLE),roi) corr_first_exit_roi,CORR(CAST(full_exit_sec AS DOUBLE),roi) corr_full_exit_roi,SUM(net_usd) total_net_usd,MAX_BY(CONCAT('0x',TO_HEX(token)),net_usd) top_token,MAX(net_usd) top_token_net_usd,MAX(net_usd)/NULLIF(SUM(net_usd),0e0) top_token_share