BlockchainAppMaker

DeFi

DeFi staking platform development: reward math, liquid staking and the risks

"Staking platform" covers two very different products: token staking, where users lock a token in a contract to earn rewards someone else funds, and protocol staking, where users delegate assets to validators that secure a proof-of-stake network. They share a user interface but almost nothing else, so decide which one you are building first.

Two kinds of staking

Token (reward) stakingProtocol (validator) staking
Where rewards come fromA treasury, emissions or protocol feesNetwork issuance and transaction fees
What secures itYour contract's accountingValidator operations plus your contracts
Main risksAccounting bugs, unsustainable rewardsSlashing, downtime, withdrawal delays, operator concentration
Typical formSingle-asset pool, LP staking, ve-locksDelegation UI, staking pool, liquid staking token
Examples of the patternSynthetix StakingRewards, Curve veCRVLido stETH, Rocket Pool rETH

If you stake an NFT rather than a fungible token, the accounting is similar but the custody and metadata questions differ; see the NFT staking guide.

Token staking: the reward accumulator

A naive staking contract loops over every staker to distribute rewards. That fails once you have more than a few hundred users because the loop exceeds the block gas limit. The standard solution, popularized by Synthetix's StakingRewards contract, is a global accumulator.

The contract stores rewardPerTokenStored: the total reward one staked token would have earned since the start. Whenever anyone stakes, withdraws or claims, it first updates:

rewardPerToken = rewardPerTokenStored
    + (now - lastUpdateTime) * rewardRate * 1e18 / totalStaked

earned(user) = balance[user] * (rewardPerToken - userRewardPerTokenPaid[user]) / 1e18
             + rewards[user]

Then it records the user's checkpoint. Every operation is constant-time regardless of how many users there are. The same idea underlies MasterChef farms and most reward distributors.

Details that cause real bugs

  • Update before you change balances. If a function modifies balance before calling the update modifier, the user is credited for time they were not staked. This is the single most common staking bug.
  • Division by zero and idle periods. When totalStaked is zero, rewards for that period are either lost or must be explicitly carried forward. Decide which and document it.
  • Precision. With a low-decimal reward token and a large total stake, rewardRate * dt / totalStaked rounds to zero. Scale by 1e18 or more and test with realistic magnitudes.
  • Reward funding. Setting a reward rate the contract cannot pay leads to the last claimers getting nothing. Check that the contract holds enough reward tokens for the period when a rate is set.
  • Same token for stake and reward. If users stake the reward token, the contract's balance includes both principal and rewards. Track them separately so a reward shortfall never touches principal.
  • Weird tokens. Fee-on-transfer and rebasing tokens break balance assumptions. Measure actual amounts received or exclude them.

Lockups, multipliers and vote-escrow

Many platforms reward commitment. Common designs:

  • Fixed-term locks with higher rates for longer terms. Simple, but users with funds stuck during a crash become angry users. Consider early exit with a penalty that flows to remaining stakers.
  • Cooldowns, where unstaking starts a timer before withdrawal. This protects against flash-loan stake-and-vote attacks and sudden liquidity flight.
  • Vote-escrow (ve) tokens, introduced by Curve. Users lock for up to a maximum period and receive non-transferable voting power that decays linearly to zero at unlock. Voting power directs emissions or fee shares. It aligns long-term holders but spawns secondary markets (liquid wrappers, bribe platforms) that you should anticipate.

Protocol staking and liquid staking

On Ethereum, a validator requires 32 ETH and runs consensus and execution clients. Since the Shanghai/Capella upgrade in April 2023, staked ETH can be withdrawn, and the Pectra upgrade in May 2025 raised the maximum effective balance per validator from 32 to 2,048 ETH, which lets large operators consolidate validators. The official ethereum.org staking documentation describes the options from solo staking to pooled services.

A staking pool collects deposits, runs or delegates to node operators and issues a receipt token. That token comes in two styles:

  • Rebasing: the balance in the user's wallet grows as rewards accrue. Intuitive, but many DeFi contracts do not handle balances that change on their own.
  • Value-accruing: the balance stays fixed and the exchange rate to the underlying asset rises. This integrates cleanly with lending markets and AMMs, which is why wrapped, non-rebasing versions exist.

The receipt token's market price can drift below its redemption value when withdrawal queues are long or markets panic. Any protocol that uses it as collateral should price it carefully rather than assuming 1:1.

