m3jiconscious-fuchsia
    Updated 2025-03-21
    -- Step 1: Create a base table with each user's first activity date
    WITH first_activity AS (
    SELECT
    FROM_ADDRESS,
    DATE_TRUNC('week', MIN(BLOCK_TIMESTAMP)) AS cohort_week
    FROM monad.testnet.fact_transactions
    WHERE BLOCK_TIMESTAMP >= '2025-02-19'::timestamp
    GROUP BY FROM_ADDRESS
    ),

    -- Step 2: Get all transactions with cohort information
    transactions_with_cohort AS (
    SELECT
    t.FROM_ADDRESS,
    t.TO_ADDRESS,
    t.BLOCK_TIMESTAMP,
    t.TX_SUCCEEDED,
    t.GAS_USED,
    t.TX_FEE,
    t.INPUT_DATA,
    CASE WHEN t.INPUT_DATA != '0x' THEN TRUE ELSE FALSE END AS is_contract_interaction,
    fa.cohort_week,
    DATEDIFF('week', fa.cohort_week, DATE_TRUNC('week', t.BLOCK_TIMESTAMP)) AS week_number
    FROM monad.testnet.fact_transactions t
    JOIN first_activity fa ON t.FROM_ADDRESS = fa.FROM_ADDRESS
    WHERE t.BLOCK_TIMESTAMP >= '2025-02-19'
    ),

    -- Step 3: Aggregate behavior metrics by cohort and week number
    cohort_metrics AS (
    SELECT
    cohort_week,
    week_number,
    COUNT(DISTINCT FROM_ADDRESS) AS active_users,
    COUNT(*) AS transaction_count,
    SUM(CASE WHEN TX_SUCCEEDED = true THEN 1 ELSE 0 END) AS successful_transactions,
    Last run: about 1 month ago
    COHORT
    Txns Week 0
    Txns Week 1
    Txns Week 2
    Txns Week 3
    Txns Week 4
    Txns Week 5
    Contract % Week 0
    Contract % Week 1
    Contract % Week 2
    Contract % Week 3
    Contract % Week 4
    Contract % Week 5
    Success % Week 0
    Success % Week 1
    Success % Week 2
    Success % Week 3
    Success % Week 4
    Success % Week 5
    1
    2025-02-1720.42564864.30528949.5259182.82598247.74472985.82765991.61132692.15638794.52342594.65044298.44900897.19487196.17791395.67701695.850018
    2
    2025-02-2415.39254220.28695230.27253621.30740293.114191.55793895.54933996.7422996.79083196.37058396.68525894.144505
    3
    2025-03-035.10784116.34169612.14211885.49123192.46139390.6510296.34013595.1069296.169967
    4
    2025-03-103.9521386.58759268.99843478.28836599.14132497.428199
    5
    2025-03-171.42185329.92903999.421768
    5
    741B
    66s