1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct CollectProtocolFees {
14 pub whirlpools_config: solana_pubkey::Pubkey,
15
16 pub whirlpool: solana_pubkey::Pubkey,
17
18 pub collect_protocol_fees_authority: solana_pubkey::Pubkey,
19
20 pub token_vault_a: solana_pubkey::Pubkey,
21
22 pub token_vault_b: solana_pubkey::Pubkey,
23
24 pub token_destination_a: solana_pubkey::Pubkey,
25
26 pub token_destination_b: solana_pubkey::Pubkey,
27
28 pub token_program: solana_pubkey::Pubkey,
29}
30
31impl CollectProtocolFees {
32 pub fn instruction(&self) -> solana_instruction::Instruction {
33 self.instruction_with_remaining_accounts(&[])
34 }
35 #[allow(clippy::arithmetic_side_effects)]
36 #[allow(clippy::vec_init_then_push)]
37 pub fn instruction_with_remaining_accounts(
38 &self,
39 remaining_accounts: &[solana_instruction::AccountMeta],
40 ) -> solana_instruction::Instruction {
41 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
42 accounts.push(solana_instruction::AccountMeta::new_readonly(
43 self.whirlpools_config,
44 false,
45 ));
46 accounts.push(solana_instruction::AccountMeta::new(self.whirlpool, false));
47 accounts.push(solana_instruction::AccountMeta::new_readonly(
48 self.collect_protocol_fees_authority,
49 true,
50 ));
51 accounts.push(solana_instruction::AccountMeta::new(
52 self.token_vault_a,
53 false,
54 ));
55 accounts.push(solana_instruction::AccountMeta::new(
56 self.token_vault_b,
57 false,
58 ));
59 accounts.push(solana_instruction::AccountMeta::new(
60 self.token_destination_a,
61 false,
62 ));
63 accounts.push(solana_instruction::AccountMeta::new(
64 self.token_destination_b,
65 false,
66 ));
67 accounts.push(solana_instruction::AccountMeta::new_readonly(
68 self.token_program,
69 false,
70 ));
71 accounts.extend_from_slice(remaining_accounts);
72 let data = borsh::to_vec(&CollectProtocolFeesInstructionData::new()).unwrap();
73
74 solana_instruction::Instruction {
75 program_id: crate::WHIRLPOOL_ID,
76 accounts,
77 data,
78 }
79 }
80}
81
82#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
83#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
84pub struct CollectProtocolFeesInstructionData {
85 discriminator: [u8; 8],
86}
87
88impl CollectProtocolFeesInstructionData {
89 pub fn new() -> Self {
90 Self {
91 discriminator: [22, 67, 23, 98, 150, 178, 70, 220],
92 }
93 }
94}
95
96impl Default for CollectProtocolFeesInstructionData {
97 fn default() -> Self {
98 Self::new()
99 }
100}
101
102#[derive(Clone, Debug, Default)]
115pub struct CollectProtocolFeesBuilder {
116 whirlpools_config: Option<solana_pubkey::Pubkey>,
117 whirlpool: Option<solana_pubkey::Pubkey>,
118 collect_protocol_fees_authority: Option<solana_pubkey::Pubkey>,
119 token_vault_a: Option<solana_pubkey::Pubkey>,
120 token_vault_b: Option<solana_pubkey::Pubkey>,
121 token_destination_a: Option<solana_pubkey::Pubkey>,
122 token_destination_b: Option<solana_pubkey::Pubkey>,
123 token_program: Option<solana_pubkey::Pubkey>,
124 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
125}
126
127impl CollectProtocolFeesBuilder {
128 pub fn new() -> Self {
129 Self::default()
130 }
131 #[inline(always)]
132 pub fn whirlpools_config(&mut self, whirlpools_config: solana_pubkey::Pubkey) -> &mut Self {
133 self.whirlpools_config = Some(whirlpools_config);
134 self
135 }
136 #[inline(always)]
137 pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
138 self.whirlpool = Some(whirlpool);
139 self
140 }
141 #[inline(always)]
142 pub fn collect_protocol_fees_authority(
143 &mut self,
144 collect_protocol_fees_authority: solana_pubkey::Pubkey,
145 ) -> &mut Self {
146 self.collect_protocol_fees_authority = Some(collect_protocol_fees_authority);
147 self
148 }
149 #[inline(always)]
150 pub fn token_vault_a(&mut self, token_vault_a: solana_pubkey::Pubkey) -> &mut Self {
151 self.token_vault_a = Some(token_vault_a);
152 self
153 }
154 #[inline(always)]
155 pub fn token_vault_b(&mut self, token_vault_b: solana_pubkey::Pubkey) -> &mut Self {
156 self.token_vault_b = Some(token_vault_b);
157 self
158 }
159 #[inline(always)]
160 pub fn token_destination_a(&mut self, token_destination_a: solana_pubkey::Pubkey) -> &mut Self {
161 self.token_destination_a = Some(token_destination_a);
162 self
163 }
164 #[inline(always)]
165 pub fn token_destination_b(&mut self, token_destination_b: solana_pubkey::Pubkey) -> &mut Self {
166 self.token_destination_b = Some(token_destination_b);
167 self
168 }
169 #[inline(always)]
171 pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
172 self.token_program = Some(token_program);
173 self
174 }
175 #[inline(always)]
177 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
178 self.__remaining_accounts.push(account);
179 self
180 }
181 #[inline(always)]
183 pub fn add_remaining_accounts(
184 &mut self,
185 accounts: &[solana_instruction::AccountMeta],
186 ) -> &mut Self {
187 self.__remaining_accounts.extend_from_slice(accounts);
188 self
189 }
190 #[allow(clippy::clone_on_copy)]
191 pub fn instruction(&self) -> solana_instruction::Instruction {
192 let accounts = CollectProtocolFees {
193 whirlpools_config: self
194 .whirlpools_config
195 .expect("whirlpools_config is not set"),
196 whirlpool: self.whirlpool.expect("whirlpool is not set"),
197 collect_protocol_fees_authority: self
198 .collect_protocol_fees_authority
199 .expect("collect_protocol_fees_authority is not set"),
200 token_vault_a: self.token_vault_a.expect("token_vault_a is not set"),
201 token_vault_b: self.token_vault_b.expect("token_vault_b is not set"),
202 token_destination_a: self
203 .token_destination_a
204 .expect("token_destination_a is not set"),
205 token_destination_b: self
206 .token_destination_b
207 .expect("token_destination_b is not set"),
208 token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
209 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
210 )),
211 };
212
213 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
214 }
215}
216
217pub struct CollectProtocolFeesCpiAccounts<'a, 'b> {
219 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
220
221 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
222
223 pub collect_protocol_fees_authority: &'b solana_account_info::AccountInfo<'a>,
224
225 pub token_vault_a: &'b solana_account_info::AccountInfo<'a>,
226
227 pub token_vault_b: &'b solana_account_info::AccountInfo<'a>,
228
229 pub token_destination_a: &'b solana_account_info::AccountInfo<'a>,
230
231 pub token_destination_b: &'b solana_account_info::AccountInfo<'a>,
232
233 pub token_program: &'b solana_account_info::AccountInfo<'a>,
234}
235
236pub struct CollectProtocolFeesCpi<'a, 'b> {
238 pub __program: &'b solana_account_info::AccountInfo<'a>,
240
241 pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
242
243 pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
244
245 pub collect_protocol_fees_authority: &'b solana_account_info::AccountInfo<'a>,
246
247 pub token_vault_a: &'b solana_account_info::AccountInfo<'a>,
248
249 pub token_vault_b: &'b solana_account_info::AccountInfo<'a>,
250
251 pub token_destination_a: &'b solana_account_info::AccountInfo<'a>,
252
253 pub token_destination_b: &'b solana_account_info::AccountInfo<'a>,
254
255 pub token_program: &'b solana_account_info::AccountInfo<'a>,
256}
257
258impl<'a, 'b> CollectProtocolFeesCpi<'a, 'b> {
259 pub fn new(
260 program: &'b solana_account_info::AccountInfo<'a>,
261 accounts: CollectProtocolFeesCpiAccounts<'a, 'b>,
262 ) -> Self {
263 Self {
264 __program: program,
265 whirlpools_config: accounts.whirlpools_config,
266 whirlpool: accounts.whirlpool,
267 collect_protocol_fees_authority: accounts.collect_protocol_fees_authority,
268 token_vault_a: accounts.token_vault_a,
269 token_vault_b: accounts.token_vault_b,
270 token_destination_a: accounts.token_destination_a,
271 token_destination_b: accounts.token_destination_b,
272 token_program: accounts.token_program,
273 }
274 }
275 #[inline(always)]
276 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
277 self.invoke_signed_with_remaining_accounts(&[], &[])
278 }
279 #[inline(always)]
280 pub fn invoke_with_remaining_accounts(
281 &self,
282 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
283 ) -> solana_program_entrypoint::ProgramResult {
284 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
285 }
286 #[inline(always)]
287 pub fn invoke_signed(
288 &self,
289 signers_seeds: &[&[&[u8]]],
290 ) -> solana_program_entrypoint::ProgramResult {
291 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
292 }
293 #[allow(clippy::arithmetic_side_effects)]
294 #[allow(clippy::clone_on_copy)]
295 #[allow(clippy::vec_init_then_push)]
296 pub fn invoke_signed_with_remaining_accounts(
297 &self,
298 signers_seeds: &[&[&[u8]]],
299 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
300 ) -> solana_program_entrypoint::ProgramResult {
301 let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
302 accounts.push(solana_instruction::AccountMeta::new_readonly(
303 *self.whirlpools_config.key,
304 false,
305 ));
306 accounts.push(solana_instruction::AccountMeta::new(
307 *self.whirlpool.key,
308 false,
309 ));
310 accounts.push(solana_instruction::AccountMeta::new_readonly(
311 *self.collect_protocol_fees_authority.key,
312 true,
313 ));
314 accounts.push(solana_instruction::AccountMeta::new(
315 *self.token_vault_a.key,
316 false,
317 ));
318 accounts.push(solana_instruction::AccountMeta::new(
319 *self.token_vault_b.key,
320 false,
321 ));
322 accounts.push(solana_instruction::AccountMeta::new(
323 *self.token_destination_a.key,
324 false,
325 ));
326 accounts.push(solana_instruction::AccountMeta::new(
327 *self.token_destination_b.key,
328 false,
329 ));
330 accounts.push(solana_instruction::AccountMeta::new_readonly(
331 *self.token_program.key,
332 false,
333 ));
334 remaining_accounts.iter().for_each(|remaining_account| {
335 accounts.push(solana_instruction::AccountMeta {
336 pubkey: *remaining_account.0.key,
337 is_signer: remaining_account.1,
338 is_writable: remaining_account.2,
339 })
340 });
341 let data = borsh::to_vec(&CollectProtocolFeesInstructionData::new()).unwrap();
342
343 let instruction = solana_instruction::Instruction {
344 program_id: crate::WHIRLPOOL_ID,
345 accounts,
346 data,
347 };
348 let mut account_infos = Vec::with_capacity(9 + remaining_accounts.len());
349 account_infos.push(self.__program.clone());
350 account_infos.push(self.whirlpools_config.clone());
351 account_infos.push(self.whirlpool.clone());
352 account_infos.push(self.collect_protocol_fees_authority.clone());
353 account_infos.push(self.token_vault_a.clone());
354 account_infos.push(self.token_vault_b.clone());
355 account_infos.push(self.token_destination_a.clone());
356 account_infos.push(self.token_destination_b.clone());
357 account_infos.push(self.token_program.clone());
358 remaining_accounts
359 .iter()
360 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
361
362 if signers_seeds.is_empty() {
363 solana_cpi::invoke(&instruction, &account_infos)
364 } else {
365 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
366 }
367 }
368}
369
370#[derive(Clone, Debug)]
383pub struct CollectProtocolFeesCpiBuilder<'a, 'b> {
384 instruction: Box<CollectProtocolFeesCpiBuilderInstruction<'a, 'b>>,
385}
386
387impl<'a, 'b> CollectProtocolFeesCpiBuilder<'a, 'b> {
388 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
389 let instruction = Box::new(CollectProtocolFeesCpiBuilderInstruction {
390 __program: program,
391 whirlpools_config: None,
392 whirlpool: None,
393 collect_protocol_fees_authority: None,
394 token_vault_a: None,
395 token_vault_b: None,
396 token_destination_a: None,
397 token_destination_b: None,
398 token_program: None,
399 __remaining_accounts: Vec::new(),
400 });
401 Self { instruction }
402 }
403 #[inline(always)]
404 pub fn whirlpools_config(
405 &mut self,
406 whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
407 ) -> &mut Self {
408 self.instruction.whirlpools_config = Some(whirlpools_config);
409 self
410 }
411 #[inline(always)]
412 pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
413 self.instruction.whirlpool = Some(whirlpool);
414 self
415 }
416 #[inline(always)]
417 pub fn collect_protocol_fees_authority(
418 &mut self,
419 collect_protocol_fees_authority: &'b solana_account_info::AccountInfo<'a>,
420 ) -> &mut Self {
421 self.instruction.collect_protocol_fees_authority = Some(collect_protocol_fees_authority);
422 self
423 }
424 #[inline(always)]
425 pub fn token_vault_a(
426 &mut self,
427 token_vault_a: &'b solana_account_info::AccountInfo<'a>,
428 ) -> &mut Self {
429 self.instruction.token_vault_a = Some(token_vault_a);
430 self
431 }
432 #[inline(always)]
433 pub fn token_vault_b(
434 &mut self,
435 token_vault_b: &'b solana_account_info::AccountInfo<'a>,
436 ) -> &mut Self {
437 self.instruction.token_vault_b = Some(token_vault_b);
438 self
439 }
440 #[inline(always)]
441 pub fn token_destination_a(
442 &mut self,
443 token_destination_a: &'b solana_account_info::AccountInfo<'a>,
444 ) -> &mut Self {
445 self.instruction.token_destination_a = Some(token_destination_a);
446 self
447 }
448 #[inline(always)]
449 pub fn token_destination_b(
450 &mut self,
451 token_destination_b: &'b solana_account_info::AccountInfo<'a>,
452 ) -> &mut Self {
453 self.instruction.token_destination_b = Some(token_destination_b);
454 self
455 }
456 #[inline(always)]
457 pub fn token_program(
458 &mut self,
459 token_program: &'b solana_account_info::AccountInfo<'a>,
460 ) -> &mut Self {
461 self.instruction.token_program = Some(token_program);
462 self
463 }
464 #[inline(always)]
466 pub fn add_remaining_account(
467 &mut self,
468 account: &'b solana_account_info::AccountInfo<'a>,
469 is_writable: bool,
470 is_signer: bool,
471 ) -> &mut Self {
472 self.instruction
473 .__remaining_accounts
474 .push((account, is_writable, is_signer));
475 self
476 }
477 #[inline(always)]
482 pub fn add_remaining_accounts(
483 &mut self,
484 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
485 ) -> &mut Self {
486 self.instruction
487 .__remaining_accounts
488 .extend_from_slice(accounts);
489 self
490 }
491 #[inline(always)]
492 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
493 self.invoke_signed(&[])
494 }
495 #[allow(clippy::clone_on_copy)]
496 #[allow(clippy::vec_init_then_push)]
497 pub fn invoke_signed(
498 &self,
499 signers_seeds: &[&[&[u8]]],
500 ) -> solana_program_entrypoint::ProgramResult {
501 let instruction = CollectProtocolFeesCpi {
502 __program: self.instruction.__program,
503
504 whirlpools_config: self
505 .instruction
506 .whirlpools_config
507 .expect("whirlpools_config is not set"),
508
509 whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
510
511 collect_protocol_fees_authority: self
512 .instruction
513 .collect_protocol_fees_authority
514 .expect("collect_protocol_fees_authority is not set"),
515
516 token_vault_a: self
517 .instruction
518 .token_vault_a
519 .expect("token_vault_a is not set"),
520
521 token_vault_b: self
522 .instruction
523 .token_vault_b
524 .expect("token_vault_b is not set"),
525
526 token_destination_a: self
527 .instruction
528 .token_destination_a
529 .expect("token_destination_a is not set"),
530
531 token_destination_b: self
532 .instruction
533 .token_destination_b
534 .expect("token_destination_b is not set"),
535
536 token_program: self
537 .instruction
538 .token_program
539 .expect("token_program is not set"),
540 };
541 instruction.invoke_signed_with_remaining_accounts(
542 signers_seeds,
543 &self.instruction.__remaining_accounts,
544 )
545 }
546}
547
548#[derive(Clone, Debug)]
549struct CollectProtocolFeesCpiBuilderInstruction<'a, 'b> {
550 __program: &'b solana_account_info::AccountInfo<'a>,
551 whirlpools_config: Option<&'b solana_account_info::AccountInfo<'a>>,
552 whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
553 collect_protocol_fees_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
554 token_vault_a: Option<&'b solana_account_info::AccountInfo<'a>>,
555 token_vault_b: Option<&'b solana_account_info::AccountInfo<'a>>,
556 token_destination_a: Option<&'b solana_account_info::AccountInfo<'a>>,
557 token_destination_b: Option<&'b solana_account_info::AccountInfo<'a>>,
558 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
559 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
561}