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

Commit ffb8b65

Browse files
committed
instruction to add metadata for pool token
1 parent 7caf27c commit ffb8b65

File tree

7 files changed

+628
-0
lines changed

7 files changed

+628
-0
lines changed

Cargo.lock

Lines changed: 67 additions & 0 deletions
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: 1 addition & 0 deletions
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/instruction.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! Instruction types
22
33
#![allow(clippy::too_many_arguments)]
4+
5+
use crate::AUTHORITY_WITHDRAW;
6+
use mpl_token_metadata::state::PREFIX;
7+
use solana_program::info;
8+
use std::str::FromStr;
49
use {
510
crate::{
611
find_deposit_authority_program_address, find_stake_program_address,
@@ -374,6 +379,43 @@ pub enum StakePoolInstruction {
374379
/// 11. `[]` Token program id
375380
/// 12. `[s]` (Optional) Stake pool sol withdraw authority
376381
WithdrawSol(u64),
382+
383+
/// Create token metadata for the stake-pool token in the
384+
/// metaplex-token program
385+
///
386+
/// 0. `[w]` Stake pool
387+
/// 1. `[]` Stake pool withdraw authority
388+
/// 2. `[w]` Pool token mint account
389+
/// 3. `[w]` Payer account
390+
CreateTokenMetadata {
391+
#[allow(dead_code)]
392+
/// Token name
393+
name: String,
394+
#[allow(dead_code)]
395+
/// Token symbol e.g. stkSOL
396+
symbol: String,
397+
/// URI of the uploaded metadata of the spl-token
398+
#[allow(dead_code)]
399+
uri: String,
400+
},
401+
/// Update token metadata for the stake-pool token in the
402+
/// metaplex-token program
403+
///
404+
/// 0. `[w]` Stake pool
405+
/// 1. `[]` Stake pool withdraw authority
406+
/// 2. `[w]` Pool token mint account
407+
/// 3. `[w]` Payer account
408+
UpdateTokenMetadata {
409+
#[allow(dead_code)]
410+
/// Token name
411+
name: String,
412+
#[allow(dead_code)]
413+
/// Token symbol e.g. stkSOL
414+
symbol: String,
415+
/// URI of the uploaded metadata of the spl-token
416+
#[allow(dead_code)]
417+
uri: String,
418+
},
377419
}
378420

379421
/// Creates an 'initialize' instruction.
@@ -1276,3 +1318,88 @@ pub fn set_funding_authority(
12761318
.unwrap(),
12771319
}
12781320
}
1321+
1322+
/// Creates an instruction to update metadata in the mpl token metadata program account for
1323+
/// the pool token
1324+
pub fn update_token_metadata(
1325+
program_id: &Pubkey,
1326+
stake_pool: &Pubkey,
1327+
manager: &Pubkey,
1328+
pool_mint: &Pubkey,
1329+
name: String,
1330+
symbol: String,
1331+
uri: String,
1332+
) -> Instruction {
1333+
let (stake_pool_withdraw_authority, _) =
1334+
Pubkey::find_program_address(&[&stake_pool.to_bytes(), AUTHORITY_WITHDRAW], &program_id);
1335+
1336+
let mpl_token_metadata_program_id = mpl_token_metadata::id();
1337+
let metadata_seeds = &[
1338+
PREFIX.as_bytes(),
1339+
mpl_token_metadata_program_id.as_ref(),
1340+
pool_mint.as_ref(),
1341+
];
1342+
let (token_metadata, _) =
1343+
Pubkey::find_program_address(metadata_seeds, &mpl_token_metadata_program_id);
1344+
1345+
let accounts = vec![
1346+
AccountMeta::new_readonly(*stake_pool, false),
1347+
AccountMeta::new_readonly(*manager, true),
1348+
AccountMeta::new_readonly(stake_pool_withdraw_authority, false),
1349+
AccountMeta::new(token_metadata, false),
1350+
AccountMeta::new_readonly(mpl_token_metadata_program_id, false),
1351+
];
1352+
1353+
Instruction {
1354+
program_id: *program_id,
1355+
accounts,
1356+
data: StakePoolInstruction::UpdateTokenMetadata { name, symbol, uri }
1357+
.try_to_vec()
1358+
.unwrap(),
1359+
}
1360+
}
1361+
1362+
/// Creates an instruction to create metadata using the mpl token metadata program for
1363+
/// the pool token
1364+
pub fn create_token_metadata(
1365+
program_id: &Pubkey,
1366+
stake_pool: &Pubkey,
1367+
manager: &Pubkey,
1368+
pool_mint: &Pubkey,
1369+
payer: &Pubkey,
1370+
name: String,
1371+
symbol: String,
1372+
uri: String,
1373+
) -> Instruction {
1374+
let (stake_pool_withdraw_authority, _) =
1375+
Pubkey::find_program_address(&[&stake_pool.to_bytes(), AUTHORITY_WITHDRAW], &program_id);
1376+
1377+
let mpl_token_metadata_program_id = mpl_token_metadata::id();
1378+
let metadata_seeds = &[
1379+
PREFIX.as_bytes(),
1380+
mpl_token_metadata_program_id.as_ref(),
1381+
pool_mint.as_ref(),
1382+
];
1383+
let (token_metadata, _) =
1384+
Pubkey::find_program_address(metadata_seeds, &mpl_token_metadata_program_id);
1385+
1386+
let accounts = vec![
1387+
AccountMeta::new_readonly(*stake_pool, false),
1388+
AccountMeta::new_readonly(*manager, true),
1389+
AccountMeta::new_readonly(stake_pool_withdraw_authority, false),
1390+
AccountMeta::new_readonly(*pool_mint, false),
1391+
AccountMeta::new_readonly(*payer, false),
1392+
AccountMeta::new(token_metadata, false),
1393+
AccountMeta::new_readonly(mpl_token_metadata_program_id, false),
1394+
AccountMeta::new_readonly(system_program::id(), false),
1395+
AccountMeta::new_readonly(sysvar::rent::id(), false),
1396+
];
1397+
1398+
Instruction {
1399+
program_id: *program_id,
1400+
accounts,
1401+
data: StakePoolInstruction::CreateTokenMetadata { name, symbol, uri }
1402+
.try_to_vec()
1403+
.unwrap(),
1404+
}
1405+
}

0 commit comments

Comments
 (0)