Skip to content

Commit

Permalink
implement new withdrawSol method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Jan 1, 2025
1 parent 663fb69 commit f6ccfbe
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import software.sava.rpc.json.http.response.AccountInfo;
import software.sava.solana.programs.clients.NativeProgramAccountClient;
import software.sava.solana.programs.stakepool.StakePoolAccounts;
import software.sava.solana.programs.stakepool.StakePoolProgram;
import software.sava.solana.programs.stakepool.StakePoolProgramClient;
import software.sava.solana.programs.stakepool.StakePoolState;

Expand Down Expand Up @@ -114,24 +115,25 @@ public Instruction depositStakeWithSlippage(final AccountInfo<StakePoolState> st
}

@Override
public Instruction withdrawSol(final AccountInfo<StakePoolState> stakePoolStateAccountInfo,
public Instruction withdrawSol(final PublicKey stakePoolProgram,
final StakePoolState stakePoolState,
final PublicKey poolTokenATA,
final long poolTokenAmount) {
final var stakePoolState = stakePoolStateAccountInfo.data();
final var stakePoolWithdrawAuthority = findStakePoolWithdrawAuthority(stakePoolStateAccountInfo);
final var stakePoolWithdrawAuthority = StakePoolProgram.
findStakePoolWithdrawAuthority(stakePoolState.address(), stakePoolProgram);
return GlamProgram.stakePoolWithdrawSol(
invokedProgram,
solanaAccounts,
manager.publicKey(),
glamFundAccounts.fundPublicKey(),
glamFundAccounts.treasuryPublicKey(),
stakePoolStateAccountInfo.owner(),
stakePoolState.address(),
stakePoolWithdrawAuthority.publicKey(),
stakePoolState.reserveStake(),
stakePoolState.poolMint(),
stakePoolState.managerFeeAccount(),
poolTokenATA,
stakePoolProgram,
stakePoolState.tokenProgramId(),
poolTokenAmount
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package software.sava.anchor.programs.marinade;

import software.sava.core.accounts.meta.AccountMeta;
import software.sava.core.accounts.PublicKey;
import software.sava.core.accounts.meta.AccountMeta;

import static software.sava.core.accounts.PublicKey.fromBase58Encoded;
import static software.sava.core.accounts.meta.AccountMeta.createInvoked;
import static software.sava.core.accounts.meta.AccountMeta.createWrite;
import static software.sava.core.accounts.PublicKey.fromBase58Encoded;

public interface MarinadeAccounts {

Expand All @@ -20,7 +20,8 @@ public interface MarinadeAccounts {
"HZsepB79dnpvH6qfVgvMpS738EndHw3qSHo4Gv5WX1KA",
"7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE",
"EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL",
"UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q"
"UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q",
"DwFYJNnhLmw19FBTrVaLWZ8SZJpxdPoSYVSJaio9tjbY"
);

PublicKey mSolTokenMint();
Expand Down Expand Up @@ -57,6 +58,8 @@ public interface MarinadeAccounts {

PublicKey liquidityPoolSolLegAccount();

PublicKey validatorListAccount();

static MarinadeAccounts createAddressConstants(
final PublicKey mSolTokenMint,
final PublicKey mSolTokenMintAuthorityPDA,
Expand All @@ -68,7 +71,8 @@ static MarinadeAccounts createAddressConstants(
final PublicKey lpAuthPDA,
final PublicKey mSolLegAccount,
final PublicKey mSolLegAuthority,
final PublicKey solLegAccount) {
final PublicKey solLegAccount,
final PublicKey validatorListAccount) {
return new MarinadeAccountsRecord(
mSolTokenMint,
mSolTokenMintAuthorityPDA,
Expand All @@ -84,7 +88,8 @@ static MarinadeAccounts createAddressConstants(
lpAuthPDA,
mSolLegAccount,
mSolLegAuthority,
solLegAccount
solLegAccount,
validatorListAccount
);
}

Expand All @@ -99,7 +104,8 @@ static MarinadeAccounts createAddressConstants(
final String lpAuthPDA,
final String mSolLegAccount,
final String mSolLegAuthority,
final String solLegAccount) {
final String solLegAccount,
final String validatorListAccount) {
return createAddressConstants(
fromBase58Encoded(mSolTokenMint),
fromBase58Encoded(mSolTokenMintAuthorityPDA),
Expand All @@ -111,7 +117,8 @@ static MarinadeAccounts createAddressConstants(
fromBase58Encoded(lpAuthPDA),
fromBase58Encoded(mSolLegAccount),
fromBase58Encoded(mSolLegAuthority),
fromBase58Encoded(solLegAccount)
fromBase58Encoded(solLegAccount),
fromBase58Encoded(validatorListAccount)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package software.sava.anchor.programs.marinade;

import software.sava.core.accounts.meta.AccountMeta;
import software.sava.core.accounts.PublicKey;
import software.sava.core.accounts.meta.AccountMeta;

record MarinadeAccountsRecord(PublicKey mSolTokenMint,
PublicKey mSolTokenMintAuthorityPDA,
Expand All @@ -19,5 +19,6 @@ record MarinadeAccountsRecord(PublicKey mSolTokenMint,
PublicKey liquidityPoolAuthPDA,
PublicKey liquidityPoolMSolLegAccount,
PublicKey liquidityPoolMSolLegAuthority,
PublicKey liquidityPoolSolLegAccount) implements MarinadeAccounts {
PublicKey liquidityPoolSolLegAccount,
PublicKey validatorListAccount) implements MarinadeAccounts {
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencyResolutionManagement {
}
versionCatalogs {
libs {
from("software.sava:solana-version-catalog:0.4.14")
from("software.sava:solana-version-catalog:0.4.19")
}
}
}

0 comments on commit f6ccfbe

Please sign in to comment.