Skip to main content

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