banbannardOptimism-Velodrome
    Updated 2022-10-26
    with base as (select
    date_trunc('day', block_timestamp) as day,
    'Velodrome',
    count(distinct(tx_hash)) as count_tx,
    count(distinct(origin_from_address)) as swapper,
    sum(count_tx) over (order by day) as cumulative_count_tx,
    sum(swapper) over (order by day) as cumulative_swapper,
    (select count(distinct(origin_from_address)) from optimism.velodrome.ez_swaps where block_timestamp >= current_date - 30) as unique_swappers
    from optimism.velodrome.ez_swaps
    where day >= current_date - 30
    group by 1),

    base2 as (select *
    from optimism.core.dim_labels
    where project_name ilike '%uniswap%'),

    base3 as (select tx_hash
    from optimism.core.fact_event_logs
    where event_name = 'Swap'
    and origin_to_address in (select address from base2)
    and block_timestamp >= current_date - 30),

    base4 as (select date_trunc('day', block_timestamp) as day,
    'Uniswap',
    count(distinct(tx_hash)) as count_tx,
    count(distinct(origin_from_address)) as swapper,
    sum(count_tx) over (order by day) as cumulative_count_tx,
    sum(swapper) over (order by day) as cumulative_swapper,
    (select count(distinct(origin_from_address)) from optimism.core.fact_event_logs where event_name = 'Transfer' and tx_hash in (select tx_hash from base3) and event_inputs:value > 0) as unique_swappers
    from optimism.core.fact_event_logs
    where
    event_name = 'Transfer'
    and tx_hash in (select tx_hash from base3)
    and event_inputs:value > 0
    group by 1),

    Run a query to Download Data