Skip to main content

jito_restaking_client/generated/instructions/
initialize_config.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
7use borsh::{BorshDeserialize, BorshSerialize};
8
9/// Accounts.
10pub struct InitializeConfig {
11    pub config: solana_program::pubkey::Pubkey,
12
13    pub admin: solana_program::pubkey::Pubkey,
14
15    pub vault_program: solana_program::pubkey::Pubkey,
16
17    pub system_program: solana_program::pubkey::Pubkey,
18}
19
20impl InitializeConfig {
21    pub fn instruction(&self) -> solana_program::instruction::Instruction {
22        self.instruction_with_remaining_accounts(&[])
23    }
24    #[allow(clippy::vec_init_then_push)]
25    pub fn instruction_with_remaining_accounts(
26        &self,
27        remaining_accounts: &[solana_program::instruction::AccountMeta],
28    ) -> solana_program::instruction::Instruction {
29        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
30        accounts.push(solana_program::instruction::AccountMeta::new(
31            self.config,
32            false,
33        ));
34        accounts.push(solana_program::instruction::AccountMeta::new(
35            self.admin, true,
36        ));
37        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
38            self.vault_program,
39            false,
40        ));
41        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
42            self.system_program,
43            false,
44        ));
45        accounts.extend_from_slice(remaining_accounts);
46        let data = InitializeConfigInstructionData::new().try_to_vec().unwrap();
47
48        solana_program::instruction::Instruction {
49            program_id: crate::JITO_RESTAKING_ID,
50            accounts,
51            data,
52        }
53    }
54}
55
56#[derive(BorshDeserialize, BorshSerialize)]
57pub struct InitializeConfigInstructionData {
58    discriminator: u8,
59}
60
61impl InitializeConfigInstructionData {
62    pub fn new() -> Self {
63        Self { discriminator: 0 }
64    }
65}
66
67impl Default for InitializeConfigInstructionData {
68    fn default() -> Self {
69        Self::new()
70    }
71}
72
73/// Instruction builder for `InitializeConfig`.
74///
75/// ### Accounts:
76///
77///   0. `[writable]` config
78///   1. `[writable, signer]` admin
79///   2. `[]` vault_program
80///   3. `[optional]` system_program (default to `11111111111111111111111111111111`)
81#[derive(Clone, Debug, Default)]
82pub struct InitializeConfigBuilder {
83    config: Option<solana_program::pubkey::Pubkey>,
84    admin: Option<solana_program::pubkey::Pubkey>,
85    vault_program: Option<solana_program::pubkey::Pubkey>,
86    system_program: Option<solana_program::pubkey::Pubkey>,
87    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
88}
89
90impl InitializeConfigBuilder {
91    pub fn new() -> Self {
92        Self::default()
93    }
94    #[inline(always)]
95    pub fn config(&mut self, config: solana_program::pubkey::Pubkey) -> &mut Self {
96        self.config = Some(config);
97        self
98    }
99    #[inline(always)]
100    pub fn admin(&mut self, admin: solana_program::pubkey::Pubkey) -> &mut Self {
101        self.admin = Some(admin);
102        self
103    }
104    #[inline(always)]
105    pub fn vault_program(&mut self, vault_program: solana_program::pubkey::Pubkey) -> &mut Self {
106        self.vault_program = Some(vault_program);
107        self
108    }
109    /// `[optional account, default to '11111111111111111111111111111111']`
110    #[inline(always)]
111    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
112        self.system_program = Some(system_program);
113        self
114    }
115    /// Add an additional account to the instruction.
116    #[inline(always)]
117    pub fn add_remaining_account(
118        &mut self,
119        account: solana_program::instruction::AccountMeta,
120    ) -> &mut Self {
121        self.__remaining_accounts.push(account);
122        self
123    }
124    /// Add additional accounts to the instruction.
125    #[inline(always)]
126    pub fn add_remaining_accounts(
127        &mut self,
128        accounts: &[solana_program::instruction::AccountMeta],
129    ) -> &mut Self {
130        self.__remaining_accounts.extend_from_slice(accounts);
131        self
132    }
133    #[allow(clippy::clone_on_copy)]
134    pub fn instruction(&self) -> solana_program::instruction::Instruction {
135        let accounts = InitializeConfig {
136            config: self.config.expect("config is not set"),
137            admin: self.admin.expect("admin is not set"),
138            vault_program: self.vault_program.expect("vault_program is not set"),
139            system_program: self
140                .system_program
141                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
142        };
143
144        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
145    }
146}
147
148/// `initialize_config` CPI accounts.
149pub struct InitializeConfigCpiAccounts<'a, 'b> {
150    pub config: &'b solana_program::account_info::AccountInfo<'a>,
151
152    pub admin: &'b solana_program::account_info::AccountInfo<'a>,
153
154    pub vault_program: &'b solana_program::account_info::AccountInfo<'a>,
155
156    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
157}
158
159/// `initialize_config` CPI instruction.
160pub struct InitializeConfigCpi<'a, 'b> {
161    /// The program to invoke.
162    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
163
164    pub config: &'b solana_program::account_info::AccountInfo<'a>,
165
166    pub admin: &'b solana_program::account_info::AccountInfo<'a>,
167
168    pub vault_program: &'b solana_program::account_info::AccountInfo<'a>,
169
170    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
171}
172
173impl<'a, 'b> InitializeConfigCpi<'a, 'b> {
174    pub fn new(
175        program: &'b solana_program::account_info::AccountInfo<'a>,
176        accounts: InitializeConfigCpiAccounts<'a, 'b>,
177    ) -> Self {
178        Self {
179            __program: program,
180            config: accounts.config,
181            admin: accounts.admin,
182            vault_program: accounts.vault_program,
183            system_program: accounts.system_program,
184        }
185    }
186    #[inline(always)]
187    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
188        self.invoke_signed_with_remaining_accounts(&[], &[])
189    }
190    #[inline(always)]
191    pub fn invoke_with_remaining_accounts(
192        &self,
193        remaining_accounts: &[(
194            &'b solana_program::account_info::AccountInfo<'a>,
195            bool,
196            bool,
197        )],
198    ) -> solana_program::entrypoint::ProgramResult {
199        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
200    }
201    #[inline(always)]
202    pub fn invoke_signed(
203        &self,
204        signers_seeds: &[&[&[u8]]],
205    ) -> solana_program::entrypoint::ProgramResult {
206        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
207    }
208    #[allow(clippy::clone_on_copy)]
209    #[allow(clippy::vec_init_then_push)]
210    pub fn invoke_signed_with_remaining_accounts(
211        &self,
212        signers_seeds: &[&[&[u8]]],
213        remaining_accounts: &[(
214            &'b solana_program::account_info::AccountInfo<'a>,
215            bool,
216            bool,
217        )],
218    ) -> solana_program::entrypoint::ProgramResult {
219        let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
220        accounts.push(solana_program::instruction::AccountMeta::new(
221            *self.config.key,
222            false,
223        ));
224        accounts.push(solana_program::instruction::AccountMeta::new(
225            *self.admin.key,
226            true,
227        ));
228        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
229            *self.vault_program.key,
230            false,
231        ));
232        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
233            *self.system_program.key,
234            false,
235        ));
236        remaining_accounts.iter().for_each(|remaining_account| {
237            accounts.push(solana_program::instruction::AccountMeta {
238                pubkey: *remaining_account.0.key,
239                is_signer: remaining_account.1,
240                is_writable: remaining_account.2,
241            })
242        });
243        let data = InitializeConfigInstructionData::new().try_to_vec().unwrap();
244
245        let instruction = solana_program::instruction::Instruction {
246            program_id: crate::JITO_RESTAKING_ID,
247            accounts,
248            data,
249        };
250        let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
251        account_infos.push(self.__program.clone());
252        account_infos.push(self.config.clone());
253        account_infos.push(self.admin.clone());
254        account_infos.push(self.vault_program.clone());
255        account_infos.push(self.system_program.clone());
256        remaining_accounts
257            .iter()
258            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
259
260        if signers_seeds.is_empty() {
261            solana_program::program::invoke(&instruction, &account_infos)
262        } else {
263            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
264        }
265    }
266}
267
268/// Instruction builder for `InitializeConfig` via CPI.
269///
270/// ### Accounts:
271///
272///   0. `[writable]` config
273///   1. `[writable, signer]` admin
274///   2. `[]` vault_program
275///   3. `[]` system_program
276#[derive(Clone, Debug)]
277pub struct InitializeConfigCpiBuilder<'a, 'b> {
278    instruction: Box<InitializeConfigCpiBuilderInstruction<'a, 'b>>,
279}
280
281impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> {
282    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
283        let instruction = Box::new(InitializeConfigCpiBuilderInstruction {
284            __program: program,
285            config: None,
286            admin: None,
287            vault_program: None,
288            system_program: None,
289            __remaining_accounts: Vec::new(),
290        });
291        Self { instruction }
292    }
293    #[inline(always)]
294    pub fn config(
295        &mut self,
296        config: &'b solana_program::account_info::AccountInfo<'a>,
297    ) -> &mut Self {
298        self.instruction.config = Some(config);
299        self
300    }
301    #[inline(always)]
302    pub fn admin(&mut self, admin: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
303        self.instruction.admin = Some(admin);
304        self
305    }
306    #[inline(always)]
307    pub fn vault_program(
308        &mut self,
309        vault_program: &'b solana_program::account_info::AccountInfo<'a>,
310    ) -> &mut Self {
311        self.instruction.vault_program = Some(vault_program);
312        self
313    }
314    #[inline(always)]
315    pub fn system_program(
316        &mut self,
317        system_program: &'b solana_program::account_info::AccountInfo<'a>,
318    ) -> &mut Self {
319        self.instruction.system_program = Some(system_program);
320        self
321    }
322    /// Add an additional account to the instruction.
323    #[inline(always)]
324    pub fn add_remaining_account(
325        &mut self,
326        account: &'b solana_program::account_info::AccountInfo<'a>,
327        is_writable: bool,
328        is_signer: bool,
329    ) -> &mut Self {
330        self.instruction
331            .__remaining_accounts
332            .push((account, is_writable, is_signer));
333        self
334    }
335    /// Add additional accounts to the instruction.
336    ///
337    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
338    /// and a `bool` indicating whether the account is a signer or not.
339    #[inline(always)]
340    pub fn add_remaining_accounts(
341        &mut self,
342        accounts: &[(
343            &'b solana_program::account_info::AccountInfo<'a>,
344            bool,
345            bool,
346        )],
347    ) -> &mut Self {
348        self.instruction
349            .__remaining_accounts
350            .extend_from_slice(accounts);
351        self
352    }
353    #[inline(always)]
354    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
355        self.invoke_signed(&[])
356    }
357    #[allow(clippy::clone_on_copy)]
358    #[allow(clippy::vec_init_then_push)]
359    pub fn invoke_signed(
360        &self,
361        signers_seeds: &[&[&[u8]]],
362    ) -> solana_program::entrypoint::ProgramResult {
363        let instruction = InitializeConfigCpi {
364            __program: self.instruction.__program,
365
366            config: self.instruction.config.expect("config is not set"),
367
368            admin: self.instruction.admin.expect("admin is not set"),
369
370            vault_program: self
371                .instruction
372                .vault_program
373                .expect("vault_program is not set"),
374
375            system_program: self
376                .instruction
377                .system_program
378                .expect("system_program is not set"),
379        };
380        instruction.invoke_signed_with_remaining_accounts(
381            signers_seeds,
382            &self.instruction.__remaining_accounts,
383        )
384    }
385}
386
387#[derive(Clone, Debug)]
388struct InitializeConfigCpiBuilderInstruction<'a, 'b> {
389    __program: &'b solana_program::account_info::AccountInfo<'a>,
390    config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
391    admin: Option<&'b solana_program::account_info::AccountInfo<'a>>,
392    vault_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
393    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
394    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
395    __remaining_accounts: Vec<(
396        &'b solana_program::account_info::AccountInfo<'a>,
397        bool,
398        bool,
399    )>,
400}