carbon_token_2022_decoder/instructions/
mint_to_checked.rs

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