boomer77$op delegate undelegate
    Updated 2022-09-27
    with del as (select date(block_timestamp) as dt, tx_hash, origin_from_address, event_inputs/1e18:newBalance::int as newBal, event_inputs/1e18:previousBalance::in`t as prevBal, (prevbal-newbal) as delegation
    from optimism.core.fact_event_logs
    where contract_address = '0x4200000000000000000000000000000000000042' and event_name = 'DelegateVotesChanged' and tx_status = 'SUCCESS'),

    delegate as (select date_trunc('day', block_timestamp) as dt, sum(delegation) as op_delegated, count(distinct origin_from_address) as claimer_count,
    count(distinct tx_hash) as tx_count,
    SUM(op_delegated) OVER(ORDER BY dt asc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as total_op_delegated
    from del
    where delegation > 0),

    undelegate as (select date_trunc('day', block_timestamp) as dt, sum(delegation) as op_undelegated, count(distinct origin_from_address) as claimer_count,
    count(distinct tx_hash) as tx_count
    from del
    where delegation < 0)

    select a.dt, a.op_delegated, b.op_undelegated
    from delegate a
    left join undelegate b on a.dt = b.dt
    Run a query to Download Data