decreaseValidatorStake static method
(Staker only) Decrease active stake on a validator, eventually moving it to the reserve.
Internally, this instruction splits a validator stake account into its corresponding transient stake account and deactivates it.
In order to rebalance the pool without taking custody, the staker needs a way of reducing the stake on a stake account. This instruction splits some amount of stake, up to the total activated stake, from the canonical validator stake account, into its "transient" stake account.
The instruction only succeeds if the transient stake account does not exist. The amount of
lamports to move must be at least rent-exemption plus
max(crate::MINIMUM_ACTIVE_STAKE, solana_program::stake::tools::get_minimum_delegation())
.
Keys:
[]
stakePoolAddress
- Stake pool.[s]
staker
- Stake pool staker.[]
withdrawAuthority
- Stake pool withdraw authority.[w]
validatorList
- Validator list.[w]
stakeAccount
- Canonical stake account to split from.[w]
transientStakeAccount
- Transient stake account to receive split.
Data:
lamports
- Amount of lamports to split into the transient stake account.transientStakeSeed
- Seed used to create transient stake account.
Implementation
static TransactionInstruction decreaseValidatorStake({
// Keys
required final Pubkey stakePoolAddress,
required final Pubkey staker,
required final Pubkey withdrawAuthority,
required final Pubkey validatorList,
required final Pubkey stakeAccount,
required final Pubkey transientStakeAccount,
// Data
required final bu64 lamports,
required final bu64 transientStakeSeed,
}) {
// 0. `[]` Stake pool
// 1. `[s]` Stake pool staker
// 2. `[]` Stake pool withdraw authority
// 3. `[w]` Validator list
// 4. `[w]` Canonical stake account to split from
// 5. `[w]` Transient stake account to receive split
// 6. `[]` Clock sysvar
// 7. `[]` Rent sysvar
// 8. `[]` System program
// 9. `[]` Stake program
final List<AccountMeta> keys = [
AccountMeta(stakePoolAddress),
AccountMeta.signer(staker),
AccountMeta(withdrawAuthority),
AccountMeta.writable(validatorList),
AccountMeta.writable(stakeAccount),
AccountMeta.writable(transientStakeAccount),
AccountMeta(sysvarClockPubkey),
AccountMeta(sysvarRentPubkey),
AccountMeta(SystemProgram.programId),
AccountMeta(StakeProgram.programId),
];
final List<Iterable<int>> data = [
borsh.u64.encode(lamports),
borsh.u64.encode(transientStakeSeed),
];
return _instance.createTransactionIntruction(
StakePoolInstruction.decreaseValidatorStake,
keys: keys,
data: data,
);
}