spl_token_2022/extension/pausable/
instruction.rs1#[cfg(feature = "serde-traits")]
2use serde::{Deserialize, Serialize};
3use {
4 crate::{
5 check_program_account,
6 instruction::{encode_instruction, TokenInstruction},
7 },
8 bytemuck::{Pod, Zeroable},
9 num_enum::{IntoPrimitive, TryFromPrimitive},
10 solana_program::{
11 instruction::{AccountMeta, Instruction},
12 program_error::ProgramError,
13 pubkey::Pubkey,
14 },
15};
16
17#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
19#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
20#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
21#[repr(u8)]
22pub enum PausableInstruction {
23 Initialize,
35 Pause,
47 Resume,
59}
60
61#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
63#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
64#[derive(Clone, Copy, Pod, Zeroable)]
65#[repr(C)]
66pub struct InitializeInstructionData {
67 pub authority: Pubkey,
69}
70
71pub fn initialize(
73 token_program_id: &Pubkey,
74 mint: &Pubkey,
75 authority: &Pubkey,
76) -> Result<Instruction, ProgramError> {
77 check_program_account(token_program_id)?;
78 let accounts = vec![AccountMeta::new(*mint, false)];
79 Ok(encode_instruction(
80 token_program_id,
81 accounts,
82 TokenInstruction::PausableExtension,
83 PausableInstruction::Initialize,
84 &InitializeInstructionData {
85 authority: *authority,
86 },
87 ))
88}
89
90pub fn pause(
92 token_program_id: &Pubkey,
93 mint: &Pubkey,
94 authority: &Pubkey,
95 signers: &[&Pubkey],
96) -> Result<Instruction, ProgramError> {
97 check_program_account(token_program_id)?;
98 let mut accounts = vec![
99 AccountMeta::new(*mint, false),
100 AccountMeta::new_readonly(*authority, signers.is_empty()),
101 ];
102 for signer_pubkey in signers.iter() {
103 accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
104 }
105 Ok(encode_instruction(
106 token_program_id,
107 accounts,
108 TokenInstruction::PausableExtension,
109 PausableInstruction::Pause,
110 &(),
111 ))
112}
113
114pub fn resume(
116 token_program_id: &Pubkey,
117 mint: &Pubkey,
118 authority: &Pubkey,
119 signers: &[&Pubkey],
120) -> Result<Instruction, ProgramError> {
121 check_program_account(token_program_id)?;
122 let mut accounts = vec![
123 AccountMeta::new(*mint, false),
124 AccountMeta::new_readonly(*authority, signers.is_empty()),
125 ];
126 for signer_pubkey in signers.iter() {
127 accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
128 }
129 Ok(encode_instruction(
130 token_program_id,
131 accounts,
132 TokenInstruction::PausableExtension,
133 PausableInstruction::Resume,
134 &(),
135 ))
136}