carbon_token_2022_decoder/instructions/
transfer_checked_with_fee.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/// Transfer, providing expected mint information and fees.
14///
15/// This instruction succeeds if the mint has no configured transfer fee
16/// and the provided fee is 0. This allows applications to use
17/// `TransferCheckedWithFee` with any mint.
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq)]
20pub struct TransferCheckedWithFee {
21    pub transfer_fee_discriminator: u8,
22    /// The amount of tokens to transfer.
23    pub amount: u64,
24    /// Expected number of base 10 digits to the right of the decimal place.
25    pub decimals: u8,
26    /// Expected fee assessed on this transfer, calculated off-chain based
27    /// on the transfer_fee_basis_points and maximum_fee of the mint. May
28    /// be 0 for a mint without a configured transfer fee.
29    pub fee: u64,
30}
31
32#[derive(Debug, Clone, PartialEq)]
33#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
34pub struct TransferCheckedWithFeeInstructionAccounts {
35    pub source: solana_pubkey::Pubkey,
36    pub mint: solana_pubkey::Pubkey,
37    pub destination: solana_pubkey::Pubkey,
38    pub authority: solana_pubkey::Pubkey,
39    pub remaining: Vec<solana_instruction::AccountMeta>,
40}
41
42impl TransferCheckedWithFee {
43    pub fn decode(data: &[u8]) -> Option<Self> {
44        if data.len() < 2 {
45            return None;
46        }
47        let discriminator = &data[0..1];
48        if discriminator != [26] {
49            return None;
50        }
51        let transfer_fee_discriminator = data[1];
52        if transfer_fee_discriminator != 1 {
53            return None;
54        }
55
56        let data_slice = data;
57
58        let data_slice = &data_slice[1..];
59
60        Self::deserialize(data_slice)
61    }
62}
63
64impl ArrangeAccounts for TransferCheckedWithFee {
65    type ArrangedAccounts = TransferCheckedWithFeeInstructionAccounts;
66
67    fn arrange_accounts(
68        accounts: &[solana_instruction::AccountMeta],
69    ) -> Option<Self::ArrangedAccounts> {
70        let mut iter = accounts.iter();
71
72        let source = next_account(&mut iter)?;
73        let mint = next_account(&mut iter)?;
74        let destination = next_account(&mut iter)?;
75        let authority = next_account(&mut iter)?;
76
77        let remaining = iter.as_slice();
78
79        Some(TransferCheckedWithFeeInstructionAccounts {
80            source,
81            mint,
82            destination,
83            authority,
84            remaining: remaining.to_vec(),
85        })
86    }
87}