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