carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {crate::types::LoanState, solana_pubkey::Pubkey};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Loan {
    pub version: u8,
    /// amount in tokens, decimals included
    pub principal_lamports: u64,
    pub order_book: Pubkey,
    /// Token mint for what the loan is in (spl address)
    pub value_token_mint: Pubkey,
    pub escrow_bump_seed: u8,
    /// stores start and duration
    pub loan_state: LoanState,
}

impl Loan {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [20, 195, 70, 117, 165, 227, 182, 1] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
    }
}