nasdfajskljquery for liq pools 2
    Updated 2024-08-06

    ----1. get volumes
    with vols as (
    select
    swap_to_mint
    ,sum(swap_to_amount_usd) as vol
    from solana.defi.ez_dex_swaps
    where 1=1
    and block_timestamp between '2024-07-28' and '2024-08-04'
    and swap_from_mint = 'So11111111111111111111111111111111111111112'
    group by swap_to_mint
    having vol>1000
    --1352 with over $1000 volume, --919 with over $10,000 volume, --474 with over $100,000 volume
    )

    ----2. get tx_ids for first liq pool tx
    ,firsttx as (

    SELECT *
    FROM (
    SELECT mint, tx_id, block_id, ROW_NUMBER() OVER (PARTITION BY mint ORDER BY (SELECT NULL)) AS rn
    from vols a
    join solana.defi.fact_liquidity_pool_actions b --select * from solana.defi.fact_liquidity_pool_actions limit 10
    on a.swap_to_mint = b.mint
    ) subquery
    WHERE rn = 1
    ) -- 1222 rows



    ----3. get pools
    ,pools as (
    SELECT a.tx_id, b.mint, flattened_data.value:name::string, value:pubkey::string AS pubkey
    FROM solana.core.ez_events_decoded a join firsttx b on a.tx_id = b.tx_id,
    LATERAL FLATTEN(input => decoded_accounts) AS flattened_data
    WHERE 1=1
    QueryRunArchived: QueryRun has been archived