1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct CreateEscrowAccount {
13 pub escrow: solana_program::pubkey::Pubkey,
15 pub metadata: solana_program::pubkey::Pubkey,
17 pub mint: solana_program::pubkey::Pubkey,
19 pub token_account: solana_program::pubkey::Pubkey,
21 pub edition: solana_program::pubkey::Pubkey,
23 pub payer: solana_program::pubkey::Pubkey,
25 pub system_program: solana_program::pubkey::Pubkey,
27 pub sysvar_instructions: solana_program::pubkey::Pubkey,
29 pub authority: Option<solana_program::pubkey::Pubkey>,
31}
32
33impl CreateEscrowAccount {
34 pub fn instruction(&self) -> solana_program::instruction::Instruction {
35 self.instruction_with_remaining_accounts(&[])
36 }
37 #[allow(clippy::vec_init_then_push)]
38 pub fn instruction_with_remaining_accounts(
39 &self,
40 remaining_accounts: &[solana_program::instruction::AccountMeta],
41 ) -> solana_program::instruction::Instruction {
42 let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
43 accounts.push(solana_program::instruction::AccountMeta::new(
44 self.escrow,
45 false,
46 ));
47 accounts.push(solana_program::instruction::AccountMeta::new(
48 self.metadata,
49 false,
50 ));
51 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
52 self.mint, false,
53 ));
54 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
55 self.token_account,
56 false,
57 ));
58 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
59 self.edition,
60 false,
61 ));
62 accounts.push(solana_program::instruction::AccountMeta::new(
63 self.payer, true,
64 ));
65 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
66 self.system_program,
67 false,
68 ));
69 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
70 self.sysvar_instructions,
71 false,
72 ));
73 if let Some(authority) = self.authority {
74 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
75 authority, true,
76 ));
77 }
78 accounts.extend_from_slice(remaining_accounts);
79 let data = CreateEscrowAccountInstructionData::new()
80 .try_to_vec()
81 .unwrap();
82
83 solana_program::instruction::Instruction {
84 program_id: crate::MPL_TOKEN_METADATA_ID,
85 accounts,
86 data,
87 }
88 }
89}
90
91#[derive(BorshDeserialize, BorshSerialize)]
92struct CreateEscrowAccountInstructionData {
93 discriminator: u8,
94}
95
96impl CreateEscrowAccountInstructionData {
97 fn new() -> Self {
98 Self { discriminator: 38 }
99 }
100}
101
102#[derive(Default)]
116pub struct CreateEscrowAccountBuilder {
117 escrow: Option<solana_program::pubkey::Pubkey>,
118 metadata: Option<solana_program::pubkey::Pubkey>,
119 mint: Option<solana_program::pubkey::Pubkey>,
120 token_account: Option<solana_program::pubkey::Pubkey>,
121 edition: Option<solana_program::pubkey::Pubkey>,
122 payer: Option<solana_program::pubkey::Pubkey>,
123 system_program: Option<solana_program::pubkey::Pubkey>,
124 sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
125 authority: Option<solana_program::pubkey::Pubkey>,
126 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
127}
128
129impl CreateEscrowAccountBuilder {
130 pub fn new() -> Self {
131 Self::default()
132 }
133 #[inline(always)]
135 pub fn escrow(&mut self, escrow: solana_program::pubkey::Pubkey) -> &mut Self {
136 self.escrow = Some(escrow);
137 self
138 }
139 #[inline(always)]
141 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
142 self.metadata = Some(metadata);
143 self
144 }
145 #[inline(always)]
147 pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
148 self.mint = Some(mint);
149 self
150 }
151 #[inline(always)]
153 pub fn token_account(&mut self, token_account: solana_program::pubkey::Pubkey) -> &mut Self {
154 self.token_account = Some(token_account);
155 self
156 }
157 #[inline(always)]
159 pub fn edition(&mut self, edition: solana_program::pubkey::Pubkey) -> &mut Self {
160 self.edition = Some(edition);
161 self
162 }
163 #[inline(always)]
165 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
166 self.payer = Some(payer);
167 self
168 }
169 #[inline(always)]
172 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
173 self.system_program = Some(system_program);
174 self
175 }
176 #[inline(always)]
179 pub fn sysvar_instructions(
180 &mut self,
181 sysvar_instructions: solana_program::pubkey::Pubkey,
182 ) -> &mut Self {
183 self.sysvar_instructions = Some(sysvar_instructions);
184 self
185 }
186 #[inline(always)]
189 pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
190 self.authority = authority;
191 self
192 }
193 #[inline(always)]
195 pub fn add_remaining_account(
196 &mut self,
197 account: solana_program::instruction::AccountMeta,
198 ) -> &mut Self {
199 self.__remaining_accounts.push(account);
200 self
201 }
202 #[inline(always)]
204 pub fn add_remaining_accounts(
205 &mut self,
206 accounts: &[solana_program::instruction::AccountMeta],
207 ) -> &mut Self {
208 self.__remaining_accounts.extend_from_slice(accounts);
209 self
210 }
211 #[allow(clippy::clone_on_copy)]
212 pub fn instruction(&self) -> solana_program::instruction::Instruction {
213 let accounts = CreateEscrowAccount {
214 escrow: self.escrow.expect("escrow is not set"),
215 metadata: self.metadata.expect("metadata is not set"),
216 mint: self.mint.expect("mint is not set"),
217 token_account: self.token_account.expect("token_account is not set"),
218 edition: self.edition.expect("edition is not set"),
219 payer: self.payer.expect("payer is not set"),
220 system_program: self
221 .system_program
222 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
223 sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
224 "Sysvar1nstructions1111111111111111111111111"
225 )),
226 authority: self.authority,
227 };
228
229 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
230 }
231}
232
233pub struct CreateEscrowAccountCpiAccounts<'a, 'b> {
235 pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
237 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
239 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
241 pub token_account: &'b solana_program::account_info::AccountInfo<'a>,
243 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
245 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
247 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
249 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
251 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
253}
254
255pub struct CreateEscrowAccountCpi<'a, 'b> {
257 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
259 pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
261 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
263 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
265 pub token_account: &'b solana_program::account_info::AccountInfo<'a>,
267 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
269 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
271 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
273 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
275 pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
277}
278
279impl<'a, 'b> CreateEscrowAccountCpi<'a, 'b> {
280 pub fn new(
281 program: &'b solana_program::account_info::AccountInfo<'a>,
282 accounts: CreateEscrowAccountCpiAccounts<'a, 'b>,
283 ) -> Self {
284 Self {
285 __program: program,
286 escrow: accounts.escrow,
287 metadata: accounts.metadata,
288 mint: accounts.mint,
289 token_account: accounts.token_account,
290 edition: accounts.edition,
291 payer: accounts.payer,
292 system_program: accounts.system_program,
293 sysvar_instructions: accounts.sysvar_instructions,
294 authority: accounts.authority,
295 }
296 }
297 #[inline(always)]
298 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
299 self.invoke_signed_with_remaining_accounts(&[], &[])
300 }
301 #[inline(always)]
302 pub fn invoke_with_remaining_accounts(
303 &self,
304 remaining_accounts: &[(
305 &'b solana_program::account_info::AccountInfo<'a>,
306 bool,
307 bool,
308 )],
309 ) -> solana_program::entrypoint::ProgramResult {
310 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
311 }
312 #[inline(always)]
313 pub fn invoke_signed(
314 &self,
315 signers_seeds: &[&[&[u8]]],
316 ) -> solana_program::entrypoint::ProgramResult {
317 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
318 }
319 #[allow(clippy::clone_on_copy)]
320 #[allow(clippy::vec_init_then_push)]
321 pub fn invoke_signed_with_remaining_accounts(
322 &self,
323 signers_seeds: &[&[&[u8]]],
324 remaining_accounts: &[(
325 &'b solana_program::account_info::AccountInfo<'a>,
326 bool,
327 bool,
328 )],
329 ) -> solana_program::entrypoint::ProgramResult {
330 let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
331 accounts.push(solana_program::instruction::AccountMeta::new(
332 *self.escrow.key,
333 false,
334 ));
335 accounts.push(solana_program::instruction::AccountMeta::new(
336 *self.metadata.key,
337 false,
338 ));
339 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
340 *self.mint.key,
341 false,
342 ));
343 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
344 *self.token_account.key,
345 false,
346 ));
347 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
348 *self.edition.key,
349 false,
350 ));
351 accounts.push(solana_program::instruction::AccountMeta::new(
352 *self.payer.key,
353 true,
354 ));
355 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
356 *self.system_program.key,
357 false,
358 ));
359 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
360 *self.sysvar_instructions.key,
361 false,
362 ));
363 if let Some(authority) = self.authority {
364 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
365 *authority.key,
366 true,
367 ));
368 }
369 remaining_accounts.iter().for_each(|remaining_account| {
370 accounts.push(solana_program::instruction::AccountMeta {
371 pubkey: *remaining_account.0.key,
372 is_signer: remaining_account.1,
373 is_writable: remaining_account.2,
374 })
375 });
376 let data = CreateEscrowAccountInstructionData::new()
377 .try_to_vec()
378 .unwrap();
379
380 let instruction = solana_program::instruction::Instruction {
381 program_id: crate::MPL_TOKEN_METADATA_ID,
382 accounts,
383 data,
384 };
385 let mut account_infos = Vec::with_capacity(9 + 1 + remaining_accounts.len());
386 account_infos.push(self.__program.clone());
387 account_infos.push(self.escrow.clone());
388 account_infos.push(self.metadata.clone());
389 account_infos.push(self.mint.clone());
390 account_infos.push(self.token_account.clone());
391 account_infos.push(self.edition.clone());
392 account_infos.push(self.payer.clone());
393 account_infos.push(self.system_program.clone());
394 account_infos.push(self.sysvar_instructions.clone());
395 if let Some(authority) = self.authority {
396 account_infos.push(authority.clone());
397 }
398 remaining_accounts
399 .iter()
400 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
401
402 if signers_seeds.is_empty() {
403 solana_program::program::invoke(&instruction, &account_infos)
404 } else {
405 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
406 }
407 }
408}
409
410pub struct CreateEscrowAccountCpiBuilder<'a, 'b> {
424 instruction: Box<CreateEscrowAccountCpiBuilderInstruction<'a, 'b>>,
425}
426
427impl<'a, 'b> CreateEscrowAccountCpiBuilder<'a, 'b> {
428 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
429 let instruction = Box::new(CreateEscrowAccountCpiBuilderInstruction {
430 __program: program,
431 escrow: None,
432 metadata: None,
433 mint: None,
434 token_account: None,
435 edition: None,
436 payer: None,
437 system_program: None,
438 sysvar_instructions: None,
439 authority: None,
440 __remaining_accounts: Vec::new(),
441 });
442 Self { instruction }
443 }
444 #[inline(always)]
446 pub fn escrow(
447 &mut self,
448 escrow: &'b solana_program::account_info::AccountInfo<'a>,
449 ) -> &mut Self {
450 self.instruction.escrow = Some(escrow);
451 self
452 }
453 #[inline(always)]
455 pub fn metadata(
456 &mut self,
457 metadata: &'b solana_program::account_info::AccountInfo<'a>,
458 ) -> &mut Self {
459 self.instruction.metadata = Some(metadata);
460 self
461 }
462 #[inline(always)]
464 pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
465 self.instruction.mint = Some(mint);
466 self
467 }
468 #[inline(always)]
470 pub fn token_account(
471 &mut self,
472 token_account: &'b solana_program::account_info::AccountInfo<'a>,
473 ) -> &mut Self {
474 self.instruction.token_account = Some(token_account);
475 self
476 }
477 #[inline(always)]
479 pub fn edition(
480 &mut self,
481 edition: &'b solana_program::account_info::AccountInfo<'a>,
482 ) -> &mut Self {
483 self.instruction.edition = Some(edition);
484 self
485 }
486 #[inline(always)]
488 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
489 self.instruction.payer = Some(payer);
490 self
491 }
492 #[inline(always)]
494 pub fn system_program(
495 &mut self,
496 system_program: &'b solana_program::account_info::AccountInfo<'a>,
497 ) -> &mut Self {
498 self.instruction.system_program = Some(system_program);
499 self
500 }
501 #[inline(always)]
503 pub fn sysvar_instructions(
504 &mut self,
505 sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
506 ) -> &mut Self {
507 self.instruction.sysvar_instructions = Some(sysvar_instructions);
508 self
509 }
510 #[inline(always)]
513 pub fn authority(
514 &mut self,
515 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
516 ) -> &mut Self {
517 self.instruction.authority = authority;
518 self
519 }
520 #[inline(always)]
522 pub fn add_remaining_account(
523 &mut self,
524 account: &'b solana_program::account_info::AccountInfo<'a>,
525 is_writable: bool,
526 is_signer: bool,
527 ) -> &mut Self {
528 self.instruction
529 .__remaining_accounts
530 .push((account, is_writable, is_signer));
531 self
532 }
533 #[inline(always)]
538 pub fn add_remaining_accounts(
539 &mut self,
540 accounts: &[(
541 &'b solana_program::account_info::AccountInfo<'a>,
542 bool,
543 bool,
544 )],
545 ) -> &mut Self {
546 self.instruction
547 .__remaining_accounts
548 .extend_from_slice(accounts);
549 self
550 }
551 #[inline(always)]
552 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
553 self.invoke_signed(&[])
554 }
555 #[allow(clippy::clone_on_copy)]
556 #[allow(clippy::vec_init_then_push)]
557 pub fn invoke_signed(
558 &self,
559 signers_seeds: &[&[&[u8]]],
560 ) -> solana_program::entrypoint::ProgramResult {
561 let instruction = CreateEscrowAccountCpi {
562 __program: self.instruction.__program,
563
564 escrow: self.instruction.escrow.expect("escrow is not set"),
565
566 metadata: self.instruction.metadata.expect("metadata is not set"),
567
568 mint: self.instruction.mint.expect("mint is not set"),
569
570 token_account: self
571 .instruction
572 .token_account
573 .expect("token_account is not set"),
574
575 edition: self.instruction.edition.expect("edition is not set"),
576
577 payer: self.instruction.payer.expect("payer is not set"),
578
579 system_program: self
580 .instruction
581 .system_program
582 .expect("system_program is not set"),
583
584 sysvar_instructions: self
585 .instruction
586 .sysvar_instructions
587 .expect("sysvar_instructions is not set"),
588
589 authority: self.instruction.authority,
590 };
591 instruction.invoke_signed_with_remaining_accounts(
592 signers_seeds,
593 &self.instruction.__remaining_accounts,
594 )
595 }
596}
597
598struct CreateEscrowAccountCpiBuilderInstruction<'a, 'b> {
599 __program: &'b solana_program::account_info::AccountInfo<'a>,
600 escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
601 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
602 mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
603 token_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
604 edition: 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 sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
608 authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
609 __remaining_accounts: Vec<(
611 &'b solana_program::account_info::AccountInfo<'a>,
612 bool,
613 bool,
614 )>,
615}