elsina2025-02-25: Avg Age wallet
    Updated 2025-02-26
    WITH base AS (
    SELECT
    block_timestamp,
    origin_from_address,
    tx_hash,
    pool_name,
    CASE
    WHEN amount_in_usd IS NOT NULL AND amount_out_usd IS NOT NULL
    THEN (amount_in_usd + amount_out_usd) / 2
    ELSE COALESCE(amount_in_usd, amount_out_usd)
    END AS amount
    FROM avalanche.defi.ez_dex_swaps
    WHERE
    platform = 'pangolin'
    AND (amount_in_usd IS NOT NULL OR amount_out_usd IS NOT NULL)
    ),

    t1 AS (
    SELECT
    origin_from_address AS user,
    MIN(block_timestamp) AS min_platform_tx
    FROM base
    GROUP BY origin_from_address
    ),

    t2 AS (
    SELECT
    a.user,
    a.min_platform_tx,
    MIN(b.block_timestamp) AS min_tx
    FROM t1 a
    LEFT JOIN avalanche.core.fact_transactions b
    ON a.user = b.from_address
    GROUP BY a.user, a.min_platform_tx
    ),

    Last run: about 2 months ago
    AVG_AGE_WALLETS
    1
    67.237627
    1
    13B
    23s