Skip to main content

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