Skip to main content

carbon_token_program_decoder/instructions/
transfer_checked.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Transfers tokens from one account to another either directly or via a
4/// delegate. If this account is associated with the native mint then equal
5/// amounts of SOL and Tokens will be transferred to the destination account.
6/// This instruction differs from Transfer in that the token mint and
7/// decimals value is checked by the caller. This may be useful when
8/// creating transactions offline or within a hardware wallet.
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
11pub struct TransferChecked {
12    /// The amount of tokens to transfer.
13    pub amount: u64,
14    /// Expected number of base 10 digits to the right of the decimal place.
15    pub decimals: u8,
16}
17
18#[derive(Debug, Clone, PartialEq)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub struct TransferCheckedInstructionAccounts {
21    pub source: solana_pubkey::Pubkey,
22    pub mint: solana_pubkey::Pubkey,
23    pub destination: solana_pubkey::Pubkey,
24    pub authority: solana_pubkey::Pubkey,
25    pub remaining: Vec<solana_instruction::AccountMeta>,
26}
27
28impl TransferChecked {
29    pub fn decode(data: &[u8]) -> Option<Self> {
30        if data.is_empty() {
31            return None;
32        }
33        let discriminator = &data[0..1];
34        if discriminator != [12] {
35            return None;
36        }
37
38        let mut data_slice = data;
39
40        data_slice = &data_slice[1..];
41
42        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
43    }
44}
45
46impl ArrangeAccounts for TransferChecked {
47    type ArrangedAccounts = TransferCheckedInstructionAccounts;
48
49    fn arrange_accounts(
50        accounts: &[solana_instruction::AccountMeta],
51    ) -> Option<Self::ArrangedAccounts> {
52        let mut iter = accounts.iter();
53
54        let source = next_account(&mut iter)?;
55        let mint = next_account(&mut iter)?;
56        let destination = next_account(&mut iter)?;
57        let authority = next_account(&mut iter)?;
58
59        let remaining = iter.as_slice();
60
61        Some(TransferCheckedInstructionAccounts {
62            source,
63            mint,
64            destination,
65            authority,
66            remaining: remaining.to_vec(),
67        })
68    }
69}