BlockchainAppMaker

DeFi

Yield farming development: emissions, vaults and why most farms fade

A yield farming platform pays users, usually in a protocol token, for supplying liquidity or capital to a protocol. The contracts are well understood; the difficult part is designing incentives that buy durable liquidity rather than renting capital that leaves the moment rewards drop.

What yield farming actually is

Liquidity mining took off in mid-2020 when Compound began distributing COMP to its lenders and borrowers. Within weeks, protocols were paying their own tokens to anyone who deposited LP tokens, and "farmers" moved capital between them chasing the highest APY. The pattern has three layers:

  1. Base yield: trading fees earned by an AMM LP position, interest from a lending market, or staking rewards.
  2. Incentive yield: extra tokens emitted by a protocol to attract that capital.
  3. Strategy layer: vaults that automatically claim incentives, sell them and reinvest, so users compound without manual work.

A farming platform can sit at any of these layers. A new DEX runs an incentive program on its own pools; a yield aggregator builds vaults on top of other protocols' farms.

Incentive contracts

MasterChef

The MasterChef contract, introduced by SushiSwap and copied by countless forks, distributes a fixed amount of reward token per block across pools according to allocation points. Each pool keeps an accRewardPerShare; each user stores a rewardDebt. Pending rewards are amount × accRewardPerShare − rewardDebt. It is efficient, but forks have shipped dangerous variations: owner-callable migrators that can move all staked LP tokens, uncapped minting, and deposit fees that can be raised to 100%. Read any MasterChef you inherit line by line.

Gauges and vote-escrow

Curve's model separates emission decisions from the core team. Token holders lock CRV into veCRV, and their votes set the weights of liquidity gauges that receive emissions. This created a market: protocols that want liquidity in their pools acquire voting power or pay holders to vote for them (bribes). Platforms like Convex aggregated veCRV and turned that market into its own business. Gauge systems are more decentralized than an owner setting allocation points, but they are complex, and whoever accumulates voting power controls the emissions.

Off-chain computed rewards

Some programs compute rewards off-chain from event data and publish a Merkle root that users claim against. This allows sophisticated reward rules (rewarding only in-range concentrated liquidity, for example) without expensive on-chain bookkeeping. The trade-off is trust: users rely on the operator to compute the root honestly, so publish the scripts and data so anyone can verify it.

Vaults and auto-compounders

A vault accepts deposits, issues shares and runs a strategy. The ERC-4626 standard defines the interface: deposit, mint, withdraw, redeem, and preview and conversion functions. Using it makes your vault composable with lending markets, aggregators and dashboards.

Vault-specific risks:

  • Inflation (donation) attack. When a vault is empty, the first depositor can mint one share and then donate a large amount of the underlying asset directly to the vault, inflating the share price so that the next depositor's shares round down to zero. Mitigate with virtual shares and assets (OpenZeppelin's ERC-4626 implementation includes a decimals offset), by minting dead shares at deployment, or by requiring a minimum first deposit.
  • Harvest sandwiching. When a vault sells reward tokens, MEV bots can trade around the swap. Use slippage limits based on an oracle, private transaction submission, or smaller, more frequent harvests.
  • Share-price manipulation. If totalAssets() reads a spot price or a balance that can be moved in one transaction, attackers can deposit cheap and withdraw dear. Harvest Finance lost tens of millions in 2020 this way, through a Curve pool price manipulated with flash loans.
  • Strategy loss. The underlying protocol can be exploited, depeg or freeze withdrawals. Vault depositors inherit all upstream risk.

For a deeper look at aggregator architecture, see the Yearn-style protocol guide.

Impermanent loss: tell farmers the truth

Most farms reward LP positions, and LPs in a constant-product pool suffer impermanent loss when prices diverge. If one asset's price changes by a factor r relative to the other, the LP position is worth 2√r / (1 + r) of simply holding the two assets.

Relative price changeLP value vs. holding
1.25× (25%)about −0.6%
1.5× (50%)about −2.0%
2×about −5.7%
4×−20%
5×about −25.5%

Concentrated liquidity magnifies both fee income and this loss within the chosen range. A farm's displayed APY rarely subtracts impermanent loss; good interfaces at least show it.

APR, APY and TVL: reading the numbers

