switchboard_solana/oracle_program/accounts/
lease.rs

1use crate::prelude::*;
2
3#[account(zero_copy(unsafe))]
4#[repr(packed)]
5pub struct LeaseAccountData {
6    /// Public key of the token account holding the lease contract funds until rewarded to oracles for successfully processing updates
7    pub escrow: Pubkey, // Needed, maybe derived, key + "update_escrow"?
8    /// Public key of the oracle queue that the lease contract is applicable for.
9    pub queue: Pubkey,
10    /// Public key of the aggregator that the lease contract is applicable for
11    pub aggregator: Pubkey,
12    /// Public key of the Solana token program ID.
13    pub token_program: Pubkey,
14    /// Whether the lease contract is still active.
15    pub is_active: bool,
16    /// Index of an aggregators position on a crank.
17    pub crank_row_count: u32,
18    /// 	Timestamp when the lease contract was created.
19    pub created_at: i64,
20    /// Counter keeping track of the number of updates for the given aggregator.
21    pub update_count: u128,
22    /// Public key of keypair that may withdraw funds from the lease at any time
23    pub withdraw_authority: Pubkey,
24    /// The PDA bump to derive the pubkey.
25    pub bump: u8,
26    // Reserved for future info.
27    pub _ebuf: [u8; 255],
28}
29impl Default for LeaseAccountData {
30    fn default() -> Self {
31        unsafe { std::mem::zeroed() }
32    }
33}
34
35impl LeaseAccountData {
36    pub fn size() -> usize {
37        8 + std::mem::size_of::<LeaseAccountData>()
38    }
39}
40
41impl TryInto<LeaseAccountData> for Option<Vec<u8>> {
42    type Error = SwitchboardError;
43
44    fn try_into(self) -> std::result::Result<LeaseAccountData, Self::Error> {
45        if let Some(data) = self {
46            bytemuck::try_from_bytes(&data)
47                .map(|&x| x)
48                .map_err(|_| SwitchboardError::AccountDeserializationError)
49        } else {
50            Err(SwitchboardError::AccountDeserializationError)
51        }
52    }
53}