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