1use crate::generated::types::UpdateMetadataArgs;
9use borsh::BorshDeserialize;
10use borsh::BorshSerialize;
11
12pub const UPDATE_METADATA_DISCRIMINATOR: u8 = 1;
13
14#[derive(Debug)]
16pub struct UpdateMetadata {
17 pub mint: solana_pubkey::Pubkey,
18
19 pub verification_config_or_mint_authority: solana_pubkey::Pubkey,
20
21 pub instructions_sysvar_or_creator: solana_pubkey::Pubkey,
22
23 pub mint_authority: solana_pubkey::Pubkey,
24
25 pub payer: solana_pubkey::Pubkey,
26
27 pub mint_account: solana_pubkey::Pubkey,
28
29 pub token_program: solana_pubkey::Pubkey,
30
31 pub system_program: solana_pubkey::Pubkey,
32}
33
34impl UpdateMetadata {
35 pub fn instruction(
36 &self,
37 args: UpdateMetadataInstructionArgs,
38 ) -> solana_instruction::Instruction {
39 self.instruction_with_remaining_accounts(args, &[])
40 }
41 #[allow(clippy::arithmetic_side_effects)]
42 #[allow(clippy::vec_init_then_push)]
43 pub fn instruction_with_remaining_accounts(
44 &self,
45 args: UpdateMetadataInstructionArgs,
46 remaining_accounts: &[solana_instruction::AccountMeta],
47 ) -> solana_instruction::Instruction {
48 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
49 accounts.push(solana_instruction::AccountMeta::new_readonly(
50 self.mint, false,
51 ));
52 accounts.push(solana_instruction::AccountMeta::new_readonly(
53 self.verification_config_or_mint_authority,
54 false,
55 ));
56 accounts.push(solana_instruction::AccountMeta::new_readonly(
57 self.instructions_sysvar_or_creator,
58 false,
59 ));
60 accounts.push(solana_instruction::AccountMeta::new_readonly(
61 self.mint_authority,
62 false,
63 ));
64 accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
65 accounts.push(solana_instruction::AccountMeta::new(
66 self.mint_account,
67 false,
68 ));
69 accounts.push(solana_instruction::AccountMeta::new_readonly(
70 self.token_program,
71 false,
72 ));
73 accounts.push(solana_instruction::AccountMeta::new_readonly(
74 self.system_program,
75 false,
76 ));
77 accounts.extend_from_slice(remaining_accounts);
78 let mut data = borsh::to_vec(&UpdateMetadataInstructionData::new()).unwrap();
79 let mut args = borsh::to_vec(&args).unwrap();
80 data.append(&mut args);
81
82 solana_instruction::Instruction {
83 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
84 accounts,
85 data,
86 }
87 }
88}
89
90#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
91#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
92pub struct UpdateMetadataInstructionData {
93 discriminator: u8,
94}
95
96impl UpdateMetadataInstructionData {
97 pub fn new() -> Self {
98 Self { discriminator: 1 }
99 }
100}
101
102impl Default for UpdateMetadataInstructionData {
103 fn default() -> Self {
104 Self::new()
105 }
106}
107
108#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
109#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110pub struct UpdateMetadataInstructionArgs {
111 pub update_metadata_args: UpdateMetadataArgs,
112}
113
114#[derive(Clone, Debug, Default)]
127pub struct UpdateMetadataBuilder {
128 mint: Option<solana_pubkey::Pubkey>,
129 verification_config_or_mint_authority: Option<solana_pubkey::Pubkey>,
130 instructions_sysvar_or_creator: Option<solana_pubkey::Pubkey>,
131 mint_authority: Option<solana_pubkey::Pubkey>,
132 payer: Option<solana_pubkey::Pubkey>,
133 mint_account: Option<solana_pubkey::Pubkey>,
134 token_program: Option<solana_pubkey::Pubkey>,
135 system_program: Option<solana_pubkey::Pubkey>,
136 update_metadata_args: Option<UpdateMetadataArgs>,
137 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
138}
139
140impl UpdateMetadataBuilder {
141 pub fn new() -> Self {
142 Self::default()
143 }
144 #[inline(always)]
145 pub fn mint(&mut self, mint: solana_pubkey::Pubkey) -> &mut Self {
146 self.mint = Some(mint);
147 self
148 }
149 #[inline(always)]
150 pub fn verification_config_or_mint_authority(
151 &mut self,
152 verification_config_or_mint_authority: solana_pubkey::Pubkey,
153 ) -> &mut Self {
154 self.verification_config_or_mint_authority = Some(verification_config_or_mint_authority);
155 self
156 }
157 #[inline(always)]
158 pub fn instructions_sysvar_or_creator(
159 &mut self,
160 instructions_sysvar_or_creator: solana_pubkey::Pubkey,
161 ) -> &mut Self {
162 self.instructions_sysvar_or_creator = Some(instructions_sysvar_or_creator);
163 self
164 }
165 #[inline(always)]
166 pub fn mint_authority(&mut self, mint_authority: solana_pubkey::Pubkey) -> &mut Self {
167 self.mint_authority = Some(mint_authority);
168 self
169 }
170 #[inline(always)]
171 pub fn payer(&mut self, payer: solana_pubkey::Pubkey) -> &mut Self {
172 self.payer = Some(payer);
173 self
174 }
175 #[inline(always)]
176 pub fn mint_account(&mut self, mint_account: solana_pubkey::Pubkey) -> &mut Self {
177 self.mint_account = Some(mint_account);
178 self
179 }
180 #[inline(always)]
182 pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
183 self.token_program = Some(token_program);
184 self
185 }
186 #[inline(always)]
188 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
189 self.system_program = Some(system_program);
190 self
191 }
192 #[inline(always)]
193 pub fn update_metadata_args(&mut self, update_metadata_args: UpdateMetadataArgs) -> &mut Self {
194 self.update_metadata_args = Some(update_metadata_args);
195 self
196 }
197 #[inline(always)]
199 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
200 self.__remaining_accounts.push(account);
201 self
202 }
203 #[inline(always)]
205 pub fn add_remaining_accounts(
206 &mut self,
207 accounts: &[solana_instruction::AccountMeta],
208 ) -> &mut Self {
209 self.__remaining_accounts.extend_from_slice(accounts);
210 self
211 }
212 #[allow(clippy::clone_on_copy)]
213 pub fn instruction(&self) -> solana_instruction::Instruction {
214 let accounts = UpdateMetadata {
215 mint: self.mint.expect("mint is not set"),
216 verification_config_or_mint_authority: self
217 .verification_config_or_mint_authority
218 .expect("verification_config_or_mint_authority is not set"),
219 instructions_sysvar_or_creator: self
220 .instructions_sysvar_or_creator
221 .expect("instructions_sysvar_or_creator is not set"),
222 mint_authority: self.mint_authority.expect("mint_authority is not set"),
223 payer: self.payer.expect("payer is not set"),
224 mint_account: self.mint_account.expect("mint_account is not set"),
225 token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
226 "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
227 )),
228 system_program: self
229 .system_program
230 .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
231 };
232 let args = UpdateMetadataInstructionArgs {
233 update_metadata_args: self
234 .update_metadata_args
235 .clone()
236 .expect("update_metadata_args is not set"),
237 };
238
239 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
240 }
241}
242
243pub struct UpdateMetadataCpiAccounts<'a, 'b> {
245 pub mint: &'b solana_account_info::AccountInfo<'a>,
246
247 pub verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
248
249 pub instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
250
251 pub mint_authority: &'b solana_account_info::AccountInfo<'a>,
252
253 pub payer: &'b solana_account_info::AccountInfo<'a>,
254
255 pub mint_account: &'b solana_account_info::AccountInfo<'a>,
256
257 pub token_program: &'b solana_account_info::AccountInfo<'a>,
258
259 pub system_program: &'b solana_account_info::AccountInfo<'a>,
260}
261
262pub struct UpdateMetadataCpi<'a, 'b> {
264 pub __program: &'b solana_account_info::AccountInfo<'a>,
266
267 pub mint: &'b solana_account_info::AccountInfo<'a>,
268
269 pub verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
270
271 pub instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
272
273 pub mint_authority: &'b solana_account_info::AccountInfo<'a>,
274
275 pub payer: &'b solana_account_info::AccountInfo<'a>,
276
277 pub mint_account: &'b solana_account_info::AccountInfo<'a>,
278
279 pub token_program: &'b solana_account_info::AccountInfo<'a>,
280
281 pub system_program: &'b solana_account_info::AccountInfo<'a>,
282 pub __args: UpdateMetadataInstructionArgs,
284}
285
286impl<'a, 'b> UpdateMetadataCpi<'a, 'b> {
287 pub fn new(
288 program: &'b solana_account_info::AccountInfo<'a>,
289 accounts: UpdateMetadataCpiAccounts<'a, 'b>,
290 args: UpdateMetadataInstructionArgs,
291 ) -> Self {
292 Self {
293 __program: program,
294 mint: accounts.mint,
295 verification_config_or_mint_authority: accounts.verification_config_or_mint_authority,
296 instructions_sysvar_or_creator: accounts.instructions_sysvar_or_creator,
297 mint_authority: accounts.mint_authority,
298 payer: accounts.payer,
299 mint_account: accounts.mint_account,
300 token_program: accounts.token_program,
301 system_program: accounts.system_program,
302 __args: args,
303 }
304 }
305 #[inline(always)]
306 pub fn invoke(&self) -> solana_program_error::ProgramResult {
307 self.invoke_signed_with_remaining_accounts(&[], &[])
308 }
309 #[inline(always)]
310 pub fn invoke_with_remaining_accounts(
311 &self,
312 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
313 ) -> solana_program_error::ProgramResult {
314 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
315 }
316 #[inline(always)]
317 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
318 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
319 }
320 #[allow(clippy::arithmetic_side_effects)]
321 #[allow(clippy::clone_on_copy)]
322 #[allow(clippy::vec_init_then_push)]
323 pub fn invoke_signed_with_remaining_accounts(
324 &self,
325 signers_seeds: &[&[&[u8]]],
326 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
327 ) -> solana_program_error::ProgramResult {
328 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
329 accounts.push(solana_instruction::AccountMeta::new_readonly(
330 *self.mint.key,
331 false,
332 ));
333 accounts.push(solana_instruction::AccountMeta::new_readonly(
334 *self.verification_config_or_mint_authority.key,
335 false,
336 ));
337 accounts.push(solana_instruction::AccountMeta::new_readonly(
338 *self.instructions_sysvar_or_creator.key,
339 false,
340 ));
341 accounts.push(solana_instruction::AccountMeta::new_readonly(
342 *self.mint_authority.key,
343 false,
344 ));
345 accounts.push(solana_instruction::AccountMeta::new(*self.payer.key, true));
346 accounts.push(solana_instruction::AccountMeta::new(
347 *self.mint_account.key,
348 false,
349 ));
350 accounts.push(solana_instruction::AccountMeta::new_readonly(
351 *self.token_program.key,
352 false,
353 ));
354 accounts.push(solana_instruction::AccountMeta::new_readonly(
355 *self.system_program.key,
356 false,
357 ));
358 remaining_accounts.iter().for_each(|remaining_account| {
359 accounts.push(solana_instruction::AccountMeta {
360 pubkey: *remaining_account.0.key,
361 is_signer: remaining_account.1,
362 is_writable: remaining_account.2,
363 })
364 });
365 let mut data = borsh::to_vec(&UpdateMetadataInstructionData::new()).unwrap();
366 let mut args = borsh::to_vec(&self.__args).unwrap();
367 data.append(&mut args);
368
369 let instruction = solana_instruction::Instruction {
370 program_id: crate::SECURITY_TOKEN_PROGRAM_ID,
371 accounts,
372 data,
373 };
374 let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
375 account_infos.push(self.__program.clone());
376 account_infos.push(self.mint.clone());
377 account_infos.push(self.verification_config_or_mint_authority.clone());
378 account_infos.push(self.instructions_sysvar_or_creator.clone());
379 account_infos.push(self.mint_authority.clone());
380 account_infos.push(self.payer.clone());
381 account_infos.push(self.mint_account.clone());
382 account_infos.push(self.token_program.clone());
383 account_infos.push(self.system_program.clone());
384 remaining_accounts
385 .iter()
386 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
387
388 if signers_seeds.is_empty() {
389 solana_cpi::invoke(&instruction, &account_infos)
390 } else {
391 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
392 }
393 }
394}
395
396#[derive(Clone, Debug)]
409pub struct UpdateMetadataCpiBuilder<'a, 'b> {
410 instruction: Box<UpdateMetadataCpiBuilderInstruction<'a, 'b>>,
411}
412
413impl<'a, 'b> UpdateMetadataCpiBuilder<'a, 'b> {
414 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
415 let instruction = Box::new(UpdateMetadataCpiBuilderInstruction {
416 __program: program,
417 mint: None,
418 verification_config_or_mint_authority: None,
419 instructions_sysvar_or_creator: None,
420 mint_authority: None,
421 payer: None,
422 mint_account: None,
423 token_program: None,
424 system_program: None,
425 update_metadata_args: None,
426 __remaining_accounts: Vec::new(),
427 });
428 Self { instruction }
429 }
430 #[inline(always)]
431 pub fn mint(&mut self, mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
432 self.instruction.mint = Some(mint);
433 self
434 }
435 #[inline(always)]
436 pub fn verification_config_or_mint_authority(
437 &mut self,
438 verification_config_or_mint_authority: &'b solana_account_info::AccountInfo<'a>,
439 ) -> &mut Self {
440 self.instruction.verification_config_or_mint_authority =
441 Some(verification_config_or_mint_authority);
442 self
443 }
444 #[inline(always)]
445 pub fn instructions_sysvar_or_creator(
446 &mut self,
447 instructions_sysvar_or_creator: &'b solana_account_info::AccountInfo<'a>,
448 ) -> &mut Self {
449 self.instruction.instructions_sysvar_or_creator = Some(instructions_sysvar_or_creator);
450 self
451 }
452 #[inline(always)]
453 pub fn mint_authority(
454 &mut self,
455 mint_authority: &'b solana_account_info::AccountInfo<'a>,
456 ) -> &mut Self {
457 self.instruction.mint_authority = Some(mint_authority);
458 self
459 }
460 #[inline(always)]
461 pub fn payer(&mut self, payer: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
462 self.instruction.payer = Some(payer);
463 self
464 }
465 #[inline(always)]
466 pub fn mint_account(
467 &mut self,
468 mint_account: &'b solana_account_info::AccountInfo<'a>,
469 ) -> &mut Self {
470 self.instruction.mint_account = Some(mint_account);
471 self
472 }
473 #[inline(always)]
474 pub fn token_program(
475 &mut self,
476 token_program: &'b solana_account_info::AccountInfo<'a>,
477 ) -> &mut Self {
478 self.instruction.token_program = Some(token_program);
479 self
480 }
481 #[inline(always)]
482 pub fn system_program(
483 &mut self,
484 system_program: &'b solana_account_info::AccountInfo<'a>,
485 ) -> &mut Self {
486 self.instruction.system_program = Some(system_program);
487 self
488 }
489 #[inline(always)]
490 pub fn update_metadata_args(&mut self, update_metadata_args: UpdateMetadataArgs) -> &mut Self {
491 self.instruction.update_metadata_args = Some(update_metadata_args);
492 self
493 }
494 #[inline(always)]
496 pub fn add_remaining_account(
497 &mut self,
498 account: &'b solana_account_info::AccountInfo<'a>,
499 is_writable: bool,
500 is_signer: bool,
501 ) -> &mut Self {
502 self.instruction
503 .__remaining_accounts
504 .push((account, is_writable, is_signer));
505 self
506 }
507 #[inline(always)]
512 pub fn add_remaining_accounts(
513 &mut self,
514 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
515 ) -> &mut Self {
516 self.instruction
517 .__remaining_accounts
518 .extend_from_slice(accounts);
519 self
520 }
521 #[inline(always)]
522 pub fn invoke(&self) -> solana_program_error::ProgramResult {
523 self.invoke_signed(&[])
524 }
525 #[allow(clippy::clone_on_copy)]
526 #[allow(clippy::vec_init_then_push)]
527 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
528 let args = UpdateMetadataInstructionArgs {
529 update_metadata_args: self
530 .instruction
531 .update_metadata_args
532 .clone()
533 .expect("update_metadata_args is not set"),
534 };
535 let instruction = UpdateMetadataCpi {
536 __program: self.instruction.__program,
537
538 mint: self.instruction.mint.expect("mint is not set"),
539
540 verification_config_or_mint_authority: self
541 .instruction
542 .verification_config_or_mint_authority
543 .expect("verification_config_or_mint_authority is not set"),
544
545 instructions_sysvar_or_creator: self
546 .instruction
547 .instructions_sysvar_or_creator
548 .expect("instructions_sysvar_or_creator is not set"),
549
550 mint_authority: self
551 .instruction
552 .mint_authority
553 .expect("mint_authority is not set"),
554
555 payer: self.instruction.payer.expect("payer is not set"),
556
557 mint_account: self
558 .instruction
559 .mint_account
560 .expect("mint_account is not set"),
561
562 token_program: self
563 .instruction
564 .token_program
565 .expect("token_program is not set"),
566
567 system_program: self
568 .instruction
569 .system_program
570 .expect("system_program is not set"),
571 __args: args,
572 };
573 instruction.invoke_signed_with_remaining_accounts(
574 signers_seeds,
575 &self.instruction.__remaining_accounts,
576 )
577 }
578}
579
580#[derive(Clone, Debug)]
581struct UpdateMetadataCpiBuilderInstruction<'a, 'b> {
582 __program: &'b solana_account_info::AccountInfo<'a>,
583 mint: Option<&'b solana_account_info::AccountInfo<'a>>,
584 verification_config_or_mint_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
585 instructions_sysvar_or_creator: Option<&'b solana_account_info::AccountInfo<'a>>,
586 mint_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
587 payer: Option<&'b solana_account_info::AccountInfo<'a>>,
588 mint_account: Option<&'b solana_account_info::AccountInfo<'a>>,
589 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
590 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
591 update_metadata_args: Option<UpdateMetadataArgs>,
592 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
594}