Skip to main content

SDK Components

The GLAM SDK follows a modular architecture with a main GlamClient that provides access to specialized sub-clients for different functionalities:
  • BaseClient: Foundation class providing core Solana functionality
  • GlamClient: Main entry point with lazy-loaded sub-clients
  • Sub-clients: Specialized clients for specific protocol features
  • Models: Type definitions and data structures
  • Utils: Helper functions and utilities

GlamClient

The GlamClient is the main entry point for the GLAM SDK. It uses lazy initialization to load sub-clients only when needed, optimizing performance and resource usage.

Initialization

The GlamClient can be initialized using default Anchor provider and wallet:
import { GlamClient, ClusterNetwork } from '@glamsystems/glam-sdk';

// ANCHOR_PROVIDER_URL and ANCHOR_WALLET env variables must be set
const glamClient = new GlamClient();
Alternatively, a GlamClient can be initialized from a RPC URL and a wallet keypair:
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { AnchorProvider } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";
import { GlamClient} from "@glamsystems/glam-sdk";

const rpcUrl = "https://api.mainnet-beta.solana.com";
const keypairPath = "/path/to/wallet/kaypair.json";

const loadWallet = (path: string) => {
  let keypair = Keypair.fromSecretKey(
    Buffer.from(
      JSON.parse(require("fs").readFileSync(path, { encoding: "utf-8" })),
    ),
  );
  return new NodeWallet(keypair);
};

const glamClient = new GlamClient({
  provider: new AnchorProvider(
     new Connection(rpcUrl),
    loadWallet(keypairPath),
    { commitment: "confirmed" },
  ),
  cluster: ClusterNetwork.Mainnet,
});

Core Features

The GlamClient extends BaseClient and provides:
  • Connection Management: Handles Solana RPC connections
  • Transaction Processing: Sign, send, and confirm transactions
  • Program Integration: Interfaces with GLAM protocol programs
  • Sub-client Access: Lazy-loaded specialized clients

Sub-clients

Sub-clients are loaded on first use.
// Protocol integrations
glamClient.drift          // Drift protocol 
glamClient.driftVaults    // Drift vaults 
glamClient.jupiterSwap    // Jupiter swaps
glamClient.marinade       // Marinade staking
glamClient.kaminoLending  // Kamino lending 
glamClient.kaminoFarm     // Kamino farming
glamClient.kaminoVaults   // Kamino vaults 

// Core vault operations
glamClient.vault          // Vault management
glamClient.invest         // Investment flows
glamClient.fees           // Fee management
glamClient.access         // ACL management

// Utilities
glamClient.state          // Vault state queries
glamClient.price          // For pricing tokens and positions

Transaction Options

Most client methods accept an optional TxOptions parameter:
const txOptions: TxOptions = {
  simulate: true,
  maxFeeLamports: 100_000, // 0.0001 SOL
  useMaxFee: true
}

await glamClient.invest.subscribe(amount, false, txOptions);
TxOptions allows client methods to provide additional options that configure the transaction. Here is the type definition:
export type TxOptions = {
  signer?: PublicKey;
  computeUnitLimit?: number;
  getPriorityFeeMicroLamports?: (tx: VersionedTransaction) => Promise<number>;
  maxFeeLamports?: number;
  useMaxFee?: boolean;
  preInstructions?: TransactionInstruction[];
  lookupTables?: PublicKey[] | AddressLookupTableAccount[];
  simulate?: boolean;
};
  • signer: Overrides the default signer for the transaction
  • computeUnitLimit: Sets the compute unit limit for the transaction
  • getPriorityFeeMicroLamports: A callback function for getting the dynamic priority fee for the transaction
  • maxFeeLamports: Sets the maximum priority fee for the transaction
  • useMaxFee: If true, uses the maximum priority fee
  • preInstructions: Adds instructions to the transaction before the main instruction
  • lookupTables: Adds lookup tables to the transaction
  • simulate: If true, simulates the transaction before sending it

Example Apps

See example apps on Github.