Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 86f1fff

Browse files
authored
stake-pool: Remove mpl crate dependency for 1.16 upgrade (#4588)
1 parent 7a9e2fe commit 86f1fff

File tree

9 files changed

+174
-45
lines changed

9 files changed

+174
-45
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stake-pool/program/Cargo.toml

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

stake-pool/program/src/instruction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use {
77
find_deposit_authority_program_address, find_ephemeral_stake_program_address,
88
find_stake_program_address, find_transient_stake_program_address,
99
find_withdraw_authority_program_address,
10+
inline_mpl_token_metadata::{self, pda::find_metadata_account},
1011
state::{Fee, FeeType, StakePool, ValidatorList},
1112
MAX_VALIDATORS_TO_UPDATE,
1213
},
1314
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
14-
mpl_token_metadata::pda::find_metadata_account,
1515
solana_program::{
1616
instruction::{AccountMeta, Instruction},
1717
pubkey::Pubkey,
@@ -2228,7 +2228,7 @@ pub fn update_token_metadata(
22282228
AccountMeta::new_readonly(*manager, true),
22292229
AccountMeta::new_readonly(stake_pool_withdraw_authority, false),
22302230
AccountMeta::new(token_metadata, false),
2231-
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
2231+
AccountMeta::new_readonly(inline_mpl_token_metadata::id(), false),
22322232
];
22332233

22342234
Instruction {
@@ -2263,7 +2263,7 @@ pub fn create_token_metadata(
22632263
AccountMeta::new_readonly(*pool_mint, false),
22642264
AccountMeta::new(*payer, true),
22652265
AccountMeta::new(token_metadata, false),
2266-
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
2266+
AccountMeta::new_readonly(inline_mpl_token_metadata::id(), false),
22672267
AccountMeta::new_readonly(system_program::id(), false),
22682268
];
22692269

stake-pool/program/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
pub mod big_vec;
66
pub mod error;
7+
pub mod inline_mpl_token_metadata;
78
pub mod instruction;
89
pub mod processor;
910
pub mod state;

stake-pool/program/src/processor.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ use {
44
crate::{
55
error::StakePoolError,
66
find_deposit_authority_program_address,
7+
inline_mpl_token_metadata::{
8+
self,
9+
instruction::{create_metadata_accounts_v3, update_metadata_accounts_v2},
10+
pda::find_metadata_account,
11+
state::DataV2,
12+
},
713
instruction::{FundingType, PreferredValidatorType, StakePoolInstruction},
814
minimum_delegation, minimum_reserve_lamports, minimum_stake_lamports,
915
state::{
@@ -15,11 +21,6 @@ use {
1521
TRANSIENT_STAKE_SEED_PREFIX,
1622
},
1723
borsh::BorshDeserialize,
18-
mpl_token_metadata::{
19-
instruction::{create_metadata_accounts_v3, update_metadata_accounts_v2},
20-
pda::find_metadata_account,
21-
state::DataV2,
22-
},
2324
num_traits::FromPrimitive,
2425
solana_program::{
2526
account_info::{next_account_info, AccountInfo},
@@ -161,10 +162,10 @@ fn check_stake_program(program_id: &Pubkey) -> Result<(), ProgramError> {
161162

162163
/// Check mpl metadata program
163164
fn check_mpl_metadata_program(program_id: &Pubkey) -> Result<(), ProgramError> {
164-
if *program_id != mpl_token_metadata::id() {
165+
if *program_id != inline_mpl_token_metadata::id() {
165166
msg!(
166167
"Expected mpl metadata program {}, received {}",
167-
mpl_token_metadata::id(),
168+
inline_mpl_token_metadata::id(),
168169
program_id
169170
);
170171
Err(ProgramError::IncorrectProgramId)
@@ -3512,13 +3513,6 @@ impl Processor {
35123513
name,
35133514
symbol,
35143515
uri,
3515-
None,
3516-
0,
3517-
true,
3518-
true,
3519-
None,
3520-
None,
3521-
None,
35223516
);
35233517

35243518
let (_, stake_withdraw_bump_seed) =

stake-pool/program/tests/create_pool_token_metadata.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ mod helpers;
44

55
use {
66
helpers::*,
7-
mpl_token_metadata::{
8-
state::{MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH},
9-
utils::puffed_out_string,
10-
},
117
solana_program::{instruction::InstructionError, pubkey::Pubkey},
128
solana_program_test::*,
139
solana_sdk::{
@@ -49,10 +45,6 @@ async fn success(token_program_id: Pubkey) {
4945
let symbol = "SYM";
5046
let uri = "test_uri";
5147

52-
let puffed_name = puffed_out_string(name, MAX_NAME_LENGTH);
53-
let puffed_symbol = puffed_out_string(symbol, MAX_SYMBOL_LENGTH);
54-
let puffed_uri = puffed_out_string(uri, MAX_URI_LENGTH);
55-
5648
let ix = instruction::create_token_metadata(
5749
&spl_stake_pool::id(),
5850
&stake_pool_accounts.stake_pool.pubkey(),
@@ -83,9 +75,9 @@ async fn success(token_program_id: Pubkey) {
8375
)
8476
.await;
8577

86-
assert_eq!(metadata.data.name, puffed_name);
87-
assert_eq!(metadata.data.symbol, puffed_symbol);
88-
assert_eq!(metadata.data.uri, puffed_uri);
78+
assert!(metadata.name.starts_with(name));
79+
assert!(metadata.symbol.starts_with(symbol));
80+
assert!(metadata.uri.starts_with(uri));
8981
}
9082

9183
#[tokio::test]

stake-pool/program/tests/helpers/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![allow(dead_code)]
22

33
use {
4-
borsh::BorshSerialize,
5-
mpl_token_metadata::{pda::find_metadata_account, state::Metadata},
4+
borsh::{BorshDeserialize, BorshSerialize},
65
solana_program::{
76
borsh::{get_instance_packed_len, get_packed_len, try_from_slice_unchecked},
87
hash::Hash,
@@ -28,7 +27,9 @@ use {
2827
spl_stake_pool::{
2928
find_deposit_authority_program_address, find_ephemeral_stake_program_address,
3029
find_stake_program_address, find_transient_stake_program_address,
31-
find_withdraw_authority_program_address, id, instruction, minimum_delegation,
30+
find_withdraw_authority_program_address, id,
31+
inline_mpl_token_metadata::{self, pda::find_metadata_account},
32+
instruction, minimum_delegation,
3233
processor::Processor,
3334
state::{self, FeeType, FutureEpoch, StakePool, ValidatorList},
3435
MINIMUM_RESERVE_LAMPORTS,
@@ -62,7 +63,7 @@ pub fn program_test() -> ProgramTest {
6263
pub fn program_test_with_metadata_program() -> ProgramTest {
6364
let mut program_test = ProgramTest::default();
6465
program_test.add_program("spl_stake_pool", id(), processor!(Processor::process));
65-
program_test.add_program("mpl_token_metadata", mpl_token_metadata::id(), None);
66+
program_test.add_program("mpl_token_metadata", inline_mpl_token_metadata::id(), None);
6667
program_test.prefer_bpf(false);
6768
program_test.add_program(
6869
"spl_token_2022",
@@ -430,6 +431,20 @@ pub async fn get_token_balance(banks_client: &mut BanksClient, token: &Pubkey) -
430431
account_info.base.amount
431432
}
432433

434+
#[derive(Clone, BorshDeserialize, Debug, PartialEq, Eq)]
435+
pub struct Metadata {
436+
pub key: u8,
437+
pub update_authority: Pubkey,
438+
pub mint: Pubkey,
439+
pub name: String,
440+
pub symbol: String,
441+
pub uri: String,
442+
pub seller_fee_basis_points: u16,
443+
pub creators: Option<Vec<u8>>,
444+
pub primary_sale_happened: bool,
445+
pub is_mutable: bool,
446+
}
447+
433448
pub async fn get_metadata_account(banks_client: &mut BanksClient, token_mint: &Pubkey) -> Metadata {
434449
let (token_metadata, _) = find_metadata_account(token_mint);
435450
let token_metadata_account = banks_client

stake-pool/program/tests/update_pool_token_metadata.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ mod helpers;
44

55
use {
66
helpers::*,
7-
mpl_token_metadata::{
8-
state::{MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH},
9-
utils::puffed_out_string,
10-
},
117
solana_program::instruction::InstructionError,
128
solana_program_test::*,
139
solana_sdk::{
@@ -74,10 +70,6 @@ async fn success_update_pool_token_metadata() {
7470
let updated_symbol = "USYM";
7571
let updated_uri = "updated_uri";
7672

77-
let puffed_name = puffed_out_string(updated_name, MAX_NAME_LENGTH);
78-
let puffed_symbol = puffed_out_string(updated_symbol, MAX_SYMBOL_LENGTH);
79-
let puffed_uri = puffed_out_string(updated_uri, MAX_URI_LENGTH);
80-
8173
let ix = instruction::update_token_metadata(
8274
&spl_stake_pool::id(),
8375
&stake_pool_accounts.stake_pool.pubkey(),
@@ -107,9 +99,9 @@ async fn success_update_pool_token_metadata() {
10799
)
108100
.await;
109101

110-
assert_eq!(metadata.data.name, puffed_name);
111-
assert_eq!(metadata.data.symbol, puffed_symbol);
112-
assert_eq!(metadata.data.uri, puffed_uri);
102+
assert!(metadata.name.starts_with(updated_name));
103+
assert!(metadata.symbol.starts_with(updated_symbol));
104+
assert!(metadata.uri.starts_with(updated_uri));
113105
}
114106

115107
#[tokio::test]

0 commit comments

Comments
 (0)