brian-terraVertex - Monthly Stats
    Updated 2024-03-11
    -- forked from Vertex - Daily Stats @ https://flipsidecrypto.xyz/edit/queries/c4a68ed6-3525-4c92-983c-b1b3b13619e1

    WITH qMain as (
    SELECT DISTINCT
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    'perp' AS label
    FROM arbitrum.vertex.ez_perp_trades

    UNION ALL

    SELECT DISTINCT
    block_timestamp,
    tx_hash,
    contract_address,
    symbol,
    trader,
    amount_usd,
    fee_amount,
    'spot' AS label
    FROM arbitrum.vertex.ez_spot_trades
    )

    SELECT date_trunc('month', block_timestamp) AS month,
    COUNT(DISTINCT CASE WHEN label = 'spot' THEN trader END) AS distinct_spot_traders,
    COUNT(DISTINCT CASE WHEN label = 'perp' THEN trader END) AS distinct_perp_traders,
    COUNT(DISTINCT trader) AS distinct_total_traders,
    COUNT(DISTINCT CASE WHEN label = 'spot' THEN tx_hash END) AS distinct_spot_txns,
    COUNT(DISTINCT CASE WHEN label = 'perp' THEN tx_hash END) AS distinct_perp_txns,
    COUNT(DISTINCT tx_hash) AS distinct_total_txns,
    SUM(CASE WHEN label = 'spot' THEN amount_usd ELSE 0 END) AS total_amount_spot,
    QueryRunArchived: QueryRun has been archived