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