merge static method

TransactionInstruction merge({
  1. required Pubkey destinationStakeAccount,
  2. required Pubkey sourceStakeAccount,
  3. required Pubkey authority,
})

Merge two stake accounts.

Both accounts must have identical lockup and authority keys. A merge is possible between two stakes in the following states with no additional conditions:

  • two deactivated stakes
  • an inactive stake into an activating stake during its activation epoch

For the following cases, the voter pubkey and vote credits observed must match:

  • two activated stakes
  • two activating accounts that share an activation epoch, during the activation epoch

All other combinations of stake states will fail to merge, including all "transient" states, where a stake is activating or deactivating with a non-zero effective stake.

Keys:

  • [w] destinationStakeAccount - Destination stake account.
  • [w] sourceStakeAccount - Source stake account, this account will be drained.
  • [s] authority - Stake authority.

Implementation

static TransactionInstruction merge({
  required final Pubkey destinationStakeAccount,
  required final Pubkey sourceStakeAccount,
  required final Pubkey authority,
}) {
  // 0. `[w]` Destination stake account for the merge
  // 1. `[w]` Source stake account for to merge.  This account will be drained
  // 2. `[]` Clock sysvar
  // 3. `[]` Stake history sysvar that carries stake warmup/cooldown history
  // 4. `[s]` Stake authority
  final List<AccountMeta> keys = [
    AccountMeta.writable(destinationStakeAccount),
    AccountMeta.writable(sourceStakeAccount),
    AccountMeta(sysvarClockPubkey),
    AccountMeta(sysvarStakeHistoryPubkey),
    AccountMeta.signer(authority),
  ];

  return _instance.createTransactionIntruction(
    StakeInstruction.merge,
    keys: keys,
  );
}