setPreferredValidator static method

TransactionInstruction setPreferredValidator({
  1. required Pubkey stakePoolAddress,
  2. required Pubkey staker,
  3. required Pubkey validatorList,
  4. required PreferredValidatorType validatorType,
  5. required Pubkey? validatorVoteAddress,
})

(Staker only) Set the preferred deposit or withdraw stake account for the stake pool.

In order to avoid users abusing the stake pool as a free conversion between SOL staked on different validators, the staker can force all deposits and/or withdraws to go to one chosen account, or unset that account.

Fails if the validator is not part of the stake pool.

Keys:

  • stakePoolAddress [w] - Stake pool.
  • staker [s] Stake pool staker.
  • validatorList [] Validator list.

Data:

  • validatorType - Affected operation (deposit or withdraw).
  • validatorVoteAddress - Validator vote account that deposits or withdraws must go through, unset with null

Implementation

static TransactionInstruction setPreferredValidator({
  // Keys
  required final Pubkey stakePoolAddress,
  required final Pubkey staker,
  required final Pubkey validatorList,
  // Data
  required final PreferredValidatorType validatorType,
  required final Pubkey? validatorVoteAddress,
}) {
  // 0. `[w]` Stake pool
  // 1. `[s]` Stake pool staker
  // 2. `[]` Validator list
  final List<AccountMeta> keys = [
    AccountMeta.writable(stakePoolAddress),
    AccountMeta.signer(staker),
    AccountMeta(validatorList),
  ];

  final List<Iterable<int>> data = [
    borsh.enumeration(PreferredValidatorType.values).encode(validatorType),
    borsh.pubkey.option().encode(validatorVoteAddress?.toBase58()),
  ];

  return _instance.createTransactionIntruction(
    StakePoolInstruction.setPreferredValidator,
    keys: keys,
    data: data,
  );
}