Skip to main content
The jupiterSwap sub-client enables token swaps through the Jupiter aggregator for GLAM vaults.
Jupiter integration requires a Jupiter API key. Configure it when initializing the client:
const glamClient = new GlamClient({ jupiterApiKey: "YOUR_JUPITER_API_KEY" });

Swap

Execute a token swap through Jupiter. The swap method accepts Jupiter quote parameters, a quote response, or pre-built swap instructions:
import { GlamClient, WSOL } from "@glamsystems/glam-sdk";
import { PublicKey } from "@solana/web3.js";

const glamClient = new GlamClient({ jupiterApiKey: "YOUR_API_KEY" });

const USDC = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");

// Swap 1 SOL to USDC using quote parameters
const txSig = await glamClient.jupiterSwap.swap({
  quoteParams: {
    inputMint: WSOL.toBase58(),
    outputMint: USDC.toBase58(),
    amount: 1_000_000_000, // 1 SOL
    slippageBps: 50, // 0.5% slippage
  },
});

Swap with Quote Response

If you have already fetched a Jupiter quote, pass it directly:
// Fetch quote externally
const quoteResponse = await fetchJupiterQuote(/* ... */);

// Swap using the pre-fetched quote
const txSig = await glamClient.jupiterSwap.swap({ quoteResponse });

Swap with Pre-built Instructions

For full control, pass pre-built swap instructions:
const txSig = await glamClient.jupiterSwap.swap({
  swapInstructions: {
    // Jupiter swap instructions object
  },
});

Transaction Options

Pass TxOptions to customize the swap transaction:
const txSig = await glamClient.jupiterSwap.swap(
  {
    quoteParams: {
      inputMint: WSOL.toBase58(),
      outputMint: USDC.toBase58(),
      amount: 1_000_000_000,
      slippageBps: 50,
    },
  },
  {
    simulate: true,
    maxFeeLamports: 100_000,
  },
);