cybergenlab[CEX Overview] Network monthly metrics
    Updated 2024-11-16
    -- forked from [Bridge Overview] Network monthly metrics @ https://flipsidecrypto.xyz/studio/queries/47c691a1-fcea-43b2-9d49-3886f4ca4c7c

    -- forked from [DEX Overview] Network monthly metrics @ https://flipsidecrypto.xyz/studio/queries/865c08fc-8d2b-44eb-a384-673341c31d37

    -- forked from [DeFi Overview] Network monthly metrics @ https://flipsidecrypto.xyz/studio/queries/a5962a5c-5b06-4abd-b33a-d721078d736b

    /* Existing sectors in dim_labels
    dex, dapp, operator, games, chadmin, bridge, token, nft, flotsam, cex, defi
    */

    --Get all metrics for Top Ethereum DeFi metrics

    with monthly_users as (
    select
    date_trunc('month', block_timestamp) as time,
    coalesce((label_type), 'other') as category,
    count(distinct from_address) as users,
    from ethereum.core.fact_transactions as transactions
    left join ethereum.core.dim_labels labels on transactions.to_address = labels.address
    where block_timestamp >= dateadd(month, -1, date_trunc('month',current_date()))
    and block_timestamp < date_trunc('month',current_date())
    and category in ('cex')
    and status = 'SUCCESS'
    group by 1,2
    )

    , monthly_new_users as (
    select
    date_trunc('month', block_timestamp) as time,
    label_type as category,
    count(distinct from_address) as new_users,
    from ethereum.core.fact_transactions as transactions
    left join ethereum.core.dim_labels labels on transactions.to_address = labels.address
    where block_timestamp >= dateadd(month, -1, date_trunc('month',current_date()))
    and nonce = 0
    and block_timestamp < date_trunc('month',current_date())
    QueryRunArchived: QueryRun has been archived