tensor_escrow/generated/instructions/
withdraw_margin_account_cpi_tcomp.rs

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