ArioUser Retention
    Updated 2024-04-09

    -- forked from 0xDataWolf / Time based Cohort Wide @ https://flipsidecrypto.xyz/0xDataWolf/q/jEC6M61jinzx/time-based-cohort-wide
    with base_table as (
    -- this is data prep
    select
    ORIGIN_FROM_ADDRESS as Swapper,
    date_trunc('week', block_timestamp) as date,
    min(date_trunc('week', block_timestamp)) over(partition by Swapper) as earliest_date,
    datediff(
    'week',
    min(date_trunc('week', block_timestamp)) over(partition by Swapper) -- earliest_date
    ,
    date_trunc('week', block_timestamp) -- current date in week
    ) as difference
    from
    base.defi.ez_dex_swaps
    where
    1 = 1
    and block_timestamp >= current_timestamp() - interval '1 year'
    --and block_timestamp::date > '2023-07-31'
    ),
    count_new_users as(
    select
    earliest_date,
    count(distinct Swapper) as new_users
    from
    base_table
    group by
    1
    ),
    count_returning_users as(
    select
    earliest_date,
    difference,
    count(distinct Swapper) as existing_users
    from
    QueryRunArchived: QueryRun has been archived