Farm Position TypesUser rewards can come from different types of farm positions:
- Liquidity Farms: Rewards from providing liquidity to Kamino vaults
- Lend Farms: Rewards from depositing collateral or holding vault shares
- Borrow Markets Farms: Rewards from borrowing assets (debt farms) or holding collateral/debt combinations (extra farms)
- Multiply Farms: Rewards from leveraged positions
Calculate Claimable User Rewards
Calculate pending rewards for a user across all farm positions and check if they are claimable based on cooldown periods.Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, and decimal calculations.Initialize RPC and User Address
Set up the Solana RPC connection and define the user wallet and lending market addresses.Define Helper Functions
Create helper functions to validate addresses and determine farm position types. First, define the address validation helper:The
determineFarmType function uses various state checks to identify the farm position type. Liquidity farms have a strategyId, Lend farms have a vaultId or specific delegation patterns, and Borrow Markets farms are identified by obligation delegation.Fetch User Farms
Get all farms the user is participating in and fetch their states in parallel.The
getAllFarmsForUser method returns a map of all farms where the user has an active position. Using FarmState.fetchMultiple fetches all farm states in a single batch request.Calculate Obligation PDA and Display Rewards
Calculate the obligation PDA, then loop through all user farms to calculate pending rewards and check if they’re claimable based on cooldown periods. First, calculate the obligation PDA:The script outputs all pending rewards grouped by farm type and position. Each reward shows the token mint, amount, and claimability status. If a reward has a cooldown period, the remaining time is displayed in minutes.