namanasync2023-05-20 07:47 PM copy
    Updated 2024-08-30
    -- forked from Afonso_Diaz / 2023-05-20 07:47 PM @ https://flipsidecrypto.xyz/Afonso_Diaz/q/rt2r9fQSOBI1/2023-05-20-07-47-pm

    with t as (
    select
    tx_hash,
    block_timestamp,
    'Outflow' as type,
    to_address as user,
    amount_usd
    from ethereum.core.ez_token_transfers
    join ethereum.core.dim_labels
    on address = from_address
    where symbol = 'UNI'
    and label_type = 'dex'

    union all

    select
    tx_hash,
    block_timestamp,
    'Inflow' as type,
    to_address as user,
    amount_usd
    from ethereum.core.ez_token_transfers
    join ethereum.core.dim_labels
    on address = to_address
    where symbol = 'UNI'
    and label_type = 'dex'
    )

    select
    count(distinct tx_hash) as transactions,
    count(distinct iff(type = 'Inflow', tx_hash, null)) as inflow_transactions,
    count(distinct iff(type = 'Outflow', tx_hash, null)) as outflow_transactions,
    inflow_transactions - outflow_transactions as netflow_transactions,
    count(distinct user) as users,
    QueryRunArchived: QueryRun has been archived