Skip to main content
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
This tutorial shows how to identify all farm positions for a user and calculate their claimable rewards across all position types.

Calculate Claimable User Rewards

Calculate pending rewards for a user across all farm positions and check if they are claimable based on cooldown periods.
1

Import Dependencies

Import the required packages for Solana RPC communication, Kamino SDK operations, and decimal calculations.
2

Initialize RPC and User Address

Set up the Solana RPC connection and define the user wallet and lending market addresses.
3

Define Helper Functions

Create helper functions to validate addresses and determine farm position types. First, define the address validation helper:
Next, create the farm type determination function that checks for Liquidity and Lend farms:
Finally, add the delegation logic to identify Borrow Markets and Multiply positions:
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.
4

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.
5

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:
Then iterate through farms and filter rewards with positive amounts:
Finally, check claimability based on cooldown periods and display the results:
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.