1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct WithdrawMarginAccountCpiTamm {
13 pub margin_account: solana_program::pubkey::Pubkey,
14
15 pub pool: solana_program::pubkey::Pubkey,
16
17 pub owner: solana_program::pubkey::Pubkey,
18
19 pub destination: solana_program::pubkey::Pubkey,
20
21 pub system_program: solana_program::pubkey::Pubkey,
22}
23
24impl WithdrawMarginAccountCpiTamm {
25 pub fn instruction(
26 &self,
27 args: WithdrawMarginAccountCpiTammInstructionArgs,
28 ) -> solana_program::instruction::Instruction {
29 self.instruction_with_remaining_accounts(args, &[])
30 }
31 #[allow(clippy::vec_init_then_push)]
32 pub fn instruction_with_remaining_accounts(
33 &self,
34 args: WithdrawMarginAccountCpiTammInstructionArgs,
35 remaining_accounts: &[solana_program::instruction::AccountMeta],
36 ) -> solana_program::instruction::Instruction {
37 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
38 accounts.push(solana_program::instruction::AccountMeta::new(
39 self.margin_account,
40 false,
41 ));
42 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
43 self.pool, true,
44 ));
45 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
46 self.owner, false,
47 ));
48 accounts.push(solana_program::instruction::AccountMeta::new(
49 self.destination,
50 false,
51 ));
52 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
53 self.system_program,
54 false,
55 ));
56 accounts.extend_from_slice(remaining_accounts);
57 let mut data = WithdrawMarginAccountCpiTammInstructionData::new()
58 .try_to_vec()
59 .unwrap();
60 let mut args = args.try_to_vec().unwrap();
61 data.append(&mut args);
62
63 solana_program::instruction::Instruction {
64 program_id: crate::TENSOR_ESCROW_ID,
65 accounts,
66 data,
67 }
68 }
69}
70
71#[derive(BorshDeserialize, BorshSerialize)]
72pub struct WithdrawMarginAccountCpiTammInstructionData {
73 discriminator: [u8; 8],
74}
75
76impl WithdrawMarginAccountCpiTammInstructionData {
77 pub fn new() -> Self {
78 Self {
79 discriminator: [35, 89, 16, 235, 226, 89, 248, 45],
80 }
81 }
82}
83
84impl Default for WithdrawMarginAccountCpiTammInstructionData {
85 fn default() -> Self {
86 Self::new()
87 }
88}
89
90#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
91#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
92pub struct WithdrawMarginAccountCpiTammInstructionArgs {
93 pub bump: u8,
94 pub pool_id: [u8; 32],
95 pub lamports: u64,
96}
97
98#[derive(Clone, Debug, Default)]
108pub struct WithdrawMarginAccountCpiTammBuilder {
109 margin_account: Option<solana_program::pubkey::Pubkey>,
110 pool: Option<solana_program::pubkey::Pubkey>,
111 owner: Option<solana_program::pubkey::Pubkey>,
112 destination: Option<solana_program::pubkey::Pubkey>,
113 system_program: Option<solana_program::pubkey::Pubkey>,
114 bump: Option<u8>,
115 pool_id: Option<[u8; 32]>,
116 lamports: Option<u64>,
117 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
118}
119
120impl WithdrawMarginAccountCpiTammBuilder {
121 pub fn new() -> Self {
122 Self::default()
123 }
124 #[inline(always)]
125 pub fn margin_account(&mut self, margin_account: solana_program::pubkey::Pubkey) -> &mut Self {
126 self.margin_account = Some(margin_account);
127 self
128 }
129 #[inline(always)]
130 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
131 self.pool = Some(pool);
132 self
133 }
134 #[inline(always)]
135 pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
136 self.owner = Some(owner);
137 self
138 }
139 #[inline(always)]
140 pub fn destination(&mut self, destination: solana_program::pubkey::Pubkey) -> &mut Self {
141 self.destination = Some(destination);
142 self
143 }
144 #[inline(always)]
146 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
147 self.system_program = Some(system_program);
148 self
149 }
150 #[inline(always)]
151 pub fn bump(&mut self, bump: u8) -> &mut Self {
152 self.bump = Some(bump);
153 self
154 }
155 #[inline(always)]
156 pub fn pool_id(&mut self, pool_id: [u8; 32]) -> &mut Self {
157 self.pool_id = Some(pool_id);
158 self
159 }
160 #[inline(always)]
161 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
162 self.lamports = Some(lamports);
163 self
164 }
165 #[inline(always)]
167 pub fn add_remaining_account(
168 &mut self,
169 account: solana_program::instruction::AccountMeta,
170 ) -> &mut Self {
171 self.__remaining_accounts.push(account);
172 self
173 }
174 #[inline(always)]
176 pub fn add_remaining_accounts(
177 &mut self,
178 accounts: &[solana_program::instruction::AccountMeta],
179 ) -> &mut Self {
180 self.__remaining_accounts.extend_from_slice(accounts);
181 self
182 }
183 #[allow(clippy::clone_on_copy)]
184 pub fn instruction(&self) -> solana_program::instruction::Instruction {
185 let accounts = WithdrawMarginAccountCpiTamm {
186 margin_account: self.margin_account.expect("margin_account is not set"),
187 pool: self.pool.expect("pool is not set"),
188 owner: self.owner.expect("owner is not set"),
189 destination: self.destination.expect("destination is not set"),
190 system_program: self
191 .system_program
192 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
193 };
194 let args = WithdrawMarginAccountCpiTammInstructionArgs {
195 bump: self.bump.clone().expect("bump is not set"),
196 pool_id: self.pool_id.clone().expect("pool_id is not set"),
197 lamports: self.lamports.clone().expect("lamports is not set"),
198 };
199
200 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
201 }
202}
203
204pub struct WithdrawMarginAccountCpiTammCpiAccounts<'a, 'b> {
206 pub margin_account: &'b solana_program::account_info::AccountInfo<'a>,
207
208 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
209
210 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
211
212 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
213
214 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
215}
216
217pub struct WithdrawMarginAccountCpiTammCpi<'a, 'b> {
219 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
221
222 pub margin_account: &'b solana_program::account_info::AccountInfo<'a>,
223
224 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
225
226 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
227
228 pub destination: &'b solana_program::account_info::AccountInfo<'a>,
229
230 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
231 pub __args: WithdrawMarginAccountCpiTammInstructionArgs,
233}
234
235impl<'a, 'b> WithdrawMarginAccountCpiTammCpi<'a, 'b> {
236 pub fn new(
237 program: &'b solana_program::account_info::AccountInfo<'a>,
238 accounts: WithdrawMarginAccountCpiTammCpiAccounts<'a, 'b>,
239 args: WithdrawMarginAccountCpiTammInstructionArgs,
240 ) -> Self {
241 Self {
242 __program: program,
243 margin_account: accounts.margin_account,
244 pool: accounts.pool,
245 owner: accounts.owner,
246 destination: accounts.destination,
247 system_program: accounts.system_program,
248 __args: args,
249 }
250 }
251 #[inline(always)]
252 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
253 self.invoke_signed_with_remaining_accounts(&[], &[])
254 }
255 #[inline(always)]
256 pub fn invoke_with_remaining_accounts(
257 &self,
258 remaining_accounts: &[(
259 &'b solana_program::account_info::AccountInfo<'a>,
260 bool,
261 bool,
262 )],
263 ) -> solana_program::entrypoint::ProgramResult {
264 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
265 }
266 #[inline(always)]
267 pub fn invoke_signed(
268 &self,
269 signers_seeds: &[&[&[u8]]],
270 ) -> solana_program::entrypoint::ProgramResult {
271 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
272 }
273 #[allow(clippy::clone_on_copy)]
274 #[allow(clippy::vec_init_then_push)]
275 pub fn invoke_signed_with_remaining_accounts(
276 &self,
277 signers_seeds: &[&[&[u8]]],
278 remaining_accounts: &[(
279 &'b solana_program::account_info::AccountInfo<'a>,
280 bool,
281 bool,
282 )],
283 ) -> solana_program::entrypoint::ProgramResult {
284 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
285 accounts.push(solana_program::instruction::AccountMeta::new(
286 *self.margin_account.key,
287 false,
288 ));
289 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
290 *self.pool.key,
291 true,
292 ));
293 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
294 *self.owner.key,
295 false,
296 ));
297 accounts.push(solana_program::instruction::AccountMeta::new(
298 *self.destination.key,
299 false,
300 ));
301 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
302 *self.system_program.key,
303 false,
304 ));
305 remaining_accounts.iter().for_each(|remaining_account| {
306 accounts.push(solana_program::instruction::AccountMeta {
307 pubkey: *remaining_account.0.key,
308 is_signer: remaining_account.1,
309 is_writable: remaining_account.2,
310 })
311 });
312 let mut data = WithdrawMarginAccountCpiTammInstructionData::new()
313 .try_to_vec()
314 .unwrap();
315 let mut args = self.__args.try_to_vec().unwrap();
316 data.append(&mut args);
317
318 let instruction = solana_program::instruction::Instruction {
319 program_id: crate::TENSOR_ESCROW_ID,
320 accounts,
321 data,
322 };
323 let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len());
324 account_infos.push(self.__program.clone());
325 account_infos.push(self.margin_account.clone());
326 account_infos.push(self.pool.clone());
327 account_infos.push(self.owner.clone());
328 account_infos.push(self.destination.clone());
329 account_infos.push(self.system_program.clone());
330 remaining_accounts
331 .iter()
332 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
333
334 if signers_seeds.is_empty() {
335 solana_program::program::invoke(&instruction, &account_infos)
336 } else {
337 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
338 }
339 }
340}
341
342#[derive(Clone, Debug)]
352pub struct WithdrawMarginAccountCpiTammCpiBuilder<'a, 'b> {
353 instruction: Box<WithdrawMarginAccountCpiTammCpiBuilderInstruction<'a, 'b>>,
354}
355
356impl<'a, 'b> WithdrawMarginAccountCpiTammCpiBuilder<'a, 'b> {
357 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
358 let instruction = Box::new(WithdrawMarginAccountCpiTammCpiBuilderInstruction {
359 __program: program,
360 margin_account: None,
361 pool: None,
362 owner: None,
363 destination: None,
364 system_program: None,
365 bump: None,
366 pool_id: None,
367 lamports: None,
368 __remaining_accounts: Vec::new(),
369 });
370 Self { instruction }
371 }
372 #[inline(always)]
373 pub fn margin_account(
374 &mut self,
375 margin_account: &'b solana_program::account_info::AccountInfo<'a>,
376 ) -> &mut Self {
377 self.instruction.margin_account = Some(margin_account);
378 self
379 }
380 #[inline(always)]
381 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
382 self.instruction.pool = Some(pool);
383 self
384 }
385 #[inline(always)]
386 pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
387 self.instruction.owner = Some(owner);
388 self
389 }
390 #[inline(always)]
391 pub fn destination(
392 &mut self,
393 destination: &'b solana_program::account_info::AccountInfo<'a>,
394 ) -> &mut Self {
395 self.instruction.destination = Some(destination);
396 self
397 }
398 #[inline(always)]
399 pub fn system_program(
400 &mut self,
401 system_program: &'b solana_program::account_info::AccountInfo<'a>,
402 ) -> &mut Self {
403 self.instruction.system_program = Some(system_program);
404 self
405 }
406 #[inline(always)]
407 pub fn bump(&mut self, bump: u8) -> &mut Self {
408 self.instruction.bump = Some(bump);
409 self
410 }
411 #[inline(always)]
412 pub fn pool_id(&mut self, pool_id: [u8; 32]) -> &mut Self {
413 self.instruction.pool_id = Some(pool_id);
414 self
415 }
416 #[inline(always)]
417 pub fn lamports(&mut self, lamports: u64) -> &mut Self {
418 self.instruction.lamports = Some(lamports);
419 self
420 }
421 #[inline(always)]
423 pub fn add_remaining_account(
424 &mut self,
425 account: &'b solana_program::account_info::AccountInfo<'a>,
426 is_writable: bool,
427 is_signer: bool,
428 ) -> &mut Self {
429 self.instruction
430 .__remaining_accounts
431 .push((account, is_writable, is_signer));
432 self
433 }
434 #[inline(always)]
439 pub fn add_remaining_accounts(
440 &mut self,
441 accounts: &[(
442 &'b solana_program::account_info::AccountInfo<'a>,
443 bool,
444 bool,
445 )],
446 ) -> &mut Self {
447 self.instruction
448 .__remaining_accounts
449 .extend_from_slice(accounts);
450 self
451 }
452 #[inline(always)]
453 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
454 self.invoke_signed(&[])
455 }
456 #[allow(clippy::clone_on_copy)]
457 #[allow(clippy::vec_init_then_push)]
458 pub fn invoke_signed(
459 &self,
460 signers_seeds: &[&[&[u8]]],
461 ) -> solana_program::entrypoint::ProgramResult {
462 let args = WithdrawMarginAccountCpiTammInstructionArgs {
463 bump: self.instruction.bump.clone().expect("bump is not set"),
464 pool_id: self
465 .instruction
466 .pool_id
467 .clone()
468 .expect("pool_id is not set"),
469 lamports: self
470 .instruction
471 .lamports
472 .clone()
473 .expect("lamports is not set"),
474 };
475 let instruction = WithdrawMarginAccountCpiTammCpi {
476 __program: self.instruction.__program,
477
478 margin_account: self
479 .instruction
480 .margin_account
481 .expect("margin_account is not set"),
482
483 pool: self.instruction.pool.expect("pool is not set"),
484
485 owner: self.instruction.owner.expect("owner is not set"),
486
487 destination: self
488 .instruction
489 .destination
490 .expect("destination is not set"),
491
492 system_program: self
493 .instruction
494 .system_program
495 .expect("system_program is not set"),
496 __args: args,
497 };
498 instruction.invoke_signed_with_remaining_accounts(
499 signers_seeds,
500 &self.instruction.__remaining_accounts,
501 )
502 }
503}
504
505#[derive(Clone, Debug)]
506struct WithdrawMarginAccountCpiTammCpiBuilderInstruction<'a, 'b> {
507 __program: &'b solana_program::account_info::AccountInfo<'a>,
508 margin_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
509 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
510 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
511 destination: Option<&'b solana_program::account_info::AccountInfo<'a>>,
512 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
513 bump: Option<u8>,
514 pool_id: Option<[u8; 32]>,
515 lamports: Option<u64>,
516 __remaining_accounts: Vec<(
518 &'b solana_program::account_info::AccountInfo<'a>,
519 bool,
520 bool,
521 )>,
522}