carbon_token_program_decoder/instructions/
transfer_checked.rs1use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
11pub struct TransferChecked {
12 pub amount: u64,
14 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}