adambalaUntitled Query
    Updated 2022-10-09
    with base as (select
    block_timestamp,
    'slingshot' as platform,
    a.tx_hash,
    a.origin_from_address swapper,
    ((c.price * b.raw_amount)/pow(10, c.decimals)) as AMOUNT_IN_USD
    from optimism.core.fact_event_logs a
    join optimism.core.fact_token_transfers b using(tx_hash)
    join optimism.core.fact_hourly_token_prices c on c.token_address = b.contract_address and date_trunc('hour', b.block_timestamp) = c.hour
    where a.event_name = 'Swap'
    and a.origin_to_address in ('0xba12222222228d8ba445958a75a0704d566bf2c8')),

    fin as (
    select
    date_trunc(day,block_timestamp)::date as days,platform,
    sum(AMOUNT_IN_USD) as swap_volume,
    count(distinct swapper) as swapper_count,
    count(distinct tx_hash) as swap_count,
    sum(swap_volume)over( partition by platform order by days rows between unbounded preceding and current row ) as cumulative_swap_volume
    from base
    group by 1,2
    )

    ,price as (
    select
    date_trunc(day,hour)::date as days,
    avg (price) as price
    from
    optimism.core.fact_hourly_token_prices
    where
    symbol ilike 'op'
    group by 1
    )

    select
    Run a query to Download Data