kidaCapital Efficiency by Version
    Updated 2022-02-09
    WITH uniswap_pools AS (
    SELECT
    NVL(event_inputs:pair, event_inputs:pool)::string as pool_address,
    IFF(event_inputs:fee IS NOT NULL, 'v3', 'v2') as version,
    NVL(event_inputs:fee / 10000, 0.3) as fee,
    event_inputs:token0::string as token0,
    event_inputs:token1::string as token1
    FROM ethereum.events_emitted
    WHERE
    contract_address IN ('0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f', '0x1f98431c8ad98523631ae4a59f267346ea31f984') --factory addresses
    AND tx_succeeded = TRUE
    AND event_name IN ('PairCreated','PoolCreated')
    ),

    cumulative_fees as (
    SELECT
    date,
    pool_address,
    version,
    fee,
    fee_str,
    SUM(amount_usd) as total_volume,
    SUM(amount_usd * fee / 100) as total_fee -- fees are charged accross every pool
    FROM(
    SELECT
    TRUNC(block_timestamp, 'day') as date,
    a.pool_address,
    a.tx_id,
    version,
    fee,
    fee || '%' as fee_str,
    MAX(amount_usd) as amount_usd
    FROM
    ethereum.dex_swaps a
    JOIN
    uniswap_pools b
    Run a query to Download Data