Skip to main content

carbon_token_program_decoder/instructions/
initialize_mint.rs

1//! This code was AUTOGENERATED using the Codama library.
2use {
3    carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts},
4    solana_pubkey::Pubkey,
5};
6/// Initializes a new mint and optionally deposits all the newly minted
7/// tokens in an account.
8/// The `InitializeMint` instruction requires no signers and MUST be
9/// included within the same Transaction as the system program's
10/// `CreateAccount` instruction that creates the account being initialized.
11/// Otherwise another party can acquire ownership of the uninitialized account.
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
14pub struct InitializeMint {
15    /// Number of decimals in token account amounts.
16    pub decimals: u8,
17    /// Minting authority.
18    pub mint_authority: Pubkey,
19    /// Optional authority that can freeze token accounts.
20    pub freeze_authority: Option<Pubkey>,
21}
22
23#[derive(Debug, Clone, PartialEq)]
24#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
25pub struct InitializeMintInstructionAccounts {
26    pub mint: solana_pubkey::Pubkey,
27    pub rent: solana_pubkey::Pubkey,
28    pub remaining: Vec<solana_instruction::AccountMeta>,
29}
30
31impl InitializeMint {
32    pub fn decode(data: &[u8]) -> Option<Self> {
33        if data.is_empty() {
34            return None;
35        }
36        let discriminator = &data[0..1];
37        if discriminator != [0] {
38            return None;
39        }
40
41        let mut data_slice = data;
42
43        data_slice = &data_slice[1..];
44
45        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
46    }
47}
48
49impl ArrangeAccounts for InitializeMint {
50    type ArrangedAccounts = InitializeMintInstructionAccounts;
51
52    fn arrange_accounts(
53        accounts: &[solana_instruction::AccountMeta],
54    ) -> Option<Self::ArrangedAccounts> {
55        let mut iter = accounts.iter();
56
57        let mint = next_account(&mut iter)?;
58        let rent = next_account(&mut iter)?;
59
60        let remaining = iter.as_slice();
61
62        Some(InitializeMintInstructionAccounts {
63            mint,
64            rent,
65            remaining: remaining.to_vec(),
66        })
67    }
68}