LpFarm
FarmEmission
Individual emission token configuration and state.Key Concepts
Emission Mechanism
The LP farm distributes reward tokens to liquidity providers proportionally to their share of the total liquidity. EachFarmEmission represents a separate reward token stream.
The emission mechanism works as follows:
- Emissions accrue at
token_ratetokens per second - The global
indexincreases based on emissions and total liquidity - Each LP position tracks its
last_seen_indexfor each emission - Rewards owed = (current_index - last_seen_index) × lp_balance
Token Rate and Duration
Thetoken_rate field specifies how many tokens are distributed per second across all LPs. This rate combined with the expiry_timestamp determines the total emission budget:
Expiration Timestamp
Theexpiry_timestamp marks when this particular emission ends. After this time:
- The
indexstops increasing for this emission - No new rewards accrue, but unclaimed rewards remain claimable
- The emission slot may be reused for a new reward program
Global Index
Theindex field is a cumulative measure of emissions per unit of liquidity. It uses the Number type (Q64.64 fixed-point) to maintain precision despite division by large liquidity amounts.
Index updates occur during these operations:
- LP deposits (add liquidity)
- LP withdrawals (remove liquidity)
- Explicit farm update calls
- Emission claims
Multiple Emissions
A single farm can run multiple emissions simultaneously via thefarm_emissions vector. This allows markets to incentivize liquidity with multiple reward tokens (e.g., protocol token + partner token).
Each emission operates independently with its own:
- Reward token mint
- Emission rate
- Expiration timestamp
- Index tracking
Farm Lifecycle
- Initialization — Farm is created with initial emission configurations
- Active Emissions — While
current_timestamp < expiry_timestamp, emissions accrue attoken_rate - Index Updates — The global
indexis updated whenever LPs interact with the market - Expiration — After
expiry_timestamp, the emission stops accruing but remains claimable - Renewal — Expired emissions can be replaced with new emission configurations
Last Seen Timestamp
Thelast_seen_timestamp tracks when the farm was last updated. This is used to calculate the time delta for index updates:
Escrow Account Tracking
While not directly stored in theLpFarm struct, each emission requires a corresponding escrow token account owned by the market authority. This escrow holds the emission tokens that will be distributed to LPs. The market program enforces that sufficient tokens are escrowed before allowing emission configuration.