Query editor
WITH latest_balances AS (SELECT delegate, MAX(evt_block_time) AS max_evt_blockFROM op_optimism.GovernanceToken_evt_DelegateVotesChangedGROUP BY delegate),ranked_balances AS (SELECTROW_NUMBER() OVER (ORDER BY vc.newBalance DESC) AS position, lb.delegate, vc.evt_block_time, CAST(vc.newBalance AS DOUBLE) / POW(10,18) AS op_amount_latest, cast(vc.newBalance as double) / sum(cast(vc.newBalance as double)) over () as percentage_latestFROM latest_balances lbJOIN op_optimism.GovernanceToken_evt_DelegateVotesChanged vcON lb.delegate = vc.delegate AND lb.max_evt_block = vc.evt_block_time),last_change_before_airdrop AS (SELECT delegate, MAX(evt_block_time) AS max_evt_blockFROM op_optimism.GovernanceToken_evt_DelegateVotesChangedWHERE evt_block_time < CAST('2024-02-18' AS TIMESTAMP) -- airdrop started on the 18th of FebruaryGROUP BY delegate),balances_before_airdrop AS (SELECTcba.delegate, vc.evt_block_time, CAST(vc.newBalance AS DOUBLE) / POW(10,18) AS op_amount_prior, cast(vc.newBalance as double) / sum(cast(vc.newBalance as double)) over () as percentage_priorFROM last_change_before_airdrop cbaJOIN op_optimism.GovernanceToken_evt_DelegateVotesChanged vcON cba.delegate = vc.delegate AND cba.max_evt_block = vc.evt_block_time)selectposition, rb.delegate, ens.name, rb.evt_block_time, op_amount_latest, percentage_latest, op_amount_prior, percentage_priorfrom ranked_balances rbjoin balances_before_airdrop bbaon rb.delegate = bba.delegateleft join labels.ens ens -- joining the ens to get the domain names from the userson ens.address = rb.delegateorder by position asc