Skip to main content
Deposit collateral (supply assets) into an existing Jupiter Lend borrow position. The SDK builds operate instructions with a positive collateral amount and zero debt change. Transactions use versioned (v0) format with address lookup tables.

Deposit

1

Import Dependencies

Import the required packages for Solana RPC, Jupiter Lend borrow SDK, and versioned transaction building.
import {
  Connection,
  Keypair,
  TransactionMessage,
  VersionedTransaction,
} from "@solana/web3.js";
import BN from "bn.js";
import { getOperateIx } from "@jup-ag/lend/borrow";
import fs from "fs";
import path from "path";
Deposit uses getOperateIx with positive colAmount and zero debtAmount. Versioned transactions and address lookup tables are required.
2

Load Keypair and Initialise Connection

Load the signer and create the RPC connection. Set vault ID, position ID, and deposit amount.
const KEYPAIR_PATH = "/path/to/your/keypair.json";
const RPC_URL = "https://api.mainnet-beta.solana.com";
const VAULT_ID = 1;
const POSITION_ID = 0; // Use 0 to create position + deposit in one tx; or nftId from Create Position
const DEPOSIT_AMOUNT = new BN(1_000_000); // Collateral in base units (e.g. 1 USDC = 1_000_000)

function loadKeypair(keypairPath: string): Keypair {
  const fullPath = path.resolve(keypairPath);
  const secret = JSON.parse(fs.readFileSync(fullPath, "utf8"));
  return Keypair.fromSecretKey(new Uint8Array(secret));
}

const userKeypair = loadKeypair(KEYPAIR_PATH);
const connection = new Connection(RPC_URL, { commitment: "confirmed" });
const signer = userKeypair.publicKey;
Pass positionId: 0 to batch init position + deposit in one transaction. The SDK returns nftId (your new position ID) for future operations. If you already have a position, use its nftId instead.
3

Build Deposit Instructions

Build operate instructions with positive collateral amount and no debt change.
const { ixs, addressLookupTableAccounts, nftId } = await getOperateIx({
  vaultId: VAULT_ID,
  positionId: POSITION_ID,
  colAmount: DEPOSIT_AMOUNT,
  debtAmount: new BN(0),
  connection,
  signer,
});

// When positionId is 0, nftId is the new position ID
if (POSITION_ID === 0) console.log("New position ID (nftId):", nftId);

if (!ixs?.length) {
  throw new Error("No deposit instructions returned by Jupiter Lend SDK.");
}
Deposit is operate with colAmount > 0 and debtAmount = 0. Your supplied tokens are locked as collateral and increase your borrowing capacity.
4

Build and Sign Transaction

Build a v0 message with the instructions and address lookup tables, then sign.
const latestBlockhash = await connection.getLatestBlockhash();
const message = new TransactionMessage({
  payerKey: signer,
  recentBlockhash: latestBlockhash.blockhash,
  instructions: ixs,
}).compileToV0Message(addressLookupTableAccounts ?? []);

const transaction = new VersionedTransaction(message);
transaction.sign([userKeypair]);
5

Send and Confirm Transaction

Send the transaction and confirm.
const signature = await connection.sendTransaction(transaction, {
  skipPreflight: false,
  maxRetries: 3,
  preflightCommitment: "confirmed",
});
await connection.confirmTransaction(signature, "confirmed");

console.log("Deposit successful! Signature:", signature);
After depositing, you can Borrow against this collateral. Monitor your LTV to avoid liquidation.

Operate parameters

getOperateIx accepts the following parameters:
ParameterTypeDescription
vaultIdnumberTarget vault (market) ID.
positionIdnumberPosition NFT ID. Use 0 to create a new position and deposit in one transaction.
colAmountBNSigned collateral amount in base units. Positive = deposit (add collateral). Negative = withdraw. Use new BN(0) for borrow/repay-only.
debtAmountBNSigned debt amount in base units. Positive = borrow (add debt). Negative = repay (reduce debt). Use new BN(0) for deposit/withdraw-only.
connectionConnectionSolana RPC connection.
signerPublicKeyWallet that signs the transaction (position owner).
For deposit: colAmount > 0, debtAmount = 0.
Deposit adds collateral (supply token) to your position. Borrow withdraws the borrow token from the vault to your wallet and increases your debt. Deposit first, then borrow.

Full code example

import {
    Connection,
    Keypair,
    TransactionMessage,
    VersionedTransaction,
} from "@solana/web3.js";
import BN from "bn.js";
import { getOperateIx } from "@jup-ag/lend/borrow";
import fs from "fs";
import path from "path";

const KEYPAIR_PATH = "/path/to/your/keypair.json"; // Path to your local keypair file (update this path)
const RPC_URL = "https://api.mainnet-beta.solana.com"; // RPC endpoint
const VAULT_ID = 1; // Target vault (market)
const POSITION_ID = 0; // 0 = create + deposit in one tx; or nftId from existing position
const DEPOSIT_AMOUNT = new BN(1_000_000); // Collateral to deposit, in smallest units (supply token base units)

function loadKeypair(keypairPath: string): Keypair {
    const fullPath = path.resolve(keypairPath);
    const secret = JSON.parse(fs.readFileSync(fullPath, "utf8"));
    return Keypair.fromSecretKey(new Uint8Array(secret));
}

// 1. Load user keypair and establish connection
const userKeypair = loadKeypair(KEYPAIR_PATH);
const connection = new Connection(RPC_URL, { commitment: "confirmed" });
const signer = userKeypair.publicKey;

// 2. Get deposit instructions from SDK (operate with positive colAmount, zero debtAmount)
// Pass positionId: 0 to batch init position + deposit in one transaction
const { ixs, addressLookupTableAccounts, nftId } = await getOperateIx({
    vaultId: VAULT_ID,
    positionId: POSITION_ID,
    colAmount: DEPOSIT_AMOUNT,
    debtAmount: new BN(0),
    connection,
    signer,
});

if (!ixs?.length) {
    throw new Error("No deposit instructions returned by Jupiter Lend SDK.");
}

// 3. Build the transaction with latest blockhash and add deposit instructions
// Versioned (v0) transaction with address lookup tables; ready to be signed and sent
const latestBlockhash = await connection.getLatestBlockhash();
const message = new TransactionMessage({
    payerKey: signer,
    recentBlockhash: latestBlockhash.blockhash,
    instructions: ixs,
}).compileToV0Message(addressLookupTableAccounts ?? []);

const transaction = new VersionedTransaction(message);
transaction.sign([userKeypair]);

// 4. Send and confirm the transaction
const signature = await connection.sendTransaction(transaction, {
    skipPreflight: false,
    maxRetries: 3,
    preflightCommitment: "confirmed",
});
await connection.confirmTransaction(
    { signature, ...latestBlockhash },
    "confirmed"
);

console.log("Deposit successful! Signature:", signature);