|
1 | 1 | //! Instruction types
|
2 | 2 |
|
3 | 3 | #![allow(clippy::too_many_arguments)]
|
| 4 | + |
4 | 5 | use {
|
5 | 6 | crate::{
|
6 | 7 | find_deposit_authority_program_address, find_stake_program_address,
|
|
9 | 10 | MAX_VALIDATORS_TO_UPDATE,
|
10 | 11 | },
|
11 | 12 | borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
|
| 13 | + mpl_token_metadata::pda::find_metadata_account, |
12 | 14 | solana_program::{
|
13 | 15 | instruction::{AccountMeta, Instruction},
|
14 | 16 | pubkey::Pubkey,
|
@@ -374,6 +376,48 @@ pub enum StakePoolInstruction {
|
374 | 376 | /// 11. `[]` Token program id
|
375 | 377 | /// 12. `[s]` (Optional) Stake pool sol withdraw authority
|
376 | 378 | 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 | + }, |
377 | 421 | }
|
378 | 422 |
|
379 | 423 | /// Creates an 'initialize' instruction.
|
@@ -1276,3 +1320,72 @@ pub fn set_funding_authority(
|
1276 | 1320 | .unwrap(),
|
1277 | 1321 | }
|
1278 | 1322 | }
|
| 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