carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::OrderTrigger,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// (user) Create a new Order.
/// * bank_keys - Currently only two keys: the lending position and borrowing
///   position in the
///
/// users's Balances for which the order is being placed
/// * trigger - the type of order (stop loss, take profit, or both), and the
///   threshold at which
///
/// to trigger the order, in dollars
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct MarginfiAccountPlaceOrder {
    pub bank_keys: Vec<Pubkey>,
    pub trigger: OrderTrigger,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MarginfiAccountPlaceOrderInstructionAccounts {
    pub group: solana_pubkey::Pubkey,
    pub marginfi_account: solana_pubkey::Pubkey,
    pub fee_payer: solana_pubkey::Pubkey,
    pub authority: solana_pubkey::Pubkey,
    pub order: solana_pubkey::Pubkey,
    pub fee_state: solana_pubkey::Pubkey,
    pub global_fee_wallet: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl MarginfiAccountPlaceOrder {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [244, 112, 75, 138, 143, 108, 7, 186] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for MarginfiAccountPlaceOrder {
    type ArrangedAccounts = MarginfiAccountPlaceOrderInstructionAccounts;

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

        let group = next_account(&mut iter)?;
        let marginfi_account = next_account(&mut iter)?;
        let fee_payer = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;
        let order = next_account(&mut iter)?;
        let fee_state = next_account(&mut iter)?;
        let global_fee_wallet = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(MarginfiAccountPlaceOrderInstructionAccounts {
            group,
            marginfi_account,
            fee_payer,
            authority,
            order,
            fee_state,
            global_fee_wallet,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}