Skip to main content

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