1use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12pub const SUSPEND_SPL_STRATEGY_DISCRIMINATOR: [u8; 8] = [75, 56, 252, 86, 120, 113, 128, 151];
13
14#[derive(Debug)]
16pub struct SuspendSplStrategy {
17
18
19 pub main: solana_pubkey::Pubkey,
20
21
22 pub admin: solana_pubkey::Pubkey,
23
24
25 pub system_program: solana_pubkey::Pubkey,
26
27
28 pub strategy: solana_pubkey::Pubkey,
29
30
31 pub admin_permissions: solana_pubkey::Pubkey,
32 }
33
34impl SuspendSplStrategy {
35 pub fn instruction(&self, args: SuspendSplStrategyInstructionArgs) -> solana_instruction::Instruction {
36 self.instruction_with_remaining_accounts(args, &[])
37 }
38 #[allow(clippy::arithmetic_side_effects)]
39 #[allow(clippy::vec_init_then_push)]
40 pub fn instruction_with_remaining_accounts(&self, args: SuspendSplStrategyInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
41 let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
42 accounts.push(solana_instruction::AccountMeta::new(
43 self.main,
44 false
45 ));
46 accounts.push(solana_instruction::AccountMeta::new(
47 self.admin,
48 true
49 ));
50 accounts.push(solana_instruction::AccountMeta::new_readonly(
51 self.system_program,
52 false
53 ));
54 accounts.push(solana_instruction::AccountMeta::new(
55 self.strategy,
56 false
57 ));
58 accounts.push(solana_instruction::AccountMeta::new(
59 self.admin_permissions,
60 false
61 ));
62 accounts.extend_from_slice(remaining_accounts);
63 let mut data = SuspendSplStrategyInstructionData::new().try_to_vec().unwrap();
64 let mut args = args.try_to_vec().unwrap();
65 data.append(&mut args);
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))]
77 pub struct SuspendSplStrategyInstructionData {
78 discriminator: [u8; 8],
79 }
80
81impl SuspendSplStrategyInstructionData {
82 pub fn new() -> Self {
83 Self {
84 discriminator: [75, 56, 252, 86, 120, 113, 128, 151],
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 SuspendSplStrategyInstructionData {
94 fn default() -> Self {
95 Self::new()
96 }
97}
98
99#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
100#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
101 pub struct SuspendSplStrategyInstructionArgs {
102 pub lst_mint: Pubkey,
103 pub freeze: bool,
104 }
105
106impl SuspendSplStrategyInstructionArgs {
107 pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
108 borsh::to_vec(self)
109 }
110}
111
112
113#[derive(Clone, Debug, Default)]
123pub struct SuspendSplStrategyBuilder {
124 main: Option<solana_pubkey::Pubkey>,
125 admin: Option<solana_pubkey::Pubkey>,
126 system_program: Option<solana_pubkey::Pubkey>,
127 strategy: Option<solana_pubkey::Pubkey>,
128 admin_permissions: Option<solana_pubkey::Pubkey>,
129 lst_mint: Option<Pubkey>,
130 freeze: Option<bool>,
131 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
132}
133
134impl SuspendSplStrategyBuilder {
135 pub fn new() -> Self {
136 Self::default()
137 }
138 #[inline(always)]
139 pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
140 self.main = Some(main);
141 self
142 }
143 #[inline(always)]
144 pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
145 self.admin = Some(admin);
146 self
147 }
148 #[inline(always)]
150 pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
151 self.system_program = Some(system_program);
152 self
153 }
154 #[inline(always)]
155 pub fn strategy(&mut self, strategy: solana_pubkey::Pubkey) -> &mut Self {
156 self.strategy = Some(strategy);
157 self
158 }
159 #[inline(always)]
160 pub fn admin_permissions(&mut self, admin_permissions: solana_pubkey::Pubkey) -> &mut Self {
161 self.admin_permissions = Some(admin_permissions);
162 self
163 }
164 #[inline(always)]
165 pub fn lst_mint(&mut self, lst_mint: Pubkey) -> &mut Self {
166 self.lst_mint = Some(lst_mint);
167 self
168 }
169 #[inline(always)]
170 pub fn freeze(&mut self, freeze: bool) -> &mut Self {
171 self.freeze = Some(freeze);
172 self
173 }
174 #[inline(always)]
176 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
177 self.__remaining_accounts.push(account);
178 self
179 }
180 #[inline(always)]
182 pub fn add_remaining_accounts(&mut self, accounts: &[solana_instruction::AccountMeta]) -> &mut Self {
183 self.__remaining_accounts.extend_from_slice(accounts);
184 self
185 }
186 #[allow(clippy::clone_on_copy)]
187 pub fn instruction(&self) -> solana_instruction::Instruction {
188 let accounts = SuspendSplStrategy {
189 main: self.main.expect("main is not set"),
190 admin: self.admin.expect("admin is not set"),
191 system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
192 strategy: self.strategy.expect("strategy is not set"),
193 admin_permissions: self.admin_permissions.expect("admin_permissions is not set"),
194 };
195 let args = SuspendSplStrategyInstructionArgs {
196 lst_mint: self.lst_mint.clone().expect("lst_mint is not set"),
197 freeze: self.freeze.clone().expect("freeze is not set"),
198 };
199
200 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
201 }
202}
203
204 pub struct SuspendSplStrategyCpiAccounts<'a, 'b> {
206
207
208 pub main: &'b solana_account_info::AccountInfo<'a>,
209
210
211 pub admin: &'b solana_account_info::AccountInfo<'a>,
212
213
214 pub system_program: &'b solana_account_info::AccountInfo<'a>,
215
216
217 pub strategy: &'b solana_account_info::AccountInfo<'a>,
218
219
220 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
221 }
222
223pub struct SuspendSplStrategyCpi<'a, 'b> {
225 pub __program: &'b solana_account_info::AccountInfo<'a>,
227
228
229 pub main: &'b solana_account_info::AccountInfo<'a>,
230
231
232 pub admin: &'b solana_account_info::AccountInfo<'a>,
233
234
235 pub system_program: &'b solana_account_info::AccountInfo<'a>,
236
237
238 pub strategy: &'b solana_account_info::AccountInfo<'a>,
239
240
241 pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
242 pub __args: SuspendSplStrategyInstructionArgs,
244 }
245
246impl<'a, 'b> SuspendSplStrategyCpi<'a, 'b> {
247 pub fn new(
248 program: &'b solana_account_info::AccountInfo<'a>,
249 accounts: SuspendSplStrategyCpiAccounts<'a, 'b>,
250 args: SuspendSplStrategyInstructionArgs,
251 ) -> Self {
252 Self {
253 __program: program,
254 main: accounts.main,
255 admin: accounts.admin,
256 system_program: accounts.system_program,
257 strategy: accounts.strategy,
258 admin_permissions: accounts.admin_permissions,
259 __args: args,
260 }
261 }
262 #[inline(always)]
263 pub fn invoke(&self) -> solana_program_error::ProgramResult {
264 self.invoke_signed_with_remaining_accounts(&[], &[])
265 }
266 #[inline(always)]
267 pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> solana_program_error::ProgramResult {
268 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
269 }
270 #[inline(always)]
271 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
272 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
273 }
274 #[allow(clippy::arithmetic_side_effects)]
275 #[allow(clippy::clone_on_copy)]
276 #[allow(clippy::vec_init_then_push)]
277 pub fn invoke_signed_with_remaining_accounts(
278 &self,
279 signers_seeds: &[&[&[u8]]],
280 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]
281 ) -> solana_program_error::ProgramResult {
282 let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
283 accounts.push(solana_instruction::AccountMeta::new(
284 *self.main.key,
285 false
286 ));
287 accounts.push(solana_instruction::AccountMeta::new(
288 *self.admin.key,
289 true
290 ));
291 accounts.push(solana_instruction::AccountMeta::new_readonly(
292 *self.system_program.key,
293 false
294 ));
295 accounts.push(solana_instruction::AccountMeta::new(
296 *self.strategy.key,
297 false
298 ));
299 accounts.push(solana_instruction::AccountMeta::new(
300 *self.admin_permissions.key,
301 false
302 ));
303 remaining_accounts.iter().for_each(|remaining_account| {
304 accounts.push(solana_instruction::AccountMeta {
305 pubkey: *remaining_account.0.key,
306 is_signer: remaining_account.1,
307 is_writable: remaining_account.2,
308 })
309 });
310 let mut data = SuspendSplStrategyInstructionData::new().try_to_vec().unwrap();
311 let mut args = self.__args.try_to_vec().unwrap();
312 data.append(&mut args);
313
314 let instruction = solana_instruction::Instruction {
315 program_id: crate::REFLECT_MAIN_ID,
316 accounts,
317 data,
318 };
319 let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
320 account_infos.push(self.__program.clone());
321 account_infos.push(self.main.clone());
322 account_infos.push(self.admin.clone());
323 account_infos.push(self.system_program.clone());
324 account_infos.push(self.strategy.clone());
325 account_infos.push(self.admin_permissions.clone());
326 remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
327
328 if signers_seeds.is_empty() {
329 solana_cpi::invoke(&instruction, &account_infos)
330 } else {
331 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
332 }
333 }
334}
335
336#[derive(Clone, Debug)]
346pub struct SuspendSplStrategyCpiBuilder<'a, 'b> {
347 instruction: Box<SuspendSplStrategyCpiBuilderInstruction<'a, 'b>>,
348}
349
350impl<'a, 'b> SuspendSplStrategyCpiBuilder<'a, 'b> {
351 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
352 let instruction = Box::new(SuspendSplStrategyCpiBuilderInstruction {
353 __program: program,
354 main: None,
355 admin: None,
356 system_program: None,
357 strategy: None,
358 admin_permissions: None,
359 lst_mint: None,
360 freeze: None,
361 __remaining_accounts: Vec::new(),
362 });
363 Self { instruction }
364 }
365 #[inline(always)]
366 pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
367 self.instruction.main = Some(main);
368 self
369 }
370 #[inline(always)]
371 pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
372 self.instruction.admin = Some(admin);
373 self
374 }
375 #[inline(always)]
376 pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
377 self.instruction.system_program = Some(system_program);
378 self
379 }
380 #[inline(always)]
381 pub fn strategy(&mut self, strategy: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
382 self.instruction.strategy = Some(strategy);
383 self
384 }
385 #[inline(always)]
386 pub fn admin_permissions(&mut self, admin_permissions: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
387 self.instruction.admin_permissions = Some(admin_permissions);
388 self
389 }
390 #[inline(always)]
391 pub fn lst_mint(&mut self, lst_mint: Pubkey) -> &mut Self {
392 self.instruction.lst_mint = Some(lst_mint);
393 self
394 }
395 #[inline(always)]
396 pub fn freeze(&mut self, freeze: bool) -> &mut Self {
397 self.instruction.freeze = Some(freeze);
398 self
399 }
400 #[inline(always)]
402 pub fn add_remaining_account(&mut self, account: &'b solana_account_info::AccountInfo<'a>, is_writable: bool, is_signer: bool) -> &mut Self {
403 self.instruction.__remaining_accounts.push((account, is_writable, is_signer));
404 self
405 }
406 #[inline(always)]
411 pub fn add_remaining_accounts(&mut self, accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)]) -> &mut Self {
412 self.instruction.__remaining_accounts.extend_from_slice(accounts);
413 self
414 }
415 #[inline(always)]
416 pub fn invoke(&self) -> solana_program_error::ProgramResult {
417 self.invoke_signed(&[])
418 }
419 #[allow(clippy::clone_on_copy)]
420 #[allow(clippy::vec_init_then_push)]
421 pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::ProgramResult {
422 let args = SuspendSplStrategyInstructionArgs {
423 lst_mint: self.instruction.lst_mint.clone().expect("lst_mint is not set"),
424 freeze: self.instruction.freeze.clone().expect("freeze is not set"),
425 };
426 let instruction = SuspendSplStrategyCpi {
427 __program: self.instruction.__program,
428
429 main: self.instruction.main.expect("main is not set"),
430
431 admin: self.instruction.admin.expect("admin is not set"),
432
433 system_program: self.instruction.system_program.expect("system_program is not set"),
434
435 strategy: self.instruction.strategy.expect("strategy is not set"),
436
437 admin_permissions: self.instruction.admin_permissions.expect("admin_permissions is not set"),
438 __args: args,
439 };
440 instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
441 }
442}
443
444#[derive(Clone, Debug)]
445struct SuspendSplStrategyCpiBuilderInstruction<'a, 'b> {
446 __program: &'b solana_account_info::AccountInfo<'a>,
447 main: Option<&'b solana_account_info::AccountInfo<'a>>,
448 admin: Option<&'b solana_account_info::AccountInfo<'a>>,
449 system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
450 strategy: Option<&'b solana_account_info::AccountInfo<'a>>,
451 admin_permissions: Option<&'b solana_account_info::AccountInfo<'a>>,
452 lst_mint: Option<Pubkey>,
453 freeze: Option<bool>,
454 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
456}
457