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 position in a Whirlpool. A unique token will be minted to represent
/// the position in the users wallet. Additional TokenMetadata extension is
/// initialized to identify the token. Mint and TokenAccount are based on
/// Token-2022. The position will start off with 0 liquidity.
/// ### Parameters
/// - `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.
/// - `with_token_metadata_extension` - If true, the token metadata extension
///   will be initialized.
///
/// #### Special Errors
/// - `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 OpenPositionWithTokenExtensions {
    pub tick_lower_index: i32,
    pub tick_upper_index: i32,
    pub with_token_metadata_extension: bool,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OpenPositionWithTokenExtensionsInstructionAccounts {
    pub funder: solana_pubkey::Pubkey,
    pub owner: solana_pubkey::Pubkey,
    pub position: solana_pubkey::Pubkey,
    pub position_mint: solana_pubkey::Pubkey,
    pub position_token_account: solana_pubkey::Pubkey,
    pub whirlpool: solana_pubkey::Pubkey,
    pub token2022_program: solana_pubkey::Pubkey,
    pub system_program: solana_pubkey::Pubkey,
    pub associated_token_program: solana_pubkey::Pubkey,
    pub metadata_update_auth: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl OpenPositionWithTokenExtensions {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [212, 47, 95, 92, 114, 102, 131, 250] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for OpenPositionWithTokenExtensions {
    type ArrangedAccounts = OpenPositionWithTokenExtensionsInstructionAccounts;

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

        let funder = next_account(&mut iter)?;
        let owner = next_account(&mut iter)?;
        let position = next_account(&mut iter)?;
        let position_mint = next_account(&mut iter)?;
        let position_token_account = next_account(&mut iter)?;
        let whirlpool = next_account(&mut iter)?;
        let token2022_program = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;
        let associated_token_program = next_account(&mut iter)?;
        let metadata_update_auth = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(OpenPositionWithTokenExtensionsInstructionAccounts {
            funder,
            owner,
            position,
            position_mint,
            position_token_account,
            whirlpool,
            token2022_program,
            system_program,
            associated_token_program,
            metadata_update_auth,
            remaining: remaining.to_vec(),
        })
    }
}