carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
/// Transfer all withheld tokens in the mint to an account. Signed by the
/// mint's withdraw withheld tokens authority.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct WithdrawWithheldTokensFromMint {}

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

impl WithdrawWithheldTokensFromMint {
    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 != 2 {
            return None;
        }

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for WithdrawWithheldTokensFromMint {
    type ArrangedAccounts = WithdrawWithheldTokensFromMintInstructionAccounts;

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

        let mint = next_account(&mut iter)?;
        let fee_receiver = next_account(&mut iter)?;
        let withdraw_withheld_authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(WithdrawWithheldTokensFromMintInstructionAccounts {
            mint,
            fee_receiver,
            withdraw_withheld_authority,
            remaining: remaining.to_vec(),
        })
    }
}