Skip to main content

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