Updated 2022-11-03
    WITH contracts as (
    SELECT *
    FROM optimism.core.dim_labels
    WHERE project_name LIKE 'perpetual protocol'
    )
    ,
    m as(
    SELECT
    date_trunc('day', block_timestamp) as day,
    COUNT(DISTINCT tx_hash) as events,
    COUNT(DISTINCT ORIGIN_FROM_ADDRESS) as users,
    sum(events) over(order by day asc) as Cum_events,
    sum(users) over(order by day asc) as Cum_users,
    Avg(users) over(order by day asc) as Avg_users
    FROM optimism.core.fact_event_logs
    WHERE contract_address IN (SELECT address FROM contracts)
    GROUP BY 1
    order by 1 asc
    )
    select sum(events), round((select sum(users)/count(distinct day) from m),0) as Avg_Users from m
    limit 1






    Run a query to Download Data