Hossein2024-07-13 11:16 PM copy
    Updated 2024-07-14
    with optimism as (
    select
    block_timestamp::Date AS date,tx_hash,
    amount_in_usd AS amountUSD,
    origin_from_address as user
    from optimism.defi.ez_dex_swaps
    where amount_in_usd<power(10,6)
    and tx_hash in (select distinct(tx_hash) from optimism.core.ez_decoded_event_logs where origin_to_address in ('0xcb1355ff08ab38bbce60111f1bb2b784be25d7e8','0x1ba16f6bb1ca9d9b32346e9d51966a606ef21c60','0xb555edf5dcf85f42ceef1f3630a52a108e55a654' ,'0xec8b0f7ffe3ae75d7ffab09429e3675bb63503e4'))
    and date>='2023-01-01'
    )

    select
    case when date>='2023-10-17' then 'after fee changes' else 'before fee changes' end as type,
    count(distinct(user)) as "Users",
    count(distinct tx_hash) as "Swaps",
    avg(amountUSD) as "Amount Avg",
    sum(amountUSD) as "Volume",
    date_trunc('{{ time }}', date) as dt,
    sum("Swaps") over (partition by type order by date_trunc('{{ time }}', date)) as "Swaps(cum)",
    sum("Volume") over (partition by type order by date_trunc('{{ time }}', date)) as "Volume(cum)",
    (("Swaps" - lag("Swaps", 1) over (partition by type order by date_trunc('{{ time }}', date)))/lag("Swaps", 1) over (partition by type order by date_trunc('{{ time }}', date))) * 100 as "swap changes(%)",
    (("Volume" - lag("Volume", 1) over (partition by type order by date_trunc('{{ time }}', date)))/lag("Volume", 1) over (partition by type order by date_trunc('{{ time }}', date))) * 100 as "volume changes(%)",
    (("Users" - lag("Users", 1) over (partition by type order by date_trunc('{{ time }}', date)))/lag("Users", 1) over (partition by type order by date_trunc('{{ time }}', date))) * 100 as "user changes(%)"
    from optimism
    group by type,dt



    QueryRunArchived: QueryRun has been archived