The interest rate curve shows how borrow and supply APY change as pool utilization increases from 0% to 100%, where utilization represents the share of supplied liquidity that is borrowed.
Calculate Interest Rate Curve
Generate curve points showing APY at different utilization levels.Import Dependencies
Import the required packages for Solana RPC communication and Kamino SDK operations.Configure Market and Reserve
Set up the lending market, reserve address, and calculation parameters.The STEP value determines curve granularity: 0.05 = 21 points, 0.01 = 101 points. Smaller steps provide smoother curves but increase computation.
Load Market and Reserve
Initialize RPC connection and load the market and reserve data.The
getReserveByAddress method retrieves reserve configuration including the borrow rate curve points and protocol parameters needed for APY calculations.Extract Borrow Curve Points
Convert the reserve’s borrow rate curve from basis points to decimal values.The borrow curve defines interest rates at specific utilization thresholds and interpolates between them. Rates rise sharply after 80% utilization to discourage the pool from becoming fully utilized.
Calculate Adjustment Parameters
Get parameters needed to convert per-slot rates to annual APY.Key Parameters Explained
- Slot Adjustment Factor: Converts per-slot rates to annual rates. Solana has ~2 slots per second with average 400ms duration.
- Protocol Take Rate: The percentage of borrow interest paid to suppliers. If protocol takes 10%, suppliers receive 90% of interest paid by borrowers.
- Fixed Host Interest Rate: A small base rate added to all borrows, ensuring borrowers pay at least a minimum rate even at 0% utilization.
Generate Curve Points
Calculate borrow and supply APY at each utilization level.How the Calculation Works
getBorrowRateinterpolates the borrow rate from the curve at the given utilizationcalculateAPYFromAPRconverts APR to APY:APY = (1 + rate/periods)^periods - 1, accounting for compound interest per slot- Supply APY formula:
supplyAPY = utilization × borrowAPR × (1 - protocolFee)- suppliers earn interest only on borrowed funds, minus the protocol fee
Build Result with Current Metrics
Combine the curve data with current reserve metrics.The result includes the reserve symbol, current utilization and APY values, plus an array of curve points. Each curve point contains the utilization level, borrow APY, and supply APY at that utilization. This data can be used to visualize the interest rate curve with charting libraries.
Understanding the Results
The curve shows how rates change with utilization:- Low utilization (0-50%): Borrow rates are low to encourage borrowing, supply rates are minimal
- Medium utilization (50-80%): Rates increase moderately to balance supply and demand - this is the target range
- High utilization (80-100%): Rates increase sharply to incentivize repayment and new deposits