MLDZMNOrca2
    Updated 2023-01-13
    with price_t as (select
    RECORDED_HOUR::date as day,
    TOKEN_ADDRESS,
    avg(CLOSE) as token_price
    from solana.core.ez_token_prices_hourly
    group by 1,2
    ),

    orca_pools as (select
    distinct address,
    ADDRESS_NAME
    from solana.core.dim_labels
    where LABEL_TYPE='dex' and LABEL_SUBTYPE='pool' and LABEL='orca'
    )

    select
    date_trunc('week',s.block_timestamp) as date,
    count(distinct s.tx_id) as no_txn,
    count(distinct TX_FROM) as no_users,
    sum(AMOUNT*token_price) as usd_volume,
    avg(AMOUNT*token_price) as avg_volume,
    median(AMOUNT*token_price) as median_volume,
    sum(no_txn) over (order by date) as cum_actions,
    sum(no_users) over (order by date) as cum_users,
    sum(usd_volume) over (order by date) as cum_volume
    from solana.core.fact_transfers s left join price_t a on s.mint=a.TOKEN_ADDRESS and s.BLOCK_TIMESTAMP::date=a.day
    left join solana.core.fact_events b on s.tx_id=b.tx_id
    where PROGRAM_ID='whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'
    and TX_TO in (select address from orca_pools)
    group by 1
    order by 1
    Run a query to Download Data