spl_single_pool/
inline_mpl_token_metadata.rs

1//! Inline MPL metadata types to avoid a direct dependency on `mpl-token-metadata'.
2
3solana_pubkey::declare_id!("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
4
5pub(crate) mod instruction {
6    use {
7        super::state::DataV2,
8        borsh::{BorshDeserialize, BorshSerialize},
9        solana_instruction::{AccountMeta, Instruction},
10        solana_pubkey::Pubkey,
11        solana_system_interface::program as system_program,
12    };
13
14    #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
15    struct CreateMetadataAccountArgsV3 {
16        /// Note that unique metadata is disabled for now.
17        pub data: DataV2,
18        /// Whether you want your metadata to be changeable in the future.
19        pub is_mutable: bool,
20        /// UNUSED If this is a collection parent NFT.
21        pub collection_details: Option<u8>,
22    }
23
24    #[allow(clippy::too_many_arguments)]
25    pub(crate) fn create_metadata_accounts_v3(
26        program_id: Pubkey,
27        metadata_account: Pubkey,
28        mint: Pubkey,
29        mint_authority: Pubkey,
30        payer: Pubkey,
31        update_authority: Pubkey,
32        name: String,
33        symbol: String,
34        uri: String,
35    ) -> Instruction {
36        let mut data = vec![33]; // CreateMetadataAccountV3
37        data.append(
38            &mut borsh::to_vec(&CreateMetadataAccountArgsV3 {
39                data: DataV2 {
40                    name,
41                    symbol,
42                    uri,
43                    seller_fee_basis_points: 0,
44                    creators: None,
45                    collection: None,
46                    uses: None,
47                },
48                is_mutable: true,
49                collection_details: None,
50            })
51            .unwrap(),
52        );
53        Instruction {
54            program_id,
55            accounts: vec![
56                AccountMeta::new(metadata_account, false),
57                AccountMeta::new_readonly(mint, false),
58                AccountMeta::new_readonly(mint_authority, true),
59                AccountMeta::new(payer, true),
60                AccountMeta::new_readonly(update_authority, true),
61                AccountMeta::new_readonly(system_program::ID, false),
62            ],
63            data,
64        }
65    }
66
67    #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
68    struct UpdateMetadataAccountArgsV2 {
69        pub data: Option<DataV2>,
70        pub update_authority: Option<Pubkey>,
71        pub primary_sale_happened: Option<bool>,
72        pub is_mutable: Option<bool>,
73    }
74    pub(crate) fn update_metadata_accounts_v2(
75        program_id: Pubkey,
76        metadata_account: Pubkey,
77        update_authority: Pubkey,
78        new_update_authority: Option<Pubkey>,
79        metadata: Option<DataV2>,
80        primary_sale_happened: Option<bool>,
81        is_mutable: Option<bool>,
82    ) -> Instruction {
83        let mut data = vec![15]; // UpdateMetadataAccountV2
84        data.append(
85            &mut borsh::to_vec(&UpdateMetadataAccountArgsV2 {
86                data: metadata,
87                update_authority: new_update_authority,
88                primary_sale_happened,
89                is_mutable,
90            })
91            .unwrap(),
92        );
93        Instruction {
94            program_id,
95            accounts: vec![
96                AccountMeta::new(metadata_account, false),
97                AccountMeta::new_readonly(update_authority, true),
98            ],
99            data,
100        }
101    }
102}
103
104/// PDA creation helpers
105pub mod pda {
106    use {super::ID, solana_pubkey::Pubkey};
107    const PREFIX: &str = "metadata";
108    /// Helper to find a metadata account address
109    pub fn find_metadata_account(mint: &Pubkey) -> (Pubkey, u8) {
110        Pubkey::find_program_address(&[PREFIX.as_bytes(), ID.as_ref(), mint.as_ref()], &ID)
111    }
112}
113
114pub(crate) mod state {
115    use borsh::{BorshDeserialize, BorshSerialize};
116    #[repr(C)]
117    #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone)]
118    pub(crate) struct DataV2 {
119        /// The name of the asset
120        pub name: String,
121        /// The symbol for the asset
122        pub symbol: String,
123        /// URI pointing to JSON representing the asset
124        pub uri: String,
125        /// Royalty basis points that goes to creators in secondary sales
126        /// (0-10000)
127        pub seller_fee_basis_points: u16,
128        /// UNUSED Array of creators, optional
129        pub creators: Option<u8>,
130        /// UNUSED Collection
131        pub collection: Option<u8>,
132        /// UNUSED Uses
133        pub uses: Option<u8>,
134    }
135}