Skip to main content

hpsvm_token/
create_native_mint_2022.rs

1use hpsvm::{HPSVM, types::FailedTransactionMetadata};
2use solana_address::Address;
3use solana_keypair::Keypair;
4use solana_signer::Signer;
5use spl_token_2022_interface::instruction::create_native_mint;
6
7/// ### Description
8/// Builder for the [`create_native_mint`] instruction.
9#[derive(Debug)]
10pub struct CreateNativeMint<'a> {
11    svm: &'a mut HPSVM,
12    payer: &'a Keypair,
13    token_program_id: Option<&'a Address>,
14}
15
16impl<'a> CreateNativeMint<'a> {
17    /// Creates a new instance of [`create_native_mint`] instruction.
18    pub fn new(svm: &'a mut HPSVM, payer: &'a Keypair) -> Self {
19        CreateNativeMint { svm, payer, token_program_id: None }
20    }
21
22    /// Sets the token program id for the instruction.
23    pub fn token_program_id(mut self, program_id: &'a Address) -> Self {
24        self.token_program_id = Some(program_id);
25        self
26    }
27
28    /// Sends the transaction.
29    pub fn send(self) -> Result<(), FailedTransactionMetadata> {
30        let token_program_id = self.token_program_id.unwrap_or(&spl_token_2022_interface::ID);
31        let payer_pk = self.payer.pubkey();
32
33        let ix = create_native_mint(token_program_id, &payer_pk)?;
34
35        super::sign_and_send(self.svm, self.payer, &[], ix)
36    }
37}