Skip to main content

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