Updated 2023-12-22
    With Swaps AS (
    SELECT
    date_trunc('day', BLOCK_TIMESTAMP) :: date as day,
    Count(DISTINCT TRADER) AS Number_of_Swappers,
    Count(DISTINCT TX_ID) AS Number_of_Swaps,
    Sum(TO_AMOUNT / 1e6) AS Swap_Volume_to_KAVA,
    Avg(Swap_Volume_to_KAVA) over (
    Order by
    day
    ) as avg_Swap_Volume_to_KAVA
    FROM
    osmosis.defi.fact_swaps
    WHERE
    TO_CURRENCY = 'ibc/57AA1A70A4BC9769C525EBF6386F7A21536E04A79D62E1981EFCEF9428EBB205' --KAVA contract
    AND BLOCK_TIMESTAMP >= '2023-06-01'
    AND TX_SUCCEEDED = TRUE
    GROUP BY
    day
    ORDER BY
    day ASC
    ),
    KAVA_Price AS (
    SELECT
    date_trunc('day', RECORDED_HOUR) :: date as day,
    AVG(PRICE) AS KAVA_Price
    FROM
    osmosis.price.ez_prices
    WHERE
    CURRENCY = 'ibc/57AA1A70A4BC9769C525EBF6386F7A21536E04A79D62E1981EFCEF9428EBB205'
    GROUP BY
    day
    ORDER BY
    day ASC
    )
    SELECT
    S.day AS date,
    QueryRunArchived: QueryRun has been archived