Clients for native staking and stake pool operations.
StakePoolClient
Client for interacting with stake pools (liquid staking tokens).
Constructor
new StakePoolClient(
base: BaseClient,
stake: StakeClient,
marinade: MarinadeClient
)
Methods
depositSol
Deposits SOL to a stake pool and receives pool tokens.
await client.stakePool.depositSol(
stakePool: PublicKey,
amount: BN,
txOptions?: TxOptions
): Promise<TransactionSignature>
Amount of SOL to deposit in lamports
depositStake
Deposits a stake account to a stake pool.
await client.stakePool.depositStake(
stakePool: PublicKey,
stakeAccount: PublicKey,
txOptions?: TxOptions
): Promise<TransactionSignature>
withdrawStake
Withdraws pool tokens for a stake account.
await client.stakePool.withdrawStake(
stakePool: PublicKey,
amount: BN,
deactivate?: boolean,
txOptions?: TxOptions
): Promise<TransactionSignature>
Amount of pool tokens to withdraw
Whether to deactivate the stake account immediately
unstake
Unstakes any liquid staking token (LST) back to native stake.
await client.stakePool.unstake(
asset: PublicKey,
amount: number | BN,
deactivate?: boolean,
txOptions?: TxOptions
): Promise<TransactionSignature>
LST mint address (e.g., mSOL, JitoSOL, bSOL)
Whether to deactivate the stake account immediately
Data Fetching
getStakePoolAccountData
Fetches stake pool account data.
await client.stakePool.getStakePoolAccountData(
stakePool: PublicKey
): Promise<StakePoolAccountData>
Returns: Stake pool configuration and state
getStakeAccountVoter
Gets the vote account for a stake account.
await client.stakePool.getStakeAccountVoter(
stakeAccount: PublicKey
): Promise<PublicKey | null>
StakeClient
Client for native staking operations.
Constructor
new StakeClient(
base: BaseClient
)
Methods
initializeAndDelegateStake
Creates a new stake account, initializes it, and delegates to a validator.
await client.stake.initializeAndDelegateStake(
vote: PublicKey,
amount: BN,
txOptions?: TxOptions
): Promise<TransactionSignature>
Vote account address of the validator
Amount to stake in lamports
deactivate
Deactivates one or more stake accounts.
await client.stake.deactivate(
stakeAccounts: PublicKey[],
txOptions?: TxOptions
): Promise<TransactionSignature>
Array of stake accounts to deactivate
withdraw
Withdraws from deactivated stake accounts.
await client.stake.withdraw(
stakeAccounts: PublicKey[],
txOptions?: TxOptions
): Promise<TransactionSignature>
Array of deactivated stake accounts to withdraw from
merge
Merges two stake accounts.
await client.stake.merge(
destinationStake: PublicKey,
sourceStake: PublicKey,
txOptions?: TxOptions
): Promise<TransactionSignature>
Destination stake account
Source stake account (will be closed)
split
Splits a stake account into two.
await client.stake.split(
existingStake: PublicKey,
lamports: BN,
txOptions?: TxOptions
): Promise<{
newStake: PublicKey;
txSig: TransactionSignature;
}>
Existing stake account to split
Amount to split into the new stake account
Returns: Object containing the new stake account address and transaction signature
move
Moves stake from one account to another.
await client.stake.move(
sourceStake: PublicKey,
destinationStake: PublicKey,
amount: BN,
txOptions?: TxOptions
): Promise<TransactionSignature>
Destination stake account
Amount to move in lamports
Helper Methods
createStakeAccount
Creates a new empty stake account.
await client.stake.createStakeAccount(
signer: PublicKey
): Promise<[PublicKey, TransactionInstruction]>
Returns: Tuple of [stakeAccountAddress, createInstruction]
getStakeAccountVoter
Gets the vote account a stake account is delegated to.
await client.stake.getStakeAccountVoter(
stakeAccount: PublicKey
): Promise<PublicKey | null>
Example
import { BN } from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
import { GlamClient } from '@glam/anchor';
const client = new GlamClient();
// Native staking to a validator
const voteAccount = new PublicKey('...');
const stakeSig = await client.stake.initializeAndDelegateStake(
voteAccount,
new BN(10_000_000_000) // 10 SOL
);
// Deposit SOL to a stake pool
const stakePoolAddress = new PublicKey('...');
const depositSig = await client.stakePool.depositSol(
stakePoolAddress,
new BN(5_000_000_000) // 5 SOL
);
// Unstake mSOL back to native stake
const MSOL = new PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So');
const unstakeSig = await client.stakePool.unstake(
MSOL,
new BN(1_000_000_000), // 1 mSOL
true // deactivate immediately
);
// Split a stake account
const stakeAccount = new PublicKey('...');
const { newStake, txSig } = await client.stake.split(
stakeAccount,
new BN(2_000_000_000) // Split 2 SOL into new account
);
console.log('New stake account:', newStake.toBase58());