Skip to main content

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