Lending & Borrowing
Solana money markets (Kamino, MarginFi, and similar) let users supply collateral, borrow assets, and earn yield. Integrate when your product needs leverage, vault strategies, or automated repay flows.
Search across all documentation pages
Solana money markets (Kamino, MarginFi, and similar) let users supply collateral, borrow assets, and earn yield. Integrate when your product needs leverage, vault strategies, or automated repay flows.
Quick-reference recipe card - copy-paste ready.
// MarginFi - deposit collateral (SDK pattern)
import { MarginfiClient } from "@mrgnlabs/marginfi-client-v2";
const client = await MarginfiClient.fetch(config, wallet, connection);
const bank = client.getBankByMint(usdcMint);
await bank.deposit(amount, wallet.publicKey);#[account(constraint = health_factor >= MIN_HEALTH @ ErrorCode::Undercollateralized)]
pub user_state: Account<'info, UserState>,When to reach for this:
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
// Kamino lending market program
const kaminoProgram = address("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
const accounts = await rpc.getProgramAccounts(kaminoProgram, {
encoding: "jsonParsed",
filters: [{ dataSize: 1024 }], // filter illustrative - use SDK for real layout
}).send();
console.log("Kamino accounts found:", accounts.length);What this demonstrates:
| Aspect | Kamino | MarginFi |
|---|---|---|
| Focus | Lend + automated vaults | Pure money market |
| Collateral | Multi-asset baskets | Bank-per-mint model |
| SDK | kamino-sdk | marginfi-client-v2 |
| Oracle | Pyth-heavy | Pyth + Switchboard |
pub fn health_factor(collateral_usd: u128, debt_usd: u128) -> Result<u128> {
if debt_usd == 0 {
return Ok(u128::MAX);
}
Ok(collateral_usd
.checked_mul(PRECISION)
.and_then(|v| v.checked_div(debt_usd))
.ok_or(ErrorCode::MathOverflow)?)
}getOutstandingDebt helpers.| Alternative | Use When | Don't Use When |
|---|---|---|
| Hold spot only | No leverage risk | You need yield on idle capital |
| AMM LP | Earn trading fees | You want isolated borrow exposure |
| Off-chain credit | KYC counterparties | You need permissionless composability |
Collateral value divided by debt value (with haircuts). Below 1.0 triggers liquidation on most markets.
Yes - compose borrow CPI, Jupiter swap CPI, and redeposit in one versioned transaction with enough CU.
Kamino adds automated vault strategies that rebalance collateral across reserves and external yield sources.
Pyth price feeds are primary on Kamino and MarginFi mainnet deployments. Always read the reserve's configured oracle pubkey.
Keepers monitor health factors and submit liquidation txs for a bonus. Build bots with low-latency oracle feeds.
Depends on reserve design - some use cTokens (SPL mints), others use internal accounting only.
Fork mainnet reserves with Surfpool 0.12.0 or clone specific accounts into test-validator.
Borrow/withdraw instructions fail closed when price accounts are stale or invalid - transactions revert atomically.
Yes if a PDA is the authority - but upgrade authority and key management become critical security concerns.
Continuously via reserve index - even sub-slot borrows accrue on next index update inside the program.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 19, 2026