carbon-token-program-decoder 1.0.0

Token Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Burns tokens by removing them from an account. `BurnChecked` does not
/// support accounts associated with the native mint, use `CloseAccount`
/// instead. This instruction differs from Burn in that the decimals value is
/// checked by the caller. This may be useful when creating transactions offline
/// or within a hardware wallet.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct BurnChecked {
    /// The amount of tokens to burn.
    pub amount: u64,
    /// Expected number of base 10 digits to the right of the decimal place.
    pub decimals: u8,
}

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

impl BurnChecked {
    pub fn decode(data: &[u8]) -> Option<Self> {
        if data.is_empty() {
            return None;
        }
        let discriminator = &data[0..1];
        if discriminator != [15] {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for BurnChecked {
    type ArrangedAccounts = BurnCheckedInstructionAccounts;

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

        let account = next_account(&mut iter)?;
        let mint = next_account(&mut iter)?;
        let authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(BurnCheckedInstructionAccounts {
            account,
            mint,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}