carbon-orca-whirlpool-decoder 1.0.0

Orca Whirlpool Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::TokenBadgeAttribute,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Set an attribute on a TokenBadge account.
/// ### Authority
/// - "token_badge_authority" - Set authority in the WhirlpoolConfigExtension
///
/// ### Parameters
/// - `attribute` - The attribute to set on the TokenBadge account.
///
/// #### Special Errors
/// - `FeatureIsNotEnabled` - If the feature flag for token badges is not
///   enabled.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct SetTokenBadgeAttribute {
    pub attribute: TokenBadgeAttribute,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SetTokenBadgeAttributeInstructionAccounts {
    pub whirlpools_config: solana_pubkey::Pubkey,
    pub whirlpools_config_extension: solana_pubkey::Pubkey,
    pub token_badge_authority: solana_pubkey::Pubkey,
    pub token_mint: solana_pubkey::Pubkey,
    pub token_badge: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

impl SetTokenBadgeAttribute {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 8 {
            return None;
        }
        let discriminator = &data[0..8];
        if discriminator != [224, 88, 65, 33, 138, 147, 246, 137] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[8..];

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

impl ArrangeAccounts for SetTokenBadgeAttribute {
    type ArrangedAccounts = SetTokenBadgeAttributeInstructionAccounts;

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

        let whirlpools_config = next_account(&mut iter)?;
        let whirlpools_config_extension = next_account(&mut iter)?;
        let token_badge_authority = next_account(&mut iter)?;
        let token_mint = next_account(&mut iter)?;
        let token_badge = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(SetTokenBadgeAttributeInstructionAccounts {
            whirlpools_config,
            whirlpools_config_extension,
            token_badge_authority,
            token_mint,
            token_badge,
            remaining: remaining.to_vec(),
        })
    }
}