Skip to main content

mpl_token_metadata/generated/instructions/
delegate.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 crate::generated::types::DelegateArgs;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12/// Accounts.
13pub struct Delegate {
14    /// Delegate record account
15    pub delegate_record: Option<solana_program::pubkey::Pubkey>,
16    /// Owner of the delegated account
17    pub delegate: solana_program::pubkey::Pubkey,
18    /// Metadata account
19    pub metadata: solana_program::pubkey::Pubkey,
20    /// Master Edition account
21    pub master_edition: Option<solana_program::pubkey::Pubkey>,
22    /// Token record account
23    pub token_record: Option<solana_program::pubkey::Pubkey>,
24    /// Mint of metadata
25    pub mint: solana_program::pubkey::Pubkey,
26    /// Token account of mint
27    pub token: Option<solana_program::pubkey::Pubkey>,
28    /// Update authority or token owner
29    pub authority: solana_program::pubkey::Pubkey,
30    /// Payer
31    pub payer: solana_program::pubkey::Pubkey,
32    /// System Program
33    pub system_program: solana_program::pubkey::Pubkey,
34    /// Instructions sysvar account
35    pub sysvar_instructions: solana_program::pubkey::Pubkey,
36    /// SPL Token Program
37    pub spl_token_program: Option<solana_program::pubkey::Pubkey>,
38    /// Token Authorization Rules Program
39    pub authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
40    /// Token Authorization Rules account
41    pub authorization_rules: Option<solana_program::pubkey::Pubkey>,
42}
43
44impl Delegate {
45    pub fn instruction(
46        &self,
47        args: DelegateInstructionArgs,
48    ) -> solana_program::instruction::Instruction {
49        self.instruction_with_remaining_accounts(args, &[])
50    }
51    #[allow(clippy::vec_init_then_push)]
52    pub fn instruction_with_remaining_accounts(
53        &self,
54        args: DelegateInstructionArgs,
55        remaining_accounts: &[solana_program::instruction::AccountMeta],
56    ) -> solana_program::instruction::Instruction {
57        let mut accounts = Vec::with_capacity(14 + remaining_accounts.len());
58        if let Some(delegate_record) = self.delegate_record {
59            accounts.push(solana_program::instruction::AccountMeta::new(
60                delegate_record,
61                false,
62            ));
63        } else {
64            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
65                crate::MPL_TOKEN_METADATA_ID,
66                false,
67            ));
68        }
69        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
70            self.delegate,
71            false,
72        ));
73        accounts.push(solana_program::instruction::AccountMeta::new(
74            self.metadata,
75            false,
76        ));
77        if let Some(master_edition) = self.master_edition {
78            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
79                master_edition,
80                false,
81            ));
82        } else {
83            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
84                crate::MPL_TOKEN_METADATA_ID,
85                false,
86            ));
87        }
88        if let Some(token_record) = self.token_record {
89            accounts.push(solana_program::instruction::AccountMeta::new(
90                token_record,
91                false,
92            ));
93        } else {
94            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
95                crate::MPL_TOKEN_METADATA_ID,
96                false,
97            ));
98        }
99        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
100            self.mint, false,
101        ));
102        if let Some(token) = self.token {
103            accounts.push(solana_program::instruction::AccountMeta::new(token, false));
104        } else {
105            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
106                crate::MPL_TOKEN_METADATA_ID,
107                false,
108            ));
109        }
110        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
111            self.authority,
112            true,
113        ));
114        accounts.push(solana_program::instruction::AccountMeta::new(
115            self.payer, true,
116        ));
117        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
118            self.system_program,
119            false,
120        ));
121        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
122            self.sysvar_instructions,
123            false,
124        ));
125        if let Some(spl_token_program) = self.spl_token_program {
126            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
127                spl_token_program,
128                false,
129            ));
130        } else {
131            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
132                crate::MPL_TOKEN_METADATA_ID,
133                false,
134            ));
135        }
136        if let Some(authorization_rules_program) = self.authorization_rules_program {
137            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
138                authorization_rules_program,
139                false,
140            ));
141        } else {
142            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
143                crate::MPL_TOKEN_METADATA_ID,
144                false,
145            ));
146        }
147        if let Some(authorization_rules) = self.authorization_rules {
148            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
149                authorization_rules,
150                false,
151            ));
152        } else {
153            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
154                crate::MPL_TOKEN_METADATA_ID,
155                false,
156            ));
157        }
158        accounts.extend_from_slice(remaining_accounts);
159        let mut data = DelegateInstructionData::new().try_to_vec().unwrap();
160        let mut args = args.try_to_vec().unwrap();
161        data.append(&mut args);
162
163        solana_program::instruction::Instruction {
164            program_id: crate::MPL_TOKEN_METADATA_ID,
165            accounts,
166            data,
167        }
168    }
169}
170
171#[derive(BorshDeserialize, BorshSerialize)]
172struct DelegateInstructionData {
173    discriminator: u8,
174}
175
176impl DelegateInstructionData {
177    fn new() -> Self {
178        Self { discriminator: 44 }
179    }
180}
181
182#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
183#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
184pub struct DelegateInstructionArgs {
185    pub delegate_args: DelegateArgs,
186}
187
188/// Instruction builder for `Delegate`.
189///
190/// ### Accounts:
191///
192///   0. `[writable, optional]` delegate_record
193///   1. `[]` delegate
194///   2. `[writable]` metadata
195///   3. `[optional]` master_edition
196///   4. `[writable, optional]` token_record
197///   5. `[]` mint
198///   6. `[writable, optional]` token
199///   7. `[signer]` authority
200///   8. `[writable, signer]` payer
201///   9. `[optional]` system_program (default to `11111111111111111111111111111111`)
202///   10. `[optional]` sysvar_instructions (default to `Sysvar1nstructions1111111111111111111111111`)
203///   11. `[optional]` spl_token_program
204///   12. `[optional]` authorization_rules_program
205///   13. `[optional]` authorization_rules
206#[derive(Default)]
207pub struct DelegateBuilder {
208    delegate_record: Option<solana_program::pubkey::Pubkey>,
209    delegate: Option<solana_program::pubkey::Pubkey>,
210    metadata: Option<solana_program::pubkey::Pubkey>,
211    master_edition: Option<solana_program::pubkey::Pubkey>,
212    token_record: Option<solana_program::pubkey::Pubkey>,
213    mint: Option<solana_program::pubkey::Pubkey>,
214    token: Option<solana_program::pubkey::Pubkey>,
215    authority: Option<solana_program::pubkey::Pubkey>,
216    payer: Option<solana_program::pubkey::Pubkey>,
217    system_program: Option<solana_program::pubkey::Pubkey>,
218    sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
219    spl_token_program: Option<solana_program::pubkey::Pubkey>,
220    authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
221    authorization_rules: Option<solana_program::pubkey::Pubkey>,
222    delegate_args: Option<DelegateArgs>,
223    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
224}
225
226impl DelegateBuilder {
227    pub fn new() -> Self {
228        Self::default()
229    }
230    /// `[optional account]`
231    /// Delegate record account
232    #[inline(always)]
233    pub fn delegate_record(
234        &mut self,
235        delegate_record: Option<solana_program::pubkey::Pubkey>,
236    ) -> &mut Self {
237        self.delegate_record = delegate_record;
238        self
239    }
240    /// Owner of the delegated account
241    #[inline(always)]
242    pub fn delegate(&mut self, delegate: solana_program::pubkey::Pubkey) -> &mut Self {
243        self.delegate = Some(delegate);
244        self
245    }
246    /// Metadata account
247    #[inline(always)]
248    pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
249        self.metadata = Some(metadata);
250        self
251    }
252    /// `[optional account]`
253    /// Master Edition account
254    #[inline(always)]
255    pub fn master_edition(
256        &mut self,
257        master_edition: Option<solana_program::pubkey::Pubkey>,
258    ) -> &mut Self {
259        self.master_edition = master_edition;
260        self
261    }
262    /// `[optional account]`
263    /// Token record account
264    #[inline(always)]
265    pub fn token_record(
266        &mut self,
267        token_record: Option<solana_program::pubkey::Pubkey>,
268    ) -> &mut Self {
269        self.token_record = token_record;
270        self
271    }
272    /// Mint of metadata
273    #[inline(always)]
274    pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
275        self.mint = Some(mint);
276        self
277    }
278    /// `[optional account]`
279    /// Token account of mint
280    #[inline(always)]
281    pub fn token(&mut self, token: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
282        self.token = token;
283        self
284    }
285    /// Update authority or token owner
286    #[inline(always)]
287    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
288        self.authority = Some(authority);
289        self
290    }
291    /// Payer
292    #[inline(always)]
293    pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
294        self.payer = Some(payer);
295        self
296    }
297    /// `[optional account, default to '11111111111111111111111111111111']`
298    /// System Program
299    #[inline(always)]
300    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
301        self.system_program = Some(system_program);
302        self
303    }
304    /// `[optional account, default to 'Sysvar1nstructions1111111111111111111111111']`
305    /// Instructions sysvar account
306    #[inline(always)]
307    pub fn sysvar_instructions(
308        &mut self,
309        sysvar_instructions: solana_program::pubkey::Pubkey,
310    ) -> &mut Self {
311        self.sysvar_instructions = Some(sysvar_instructions);
312        self
313    }
314    /// `[optional account]`
315    /// SPL Token Program
316    #[inline(always)]
317    pub fn spl_token_program(
318        &mut self,
319        spl_token_program: Option<solana_program::pubkey::Pubkey>,
320    ) -> &mut Self {
321        self.spl_token_program = spl_token_program;
322        self
323    }
324    /// `[optional account]`
325    /// Token Authorization Rules Program
326    #[inline(always)]
327    pub fn authorization_rules_program(
328        &mut self,
329        authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
330    ) -> &mut Self {
331        self.authorization_rules_program = authorization_rules_program;
332        self
333    }
334    /// `[optional account]`
335    /// Token Authorization Rules account
336    #[inline(always)]
337    pub fn authorization_rules(
338        &mut self,
339        authorization_rules: Option<solana_program::pubkey::Pubkey>,
340    ) -> &mut Self {
341        self.authorization_rules = authorization_rules;
342        self
343    }
344    #[inline(always)]
345    pub fn delegate_args(&mut self, delegate_args: DelegateArgs) -> &mut Self {
346        self.delegate_args = Some(delegate_args);
347        self
348    }
349    /// Add an aditional account to the instruction.
350    #[inline(always)]
351    pub fn add_remaining_account(
352        &mut self,
353        account: solana_program::instruction::AccountMeta,
354    ) -> &mut Self {
355        self.__remaining_accounts.push(account);
356        self
357    }
358    /// Add additional accounts to the instruction.
359    #[inline(always)]
360    pub fn add_remaining_accounts(
361        &mut self,
362        accounts: &[solana_program::instruction::AccountMeta],
363    ) -> &mut Self {
364        self.__remaining_accounts.extend_from_slice(accounts);
365        self
366    }
367    #[allow(clippy::clone_on_copy)]
368    pub fn instruction(&self) -> solana_program::instruction::Instruction {
369        let accounts = Delegate {
370            delegate_record: self.delegate_record,
371            delegate: self.delegate.expect("delegate is not set"),
372            metadata: self.metadata.expect("metadata is not set"),
373            master_edition: self.master_edition,
374            token_record: self.token_record,
375            mint: self.mint.expect("mint is not set"),
376            token: self.token,
377            authority: self.authority.expect("authority is not set"),
378            payer: self.payer.expect("payer is not set"),
379            system_program: self
380                .system_program
381                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
382            sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
383                "Sysvar1nstructions1111111111111111111111111"
384            )),
385            spl_token_program: self.spl_token_program,
386            authorization_rules_program: self.authorization_rules_program,
387            authorization_rules: self.authorization_rules,
388        };
389        let args = DelegateInstructionArgs {
390            delegate_args: self
391                .delegate_args
392                .clone()
393                .expect("delegate_args is not set"),
394        };
395
396        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
397    }
398}
399
400/// `delegate` CPI accounts.
401pub struct DelegateCpiAccounts<'a, 'b> {
402    /// Delegate record account
403    pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
404    /// Owner of the delegated account
405    pub delegate: &'b solana_program::account_info::AccountInfo<'a>,
406    /// Metadata account
407    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
408    /// Master Edition account
409    pub master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
410    /// Token record account
411    pub token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
412    /// Mint of metadata
413    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
414    /// Token account of mint
415    pub token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
416    /// Update authority or token owner
417    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
418    /// Payer
419    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
420    /// System Program
421    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
422    /// Instructions sysvar account
423    pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
424    /// SPL Token Program
425    pub spl_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
426    /// Token Authorization Rules Program
427    pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
428    /// Token Authorization Rules account
429    pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
430}
431
432/// `delegate` CPI instruction.
433pub struct DelegateCpi<'a, 'b> {
434    /// The program to invoke.
435    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
436    /// Delegate record account
437    pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
438    /// Owner of the delegated account
439    pub delegate: &'b solana_program::account_info::AccountInfo<'a>,
440    /// Metadata account
441    pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
442    /// Master Edition account
443    pub master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
444    /// Token record account
445    pub token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
446    /// Mint of metadata
447    pub mint: &'b solana_program::account_info::AccountInfo<'a>,
448    /// Token account of mint
449    pub token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
450    /// Update authority or token owner
451    pub authority: &'b solana_program::account_info::AccountInfo<'a>,
452    /// Payer
453    pub payer: &'b solana_program::account_info::AccountInfo<'a>,
454    /// System Program
455    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
456    /// Instructions sysvar account
457    pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
458    /// SPL Token Program
459    pub spl_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
460    /// Token Authorization Rules Program
461    pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
462    /// Token Authorization Rules account
463    pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
464    /// The arguments for the instruction.
465    pub __args: DelegateInstructionArgs,
466}
467
468impl<'a, 'b> DelegateCpi<'a, 'b> {
469    pub fn new(
470        program: &'b solana_program::account_info::AccountInfo<'a>,
471        accounts: DelegateCpiAccounts<'a, 'b>,
472        args: DelegateInstructionArgs,
473    ) -> Self {
474        Self {
475            __program: program,
476            delegate_record: accounts.delegate_record,
477            delegate: accounts.delegate,
478            metadata: accounts.metadata,
479            master_edition: accounts.master_edition,
480            token_record: accounts.token_record,
481            mint: accounts.mint,
482            token: accounts.token,
483            authority: accounts.authority,
484            payer: accounts.payer,
485            system_program: accounts.system_program,
486            sysvar_instructions: accounts.sysvar_instructions,
487            spl_token_program: accounts.spl_token_program,
488            authorization_rules_program: accounts.authorization_rules_program,
489            authorization_rules: accounts.authorization_rules,
490            __args: args,
491        }
492    }
493    #[inline(always)]
494    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
495        self.invoke_signed_with_remaining_accounts(&[], &[])
496    }
497    #[inline(always)]
498    pub fn invoke_with_remaining_accounts(
499        &self,
500        remaining_accounts: &[(
501            &'b solana_program::account_info::AccountInfo<'a>,
502            bool,
503            bool,
504        )],
505    ) -> solana_program::entrypoint::ProgramResult {
506        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
507    }
508    #[inline(always)]
509    pub fn invoke_signed(
510        &self,
511        signers_seeds: &[&[&[u8]]],
512    ) -> solana_program::entrypoint::ProgramResult {
513        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
514    }
515    #[allow(clippy::clone_on_copy)]
516    #[allow(clippy::vec_init_then_push)]
517    pub fn invoke_signed_with_remaining_accounts(
518        &self,
519        signers_seeds: &[&[&[u8]]],
520        remaining_accounts: &[(
521            &'b solana_program::account_info::AccountInfo<'a>,
522            bool,
523            bool,
524        )],
525    ) -> solana_program::entrypoint::ProgramResult {
526        let mut accounts = Vec::with_capacity(14 + remaining_accounts.len());
527        if let Some(delegate_record) = self.delegate_record {
528            accounts.push(solana_program::instruction::AccountMeta::new(
529                *delegate_record.key,
530                false,
531            ));
532        } else {
533            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
534                crate::MPL_TOKEN_METADATA_ID,
535                false,
536            ));
537        }
538        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
539            *self.delegate.key,
540            false,
541        ));
542        accounts.push(solana_program::instruction::AccountMeta::new(
543            *self.metadata.key,
544            false,
545        ));
546        if let Some(master_edition) = self.master_edition {
547            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
548                *master_edition.key,
549                false,
550            ));
551        } else {
552            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
553                crate::MPL_TOKEN_METADATA_ID,
554                false,
555            ));
556        }
557        if let Some(token_record) = self.token_record {
558            accounts.push(solana_program::instruction::AccountMeta::new(
559                *token_record.key,
560                false,
561            ));
562        } else {
563            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
564                crate::MPL_TOKEN_METADATA_ID,
565                false,
566            ));
567        }
568        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
569            *self.mint.key,
570            false,
571        ));
572        if let Some(token) = self.token {
573            accounts.push(solana_program::instruction::AccountMeta::new(
574                *token.key, false,
575            ));
576        } else {
577            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
578                crate::MPL_TOKEN_METADATA_ID,
579                false,
580            ));
581        }
582        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
583            *self.authority.key,
584            true,
585        ));
586        accounts.push(solana_program::instruction::AccountMeta::new(
587            *self.payer.key,
588            true,
589        ));
590        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
591            *self.system_program.key,
592            false,
593        ));
594        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
595            *self.sysvar_instructions.key,
596            false,
597        ));
598        if let Some(spl_token_program) = self.spl_token_program {
599            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
600                *spl_token_program.key,
601                false,
602            ));
603        } else {
604            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
605                crate::MPL_TOKEN_METADATA_ID,
606                false,
607            ));
608        }
609        if let Some(authorization_rules_program) = self.authorization_rules_program {
610            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
611                *authorization_rules_program.key,
612                false,
613            ));
614        } else {
615            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
616                crate::MPL_TOKEN_METADATA_ID,
617                false,
618            ));
619        }
620        if let Some(authorization_rules) = self.authorization_rules {
621            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
622                *authorization_rules.key,
623                false,
624            ));
625        } else {
626            accounts.push(solana_program::instruction::AccountMeta::new_readonly(
627                crate::MPL_TOKEN_METADATA_ID,
628                false,
629            ));
630        }
631        remaining_accounts.iter().for_each(|remaining_account| {
632            accounts.push(solana_program::instruction::AccountMeta {
633                pubkey: *remaining_account.0.key,
634                is_signer: remaining_account.1,
635                is_writable: remaining_account.2,
636            })
637        });
638        let mut data = DelegateInstructionData::new().try_to_vec().unwrap();
639        let mut args = self.__args.try_to_vec().unwrap();
640        data.append(&mut args);
641
642        let instruction = solana_program::instruction::Instruction {
643            program_id: crate::MPL_TOKEN_METADATA_ID,
644            accounts,
645            data,
646        };
647        let mut account_infos = Vec::with_capacity(14 + 1 + remaining_accounts.len());
648        account_infos.push(self.__program.clone());
649        if let Some(delegate_record) = self.delegate_record {
650            account_infos.push(delegate_record.clone());
651        }
652        account_infos.push(self.delegate.clone());
653        account_infos.push(self.metadata.clone());
654        if let Some(master_edition) = self.master_edition {
655            account_infos.push(master_edition.clone());
656        }
657        if let Some(token_record) = self.token_record {
658            account_infos.push(token_record.clone());
659        }
660        account_infos.push(self.mint.clone());
661        if let Some(token) = self.token {
662            account_infos.push(token.clone());
663        }
664        account_infos.push(self.authority.clone());
665        account_infos.push(self.payer.clone());
666        account_infos.push(self.system_program.clone());
667        account_infos.push(self.sysvar_instructions.clone());
668        if let Some(spl_token_program) = self.spl_token_program {
669            account_infos.push(spl_token_program.clone());
670        }
671        if let Some(authorization_rules_program) = self.authorization_rules_program {
672            account_infos.push(authorization_rules_program.clone());
673        }
674        if let Some(authorization_rules) = self.authorization_rules {
675            account_infos.push(authorization_rules.clone());
676        }
677        remaining_accounts
678            .iter()
679            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
680
681        if signers_seeds.is_empty() {
682            solana_program::program::invoke(&instruction, &account_infos)
683        } else {
684            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
685        }
686    }
687}
688
689/// Instruction builder for `Delegate` via CPI.
690///
691/// ### Accounts:
692///
693///   0. `[writable, optional]` delegate_record
694///   1. `[]` delegate
695///   2. `[writable]` metadata
696///   3. `[optional]` master_edition
697///   4. `[writable, optional]` token_record
698///   5. `[]` mint
699///   6. `[writable, optional]` token
700///   7. `[signer]` authority
701///   8. `[writable, signer]` payer
702///   9. `[]` system_program
703///   10. `[]` sysvar_instructions
704///   11. `[optional]` spl_token_program
705///   12. `[optional]` authorization_rules_program
706///   13. `[optional]` authorization_rules
707pub struct DelegateCpiBuilder<'a, 'b> {
708    instruction: Box<DelegateCpiBuilderInstruction<'a, 'b>>,
709}
710
711impl<'a, 'b> DelegateCpiBuilder<'a, 'b> {
712    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
713        let instruction = Box::new(DelegateCpiBuilderInstruction {
714            __program: program,
715            delegate_record: None,
716            delegate: None,
717            metadata: None,
718            master_edition: None,
719            token_record: None,
720            mint: None,
721            token: None,
722            authority: None,
723            payer: None,
724            system_program: None,
725            sysvar_instructions: None,
726            spl_token_program: None,
727            authorization_rules_program: None,
728            authorization_rules: None,
729            delegate_args: None,
730            __remaining_accounts: Vec::new(),
731        });
732        Self { instruction }
733    }
734    /// `[optional account]`
735    /// Delegate record account
736    #[inline(always)]
737    pub fn delegate_record(
738        &mut self,
739        delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
740    ) -> &mut Self {
741        self.instruction.delegate_record = delegate_record;
742        self
743    }
744    /// Owner of the delegated account
745    #[inline(always)]
746    pub fn delegate(
747        &mut self,
748        delegate: &'b solana_program::account_info::AccountInfo<'a>,
749    ) -> &mut Self {
750        self.instruction.delegate = Some(delegate);
751        self
752    }
753    /// Metadata account
754    #[inline(always)]
755    pub fn metadata(
756        &mut self,
757        metadata: &'b solana_program::account_info::AccountInfo<'a>,
758    ) -> &mut Self {
759        self.instruction.metadata = Some(metadata);
760        self
761    }
762    /// `[optional account]`
763    /// Master Edition account
764    #[inline(always)]
765    pub fn master_edition(
766        &mut self,
767        master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
768    ) -> &mut Self {
769        self.instruction.master_edition = master_edition;
770        self
771    }
772    /// `[optional account]`
773    /// Token record account
774    #[inline(always)]
775    pub fn token_record(
776        &mut self,
777        token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
778    ) -> &mut Self {
779        self.instruction.token_record = token_record;
780        self
781    }
782    /// Mint of metadata
783    #[inline(always)]
784    pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
785        self.instruction.mint = Some(mint);
786        self
787    }
788    /// `[optional account]`
789    /// Token account of mint
790    #[inline(always)]
791    pub fn token(
792        &mut self,
793        token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
794    ) -> &mut Self {
795        self.instruction.token = token;
796        self
797    }
798    /// Update authority or token owner
799    #[inline(always)]
800    pub fn authority(
801        &mut self,
802        authority: &'b solana_program::account_info::AccountInfo<'a>,
803    ) -> &mut Self {
804        self.instruction.authority = Some(authority);
805        self
806    }
807    /// Payer
808    #[inline(always)]
809    pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
810        self.instruction.payer = Some(payer);
811        self
812    }
813    /// System Program
814    #[inline(always)]
815    pub fn system_program(
816        &mut self,
817        system_program: &'b solana_program::account_info::AccountInfo<'a>,
818    ) -> &mut Self {
819        self.instruction.system_program = Some(system_program);
820        self
821    }
822    /// Instructions sysvar account
823    #[inline(always)]
824    pub fn sysvar_instructions(
825        &mut self,
826        sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
827    ) -> &mut Self {
828        self.instruction.sysvar_instructions = Some(sysvar_instructions);
829        self
830    }
831    /// `[optional account]`
832    /// SPL Token Program
833    #[inline(always)]
834    pub fn spl_token_program(
835        &mut self,
836        spl_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
837    ) -> &mut Self {
838        self.instruction.spl_token_program = spl_token_program;
839        self
840    }
841    /// `[optional account]`
842    /// Token Authorization Rules Program
843    #[inline(always)]
844    pub fn authorization_rules_program(
845        &mut self,
846        authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
847    ) -> &mut Self {
848        self.instruction.authorization_rules_program = authorization_rules_program;
849        self
850    }
851    /// `[optional account]`
852    /// Token Authorization Rules account
853    #[inline(always)]
854    pub fn authorization_rules(
855        &mut self,
856        authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
857    ) -> &mut Self {
858        self.instruction.authorization_rules = authorization_rules;
859        self
860    }
861    #[inline(always)]
862    pub fn delegate_args(&mut self, delegate_args: DelegateArgs) -> &mut Self {
863        self.instruction.delegate_args = Some(delegate_args);
864        self
865    }
866    /// Add an additional account to the instruction.
867    #[inline(always)]
868    pub fn add_remaining_account(
869        &mut self,
870        account: &'b solana_program::account_info::AccountInfo<'a>,
871        is_writable: bool,
872        is_signer: bool,
873    ) -> &mut Self {
874        self.instruction
875            .__remaining_accounts
876            .push((account, is_writable, is_signer));
877        self
878    }
879    /// Add additional accounts to the instruction.
880    ///
881    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
882    /// and a `bool` indicating whether the account is a signer or not.
883    #[inline(always)]
884    pub fn add_remaining_accounts(
885        &mut self,
886        accounts: &[(
887            &'b solana_program::account_info::AccountInfo<'a>,
888            bool,
889            bool,
890        )],
891    ) -> &mut Self {
892        self.instruction
893            .__remaining_accounts
894            .extend_from_slice(accounts);
895        self
896    }
897    #[inline(always)]
898    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
899        self.invoke_signed(&[])
900    }
901    #[allow(clippy::clone_on_copy)]
902    #[allow(clippy::vec_init_then_push)]
903    pub fn invoke_signed(
904        &self,
905        signers_seeds: &[&[&[u8]]],
906    ) -> solana_program::entrypoint::ProgramResult {
907        let args = DelegateInstructionArgs {
908            delegate_args: self
909                .instruction
910                .delegate_args
911                .clone()
912                .expect("delegate_args is not set"),
913        };
914        let instruction = DelegateCpi {
915            __program: self.instruction.__program,
916
917            delegate_record: self.instruction.delegate_record,
918
919            delegate: self.instruction.delegate.expect("delegate is not set"),
920
921            metadata: self.instruction.metadata.expect("metadata is not set"),
922
923            master_edition: self.instruction.master_edition,
924
925            token_record: self.instruction.token_record,
926
927            mint: self.instruction.mint.expect("mint is not set"),
928
929            token: self.instruction.token,
930
931            authority: self.instruction.authority.expect("authority is not set"),
932
933            payer: self.instruction.payer.expect("payer is not set"),
934
935            system_program: self
936                .instruction
937                .system_program
938                .expect("system_program is not set"),
939
940            sysvar_instructions: self
941                .instruction
942                .sysvar_instructions
943                .expect("sysvar_instructions is not set"),
944
945            spl_token_program: self.instruction.spl_token_program,
946
947            authorization_rules_program: self.instruction.authorization_rules_program,
948
949            authorization_rules: self.instruction.authorization_rules,
950            __args: args,
951        };
952        instruction.invoke_signed_with_remaining_accounts(
953            signers_seeds,
954            &self.instruction.__remaining_accounts,
955        )
956    }
957}
958
959struct DelegateCpiBuilderInstruction<'a, 'b> {
960    __program: &'b solana_program::account_info::AccountInfo<'a>,
961    delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
962    delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
963    metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
964    master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
965    token_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
966    mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
967    token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
968    authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
969    payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
970    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
971    sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
972    spl_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
973    authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
974    authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
975    delegate_args: Option<DelegateArgs>,
976    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
977    __remaining_accounts: Vec<(
978        &'b solana_program::account_info::AccountInfo<'a>,
979        bool,
980        bool,
981    )>,
982}