Updated 2024-09-12
    WITH tvl AS (
    -- Fetch TVL for both chains
    SELECT
    LOWER(chain) AS chain,
    chain_tvl
    FROM external.defillama.fact_protocol_tvl
    WHERE protocol LIKE 'Uniswap V2'
    AND chain IN ('Ethereum', 'Arbitrum')
    AND date = current_date
    ),

    volume AS (
    -- Calculate total trading volume for WBTC-WETH pool on Ethereum and Arbitrum
    SELECT
    'ethereum' AS chain,
    SUM(amount_in_usd + amount_out_usd)/2 AS total_trading_volume
    FROM ethereum.defi.ez_dex_swaps
    WHERE platform = 'uniswap-v2'
    AND pool_name = 'WBTC-WETH'
    UNION ALL

    SELECT
    'arbitrum' AS chain,
    SUM(amount_in_usd + amount_out_usd)/2 AS total_trading_volume
    FROM arbitrum.defi.ez_dex_swaps
    WHERE platform = 'uniswap-v2'
    AND pool_name = 'WBTC-WETH'
    ),

    users AS (
    -- Calculate distinct users interacting with the WBTC-WETH pool on Ethereum and Arbitrum
    SELECT
    'ethereum' AS chain,
    COUNT(DISTINCT sender) AS users
    FROM ethereum.defi.ez_dex_swaps
    QueryRunArchived: QueryRun has been archived