ArioTrader Joe User Retention
    Updated 2023-10-11
    -- 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('month', block_timestamp) as date,
    min(date_trunc('month', block_timestamp)) over(partition by Swapper) as earliest_date,
    datediff(
    'month',
    min(date_trunc('month', block_timestamp)) over(partition by Swapper) -- earliest_date
    ,
    date_trunc('month', block_timestamp) -- current date in month
    ) as difference
    from
    {{Blokchain}}.defi.ez_dex_swaps
    where
    1 = 1
    and block_timestamp >= current_timestamp() - interval '1 year'
    and platform in ('trader-joe-v1', 'trader-joe-v2')
    ),
    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
    base_table
    Run a query to Download Data