1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct DeletePositionBundle {
14 pub position_bundle: solana_pubkey::Pubkey,
15
16 pub position_bundle_mint: solana_pubkey::Pubkey,
17
18 pub position_bundle_token_account: solana_pubkey::Pubkey,
19
20 pub position_bundle_owner: solana_pubkey::Pubkey,
21
22 pub receiver: solana_pubkey::Pubkey,
23
24 pub token_program: solana_pubkey::Pubkey,
25}
26
27impl DeletePositionBundle {
28 pub fn instruction(&self) -> solana_instruction::Instruction {
29 self.instruction_with_remaining_accounts(&[])
30 }
31 #[allow(clippy::arithmetic_side_effects)]
32 #[allow(clippy::vec_init_then_push)]
33 pub fn instruction_with_remaining_accounts(
34 &self,
35 remaining_accounts: &[solana_instruction::AccountMeta],
36 ) -> solana_instruction::Instruction {
37 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
38 accounts.push(solana_instruction::AccountMeta::new(
39 self.position_bundle,
40 false,
41 ));
42 accounts.push(solana_instruction::AccountMeta::new(
43 self.position_bundle_mint,
44 false,
45 ));
46 accounts.push(solana_instruction::AccountMeta::new(
47 self.position_bundle_token_account,
48 false,
49 ));
50 accounts.push(solana_instruction::AccountMeta::new_readonly(
51 self.position_bundle_owner,
52 true,
53 ));
54 accounts.push(solana_instruction::AccountMeta::new(self.receiver, false));
55 accounts.push(solana_instruction::AccountMeta::new_readonly(
56 self.token_program,
57 false,
58 ));
59 accounts.extend_from_slice(remaining_accounts);
60 let data = borsh::to_vec(&DeletePositionBundleInstructionData::new()).unwrap();
61
62 solana_instruction::Instruction {
63 program_id: crate::WHIRLPOOL_ID,
64 accounts,
65 data,
66 }
67 }
68}
69
70#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
71#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
72pub struct DeletePositionBundleInstructionData {
73 discriminator: [u8; 8],
74}
75
76impl DeletePositionBundleInstructionData {
77 pub fn new() -> Self {
78 Self {
79 discriminator: [100, 25, 99, 2, 217, 239, 124, 173],
80 }
81 }
82}
83
84impl Default for DeletePositionBundleInstructionData {
85 fn default() -> Self {
86 Self::new()
87 }
88}
89
90#[derive(Clone, Debug, Default)]
101pub struct DeletePositionBundleBuilder {
102 position_bundle: Option<solana_pubkey::Pubkey>,
103 position_bundle_mint: Option<solana_pubkey::Pubkey>,
104 position_bundle_token_account: Option<solana_pubkey::Pubkey>,
105 position_bundle_owner: Option<solana_pubkey::Pubkey>,
106 receiver: Option<solana_pubkey::Pubkey>,
107 token_program: Option<solana_pubkey::Pubkey>,
108 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
109}
110
111impl DeletePositionBundleBuilder {
112 pub fn new() -> Self {
113 Self::default()
114 }
115 #[inline(always)]
116 pub fn position_bundle(&mut self, position_bundle: solana_pubkey::Pubkey) -> &mut Self {
117 self.position_bundle = Some(position_bundle);
118 self
119 }
120 #[inline(always)]
121 pub fn position_bundle_mint(
122 &mut self,
123 position_bundle_mint: solana_pubkey::Pubkey,
124 ) -> &mut Self {
125 self.position_bundle_mint = Some(position_bundle_mint);
126 self
127 }
128 #[inline(always)]
129 pub fn position_bundle_token_account(
130 &mut self,
131 position_bundle_token_account: solana_pubkey::Pubkey,
132 ) -> &mut Self {
133 self.position_bundle_token_account = Some(position_bundle_token_account);
134 self
135 }
136 #[inline(always)]
137 pub fn position_bundle_owner(
138 &mut self,
139 position_bundle_owner: solana_pubkey::Pubkey,
140 ) -> &mut Self {
141 self.position_bundle_owner = Some(position_bundle_owner);
142 self
143 }
144 #[inline(always)]
145 pub fn receiver(&mut self, receiver: solana_pubkey::Pubkey) -> &mut Self {
146 self.receiver = Some(receiver);
147 self
148 }
149 #[inline(always)]
151 pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
152 self.token_program = Some(token_program);
153 self
154 }
155 #[inline(always)]
157 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
158 self.__remaining_accounts.push(account);
159 self
160 }
161 #[inline(always)]
163 pub fn add_remaining_accounts(
164 &mut self,
165 accounts: &[solana_instruction::AccountMeta],
166 ) -> &mut Self {
167 self.__remaining_accounts.extend_from_slice(accounts);
168 self
169 }
170 #[allow(clippy::clone_on_copy)]
171 pub fn instruction(&self) -> solana_instruction::Instruction {
172 let accounts = DeletePositionBundle {
173 position_bundle: self.position_bundle.expect("position_bundle is not set"),
174 position_bundle_mint: self
175 .position_bundle_mint
176 .expect("position_bundle_mint is not set"),
177 position_bundle_token_account: self
178 .position_bundle_token_account
179 .expect("position_bundle_token_account is not set"),
180 position_bundle_owner: self
181 .position_bundle_owner
182 .expect("position_bundle_owner is not set"),
183 receiver: self.receiver.expect("receiver is not set"),
184 token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
185 "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
186 )),
187 };
188
189 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
190 }
191}
192
193pub struct DeletePositionBundleCpiAccounts<'a, 'b> {
195 pub position_bundle: &'b solana_account_info::AccountInfo<'a>,
196
197 pub position_bundle_mint: &'b solana_account_info::AccountInfo<'a>,
198
199 pub position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
200
201 pub position_bundle_owner: &'b solana_account_info::AccountInfo<'a>,
202
203 pub receiver: &'b solana_account_info::AccountInfo<'a>,
204
205 pub token_program: &'b solana_account_info::AccountInfo<'a>,
206}
207
208pub struct DeletePositionBundleCpi<'a, 'b> {
210 pub __program: &'b solana_account_info::AccountInfo<'a>,
212
213 pub position_bundle: &'b solana_account_info::AccountInfo<'a>,
214
215 pub position_bundle_mint: &'b solana_account_info::AccountInfo<'a>,
216
217 pub position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
218
219 pub position_bundle_owner: &'b solana_account_info::AccountInfo<'a>,
220
221 pub receiver: &'b solana_account_info::AccountInfo<'a>,
222
223 pub token_program: &'b solana_account_info::AccountInfo<'a>,
224}
225
226impl<'a, 'b> DeletePositionBundleCpi<'a, 'b> {
227 pub fn new(
228 program: &'b solana_account_info::AccountInfo<'a>,
229 accounts: DeletePositionBundleCpiAccounts<'a, 'b>,
230 ) -> Self {
231 Self {
232 __program: program,
233 position_bundle: accounts.position_bundle,
234 position_bundle_mint: accounts.position_bundle_mint,
235 position_bundle_token_account: accounts.position_bundle_token_account,
236 position_bundle_owner: accounts.position_bundle_owner,
237 receiver: accounts.receiver,
238 token_program: accounts.token_program,
239 }
240 }
241 #[inline(always)]
242 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
243 self.invoke_signed_with_remaining_accounts(&[], &[])
244 }
245 #[inline(always)]
246 pub fn invoke_with_remaining_accounts(
247 &self,
248 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
249 ) -> solana_program_entrypoint::ProgramResult {
250 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
251 }
252 #[inline(always)]
253 pub fn invoke_signed(
254 &self,
255 signers_seeds: &[&[&[u8]]],
256 ) -> solana_program_entrypoint::ProgramResult {
257 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
258 }
259 #[allow(clippy::arithmetic_side_effects)]
260 #[allow(clippy::clone_on_copy)]
261 #[allow(clippy::vec_init_then_push)]
262 pub fn invoke_signed_with_remaining_accounts(
263 &self,
264 signers_seeds: &[&[&[u8]]],
265 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
266 ) -> solana_program_entrypoint::ProgramResult {
267 let mut accounts = Vec::with_capacity(6 + remaining_accounts.len());
268 accounts.push(solana_instruction::AccountMeta::new(
269 *self.position_bundle.key,
270 false,
271 ));
272 accounts.push(solana_instruction::AccountMeta::new(
273 *self.position_bundle_mint.key,
274 false,
275 ));
276 accounts.push(solana_instruction::AccountMeta::new(
277 *self.position_bundle_token_account.key,
278 false,
279 ));
280 accounts.push(solana_instruction::AccountMeta::new_readonly(
281 *self.position_bundle_owner.key,
282 true,
283 ));
284 accounts.push(solana_instruction::AccountMeta::new(
285 *self.receiver.key,
286 false,
287 ));
288 accounts.push(solana_instruction::AccountMeta::new_readonly(
289 *self.token_program.key,
290 false,
291 ));
292 remaining_accounts.iter().for_each(|remaining_account| {
293 accounts.push(solana_instruction::AccountMeta {
294 pubkey: *remaining_account.0.key,
295 is_signer: remaining_account.1,
296 is_writable: remaining_account.2,
297 })
298 });
299 let data = borsh::to_vec(&DeletePositionBundleInstructionData::new()).unwrap();
300
301 let instruction = solana_instruction::Instruction {
302 program_id: crate::WHIRLPOOL_ID,
303 accounts,
304 data,
305 };
306 let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len());
307 account_infos.push(self.__program.clone());
308 account_infos.push(self.position_bundle.clone());
309 account_infos.push(self.position_bundle_mint.clone());
310 account_infos.push(self.position_bundle_token_account.clone());
311 account_infos.push(self.position_bundle_owner.clone());
312 account_infos.push(self.receiver.clone());
313 account_infos.push(self.token_program.clone());
314 remaining_accounts
315 .iter()
316 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
317
318 if signers_seeds.is_empty() {
319 solana_cpi::invoke(&instruction, &account_infos)
320 } else {
321 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
322 }
323 }
324}
325
326#[derive(Clone, Debug)]
337pub struct DeletePositionBundleCpiBuilder<'a, 'b> {
338 instruction: Box<DeletePositionBundleCpiBuilderInstruction<'a, 'b>>,
339}
340
341impl<'a, 'b> DeletePositionBundleCpiBuilder<'a, 'b> {
342 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
343 let instruction = Box::new(DeletePositionBundleCpiBuilderInstruction {
344 __program: program,
345 position_bundle: None,
346 position_bundle_mint: None,
347 position_bundle_token_account: None,
348 position_bundle_owner: None,
349 receiver: None,
350 token_program: None,
351 __remaining_accounts: Vec::new(),
352 });
353 Self { instruction }
354 }
355 #[inline(always)]
356 pub fn position_bundle(
357 &mut self,
358 position_bundle: &'b solana_account_info::AccountInfo<'a>,
359 ) -> &mut Self {
360 self.instruction.position_bundle = Some(position_bundle);
361 self
362 }
363 #[inline(always)]
364 pub fn position_bundle_mint(
365 &mut self,
366 position_bundle_mint: &'b solana_account_info::AccountInfo<'a>,
367 ) -> &mut Self {
368 self.instruction.position_bundle_mint = Some(position_bundle_mint);
369 self
370 }
371 #[inline(always)]
372 pub fn position_bundle_token_account(
373 &mut self,
374 position_bundle_token_account: &'b solana_account_info::AccountInfo<'a>,
375 ) -> &mut Self {
376 self.instruction.position_bundle_token_account = Some(position_bundle_token_account);
377 self
378 }
379 #[inline(always)]
380 pub fn position_bundle_owner(
381 &mut self,
382 position_bundle_owner: &'b solana_account_info::AccountInfo<'a>,
383 ) -> &mut Self {
384 self.instruction.position_bundle_owner = Some(position_bundle_owner);
385 self
386 }
387 #[inline(always)]
388 pub fn receiver(&mut self, receiver: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
389 self.instruction.receiver = Some(receiver);
390 self
391 }
392 #[inline(always)]
393 pub fn token_program(
394 &mut self,
395 token_program: &'b solana_account_info::AccountInfo<'a>,
396 ) -> &mut Self {
397 self.instruction.token_program = Some(token_program);
398 self
399 }
400 #[inline(always)]
402 pub fn add_remaining_account(
403 &mut self,
404 account: &'b solana_account_info::AccountInfo<'a>,
405 is_writable: bool,
406 is_signer: bool,
407 ) -> &mut Self {
408 self.instruction
409 .__remaining_accounts
410 .push((account, is_writable, is_signer));
411 self
412 }
413 #[inline(always)]
418 pub fn add_remaining_accounts(
419 &mut self,
420 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
421 ) -> &mut Self {
422 self.instruction
423 .__remaining_accounts
424 .extend_from_slice(accounts);
425 self
426 }
427 #[inline(always)]
428 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
429 self.invoke_signed(&[])
430 }
431 #[allow(clippy::clone_on_copy)]
432 #[allow(clippy::vec_init_then_push)]
433 pub fn invoke_signed(
434 &self,
435 signers_seeds: &[&[&[u8]]],
436 ) -> solana_program_entrypoint::ProgramResult {
437 let instruction = DeletePositionBundleCpi {
438 __program: self.instruction.__program,
439
440 position_bundle: self
441 .instruction
442 .position_bundle
443 .expect("position_bundle is not set"),
444
445 position_bundle_mint: self
446 .instruction
447 .position_bundle_mint
448 .expect("position_bundle_mint is not set"),
449
450 position_bundle_token_account: self
451 .instruction
452 .position_bundle_token_account
453 .expect("position_bundle_token_account is not set"),
454
455 position_bundle_owner: self
456 .instruction
457 .position_bundle_owner
458 .expect("position_bundle_owner is not set"),
459
460 receiver: self.instruction.receiver.expect("receiver is not set"),
461
462 token_program: self
463 .instruction
464 .token_program
465 .expect("token_program is not set"),
466 };
467 instruction.invoke_signed_with_remaining_accounts(
468 signers_seeds,
469 &self.instruction.__remaining_accounts,
470 )
471 }
472}
473
474#[derive(Clone, Debug)]
475struct DeletePositionBundleCpiBuilderInstruction<'a, 'b> {
476 __program: &'b solana_account_info::AccountInfo<'a>,
477 position_bundle: Option<&'b solana_account_info::AccountInfo<'a>>,
478 position_bundle_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
479 position_bundle_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
480 position_bundle_owner: Option<&'b solana_account_info::AccountInfo<'a>>,
481 receiver: Option<&'b solana_account_info::AccountInfo<'a>>,
482 token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
483 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
485}