Skip to content

Commit

Permalink
SPL: WIP for finding a valid stake account to withdraw from
Browse files Browse the repository at this point in the history
  • Loading branch information
dankelleher committed Feb 29, 2024
1 parent a88131c commit 10e19c2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/sdks/spl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ export class SplClient extends BeamInterface<SplBeam.SplBeam, StateAccount> {
return transaction.add(instruction);
}

private async findStakeAccountToSplit(amount: BN): Promise<PublicKey> {

Check failure on line 338 in packages/sdks/spl/src/index.ts

View workflow job for this annotation

GitHub Actions / yarn-lint

'amount' is defined but never used
// Finds a validator stake account with sufficient active or transient stake to withdraw from there
// If none is found, revert to the reserve stake account
const validatorList = this.spl.stakePoolState.validatorList;
const data =
await this.provider.connection.getParsedAccountInfo(validatorList);
console.log(data);

return this.spl.stakePoolState.reserveStake;
}

/**
* Returns a transaction to withdraw from an SPL stake-pool into a new stake account
*/
Expand All @@ -351,6 +362,8 @@ export class SplClient extends BeamInterface<SplBeam.SplBeam, StateAccount> {
gsolTokenAccount,
);

const stakeAccountToSplit = await this.findStakeAccountToSplit(amount);

const instruction = await this.program.methods
.withdrawStake(amount)
.accounts({
Expand All @@ -365,7 +378,7 @@ export class SplClient extends BeamInterface<SplBeam.SplBeam, StateAccount> {
vaultAuthority: this.vaultAuthority[0],
stakePoolWithdrawAuthority: this.spl.withdrawAuthority,
validatorStakeList: this.spl.stakePoolState.validatorList,
stakeAccountToSplit: this.spl.stakePoolState.reserveStake,
stakeAccountToSplit,
managerFeeAccount: this.spl.stakePoolState.managerFeeAccount,
sysvarClock: SYSVAR_CLOCK_PUBKEY,
sysvarStakeHistory: SYSVAR_STAKE_HISTORY_PUBKEY,
Expand Down

0 comments on commit 10e19c2

Please sign in to comment.