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 the fee rate for a Whirlpool.
/// Fee rate is represented as hundredths of a basis point.
/// Only the current fee authority has permission to invoke this instruction.
/// ### Authority
/// - "fee_authority" - Set authority that can modify pool fees in the
///   WhirlpoolConfig
///
/// ### Parameters
/// - `fee_rate` - The rate that the pool will use to calculate fees going
///   onwards.
///
/// #### Special Errors
/// - `FeeRateMaxExceeded` - If the provided fee_rate exceeds MAX_FEE_RATE.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetFeeRate {
    pub fee_rate: u16,
}

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

impl SetFeeRate {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [53, 243, 137, 65, 8, 140, 158, 6] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SetFeeRate {
    type ArrangedAccounts = SetFeeRateInstructionAccounts;

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

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

        let remaining = iter.as_slice();

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