Query editor
-- FOMO: trader PnL, four definitions side by side-- UNVERIFIED: not executed against Dune. Table/column names need a dry run.---- Cohort window = 90d (who counts as a FOMO trader)-- Basis lookback = 365d (so cost basis is not truncated by the cohort window)with quotes as (select mint from (values('So11111111111111111111111111111111111111112'), -- wSOL('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'), -- USDC('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB') -- USDT) as t(mint)),-- 1. Cohort: wallets that moved tokens EITHER WAY with the FOMO address.-- Original query only looked at to_owner, which drops withdrawal-only users.fomo_wallets as (select distinct owner as trader from (select from_owner as owner from tokens_solana.transferswhere to_owner = 'R4rNJHaffSUotNmqSKNEfDcJE8A7zJUkaoM5Jkd7cYX'and block_time >= now() - interval '90' dayunion allselect to_owner as owner from tokens_solana.transferswhere from_owner = 'R4rNJHaffSUotNmqSKNEfDcJE8A7zJUkaoM5Jkd7cYX'and block_time >= now() - interval '90' day)where owner is not nulland owner <> 'R4rNJHaffSUotNmqSKNEfDcJE8A7zJUkaoM5Jkd7cYX'),-- 2. Which tokens count as "FOMO positions": tokens the wallet touched in a-- FOMO-routed tx. Attribution choice -- see notes at bottom.fomo_tx as (select distinct tx_id from tokens_solana.transferswhere (to_owner = 'R4rNJHaffSUotNmqSKNEfDcJE8A7zJUkaoM5Jkd7cYX'or from_owner = 'R4rNJHaffSUotNmqSKNEfDcJE8A7zJUkaoM5Jkd7cYX')and block_time >= now() - interval '90' day),fomo_positions as (select distinct t.trader_id as trader, tok.mint as tokenfrom dex_solana.trades tjoin fomo_tx f on t.tx_id = f.tx_idjoin fomo_wallets w on w.trader = t.trader_idcross join unnest(array[t.token_bought_mint_address, t.token_sold_mint_address]) as tok(mint)where tok.mint not in (select mint from quotes)and t.block_month >= date_trunc('month', now() - interval '90' day)),-- 3. ALL trades by those wallets in those tokens, over the basis lookback.-- This is the fix for the biggest hole: the original joined on tx_id, so a-- buy through FOMO followed by a sell on Jupiter counted the buy and not-- the sell -- guaranteeing a loss.trades as (select t.trader_id as trader, t.block_time, t.tx_id,t.token_bought_mint_address as tb, t.token_sold_mint_address as ts,t.token_bought_amount, t.token_sold_amount, t.amount_usdfrom dex_solana.trades tjoin fomo_positions pon p.trader = t.trader_idand (p.token = t.token_bought_mint_address or p.token = t.token_sold_mint_address)