carbon_token_2022_decoder/instructions/
transfer_checked.rs

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