Skip to main content

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