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};
/// Sets specific adaptive fee constants for a pool. Only the provided constants
/// will be updated, others remain unchanged. Caller should avoid invoking this
/// instruction when a pool's adaptive fee is high to prevent LP revenue loss
/// ### Authority
/// - `fee_authority` - Set authority in the WhirlpoolsConfig
///
/// ### Parameters
/// All parameters are optional. Only provided values will be updated.
/// - `filter_period` - Period determine high frequency trading time window.
///   (seconds)
/// - `decay_period` - Period determine when the adaptive fee start decrease.
///   (seconds)
/// - `reduction_factor` - Adaptive fee rate decrement rate.
/// - `adaptive_fee_control_factor` - Adaptive fee control factor.
/// - `max_volatility_accumulator` - Max volatility accumulator.
/// - `tick_group_size` - Tick group size to define tick group index.
/// - `major_swap_threshold_ticks` - Major swap threshold ticks to define major
///   swap.
///
/// #### Special Errors
/// - `InvalidAdaptiveFeeConstants` - If the resulting constants are invalid for
///   the pool's tick_spacing.
/// - `AdaptiveFeeConstantsUnchanged` - If the provided adaptive fee constants
///   are unchanged from the existing constants.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetAdaptiveFeeConstants {
    pub filter_period: Option<u16>,
    pub decay_period: Option<u16>,
    pub reduction_factor: Option<u16>,
    pub adaptive_fee_control_factor: Option<u32>,
    pub max_volatility_accumulator: Option<u32>,
    pub tick_group_size: Option<u16>,
    pub major_swap_threshold_ticks: Option<u16>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SetAdaptiveFeeConstantsInstructionAccounts {
    pub whirlpool: solana_pubkey::Pubkey,
    pub whirlpools_config: solana_pubkey::Pubkey,
    pub oracle: solana_pubkey::Pubkey,
    pub fee_authority: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SetAdaptiveFeeConstants {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [133, 158, 212, 189, 237, 12, 73, 39] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SetAdaptiveFeeConstants {
    type ArrangedAccounts = SetAdaptiveFeeConstantsInstructionAccounts;

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

        let whirlpool = next_account(&mut iter)?;
        let whirlpools_config = next_account(&mut iter)?;
        let oracle = next_account(&mut iter)?;
        let fee_authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SetAdaptiveFeeConstantsInstructionAccounts {
            whirlpool,
            whirlpools_config,
            oracle,
            fee_authority,
            remaining: remaining.to_vec(),
        })
    }
}