carbon-sharky-decoder 2.0.0

Sharky Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{BookLoanTerms, OrderBookType, APY},
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// Updates an order book, must be signed by sharky key
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct UpdateOrderBook {
    pub order_book_type: Option<OrderBookType>,
    pub apy: Option<APY>,
    pub loan_terms: Option<BookLoanTerms>,
    pub fee_permillicentage: Option<u16>,
    pub fee_authority: Option<Pubkey>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateOrderBookInstructionAccounts {
    pub order_book: solana_pubkey::Pubkey,
    pub payer: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl UpdateOrderBook {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [31, 72, 159, 232, 220, 153, 90, 109] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for UpdateOrderBook {
    type ArrangedAccounts = UpdateOrderBookInstructionAccounts;

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

        let order_book = next_account(&mut iter)?;
        let payer = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(UpdateOrderBookInstructionAccounts {
            order_book,
            payer,
            remaining: remaining.to_vec(),
        })
    }
}