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_instruction::{AccountMeta, Instruction},
11 solana_program_error::ProgramError,
12 solana_pubkey::Pubkey,
13};
14
15#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
17#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
18#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
19#[repr(u8)]
20pub enum PausableInstruction {
21 Initialize,
33 Pause,
45 Resume,
57}
58
59#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
61#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
62#[derive(Clone, Copy, Pod, Zeroable)]
63#[repr(C)]
64pub struct InitializeInstructionData {
65 pub authority: Pubkey,
67}
68
69pub fn initialize(
71 token_program_id: &Pubkey,
72 mint: &Pubkey,
73 authority: &Pubkey,
74) -> Result<Instruction, ProgramError> {
75 check_program_account(token_program_id)?;
76 let accounts = vec![AccountMeta::new(*mint, false)];
77 Ok(encode_instruction(
78 token_program_id,
79 accounts,
80 TokenInstruction::PausableExtension,
81 PausableInstruction::Initialize,
82 &InitializeInstructionData {
83 authority: *authority,
84 },
85 ))
86}
87
88pub fn pause(
90 token_program_id: &Pubkey,
91 mint: &Pubkey,
92 authority: &Pubkey,
93 signers: &[&Pubkey],
94) -> Result<Instruction, ProgramError> {
95 check_program_account(token_program_id)?;
96 let mut accounts = vec![
97 AccountMeta::new(*mint, false),
98 AccountMeta::new_readonly(*authority, signers.is_empty()),
99 ];
100 for signer_pubkey in signers.iter() {
101 accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
102 }
103 Ok(encode_instruction(
104 token_program_id,
105 accounts,
106 TokenInstruction::PausableExtension,
107 PausableInstruction::Pause,
108 &(),
109 ))
110}
111
112pub fn resume(
114 token_program_id: &Pubkey,
115 mint: &Pubkey,
116 authority: &Pubkey,
117 signers: &[&Pubkey],
118) -> Result<Instruction, ProgramError> {
119 check_program_account(token_program_id)?;
120 let mut accounts = vec![
121 AccountMeta::new(*mint, false),
122 AccountMeta::new_readonly(*authority, signers.is_empty()),
123 ];
124 for signer_pubkey in signers.iter() {
125 accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
126 }
127 Ok(encode_instruction(
128 token_program_id,
129 accounts,
130 TokenInstruction::PausableExtension,
131 PausableInstruction::Resume,
132 &(),
133 ))
134}