klend-interface
Instruction builders and zero-copy account deserialization for
Kamino Lending (Klend). No anchor-lang dependency;
targets solana-sdk v2.x.
Quick start
Add to your Cargo.toml:
[]
= { = "https://github.com/Kamino-Finance/klend" }
= "2.1"
= "2.1"
= "~2.3"
= "2.1"
= "6"
Two-level API
The crate provides two levels of instruction building:
-
Low-level ([
instructions]): one function per Klend instruction, returning a single [solana_instruction::Instruction]. You supply every account address manually. -
High-level ([
helpers]): workflow builders that returnVec<Instruction>with requiredrefresh_reserve/refresh_obligationinstructions prepended automatically. Uses [ReserveInfo] and [ObligationContext] to auto-derive PDAs.
Core types
| Type | Purpose |
|---|---|
[ReserveInfo] |
On-chain reserve metadata; built via [ReserveInfo::from_account_data]. |
[ObligationContext] |
Bundles an obligation with all its reserves; provides .deposit(), .borrow(), .repay(), .withdraw(). |
[state::Reserve] |
Zero-copy deserialization of the on-chain Reserve account (8616 bytes). |
[state::Obligation] |
Zero-copy deserialization of the on-chain Obligation account (3336 bytes). |
[state::LendingMarket] |
Zero-copy deserialization of the on-chain LendingMarket account (4656 bytes). |
Typical flow with ObligationContext
use ;
use Pubkey;
#
Scaled fraction fields (_sf)
All on-chain fields ending in _sf (e.g. market_price_sf, borrowed_amount_sf) are
128-bit fixed-point numbers stored as raw u128 bits. Use [Fraction] (U68F60 from the
fixed crate) to interpret them:
use Fraction;
let raw_sf: u128 = 1_152_921_504_606_846_976; // 1.0 encoded
let value = from_bits;
let float_value: f64 = value.to_num;
Examples
The examples/ directory contains runnable examples matching the
Kamino developer documentation:
| Example | Description |
|---|---|
deposit_lending |
Deposit liquidity and receive cTokens directly (no obligation). |
deposit_borrowing |
Deposit as collateral into an obligation using ObligationContext. |
borrow |
Borrow liquidity against an obligation. |
repay |
Repay borrowed liquidity. |
withdraw_obligation |
Withdraw collateral from an obligation and redeem for liquidity. |
redeem_ctokens |
Redeem cTokens for the underlying liquidity (no obligation). |
flash_loan |
Flash-borrow and repay within a single transaction. |
market_data |
Fetch and inspect lending market and reserve data. |
user_position |
Read an obligation and display deposit/borrow positions. |
cpi_deposit_and_borrow |
CPI from an Anchor program: deposit collateral and borrow (reference only, not runnable). |
Full source for each example is included in the crate documentation or in the public GitHub repository.
License
Licensed under Business Source License 1.1 with an Additional Use Grant permitting unmodified use as a dependency. See the LICENSE file for full terms.