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