Operational risks

  • Slashing penalizes validators for double-signing or equivocation. Decide whether losses are socialized across all stakers or absorbed by an operator bond or insurance fund.
  • Operator concentration creates both network and counterparty risk. Diversify operators and clients.
  • Withdrawal credentials must point to a contract you control correctly. A misconfigured credential can strand funds permanently.
  • Restaking layers, which reuse staked ETH to secure other services, add additional slashing conditions. Each layer compounds risk; disclose it.

Staking on other proof-of-stake chains

Ethereum is not the only model. If your platform supports several networks, each one's staking mechanics shape the product you can offer:

  • Cosmos SDK chains use native delegation: users delegate tokens to a validator from their own wallet, rewards accrue to be claimed, and undelegating starts an unbonding period (21 days on the Cosmos Hub) during which tokens earn nothing and can still be slashed. A staking UI here is mostly a validator selector, a claim button and clear unbonding timers.
  • Polkadot uses nominated proof of stake: nominators back a set of validators, and nomination pools let smaller holders participate together. Unbonding also takes weeks.
  • Solana uses stake accounts delegated to a validator; activation and deactivation happen at epoch boundaries, roughly every couple of days. Liquid staking pools issue SPL receipt tokens.

The user-facing flow is usually the same three actions under different names: delegate (or stake), claim (or compound) and undelegate (or unstake). The engineering differences sit underneath: whether rewards auto-compound, how long exits take, how slashing is applied and whether you need your own contracts at all. On many native-delegation chains you write no smart contracts; you build a wallet-connected interface that constructs staking transactions, which dramatically reduces audit scope.

Building a staking platform step by step

  1. Define the source of yield. Fees, network issuance or emissions. If the honest answer is "our own token's inflation", the rewards dilute holders and the APY will fall as stake grows. Say so in your interface.
  2. Choose the accounting model: accumulator, ve-locks, or share-based vault. For deposit-and-earn products, the ERC-4626 tokenized vault standard gives you a standard interface that wallets and aggregators already understand.
  3. Write invariants: total claimable rewards never exceed funded rewards; a user's principal is always withdrawable after unlock.
  4. Test with fuzzing across many users and random timings, and with tokens of different decimals.
  5. Audit the contracts, including admin functions that change reward rates or durations.
  6. Launch with caps and monitor that reward balances match accrued obligations.

Displaying APY honestly

An APY figure is a projection, not a promise. It is usually computed from the current reward rate divided by current total stake, so it falls as more people stake and changes with the reward token's price. Show the components (base yield, token rewards), the assumptions, and the risks. Never describe rewards as guaranteed.

This is general information, not legal or financial advice. Staking services can be regulated differently depending on whether a provider takes custody, who controls the assets and the jurisdiction. US SEC staff issued statements in 2025 on protocol staking and liquid staking; staff statements are not rules, and other regimes such as the EU's MiCA apply their own tests.

Cost and timeline

As an estimate, a single-asset token staking contract based on a known pattern, with a front end, is two to four weeks of engineering plus a small audit. A ve-token system with gauges and fee distribution is a multi-month project. A liquid staking protocol, with operator management, oracle reporting of validator balances and withdrawal queues, is one of the more demanding DeFi builds and should be scoped like a full protocol; the DeFi development overview covers that wider process, and the audit guide covers review.

Frequently asked questions

What is the difference between staking and yield farming?

Staking usually means locking a single asset to earn rewards or secure a network. Yield farming usually means providing liquidity, often an LP token, and earning incentive tokens on top of trading fees. The reward accounting is similar; the risks differ, since farming adds impermanent loss. See the yield farming guide.

Where does staking yield come from?

From network issuance and fees for protocol staking, or from a treasury, protocol revenue or token emissions for token staking. Emissions-funded yield is paid by dilution of other holders.

Can a staking contract be upgradeable?

It can, but every upgrade path is a way for a compromised admin to take user funds. If you use a proxy, put upgrades behind a multisig and timelock, and consider making principal-withdrawal logic immutable.

How do I prevent flash-loan staking attacks?

Do not grant voting power or reward snapshots based on balances that can be acquired and returned in one transaction. Use time-weighted balances, snapshots taken before a proposal, or a minimum staking duration.

Should rewards be claimed or auto-compounded?

Manual claims are simpler and cheaper to audit. Auto-compounding is convenient but requires swaps, which introduce slippage and sandwich risk. Many platforms offer auto-compounding as a separate vault on top of the base staking contract.

What happens if validators get slashed?

Losses reduce the pool's underlying assets, which either lowers the receipt token's exchange rate or rebases balances down, unless the protocol covers it from operator bonds or an insurance fund. Your documentation should state which.