carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Forecloses on a taken lone that has met some condition (core)
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ForecloseLoanCore {}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ForecloseLoanCoreInstructionAccounts {
    pub loan: solana_pubkey::Pubkey,
    pub escrow: solana_pubkey::Pubkey,
    pub collateral_mint: solana_pubkey::Pubkey,
    pub collection: Option<solana_pubkey::Pubkey>,
    pub borrower: solana_pubkey::Pubkey,
    pub lender: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: solana_pubkey::Pubkey,
    pub log_wrapper: Option<solana_pubkey::Pubkey>,
    pub mpl_core_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl ForecloseLoanCore {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [207, 35, 84, 147, 119, 14, 195, 133] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for ForecloseLoanCore {
    type ArrangedAccounts = ForecloseLoanCoreInstructionAccounts;

    fn arrange_accounts(
        accounts: &[solana_instruction::AccountMeta],
    ) -> Option<Self::ArrangedAccounts> {
        let mut iter = accounts.iter();

        let loan = next_account(&mut iter)?;
        let escrow = next_account(&mut iter)?;
        let collateral_mint = next_account(&mut iter)?;
        let collection = next_account(&mut iter);
        let borrower = next_account(&mut iter)?;
        let lender = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter)?;
        let log_wrapper = next_account(&mut iter);
        let mpl_core_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ForecloseLoanCoreInstructionAccounts {
            loan,
            escrow,
            collateral_mint,
            collection,
            borrower,
            lender,
            system_program,
            rent,
            log_wrapper,
            mpl_core_program,
            remaining: remaining.to_vec(),
        })
    }
}