intensodefi2023-11-22 08:21 PM
    Updated 2023-11-22
    WITH newUsers AS (
    SELECT
    recipient as wallet_address,
    date_trunc('month', min(block_timestamp)::date)::date AS start_month
    FROM ethereum.uniswapv3.ez_swaps
    GROUP BY wallet_address
    ),

    monthly_activity AS (
    SELECT
    recipient as wallet_address,
    date_trunc('month', block_timestamp::date)::date AS active_month,
    amount0_usd,
    token0_symbol as token
    FROM ethereum.uniswapv3.ez_swaps
    ),

    monthly_user_data AS (
    SELECT
    active_month as month,
    wallet_address,
    COUNT(*) as transaction_count,
    AVG(ABS(amount0_usd)) as avg_volume_usd,
    token
    FROM(
    SELECT
    monthly_activity.active_month,
    monthly_activity.wallet_address,
    monthly_activity.amount0_usd,
    monthly_activity.token,
    CASE
    WHEN newUsers.start_month = monthly_activity.active_month THEN 'New User'
    ELSE 'Existing User'
    END AS user_type
    FROM monthly_activity
    LEFT JOIN newUsers
    Run a query to Download Data