Mrftisilky-silver
    Updated 2024-09-29
    -- Step 1: Identify top profitable wallets based on trading activity
    WITH all_pump_wallets AS (
    -- Get wallets that have been active in the last 30 days with at least 10 trades
    SELECT
    swapper AS wallet,
    COUNT(*) AS trade_count
    FROM
    solana.defi.ez_dex_swaps
    WHERE
    block_timestamp::date >= current_date - 30
    GROUP BY
    swapper
    HAVING
    COUNT(*) >= 10
    ),
    -- Step 2: Find all tokens these wallets traded (both historical buys and sells)
    token_trades AS (
    SELECT
    swapper AS wallet,
    swap_from_mint AS token_address,
    SUM(swap_from_amount_usd) AS total_buy_volume_usd,
    0 AS total_sell_volume_usd
    FROM
    solana.defi.ez_dex_swaps
    WHERE
    swap_from_mint != 'So11111111111111111111111111111111111111112' -- Exclude SOL to avoid clutter
    AND swap_to_mint = 'So11111111111111111111111111111111111111112' -- They are selling this token for SOL
    AND swapper IN (SELECT wallet FROM all_pump_wallets)
    GROUP BY
    swapper, swap_from_mint
    UNION ALL
    SELECT
    swapper AS wallet,
    swap_to_mint AS token_address,
    QueryRunArchived: QueryRun has been archived