Withdraw
Import Dependencies
Import the required packages for Solana RPC, Jupiter Lend borrow SDK, and versioned transaction building.
Withdraw uses
getOperateIx with negative colAmount and zero debtAmount. The withdrawn collateral is sent back to your wallet.Load Keypair and Initialise Connection
Load the signer and create the RPC connection. Set vault ID, position ID, and withdraw amount (positive number; the script passes it as negative to the SDK).
Build Withdraw Instructions
Build operate instructions with negative collateral amount and no debt change.
Withdraw is operate with
colAmount < 0 and debtAmount = 0. Use .neg() so the SDK receives a negative BN. The vault may reject if the withdrawal would breach LTV limits.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 (reduce collateral). Pass a negative BN, e.g. WITHDRAW_AMOUNT.neg(). |
debtAmount | BN | Signed debt amount in base units. Positive = borrow. Negative = repay. Use new BN(0) for withdraw-only. |
connection | Connection | Solana RPC connection. |
signer | PublicKey | Wallet that signs the transaction (position owner). |
colAmount < 0 (negative), debtAmount = 0.
When can I withdraw?
When can I withdraw?
You can withdraw collateral as long as the resulting position stays within the vault’s LTV rules. If you have outstanding debt, the protocol may limit how much you can withdraw until you repay.
Max withdraw (withdraw all collateral)
Max withdraw (withdraw all collateral)
To withdraw all collateral in one go, use This only succeeds if the resulting position stays within LTV (e.g. you have no debt, or you repay first). Otherwise the vault will reject the transaction.
MAX_WITHDRAW_AMOUNT from the SDK as colAmount. The protocol treats this sentinel as “withdraw all collateral”: