carbon-token-2022-decoder 1.0.0

Carbon Token 2022 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::DecryptableBalance,
    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
};
/// Configures confidential transfers for a token account.
/// The instruction fails if the confidential transfers are already
/// configured, or if the mint was not initialized with confidential
/// transfer support.
/// The instruction fails if the `TokenInstruction::InitializeAccount`
/// instruction has not yet successfully executed for the token account.
/// Upon success, confidential and non-confidential deposits and transfers
/// are enabled. Use the `DisableConfidentialCredits` and
/// `DisableNonConfidentialCredits` instructions to disable.
/// In order for this instruction to be successfully processed, it must be
/// accompanied by the `VerifyPubkeyValidity` instruction of the
/// `zk_elgamal_proof` program in the same transaction or the address of a
/// context state account for the proof must be provided.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ConfigureConfidentialTransferAccount {
    /// The decryptable balance (always 0) once the configure account succeeds.
    pub decryptable_zero_balance: DecryptableBalance,
    /// The maximum number of despots and transfers that an account can receiver
    /// before the `ApplyPendingBalance` is executed
    pub maximum_pending_balance_credit_counter: u64,
    /// Relative location of the `ProofInstruction::ZeroCiphertextProof`
    /// instruction to the `ConfigureAccount` instruction in the
    /// transaction. If the offset is `0`, then use a context state account
    /// for the proof.
    pub proof_instruction_offset: i8,
}

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

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for ConfigureConfidentialTransferAccount {
    type ArrangedAccounts = ConfigureConfidentialTransferAccountInstructionAccounts;

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

        let token = next_account(&mut iter)?;
        let mint = next_account(&mut iter)?;
        let instructions_sysvar_or_context_state = next_account(&mut iter)?;
        let record = next_account(&mut iter);
        let authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ConfigureConfidentialTransferAccountInstructionAccounts {
            token,
            mint,
            instructions_sysvar_or_context_state,
            record,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}