Farm instructions are version-specific. A
Deposit on v6 is not callable on a v5 farm and vice versa. The SDK dispatches by reading the farm’s program owner; for on-chain CPI you must choose the right program ID up front.Instruction inventory
On v3 and v5, the canonical way to claim rewards without changing stake is to call
Deposit with amount = 0. The program treats this as a pure settlement. v6 introduced an explicit Harvest for clarity.
The SDK abstracts all of these behind raydium.farm.deposit({ ... }) etc. The sections below document the underlying account lists for integrators who need to build instructions manually (aggregators, monitoring tools, SDK extensions).
CreateFarm (v6)
Spin up a new v6 farm.
Arguments
reward_info_count = 1)
Preconditions
open_time > now,end_time > open_time.creatorATAs hold at leastemission_per_second_x64 × (end_time − open_time) / 2^64of the reward mint.staking_minthas no freeze authority, or freeze authority is disabled.
FarmStateinitialized,total_staked = 0.- Reward vault(s) funded with the full stream budget.
- The creator’s reward ATA is drained by that amount.
Deposit (v6)
Stake amount of the staking mint.
Arguments
If the
user_ledger does not exist, the SDK prepends a CreateAccount-style ix; the v6 program can also lazily create it given the system program account. Remaining accounts pattern: for each live reward, append (reward_vault, user_reward_ata) so the settlement can pay out.
Effect
- Refresh
reward_per_share_x64[i]for each live reward stream using the lazy update formula. - Compute
pending_i = user_ledger.deposited × reward_per_share_x64[i] / 2^64 − user_ledger.reward_debts[i]. - Transfer
pending_ifromreward_vault_{i}touser_reward_ata_{i}. - Transfer
amountstaking mint fromuser_staking_atatostaking_vault. - Update
user_ledger.deposited += amountand re-snapshotreward_debts[i]. - Update
farm_state.total_staked += amount.
amount > 0for a true stake (v6 forbidsamount = 0— useHarvestfor claim-only).user_staking_ataholds at leastamount.- Each live reward vault holds at least the pending owed to this user.
Withdraw (v6)
Unstake amount.
Arguments
Deposit.
Effect — same settlement as Deposit, then move staking mint back to the user: staking_vault → user_staking_ata. total_staked and user_ledger.deposited both decrease.
Preconditions
amount ≤ user_ledger.deposited.- Farm is not paused.
Harvest (v6)
Claim pending rewards without changing stake.
Arguments — none.
Accounts — same as Deposit, no staking-side movement.
Effect — refresh reward_per_share_x64[i], pay out pending_i, re-snapshot reward_debts[i]. No change to total_staked or deposited.
AddReward (v5/v6)
Add a new reward stream to an existing farm that has an unused slot.
Arguments
- A free slot exists (
reward_info_count < 5on v6,< 2on v5). open_time ≥ now(may be in the future) oropen_time < nowis allowed only if the program version permits it — v6 does, v5 does not.
- The new stream is initialized at index
reward_info_count,reward_info_count++. - The reward vault is credited with the full stream budget from the caller’s ATA.
RewardAlreadyExists if the mint collides with an existing slot.
SetRewards (v5/v6)
Extend or top up an existing reward stream. Cannot change the mint; cannot shorten end_time; cannot lower emission_per_second_x64 once running.
Arguments
- The stream is still running (
reward_state == 1). new_end_time ≥ current end_time.- The additional budget required
(new_emission × new_duration − already_emissioned)is present in the sender’s ATA and is transferred to the reward vault by the instruction.
SetRewards with a smaller argument set (no per-second changes on live streams).
RestartRewards (v5/v6)
Restart a stream after its end_time has passed. Conceptually the same as AddReward for a mint that already has a slot.
Arguments — identical shape to AddReward at that index.
Preconditions
reward_state == 2(ended).- Caller is
reward_senderof the slot (v6) or farmowner(v5).
WithdrawReward (v5/v6)
Admin sweep of unclaimed reward vault balance after a stream has ended and all stakers have had a chance to harvest.
Arguments
- Stream is ended (
reward_state == 2). reward_total_emissioned == reward_claimed + vault_balance(nothing is currently owed).
reward_sender_ata. The program does not prevent withdrawing while stakers still have pending claims; the admin is expected to harvest on behalf of lagging stakers first (or let them harvest). If you sweep early, users lose access to their unclaimed rewards. Do not call this early.
v5 variations
Deposit/Withdrawhave the same shape as v6 but use up to 2 reward slots andreward_per_shareisu128(fixed-point with a different radix).CreateAssociatedLedgeris a required separate call before the firstDeposit; v6 merged it.AddRewardis available,Harvestis not (useDeposit 0).
v3 variations
- Single reward stream. No
AddReward, no second slot. Deposit 0is the only way to claim.CreateUserLedgermust be called before the firstDeposit.
State-change matrix
Where to go next
products/farm-staking/code-demos— TypeScript examples.products/farm-staking/accounts—FarmState/UserLedger/UserStakelayouts.reference/error-codes— farm error enum.
- Raydium SDK v2
Farmmodule - Raydium farm program source (v3 / v5 / v6)