Farm dashboards show three numbers that are easy to misread, and your interface should define each one.

  • APR is the simple annualized rate without compounding: rewards per year divided by the value deposited.
  • APY assumes rewards are reinvested. With n compounding periods a year, APY = (1 + APR/n)^n − 1. A 100% APR compounded daily becomes about 171.5% APY, but only if you actually compound daily, the reward token price holds, and gas does not eat the gains. Showing APY for a farm that does not auto-compound overstates what users receive.
  • TVL (total value locked) is the market value of assets in the contracts. It moves with token prices, can double-count when one protocol's deposits are another's, and says little about revenue. Treat it as a size indicator, not a health metric.

Both APR and APY in a farm are usually calculated from the current emission rate, current reward-token price and current deposits. All three change constantly. As deposits grow, the rate per dollar falls; as farmers sell rewards, the token price falls. A rate shown at launch is almost never the rate a farmer earns over a year.

A more honest display splits the figure into base yield (fees or interest, paid in the deposited assets) and incentive yield (paid in the reward token), and shows the incentive schedule's end date.

The mercenary liquidity problem

Emissions are a cost. When you pay 200% APY in your own token, farmers deposit, claim and sell. The sell pressure lowers the token price, which lowers APY, which makes farmers leave. Many 2020–2022 farms followed exactly this arc, and some of their tokens lost almost all their value.

Designs that hold up better:

  • Fund rewards from revenue, not just inflation. "Real yield" from fees is smaller but sustainable.
  • Measure cost per retained dollar. Track how much liquidity remains 30 and 90 days after a program ends, not just peak TVL.
  • Target incentives at pools you actually need deep (your core pairs), and taper them on a published schedule.
  • Reward commitment through lockups, vesting of rewards or ve-style boosts, while recognizing these add complexity and their own failure modes.
  • Avoid points programs with vague promises. Points that imply a future token without terms invite disputes and regulatory attention.

Build process

  1. Model the economics. Total emissions, schedule, expected TVL, token price sensitivity. Run a scenario where the token price falls 80%.
  2. Choose the reward mechanism: MasterChef-style, per-pool staking contracts, gauges, or Merkle distribution.
  3. Write or fork contracts, removing owner powers you do not need and timelocking the rest.
  4. Test edge cases: zero total stake, many pools, reward token with low decimals, fee-on-transfer LP tokens, emissions ending.
  5. Audit the farm and any vault strategies. Strategies that call external protocols need fork tests against real deployments.
  6. Launch, monitor and taper. Publish the schedule and stick to it.

Cost and timeline drivers

ScopeReasoned estimateMain effort
Forked MasterChef + UI for your own pools3–6 weeks, small teamRemoving unsafe owner powers, audit
Single-strategy ERC-4626 vault4–8 weeksStrategy integration, harvest safety, fork tests
Gauge and ve-token system3–6 monthsVoting math, decay, fee distribution, governance
Multi-strategy aggregator6+ monthsMany integrations, risk framework, ongoing operations

Audit costs scale with code size and complexity and are a meaningful share of any of these budgets. If you are building the pools that will be farmed, start with the DEX development guide; for single-asset rewards, see the staking platform guide.

General information only, not financial or legal advice. Advertising fixed or guaranteed farming returns can be misleading and may breach financial-promotion rules in several jurisdictions.

Frequently asked questions

Is yield farming the same as staking?

They overlap. Farming usually means depositing LP tokens or capital into a protocol and earning incentive tokens; staking usually means locking a single asset. The reward accounting is often identical, but farming adds impermanent loss and more protocol dependencies.

Where does farming yield come from?

From trading fees, lending interest and token emissions. Emissions are funded by diluting existing holders, so high APYs driven by emissions tend to fall quickly.

Why do so many farm tokens lose value?

Because farmers sell rewards to realize profit. If the token has no demand beyond farming, continuous emissions create continuous sell pressure. Tie the token to revenue or utility, and keep emissions modest.

What is an auto-compounding vault?

A contract that claims farming rewards on depositors' behalf, swaps them for more of the underlying asset and redeposits. It saves users gas and effort but adds swap, strategy and contract risk.

Should a farm contract be upgradeable?

Prefer immutable core contracts with replaceable reward distributors. If you need upgradeability, put it behind a multisig and timelock long enough for users to exit.

How are APYs calculated?

Usually reward tokens per year multiplied by their price, divided by the value of staked liquidity, plus base fees. All inputs change constantly, so the figure is a snapshot, not a forecast.