Query editor
WITH delegate_actions AS (-- Get all the stake accounts that have actually triggered a delegate event; it's one of two ways a stake account can delegate to a validator-- By default, this action takes effect in the next epoch.-- Special case is when there is over 25% of the network's stake delegating and undelegating (deactivating) in the same epoch-- In this case, it's "first come, first serve"; the first 25% delegates and undelegates in the next epoch while the portion of stake above does theirs in the epoch after and so onSELECTaccount_stakeAccount AS stake_account,account_voteAccount AS validator_vote_account,call_block_slot AS slot_number,call_tx_id AS tx_idFROM stake_program_solana.stake_call_DelegateStakeWHERE account_voteAccount = 'GE6atKoWiQ2pt3zL7N13pjNHjdLVys8LinG8qeJLcAiL' -- remove condition for generalizationAND call_block_slot <= 240623999),deactivate_actions AS (-- This is the action that undelegates a delegated stake account from a validator-- Same rules for delegations govern deactivations (eg. next epoch effect unless 25% rule kicks in)SELECTaccount_delegatedStakeAccount AS stake_account,call_block_slot AS slot_number,call_tx_id AS tx_idFROM stake_program_solana.stake_call_DeactivateWHERE call_block_slot <= 240623999AND account_delegatedStakeAccount IN (SELECT stake_account FROM delegate_actions) -- remove condition for generalizationUNION ALLSELECTaccount_delegatedStakeAccount AS stake_account,call_block_slot AS slot_number,call_tx_id AS tx_idFROM stake_program_solana.stake_call_DeactivateDelinquentWHERE call_block_slot <= 240623999AND account_delegatedStakeAccount IN (SELECT stake_account FROM delegate_actions) -- remove condition for generalization),latest_delegation_all AS (-- This CTE is to help us filter for a specific validator. We'll most likely remove this in prod.-- We'll get the latest slot a stake account did a delegation event in order to get which vote account they are delegated to if ever they are currently delegated-- This helps also us identify the delegation of destination split accounts as the resulting stake account from a split inherits the state of the source.-- If we know the delegation of the source, we'll know the delegation of the destination.SELECTaccount_stakeAccount AS stake_account,MAX(call_block_slot) AS latest_delegate_slotFROM stake_program_solana.stake_call_DelegateStakeGROUP BY account_stakeAccount),latest_delegation AS (-- We'll get the latest slot a stake account did a delegation event in order to get which vote account they are delegated to if ever they are currently delegated-- This helps also us identify the delegation of destination split accounts as the resulting stake account from a split inherits the state of the source.-- If we know the delegation of the source, we'll know the delegation of the destination.-- use the latest version of latest delegation: https://dune.com/queries/3357880SELECTstake_account,MAX(slot_number) AS latest_delegate_slotFROM delegate_actionsGROUP BY stake_account),