carbon-token-2022-decoder 2.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
    solana_pubkey::Pubkey,
};
/// Initialize the transfer fee on a new mint.
/// Fails if the mint has already been initialized, so must be called before
/// `InitializeMint`. The mint must have exactly enough space allocated for the
/// base mint (82 bytes), plus 83 bytes of padding, 1 byte reserved for the
/// account type, then space required for this extension, plus any others.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct InitializeTransferFeeConfig {
    /// Pubkey that may update the fees.
    pub transfer_fee_config_authority: Option<Pubkey>,
    /// Withdraw instructions must be signed by this key.
    pub withdraw_withheld_authority: Option<Pubkey>,
    /// Amount of transfer collected as fees, expressed as basis points of the
    /// transfer amount.
    pub transfer_fee_basis_points: u16,
    /// Maximum fee assessed on transfers.
    pub maximum_fee: u64,
}

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

impl InitializeTransferFeeConfig {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.len() < 2 {
            return None;
        }
        let discriminator = data[0];
        if discriminator != 26 {
            return None;
        }
        let transfer_fee_discriminator = data[1];
        if transfer_fee_discriminator != 0 {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for InitializeTransferFeeConfig {
    type ArrangedAccounts = InitializeTransferFeeConfigInstructionAccounts;

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

        let mint = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(InitializeTransferFeeConfigInstructionAccounts {
            mint,
            remaining: remaining.to_vec(),
        })
    }
}