1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct SetFeeRate {
14 pub whirlpools_config: solana_pubkey::Pubkey,
15
16 pub whirlpool: solana_pubkey::Pubkey,
17
18 pub fee_authority: solana_pubkey::Pubkey,
19}
20
21impl SetFeeRate {
22 pub fn instruction(&self, args: SetFeeRateInstructionArgs) -> solana_instruction::Instruction {
23 self.instruction_with_remaining_accounts(args, &[])
24 }
25 #[allow(clippy::arithmetic_side_effects)]
26 #[allow(clippy::vec_init_then_push)]
27 pub fn instruction_with_remaining_accounts(
28 &self,
29 args: SetFeeRateInstructionArgs,
30 remaining_accounts: &[solana_instruction::AccountMeta],
31 ) -> solana_instruction::Instruction {
32 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
33 accounts.push(solana_instruction::AccountMeta::new_readonly(
34 self.whirlpools_config,
35 false,
36 ));
37 accounts.push(solana_instruction::AccountMeta::new(self.whirlpool, false));
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(&SetFeeRateInstructionData::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 SetFeeRateInstructionData {
58 discriminator: [u8; 8],
59}
60
61impl SetFeeRateInstructionData {
62 pub fn new() -> Self {
63 Self {
64 discriminator: [53, 243, 137, 65, 8, 140, 158, 6],
65 }
66 }
67}
68
69impl Default for SetFeeRateInstructionData {
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 SetFeeRateInstructionArgs {
78 pub fee_rate: u16,
79}
80
81#[derive(Clone, Debug, Default)]
89pub struct SetFeeRateBuilder {
90 whirlpools_config: Option<solana_pubkey::Pubkey>,
91 whirlpool: Option<solana_pubkey::Pubkey>,
92 fee_authority: Option<solana_pubkey::Pubkey>,
93 fee_rate: Option<u16>,
94 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
95}
96
97impl SetFeeRateBuilder {
98 pub fn new() -> Self {
99 Self::default()
100 }
101 #[inline(always)]
102 pub fn whirlpools_config(&mut self, whirlpools_config: solana_pubkey::Pubkey) -> &mut Self {
103 self.whirlpools_config = Some(whirlpools_config);
104 self
105 }
106 #[inline(always)]
107 pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
108 self.whirlpool = Some(whirlpool);
109 self
110 }
111 #[inline(always)]
112 pub fn fee_authority(&mut self, fee_authority: solana_pubkey::Pubkey) -> &mut Self {
113 self.fee_authority = Some(fee_authority);
114 self
115 }
116 #[inline(always)]
117 pub fn fee_rate(&mut self, fee_rate: u16) -> &mut Self {
118 self.fee_rate = Some(fee_rate);
119 self
120 }
121 #[inline(always)]
123 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
124 self.__remaining_accounts.push(account);
125 self
126 }
127 #[inline(always)]
129 pub fn add_remaining_accounts(
130 &mut self,
131 accounts: &[solana_instruction::AccountMeta],
132 ) -> &mut Self {
133 self.__remaining_accounts.extend_from_slice(accounts);
134 self
135 }
136 #[allow(clippy::clone_on_copy)]
137 pub fn instruction(&self) -> solana_instruction::Instruction {
138 let accounts = SetFeeRate {
139 whirlpools_config: self
140 .whirlpools_config
141 .expect("whirlpools_config is not set"),
142 whirlpool: self.whirlpool.expect("whirlpool is not set"),
143 fee_authority: self.fee_authority.expect("fee_authority is not set"),
144 };
145 let args = SetFeeRateInstructionArgs {
146 fee_rate: self.fee_rate.clone().expect("fee_rate is not set"),
147 };
148
149 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
150 }
151}
152
153pub struct SetFeeRateCpiAccounts<'a, 'b> {
155 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
156
157 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
158
159 pub fee_authority: &'b solana_account_info::AccountInfo<'a>,
160}
161
162pub struct SetFeeRateCpi<'a, 'b> {
164 pub __program: &'b solana_account_info::AccountInfo<'a>,
166
167 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
168
169 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
170
171 pub fee_authority: &'b solana_account_info::AccountInfo<'a>,
172 pub __args: SetFeeRateInstructionArgs,
174}
175
176impl<'a, 'b> SetFeeRateCpi<'a, 'b> {
177 pub fn new(
178 program: &'b solana_account_info::AccountInfo<'a>,
179 accounts: SetFeeRateCpiAccounts<'a, 'b>,
180 args: SetFeeRateInstructionArgs,
181 ) -> Self {
182 Self {
183 __program: program,
184 whirlpools_config: accounts.whirlpools_config,
185 whirlpool: accounts.whirlpool,
186 fee_authority: accounts.fee_authority,
187 __args: args,
188 }
189 }
190 #[inline(always)]
191 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
192 self.invoke_signed_with_remaining_accounts(&[], &[])
193 }
194 #[inline(always)]
195 pub fn invoke_with_remaining_accounts(
196 &self,
197 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
198 ) -> solana_program_entrypoint::ProgramResult {
199 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
200 }
201 #[inline(always)]
202 pub fn invoke_signed(
203 &self,
204 signers_seeds: &[&[&[u8]]],
205 ) -> solana_program_entrypoint::ProgramResult {
206 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
207 }
208 #[allow(clippy::arithmetic_side_effects)]
209 #[allow(clippy::clone_on_copy)]
210 #[allow(clippy::vec_init_then_push)]
211 pub fn invoke_signed_with_remaining_accounts(
212 &self,
213 signers_seeds: &[&[&[u8]]],
214 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
215 ) -> solana_program_entrypoint::ProgramResult {
216 let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
217 accounts.push(solana_instruction::AccountMeta::new_readonly(
218 *self.whirlpools_config.key,
219 false,
220 ));
221 accounts.push(solana_instruction::AccountMeta::new(
222 *self.whirlpool.key,
223 false,
224 ));
225 accounts.push(solana_instruction::AccountMeta::new_readonly(
226 *self.fee_authority.key,
227 true,
228 ));
229 remaining_accounts.iter().for_each(|remaining_account| {
230 accounts.push(solana_instruction::AccountMeta {
231 pubkey: *remaining_account.0.key,
232 is_signer: remaining_account.1,
233 is_writable: remaining_account.2,
234 })
235 });
236 let mut data = borsh::to_vec(&SetFeeRateInstructionData::new()).unwrap();
237 let mut args = borsh::to_vec(&self.__args).unwrap();
238 data.append(&mut args);
239
240 let instruction = solana_instruction::Instruction {
241 program_id: crate::WHIRLPOOL_ID,
242 accounts,
243 data,
244 };
245 let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
246 account_infos.push(self.__program.clone());
247 account_infos.push(self.whirlpools_config.clone());
248 account_infos.push(self.whirlpool.clone());
249 account_infos.push(self.fee_authority.clone());
250 remaining_accounts
251 .iter()
252 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
253
254 if signers_seeds.is_empty() {
255 solana_cpi::invoke(&instruction, &account_infos)
256 } else {
257 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
258 }
259 }
260}
261
262#[derive(Clone, Debug)]
270pub struct SetFeeRateCpiBuilder<'a, 'b> {
271 instruction: Box<SetFeeRateCpiBuilderInstruction<'a, 'b>>,
272}
273
274impl<'a, 'b> SetFeeRateCpiBuilder<'a, 'b> {
275 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
276 let instruction = Box::new(SetFeeRateCpiBuilderInstruction {
277 __program: program,
278 whirlpools_config: None,
279 whirlpool: None,
280 fee_authority: None,
281 fee_rate: None,
282 __remaining_accounts: Vec::new(),
283 });
284 Self { instruction }
285 }
286 #[inline(always)]
287 pub fn whirlpools_config(
288 &mut self,
289 whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
290 ) -> &mut Self {
291 self.instruction.whirlpools_config = Some(whirlpools_config);
292 self
293 }
294 #[inline(always)]
295 pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
296 self.instruction.whirlpool = Some(whirlpool);
297 self
298 }
299 #[inline(always)]
300 pub fn fee_authority(
301 &mut self,
302 fee_authority: &'b solana_account_info::AccountInfo<'a>,
303 ) -> &mut Self {
304 self.instruction.fee_authority = Some(fee_authority);
305 self
306 }
307 #[inline(always)]
308 pub fn fee_rate(&mut self, fee_rate: u16) -> &mut Self {
309 self.instruction.fee_rate = Some(fee_rate);
310 self
311 }
312 #[inline(always)]
314 pub fn add_remaining_account(
315 &mut self,
316 account: &'b solana_account_info::AccountInfo<'a>,
317 is_writable: bool,
318 is_signer: bool,
319 ) -> &mut Self {
320 self.instruction
321 .__remaining_accounts
322 .push((account, is_writable, is_signer));
323 self
324 }
325 #[inline(always)]
330 pub fn add_remaining_accounts(
331 &mut self,
332 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
333 ) -> &mut Self {
334 self.instruction
335 .__remaining_accounts
336 .extend_from_slice(accounts);
337 self
338 }
339 #[inline(always)]
340 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
341 self.invoke_signed(&[])
342 }
343 #[allow(clippy::clone_on_copy)]
344 #[allow(clippy::vec_init_then_push)]
345 pub fn invoke_signed(
346 &self,
347 signers_seeds: &[&[&[u8]]],
348 ) -> solana_program_entrypoint::ProgramResult {
349 let args = SetFeeRateInstructionArgs {
350 fee_rate: self
351 .instruction
352 .fee_rate
353 .clone()
354 .expect("fee_rate is not set"),
355 };
356 let instruction = SetFeeRateCpi {
357 __program: self.instruction.__program,
358
359 whirlpools_config: self
360 .instruction
361 .whirlpools_config
362 .expect("whirlpools_config is not set"),
363
364 whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
365
366 fee_authority: self
367 .instruction
368 .fee_authority
369 .expect("fee_authority is not set"),
370 __args: args,
371 };
372 instruction.invoke_signed_with_remaining_accounts(
373 signers_seeds,
374 &self.instruction.__remaining_accounts,
375 )
376 }
377}
378
379#[derive(Clone, Debug)]
380struct SetFeeRateCpiBuilderInstruction<'a, 'b> {
381 __program: &'b solana_account_info::AccountInfo<'a>,
382 whirlpools_config: Option<&'b solana_account_info::AccountInfo<'a>>,
383 whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
384 fee_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
385 fee_rate: Option<u16>,
386 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
388}