spl_token_2022_interface/extension/memo_transfer/
instruction.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3use {
4    crate::{
5        check_program_account,
6        instruction::{encode_instruction, TokenInstruction},
7    },
8    num_enum::{IntoPrimitive, TryFromPrimitive},
9    solana_instruction::{AccountMeta, Instruction},
10    solana_program_error::ProgramError,
11    solana_pubkey::Pubkey,
12};
13
14/// Required Memo Transfers extension instructions
15#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
16#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
17#[derive(Clone, Copy, Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
18#[repr(u8)]
19pub enum RequiredMemoTransfersInstruction {
20    /// Require memos for transfers into this Account. Adds the `MemoTransfer`
21    /// extension to the Account, if it doesn't already exist.
22    ///
23    /// Accounts expected by this instruction:
24    ///
25    ///   0. `[writable]` The account to update.
26    ///   1. `[signer]` The account's owner.
27    ///
28    ///   * Multisignature authority
29    ///   0. `[writable]` The account to update.
30    ///   1. `[]` The account's multisignature owner.
31    ///   2. `..2+M` `[signer]` M signer accounts.
32    Enable,
33    /// Stop requiring memos for transfers into this Account.
34    ///
35    /// Implicitly initializes the extension in the case where it is not
36    /// present.
37    ///
38    /// Accounts expected by this instruction:
39    ///
40    ///   0. `[writable]` The account to update.
41    ///   1. `[signer]` The account's owner.
42    ///
43    ///   * Multisignature authority
44    ///   0. `[writable]` The account to update.
45    ///   1. `[]`  The account's multisignature owner.
46    ///   2. `..2+M` `[signer]` M signer accounts.
47    Disable,
48}
49
50/// Create an `Enable` instruction
51pub fn enable_required_transfer_memos(
52    token_program_id: &Pubkey,
53    account: &Pubkey,
54    owner: &Pubkey,
55    signers: &[&Pubkey],
56) -> Result<Instruction, ProgramError> {
57    check_program_account(token_program_id)?;
58    let mut accounts = vec![
59        AccountMeta::new(*account, false),
60        AccountMeta::new_readonly(*owner, signers.is_empty()),
61    ];
62    for signer_pubkey in signers.iter() {
63        accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
64    }
65    Ok(encode_instruction(
66        token_program_id,
67        accounts,
68        TokenInstruction::MemoTransferExtension,
69        RequiredMemoTransfersInstruction::Enable,
70        &(),
71    ))
72}
73
74/// Create a `Disable` instruction
75pub fn disable_required_transfer_memos(
76    token_program_id: &Pubkey,
77    account: &Pubkey,
78    owner: &Pubkey,
79    signers: &[&Pubkey],
80) -> Result<Instruction, ProgramError> {
81    check_program_account(token_program_id)?;
82    let mut accounts = vec![
83        AccountMeta::new(*account, false),
84        AccountMeta::new_readonly(*owner, signers.is_empty()),
85    ];
86    for signer_pubkey in signers.iter() {
87        accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
88    }
89    Ok(encode_instruction(
90        token_program_id,
91        accounts,
92        TokenInstruction::MemoTransferExtension,
93        RequiredMemoTransfersInstruction::Disable,
94        &(),
95    ))
96}