Skip to main content

sealevel_tools/cpi/token_program/extensions/
initialize_immutable_owner.rs

1use crate::{cpi::CpiInstruction, entrypoint::NoStdAccountInfo, pubkey::Pubkey};
2
3/// Arguments for the initialize immutable owner instruction on the specified Token program, which
4/// prevents the owner of a token account from being updated. This instruction must be called
5/// before a token account is initialized.
6#[derive(Clone, PartialEq, Eq)]
7pub struct InitializeImmutableOwner<'a> {
8    pub token_program_id: &'a Pubkey,
9    pub account: &'a NoStdAccountInfo,
10}
11
12impl<'a> InitializeImmutableOwner<'a> {
13    /// Consume arguments to perform CPI call.
14    #[inline(always)]
15    pub fn into_invoke(self) {
16        let Self {
17            token_program_id,
18            account,
19        } = self;
20
21        CpiInstruction {
22            program_id: token_program_id,
23            accounts: &[account.to_meta_c()],
24            // Initialize immutable owner selector == 22.
25            data: &[22],
26        }
27        .invoke_signed(&[account.to_info_c()], &[]);
28    }
29}