cypherOp delegates
    Updated 2023-07-01
    WITH op_claims as (select
    date_trunc('day', block_timestamp) as day,
    tx_hash,
    to_address as claimer,
    raw_amount/1e18 as amount
    from optimism.core.fact_token_transfers
    where contract_address = lower('0x4200000000000000000000000000000000000042') --OP token
    and from_address = lower('0xfedfaf1a10335448b7fa0268f56d2b44dbd357de') --claim contract
    ),

    total_claimed as (select
    distinct(claimer) as unique_claimer,
    sum(amount) as total_claimed
    from op_claims
    group by unique_claimer),

    delegations as (select
    block_timestamp,
    tx_hash,
    origin_from_address as delegater,
    event_inputs:newBalance as new_balance,
    event_inputs:previousBalance as old_balance,
    (new_balance - old_balance)/1e18 as delegated_amount
    from optimism.core.fact_event_logs
    where event_name = 'DelegateVotesChanged'
    and block_timestamp > '2022-05-31 23:45:00'
    and delegated_amount >= 0),

    claimer_delegations as (select * from delegations
    where delegater in (select unique_claimer from total_claimed)),

    total_delegations as (select delegater, sum(delegated_amount) as total_delegated
    from claimer_delegations
    group by delegater),


    Run a query to Download Data