1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct SetProtocolFeeRate {
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 SetProtocolFeeRate {
22 pub fn instruction(
23 &self,
24 args: SetProtocolFeeRateInstructionArgs,
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: SetProtocolFeeRateInstructionArgs,
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.whirlpool, 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(&SetProtocolFeeRateInstructionData::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 SetProtocolFeeRateInstructionData {
61 discriminator: [u8; 8],
62}
63
64impl SetProtocolFeeRateInstructionData {
65 pub fn new() -> Self {
66 Self {
67 discriminator: [95, 7, 4, 50, 154, 79, 156, 131],
68 }
69 }
70}
71
72impl Default for SetProtocolFeeRateInstructionData {
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 SetProtocolFeeRateInstructionArgs {
81 pub protocol_fee_rate: u16,
82}
83
84#[derive(Clone, Debug, Default)]
92pub struct SetProtocolFeeRateBuilder {
93 whirlpools_config: Option<solana_pubkey::Pubkey>,
94 whirlpool: Option<solana_pubkey::Pubkey>,
95 fee_authority: Option<solana_pubkey::Pubkey>,
96 protocol_fee_rate: Option<u16>,
97 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
98}
99
100impl SetProtocolFeeRateBuilder {
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 whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
111 self.whirlpool = Some(whirlpool);
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 protocol_fee_rate(&mut self, protocol_fee_rate: u16) -> &mut Self {
121 self.protocol_fee_rate = Some(protocol_fee_rate);
122 self
123 }
124 #[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 #[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 = SetProtocolFeeRate {
142 whirlpools_config: self
143 .whirlpools_config
144 .expect("whirlpools_config is not set"),
145 whirlpool: self.whirlpool.expect("whirlpool is not set"),
146 fee_authority: self.fee_authority.expect("fee_authority is not set"),
147 };
148 let args = SetProtocolFeeRateInstructionArgs {
149 protocol_fee_rate: self
150 .protocol_fee_rate
151 .clone()
152 .expect("protocol_fee_rate is not set"),
153 };
154
155 accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
156 }
157}
158
159pub struct SetProtocolFeeRateCpiAccounts<'a, 'b> {
161 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
162
163 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
164
165 pub fee_authority: &'b solana_account_info::AccountInfo<'a>,
166}
167
168pub struct SetProtocolFeeRateCpi<'a, 'b> {
170 pub __program: &'b solana_account_info::AccountInfo<'a>,
172
173 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
174
175 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
176
177 pub fee_authority: &'b solana_account_info::AccountInfo<'a>,
178 pub __args: SetProtocolFeeRateInstructionArgs,
180}
181
182impl<'a, 'b> SetProtocolFeeRateCpi<'a, 'b> {
183 pub fn new(
184 program: &'b solana_account_info::AccountInfo<'a>,
185 accounts: SetProtocolFeeRateCpiAccounts<'a, 'b>,
186 args: SetProtocolFeeRateInstructionArgs,
187 ) -> Self {
188 Self {
189 __program: program,
190 whirlpools_config: accounts.whirlpools_config,
191 whirlpool: accounts.whirlpool,
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.whirlpool.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(&SetProtocolFeeRateInstructionData::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.whirlpool.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#[derive(Clone, Debug)]
276pub struct SetProtocolFeeRateCpiBuilder<'a, 'b> {
277 instruction: Box<SetProtocolFeeRateCpiBuilderInstruction<'a, 'b>>,
278}
279
280impl<'a, 'b> SetProtocolFeeRateCpiBuilder<'a, 'b> {
281 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
282 let instruction = Box::new(SetProtocolFeeRateCpiBuilderInstruction {
283 __program: program,
284 whirlpools_config: None,
285 whirlpool: None,
286 fee_authority: None,
287 protocol_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 whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
302 self.instruction.whirlpool = Some(whirlpool);
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 protocol_fee_rate(&mut self, protocol_fee_rate: u16) -> &mut Self {
315 self.instruction.protocol_fee_rate = Some(protocol_fee_rate);
316 self
317 }
318 #[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 #[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 = SetProtocolFeeRateInstructionArgs {
356 protocol_fee_rate: self
357 .instruction
358 .protocol_fee_rate
359 .clone()
360 .expect("protocol_fee_rate is not set"),
361 };
362 let instruction = SetProtocolFeeRateCpi {
363 __program: self.instruction.__program,
364
365 whirlpools_config: self
366 .instruction
367 .whirlpools_config
368 .expect("whirlpools_config is not set"),
369
370 whirlpool: self.instruction.whirlpool.expect("whirlpool 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 SetProtocolFeeRateCpiBuilderInstruction<'a, 'b> {
387 __program: &'b solana_account_info::AccountInfo<'a>,
388 whirlpools_config: Option<&'b solana_account_info::AccountInfo<'a>>,
389 whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
390 fee_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
391 protocol_fee_rate: Option<u16>,
392 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
394}