Fug603helius livequery remix copy
    Updated 2024-05-17
    -- forked from theericstone / helius livequery remix @ https://flipsidecrypto.xyz/theericstone/q/0ANbVUh_NMcr/helius-livequery-remix
    -- let's use flipside and helius together
    -- to find their tokens/holdings
    with maddestlad as (
    select
    sales.purchaser,
    sum(sales.sales_amount) as sol_spent
    from
    solana.nft.fact_nft_sales sales
    join solana.core.dim_labels nfts on nfts.address = sales.mint
    where
    sales.block_timestamp > current_date - 30
    and nfts.label = 'mad lads'
    group by
    purchaser
    order by
    sol_spent desc
    ),
    -- now let's pull the address of the most active mad lads trader
    -- we'll get their balances via a call to Helius
    rawbals as (
    SELECT
    livequery.live.udf_api(
    concat(
    'https://api.helius.xyz/v0/addresses/',
    (
    select
    distinct first_value(purchaser) OVER (
    order by
    sol_spent desc
    )
    from
    maddestlad
    ),
    '/balances?api-key=ed2451a6-5f4e-4a9e-baf4-3d0affb608d0'
    )
    QueryRunArchived: QueryRun has been archived