shadabSEI Fee stats copy
    Updated 2024-05-15
    -- forked from Moe / SEI Fee stats @ https://flipsidecrypto.xyz/Moe/q/zLvsomVakPYB/sei-fee-stats

    with price as (
    SELECT
    TO_TIMESTAMP(value [0] :: string) as date,
    'SEI' as symbol,
    value [1] as price
    from
    (
    SELECT
    livequery.live.udf_api(
    'https://api.coingecko.com/api/v3/coins/sei-network/market_chart?vs_currency=usd&days=90&interval=daily&precision=3'
    ) as resp
    ),
    LATERAL FLATTEN (input => resp:data:prices)
    ),
    mid as (
    select
    *,
    price * (split(fee, 'usei') [0] / pow(10, 6)) as fee_usd
    from
    sei.core.fact_transactions
    left join price
    where
    tx_from is not null
    and block_timestamp :: date = date
    )
    select
    block_timestamp::date as date ,
    count(distinct tx_id) as tx_count,
    sum(fee_usd) as total_fee_us
    from
    mid
    group by 1


    QueryRunArchived: QueryRun has been archived