Skip to main content

carbon_token_program_decoder/instructions/
approve_checked.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Approves a delegate. A delegate is given the authority over tokens on
4/// behalf of the source account's owner.
5/// This instruction differs from Approve in that the token mint and
6/// decimals value is checked by the caller. This may be useful when
7/// creating transactions offline or within a hardware wallet.
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
10pub struct ApproveChecked {
11    /// The amount of tokens the delegate is approved for.
12    pub amount: u64,
13    /// Expected number of base 10 digits to the right of the decimal place.
14    pub decimals: u8,
15}
16
17#[derive(Debug, Clone, PartialEq)]
18#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
19pub struct ApproveCheckedInstructionAccounts {
20    pub source: solana_pubkey::Pubkey,
21    pub mint: solana_pubkey::Pubkey,
22    pub delegate: solana_pubkey::Pubkey,
23    pub owner: solana_pubkey::Pubkey,
24    pub remaining: Vec<solana_instruction::AccountMeta>,
25}
26
27impl ApproveChecked {
28    pub fn decode(data: &[u8]) -> Option<Self> {
29        if data.is_empty() {
30            return None;
31        }
32        let discriminator = &data[0..1];
33        if discriminator != [13] {
34            return None;
35        }
36
37        let mut data_slice = data;
38
39        data_slice = &data_slice[1..];
40
41        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
42    }
43}
44
45impl ArrangeAccounts for ApproveChecked {
46    type ArrangedAccounts = ApproveCheckedInstructionAccounts;
47
48    fn arrange_accounts(
49        accounts: &[solana_instruction::AccountMeta],
50    ) -> Option<Self::ArrangedAccounts> {
51        let mut iter = accounts.iter();
52
53        let source = next_account(&mut iter)?;
54        let mint = next_account(&mut iter)?;
55        let delegate = next_account(&mut iter)?;
56        let owner = next_account(&mut iter)?;
57
58        let remaining = iter.as_slice();
59
60        Some(ApproveCheckedInstructionAccounts {
61            source,
62            mint,
63            delegate,
64            owner,
65            remaining: remaining.to_vec(),
66        })
67    }
68}