carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Close a bundled position in a Whirlpool.
/// ### Authority
/// - `position_bundle_authority` - authority that owns the token corresponding
///   to this desired position bundle.
///
/// ### Parameters
/// - `bundle_index` - The bundle index that we'd like to close.
///
/// #### Special Errors
/// - `InvalidBundleIndex` - If the provided bundle index is out of bounds.
/// - `ClosePositionNotEmpty` - The provided position account is not empty.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CloseBundledPosition {
    pub bundle_index: u16,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CloseBundledPositionInstructionAccounts {
    pub bundled_position: solana_pubkey::Pubkey,
    pub position_bundle: solana_pubkey::Pubkey,
    pub position_bundle_token_account: solana_pubkey::Pubkey,
    pub position_bundle_authority: solana_pubkey::Pubkey,
    pub receiver: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl CloseBundledPosition {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [41, 36, 216, 245, 27, 85, 103, 67] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for CloseBundledPosition {
    type ArrangedAccounts = CloseBundledPositionInstructionAccounts;

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

        let bundled_position = next_account(&mut iter)?;
        let position_bundle = next_account(&mut iter)?;
        let position_bundle_token_account = next_account(&mut iter)?;
        let position_bundle_authority = next_account(&mut iter)?;
        let receiver = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(CloseBundledPositionInstructionAccounts {
            bundled_position,
            position_bundle,
            position_bundle_token_account,
            position_bundle_authority,
            receiver,
            remaining: remaining.to_vec(),
        })
    }
}