AMLBotDEX activity pie
    Updated 2024-06-13
    -- forked from DEX activity @ https://flipsidecrypto.xyz/edit/queries/08e92905-8b01-4f85-9525-cbef0359b303

    with raw_tx as(
    select
    block_timestamp::date day,
    tx_hash,
    token_in,
    amount_in_usd,
    token_out,
    amount_out_usd
    from {{blockchain}}.defi.ez_dex_swaps
    where block_timestamp::date >= current_date - {{days_back}}
    and (
    token_in = lower('{{token_address}}')
    or token_out = lower('{{token_address}}'))
    ),
    sell as (
    select
    day,
    'Sell' type,
    sum(case
    when token_in = lower('{{token_address}}') then amount_in_usd
    end) volume
    from raw_tx
    group by day
    ),
    buy as(
    select
    day,
    'Buy' type,
    sum(case
    when token_out = lower('{{token_address}}') then amount_out_usd
    end) volume
    from raw_tx
    group by day
    )
    QueryRunArchived: QueryRun has been archived