sigil_client/generated/instructions/
close_mint.rs

1//! This code was AUTOGENERATED using the kinobi library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun kinobi to update it.
4//!
5//! [https://github.com/metaplex-foundation/kinobi]
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11/// Accounts.
12pub struct CloseMint {
13    /// The mint account PDA derived from the ticker and authority.
14    pub mint: solana_program::pubkey::Pubkey,
15    /// The authority for the mint.
16    pub authority: solana_program::pubkey::Pubkey,
17    /// The account receiving refunded rent SOL.
18    pub recipient: Option<solana_program::pubkey::Pubkey>,
19}
20
21impl CloseMint {
22    pub fn instruction(&self) -> solana_program::instruction::Instruction {
23        self.instruction_with_remaining_accounts(&[])
24    }
25    #[allow(clippy::vec_init_then_push)]
26    pub fn instruction_with_remaining_accounts(
27        &self,
28        remaining_accounts: &[solana_program::instruction::AccountMeta],
29    ) -> solana_program::instruction::Instruction {
30        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
31        accounts.push(solana_program::instruction::AccountMeta::new(
32            self.mint, false,
33        ));
34        accounts.push(solana_program::instruction::AccountMeta::new(
35            self.authority,
36            true,
37        ));
38        if let Some(recipient) = self.recipient {
39            accounts.push(solana_program::instruction::AccountMeta::new(
40                recipient, true,
41            ));
42        } else {
43            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
44                crate::SIGIL_ID,
45                false,
46            ));
47        }
48        accounts.extend_from_slice(remaining_accounts);
49        let data = CloseMintInstructionData::new().try_to_vec().unwrap();
50
51        solana_program::instruction::Instruction {
52            program_id: crate::SIGIL_ID,
53            accounts,
54            data,
55        }
56    }
57}
58
59#[derive(BorshDeserialize, BorshSerialize)]
60pub struct CloseMintInstructionData {
61    discriminator: u8,
62}
63
64impl CloseMintInstructionData {
65    pub fn new() -> Self {
66        Self { discriminator: 2 }
67    }
68}
69
70/// Instruction builder for `CloseMint`.
71///
72/// ### Accounts:
73///
74///   0. `[writable]` mint
75///   1. `[writable, signer]` authority
76///   2. `[writable, signer, optional]` recipient
77#[derive(Default)]
78pub struct CloseMintBuilder {
79    mint: Option<solana_program::pubkey::Pubkey>,
80    authority: Option<solana_program::pubkey::Pubkey>,
81    recipient: Option<solana_program::pubkey::Pubkey>,
82    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
83}
84
85impl CloseMintBuilder {
86    pub fn new() -> Self {
87        Self::default()
88    }
89    /// The mint account PDA derived from the ticker and authority.
90    #[inline(always)]
91    pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
92        self.mint = Some(mint);
93        self
94    }
95    /// The authority for the mint.
96    #[inline(always)]
97    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
98        self.authority = Some(authority);
99        self
100    }
101    /// `[optional account]`
102    /// The account receiving refunded rent SOL.
103    #[inline(always)]
104    pub fn recipient(&mut self, recipient: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
105        self.recipient = recipient;
106        self
107    }
108    /// Add an aditional account to the instruction.
109    #[inline(always)]
110    pub fn add_remaining_account(
111        &mut self,
112        account: solana_program::instruction::AccountMeta,
113    ) -> &mut Self {
114        self.__remaining_accounts.push(account);
115        self
116    }
117    /// Add additional accounts to the instruction.
118    #[inline(always)]
119    pub fn add_remaining_accounts(
120        &mut self,
121        accounts: &[solana_program::instruction::AccountMeta],
122    ) -> &mut Self {
123        self.__remaining_accounts.extend_from_slice(accounts);
124        self
125    }
126    #[allow(clippy::clone_on_copy)]
127    pub fn instruction(&self) -> solana_program::instruction::Instruction {
128        let accounts = CloseMint {
129            mint: self.mint.expect("mint is not set"),
130            authority: self.authority.expect("authority is not set"),
131            recipient: self.recipient,
132        };
133
134        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
135    }
136}
137
138/// `close_mint` CPI accounts.
139pub struct CloseMintCpiAccounts<'a, 'b> {
140    /// The mint account PDA derived from the ticker and authority.
141    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
142    /// The authority for the mint.
143    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
144    /// The account receiving refunded rent SOL.
145    pub recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
146}
147
148/// `close_mint` CPI instruction.
149pub struct CloseMintCpi<'a, 'b> {
150    /// The program to invoke.
151    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
152    /// The mint account PDA derived from the ticker and authority.
153    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
154    /// The authority for the mint.
155    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
156    /// The account receiving refunded rent SOL.
157    pub recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
158}
159
160impl<'a, 'b> CloseMintCpi<'a, 'b> {
161    pub fn new(
162        program: &'b solana_program::account_info::AccountInfo<'a>,
163        accounts: CloseMintCpiAccounts<'a, 'b>,
164    ) -> Self {
165        Self {
166            __program: program,
167            mint: accounts.mint,
168            authority: accounts.authority,
169            recipient: accounts.recipient,
170        }
171    }
172    #[inline(always)]
173    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
174        self.invoke_signed_with_remaining_accounts(&[], &[])
175    }
176    #[inline(always)]
177    pub fn invoke_with_remaining_accounts(
178        &self,
179        remaining_accounts: &[(
180            &'b solana_program::account_info::AccountInfo<'a>,
181            bool,
182            bool,
183        )],
184    ) -> solana_program::entrypoint::ProgramResult {
185        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
186    }
187    #[inline(always)]
188    pub fn invoke_signed(
189        &self,
190        signers_seeds: &[&[&[u8]]],
191    ) -> solana_program::entrypoint::ProgramResult {
192        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
193    }
194    #[allow(clippy::clone_on_copy)]
195    #[allow(clippy::vec_init_then_push)]
196    pub fn invoke_signed_with_remaining_accounts(
197        &self,
198        signers_seeds: &[&[&[u8]]],
199        remaining_accounts: &[(
200            &'b solana_program::account_info::AccountInfo<'a>,
201            bool,
202            bool,
203        )],
204    ) -> solana_program::entrypoint::ProgramResult {
205        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
206        accounts.push(solana_program::instruction::AccountMeta::new(
207            *self.mint.key,
208            false,
209        ));
210        accounts.push(solana_program::instruction::AccountMeta::new(
211            *self.authority.key,
212            true,
213        ));
214        if let Some(recipient) = self.recipient {
215            accounts.push(solana_program::instruction::AccountMeta::new(
216                *recipient.key,
217                true,
218            ));
219        } else {
220            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
221                crate::SIGIL_ID,
222                false,
223            ));
224        }
225        remaining_accounts.iter().for_each(|remaining_account| {
226            accounts.push(solana_program::instruction::AccountMeta {
227                pubkey: *remaining_account.0.key,
228                is_signer: remaining_account.1,
229                is_writable: remaining_account.2,
230            })
231        });
232        let data = CloseMintInstructionData::new().try_to_vec().unwrap();
233
234        let instruction = solana_program::instruction::Instruction {
235            program_id: crate::SIGIL_ID,
236            accounts,
237            data,
238        };
239        let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
240        account_infos.push(self.__program.clone());
241        account_infos.push(self.mint.clone());
242        account_infos.push(self.authority.clone());
243        if let Some(recipient) = self.recipient {
244            account_infos.push(recipient.clone());
245        }
246        remaining_accounts
247            .iter()
248            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
249
250        if signers_seeds.is_empty() {
251            solana_program::program::invoke(&instruction, &account_infos)
252        } else {
253            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
254        }
255    }
256}
257
258/// Instruction builder for `CloseMint` via CPI.
259///
260/// ### Accounts:
261///
262///   0. `[writable]` mint
263///   1. `[writable, signer]` authority
264///   2. `[writable, signer, optional]` recipient
265pub struct CloseMintCpiBuilder<'a, 'b> {
266    instruction: Box<CloseMintCpiBuilderInstruction<'a, 'b>>,
267}
268
269impl<'a, 'b> CloseMintCpiBuilder<'a, 'b> {
270    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
271        let instruction = Box::new(CloseMintCpiBuilderInstruction {
272            __program: program,
273            mint: None,
274            authority: None,
275            recipient: None,
276            __remaining_accounts: Vec::new(),
277        });
278        Self { instruction }
279    }
280    /// The mint account PDA derived from the ticker and authority.
281    #[inline(always)]
282    pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
283        self.instruction.mint = Some(mint);
284        self
285    }
286    /// The authority for the mint.
287    #[inline(always)]
288    pub fn authority(
289        &mut self,
290        authority: &'b solana_program::account_info::AccountInfo<'a>,
291    ) -> &mut Self {
292        self.instruction.authority = Some(authority);
293        self
294    }
295    /// `[optional account]`
296    /// The account receiving refunded rent SOL.
297    #[inline(always)]
298    pub fn recipient(
299        &mut self,
300        recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
301    ) -> &mut Self {
302        self.instruction.recipient = recipient;
303        self
304    }
305    /// Add an additional account to the instruction.
306    #[inline(always)]
307    pub fn add_remaining_account(
308        &mut self,
309        account: &'b solana_program::account_info::AccountInfo<'a>,
310        is_writable: bool,
311        is_signer: bool,
312    ) -> &mut Self {
313        self.instruction
314            .__remaining_accounts
315            .push((account, is_writable, is_signer));
316        self
317    }
318    /// Add additional accounts to the instruction.
319    ///
320    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
321    /// and a `bool` indicating whether the account is a signer or not.
322    #[inline(always)]
323    pub fn add_remaining_accounts(
324        &mut self,
325        accounts: &[(
326            &'b solana_program::account_info::AccountInfo<'a>,
327            bool,
328            bool,
329        )],
330    ) -> &mut Self {
331        self.instruction
332            .__remaining_accounts
333            .extend_from_slice(accounts);
334        self
335    }
336    #[inline(always)]
337    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
338        self.invoke_signed(&[])
339    }
340    #[allow(clippy::clone_on_copy)]
341    #[allow(clippy::vec_init_then_push)]
342    pub fn invoke_signed(
343        &self,
344        signers_seeds: &[&[&[u8]]],
345    ) -> solana_program::entrypoint::ProgramResult {
346        let instruction = CloseMintCpi {
347            __program: self.instruction.__program,
348
349            mint: self.instruction.mint.expect("mint is not set"),
350
351            authority: self.instruction.authority.expect("authority is not set"),
352
353            recipient: self.instruction.recipient,
354        };
355        instruction.invoke_signed_with_remaining_accounts(
356            signers_seeds,
357            &self.instruction.__remaining_accounts,
358        )
359    }
360}
361
362struct CloseMintCpiBuilderInstruction<'a, 'b> {
363    __program: &'b solana_program::account_info::AccountInfo<'a>,
364    mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
365    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
366    recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
367    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
368    __remaining_accounts: Vec<(
369        &'b solana_program::account_info::AccountInfo<'a>,
370        bool,
371        bool,
372    )>,
373}