updateValidatorListBalance static method

TransactionInstruction updateValidatorListBalance({
  1. required Pubkey stakePoolAddress,
  2. required Pubkey withdrawAuthority,
  3. required Pubkey validatorList,
  4. required Pubkey reserveStake,
  5. required List<Pubkey> validatorAndTransientStakeAccounts,
  6. required u32 startIndex,
  7. required bool noMerge,
})

Updates balances of validator and transient stake accounts in the pool.

While going through the pairs of validator and transient stake accounts, if the transient stake is inactive, it is merged into the reserve stake account. If the transient stake is active and has matching credits observed, it is merged into the canonical validator stake account. In all other states, nothing is done, and the balance is simply added to the canonical stake account balance.

Keys:

  • [] stakePoolAddress - Stake pool.
  • [] withdrawAuthority - Stake pool withdraw authority.
  • [w] validatorList - Validator stake list storage account.
  • [w] reserveStake - Reserve stake account.
  • [] validatorAndTransientStakeAccounts - N pairs of validator and transient stake accounts.

Data:

  • startIndex - Index to start updating on the validator list.
  • noMerge - If true, don't try merging transient stake accounts into the reserve or validator stake account. Useful for testing or if a particular stake account is in a bad state, but we still want to update.

Implementation

static TransactionInstruction updateValidatorListBalance({
  // Keys
  required final Pubkey stakePoolAddress,
  required final Pubkey withdrawAuthority,
  required final Pubkey validatorList,
  required final Pubkey reserveStake,
  required final List<Pubkey> validatorAndTransientStakeAccounts,
  // Data
  required final u32 startIndex,
  required final bool noMerge,
}) {
  assert((validatorAndTransientStakeAccounts.length % 2) == 0);
  //  0. `[]` Stake pool
  //  1. `[]` Stake pool withdraw authority
  //  2. `[w]` Validator stake list storage account
  //  3. `[w]` Reserve stake account
  //  4. `[]` Sysvar clock
  //  5. `[]` Sysvar stake history
  //  6. `[]` Stake program
  //  7. `[w]` N pairs of validator and transient stake accounts
  final List<AccountMeta> keys = [
    AccountMeta(stakePoolAddress),
    AccountMeta(withdrawAuthority),
    AccountMeta.writable(validatorList),
    AccountMeta.writable(reserveStake),
    AccountMeta(sysvarClockPubkey),
    AccountMeta(sysvarStakeHistoryPubkey),
    AccountMeta(StakeProgram.programId),
    for (final Pubkey account in validatorAndTransientStakeAccounts)
      AccountMeta.writable(account),
  ];

  final List<Iterable<int>> data = [
    borsh.u32.encode(startIndex),
    borsh.boolean.encode(noMerge),
  ];

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