carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::{RemainingAccountsInfo, RepositionLiquidityMethod},
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// An atomic instruction that repositions liquidity for a position through the
/// following steps:
/// - Withdraws liquidity from the current position range
/// - Resets the position to a new tick range
/// - Adds liquidity to the new position range
/// - Restores fees and rewards
///
/// This instruction works with both Token and Token-2022.
/// ### Authority
/// - `position_authority` - authority that owns the token corresponding to this
///   desired position.
///
/// ### Parameters
/// - `new_tick_lower_index` - The new tick index for the lower end of the
///   position range.
/// - `new_tick_upper_index` - The new tick index for the upper end of the
///   position range.
/// - `new_liquidity_amount` - The total amount of Liquidity the user is willing
///   to deposit.
/// - `existing_range_token_min_a` - The minimum amount of tokenA the user is
///   willing to withdraw from the existing range.
/// - `existing_range_token_min_b` - The minimum amount of tokenB the user is
///   willing to withdraw from the existing range.
/// - `new_range_token_max_a` - The maximum amount of tokenA the user is willing
///   to deposit into the new range.
/// - `new_range_token_max_b` - The maximum amount of tokenB the user is willing
///   to deposit into the new range.
///
/// #### Special Errors
/// - `LiquidityZero` - Provided liquidity amount is zero.
/// - `LiquidityTooHigh` - Provided liquidity exceeds u128::max.
/// - `TokenMaxExceeded` - The required token to perform this operation exceeds
///   the user defined amount.
/// - `TokenMinSubceeded` - The required token to perform this operation
///   subceeds the user defined amount.
/// - `InvalidTickIndex` - If a provided tick is out of bounds, out of order or
///   not a multiple of
///
/// the tick-spacing in this pool.
/// - `SameTickRangeNotAllowed` - The provided tick range is the same as the
///   current tick range.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct RepositionLiquidityV2 {
    pub new_tick_lower_index: i32,
    pub new_tick_upper_index: i32,
    pub method: RepositionLiquidityMethod,
    pub remaining_accounts_info: Option<RemainingAccountsInfo>,
}

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

impl RepositionLiquidityV2 {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [191, 169, 224, 11, 131, 19, 158, 253] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for RepositionLiquidityV2 {
    type ArrangedAccounts = RepositionLiquidityV2InstructionAccounts;

    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 funder = 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 existing_tick_array_lower = next_account(&mut iter)?;
        let existing_tick_array_upper = next_account(&mut iter)?;
        let new_tick_array_lower = next_account(&mut iter)?;
        let new_tick_array_upper = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(RepositionLiquidityV2InstructionAccounts {
            whirlpool,
            token_program_a,
            token_program_b,
            memo_program,
            position_authority,
            funder,
            position,
            position_token_account,
            token_mint_a,
            token_mint_b,
            token_owner_account_a,
            token_owner_account_b,
            token_vault_a,
            token_vault_b,
            existing_tick_array_lower,
            existing_tick_array_upper,
            new_tick_array_lower,
            new_tick_array_upper,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}