Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.glam.systems/llms.txt

Use this file to discover all available pages before exploring further.

Vault Setup

Refer to CLI docs to create the vault, enable integrations and manage delegates.

Project Setup

Install @glamsystems/glam-sdk using your preferred package manager (npm, pnpm, yarn etc). An example TypeScript project using the GLAM SDK can be found on Github.

Solana Basics

Key building blocks used across programs and integrations:

Initialize a GlamClient

Build GlamClient from environment variables:
import { GlamClient} from "@glamsystems/glam-sdk";

// Make sure the following env variables are available:
// ANCHOR_PROVIDER_URL=<solana_rpc_url>
// ANCHOR_WALLET=<path_to_keypair>
const glamClient = new GlamClient();
Alternatively you can create a GlamClient instance from RPC URL and wallet keypair programmatically:
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 rpcConnection = new Connection("solana_rpc_url");
const loadWallet = (path: string) => {
  let payer = Keypair.fromSecretKey(
    Buffer.from(
      JSON.parse(require("fs").readFileSync(path, { encoding: "utf-8" })),
    ),
  );
  return new NodeWallet(payer);
};

const glamClient = new GlamClient({
  provider: new AnchorProvider(
    rpcConnection,
    loadWallet("/path/to/wallet/keypair.json"),
    { commitment: "confirmed" },
  ),
  cluster: ClusterNetwork.Mainnet,
});

Transaction Options

All glam sdk methods that initiate transactions accept a param txOptions which can be used to customize priority fees, simulation behavior, lookup tables, etc. It’s recommended to enable simulation and put a max cap on the priority fee:
const txOptions = {
  simulate: true,
  maxFeeLamports: 100_000, // 0.0001 SOL
  useMaxFee: true
}
If you want to enable a dynamic priority fee, use the getPriorityFeeMicroLamports callback function:
const txOptions = {
  simulate: true,
  getPriorityFeeMicroLamports, // a function that returns priority fee micro lamports
}

Kamino

Initialize User Metadata

      try {
        const txSig = await glamClient.kaminoLending.initUserMetadata(
          txOptions,
        );
        console.log(`Initialized Kamino user:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Deposit

      try {
        const txSig = await glamClient.kaminoLending.deposit(
          statePda,
          lendingMarket,
          asset, // mint pubkey
          amount, // BN
          txOptions,
        );
        console.log(`Deposit ${amount} ${asset} to Kamino from vault:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Borrow

      try {
        const txSig = await glamClient.kaminoLending.borrow(
          statePda,
          lendingMarket,
          asset, // mint pubkey
          amount, // BN
          txOptions,
        );
        console.log(`Borrowed ${amount} ${asset} from Kamino:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Repay

      try {
        const txSig = await glamClient.kaminoLending.repay(
          statePda,
          lendingMarket,
          asset,
          amount, // BN
          txOptions,
        );
        console.log(`Repaid ${amount} ${asset} to Kamino:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Withdraw

      try {
        const txSig = await glamClient.kaminoLending.withdraw(
          statePda,
          lendingMarket,
          asset, // mint pubkey
          amount, // BN
          txOptions,
        );
        console.log(`Withdraw ${amount} ${asset} from Kamino:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Claim Rewards

Claiming rewards from Kamino refers to harvesting current farm incentives. Future KMNO token distributions are not yet available and are planned for a later version.
      try {
        const txSig = await glamClient.kaminoFarm.harvest([farmState], txOptions);
        console.log(`Harvested farm rewards:`, txSig);
      } catch (e) {
        console.error(parseTxError(e));
        throw e;
      }

Jupiter Swap

Create quote params:
import { QuoteParams} from "@glamsystems/glam-sdk";

const quoteParams = {
  inputMint,
  outputMint,
  amount,
  swapMode: "ExactIn",
  slippageBps,
  asLegacyTransaction: false,
} as QuoteParams;
Execute the swap:
try {
  const txSig = await glamClient.jupiterSwap.swap(
    statePda,
    { quoteParams },
    txOptions,
  );
  console.log(`Swapped ${amount} ${from} to ${to}: ${txSig}`);
} catch (e) {
  console.error(parseTxError(e));
}