Skip to main content

sealevel_tools/cpi/token_program/extensions/
initialize_metadata_pointer.rs

1use crate::{cpi::CpiInstruction, entrypoint::NoStdAccountInfo, pubkey::Pubkey};
2
3/// Arguments for the initialize metadata pointer instruction on the specified Token program, which
4/// is used to establish a metadata account for a mint. This instruction must be called before a
5/// mint is initialized.
6#[derive(Clone, PartialEq, Eq)]
7pub struct InitializeMetadataPointer<'a> {
8    pub token_program_id: &'a Pubkey,
9    pub mint: &'a NoStdAccountInfo,
10    pub authority: Option<&'a Pubkey>,
11    pub metadata: Option<&'a Pubkey>,
12}
13
14impl<'a> InitializeMetadataPointer<'a> {
15    /// Consume arguments to perform CPI call.
16    #[inline(always)]
17    pub fn into_invoke(self) {
18        let Self {
19            token_program_id,
20            mint,
21            authority,
22            metadata,
23        } = self;
24
25        // Metadata pointer selector == 39.
26        let instruction_data = super::serialize_initialize_pointer_instruction_data(
27            39,
28            super::unwrap_or_default_pubkey(authority),
29            super::unwrap_or_default_pubkey(metadata),
30        );
31
32        CpiInstruction {
33            program_id: token_program_id,
34            accounts: &[mint.to_meta_c()],
35            data: &instruction_data,
36        }
37        .invoke_signed(&[mint.to_info_c()], &[]);
38    }
39}