tensor_amm/generated/instructions/
close_pool.rs1use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10
11pub struct ClosePool {
13 pub rent_payer: solana_program::pubkey::Pubkey,
15 pub owner: solana_program::pubkey::Pubkey,
17 pub pool: solana_program::pubkey::Pubkey,
19 pub system_program: solana_program::pubkey::Pubkey,
21}
22
23impl ClosePool {
24 pub fn instruction(&self) -> solana_program::instruction::Instruction {
25 self.instruction_with_remaining_accounts(&[])
26 }
27 #[allow(clippy::vec_init_then_push)]
28 pub fn instruction_with_remaining_accounts(
29 &self,
30 remaining_accounts: &[solana_program::instruction::AccountMeta],
31 ) -> solana_program::instruction::Instruction {
32 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
33 accounts.push(solana_program::instruction::AccountMeta::new(
34 self.rent_payer,
35 false,
36 ));
37 accounts.push(solana_program::instruction::AccountMeta::new(
38 self.owner, true,
39 ));
40 accounts.push(solana_program::instruction::AccountMeta::new(
41 self.pool, false,
42 ));
43 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
44 self.system_program,
45 false,
46 ));
47 accounts.extend_from_slice(remaining_accounts);
48 let data = ClosePoolInstructionData::new().try_to_vec().unwrap();
49
50 solana_program::instruction::Instruction {
51 program_id: crate::TENSOR_AMM_ID,
52 accounts,
53 data,
54 }
55 }
56}
57
58#[derive(BorshDeserialize, BorshSerialize)]
59pub struct ClosePoolInstructionData {
60 discriminator: [u8; 8],
61}
62
63impl ClosePoolInstructionData {
64 pub fn new() -> Self {
65 Self {
66 discriminator: [140, 189, 209, 23, 239, 62, 239, 11],
67 }
68 }
69}
70
71impl Default for ClosePoolInstructionData {
72 fn default() -> Self {
73 Self::new()
74 }
75}
76
77#[derive(Clone, Debug, Default)]
86pub struct ClosePoolBuilder {
87 rent_payer: Option<solana_program::pubkey::Pubkey>,
88 owner: Option<solana_program::pubkey::Pubkey>,
89 pool: Option<solana_program::pubkey::Pubkey>,
90 system_program: Option<solana_program::pubkey::Pubkey>,
91 __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
92}
93
94impl ClosePoolBuilder {
95 pub fn new() -> Self {
96 Self::default()
97 }
98 #[inline(always)]
100 pub fn rent_payer(&mut self, rent_payer: solana_program::pubkey::Pubkey) -> &mut Self {
101 self.rent_payer = Some(rent_payer);
102 self
103 }
104 #[inline(always)]
106 pub fn owner(&mut self, owner: solana_program::pubkey::Pubkey) -> &mut Self {
107 self.owner = Some(owner);
108 self
109 }
110 #[inline(always)]
112 pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
113 self.pool = Some(pool);
114 self
115 }
116 #[inline(always)]
119 pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
120 self.system_program = Some(system_program);
121 self
122 }
123 #[inline(always)]
125 pub fn add_remaining_account(
126 &mut self,
127 account: solana_program::instruction::AccountMeta,
128 ) -> &mut Self {
129 self.__remaining_accounts.push(account);
130 self
131 }
132 #[inline(always)]
134 pub fn add_remaining_accounts(
135 &mut self,
136 accounts: &[solana_program::instruction::AccountMeta],
137 ) -> &mut Self {
138 self.__remaining_accounts.extend_from_slice(accounts);
139 self
140 }
141 #[allow(clippy::clone_on_copy)]
142 pub fn instruction(&self) -> solana_program::instruction::Instruction {
143 let accounts = ClosePool {
144 rent_payer: self.rent_payer.expect("rent_payer is not set"),
145 owner: self.owner.expect("owner is not set"),
146 pool: self.pool.expect("pool is not set"),
147 system_program: self
148 .system_program
149 .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
150 };
151
152 accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
153 }
154}
155
156pub struct ClosePoolCpiAccounts<'a, 'b> {
158 pub rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
160 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
162 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
164 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
166}
167
168pub struct ClosePoolCpi<'a, 'b> {
170 pub __program: &'b solana_program::account_info::AccountInfo<'a>,
172 pub rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
174 pub owner: &'b solana_program::account_info::AccountInfo<'a>,
176 pub pool: &'b solana_program::account_info::AccountInfo<'a>,
178 pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
180}
181
182impl<'a, 'b> ClosePoolCpi<'a, 'b> {
183 pub fn new(
184 program: &'b solana_program::account_info::AccountInfo<'a>,
185 accounts: ClosePoolCpiAccounts<'a, 'b>,
186 ) -> Self {
187 Self {
188 __program: program,
189 rent_payer: accounts.rent_payer,
190 owner: accounts.owner,
191 pool: accounts.pool,
192 system_program: accounts.system_program,
193 }
194 }
195 #[inline(always)]
196 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
197 self.invoke_signed_with_remaining_accounts(&[], &[])
198 }
199 #[inline(always)]
200 pub fn invoke_with_remaining_accounts(
201 &self,
202 remaining_accounts: &[(
203 &'b solana_program::account_info::AccountInfo<'a>,
204 bool,
205 bool,
206 )],
207 ) -> solana_program::entrypoint::ProgramResult {
208 self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
209 }
210 #[inline(always)]
211 pub fn invoke_signed(
212 &self,
213 signers_seeds: &[&[&[u8]]],
214 ) -> solana_program::entrypoint::ProgramResult {
215 self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
216 }
217 #[allow(clippy::clone_on_copy)]
218 #[allow(clippy::vec_init_then_push)]
219 pub fn invoke_signed_with_remaining_accounts(
220 &self,
221 signers_seeds: &[&[&[u8]]],
222 remaining_accounts: &[(
223 &'b solana_program::account_info::AccountInfo<'a>,
224 bool,
225 bool,
226 )],
227 ) -> solana_program::entrypoint::ProgramResult {
228 let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
229 accounts.push(solana_program::instruction::AccountMeta::new(
230 *self.rent_payer.key,
231 false,
232 ));
233 accounts.push(solana_program::instruction::AccountMeta::new(
234 *self.owner.key,
235 true,
236 ));
237 accounts.push(solana_program::instruction::AccountMeta::new(
238 *self.pool.key,
239 false,
240 ));
241 accounts.push(solana_program::instruction::AccountMeta::new_readonly(
242 *self.system_program.key,
243 false,
244 ));
245 remaining_accounts.iter().for_each(|remaining_account| {
246 accounts.push(solana_program::instruction::AccountMeta {
247 pubkey: *remaining_account.0.key,
248 is_signer: remaining_account.1,
249 is_writable: remaining_account.2,
250 })
251 });
252 let data = ClosePoolInstructionData::new().try_to_vec().unwrap();
253
254 let instruction = solana_program::instruction::Instruction {
255 program_id: crate::TENSOR_AMM_ID,
256 accounts,
257 data,
258 };
259 let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
260 account_infos.push(self.__program.clone());
261 account_infos.push(self.rent_payer.clone());
262 account_infos.push(self.owner.clone());
263 account_infos.push(self.pool.clone());
264 account_infos.push(self.system_program.clone());
265 remaining_accounts
266 .iter()
267 .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
268
269 if signers_seeds.is_empty() {
270 solana_program::program::invoke(&instruction, &account_infos)
271 } else {
272 solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
273 }
274 }
275}
276
277#[derive(Clone, Debug)]
286pub struct ClosePoolCpiBuilder<'a, 'b> {
287 instruction: Box<ClosePoolCpiBuilderInstruction<'a, 'b>>,
288}
289
290impl<'a, 'b> ClosePoolCpiBuilder<'a, 'b> {
291 pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
292 let instruction = Box::new(ClosePoolCpiBuilderInstruction {
293 __program: program,
294 rent_payer: None,
295 owner: None,
296 pool: None,
297 system_program: None,
298 __remaining_accounts: Vec::new(),
299 });
300 Self { instruction }
301 }
302 #[inline(always)]
304 pub fn rent_payer(
305 &mut self,
306 rent_payer: &'b solana_program::account_info::AccountInfo<'a>,
307 ) -> &mut Self {
308 self.instruction.rent_payer = Some(rent_payer);
309 self
310 }
311 #[inline(always)]
313 pub fn owner(&mut self, owner: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
314 self.instruction.owner = Some(owner);
315 self
316 }
317 #[inline(always)]
319 pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
320 self.instruction.pool = Some(pool);
321 self
322 }
323 #[inline(always)]
325 pub fn system_program(
326 &mut self,
327 system_program: &'b solana_program::account_info::AccountInfo<'a>,
328 ) -> &mut Self {
329 self.instruction.system_program = Some(system_program);
330 self
331 }
332 #[inline(always)]
334 pub fn add_remaining_account(
335 &mut self,
336 account: &'b solana_program::account_info::AccountInfo<'a>,
337 is_writable: bool,
338 is_signer: bool,
339 ) -> &mut Self {
340 self.instruction
341 .__remaining_accounts
342 .push((account, is_writable, is_signer));
343 self
344 }
345 #[inline(always)]
350 pub fn add_remaining_accounts(
351 &mut self,
352 accounts: &[(
353 &'b solana_program::account_info::AccountInfo<'a>,
354 bool,
355 bool,
356 )],
357 ) -> &mut Self {
358 self.instruction
359 .__remaining_accounts
360 .extend_from_slice(accounts);
361 self
362 }
363 #[inline(always)]
364 pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
365 self.invoke_signed(&[])
366 }
367 #[allow(clippy::clone_on_copy)]
368 #[allow(clippy::vec_init_then_push)]
369 pub fn invoke_signed(
370 &self,
371 signers_seeds: &[&[&[u8]]],
372 ) -> solana_program::entrypoint::ProgramResult {
373 let instruction = ClosePoolCpi {
374 __program: self.instruction.__program,
375
376 rent_payer: self.instruction.rent_payer.expect("rent_payer is not set"),
377
378 owner: self.instruction.owner.expect("owner is not set"),
379
380 pool: self.instruction.pool.expect("pool is not set"),
381
382 system_program: self
383 .instruction
384 .system_program
385 .expect("system_program is not set"),
386 };
387 instruction.invoke_signed_with_remaining_accounts(
388 signers_seeds,
389 &self.instruction.__remaining_accounts,
390 )
391 }
392}
393
394#[derive(Clone, Debug)]
395struct ClosePoolCpiBuilderInstruction<'a, 'b> {
396 __program: &'b solana_program::account_info::AccountInfo<'a>,
397 rent_payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
398 owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
399 pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
400 system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
401 __remaining_accounts: Vec<(
403 &'b solana_program::account_info::AccountInfo<'a>,
404 bool,
405 bool,
406 )>,
407}