Overview
Build lending applications on Solana using the Kamino SDK. This guide covers everything from basic setup to advanced transaction building for deposit, borrow, repay, and withdraw operations.Key Components of Borrow Integration
Lending Operations
Deposit collateral, borrow assets, repay debt, and withdraw - complete
lending lifecycle management.
Loan Management
LTV ratios, health factors, obligation status and position monitoring for
safe lending.
Market Analytics
APY tracking, utilization rates, reserve metrics from API and on-chain data.
Ways to Fetch Data
Public API
Access market data, borrow rates, reserve liquidity, and obligation status.
SDK
Execute borrow operations: deposit collateral, borrow, repay, and withdraw.
Deposit
- TypeScript
Copy
Ask AI
import { createSolanaRpc, address, createNoopSigner } from '@solana/kit';
import { KaminoMarket, KaminoAction, LendingObligation } from '@kamino-finance/klend-sdk';
import { simulateTx } from '../../utils/tx';
import BN from 'bn.js';
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
const marketPubkey = address('DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek');
const usdcMint = address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const market = await KaminoMarket.load(rpc, marketPubkey, 100);
const user = address('EZC9wzVCvihCsCHEMGADYdsRhcpdRYWzSCZAVegSCfqY'); // user
// Create a LendingObligation for depositing to earn interest
const obligation = new LendingObligation(usdcMint, market!.programId, 0);
const action = await KaminoAction.buildDepositReserveLiquidityTxns(
market!,
new BN(1_000_000), // Deposit 1 USDC * 10^6 decimals
usdcMint,
createNoopSigner(user),
obligation,
undefined
);
const res = await simulateTx(rpc, user, [
...action.computeBudgetIxs,
...action.setupIxs,
...action.lendingIxs,
...action.cleanupIxs,
], []);
console.log('Simulation Result:', res);
For the full deposit example, including transaction sending and confirmation, check out Deposit Operations.
Withdraw
- TypeScript
Copy
Ask AI
import { createSolanaRpc, address, createNoopSigner } from '@solana/kit';
import { KaminoMarket, KaminoAction, VanillaObligation, PROGRAM_ID } from '@kamino-finance/klend-sdk';
import { simulateTx } from '../../utils/tx';
import BN from 'bn.js';
const rpc = createSolanaRpc('https://api.mainnet-beta.solana.com');
const marketPubkey = address('DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek');
const usdcMint = address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const market = await KaminoMarket.load(rpc, marketPubkey, 100);
const user = address('EZC9wzVCvihCsCHEMGADYdsRhcpdRYWzSCZAVegSCfqY');
// Fetch the existing obligation from the blockchain
const obligation = await market!.getObligationByWallet(
user,
new VanillaObligation(PROGRAM_ID)
);
if (!obligation) {
throw new Error('No obligation found for this wallet. You must deposit first.');
}
const action = await KaminoAction.buildWithdrawTxns(
market!,
new BN(1_000_000), // Withdraw 1 USDC * 10^6 decimals
usdcMint,
createNoopSigner(user),
obligation,
true, // useV2Ixs
undefined // scopeRefreshConfig
);
const res = await simulateTx(rpc, user, [
...action.computeBudgetIxs,
...action.setupIxs,
...action.lendingIxs,
...action.cleanupIxs,
], []);
console.log('Simulation Result:', res);
For the full withdraw example, including transaction sending and confirmation,
check out Withdraw Operations.
Key Data Structures
- TypeScript
- JSON
- Rust
Obligation
Copy
Ask AI
class Obligation {
tag: BN;
lastUpdate: types.LastUpdate;
lendingMarket: Address;
owner: Address;
deposits: Array<types.ObligationCollateral>;
lowestReserveDepositLiquidationLtv: BN;
depositedValueSf: BN;
borrows: Array<types.ObligationLiquidity>;
borrowFactorAdjustedDebtValueSf: BN;
borrowedAssetsMarketValueSf: BN;
allowedBorrowValueSf: BN;
unhealthyBorrowValueSf: BN;
depositsAssetTiers: Array<number>;
borrowsAssetTiers: Array<number>;
elevationGroup: number;
numOfObsoleteDepositReserves: number;
hasDebt: number;
referrer: Address;
borrowingDisabled: number;
autodeleverageTargetLtvPct: number;
lowestReserveDepositMaxLtvPct: number;
numOfObsoleteBorrowReserves: number;
reserved: Array<number>;
highestBorrowFactorPct: BN;
autodeleverageMarginCallStartedTimestamp: BN;
orders: Array<types.ObligationOrder>;
}
Show Fields
Show Fields
| Field | Type | Description |
|---|---|---|
tag | BN | Version of the struct |
lastUpdate | types.LastUpdate | Last update to collateral, liquidity, or their market values |
lendingMarket | Address | Lending market address |
owner | Address | Owner authority which can borrow liquidity |
deposits | Array<types.ObligationCollateral> | Deposited collateral for the obligation, unique by deposit reserve address |
lowestReserveDepositLiquidationLtv | BN | Worst LTV for the collaterals backing the loan, represented as a percentage |
depositedValueSf | BN | Market value of deposits (scaled fraction) |
borrows | Array<types.ObligationLiquidity> | Borrowed liquidity for the obligation, unique by borrow reserve address |
borrowFactorAdjustedDebtValueSf | BN | Risk adjusted market value of borrows/debt (scaled fraction) |
borrowedAssetsMarketValueSf | BN | Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) |
allowedBorrowValueSf | BN | The maximum borrow value at the weighted average loan to value ratio (scaled fraction) |
unhealthyBorrowValueSf | BN | The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) |
depositsAssetTiers | Array<number> | The asset tier of the deposits |
borrowsAssetTiers | Array<number> | The asset tier of the borrows |
elevationGroup | number | The elevation group id the obligation opted into |
numOfObsoleteDepositReserves | number | The number of obsolete reserves the obligation has a deposit in |
hasDebt | number | Marked = 1 if borrows array is not empty, 0 = borrows empty |
referrer | Address | Wallet address of the referrer |
borrowingDisabled | number | Marked = 1 if borrowing disabled, 0 = borrowing enabled |
autodeleverageTargetLtvPct | number | A target LTV set by the risk council when marking this obligation for deleveraging |
lowestReserveDepositMaxLtvPct | number | The lowest max LTV found amongst the collateral deposits |
numOfObsoleteBorrowReserves | number | The number of obsolete reserves the obligation has a borrow in |
reserved | Array<number> | Reserved space for future use |
highestBorrowFactorPct | BN | The highest borrow factor percentage across all borrows |
autodeleverageMarginCallStartedTimestamp | BN | Timestamp when risk council marked this obligation for deleveraging (zero if not applicable) |
orders | Array<types.ObligationOrder> | Owner-defined, liquidator-executed orders (e.g., stop-loss, take-profit) |
Obligation
Copy
Ask AI
{
"tag": "0",
"lastUpdate": {},
"lendingMarket": "...",
"owner": "...",
"deposits": [],
"lowestReserveDepositLiquidationLtv": "0",
"depositedValueSf": "0",
"borrows": [],
"borrowFactorAdjustedDebtValueSf": "0",
"borrowedAssetsMarketValueSf": "0",
"allowedBorrowValueSf": "0",
"unhealthyBorrowValueSf": "0",
"depositsAssetTiers": [],
"borrowsAssetTiers": [],
"elevationGroup": 0,
"numOfObsoleteDepositReserves": 0,
"hasDebt": 0,
"referrer": "...",
"borrowingDisabled": 0,
"autodeleverageTargetLtvPct": 0,
"lowestReserveDepositMaxLtvPct": 0,
"numOfObsoleteBorrowReserves": 0,
"reserved": [],
"highestBorrowFactorPct": "0",
"autodeleverageMarginCallStartedTimestamp": "0",
"orders": [],
"padding3": []
}
Show Fields
Show Fields
| Field | Type | Description |
|---|---|---|
tag | string | Version of the struct |
lastUpdate | object | Last update to collateral, liquidity, or their market values |
lendingMarket | string | Lending market address |
owner | string | Owner authority which can borrow liquidity |
deposits | array | Deposited collateral for the obligation, unique by deposit reserve address |
lowestReserveDepositLiquidationLtv | string | Worst LTV for the collaterals backing the loan, represented as a percentage |
depositedValueSf | string | Market value of deposits (scaled fraction) |
borrows | array | Borrowed liquidity for the obligation, unique by borrow reserve address |
borrowFactorAdjustedDebtValueSf | string | Risk adjusted market value of borrows/debt (scaled fraction) |
borrowedAssetsMarketValueSf | string | Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) |
allowedBorrowValueSf | string | The maximum borrow value at the weighted average loan to value ratio (scaled fraction) |
unhealthyBorrowValueSf | string | The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) |
depositsAssetTiers | array | The asset tier of the deposits |
borrowsAssetTiers | array | The asset tier of the borrows |
elevationGroup | number | The elevation group id the obligation opted into |
numOfObsoleteDepositReserves | number | The number of obsolete reserves the obligation has a deposit in |
hasDebt | number | Marked = 1 if borrows array is not empty, 0 = borrows empty |
referrer | string | Wallet address of the referrer |
borrowingDisabled | number | Marked = 1 if borrowing disabled, 0 = borrowing enabled |
autodeleverageTargetLtvPct | number | A target LTV set by the risk council when marking this obligation for deleveraging |
lowestReserveDepositMaxLtvPct | number | The lowest max LTV found amongst the collateral deposits |
numOfObsoleteBorrowReserves | number | The number of obsolete reserves the obligation has a borrow in |
reserved | array | Reserved space for future use |
highestBorrowFactorPct | string | The highest borrow factor percentage across all borrows |
autodeleverageMarginCallStartedTimestamp | string | Timestamp when risk council marked this obligation for deleveraging (zero if not applicable) |
orders | array | Owner-defined, liquidator-executed orders (e.g., stop-loss, take-profit) |
Obligation
Copy
Ask AI
pub struct Obligation {
pub tag: u64
pub last_update: LastUpdate
pub lending_market: Pubkey
pub owner: Pubkey
pub deposits: [ObligationCollateral; 8]
pub lowest_reserve_deposit_liquidation_ltv: u64
pub deposited_value_sf: u128
pub borrows: [ObligationLiquidity; 5]
pub borrow_factor_adjusted_debt_value_sf: u128
pub borrowed_assets_market_value_sf: u128
pub allowed_borrow_value_sf: u128
pub unhealthy_borrow_value_sf: u128
pub deposits_asset_tiers: [u8; 8]
pub borrows_asset_tiers: [u8; 5]
pub elevation_group: u8
pub num_of_obsolete_deposit_reserves: u8
pub has_debt: u8
pub referrer: Pubkey
pub borrowing_disabled: u8
pub autodeleverage_target_ltv_pct: u8
pub lowest_reserve_deposit_max_ltv_pct: u8
pub num_of_obsolete_borrow_reserves: u8
pub reserved: [u8; 4]
pub highest_borrow_factor_pct: u64
pub autodeleverage_margin_call_started_timestamp: u64
pub orders: [ObligationOrder; 2]
pub padding_3: [u64; 93]
}
Show Fields
Show Fields
| Field | Type | Description |
|---|---|---|
tag | string | Version of the struct |
lastUpdate | object | Last update to collateral, liquidity, or their market values |
lendingMarket | string | Lending market address |
owner | string | Owner authority which can borrow liquidity |
deposits | array | Deposited collateral for the obligation, unique by deposit reserve address |
lowestReserveDepositLiquidationLtv | string | Worst LTV for the collaterals backing the loan, represented as a percentage |
depositedValueSf | string | Market value of deposits (scaled fraction) |
borrows | array | Borrowed liquidity for the obligation, unique by borrow reserve address |
borrowFactorAdjustedDebtValueSf | string | Risk adjusted market value of borrows/debt (scaled fraction) |
borrowedAssetsMarketValueSf | string | Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) |
allowedBorrowValueSf | string | The maximum borrow value at the weighted average loan to value ratio (scaled fraction) |
unhealthyBorrowValueSf | string | The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) |
depositsAssetTiers | array | The asset tier of the deposits |
borrowsAssetTiers | array | The asset tier of the borrows |
elevationGroup | number | The elevation group id the obligation opted into |
numOfObsoleteDepositReserves | number | The number of obsolete reserves the obligation has a deposit in |
hasDebt | number | Marked = 1 if borrows array is not empty, 0 = borrows empty |
referrer | string | Wallet address of the referrer |
borrowingDisabled | number | Marked = 1 if borrowing disabled, 0 = borrowing enabled |
autodeleverageTargetLtvPct | number | A target LTV set by the risk council when marking this obligation for deleveraging |
lowestReserveDepositMaxLtvPct | number | The lowest max LTV found amongst the collateral deposits |
numOfObsoleteBorrowReserves | number | The number of obsolete reserves the obligation has a borrow in |
reserved | array | Reserved space for future use |
highestBorrowFactorPct | string | The highest borrow factor percentage across all borrows |
autodeleverageMarginCallStartedTimestamp | string | Timestamp when risk council marked this obligation for deleveraging (zero if not applicable) |
orders | array | Owner-defined, liquidator-executed orders (e.g., stop-loss, take-profit) |
Relevant Links
Fetch Market Data via the API
Access market metrics and performance data through REST endpoints.
Smart contract repository
Explore the on-chain program source code and documentation.
NPM SDK package
Install the TypeScript SDK to integrate borrowing and lending operations.
More Borrow tutorials
Step-by-step guides for building with Kamino lending markets.