Repay
Import Dependencies
Import the required packages for Solana RPC, Jupiter Lend borrow SDK, and versioned transaction building.
Repay uses
getOperateIx with zero colAmount and negative debtAmount. The repay amount is taken from your wallet and reduces your position’s debt.Load Keypair and Initialise Connection
Load the signer and create the RPC connection. Set vault ID, position ID, and repay amount (positive number; the script passes it as negative to the SDK).
Build Repay Instructions
Build operate instructions with no collateral change and negative debt amount.
Repay is operate with
colAmount = 0 and debtAmount < 0. Use .neg() so the SDK receives a negative BN. Repaying reduces debt and improves your LTV.Build and Sign Transaction
Build a v0 message with the instructions and address lookup tables, then sign.
Operate parameters
getOperateIx accepts the following parameters:
| Parameter | Type | Description |
|---|---|---|
vaultId | number | Target vault (market) ID. |
positionId | number | Position NFT ID. |
colAmount | BN | Signed collateral amount in base units. Positive = deposit. Negative = withdraw. Use new BN(0) for repay-only. |
debtAmount | BN | Signed debt amount in base units. Positive = borrow. Negative = repay (reduce debt). Pass a negative BN, e.g. REPAY_AMOUNT.neg(). |
connection | Connection | Solana RPC connection. |
signer | PublicKey | Wallet that signs the transaction (position owner). Must hold the borrow token. |
colAmount = 0, debtAmount < 0 (negative).
Partial vs full repay
Partial vs full repay
You can repay any amount up to your current debt. Partial repay reduces debt by that amount. For full repay, use your position’s total debt (check vault APIs or UI for the exact value).
Max repay (repay all debt)
Max repay (repay all debt)
To repay all debt in one go, use You must hold enough borrow token to cover the full debt; the protocol will take what is needed.
MAX_REPAY_AMOUNT from the SDK as debtAmount. The protocol treats this sentinel as “repay full debt”: