withdrawSol static method

TransactionInstruction withdrawSol({
  1. required Pubkey stakePoolAddress,
  2. required Pubkey withdrawAuthority,
  3. required Pubkey userTransferAuthority,
  4. required Pubkey userTokenAccount,
  5. required Pubkey reserveStake,
  6. required Pubkey receiverAccount,
  7. required Pubkey receiverTokenAccount,
  8. required Pubkey poolMint,
  9. Pubkey? solWithdrawAuthority,
  10. required bu64 lamports,
})

Withdraw SOL directly from the pool's reserve account. Fails if the reserve does not have enough SOL.

  • [w] stakePoolAddress - Stake pool.
  • [] withdrawAuthority - Stake pool withdraw authority.
  • [s] userTransferAuthority - User transfer authority, for pool token account.
  • [w] userTokenAccount - User account to burn pool tokens.
  • [w] reserveStake - Reserve stake account, to withdraw SOL.
  • [w] receiverAccount - Account receiving the lamports from the reserve, must be a system account.
  • [w] receiverTokenAccount - Account to receive pool fee tokens.
  • [w] poolMint - Pool token mint account.
  • [s] solWithdrawAuthority - (Optional) Stake pool sol withdraw authority.

Implementation

static TransactionInstruction withdrawSol({
  // Keys
  required final Pubkey stakePoolAddress,
  required final Pubkey withdrawAuthority,
  required final Pubkey userTransferAuthority,
  required final Pubkey userTokenAccount,
  required final Pubkey reserveStake,
  required final Pubkey receiverAccount,
  required final Pubkey receiverTokenAccount,
  required final Pubkey poolMint,
  final Pubkey? solWithdrawAuthority,
  // Data
  required final bu64 lamports,
}) {
  //  0. `[w]` Stake pool
  //  1. `[]` Stake pool withdraw authority
  //  2. `[s]` User transfer authority, for pool token account
  //  3. `[w]` User account to burn pool tokens
  //  4. `[w]` Reserve stake account, to withdraw SOL
  //  5. `[w]` Account receiving the lamports from the reserve, must be a system account
  //  6. `[w]` Account to receive pool fee tokens
  //  7. `[w]` Pool token mint account
  //  8. '[]' Clock sysvar
  //  9. '[]' Stake history sysvar
  // 10. `[]` Stake program account
  // 11. `[]` Token program id
  // 12. `[s]` (Optional) Stake pool sol withdraw authority
  final List<AccountMeta> keys = [
    AccountMeta.writable(stakePoolAddress),
    AccountMeta(withdrawAuthority),
    AccountMeta.signer(userTransferAuthority),
    AccountMeta.writable(userTokenAccount),
    AccountMeta.writable(reserveStake),
    AccountMeta.writable(receiverAccount),
    AccountMeta.writable(receiverTokenAccount),
    AccountMeta.writable(poolMint),
    AccountMeta(sysvarClockPubkey),
    AccountMeta(sysvarStakeHistoryPubkey),
    AccountMeta(StakeProgram.programId),
    AccountMeta(TokenProgram.programId),
    if (solWithdrawAuthority != null)
      AccountMeta.signer(solWithdrawAuthority)
  ];

  final List<Iterable<int>> data = [
    borsh.u64.encode(lamports),
  ];

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