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, providing expected mint information and fees.
/// This instruction succeeds if the mint has no configured transfer fee
/// and the provided fee is 0. This allows applications to use
/// `TransferCheckedWithFee` with any mint.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct TransferCheckedWithFee {
    /// The amount of tokens to transfer.
    pub amount: u64,
    /// Expected number of base 10 digits to the right of the decimal place.
    pub decimals: u8,
    /// Expected fee assessed on this transfer, calculated off-chain based
    /// on the transfer_fee_basis_points and maximum_fee of the mint. May
    /// be 0 for a mint without a configured transfer fee.
    pub fee: u64,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for TransferCheckedWithFee {
    type ArrangedAccounts = TransferCheckedWithFeeInstructionAccounts;

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

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

        let remaining = iter.as_slice();

        Some(TransferCheckedWithFeeInstructionAccounts {
            source,
            mint,
            destination,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}