Skip to main content

reflect_sdk/generated/instructions/
add_lst_drift.rs

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