Afonso_DiazOvertime
    Updated 2024-10-27
    with

    main as (
    select
    block_timestamp,
    tx_hash,
    to_address as user,
    amount,
    'From Cex' as type
    from ethereum.core.ez_token_transfers
    where contract_address = '0x6c3ea9036406852006290770bedfcaba0e23a0e8'
    and origin_from_address in (select distinct address from ethereum.core.dim_labels where label_type = 'cex')
    and block_timestamp::date between '{{ start_date }}' and '{{ end_date }}'

    union all

    select
    block_timestamp,
    tx_hash,
    origin_from_address as user,
    amount,
    'To Cex' as type
    from ethereum.core.ez_token_transfers
    where contract_address = '0x6c3ea9036406852006290770bedfcaba0e23a0e8'
    and to_address in (select distinct address from ethereum.core.dim_labels where label_type = 'cex')
    and block_timestamp::date between '{{ start_date }}' and '{{ end_date }}'
    )

    select
    date_trunc('{{ period }}', block_timestamp) as date,
    type,
    count(distinct tx_hash) as transactions,
    count(distinct user) as users,
    sum(amount) as volume_usd,
    avg(amount) as average_amount_usd,
    median(amount) as median_amount_usd,
    QueryRunArchived: QueryRun has been archived