1use crate::generated::types::ExtensionInput;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub struct Update {
14 pub asset: solana_program::pubkey::Pubkey,
16 pub authority: solana_program::pubkey::Pubkey,
18 pub buffer: Option<solana_program::pubkey::Pubkey>,
20 pub group: Option<solana_program::pubkey::Pubkey>,
22 pub payer: Option<solana_program::pubkey::Pubkey>,
24 pub system_program: Option<solana_program::pubkey::Pubkey>,
26}
27
28impl Update {
29 pub fn instruction(
30 &self,
31 args: UpdateInstructionArgs,
32 ) -> solana_program::instruction::Instruction {
33 self.instruction_with_remaining_accounts(args, &[])
34 }
35 #[allow(clippy::vec_init_then_push)]
36 pub fn instruction_with_remaining_accounts(
37 &self,
38 args: UpdateInstructionArgs,
39 remaining_accounts: &[solana_program::instruction::AccountMeta],
40 ) -> solana_program::instruction::Instruction {
41 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
42 accounts.push(solana_program::instruction::AccountMeta::new(
43 self.asset, true,
44 ));
45 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46 self.authority,
47 true,
48 ));
49 if let Some(buffer) = self.buffer {
50 accounts.push(solana_program::instruction::AccountMeta::new(buffer, false));
51 } else {
52 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53 crate::INTERFACE_ID,
54 false,
55 ));
56 }
57 if let Some(group) = self.group {
58 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
59 group, false,
60 ));
61 } else {
62 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
63 crate::INTERFACE_ID,
64 false,
65 ));
66 }
67 if let Some(payer) = self.payer {
68 accounts.push(solana_program::instruction::AccountMeta::new(payer, true));
69 } else {
70 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
71 crate::INTERFACE_ID,
72 false,
73 ));
74 }
75 if let Some(system_program) = self.system_program {
76 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
77 system_program,
78 false,
79 ));
80 } else {
81 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
82 crate::INTERFACE_ID,
83 false,
84 ));
85 }
86 accounts.extend_from_slice(remaining_accounts);
87 let mut data = UpdateInstructionData::new().try_to_vec().unwrap();
88 let mut args = args.try_to_vec().unwrap();
89 data.append(&mut args);
90
91 solana_program::instruction::Instruction {
92 program_id: crate::INTERFACE_ID,
93 accounts,
94 data,
95 }
96 }
97}
98
99#[derive(BorshDeserialize, BorshSerialize)]
100struct UpdateInstructionData {
101 discriminator: u8,
102}
103
104impl UpdateInstructionData {
105 fn new() -> Self {
106 Self { discriminator: 10 }
107 }
108}
109
110#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
111#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
112pub struct UpdateInstructionArgs {
113 pub name: Option<String>,
114 pub mutable: Option<bool>,
115 pub extension: Option<ExtensionInput>,
116}
117
118#[derive(Default)]
129pub struct UpdateBuilder {
130 asset: Option<solana_program::pubkey::Pubkey>,
131 authority: Option<solana_program::pubkey::Pubkey>,
132 buffer: Option<solana_program::pubkey::Pubkey>,
133 group: Option<solana_program::pubkey::Pubkey>,
134 payer: Option<solana_program::pubkey::Pubkey>,
135 system_program: Option<solana_program::pubkey::Pubkey>,
136 name: Option<String>,
137 mutable: Option<bool>,
138 extension: Option<ExtensionInput>,
139 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
140}
141
142impl UpdateBuilder {
143 pub fn new() -> Self {
144 Self::default()
145 }
146 #[inline(always)]
148 pub fn asset(&mut self, asset: solana_program::pubkey::Pubkey) -> &mut Self {
149 self.asset = Some(asset);
150 self
151 }
152 #[inline(always)]
154 pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
155 self.authority = Some(authority);
156 self
157 }
158 #[inline(always)]
161 pub fn buffer(&mut self, buffer: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
162 self.buffer = buffer;
163 self
164 }
165 #[inline(always)]
168 pub fn group(&mut self, group: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
169 self.group = group;
170 self
171 }
172 #[inline(always)]
175 pub fn payer(&mut self, payer: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
176 self.payer = payer;
177 self
178 }
179 #[inline(always)]
182 pub fn system_program(
183 &mut self,
184 system_program: Option<solana_program::pubkey::Pubkey>,
185 ) -> &mut Self {
186 self.system_program = system_program;
187 self
188 }
189 #[inline(always)]
191 pub fn name(&mut self, name: String) -> &mut Self {
192 self.name = Some(name);
193 self
194 }
195 #[inline(always)]
197 pub fn mutable(&mut self, mutable: bool) -> &mut Self {
198 self.mutable = Some(mutable);
199 self
200 }
201 #[inline(always)]
203 pub fn extension(&mut self, extension: ExtensionInput) -> &mut Self {
204 self.extension = Some(extension);
205 self
206 }
207 #[inline(always)]
209 pub fn add_remaining_account(
210 &mut self,
211 account: solana_program::instruction::AccountMeta,
212 ) -> &mut Self {
213 self.__remaining_accounts.push(account);
214 self
215 }
216 #[inline(always)]
218 pub fn add_remaining_accounts(
219 &mut self,
220 accounts: &[solana_program::instruction::AccountMeta],
221 ) -> &mut Self {
222 self.__remaining_accounts.extend_from_slice(accounts);
223 self
224 }
225 #[allow(clippy::clone_on_copy)]
226 pub fn instruction(&self) -> solana_program::instruction::Instruction {
227 let accounts = Update {
228 asset: self.asset.expect("asset is not set"),
229 authority: self.authority.expect("authority is not set"),
230 buffer: self.buffer,
231 group: self.group,
232 payer: self.payer,
233 system_program: self.system_program,
234 };
235 let args = UpdateInstructionArgs {
236 name: self.name.clone(),
237 mutable: self.mutable.clone(),
238 extension: self.extension.clone(),
239 };
240
241 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
242 }
243}
244
245pub struct UpdateCpiAccounts<'a, 'b> {
247 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
249 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
251 pub buffer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
253 pub group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
255 pub payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
257 pub system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
259}
260
261pub struct UpdateCpi<'a, 'b> {
263 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
265 pub asset: &'b solana_program::account_info::AccountInfo<'a>,
267 pub authority: &'b solana_program::account_info::AccountInfo<'a>,
269 pub buffer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
271 pub group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
273 pub payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
275 pub system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
277 pub __args: UpdateInstructionArgs,
279}
280
281impl<'a, 'b> UpdateCpi<'a, 'b> {
282 pub fn new(
283 program: &'b solana_program::account_info::AccountInfo<'a>,
284 accounts: UpdateCpiAccounts<'a, 'b>,
285 args: UpdateInstructionArgs,
286 ) -> Self {
287 Self {
288 __program: program,
289 asset: accounts.asset,
290 authority: accounts.authority,
291 buffer: accounts.buffer,
292 group: accounts.group,
293 payer: accounts.payer,
294 system_program: accounts.system_program,
295 __args: args,
296 }
297 }
298 #[inline(always)]
299 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
300 self.invoke_signed_with_remaining_accounts(&[], &[])
301 }
302 #[inline(always)]
303 pub fn invoke_with_remaining_accounts(
304 &self,
305 remaining_accounts: &[(
306 &'b solana_program::account_info::AccountInfo<'a>,
307 bool,
308 bool,
309 )],
310 ) -> solana_program::entrypoint::ProgramResult {
311 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
312 }
313 #[inline(always)]
314 pub fn invoke_signed(
315 &self,
316 signers_seeds: &[&[&[u8]]],
317 ) -> solana_program::entrypoint::ProgramResult {
318 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
319 }
320 #[allow(clippy::clone_on_copy)]
321 #[allow(clippy::vec_init_then_push)]
322 pub fn invoke_signed_with_remaining_accounts(
323 &self,
324 signers_seeds: &[&[&[u8]]],
325 remaining_accounts: &[(
326 &'b solana_program::account_info::AccountInfo<'a>,
327 bool,
328 bool,
329 )],
330 ) -> solana_program::entrypoint::ProgramResult {
331 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
332 accounts.push(solana_program::instruction::AccountMeta::new(
333 *self.asset.key,
334 true,
335 ));
336 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
337 *self.authority.key,
338 true,
339 ));
340 if let Some(buffer) = self.buffer {
341 accounts.push(solana_program::instruction::AccountMeta::new(
342 *buffer.key,
343 false,
344 ));
345 } else {
346 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
347 crate::INTERFACE_ID,
348 false,
349 ));
350 }
351 if let Some(group) = self.group {
352 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
353 *group.key, false,
354 ));
355 } else {
356 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
357 crate::INTERFACE_ID,
358 false,
359 ));
360 }
361 if let Some(payer) = self.payer {
362 accounts.push(solana_program::instruction::AccountMeta::new(
363 *payer.key, true,
364 ));
365 } else {
366 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
367 crate::INTERFACE_ID,
368 false,
369 ));
370 }
371 if let Some(system_program) = self.system_program {
372 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
373 *system_program.key,
374 false,
375 ));
376 } else {
377 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
378 crate::INTERFACE_ID,
379 false,
380 ));
381 }
382 remaining_accounts.iter().for_each(|remaining_account| {
383 accounts.push(solana_program::instruction::AccountMeta {
384 pubkey: *remaining_account.0.key,
385 is_signer: remaining_account.1,
386 is_writable: remaining_account.2,
387 })
388 });
389 let mut data = UpdateInstructionData::new().try_to_vec().unwrap();
390 let mut args = self.__args.try_to_vec().unwrap();
391 data.append(&mut args);
392
393 let instruction = solana_program::instruction::Instruction {
394 program_id: crate::INTERFACE_ID,
395 accounts,
396 data,
397 };
398 let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len());
399 account_infos.push(self.__program.clone());
400 account_infos.push(self.asset.clone());
401 account_infos.push(self.authority.clone());
402 if let Some(buffer) = self.buffer {
403 account_infos.push(buffer.clone());
404 }
405 if let Some(group) = self.group {
406 account_infos.push(group.clone());
407 }
408 if let Some(payer) = self.payer {
409 account_infos.push(payer.clone());
410 }
411 if let Some(system_program) = self.system_program {
412 account_infos.push(system_program.clone());
413 }
414 remaining_accounts
415 .iter()
416 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
417
418 if signers_seeds.is_empty() {
419 solana_program::program::invoke(&instruction, &account_infos)
420 } else {
421 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
422 }
423 }
424}
425
426pub struct UpdateCpiBuilder<'a, 'b> {
437 instruction: Box<UpdateCpiBuilderInstruction<'a, 'b>>,
438}
439
440impl<'a, 'b> UpdateCpiBuilder<'a, 'b> {
441 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
442 let instruction = Box::new(UpdateCpiBuilderInstruction {
443 __program: program,
444 asset: None,
445 authority: None,
446 buffer: None,
447 group: None,
448 payer: None,
449 system_program: None,
450 name: None,
451 mutable: None,
452 extension: None,
453 __remaining_accounts: Vec::new(),
454 });
455 Self { instruction }
456 }
457 #[inline(always)]
459 pub fn asset(&mut self, asset: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
460 self.instruction.asset = Some(asset);
461 self
462 }
463 #[inline(always)]
465 pub fn authority(
466 &mut self,
467 authority: &'b solana_program::account_info::AccountInfo<'a>,
468 ) -> &mut Self {
469 self.instruction.authority = Some(authority);
470 self
471 }
472 #[inline(always)]
475 pub fn buffer(
476 &mut self,
477 buffer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
478 ) -> &mut Self {
479 self.instruction.buffer = buffer;
480 self
481 }
482 #[inline(always)]
485 pub fn group(
486 &mut self,
487 group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
488 ) -> &mut Self {
489 self.instruction.group = group;
490 self
491 }
492 #[inline(always)]
495 pub fn payer(
496 &mut self,
497 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
498 ) -> &mut Self {
499 self.instruction.payer = payer;
500 self
501 }
502 #[inline(always)]
505 pub fn system_program(
506 &mut self,
507 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
508 ) -> &mut Self {
509 self.instruction.system_program = system_program;
510 self
511 }
512 #[inline(always)]
514 pub fn name(&mut self, name: String) -> &mut Self {
515 self.instruction.name = Some(name);
516 self
517 }
518 #[inline(always)]
520 pub fn mutable(&mut self, mutable: bool) -> &mut Self {
521 self.instruction.mutable = Some(mutable);
522 self
523 }
524 #[inline(always)]
526 pub fn extension(&mut self, extension: ExtensionInput) -> &mut Self {
527 self.instruction.extension = Some(extension);
528 self
529 }
530 #[inline(always)]
532 pub fn add_remaining_account(
533 &mut self,
534 account: &'b solana_program::account_info::AccountInfo<'a>,
535 is_writable: bool,
536 is_signer: bool,
537 ) -> &mut Self {
538 self.instruction
539 .__remaining_accounts
540 .push((account, is_writable, is_signer));
541 self
542 }
543 #[inline(always)]
548 pub fn add_remaining_accounts(
549 &mut self,
550 accounts: &[(
551 &'b solana_program::account_info::AccountInfo<'a>,
552 bool,
553 bool,
554 )],
555 ) -> &mut Self {
556 self.instruction
557 .__remaining_accounts
558 .extend_from_slice(accounts);
559 self
560 }
561 #[inline(always)]
562 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
563 self.invoke_signed(&[])
564 }
565 #[allow(clippy::clone_on_copy)]
566 #[allow(clippy::vec_init_then_push)]
567 pub fn invoke_signed(
568 &self,
569 signers_seeds: &[&[&[u8]]],
570 ) -> solana_program::entrypoint::ProgramResult {
571 let args = UpdateInstructionArgs {
572 name: self.instruction.name.clone(),
573 mutable: self.instruction.mutable.clone(),
574 extension: self.instruction.extension.clone(),
575 };
576 let instruction = UpdateCpi {
577 __program: self.instruction.__program,
578
579 asset: self.instruction.asset.expect("asset is not set"),
580
581 authority: self.instruction.authority.expect("authority is not set"),
582
583 buffer: self.instruction.buffer,
584
585 group: self.instruction.group,
586
587 payer: self.instruction.payer,
588
589 system_program: self.instruction.system_program,
590 __args: args,
591 };
592 instruction.invoke_signed_with_remaining_accounts(
593 signers_seeds,
594 &self.instruction.__remaining_accounts,
595 )
596 }
597}
598
599struct UpdateCpiBuilderInstruction<'a, 'b> {
600 __program: &'b solana_program::account_info::AccountInfo<'a>,
601 asset: Option<&'b solana_program::account_info::AccountInfo<'a>>,
602 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
603 buffer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
604 group: Option<&'b solana_program::account_info::AccountInfo<'a>>,
605 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
606 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
607 name: Option<String>,
608 mutable: Option<bool>,
609 extension: Option<ExtensionInput>,
610 __remaining_accounts: Vec<(
612 &'b solana_program::account_info::AccountInfo<'a>,
613 bool,
614 bool,
615 )>,
616}