Skip to main content

Overview

VaultClient handles vault operations like depositing assets, transferring tokens, wrapping/unwrapping SOL, and managing token accounts.

Access

const client = new GlamClient();
client.vault.wrap(...);

Methods

wrap

async wrap(
  amount: BN | number,
  txOptions?: TxOptions
): Promise<TransactionSignature>
Wraps vault SOL into wSOL (wrapped SOL).
amount
BN | number
required
Amount of SOL to wrap in lamports
txOptions
TxOptions
Transaction options
import { BN } from "@coral-xyz/anchor";

// Wrap 0.1 SOL
await client.vault.wrap(new BN(100_000_000));

unwrap

async unwrap(txOptions?: TxOptions): Promise<TransactionSignature>
Unwraps all vault wSOL back to SOL by closing the wSOL token account.
txOptions
TxOptions
Transaction options
// Unwrap all wSOL in vault
await client.vault.unwrap();

systemTransfer

async systemTransfer(
  amount: BN | number,
  to: PublicKey | string,
  txOptions?: TxOptions
): Promise<TransactionSignature>
Transfers SOL from vault to another account.
amount
BN | number
required
Amount of SOL to transfer in lamports
to
PublicKey | string
required
Recipient public key
txOptions
TxOptions
Transaction options
// Transfer 0.01 SOL to recipient
await client.vault.systemTransfer(
  new BN(10_000_000),
  "recipient1111111111111111111111111111111111"
);

tokenTransfer

async tokenTransfer(
  mint: PublicKey | string,
  amount: number | BN,
  to: PublicKey | string,
  txOptions?: TxOptions
): Promise<TransactionSignature>
Transfers tokens from vault to another account.
mint
PublicKey | string
required
Token mint address
amount
number | BN
required
Amount of tokens to transfer (in token’s smallest unit)
to
PublicKey | string
required
Recipient public key
txOptions
TxOptions
Transaction options
// Transfer 100 USDC (6 decimals)
const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
await client.vault.tokenTransfer(
  USDC_MINT,
  100_000_000, // 100 USDC
  recipientPubkey
);
This method automatically creates the recipient’s associated token account if it doesn’t exist.

closeTokenAccounts

async closeTokenAccounts(
  tokenAccounts: PublicKey[] | string[],
  txOptions?: TxOptions
): Promise<TransactionSignature>
Closes multiple vault token accounts and recovers rent.
tokenAccounts
PublicKey[] | string[]
required
Array of token account addresses to close
txOptions
TxOptions
Transaction options
// Close empty token accounts
await client.vault.closeTokenAccounts([
  "tokenAccount11111111111111111111111111111111",
  "tokenAccount22222222222222222222222222222222"
]);
Token accounts must have zero balance to be closed. This method handles both TOKEN_PROGRAM and TOKEN_2022_PROGRAM accounts.

deposit

async deposit(
  mint: PublicKey | string,
  amount: number | BN,
  txOptions?: TxOptions
): Promise<TransactionSignature>
Deposits tokens from signer to vault.
mint
PublicKey | string
required
Token mint address
amount
number | BN
required
Amount to deposit (in token’s smallest unit)
txOptions
TxOptions
Transaction options
// Deposit 50 USDC to vault
await client.vault.deposit(USDC_MINT, 50_000_000);

depositSol

async depositSol(
  lamports: number | BN,
  wrap?: boolean,
  txOptions?: TxOptions
): Promise<TransactionSignature>
Deposits SOL from signer to vault.
lamports
number | BN
required
Amount of SOL to deposit in lamports
wrap
boolean
default:"true"
Whether to wrap SOL as wSOL or keep as native SOL
txOptions
TxOptions
Transaction options
// Deposit 1 SOL as wSOL
await client.vault.depositSol(1_000_000_000, true);

// Deposit 1 SOL as native SOL
await client.vault.depositSol(1_000_000_000, false);

maybeWrapSol

