carbon-token-2022-decoder 2.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},
};
/// Transfer tokens confidentially.
/// In order for this instruction to be successfully processed, it must be
/// accompanied by the following list of `zk_elgamal_proof` program
/// instructions:
/// - `VerifyCiphertextCommitmentEquality`
/// - `VerifyBatchedGroupedCiphertext3HandlesValidity`
/// - `VerifyBatchedRangeProofU128`
///
/// These instructions can be accompanied in the same transaction or can be
/// pre-verified into a context state account, in which case, only their
/// context state account addresses need to be provided.
/// Fails if the associated mint is extended as `NonTransferable`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct ConfidentialTransfer {
    /// The new source decryptable balance if the transfer succeeds.
    pub new_source_decryptable_available_balance: DecryptableBalance,
    /// Relative location of the
    /// `ProofInstruction::VerifyCiphertextCommitmentEquality` instruction
    /// to the `Transfer` instruction in the transaction. If the offset is
    /// `0`, then use a context state account for the proof.
    pub equality_proof_instruction_offset: i8,
    /// Relative location of the
    /// `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity`
    /// instruction to the `Transfer` instruction in the transaction. If the
    /// offset is `0`, then use a context state account for the proof.
    pub ciphertext_validity_proof_instruction_offset: i8,
    /// Relative location of the `ProofInstruction::BatchedRangeProofU128Data`
    /// instruction to the `Transfer` instruction in the transaction. If the
    /// offset is `0`, then use a context state account for the proof.
    pub range_proof_instruction_offset: i8,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConfidentialTransferInstructionAccounts {
    pub source_token: solana_pubkey::Pubkey,
    pub mint: solana_pubkey::Pubkey,
    pub destination_token: solana_pubkey::Pubkey,
    pub instructions_sysvar: Option<solana_pubkey::Pubkey>,
    pub equality_record: Option<solana_pubkey::Pubkey>,
    pub ciphertext_validity_record: Option<solana_pubkey::Pubkey>,
    pub range_record: Option<solana_pubkey::Pubkey>,
    pub authority: solana_pubkey::Pubkey,
    pub remaining: Vec<solana_instruction::AccountMeta>,
}

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

        let mut data_slice = data;

        data_slice = &data_slice[1..];

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

impl ArrangeAccounts for ConfidentialTransfer {
    type ArrangedAccounts = ConfidentialTransferInstructionAccounts;

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

        let source_token = next_account(&mut iter)?;
        let mint = next_account(&mut iter)?;
        let destination_token = next_account(&mut iter)?;
        let instructions_sysvar = next_account(&mut iter);
        let equality_record = next_account(&mut iter);
        let ciphertext_validity_record = next_account(&mut iter);
        let range_record = next_account(&mut iter);
        let authority = next_account(&mut iter)?;

        let remaining = iter.as_slice();

        Some(ConfidentialTransferInstructionAccounts {
            source_token,
            mint,
            destination_token,
            instructions_sysvar,
            equality_record,
            ciphertext_validity_record,
            range_record,
            authority,
            remaining: remaining.to_vec(),
        })
    }
}