carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{IncreaseLiquidityMethod, RemainingAccountsInfo},
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Add liquidity to a position by specifying token maxima, not liquidity.
/// This instruction works with both Token and Token-2022.
/// NOTE: This instruction is only implemented in Pinocchio, not Anchor.
/// ### Authority
/// - `position_authority` - authority that owns the token corresponding to this
///   desired position.
///
/// ### Parameters
/// - `token_max_a` - The maximum amount of tokenA the user is willing to
///   deposit.
/// - `token_max_b` - The maximum amount of tokenB the user is willing to
///   deposit.
/// - `min_sqrt_price` - The minimum sqrt price allowed.
/// - `max_sqrt_price` - The maximum sqrt price allowed.
///
/// #### Special Errors
/// - `LiquidityZero` - Computed liquidity amount is zero.
/// - `LiquidityTooHigh` - Computed liquidity exceeds u128::max.
/// - `TokenMaxExceeded` - The required token to perform this operation exceeds
///   the user defined amount.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct IncreaseLiquidityByTokenAmountsV2 {
    pub method: IncreaseLiquidityMethod,
    pub remaining_accounts_info: Option<RemainingAccountsInfo>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IncreaseLiquidityByTokenAmountsV2InstructionAccounts {
    pub whirlpool: solana_pubkey::Pubkey,
    pub token_program_a: solana_pubkey::Pubkey,
    pub token_program_b: solana_pubkey::Pubkey,
    pub memo_program: solana_pubkey::Pubkey,
    pub position_authority: solana_pubkey::Pubkey,
    pub position: solana_pubkey::Pubkey,
    pub position_token_account: solana_pubkey::Pubkey,
    pub token_mint_a: solana_pubkey::Pubkey,
    pub token_mint_b: solana_pubkey::Pubkey,
    pub token_owner_account_a: solana_pubkey::Pubkey,
    pub token_owner_account_b: solana_pubkey::Pubkey,
    pub token_vault_a: solana_pubkey::Pubkey,
    pub token_vault_b: solana_pubkey::Pubkey,
    pub tick_array_lower: solana_pubkey::Pubkey,
    pub tick_array_upper: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl IncreaseLiquidityByTokenAmountsV2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [239, 251, 9, 124, 210, 198, 53, 43] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for IncreaseLiquidityByTokenAmountsV2 {
    type ArrangedAccounts = IncreaseLiquidityByTokenAmountsV2InstructionAccounts;

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

        let whirlpool = next_account(&mut iter)?;
        let token_program_a = next_account(&mut iter)?;
        let token_program_b = next_account(&mut iter)?;
        let memo_program = next_account(&mut iter)?;
        let position_authority = next_account(&mut iter)?;
        let position = next_account(&mut iter)?;
        let position_token_account = next_account(&mut iter)?;
        let token_mint_a = next_account(&mut iter)?;
        let token_mint_b = next_account(&mut iter)?;
        let token_owner_account_a = next_account(&mut iter)?;
        let token_owner_account_b = next_account(&mut iter)?;
        let token_vault_a = next_account(&mut iter)?;
        let token_vault_b = next_account(&mut iter)?;
        let tick_array_lower = next_account(&mut iter)?;
        let tick_array_upper = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(IncreaseLiquidityByTokenAmountsV2InstructionAccounts {
            whirlpool,
            token_program_a,
            token_program_b,
            memo_program,
            position_authority,
            position,
            position_token_account,
            token_mint_a,
            token_mint_b,
            token_owner_account_a,
            token_owner_account_b,
            token_vault_a,
            token_vault_b,
            tick_array_lower,
            tick_array_upper,
            remaining: remaining.to_vec(),
        })
    }
}