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