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

Commit 48b8381

Browse files
authored
stake-pool: Add instruction creators that re-use existing seeds (#7129)
* increase_additional_validator_stake_with_vote, decrease_additional_validator_stake_with_vote Signed-off-by: Hrushi20 <[email protected]> * fix formatting issue * address review comments Signed-off-by: Hrushi20 <[email protected]> --------- Signed-off-by: Hrushi20 <[email protected]>
1 parent 232a950 commit 48b8381

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

stake-pool/program/src/instruction.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,62 @@ pub fn decrease_validator_stake_with_vote(
13231323
)
13241324
}
13251325

1326+
/// Create a `IncreaseAdditionalValidatorStake` instruction given an existing
1327+
/// stake pool, valiator list and vote account
1328+
pub fn increase_additional_validator_stake_with_list(
1329+
program_id: &Pubkey,
1330+
stake_pool: &StakePool,
1331+
validator_list: &ValidatorList,
1332+
stake_pool_address: &Pubkey,
1333+
vote_account_address: &Pubkey,
1334+
lamports: u64,
1335+
ephemeral_stake_seed: u64,
1336+
) -> Result<Instruction, ProgramError> {
1337+
let validator_info = validator_list
1338+
.find(vote_account_address)
1339+
.ok_or(ProgramError::InvalidInstructionData)?;
1340+
let transient_stake_seed = u64::from(validator_info.transient_seed_suffix);
1341+
let validator_stake_seed = NonZeroU32::new(validator_info.validator_seed_suffix.into());
1342+
Ok(increase_additional_validator_stake_with_vote(
1343+
program_id,
1344+
stake_pool,
1345+
stake_pool_address,
1346+
vote_account_address,
1347+
lamports,
1348+
validator_stake_seed,
1349+
transient_stake_seed,
1350+
ephemeral_stake_seed,
1351+
))
1352+
}
1353+
1354+
/// Create a `DecreaseAdditionalValidatorStake` instruction given an existing
1355+
/// stake pool, valiator list and vote account
1356+
pub fn decrease_additional_validator_stake_with_list(
1357+
program_id: &Pubkey,
1358+
stake_pool: &StakePool,
1359+
validator_list: &ValidatorList,
1360+
stake_pool_address: &Pubkey,
1361+
vote_account_address: &Pubkey,
1362+
lamports: u64,
1363+
ephemeral_stake_seed: u64,
1364+
) -> Result<Instruction, ProgramError> {
1365+
let validator_info = validator_list
1366+
.find(vote_account_address)
1367+
.ok_or(ProgramError::InvalidInstructionData)?;
1368+
let transient_stake_seed = u64::from(validator_info.transient_seed_suffix);
1369+
let validator_stake_seed = NonZeroU32::new(validator_info.validator_seed_suffix.into());
1370+
Ok(decrease_additional_validator_stake_with_vote(
1371+
program_id,
1372+
stake_pool,
1373+
stake_pool_address,
1374+
vote_account_address,
1375+
lamports,
1376+
validator_stake_seed,
1377+
transient_stake_seed,
1378+
ephemeral_stake_seed,
1379+
))
1380+
}
1381+
13261382
/// Create a `DecreaseAdditionalValidatorStake` instruction given an existing
13271383
/// stake pool and vote account
13281384
pub fn decrease_additional_validator_stake_with_vote(

0 commit comments

Comments
 (0)