Skip to main content

Reading Farm Data

A delegated farm (for example a klend reserve farm or a kvault farm) has no stake-token mint of its own. A delegate authority stakes on users’ behalf, so farmState.token.mint is empty and farmState.delegateAuthority is set. A non-delegated farm owns its stake token, so farmState.token gives the stake mint and decimals. For the TypeScript shapes used below, see Farm Types.
A FarmState account exposes the values below. An Address field set to the default pubkey means it is unused, for example strategyId and vaultId on a farm attached to neither.

Get Farm State

Live on-chain read of a single farm: stake token, totals, time gates, and reward slots.
getFarmState
View Code
depositWarmupPeriod and withdrawalCooldownPeriod are farm-level time gates in seconds, stored on the farm state with no REST equivalent. The cooldown is the wait between unstaking and being able to withdraw. To load several farms at once, use FarmState.fetchMultiple(rpc, [addr, ...]). On a non-delegated farm, farms.getStakedAmountForFarm(FARM) returns the total staked in share units, already divided by the stake-token decimals.

Find Farms

Discover farms by their stake token, or batch-load known farm addresses in one call.
findFarms
View Code
getFarmsForMint filters on the stake-token mint, so it only finds non-delegated farms. Delegated farms leave that field empty, so you get their address elsewhere (a reserve’s farmCollateral / farmDebt, or a kvault’s vaultFarm; see the locating table in the overview) and batch-load them with getAllFarmStatesByPubkeys.

Get Incentive APY

Compute a farm’s reward APY two ways: the easy path for a strategy farm, and the generic path for any farm.
getIncentiveApy
View Code
getRewardsAPYForStrategy is the easy path for a strategy farm: the SDK derives the share price and reward prices itself. calculateFarmIncentivesApy is generic and works for any farm, but you supply a getPrice callback for reward tokens (from the oracle endpoint) plus the staked-token price (from the kliquidity SDK, since a strategy share is not an oracle-tracked asset). The two totals land close to each other.

Simulate APY After Stake or Unstake

Project how the incentive APY changes after a hypothetical stake or unstake, reusing the getPrice callback and stakedTokenPrice from the previous example.
simulateApy
View Code
stakedTokenDelta is in share units (the decimal share amount, not raw lamports) and adds to the current total stake. A positive delta simulates staking more, so the same rewards spread over a bigger pool and APY falls. A negative delta simulates unstaking, so APY rises.

Farm Types

TypeScript shapes used by the Farms SDK for farm reads.
On-chain farm account. Fetched with FarmState.fetch / fetchMultiple. See the collapsible field reference at the top of the page for what each value means.

Additional Resources

API Examples

SDK Repository