Extra farms provide additional rewards to users who deposit specific collateral and borrow specific assets.
Calculate Extra Farm Reward APY
Calculate APY for extra farm rewards paid in stablecoins like CASH that are pegged to USD.1
Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and decimal calculations.2
Initialize RPC and Load Market
Set up the Solana RPC connection and load the Kamino market.This example targets the SOL/CASH extra farm pair where users deposit SOL collateral and borrow CASH to earn rewards.
3
Get and Filter Extra Farms
Fetch the list of extra farms from the CDN and filter by SOL collateral and CASH debt.The CDN resources endpoint provides a list of all extra farms. We filter for farms that specifically reward SOL collateral deposits paired with CASH borrows.
4
Fetch All Farm States in Batch
Fetch all farm states in a single batch request for better performance.Using
FarmState.fetchMultiple fetches all farm states in a single batch request.5
Calculate APY for SOL/CASH Farms
Loop through the fetched farms and calculate APY for CASH rewards.The script outputs the APY for SOL/CASH extra farms paying CASH rewards. The
calculateCurrentRewardPerToken helper from farms-sdk handles the reward schedule logic. Since CASH is pegged to USD, no price lookup is required.