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