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};
/// Open a bundled position in a Whirlpool. No new tokens are issued
/// because the owner of the position bundle becomes the owner of the position.
/// The position will start off with 0 liquidity.
/// ### 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 open.
/// - `tick_lower_index` - The tick specifying the lower end of the position
///   range.
/// - `tick_upper_index` - The tick specifying the upper end of the position
///   range.
///
/// #### Special Errors
/// - `InvalidBundleIndex` - If the provided bundle index is out of bounds.
/// - `InvalidTickIndex` - If a provided tick is out of bounds, out of order or
///   not a multiple of
///
/// the tick-spacing in this pool.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct OpenBundledPosition {
    pub bundle_index: u16,
    pub tick_lower_index: i32,
    pub tick_upper_index: i32,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OpenBundledPositionInstructionAccounts {
    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 whirlpool: solana_pubkey::Pubkey,
    pub funder: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub rent: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl OpenBundledPosition {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [169, 113, 126, 171, 213, 172, 212, 49] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for OpenBundledPosition {
    type ArrangedAccounts = OpenBundledPositionInstructionAccounts;

    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 whirlpool = next_account(&mut iter)?;
        let funder = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let rent = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(OpenBundledPositionInstructionAccounts {
            bundled_position,
            position_bundle,
            position_bundle_token_account,
            position_bundle_authority,
            whirlpool,
            funder,
            system_program,
            rent,
            remaining: remaining.to_vec(),
        })
    }
}