Updated 2025-01-28
    WITH UserActivity AS (
    -- Outgoing transactions (FROM)
    SELECT
    DATE_TRUNC('{{periodicity}}', block_timestamp) AS activity_date,
    from_address AS address,
    'outgoing' AS direction
    FROM kaia.core.fact_transactions
    WHERE from_address NOT IN (
    SELECT address FROM kaia.core.dim_contracts
    )
    UNION ALL
    -- Incoming transactions (TO)
    SELECT
    DATE_TRUNC('{{periodicity}}', block_timestamp) AS activity_date,
    to_address AS address,
    'incoming' AS direction
    FROM kaia.core.fact_transactions
    WHERE to_address NOT IN (
    SELECT address FROM kaia.core.dim_contracts
    )
    ),

    FirstTransactionDates AS (
    SELECT
    address,
    direction,
    MIN(activity_date) AS first_transaction_date
    FROM UserActivity
    GROUP BY address, direction
    )

    SELECT
    UA.activity_date AS date,
    UA.direction,
    Last run: 3 months ago
    DATE
    DIRECTION
    ACTIVE_USERS
    NEW_USERS
    RETURNING_USERS
    1
    2024-01-01 00:00:00.000incoming325051855413951
    2
    2024-01-01 00:00:00.000outgoing844692720367124325
    3
    2024-01-08 00:00:00.000incoming358282055615272
    4
    2024-01-08 00:00:00.000outgoing403408283238120170
    5
    2024-01-15 00:00:00.000incoming429102259720313
    6
    2024-01-15 00:00:00.000outgoing387519264034123485
    7
    2024-01-22 00:00:00.000incoming420292871213317
    8
    2024-01-22 00:00:00.000outgoing305756189781115975
    9
    2024-01-29 00:00:00.000incoming382882328715001
    10
    2024-01-29 00:00:00.000outgoing236549116921119628
    11
    2024-02-05 00:00:00.000incoming423942902113373
    12
    2024-02-05 00:00:00.000outgoing239559118126121433
    13
    2024-02-12 00:00:00.000incoming356982058915109
    14
    2024-02-12 00:00:00.000outgoing319805204480115325
    15
    2024-02-19 00:00:00.000incoming299721309916873
    16
    2024-02-19 00:00:00.000outgoing557212444680112532
    17
    2024-02-26 00:00:00.000incoming317281759614132
    18
    2024-02-26 00:00:00.000outgoing449708327222122486
    19
    2024-03-04 00:00:00.000incoming286941525013444
    20
    2024-03-04 00:00:00.000outgoing563253440057123196
    ...
    114
    7KB
    137s