Staking Auto-Compounding System Development
Auto-compounding — automatic reinvestment of staking rewards back into position. Without it, user receives rewards to wallet and must manually restake them. With it — compound interest works automatically. Difference between 10% APY without compounding and 10.47% with daily compounding seems small, but on $1M position over 3 years it's $150K+ additional.
Mathematics of Optimal Frequency
Formula for effective APY with compounding n times per year:
APY_effective = (1 + APR/n)^n - 1
But each compound costs gas. Optimal frequency:
n_optimal = APR × Position_Size / (2 × Gas_Cost)
At 10% APR, $50K position, $10 gas per transaction:
n = 0.10 × 50000 / (2 × 10) = 250 times per year = every 1.46 days
Recalculate dynamically when gas price and position size change.
On-chain vs Off-chain Implementation
Off-chain keeper (most common): external service (bot) periodically calls compound() function in contract. Chainlink Automation, Gelato, or own keeper. Requires paying gas.
On-chain trigger: contract itself initiates compound on every new operation (deposit/withdraw). Additional gas for users, but automatic.
Vault contracts (ERC-4626): standard for yield-bearing vaults. Auto-compounding part of standard functionality. Protocols like Yearn Finance use this pattern.
// ERC-4626 inspired auto-compound
function deposit(uint256 assets, address receiver) external returns (uint256 shares) {
_compound(); // Claim and reinvest accumulated rewards
uint256 totalAssets = totalAssets(); // After compound
shares = assets.mulDivDown(totalSupply, totalAssets);
_mint(receiver, shares);
asset.safeTransferFrom(msg.sender, address(this), assets);
}
Multi-protocol Compounding
Advanced systems compound through several steps:
- Claim rewards in reward token (e.g., CRV)
- Swap CRV to USDC via Uniswap
- Add USDC to Curve pool
- Restake LP tokens back to Convex
Each step — separate transaction or atomic package via Multicall. Complex chain requires careful testing: if one step fails — entire compound can hang.
Zap contracts: atomic swap and compound in one transaction. Gas savings, better UX.
Auto-compounding system — 3-6 weeks development depending on number of supported protocols.







