Documentation Index
Fetch the complete documentation index at: https://kamino.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Repay with collateral reduces debt in a single atomic transaction by converting collateral into the debt token without requiring additional funds. The protocol flash borrows the debt token, repays the debt, withdraws the freed collateral, swaps it to the debt token via KSwap, and repays the flash loan—all in one transaction.
Repay with Collateral using KSwap
Reduce debt in a single transaction by converting collateral using a flash loan and KSwap.Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, KSwap routing, and transaction building.Load Configuration and Initialize SDKs
Load the keypair, initialize RPC connections, and set up the market and SDKs.Find Collateral Reserve
Dynamically discover the collateral token mint by searching the market reserves by symbol.Configure Repay Parameters
Set the amount of debt to repay using collateral and the slippage tolerance.Some assets may require higher slippage than others.
Setup Lookup Tables
Initialize the user’s lookup table and execute any required setup transactions.Setup transactions extend the lookup table with addresses specific to the position. This is a one-time operation per collateral/debt pair.
Fetch Existing Obligation
Retrieve the current obligation and display position details.This example uses
MultiplyObligation. For standard borrow positions, use VanillaObligation instead.Build Repay Instructions
Generate repay with collateral instructions with scope price refresh and compute budget.Build, Sign, and Send Transaction
Wait briefly to avoid rate limiting, get a fresh blockhash, compress the transaction with LUTs, and send it.The repay with collateral transaction is complete. Collateral was sold to repay debt without requiring external funds.
Helper Functions
The tutorial requires KSwap helper functions for quote retrieval and swap execution.kswap_utils.ts
kswap_utils.ts
Borrow and Multiply SDK Methods
| Method | Operation | When to Use |
|---|---|---|
getDepositWithLeverageIxs | Open position or add collateral | Creating or adding to a leveraged position |
buildRepayTxns | Repay with wallet funds | Reducing debt using USDC, SOL, etc. from wallet |
buildWithdrawTxns | Withdraw collateral | Withdrawing collateral after debt is repaid |
getWithdrawWithLeverageIxs | Deleverage and withdraw | Sell collateral to repay debt and receive remaining value in wallet |
getRepayWithCollIxs | Repay debt with collateral | Sell collateral to repay debt without withdrawing (value stays in position) |
Multiply operations use
MultiplyObligation. Standard borrow operations use VanillaObligation. The obligation type determines which PDA is derived for your position.