Skip to main content
Stake vault tokens in a direct Kamino Farm, withdraw them after unstaking, and collect rewards. Delegated farms support reward harvesting rather than direct staking.

Configure the policy

Use a loaded vault, connection, and manager Keypair. Read farmState, underlyingMint, and rewardMint from the selected Kamino Farm configuration. Use its reward ordering to select the later rewardIndex.
Install it using Configure policies. Omitting a filter or passing an empty list removes its restriction. Include each reward mint you intend to collect.

Prepare the farm position

For a direct farm, initialize its user state with kaminoFarmAction.initializeUser({ farmState }) through the installed initialization permission. The default delegatee is vault.state.squadsVault. With manual sync construction, use autoManagePositions: false for this initialization, confirm it, refresh AUM, and reload before registration. Register the existing user state before staking:
A manager can submit this registration at zero AUM; registering a new farm on a funded vault requires a proposal. Refresh AUM and reload after confirmation. The builder does not register missing farm entries automatically. Track the underlying and reward token accounts and configure their price references. For delegated harvesting, use the registered farm user’s actual delegatee, such as a Kamino obligation address. Delegated farms reject direct stake, unstake, and withdrawal; initialization for another delegatee is also rejected.

Stake and collect rewards

This stakes 1_000_000 underlying-token units. Use the mint’s decimals when converting a human amount.
build() returns an execution plan: ordered transactionSets containing instructions, additional signers, and lookup table addresses. The builder schedules supported setup and refreshes; send() simulates and submits the sequence.

Unstake, wait, and withdraw

unstake uses scaled shares from the farm user’s live state, rather than an underlying-token amount. Read UserState for activeStakeScaled, pendingWithdrawalUnstakeScaled, and pendingWithdrawalUnstakeTs; read FarmState for timeUnit and withdrawalCooldownPeriod. The Farms SDK’s public getUserStateDecoder() and getFarmStateDecoder() read the buffers returned by connection.getMultipleAccountsInfo([userState, farmState]). Convert the selected scaled share amount to BN for stakeSharesScaled. For withdrawals, compare the stored deadline against Unix seconds when timeUnit is 0, or the current slot when it is 1:
Execute unstaking first. Wait for the farm’s configured cooldown and the user’s pending withdrawal to mature, then build the withdrawal against the updated state. Reward harvesting selects one configured reward index and prepares its reward ATA if needed.