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

Commit bd60d25

Browse files
authored
single-pool: Inline and remove MPL dependency (#4589)
* single-pool: Inline and remove MPL dependency * Link the inline file rather than copy-pasta
1 parent 86f1fff commit bd60d25

File tree

11 files changed

+44
-168
lines changed

11 files changed

+44
-168
lines changed

Cargo.lock

Lines changed: 3 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stake-pool/program/src/inline_mpl_token_metadata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Inlined MPL metadata types to avoid a direct dependency on `mpl-token-metadata'
2+
//! NOTE: this file is sym-linked in `spl-single-validator-pool`, so be careful
3+
//! with changes!
24
35
solana_program::declare_id!("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
46

stake-pool/single-pool/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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../program/src/inline_mpl_token_metadata.rs

stake-pool/single-pool/src/instruction.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ use {
66
crate::{
77
find_default_deposit_account_address_and_seed, find_pool_address, find_pool_mint_address,
88
find_pool_mint_authority_address, find_pool_mpl_authority_address, find_pool_stake_address,
9-
find_pool_stake_authority_address, state::SinglePool,
9+
find_pool_stake_authority_address,
10+
inline_mpl_token_metadata::{self, pda::find_metadata_account},
11+
state::SinglePool,
1012
},
1113
borsh::{BorshDeserialize, BorshSerialize},
12-
mpl_token_metadata::pda::find_metadata_account,
1314
solana_program::{
1415
instruction::{AccountMeta, Instruction},
1516
program_pack::Pack,
@@ -377,7 +378,7 @@ pub fn create_token_metadata(
377378
),
378379
AccountMeta::new(*payer, true),
379380
AccountMeta::new(token_metadata, false),
380-
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
381+
AccountMeta::new_readonly(inline_mpl_token_metadata::id(), false),
381382
AccountMeta::new_readonly(system_program::id(), false),
382383
];
383384

@@ -413,7 +414,7 @@ pub fn update_token_metadata(
413414
),
414415
AccountMeta::new_readonly(*authorized_withdrawer, true),
415416
AccountMeta::new(token_metadata, false),
416-
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
417+
AccountMeta::new_readonly(inline_mpl_token_metadata::id(), false),
417418
];
418419

419420
Instruction {

stake-pool/single-pool/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! A program for liquid staking with a single validator
44
55
pub mod error;
6+
pub mod inline_mpl_token_metadata;
67
pub mod instruction;
78
pub mod processor;
89
pub mod state;

stake-pool/single-pool/src/processor.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
use {
44
crate::{
55
error::SinglePoolError,
6+
inline_mpl_token_metadata::{
7+
self,
8+
instruction::{create_metadata_accounts_v3, update_metadata_accounts_v2},
9+
pda::find_metadata_account,
10+
state::DataV2,
11+
},
612
instruction::SinglePoolInstruction,
713
state::{SinglePool, SinglePoolAccountType},
814
MINT_DECIMALS, POOL_MINT_AUTHORITY_PREFIX, POOL_MINT_PREFIX, POOL_MPL_AUTHORITY_PREFIX,
@@ -11,11 +17,6 @@ use {
1117
VOTE_STATE_DISCRIMINATOR_END,
1218
},
1319
borsh::BorshDeserialize,
14-
mpl_token_metadata::{
15-
instruction::{create_metadata_accounts_v3, update_metadata_accounts_v2},
16-
pda::find_metadata_account,
17-
state::DataV2,
18-
},
1920
solana_program::{
2021
account_info::{next_account_info, AccountInfo},
2122
borsh::{get_packed_len, try_from_slice_unchecked},
@@ -286,10 +287,10 @@ fn check_stake_program(program_id: &Pubkey) -> Result<(), ProgramError> {
286287

287288
/// Check MPL metadata program
288289
fn check_mpl_metadata_program(program_id: &Pubkey) -> Result<(), ProgramError> {
289-
if *program_id != mpl_token_metadata::id() {
290+
if *program_id != inline_mpl_token_metadata::id() {
290291
msg!(
291292
"Expected MPL metadata program {}, received {}",
292-
mpl_token_metadata::id(),
293+
inline_mpl_token_metadata::id(),
293294
program_id
294295
);
295296
Err(ProgramError::IncorrectProgramId)
@@ -994,13 +995,6 @@ impl Processor {
994995
token_name,
995996
token_symbol,
996997
"".to_string(),
997-
None,
998-
0,
999-
true,
1000-
true,
1001-
None,
1002-
None,
1003-
None,
1004998
);
1005999

10061000
let mint_authority_seeds = &[

stake-pool/single-pool/tests/create_pool_token_metadata.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ mod helpers;
55

66
use {
77
helpers::*,
8-
mpl_token_metadata::{
9-
state::Metadata,
10-
state::{MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH},
11-
utils::puffed_out_string,
12-
},
138
solana_program_test::*,
149
solana_sdk::{
1510
instruction::InstructionError, pubkey::Pubkey, signature::Signer,
@@ -22,11 +17,9 @@ fn assert_metadata(vote_account: &Pubkey, metadata: &Metadata) {
2217
let vote_address_str = vote_account.to_string();
2318
let name = format!("SPL Single Pool {}", &vote_address_str[0..15]);
2419
let symbol = format!("st{}", &vote_address_str[0..7]);
25-
let puffy_name = puffed_out_string(&name, MAX_NAME_LENGTH);
26-
let puffy_symbol = puffed_out_string(&symbol, MAX_SYMBOL_LENGTH);
2720

28-
assert_eq!(metadata.data.name, puffy_name);
29-
assert_eq!(metadata.data.symbol, puffy_symbol);
21+
assert!(metadata.name.starts_with(&name));
22+
assert!(metadata.symbol.starts_with(&symbol));
3023
}
3124

3225
#[tokio::test]

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use {
2020
spl_single_validator_pool::{
2121
find_pool_address, find_pool_mint_address, find_pool_mint_authority_address,
2222
find_pool_mpl_authority_address, find_pool_stake_address,
23-
find_pool_stake_authority_address, id, instruction, processor::Processor,
23+
find_pool_stake_authority_address, id, inline_mpl_token_metadata, instruction,
24+
processor::Processor,
2425
},
2526
};
2627

@@ -35,7 +36,7 @@ pub const USER_STARTING_LAMPORTS: u64 = 10_000_000_000_000; // 10k sol
3536

3637
pub fn program_test() -> ProgramTest {
3738
let mut program_test = ProgramTest::default();
38-
program_test.add_program("mpl_token_metadata", mpl_token_metadata::id(), None);
39+
program_test.add_program("mpl_token_metadata", inline_mpl_token_metadata::id(), None);
3940

4041
program_test.add_program(
4142
"spl_single_validator_pool",

stake-pool/single-pool/tests/helpers/token.rs

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

33
use {
4-
mpl_token_metadata::{pda::find_metadata_account, state::Metadata},
4+
borsh::BorshDeserialize,
55
solana_program_test::BanksClient,
66
solana_sdk::{
77
borsh::try_from_slice_unchecked,
@@ -12,6 +12,7 @@ use {
1212
transaction::Transaction,
1313
},
1414
spl_associated_token_account as atoken,
15+
spl_single_validator_pool::inline_mpl_token_metadata::pda::find_metadata_account,
1516
spl_token::state::{Account, Mint},
1617
};
1718

@@ -50,6 +51,20 @@ pub async fn get_token_supply(banks_client: &mut BanksClient, mint: &Pubkey) ->
5051
account_info.supply
5152
}
5253

54+
#[derive(Clone, BorshDeserialize, Debug, PartialEq, Eq)]
55+
pub struct Metadata {
56+
pub key: u8,
57+
pub update_authority: Pubkey,
58+
pub mint: Pubkey,
59+
pub name: String,
60+
pub symbol: String,
61+
pub uri: String,
62+
pub seller_fee_basis_points: u16,
63+
pub creators: Option<Vec<u8>>,
64+
pub primary_sale_happened: bool,
65+
pub is_mutable: bool,
66+
}
67+
5368
pub async fn get_metadata_account(banks_client: &mut BanksClient, token_mint: &Pubkey) -> Metadata {
5469
let (token_metadata, _) = find_metadata_account(token_mint);
5570
let token_metadata_account = banks_client

0 commit comments

Comments
 (0)