1#[cfg(feature = "anchor")]
9use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
10#[cfg(not(feature = "anchor"))]
11use borsh::{BorshDeserialize, BorshSerialize};
12
13pub struct DelegateExecutionV1 {
15 pub executive_profile: solana_program::pubkey::Pubkey,
17 pub agent_asset: solana_program::pubkey::Pubkey,
19 pub agent_identity: solana_program::pubkey::Pubkey,
21 pub execution_delegate_record: solana_program::pubkey::Pubkey,
23 pub payer: solana_program::pubkey::Pubkey,
25 pub authority: Option<solana_program::pubkey::Pubkey>,
27 pub system_program: solana_program::pubkey::Pubkey,
29}
30
31impl DelegateExecutionV1 {
32 pub fn instruction(&self) -> solana_program::instruction::Instruction {
33 self.instruction_with_remaining_accounts(&[])
34 }
35 #[allow(clippy::vec_init_then_push)]
36 pub fn instruction_with_remaining_accounts(
37 &self,
38 remaining_accounts: &[solana_program::instruction::AccountMeta],
39 ) -> solana_program::instruction::Instruction {
40 let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
41 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42 self.executive_profile,
43 false,
44 ));
45 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46 self.agent_asset,
47 false,
48 ));
49 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
50 self.agent_identity,
51 false,
52 ));
53 accounts.push(solana_program::instruction::AccountMeta::new(
54 self.execution_delegate_record,
55 false,
56 ));
57 accounts.push(solana_program::instruction::AccountMeta::new(
58 self.payer, true,
59 ));
60 if let Some(authority) = self.authority {
61 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
62 authority, true,
63 ));
64 } else {
65 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
66 crate::MPL_AGENT_TOOLS_ID,
67 false,
68 ));
69 }
70 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
71 self.system_program,
72 false,
73 ));
74 accounts.extend_from_slice(remaining_accounts);
75 let data = borsh::to_vec(&(DelegateExecutionV1InstructionData::new())).unwrap();
76
77 solana_program::instruction::Instruction {
78 program_id: crate::MPL_AGENT_TOOLS_ID,
79 accounts,
80 data,
81 }
82 }
83}
84
85#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
86#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
87pub struct DelegateExecutionV1InstructionData {
88 discriminator: u8,
89 padding: [u8; 7],
90}
91
92impl DelegateExecutionV1InstructionData {
93 pub fn new() -> Self {
94 Self {
95 discriminator: 1,
96 padding: [0, 0, 0, 0, 0, 0, 0],
97 }
98 }
99}
100
101#[derive(Default)]
113pub struct DelegateExecutionV1Builder {
114 executive_profile: Option<solana_program::pubkey::Pubkey>,
115 agent_asset: Option<solana_program::pubkey::Pubkey>,
116 agent_identity: Option<solana_program::pubkey::Pubkey>,
117 execution_delegate_record: Option<solana_program::pubkey::Pubkey>,
118 payer: Option<solana_program::pubkey::Pubkey>,
119 authority: Option<solana_program::pubkey::Pubkey>,
120 system_program: Option<solana_program::pubkey::Pubkey>,
121 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
122}
123
124impl DelegateExecutionV1Builder {
125 pub fn new() -> Self {
126 Self::default()
127 }
128 #[inline(always)]
130 pub fn executive_profile(
131 &mut self,
132 executive_profile: solana_program::pubkey::Pubkey,
133 ) -> &mut Self {
134 self.executive_profile = Some(executive_profile);
135 self
136 }
137 #[inline(always)]
139 pub fn agent_asset(&mut self, agent_asset: solana_program::pubkey::Pubkey) -> &mut Self {
140 self.agent_asset = Some(agent_asset);
141 self
142 }
143 #[inline(always)]
145 pub fn agent_identity(&mut self, agent_identity: solana_program::pubkey::Pubkey) -> &mut Self {
146 self.agent_identity = Some(agent_identity);
147 self
148 }
149 #[inline(always)]
151 pub fn execution_delegate_record(
152 &mut self,
153 execution_delegate_record: solana_program::pubkey::Pubkey,
154 ) -> &mut Self {
155 self.execution_delegate_record = Some(execution_delegate_record);
156 self
157 }
158 #[inline(always)]
160 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
161 self.payer = Some(payer);
162 self
163 }
164 #[inline(always)]
167 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
168 self.authority = authority;
169 self
170 }
171 #[inline(always)]
174 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
175 self.system_program = Some(system_program);
176 self
177 }
178 #[inline(always)]
180 pub fn add_remaining_account(
181 &mut self,
182 account: solana_program::instruction::AccountMeta,
183 ) -> &mut Self {
184 self.__remaining_accounts.push(account);
185 self
186 }
187 #[inline(always)]
189 pub fn add_remaining_accounts(
190 &mut self,
191 accounts: &[solana_program::instruction::AccountMeta],
192 ) -> &mut Self {
193 self.__remaining_accounts.extend_from_slice(accounts);
194 self
195 }
196 #[allow(clippy::clone_on_copy)]
197 pub fn instruction(&self) -> solana_program::instruction::Instruction {
198 let accounts = DelegateExecutionV1 {
199 executive_profile: self
200 .executive_profile
201 .expect("executive_profile is not set"),
202 agent_asset: self.agent_asset.expect("agent_asset is not set"),
203 agent_identity: self.agent_identity.expect("agent_identity is not set"),
204 execution_delegate_record: self
205 .execution_delegate_record
206 .expect("execution_delegate_record is not set"),
207 payer: self.payer.expect("payer is not set"),
208 authority: self.authority,
209 system_program: self
210 .system_program
211 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
212 };
213
214 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
215 }
216}
217
218pub struct DelegateExecutionV1CpiAccounts<'a, 'b> {
220 pub executive_profile: &'b solana_program::account_info::AccountInfo<'a>,
222 pub agent_asset: &'b solana_program::account_info::AccountInfo<'a>,
224 pub agent_identity: &'b solana_program::account_info::AccountInfo<'a>,
226 pub execution_delegate_record: &'b solana_program::account_info::AccountInfo<'a>,
228 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
230 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
232 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
234}
235
236pub struct DelegateExecutionV1Cpi<'a, 'b> {
238 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
240 pub executive_profile: &'b solana_program::account_info::AccountInfo<'a>,
242 pub agent_asset: &'b solana_program::account_info::AccountInfo<'a>,
244 pub agent_identity: &'b solana_program::account_info::AccountInfo<'a>,
246 pub execution_delegate_record: &'b solana_program::account_info::AccountInfo<'a>,
248 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
250 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
252 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
254}
255
256impl<'a, 'b> DelegateExecutionV1Cpi<'a, 'b> {
257 pub fn new(
258 program: &'b solana_program::account_info::AccountInfo<'a>,
259 accounts: DelegateExecutionV1CpiAccounts<'a, 'b>,
260 ) -> Self {
261 Self {
262 __program: program,
263 executive_profile: accounts.executive_profile,
264 agent_asset: accounts.agent_asset,
265 agent_identity: accounts.agent_identity,
266 execution_delegate_record: accounts.execution_delegate_record,
267 payer: accounts.payer,
268 authority: accounts.authority,
269 system_program: accounts.system_program,
270 }
271 }
272 #[inline(always)]
273 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
274 self.invoke_signed_with_remaining_accounts(&[], &[])
275 }
276 #[inline(always)]
277 pub fn invoke_with_remaining_accounts(
278 &self,
279 remaining_accounts: &[(
280 &'b solana_program::account_info::AccountInfo<'a>,
281 bool,
282 bool,
283 )],
284 ) -> solana_program::entrypoint::ProgramResult {
285 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
286 }
287 #[inline(always)]
288 pub fn invoke_signed(
289 &self,
290 signers_seeds: &[&[&[u8]]],
291 ) -> solana_program::entrypoint::ProgramResult {
292 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
293 }
294 #[allow(clippy::clone_on_copy)]
295 #[allow(clippy::vec_init_then_push)]
296 pub fn invoke_signed_with_remaining_accounts(
297 &self,
298 signers_seeds: &[&[&[u8]]],
299 remaining_accounts: &[(
300 &'b solana_program::account_info::AccountInfo<'a>,
301 bool,
302 bool,
303 )],
304 ) -> solana_program::entrypoint::ProgramResult {
305 let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
306 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
307 *self.executive_profile.key,
308 false,
309 ));
310 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
311 *self.agent_asset.key,
312 false,
313 ));
314 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
315 *self.agent_identity.key,
316 false,
317 ));
318 accounts.push(solana_program::instruction::AccountMeta::new(
319 *self.execution_delegate_record.key,
320 false,
321 ));
322 accounts.push(solana_program::instruction::AccountMeta::new(
323 *self.payer.key,
324 true,
325 ));
326 if let Some(authority) = self.authority {
327 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
328 *authority.key,
329 true,
330 ));
331 } else {
332 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
333 crate::MPL_AGENT_TOOLS_ID,
334 false,
335 ));
336 }
337 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
338 *self.system_program.key,
339 false,
340 ));
341 remaining_accounts.iter().for_each(|remaining_account| {
342 accounts.push(solana_program::instruction::AccountMeta {
343 pubkey: *remaining_account.0.key,
344 is_writable: remaining_account.1,
345 is_signer: remaining_account.2,
346 })
347 });
348 let data = borsh::to_vec(&(DelegateExecutionV1InstructionData::new())).unwrap();
349
350 let instruction = solana_program::instruction::Instruction {
351 program_id: crate::MPL_AGENT_TOOLS_ID,
352 accounts,
353 data,
354 };
355 let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len());
356 account_infos.push(self.__program.clone());
357 account_infos.push(self.executive_profile.clone());
358 account_infos.push(self.agent_asset.clone());
359 account_infos.push(self.agent_identity.clone());
360 account_infos.push(self.execution_delegate_record.clone());
361 account_infos.push(self.payer.clone());
362 if let Some(authority) = self.authority {
363 account_infos.push(authority.clone());
364 }
365 account_infos.push(self.system_program.clone());
366 remaining_accounts
367 .iter()
368 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
369
370 if signers_seeds.is_empty() {
371 solana_program::program::invoke(&instruction, &account_infos)
372 } else {
373 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
374 }
375 }
376}
377
378pub struct DelegateExecutionV1CpiBuilder<'a, 'b> {
390 instruction: Box<DelegateExecutionV1CpiBuilderInstruction<'a, 'b>>,
391}
392
393impl<'a, 'b> DelegateExecutionV1CpiBuilder<'a, 'b> {
394 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
395 let instruction = Box::new(DelegateExecutionV1CpiBuilderInstruction {
396 __program: program,
397 executive_profile: None,
398 agent_asset: None,
399 agent_identity: None,
400 execution_delegate_record: None,
401 payer: None,
402 authority: None,
403 system_program: None,
404 __remaining_accounts: Vec::new(),
405 });
406 Self { instruction }
407 }
408 #[inline(always)]
410 pub fn executive_profile(
411 &mut self,
412 executive_profile: &'b solana_program::account_info::AccountInfo<'a>,
413 ) -> &mut Self {
414 self.instruction.executive_profile = Some(executive_profile);
415 self
416 }
417 #[inline(always)]
419 pub fn agent_asset(
420 &mut self,
421 agent_asset: &'b solana_program::account_info::AccountInfo<'a>,
422 ) -> &mut Self {
423 self.instruction.agent_asset = Some(agent_asset);
424 self
425 }
426 #[inline(always)]
428 pub fn agent_identity(
429 &mut self,
430 agent_identity: &'b solana_program::account_info::AccountInfo<'a>,
431 ) -> &mut Self {
432 self.instruction.agent_identity = Some(agent_identity);
433 self
434 }
435 #[inline(always)]
437 pub fn execution_delegate_record(
438 &mut self,
439 execution_delegate_record: &'b solana_program::account_info::AccountInfo<'a>,
440 ) -> &mut Self {
441 self.instruction.execution_delegate_record = Some(execution_delegate_record);
442 self
443 }
444 #[inline(always)]
446 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
447 self.instruction.payer = Some(payer);
448 self
449 }
450 #[inline(always)]
453 pub fn authority(
454 &mut self,
455 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
456 ) -> &mut Self {
457 self.instruction.authority = authority;
458 self
459 }
460 #[inline(always)]
462 pub fn system_program(
463 &mut self,
464 system_program: &'b solana_program::account_info::AccountInfo<'a>,
465 ) -> &mut Self {
466 self.instruction.system_program = Some(system_program);
467 self
468 }
469 #[inline(always)]
471 pub fn add_remaining_account(
472 &mut self,
473 account: &'b solana_program::account_info::AccountInfo<'a>,
474 is_writable: bool,
475 is_signer: bool,
476 ) -> &mut Self {
477 self.instruction
478 .__remaining_accounts
479 .push((account, is_writable, is_signer));
480 self
481 }
482 #[inline(always)]
487 pub fn add_remaining_accounts(
488 &mut self,
489 accounts: &[(
490 &'b solana_program::account_info::AccountInfo<'a>,
491 bool,
492 bool,
493 )],
494 ) -> &mut Self {
495 self.instruction
496 .__remaining_accounts
497 .extend_from_slice(accounts);
498 self
499 }
500 #[inline(always)]
501 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
502 self.invoke_signed(&[])
503 }
504 #[allow(clippy::clone_on_copy)]
505 #[allow(clippy::vec_init_then_push)]
506 pub fn invoke_signed(
507 &self,
508 signers_seeds: &[&[&[u8]]],
509 ) -> solana_program::entrypoint::ProgramResult {
510 let instruction = DelegateExecutionV1Cpi {
511 __program: self.instruction.__program,
512
513 executive_profile: self
514 .instruction
515 .executive_profile
516 .expect("executive_profile is not set"),
517
518 agent_asset: self
519 .instruction
520 .agent_asset
521 .expect("agent_asset is not set"),
522
523 agent_identity: self
524 .instruction
525 .agent_identity
526 .expect("agent_identity is not set"),
527
528 execution_delegate_record: self
529 .instruction
530 .execution_delegate_record
531 .expect("execution_delegate_record is not set"),
532
533 payer: self.instruction.payer.expect("payer is not set"),
534
535 authority: self.instruction.authority,
536
537 system_program: self
538 .instruction
539 .system_program
540 .expect("system_program is not set"),
541 };
542 instruction.invoke_signed_with_remaining_accounts(
543 signers_seeds,
544 &self.instruction.__remaining_accounts,
545 )
546 }
547}
548
549struct DelegateExecutionV1CpiBuilderInstruction<'a, 'b> {
550 __program: &'b solana_program::account_info::AccountInfo<'a>,
551 executive_profile: Option<&'b solana_program::account_info::AccountInfo<'a>>,
552 agent_asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
553 agent_identity: Option<&'b solana_program::account_info::AccountInfo<'a>>,
554 execution_delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
555 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
556 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
557 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
558 __remaining_accounts: Vec<(
560 &'b solana_program::account_info::AccountInfo<'a>,
561 bool,
562 bool,
563 )>,
564}