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