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

Commit 8169e52

Browse files
authored
[stake-pool] instruction to add metadata for pool token (#3335)
* instruction to add metadata for pool token * add documentation for instruction accounts * address pull request comments * added more tests for update pool token instruction * add check for payer signature
1 parent 4d1f816 commit 8169e52

File tree

9 files changed

+900
-0
lines changed

9 files changed

+900
-0
lines changed

Cargo.lock

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stake-pool/program/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ test-bpf = []
1414
[dependencies]
1515
arrayref = "0.3.6"
1616
borsh = "0.9"
17+
mpl-token-metadata = { version = "1.3.1", features = [ "no-entrypoint" ] }
1718
num-derive = "0.3"
1819
num-traits = "0.2"
1920
num_enum = "0.5.4"

stake-pool/program/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ pub enum StakePoolError {
132132
/// Too much SOL withdrawn from the stake pool's reserve account
133133
#[error("SolWithdrawalTooLarge")]
134134
SolWithdrawalTooLarge,
135+
/// Provided metadata account does not match metadata account derived for pool mint
136+
#[error("InvalidMetadataAccount")]
137+
InvalidMetadataAccount,
135138
}
136139
impl From<StakePoolError> for ProgramError {
137140
fn from(e: StakePoolError) -> Self {

stake-pool/program/src/instruction.rs

+113
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Instruction types
22
33
#![allow(clippy::too_many_arguments)]
4+
45
use {
56
crate::{
67
find_deposit_authority_program_address, find_stake_program_address,
@@ -9,6 +10,7 @@ use {
910
MAX_VALIDATORS_TO_UPDATE,
1011
},
1112
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
13+
mpl_token_metadata::pda::find_metadata_account,
1214
solana_program::{
1315
instruction::{AccountMeta, Instruction},
1416
pubkey::Pubkey,
@@ -374,6 +376,48 @@ pub enum StakePoolInstruction {
374376
/// 11. `[]` Token program id
375377
/// 12. `[s]` (Optional) Stake pool sol withdraw authority
376378
WithdrawSol(u64),
379+
380+
/// Create token metadata for the stake-pool token in the
381+
/// metaplex-token program
382+
/// 0. `[]` Stake pool
383+
/// 1. `[s]` Manager
384+
/// 2. `[]` Stake pool withdraw authority
385+
/// 3. `[]` Pool token mint account
386+
/// 4. `[s, w]` Payer for creation of token metadata account
387+
/// 5. `[w]` Token metadata account
388+
/// 6. `[]` Metadata program id
389+
/// 7. `[]` System program id
390+
/// 8. `[]` Rent sysvar
391+
CreateTokenMetadata {
392+
#[allow(dead_code)]
393+
/// Token name
394+
name: String,
395+
#[allow(dead_code)]
396+
/// Token symbol e.g. stkSOL
397+
symbol: String,
398+
/// URI of the uploaded metadata of the spl-token
399+
#[allow(dead_code)]
400+
uri: String,
401+
},
402+
/// Update token metadata for the stake-pool token in the
403+
/// metaplex-token program
404+
///
405+
/// 0. `[]` Stake pool
406+
/// 1. `[s]` Manager
407+
/// 2. `[]` Stake pool withdraw authority
408+
/// 3. `[w]` Token metadata account
409+
/// 4. `[]` Metadata program id
410+
UpdateTokenMetadata {
411+
#[allow(dead_code)]
412+
/// Token name
413+
name: String,
414+
#[allow(dead_code)]
415+
/// Token symbol e.g. stkSOL
416+
symbol: String,
417+
/// URI of the uploaded metadata of the spl-token
418+
#[allow(dead_code)]
419+
uri: String,
420+
},
377421
}
378422

379423
/// Creates an 'initialize' instruction.
@@ -1276,3 +1320,72 @@ pub fn set_funding_authority(
12761320
.unwrap(),
12771321
}
12781322
}
1323+
1324+
/// Creates an instruction to update metadata in the mpl token metadata program account for
1325+
/// the pool token
1326+
pub fn update_token_metadata(
1327+
program_id: &Pubkey,
1328+
stake_pool: &Pubkey,
1329+
manager: &Pubkey,
1330+
pool_mint: &Pubkey,
1331+
name: String,
1332+
symbol: String,
1333+
uri: String,
1334+
) -> Instruction {
1335+
let (stake_pool_withdraw_authority, _) =
1336+
find_withdraw_authority_program_address(program_id, stake_pool);
1337+
let (token_metadata, _) = find_metadata_account(pool_mint);
1338+
1339+
let accounts = vec![
1340+
AccountMeta::new_readonly(*stake_pool, false),
1341+
AccountMeta::new_readonly(*manager, true),
1342+
AccountMeta::new_readonly(stake_pool_withdraw_authority, false),
1343+
AccountMeta::new(token_metadata, false),
1344+
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
1345+
];
1346+
1347+
Instruction {
1348+
program_id: *program_id,
1349+
accounts,
1350+
data: StakePoolInstruction::UpdateTokenMetadata { name, symbol, uri }
1351+
.try_to_vec()
1352+
.unwrap(),
1353+
}
1354+
}
1355+
1356+
/// Creates an instruction to create metadata using the mpl token metadata program for
1357+
/// the pool token
1358+
pub fn create_token_metadata(
1359+
program_id: &Pubkey,
1360+
stake_pool: &Pubkey,
1361+
manager: &Pubkey,
1362+
pool_mint: &Pubkey,
1363+
payer: &Pubkey,
1364+
name: String,
1365+
symbol: String,
1366+
uri: String,
1367+
) -> Instruction {
1368+
let (stake_pool_withdraw_authority, _) =
1369+
find_withdraw_authority_program_address(program_id, stake_pool);
1370+
let (token_metadata, _) = find_metadata_account(pool_mint);
1371+
1372+
let accounts = vec![
1373+
AccountMeta::new_readonly(*stake_pool, false),
1374+
AccountMeta::new_readonly(*manager, true),
1375+
AccountMeta::new_readonly(stake_pool_withdraw_authority, false),
1376+
AccountMeta::new_readonly(*pool_mint, false),
1377+
AccountMeta::new(*payer, true),
1378+
AccountMeta::new(token_metadata, false),
1379+
AccountMeta::new_readonly(mpl_token_metadata::id(), false),
1380+
AccountMeta::new_readonly(system_program::id(), false),
1381+
AccountMeta::new_readonly(sysvar::rent::id(), false),
1382+
];
1383+
1384+
Instruction {
1385+
program_id: *program_id,
1386+
accounts,
1387+
data: StakePoolInstruction::CreateTokenMetadata { name, symbol, uri }
1388+
.try_to_vec()
1389+
.unwrap(),
1390+
}
1391+
}

0 commit comments

Comments
 (0)