Updated 2024-10-14
    with pricet as (
    SELECT
    TO_TIMESTAMP(value[0]::string) as pdate,
    value[1] as price
    from (
    SELECT livequery.live.udf_api(
    'https://api.coingecko.com/api/v3/coins/aptos/market_chart?vs_currency=usd&days=90&interval=daily&precision=3') as resp
    )
    ,LATERAL FLATTEN (input => resp:data:prices)),

    newt as (
    select
    date_trunc('day', min_date) as fdate,
    count(distinct new_user) as new_users
    from(
    select
    distinct sender as new_user,
    min(block_timestamp::date) as min_date
    from aptos.core.fact_transactions
    where
    --tx_type = 'user_transaction'
    --and
    success = 'true'
    group by 1
    )
    group by 1
    order by 1 asc
    ),

    txt AS (
    SELECT
    date_trunc('day', block_timestamp) AS date,
    count(distinct TX_HASH) AS txs,
    count(distinct sender) AS users,
    sum((gas_used * gas_unit_price) / pow(10, 8)) AS fee_apt,
    sum((gas_used * gas_unit_price * price) / pow(10, 8)) AS fee_usd,