i_danWeekly Stats 2 copy
    Updated 2025-02-26
    with new_wallets as (
    SELECT
    MIN(block_timestamp) as create_date
    , origin_from_address
    FROM kaia.defi.ez_dex_swaps
    GROUP BY 2
    ),

    last_week as (
    SELECT
    date_trunc('week', block_timestamp) as week_a
    , SUM(CASE WHEN amount_in_usd IS NULL THEN amount_out_usd ELSE amount_in_usd END) as usd_volume_a
    , COUNT(DISTINCT(tx_hash)) as tx_count_a
    , COUNT(DISTINCT(origin_from_address)) as wallet_count_a
    FROM kaia.defi.ez_dex_swaps
    WHERE block_timestamp < date_trunc('week', current_date)
    GROUP BY 1
    ORDER BY 1 desc
    ),

    previous_week as (
    SELECT
    date_trunc('week', block_timestamp) as week_b
    , SUM(CASE WHEN amount_in_usd IS NULL THEN amount_out_usd ELSE amount_in_usd END) as usd_volume_b
    , COUNT(DISTINCT(tx_hash)) as tx_count_b
    , COUNT(DISTINCT(origin_from_address)) as wallet_count_b
    FROM kaia.defi.ez_dex_swaps
    WHERE block_timestamp < date_trunc('week', current_date)
    GROUP BY 1
    ORDER BY 1 desc
    LIMIT 2
    ),

    table_1 as (
    SELECT *
    FROM last_week
    Last run: about 1 month ago
    WEEK_A
    USD_VOLUME_A
    TX_COUNT_A
    WALLET_COUNT_A
    WEEK_B
    USD_VOLUME_B
    TX_COUNT_B
    WALLET_COUNT_B
    VOLUME_DIFF
    PERCENTAGE_DIFF
    1
    2025-02-17 00:00:00.00010958571.419082097492025-02-10 00:00:00.0009402919.98370292871555651.5116.544345018
    1
    123B
    4s