Query editor
/*DelegateVotesChanged has all voting delegation changes with the evt_tx_hash - of the transaction generating the eventDelegation may change due to Delegation or Transfer function callswith a special case for the ENS airdrop claim which allowed for claiming and delegation in the same txThere might be many delegate_vote_changing events in one transaction hashEvents have to be prioritized to build an action category for each hash (meaning user intended behavior that ended up changing delegation)There might be many of the same or different event types within the same tx (same tx_hash) - mainly happens with transfersIn the case of transfers the origin_address related to the first of such transfer event in the same tx is considered (it may not always be accurate but is useful for the purpose)Where there are more than one kind of event per tx_hash - the event label will come from the highest ranked action includednewBalance and previousBalance are UINT256 - and due to DOUBLE type precision issues, there can be special casestx_hash 0x4f081d11202fabc4dc7a3dfda9715de1238fcb55256eb334c835f1be4c8db448 : new_bal = prev_bal due to decmial precision (variation is 1e-18)It's also a coincidence that this tx also has 2 DelegateVotesChanged events for the same delegate in the same tx*/WITH transfers_first_sender AS ( -- Get the first sender for each tx_hash containing Transfer events (make schema the same as the views built below)SELECTfs.evt_tx_hash as evt_tx_hash, 'transfer' AS action, 3 AS action_rank, tr."from" AS addressFROM erc20_ethereum.evt_Transfer tr RIGHT JOIN (SELECT evt_tx_hash, MIN(evt_index) AS min_evt_index -- min evt_index will contain the first event in the transaction - it is used to fetch the first Transfer in the transactionFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72GROUP BY evt_tx_hash) fs -- first senderON -- Both have to be matchedfs.evt_tx_hash = tr.evt_tx_hashAND fs.min_evt_index = tr.evt_index), all_dvc_actions AS ( -- All user intended actions that are worth considering and can change a delegate's weight (explained above)-- Claim function callsSELECT -- Address executing the claim is considered -- there is only one address claiming for each claim eventevt_tx_hash, 'claim' AS action, 1 AS action_rank, claimant AS addressFROM ethereumnameservice_ethereum.ENSToken_evt_ClaimUNION ALL-- Delegate function callsSELECT -- There is only one possible address that can generate a Delegate event for each tx_hash so that is consideredevt_tx_hash, 'delegation' AS action, 2 AS action_rank, delegator AS addressFROM ethereumnameservice_ethereum.ENSToken_evt_DelegateChangedUNION ALL-- Transfer function calls (having only the first sender for each tx_hash)SELECT * -- first_sender fetched for all transfer events in order to have one responsible address for each transfer eventFROM transfers_first_sender)