1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct CloseEscrowAccount {
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}
30
31impl CloseEscrowAccount {
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(8 + remaining_accounts.len());
41 accounts.push(solana_program::instruction::AccountMeta::new(
42 self.escrow,
43 false,
44 ));
45 accounts.push(solana_program::instruction::AccountMeta::new(
46 self.metadata,
47 false,
48 ));
49 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
50 self.mint, false,
51 ));
52 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53 self.token_account,
54 false,
55 ));
56 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
57 self.edition,
58 false,
59 ));
60 accounts.push(solana_program::instruction::AccountMeta::new(
61 self.payer, true,
62 ));
63 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
64 self.system_program,
65 false,
66 ));
67 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
68 self.sysvar_instructions,
69 false,
70 ));
71 accounts.extend_from_slice(remaining_accounts);
72 let data = CloseEscrowAccountInstructionData::new()
73 .try_to_vec()
74 .unwrap();
75
76 solana_program::instruction::Instruction {
77 program_id: crate::MPL_TOKEN_METADATA_ID,
78 accounts,
79 data,
80 }
81 }
82}
83
84#[derive(BorshDeserialize, BorshSerialize)]
85struct CloseEscrowAccountInstructionData {
86 discriminator: u8,
87}
88
89impl CloseEscrowAccountInstructionData {
90 fn new() -> Self {
91 Self { discriminator: 39 }
92 }
93}
94
95#[derive(Default)]
108pub struct CloseEscrowAccountBuilder {
109 escrow: Option<solana_program::pubkey::Pubkey>,
110 metadata: Option<solana_program::pubkey::Pubkey>,
111 mint: Option<solana_program::pubkey::Pubkey>,
112 token_account: Option<solana_program::pubkey::Pubkey>,
113 edition: Option<solana_program::pubkey::Pubkey>,
114 payer: Option<solana_program::pubkey::Pubkey>,
115 system_program: Option<solana_program::pubkey::Pubkey>,
116 sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
117 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
118}
119
120impl CloseEscrowAccountBuilder {
121 pub fn new() -> Self {
122 Self::default()
123 }
124 #[inline(always)]
126 pub fn escrow(&mut self, escrow: solana_program::pubkey::Pubkey) -> &mut Self {
127 self.escrow = Some(escrow);
128 self
129 }
130 #[inline(always)]
132 pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
133 self.metadata = Some(metadata);
134 self
135 }
136 #[inline(always)]
138 pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
139 self.mint = Some(mint);
140 self
141 }
142 #[inline(always)]
144 pub fn token_account(&mut self, token_account: solana_program::pubkey::Pubkey) -> &mut Self {
145 self.token_account = Some(token_account);
146 self
147 }
148 #[inline(always)]
150 pub fn edition(&mut self, edition: solana_program::pubkey::Pubkey) -> &mut Self {
151 self.edition = Some(edition);
152 self
153 }
154 #[inline(always)]
156 pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
157 self.payer = Some(payer);
158 self
159 }
160 #[inline(always)]
163 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
164 self.system_program = Some(system_program);
165 self
166 }
167 #[inline(always)]
170 pub fn sysvar_instructions(
171 &mut self,
172 sysvar_instructions: solana_program::pubkey::Pubkey,
173 ) -> &mut Self {
174 self.sysvar_instructions = Some(sysvar_instructions);
175 self
176 }
177 #[inline(always)]
179 pub fn add_remaining_account(
180 &mut self,
181 account: solana_program::instruction::AccountMeta,
182 ) -> &mut Self {
183 self.__remaining_accounts.push(account);
184 self
185 }
186 #[inline(always)]
188 pub fn add_remaining_accounts(
189 &mut self,
190 accounts: &[solana_program::instruction::AccountMeta],
191 ) -> &mut Self {
192 self.__remaining_accounts.extend_from_slice(accounts);
193 self
194 }
195 #[allow(clippy::clone_on_copy)]
196 pub fn instruction(&self) -> solana_program::instruction::Instruction {
197 let accounts = CloseEscrowAccount {
198 escrow: self.escrow.expect("escrow is not set"),
199 metadata: self.metadata.expect("metadata is not set"),
200 mint: self.mint.expect("mint is not set"),
201 token_account: self.token_account.expect("token_account is not set"),
202 edition: self.edition.expect("edition is not set"),
203 payer: self.payer.expect("payer is not set"),
204 system_program: self
205 .system_program
206 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
207 sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
208 "Sysvar1nstructions1111111111111111111111111"
209 )),
210 };
211
212 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
213 }
214}
215
216pub struct CloseEscrowAccountCpiAccounts<'a, 'b> {
218 pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
220 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
222 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
224 pub token_account: &'b solana_program::account_info::AccountInfo<'a>,
226 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
228 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
230 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
232 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
234}
235
236pub struct CloseEscrowAccountCpi<'a, 'b> {
238 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
240 pub escrow: &'b solana_program::account_info::AccountInfo<'a>,
242 pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
244 pub mint: &'b solana_program::account_info::AccountInfo<'a>,
246 pub token_account: &'b solana_program::account_info::AccountInfo<'a>,
248 pub edition: &'b solana_program::account_info::AccountInfo<'a>,
250 pub payer: &'b solana_program::account_info::AccountInfo<'a>,
252 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
254 pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
256}
257
258impl<'a, 'b> CloseEscrowAccountCpi<'a, 'b> {
259 pub fn new(
260 program: &'b solana_program::account_info::AccountInfo<'a>,
261 accounts: CloseEscrowAccountCpiAccounts<'a, 'b>,
262 ) -> Self {
263 Self {
264 __program: program,
265 escrow: accounts.escrow,
266 metadata: accounts.metadata,
267 mint: accounts.mint,
268 token_account: accounts.token_account,
269 edition: accounts.edition,
270 payer: accounts.payer,
271 system_program: accounts.system_program,
272 sysvar_instructions: accounts.sysvar_instructions,
273 }
274 }
275 #[inline(always)]
276 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
277 self.invoke_signed_with_remaining_accounts(&[], &[])
278 }
279 #[inline(always)]
280 pub fn invoke_with_remaining_accounts(
281 &self,
282 remaining_accounts: &[(
283 &'b solana_program::account_info::AccountInfo<'a>,
284 bool,
285 bool,
286 )],
287 ) -> solana_program::entrypoint::ProgramResult {
288 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
289 }
290 #[inline(always)]
291 pub fn invoke_signed(
292 &self,
293 signers_seeds: &[&[&[u8]]],
294 ) -> solana_program::entrypoint::ProgramResult {
295 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
296 }
297 #[allow(clippy::clone_on_copy)]
298 #[allow(clippy::vec_init_then_push)]
299 pub fn invoke_signed_with_remaining_accounts(
300 &self,
301 signers_seeds: &[&[&[u8]]],
302 remaining_accounts: &[(
303 &'b solana_program::account_info::AccountInfo<'a>,
304 bool,
305 bool,
306 )],
307 ) -> solana_program::entrypoint::ProgramResult {
308 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
309 accounts.push(solana_program::instruction::AccountMeta::new(
310 *self.escrow.key,
311 false,
312 ));
313 accounts.push(solana_program::instruction::AccountMeta::new(
314 *self.metadata.key,
315 false,
316 ));
317 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
318 *self.mint.key,
319 false,
320 ));
321 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
322 *self.token_account.key,
323 false,
324 ));
325 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
326 *self.edition.key,
327 false,
328 ));
329 accounts.push(solana_program::instruction::AccountMeta::new(
330 *self.payer.key,
331 true,
332 ));
333 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
334 *self.system_program.key,
335 false,
336 ));
337 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
338 *self.sysvar_instructions.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_signer: remaining_account.1,
345 is_writable: remaining_account.2,
346 })
347 });
348 let data = CloseEscrowAccountInstructionData::new()
349 .try_to_vec()
350 .unwrap();
351
352 let instruction = solana_program::instruction::Instruction {
353 program_id: crate::MPL_TOKEN_METADATA_ID,
354 accounts,
355 data,
356 };
357 let mut account_infos = Vec::with_capacity(8 + 1 + remaining_accounts.len());
358 account_infos.push(self.__program.clone());
359 account_infos.push(self.escrow.clone());
360 account_infos.push(self.metadata.clone());
361 account_infos.push(self.mint.clone());
362 account_infos.push(self.token_account.clone());
363 account_infos.push(self.edition.clone());
364 account_infos.push(self.payer.clone());
365 account_infos.push(self.system_program.clone());
366 account_infos.push(self.sysvar_instructions.clone());
367 remaining_accounts
368 .iter()
369 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
370
371 if signers_seeds.is_empty() {
372 solana_program::program::invoke(&instruction, &account_infos)
373 } else {
374 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
375 }
376 }
377}
378
379pub struct CloseEscrowAccountCpiBuilder<'a, 'b> {
392 instruction: Box<CloseEscrowAccountCpiBuilderInstruction<'a, 'b>>,
393}
394
395impl<'a, 'b> CloseEscrowAccountCpiBuilder<'a, 'b> {
396 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
397 let instruction = Box::new(CloseEscrowAccountCpiBuilderInstruction {
398 __program: program,
399 escrow: None,
400 metadata: None,
401 mint: None,
402 token_account: None,
403 edition: None,
404 payer: None,
405 system_program: None,
406 sysvar_instructions: None,
407 __remaining_accounts: Vec::new(),
408 });
409 Self { instruction }
410 }
411 #[inline(always)]
413 pub fn escrow(
414 &mut self,
415 escrow: &'b solana_program::account_info::AccountInfo<'a>,
416 ) -> &mut Self {
417 self.instruction.escrow = Some(escrow);
418 self
419 }
420 #[inline(always)]
422 pub fn metadata(
423 &mut self,
424 metadata: &'b solana_program::account_info::AccountInfo<'a>,
425 ) -> &mut Self {
426 self.instruction.metadata = Some(metadata);
427 self
428 }
429 #[inline(always)]
431 pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
432 self.instruction.mint = Some(mint);
433 self
434 }
435 #[inline(always)]
437 pub fn token_account(
438 &mut self,
439 token_account: &'b solana_program::account_info::AccountInfo<'a>,
440 ) -> &mut Self {
441 self.instruction.token_account = Some(token_account);
442 self
443 }
444 #[inline(always)]
446 pub fn edition(
447 &mut self,
448 edition: &'b solana_program::account_info::AccountInfo<'a>,
449 ) -> &mut Self {
450 self.instruction.edition = Some(edition);
451 self
452 }
453 #[inline(always)]
455 pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
456 self.instruction.payer = Some(payer);
457 self
458 }
459 #[inline(always)]
461 pub fn system_program(
462 &mut self,
463 system_program: &'b solana_program::account_info::AccountInfo<'a>,
464 ) -> &mut Self {
465 self.instruction.system_program = Some(system_program);
466 self
467 }
468 #[inline(always)]
470 pub fn sysvar_instructions(
471 &mut self,
472 sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
473 ) -> &mut Self {
474 self.instruction.sysvar_instructions = Some(sysvar_instructions);
475 self
476 }
477 #[inline(always)]
479 pub fn add_remaining_account(
480 &mut self,
481 account: &'b solana_program::account_info::AccountInfo<'a>,
482 is_writable: bool,
483 is_signer: bool,
484 ) -> &mut Self {
485 self.instruction
486 .__remaining_accounts
487 .push((account, is_writable, is_signer));
488 self
489 }
490 #[inline(always)]
495 pub fn add_remaining_accounts(
496 &mut self,
497 accounts: &[(
498 &'b solana_program::account_info::AccountInfo<'a>,
499 bool,
500 bool,
501 )],
502 ) -> &mut Self {
503 self.instruction
504 .__remaining_accounts
505 .extend_from_slice(accounts);
506 self
507 }
508 #[inline(always)]
509 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
510 self.invoke_signed(&[])
511 }
512 #[allow(clippy::clone_on_copy)]
513 #[allow(clippy::vec_init_then_push)]
514 pub fn invoke_signed(
515 &self,
516 signers_seeds: &[&[&[u8]]],
517 ) -> solana_program::entrypoint::ProgramResult {
518 let instruction = CloseEscrowAccountCpi {
519 __program: self.instruction.__program,
520
521 escrow: self.instruction.escrow.expect("escrow is not set"),
522
523 metadata: self.instruction.metadata.expect("metadata is not set"),
524
525 mint: self.instruction.mint.expect("mint is not set"),
526
527 token_account: self
528 .instruction
529 .token_account
530 .expect("token_account is not set"),
531
532 edition: self.instruction.edition.expect("edition is not set"),
533
534 payer: self.instruction.payer.expect("payer is not set"),
535
536 system_program: self
537 .instruction
538 .system_program
539 .expect("system_program is not set"),
540
541 sysvar_instructions: self
542 .instruction
543 .sysvar_instructions
544 .expect("sysvar_instructions is not set"),
545 };
546 instruction.invoke_signed_with_remaining_accounts(
547 signers_seeds,
548 &self.instruction.__remaining_accounts,
549 )
550 }
551}
552
553struct CloseEscrowAccountCpiBuilderInstruction<'a, 'b> {
554 __program: &'b solana_program::account_info::AccountInfo<'a>,
555 escrow: Option<&'b solana_program::account_info::AccountInfo<'a>>,
556 metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
557 mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
558 token_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
559 edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
560 payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
561 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
562 sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
563 __remaining_accounts: Vec<(
565 &'b solana_program::account_info::AccountInfo<'a>,
566 bool,
567 bool,
568 )>,
569}