use {
crate::types::{BookLoanTerms, OrderBookType, APY},
solana_pubkey::Pubkey,
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct OrderBook {
pub version: u8,
pub order_book_type: OrderBookType,
pub apy: APY,
pub loan_terms: BookLoanTerms,
pub fee_permillicentage: u16,
pub fee_authority: Pubkey,
}
impl OrderBook {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [55, 230, 125, 218, 149, 39, 65, 248] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}