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