Query editor
WITH all_delegation_events AS (SELECTid,evt_tx_hash,delegator,delegate,evt_block_time, /* count(id), */evt_block_number,evt_index,'setDelegate' AS actionFROM snapshot_ethereum.DelegateRegistry_evt_SetDelegateWHERE("id" = 0x67656172626f782e657468000000000000000000000000000000000000000000OR "id" = 0x0000000000000000000000000000000000000000000000000000000000000000)UNIONSELECTid,evt_tx_hash,delegator,delegate,evt_block_time, /* count(id), */evt_block_number,evt_index,'setDelegate' AS actionFROM snapshot_ethereum.DelegateRegistry_evt_ClearDelegateWHERE("id" = 0x67656172626f782e657468000000000000000000000000000000000000000000OR "id" = 0x0000000000000000000000000000000000000000000000000000000000000000)), all_delegations AS (SELECTa1.delegator AS delegator,a2.delegate AS delegateFROM all_delegation_events AS a1LEFT JOIN (SELECTFIRST_VALUE(delegator) OVER (PARTITION BY delegator ORDER BY evt_block_number DESC, evt_index DESC) AS delegator,FIRST_VALUE(delegate) OVER (PARTITION BY delegator ORDER BY evt_block_number DESC, evt_index DESC) AS delegate,FIRST_VALUE(action) OVER (PARTITION BY delegator ORDER BY evt_block_number DESC, evt_index DESC) AS last_actionFROM all_delegation_events) AS a2ON a1.delegator = a2.delegator AND a2.last_action = 'setDelegate'GROUP BYa1.delegator,a2.delegate), gear AS (SELECTwallet,SUM(amount) AS amountFROM (SELECTto AS wallet,value / 1e18 AS amountFROM erc20_ethereum.evt_TransferWHEREcontract_address = 0xba3335588d9403515223f109edc4eb7269a9ab5dUNION ALL