1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11#[derive(Debug)]
13pub struct ClosePosition2 {
14 pub position: solana_pubkey::Pubkey,
15
16 pub sender: solana_pubkey::Pubkey,
17
18 pub rent_receiver: solana_pubkey::Pubkey,
19
20 pub event_authority: solana_pubkey::Pubkey,
21
22 pub program: solana_pubkey::Pubkey,
23}
24
25impl ClosePosition2 {
26 pub fn instruction(&self) -> solana_instruction::Instruction {
27 self.instruction_with_remaining_accounts(&[])
28 }
29 #[allow(clippy::arithmetic_side_effects)]
30 #[allow(clippy::vec_init_then_push)]
31 pub fn instruction_with_remaining_accounts(
32 &self,
33 remaining_accounts: &[solana_instruction::AccountMeta],
34 ) -> solana_instruction::Instruction {
35 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
36 accounts.push(solana_instruction::AccountMeta::new(self.position, false));
37 accounts.push(solana_instruction::AccountMeta::new_readonly(
38 self.sender,
39 true,
40 ));
41 accounts.push(solana_instruction::AccountMeta::new(
42 self.rent_receiver,
43 false,
44 ));
45 accounts.push(solana_instruction::AccountMeta::new_readonly(
46 self.event_authority,
47 false,
48 ));
49 accounts.push(solana_instruction::AccountMeta::new_readonly(
50 self.program,
51 false,
52 ));
53 accounts.extend_from_slice(remaining_accounts);
54 let data = borsh::to_vec(&ClosePosition2InstructionData::new()).unwrap();
55
56 solana_instruction::Instruction {
57 program_id: crate::LB_CLMM_ID,
58 accounts,
59 data,
60 }
61 }
62}
63
64#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
66pub struct ClosePosition2InstructionData {
67 discriminator: [u8; 8],
68}
69
70impl ClosePosition2InstructionData {
71 pub fn new() -> Self {
72 Self {
73 discriminator: [174, 90, 35, 115, 186, 40, 147, 226],
74 }
75 }
76}
77
78impl Default for ClosePosition2InstructionData {
79 fn default() -> Self {
80 Self::new()
81 }
82}
83
84#[derive(Clone, Debug, Default)]
94pub struct ClosePosition2Builder {
95 position: Option<solana_pubkey::Pubkey>,
96 sender: Option<solana_pubkey::Pubkey>,
97 rent_receiver: Option<solana_pubkey::Pubkey>,
98 event_authority: Option<solana_pubkey::Pubkey>,
99 program: Option<solana_pubkey::Pubkey>,
100 __remaining_accounts: Vec<solana_instruction::AccountMeta>,
101}
102
103impl ClosePosition2Builder {
104 pub fn new() -> Self {
105 Self::default()
106 }
107 #[inline(always)]
108 pub fn position(&mut self, position: solana_pubkey::Pubkey) -> &mut Self {
109 self.position = Some(position);
110 self
111 }
112 #[inline(always)]
113 pub fn sender(&mut self, sender: solana_pubkey::Pubkey) -> &mut Self {
114 self.sender = Some(sender);
115 self
116 }
117 #[inline(always)]
118 pub fn rent_receiver(&mut self, rent_receiver: solana_pubkey::Pubkey) -> &mut Self {
119 self.rent_receiver = Some(rent_receiver);
120 self
121 }
122 #[inline(always)]
123 pub fn event_authority(&mut self, event_authority: solana_pubkey::Pubkey) -> &mut Self {
124 self.event_authority = Some(event_authority);
125 self
126 }
127 #[inline(always)]
128 pub fn program(&mut self, program: solana_pubkey::Pubkey) -> &mut Self {
129 self.program = Some(program);
130 self
131 }
132 #[inline(always)]
134 pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
135 self.__remaining_accounts.push(account);
136 self
137 }
138 #[inline(always)]
140 pub fn add_remaining_accounts(
141 &mut self,
142 accounts: &[solana_instruction::AccountMeta],
143 ) -> &mut Self {
144 self.__remaining_accounts.extend_from_slice(accounts);
145 self
146 }
147 #[allow(clippy::clone_on_copy)]
148 pub fn instruction(&self) -> solana_instruction::Instruction {
149 let accounts = ClosePosition2 {
150 position: self.position.expect("position is not set"),
151 sender: self.sender.expect("sender is not set"),
152 rent_receiver: self.rent_receiver.expect("rent_receiver is not set"),
153 event_authority: self.event_authority.expect("event_authority is not set"),
154 program: self.program.expect("program is not set"),
155 };
156
157 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
158 }
159}
160
161pub struct ClosePosition2CpiAccounts<'a, 'b> {
163 pub position: &'b solana_account_info::AccountInfo<'a>,
164
165 pub sender: &'b solana_account_info::AccountInfo<'a>,
166
167 pub rent_receiver: &'b solana_account_info::AccountInfo<'a>,
168
169 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
170
171 pub program: &'b solana_account_info::AccountInfo<'a>,
172}
173
174pub struct ClosePosition2Cpi<'a, 'b> {
176 pub __program: &'b solana_account_info::AccountInfo<'a>,
178
179 pub position: &'b solana_account_info::AccountInfo<'a>,
180
181 pub sender: &'b solana_account_info::AccountInfo<'a>,
182
183 pub rent_receiver: &'b solana_account_info::AccountInfo<'a>,
184
185 pub event_authority: &'b solana_account_info::AccountInfo<'a>,
186
187 pub program: &'b solana_account_info::AccountInfo<'a>,
188}
189
190impl<'a, 'b> ClosePosition2Cpi<'a, 'b> {
191 pub fn new(
192 program: &'b solana_account_info::AccountInfo<'a>,
193 accounts: ClosePosition2CpiAccounts<'a, 'b>,
194 ) -> Self {
195 Self {
196 __program: program,
197 position: accounts.position,
198 sender: accounts.sender,
199 rent_receiver: accounts.rent_receiver,
200 event_authority: accounts.event_authority,
201 program: accounts.program,
202 }
203 }
204 #[inline(always)]
205 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
206 self.invoke_signed_with_remaining_accounts(&[], &[])
207 }
208 #[inline(always)]
209 pub fn invoke_with_remaining_accounts(
210 &self,
211 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
212 ) -> solana_program_entrypoint::ProgramResult {
213 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
214 }
215 #[inline(always)]
216 pub fn invoke_signed(
217 &self,
218 signers_seeds: &[&[&[u8]]],
219 ) -> solana_program_entrypoint::ProgramResult {
220 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
221 }
222 #[allow(clippy::arithmetic_side_effects)]
223 #[allow(clippy::clone_on_copy)]
224 #[allow(clippy::vec_init_then_push)]
225 pub fn invoke_signed_with_remaining_accounts(
226 &self,
227 signers_seeds: &[&[&[u8]]],
228 remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
229 ) -> solana_program_entrypoint::ProgramResult {
230 let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
231 accounts.push(solana_instruction::AccountMeta::new(
232 *self.position.key,
233 false,
234 ));
235 accounts.push(solana_instruction::AccountMeta::new_readonly(
236 *self.sender.key,
237 true,
238 ));
239 accounts.push(solana_instruction::AccountMeta::new(
240 *self.rent_receiver.key,
241 false,
242 ));
243 accounts.push(solana_instruction::AccountMeta::new_readonly(
244 *self.event_authority.key,
245 false,
246 ));
247 accounts.push(solana_instruction::AccountMeta::new_readonly(
248 *self.program.key,
249 false,
250 ));
251 remaining_accounts.iter().for_each(|remaining_account| {
252 accounts.push(solana_instruction::AccountMeta {
253 pubkey: *remaining_account.0.key,
254 is_signer: remaining_account.1,
255 is_writable: remaining_account.2,
256 })
257 });
258 let data = borsh::to_vec(&ClosePosition2InstructionData::new()).unwrap();
259
260 let instruction = solana_instruction::Instruction {
261 program_id: crate::LB_CLMM_ID,
262 accounts,
263 data,
264 };
265 let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
266 account_infos.push(self.__program.clone());
267 account_infos.push(self.position.clone());
268 account_infos.push(self.sender.clone());
269 account_infos.push(self.rent_receiver.clone());
270 account_infos.push(self.event_authority.clone());
271 account_infos.push(self.program.clone());
272 remaining_accounts
273 .iter()
274 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
275
276 if signers_seeds.is_empty() {
277 solana_cpi::invoke(&instruction, &account_infos)
278 } else {
279 solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
280 }
281 }
282}
283
284#[derive(Clone, Debug)]
294pub struct ClosePosition2CpiBuilder<'a, 'b> {
295 instruction: Box<ClosePosition2CpiBuilderInstruction<'a, 'b>>,
296}
297
298impl<'a, 'b> ClosePosition2CpiBuilder<'a, 'b> {
299 pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
300 let instruction = Box::new(ClosePosition2CpiBuilderInstruction {
301 __program: program,
302 position: None,
303 sender: None,
304 rent_receiver: None,
305 event_authority: None,
306 program: None,
307 __remaining_accounts: Vec::new(),
308 });
309 Self { instruction }
310 }
311 #[inline(always)]
312 pub fn position(&mut self, position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
313 self.instruction.position = Some(position);
314 self
315 }
316 #[inline(always)]
317 pub fn sender(&mut self, sender: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
318 self.instruction.sender = Some(sender);
319 self
320 }
321 #[inline(always)]
322 pub fn rent_receiver(
323 &mut self,
324 rent_receiver: &'b solana_account_info::AccountInfo<'a>,
325 ) -> &mut Self {
326 self.instruction.rent_receiver = Some(rent_receiver);
327 self
328 }
329 #[inline(always)]
330 pub fn event_authority(
331 &mut self,
332 event_authority: &'b solana_account_info::AccountInfo<'a>,
333 ) -> &mut Self {
334 self.instruction.event_authority = Some(event_authority);
335 self
336 }
337 #[inline(always)]
338 pub fn program(&mut self, program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
339 self.instruction.program = Some(program);
340 self
341 }
342 #[inline(always)]
344 pub fn add_remaining_account(
345 &mut self,
346 account: &'b solana_account_info::AccountInfo<'a>,
347 is_writable: bool,
348 is_signer: bool,
349 ) -> &mut Self {
350 self.instruction
351 .__remaining_accounts
352 .push((account, is_writable, is_signer));
353 self
354 }
355 #[inline(always)]
360 pub fn add_remaining_accounts(
361 &mut self,
362 accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
363 ) -> &mut Self {
364 self.instruction
365 .__remaining_accounts
366 .extend_from_slice(accounts);
367 self
368 }
369 #[inline(always)]
370 pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
371 self.invoke_signed(&[])
372 }
373 #[allow(clippy::clone_on_copy)]
374 #[allow(clippy::vec_init_then_push)]
375 pub fn invoke_signed(
376 &self,
377 signers_seeds: &[&[&[u8]]],
378 ) -> solana_program_entrypoint::ProgramResult {
379 let instruction = ClosePosition2Cpi {
380 __program: self.instruction.__program,
381
382 position: self.instruction.position.expect("position is not set"),
383
384 sender: self.instruction.sender.expect("sender is not set"),
385
386 rent_receiver: self
387 .instruction
388 .rent_receiver
389 .expect("rent_receiver is not set"),
390
391 event_authority: self
392 .instruction
393 .event_authority
394 .expect("event_authority is not set"),
395
396 program: self.instruction.program.expect("program is not set"),
397 };
398 instruction.invoke_signed_with_remaining_accounts(
399 signers_seeds,
400 &self.instruction.__remaining_accounts,
401 )
402 }
403}
404
405#[derive(Clone, Debug)]
406struct ClosePosition2CpiBuilderInstruction<'a, 'b> {
407 __program: &'b solana_account_info::AccountInfo<'a>,
408 position: Option<&'b solana_account_info::AccountInfo<'a>>,
409 sender: Option<&'b solana_account_info::AccountInfo<'a>>,
410 rent_receiver: Option<&'b solana_account_info::AccountInfo<'a>>,
411 event_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
412 program: Option<&'b solana_account_info::AccountInfo<'a>>,
413 __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
415}