async maybeWrapSol(
  lamports: number | BN,
  signer?: PublicKey
): Promise<TransactionInstruction[]>
Generates instructions to wrap SOL into wSOL if the vault doesn’t have enough wSOL balance.
lamports
number | BN
required
Desired amount of wSOL in lamports
signer
PublicKey
Signer public key. Defaults to client.signer
Returns an array of instructions. Empty array if vault already has sufficient wSOL.
// Get wrap instructions if needed for a swap
const wrapIxs = await client.vault.maybeWrapSol(500_000_000);

// Include in transaction
const tx = new Transaction();
tx.add(...wrapIxs);
tx.add(...swapIxs);
This is useful when preparing transactions that require wSOL. The method:
  • Checks current vault wSOL balance
  • Checks vault SOL balance
  • Returns wrap instructions only if needed and vault has sufficient SOL
  • Throws error if vault has insufficient SOL

Transaction builder

For advanced use cases, access the transaction builder directly:
client.vault.txBuilder: TxBuilder
The builder provides methods that return instructions or transactions without sending:

wrapIxs

async wrapIxs(
  amount: BN,
  glamSigner: PublicKey
): Promise<TransactionInstruction[]>
Returns instructions to wrap SOL.

wrapTx

async wrapTx(
  amount: BN,
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to wrap SOL.

unwrapIx

async unwrapIx(glamSigner: PublicKey): Promise<TransactionInstruction>
Returns instruction to unwrap wSOL.

unwrapTx

async unwrapTx(txOptions: TxOptions): Promise<VersionedTransaction>
Returns a versioned transaction to unwrap wSOL.

systemTransferIx

async systemTransferIx(
  amount: BN,
  to: PublicKey,
  glamSigner: PublicKey
): Promise<TransactionInstruction>
Returns instruction to transfer SOL.

systemTransferTx

async systemTransferTx(
  amount: BN,
  to: PublicKey,
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to transfer SOL.

tokenTransferIxs

async tokenTransferIxs(
  mint: PublicKey,
  amount: number | BN,
  to: PublicKey,
  glamSigner: PublicKey
): Promise<TransactionInstruction[]>
Returns instructions to transfer tokens.

tokenTransferTx

async tokenTransferTx(
  mint: PublicKey,
  amount: number | BN,
  to: PublicKey,
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to transfer tokens.

closeTokenAccountIx

async closeTokenAccountIx(
  tokenAccount: PublicKey,
  tokenProgram: PublicKey,
  signer?: PublicKey
): Promise<TransactionInstruction>
Returns instruction to close a token account.

closeTokenAccountsTx

async closeTokenAccountsTx(
  pubkeys: PublicKey[],
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to close token accounts.

depositSolIxs

async depositSolIxs(
  lamports: number | BN,
  wrap: boolean,
  glamSigner: PublicKey
): Promise<TransactionInstruction[]>
Returns instructions to deposit SOL.

depositSolTx

async depositSolTx(
  lamports: number | BN,
  wrap: boolean,
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to deposit SOL.

depositIxs

async depositIxs(
  asset: PublicKey,
  amount: number | BN,
  glamSigner: PublicKey
): Promise<TransactionInstruction[]>
Returns instructions to deposit tokens.

depositTx

async depositTx(
  asset: PublicKey,
  amount: number | BN,
  txOptions: TxOptions
): Promise<VersionedTransaction>
Returns a versioned transaction to deposit tokens.

Example usage

import { GlamClient } from "@glam/sdk";
import { PublicKey } from "@solana/web3.js";
import { BN } from "@coral-xyz/anchor";

const client = new GlamClient();
client.statePda = new PublicKey("your-vault-state-pda");

// Deposit USDC to vault
const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
await client.vault.deposit(USDC, new BN(100_000_000));

// Transfer some USDC from vault to recipient
await client.vault.tokenTransfer(
  USDC,
  new BN(50_000_000),
  recipientPubkey
);

// Check vault balance
const balance = await client.getVaultTokenBalance(USDC);
console.log(`Vault USDC balance: ${balance.uiAmount}`);

Build docs developers (and LLMs) love