Skip to main content
Superteam Brasil
Back
+40 XP
8/12

Staking Rewards Calculator

Build a staking rewards calculator that computes compound interest over multiple epochs.

Your calculator should compute:

  1. Final balance after N epochs with compound rewards
  2. Effective APY accounting for compounding
  3. Total rewards earned over the staking period

This is the math behind every staking dashboard and validator calculator. Master compound interest to build accurate DeFi UIs.

Test Cases

Should return object with finalBalance, totalRewards, effectiveApy
Input: 100, 7.5, 2.5, 146Expected: typeof result === 'object' && 'finalBalance' in result && 'totalRewards' in result && 'effectiveApy' in result
Final balance should be greater than initial stake
Input: 100, 7.5, 2.5, 146Expected: typeof result.finalBalance === 'number' && result.finalBalance > 100
Total rewards should be positive
Input: 100, 7.5, 2.5, 146Expected: typeof result.totalRewards === 'number' && result.totalRewards > 0

Discussion