Skip to main content

carbon_token_program_decoder/instructions/
transfer.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#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
8pub struct Transfer {
9    /// The amount of tokens to transfer.
10    pub amount: u64,
11}
12
13#[derive(Debug, Clone, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct TransferInstructionAccounts {
16    pub source: solana_pubkey::Pubkey,
17    pub destination: solana_pubkey::Pubkey,
18    pub authority: solana_pubkey::Pubkey,
19    pub remaining: Vec<solana_instruction::AccountMeta>,
20}
21
22impl Transfer {
23    pub fn decode(data: &[u8]) -> Option<Self> {
24        if data.is_empty() {
25            return None;
26        }
27        let discriminator = &data[0..1];
28        if discriminator != [3] {
29            return None;
30        }
31
32        let mut data_slice = data;
33
34        data_slice = &data_slice[1..];
35
36        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
37    }
38}
39
40impl ArrangeAccounts for Transfer {
41    type ArrangedAccounts = TransferInstructionAccounts;
42
43    fn arrange_accounts(
44        accounts: &[solana_instruction::AccountMeta],
45    ) -> Option<Self::ArrangedAccounts> {
46        let mut iter = accounts.iter();
47
48        let source = next_account(&mut iter)?;
49        let destination = next_account(&mut iter)?;
50        let authority = next_account(&mut iter)?;
51
52        let remaining = iter.as_slice();
53
54        Some(TransferInstructionAccounts {
55            source,
56            destination,
57            authority,
58            remaining: remaining.to_vec(),
59        })
60    }
61}