zackmendelTAM - V3
    Updated 2024-09-04
    -- forked from TAM - V2 @ https://flipsidecrypto.xyz/studio/queries/bb6cea4f-d7df-461d-b08b-9d5935c7017f

    WITH tvl AS (
    SELECT
    LOWER(chain) AS chain,
    chain_tvl
    FROM external.defillama.fact_protocol_tvl
    WHERE protocol LIKE 'Uniswap V3'
    AND chain IN ('Ethereum', 'Arbitrum', 'Base')
    AND date = current_date
    ),

    volume AS (
    SELECT
    chain,
    SUM(volume) AS total_volume
    FROM external.defillama.fact_dex_volume
    WHERE protocol LIKE 'uniswap v3'
    AND chain IN ('ethereum', 'arbitrum', 'base')
    -- AND date >= current_date - 30
    GROUP BY 1
    ),

    users AS (
    SELECT
    'ethereum' AS chain,
    COUNT(DISTINCT sender) AS users
    FROM ethereum.defi.ez_dex_swaps
    WHERE platform = 'uniswap-v3'
    -- AND block_timestamp::date >= current_date - 30

    UNION ALL

    SELECT
    'arbitrum' AS chain,
    COUNT(DISTINCT sender) AS users
    QueryRunArchived: QueryRun has been archived