Follow this tutorial to calculate reward APY for both deposit and borrow positions on Kamino lending reserves.Documentation Index
Fetch the complete documentation index at: https://kamino.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Reserve Farms vs Extra FarmsReserve farms are attached directly to a reserve and reward all users who deposit or borrow that reserve asset. Depositors earn rewards through collateral farms, while borrowers earn rewards through debt farms.Extra farms reward users only when specific collateral and debt combinations are used. Rewards are conditional on holding qualifying positions rather than simply depositing or borrowing a single reserve.This tutorial focuses on reserve farms.
Calculate Reserve Reward APY
Calculate APY for both collateral and debt farm rewards on a specific reserve.Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and decimal calculations.Initialize RPC and Fetch Prices
Set up the Solana RPC connection and fetch token prices from the Kamino API.Creating a price map allows quick lookups for multiple reward tokens. The example uses USDS reserve which has both collateral and debt farm rewards active.
Load Market and Reserve
Load the Kamino market and get the reserve by its mint address.The
getReserveByMint method retrieves the reserve configuration including references to both the collateral farm and debt farm addresses.Collect and Fetch Farm Addresses
Collect both collateral and debt farm addresses, checking they’re not the default pubkey, then fetch all farms in parallel.Checking for the default pubkey ensures we only fetch farms that are actually configured on the reserve. Using
FarmState.fetchMultiple fetches all farm states in a single batch request, which is more efficient than individual fetches.Calculate Farm Reward APY
Calculate APY for each active reward on both collateral and debt farms.The script outputs APY for all active rewards on both the collateral and debt farms. The
calculateCurrentRewardPerToken helper from farms-sdk handles the reward schedule logic. Each reward is priced in USD and the total staked amount represents the value of all positions earning that reward.