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