carbon_token_2022_decoder/instructions/
transfer.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 delegate.
14/// If this account is associated with the native mint then equal amounts
15/// of SOL and Tokens will be transferred to the destination account.
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
18pub struct Transfer {
19    /// The amount of tokens to transfer.
20    pub amount: u64,
21}
22
23#[derive(Debug, Clone, PartialEq)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub struct TransferInstructionAccounts {
26    pub source: solana_pubkey::Pubkey,
27    pub destination: solana_pubkey::Pubkey,
28    pub authority: solana_pubkey::Pubkey,
29    pub remaining: Vec<solana_instruction::AccountMeta>,
30}
31
32impl Transfer {
33    pub fn decode(data: &[u8]) -> Option<Self> {
34        if data.is_empty() {
35            return None;
36        }
37        let discriminator = &data[0..1];
38        if discriminator != [3] {
39            return None;
40        }
41
42        let data_slice = data;
43
44        let data_slice = &data_slice[1..];
45
46        Self::deserialize(data_slice)
47    }
48}
49
50impl ArrangeAccounts for Transfer {
51    type ArrangedAccounts = TransferInstructionAccounts;
52
53    fn arrange_accounts(
54        accounts: &[solana_instruction::AccountMeta],
55    ) -> Option<Self::ArrangedAccounts> {
56        let mut iter = accounts.iter();
57
58        let source = next_account(&mut iter)?;
59        let destination = next_account(&mut iter)?;
60        let authority = next_account(&mut iter)?;
61
62        let remaining = iter.as_slice();
63
64        Some(TransferInstructionAccounts {
65            source,
66            destination,
67            authority,
68            remaining: remaining.to_vec(),
69        })
70    }
71}