Updated 2024-08-05
    with pricet as (
    select
    hour::date as date,
    avg(price) as price_usd
    from near.price.ez_prices_hourly
    where token_address = 'wrap.near'
    group by 1
    ),

    main as (
    select
    tx_hash,
    block_timestamp,
    signer_id as user,
    amount,
    action,
    amount * price_usd as amount_usd
    from near.gov.fact_staking_actions
    left join pricet on date = block_timestamp::date
    where action = 'staking'
    and block_timestamp >= '2024-01-01'
    )

    select
    count(distinct tx_hash) as transactions,
    count(distinct user) as users,
    sum(amount) as volume_near,
    avg(amount) as average_amount_near,
    sum(amount_usd) as volume_usd,
    avg(amount_usd) as average_amount_usd,
    median(amount_usd) as median_amount_usd,
    transactions / count(distinct block_timestamp::date) as daily_average_transactions,
    users / count(distinct block_timestamp::date) as daily_average_users
    from main
    QueryRunArchived: QueryRun has been archived