Skip to main content

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