Overview
Kamino Lending is a Solana-based lending protocol built using the Anchor framework. The protocol enables users to deposit assets as collateral, borrow against them, and earn yield on deposits through a sophisticated interest rate mechanism.Core Components
The protocol architecture consists of three primary on-chain account types that work together:1. LendingMarket
TheLendingMarket is the top-level account that governs the entire lending protocol instance. Each market can contain multiple reserves and manages global parameters.
Key Fields (from state/lending_market.rs:29):
- Global protocol configuration (borrowing limits, liquidation parameters)
- Emergency controls and governance
- Elevation group management for isolated lending markets
- Referral fee distribution settings
2. Reserve
AReserve represents a single asset market within a lending market. Each reserve tracks liquidity, collateral, and interest rate state for one token type.
Key Fields (from state/reserve.rs:61):
- Tracking available and borrowed liquidity
- Managing collateral token (cToken) minting and burning
- Calculating interest rates based on utilization
- Enforcing deposit and borrow limits
3. Obligation
AnObligation represents a user’s position, containing their deposits (collateral) and borrows across multiple reserves.
Key Fields (from state/obligation.rs:28):
- Tracking user’s collateral deposits across up to 8 reserves
- Tracking user’s borrows across up to 5 reserves
- Calculating position health (LTV ratios)
- Enforcing liquidation thresholds
Architectural Hierarchy
Instruction Flow
The protocol supports the following primary operations (defined inlib.rs:34):
Deposit Flow
-
deposit_reserve_liquidity- Deposit tokens into a reserve- User transfers tokens to reserve’s supply vault
- Reserve mints cTokens (collateral tokens) to user
- Increases reserve’s
total_available_amount
-
deposit_obligation_collateral- Deposit cTokens as collateral in obligation- User transfers cTokens to reserve’s collateral vault
- Updates obligation’s deposits array
- Increases borrowing capacity
Borrow Flow
-
refresh_reserve- Update reserve interest and prices- Accrues interest based on time elapsed
- Updates cumulative borrow rate
- Refreshes oracle prices
-
refresh_obligation- Update obligation health- Recalculates deposited value
- Recalculates borrowed value with interest
- Updates LTV and liquidation thresholds
-
borrow_obligation_liquidity- Borrow tokens against collateral- Validates borrowing capacity (LTV check)
- Transfers tokens from reserve to user
- Updates obligation’s borrows array
- Applies origination fees
Repay Flow
repay_obligation_liquidity- Repay borrowed tokens- User transfers tokens to reserve
- Reduces borrowed amount in obligation
- Decreases reserve’s borrowed amount
Withdraw Flow
-
withdraw_obligation_collateral- Withdraw cTokens from obligation- Validates position remains healthy
- Transfers cTokens back to user
- Updates obligation’s deposits
-
redeem_reserve_collateral- Redeem cTokens for underlying tokens- Burns cTokens
- Transfers underlying tokens to user
- Decreases collateral supply
Liquidation Flow
liquidate_obligation_and_redeem_reserve_collateral- Liquidate unhealthy position- Validates obligation is underwater (LTV > liquidation threshold)
- Liquidator repays portion of debt
- Liquidator receives collateral at discount (liquidation bonus)
- Updates both obligation and reserves
State Updates and Interest Accrual
All reserve operations trigger interest accrual (seestate/reserve.rs:455):
- Current utilization rate
- Borrow rate curve configuration
- Time elapsed (in Solana slots)
- Protocol and referral fees
Security Features
Emergency Mode
The lending market can enter emergency mode to pause operations:Elevation Groups
Isolated lending markets within a single lending market, allowing different risk parameters for different asset classes:- Maximum 32 elevation groups per market
- Each group can have custom LTV and liquidation thresholds
- Restricts cross-collateralization between groups
Refresh Requirements
Obligations and reserves must be refreshed before operations to ensure:- Latest oracle prices are used
- Interest has been properly accrued
- Position health is accurately calculated
Program IDs
The protocol uses different program IDs for different environments (fromlib.rs:17):
Next Steps
Reserves
Learn about reserve configuration, interest rates, and liquidity management
Obligations
Understand user positions, health calculations, and liquidations
Collateral & Liquidity
Deep dive into LTV ratios, liquidation thresholds, and utilization