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};
/// Reset the position range to a new range.
/// ### Authority
/// - `position_authority` - The authority that owns the position token.
///
/// ### Parameters
/// - `new_tick_lower_index` - The new tick specifying the lower end of the
///   position range.
/// - `new_tick_upper_index` - The new tick specifying the upper end of the
///   position range.
///
/// #### 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.
/// - `ClosePositionNotEmpty` - The provided position account is not empty.
/// - `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 ResetPositionRange {
    pub new_tick_lower_index: i32,
    pub new_tick_upper_index: i32,
}

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

impl ResetPositionRange {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [164, 123, 180, 141, 194, 100, 160, 175] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for ResetPositionRange {
    type ArrangedAccounts = ResetPositionRangeInstructionAccounts;

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

        let funder = next_account(&mut iter)?;
        let position_authority = next_account(&mut iter)?;
        let whirlpool = next_account(&mut iter)?;
        let position = next_account(&mut iter)?;
        let position_token_account = next_account(&mut iter)?;
        let system_program = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ResetPositionRangeInstructionAccounts {
            funder,
            position_authority,
            whirlpool,
            position,
            position_token_account,
            system_program,
            remaining: remaining.to_vec(),
        })
    }
}