Skip to main content

carbon_token_program_decoder/instructions/
mint_to_checked.rs

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