authorizeWithSeed static method

TransactionInstruction authorizeWithSeed({
  1. required Pubkey stakeAccount,
  2. required Pubkey authorityBase,
  3. required Pubkey? custodian,
  4. required Pubkey newAuthority,
  5. required StakeAuthorize authorityType,
  6. required String authoritySeed,
  7. required Pubkey authorityOwner,
})

Authorize a key to manage stake or withdrawal with a derived key.

Keys:

  • [w] stakeAccount - Stake account to be updated.
  • [s] authorityBase - Base key of stake or withdraw authority.
  • [s] custodian - Lockup authority, if updating StakeAuthorize.withdrawer before lockup.

Implementation

static TransactionInstruction authorizeWithSeed({
  // Keys
  required final Pubkey stakeAccount,
  required final Pubkey authorityBase,
  required final Pubkey? custodian,
  // Data
  required final Pubkey newAuthority,
  required final StakeAuthorize authorityType,
  required final String authoritySeed,
  required final Pubkey authorityOwner,
}) {
  // 0. `[w]` Stake account to be updated
  // 1. `[]` Clock sysvar
  // 2. `[s]` The stake or withdraw authority
  // 3. `[s]` Lockup authority, if updating StakeAuthorize::Withdrawer before lockup expiration.
  final List<AccountMeta> keys = [
    AccountMeta.writable(stakeAccount),
    AccountMeta(sysvarClockPubkey),
    AccountMeta.signer(authorityBase),
    if (custodian != null)
      AccountMeta.signer(custodian)
  ];

  final List<Iterable<u8>> data = [
    borsh.pubkey.encode(newAuthority.toBase58()),
    borsh.enumeration(StakeAuthorize.values).encode(authorityType), [0,0,0], // padding
    borsh.rustString().encode(authoritySeed),
    borsh.pubkey.encode(authorityOwner.toBase58()),
  ];

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