Skip to main content

dlp_api/state/
delegation_record.rs

1use std::mem::size_of;
2
3use bytemuck::{Pod, Zeroable};
4use solana_program::pubkey::Pubkey;
5
6use super::discriminator::{AccountDiscriminator, AccountWithDiscriminator};
7use crate::{
8    impl_to_bytes_with_discriminator_zero_copy,
9    impl_try_from_bytes_with_discriminator_zero_copy,
10};
11
12/// The Delegation Record stores information such as the authority, the owner and the commit frequency.
13/// This is used by the ephemeral validator to update the state of the delegated account.
14#[repr(C)]
15#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
16pub struct DelegationRecord {
17    /// The delegated authority
18    pub authority: Pubkey,
19
20    /// The original owner of the account
21    pub owner: Pubkey,
22
23    /// The slot at which the delegation was created
24    pub delegation_slot: u64,
25
26    /// The lamports at the time of delegation or from the last state finalization, stored as lamports can be received even if the account is delegated
27    pub lamports: u64,
28
29    /// The state update frequency in milliseconds
30    pub commit_frequency_ms: u64,
31}
32
33impl AccountWithDiscriminator for DelegationRecord {
34    fn discriminator() -> AccountDiscriminator {
35        AccountDiscriminator::DelegationRecord
36    }
37}
38
39impl DelegationRecord {
40    pub fn size_with_discriminator() -> usize {
41        8 + size_of::<DelegationRecord>()
42    }
43}
44
45impl_to_bytes_with_discriminator_zero_copy!(DelegationRecord);
46impl_try_from_bytes_with_discriminator_zero_copy!(DelegationRecord);