Building a Fee Distribution System for Your Protocol

Building a Fee Distribution System for Your Protocol Imagine: your DeFi protocol generates $100k in fees daily, but token holders receive nothing. Uniswap V3 faced this before enabling the fee switch — governance redirected some fees to the treasury, requiring a reliable system for collection, ac

Blockchain Development Services

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1450
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1308
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    1003
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1269
  • image_logo-advance_0.webp
    B2B Advance company logo design
    717
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    1008

Building a Fee Distribution System for Your Protocol

Imagine: your DeFi protocol generates $100k in fees daily, but token holders receive nothing. Uniswap V3 faced this before enabling the fee switch — governance redirected some fees to the treasury, requiring a reliable system for collection, accumulation, and distribution. We build such systems turnkey with gas optimization and security in mind. Synthetix StakingRewards — the benchmark pattern we adapt to your architecture.

Two Distribution Patterns: Push vs Pull

Why Pull Distribution Is Better Than Push?

Push distribution — send to everyone. The contract accumulates fees and periodically calls distribute(), which iterates over the staker list and transfers each their share. Simple to understand, complex to implement: an unbounded loop is a classic gas griefing vector. With 10,000 stakers, the transaction exceeds the block gas limit (requiring ~3 million gas instead of typical 150k).

Acceptable only for systems with an explicit cap on participants and batch processing (pagination). In most cases, it's the wrong choice. Pull distribution reduces gas costs for claims by 4x, critical when scaling to thousands of stakers.

Pull distribution — users claim themselves. The contract maintains rewardPerTokenStored — accumulated reward per unit of stake since launch. On each deposit/withdraw/claim, it updates userRewardPerTokenPaid for the specific user. Reward = (rewardPerTokenStored - userRewardPerTokenPaid) * balance.

This is the math from Synthetix StakingRewards — one of the most copied patterns in DeFi. Key property: Gas-complexity O(1) for claim, independent of staker count.

function earned(address account) public view returns (uint256) { return ( (balanceOf[account] * (rewardPerToken() - userRewardPerTokenPaid[account])) / 1e18 ) + rewards[account]; } 

We use this pattern as the foundation for most fee distribution systems.

Characteristic Push distribution Pull distribution
Gas per claim ~200,000 + O(N) ~50,000 O(1)
Problem at 10,000 stakers Exceeds limit Minimal increase
Bug complexity High (repeats, frontrun) Medium (math)
Scalability Poor Excellent

Fee Collection and Conversion

How to Convert Fees Without Loss?

Protocols generate fees in various tokens — swap fees in traded tokens, lending fees in debt tokens. Before distributing to stakers, you need to convert into a single target token (usually protocol token or USDC).

FeeCollector contract — aggregates fees from all source contracts. Periodically called by a keeper (Chainlink Automation, Gelato) or any user.

Conversion via DEX — swap accumulated fees into the target token through Uniswap V3. Important: converting a large volume at once creates price impact and MEV opportunities. Solution: convert in small batches using TWAP-oriented swaps or use Cow Protocol for MEV-protected swaps. This reduces slippage by 20-30%.

Distribution in multiple tokens — sometimes it's better not to convert but distribute in original fee tokens. Curve distributes 3CRV LP tokens (a stablecoin basket) instead of converting. This is more expensive to implement (multi-reward staking) but preserves value without slippage.

Multi-Channel Distribution

Rarely does the entire fee go only to stakers. Typical scheme:

Recipient Share Mechanism
Token stakers 40-60% Pull-distribution, rewardPerToken
Treasury 20-30% Direct transfer to multisig
Insurance fund 10-20% Accumulation to cover bad debt
Burn 5-10% token.burn()

Proportions set via governance-controlled parameters with timelock. FeeDistributor contract reads current proportions on each distribute() call.

veToken Model (Vote-Escrowed)

Curve introduced a model where to receive fees, you must lock CRV for up to 4 years. The longer the lock, the more veCRV, and the larger the fee share. This aligns interests: long-term holders get more. Implementation is more complex than basic staking — requires decay calculation of voting power, periodic checkpoints, integration with gauge voting.

If you need a veToken mechanism, that is a separate scope on top of basic fee distribution.

What Is Included

  • Audit of existing architecture and selection of optimal pattern (pull/push/hybrid).
  • Development of smart contracts: FeeCollector, FeeDistributor, Staking (with reentrancy protection, OpenZeppelin checks).
  • Integration with DEX for conversion (Uniswap V3, Cow Protocol).
  • Test writing (Foundry, fuzz, fork tests) covering edge cases.
  • Deployment and verification of contracts on Etherscan.
  • Documentation for governance and auditors.
  • Post-launch support (monitoring, hotfixes).

We guarantee no reentrancy or frontrunning vulnerabilities. Team experience: 7+ years in blockchain, 50+ smart contracts, 5 years on the market. Contact us for an architecture audit — we'll assess your project in 1 day. Order a fee distribution system development – get architecture consultation.

What risks does push distribution hide?

Push distribution with a large number of stakers can exceed the block gas limit, and is also susceptible to frontrunning attacks at the moment of calling distribute(). For large protocols, pull distribution is safer.

Process and Timeline Estimates

Design (2-3 days). Determine source contracts, target token, distribution proportions, keeper mechanism for periodic conversion.

Development (5-8 days). FeeCollector + FeeDistributor + Staking contract. Tests with Foundry: correct calculation of earned() under changing total supply, correct handling of deposit/withdraw in the same block as distribute().

Integration tests. Fork test with a real Uniswap V3 pool to verify fee conversion. Fuzz tests on distribution math — edge cases with very small or very large balances.

Basic system (pull-distribution, one reward token, periodic collect) — 1 week. With DEX conversion and multi-reward — 1.5-2 weeks. veToken mechanism — additional 2-3 weeks. Cost is calculated individually based on complexity and required audit.