SleepyBN stats
    Updated 2023-05-21
    with prep as(
    select date_trunc('day', block_timestamp) day,
    trader,
    tx_id,
    token_in_contract,
    token_in_amount
    from flow.core.ez_swaps
    where day >= current_date - {{days_back}}
    ),
    prices as(
    select
    date_trunc('day', recorded_hour) day,
    id,
    token,
    avg(close) price
    from flow.core.fact_hourly_prices
    where recorded_hour::date >=
    (select min(block_timestamp::date) from flow.core.ez_swaps)
    group by day, id, token
    ),
    swapper_first_activity as(
    select trader,
    min(block_timestamp::date) first_action_day
    from flow.core.ez_swaps
    group by trader
    ),
    daily_new_swappers as(
    select first_action_day day,
    count(trader) new_swappers
    from swapper_first_activity
    group by day
    order by day
    ),
    daily_prep as(
    select
    prep.day,
    Run a query to Download Data