Skip to main content

carbon_token_program_decoder/instructions/
burn_checked.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Burns tokens by removing them from an account. `BurnChecked` does not
4/// support accounts associated with the native mint, use `CloseAccount`
5/// instead. This instruction differs from Burn in that the decimals value is
6/// checked by the caller. This may be useful when creating transactions offline
7/// 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 BurnChecked {
11    /// The amount of tokens to burn.
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 BurnCheckedInstructionAccounts {
20    pub account: solana_pubkey::Pubkey,
21    pub mint: solana_pubkey::Pubkey,
22    pub authority: solana_pubkey::Pubkey,
23    pub remaining: Vec<solana_instruction::AccountMeta>,
24}
25
26impl BurnChecked {
27    pub fn decode(data: &[u8]) -> Option<Self> {
28        if data.is_empty() {
29            return None;
30        }
31        let discriminator = &data[0..1];
32        if discriminator != [15] {
33            return None;
34        }
35
36        let mut data_slice = data;
37
38        data_slice = &data_slice[1..];
39
40        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
41    }
42}
43
44impl ArrangeAccounts for BurnChecked {
45    type ArrangedAccounts = BurnCheckedInstructionAccounts;
46
47    fn arrange_accounts(
48        accounts: &[solana_instruction::AccountMeta],
49    ) -> Option<Self::ArrangedAccounts> {
50        let mut iter = accounts.iter();
51
52        let account = next_account(&mut iter)?;
53        let mint = next_account(&mut iter)?;
54        let authority = next_account(&mut iter)?;
55
56        let remaining = iter.as_slice();
57
58        Some(BurnCheckedInstructionAccounts {
59            account,
60            mint,
61            authority,
62            remaining: remaining.to_vec(),
63        })
64    }
65}