DeFi Strategy Yield Calculator Development
A user sees 45% APY on a platform and deposits assets. Three months later, when withdrawing, they get only 8% in dollars. The rest was eaten by entry and exit fees, gas on 12 transactions, impermanent loss in the pool, and taxes on reward tokens that lost 70% of their value by harvest time. We've encountered such situations dozens of times — that's why we developed a yield calculator that shows the real picture before a decision is made. Our tool works for LP positions, lending, and staking on Ethereum, Polygon, Arbitrum, and other networks. The calculator integrates with major protocols: Aave, Compound, Uniswap, Curve, and Balancer. It accounts for not only APY but also gas, IL, token price changes, and taxes. Order the turnkey development of such a calculator — we'll assess your project and propose a solution.
What parameters must be considered when calculating yield?
How is APY different from APR?
APR (Annual Percentage Rate) is simple interest without reinvestment. APY (Annual Percentage Yield) includes compound interest. The difference is substantial:
- APR 50% → APY ≈ 64.8% with daily compounding
- APR 50% → APY ≈ 100% with compounding every block (~12 seconds on Ethereum)
The formula for APY from APR: APY = (1 + APR/n)^n - 1, where n is the number of compounding periods per year.
The problem: in DeFi, APY is often displayed assuming a constant rate and maximum compounding. In reality, the rate changes every block, and gas for each compound operation reduces real yield. compound interest
How to determine the optimal compound frequency?
With standard Ethereum gas costs and a medium-sized position at 40% APR, the optimal compound frequency is about once every 7 days. More frequent compounding causes gas to eat more than the compound earns. The calculator calculates the optimal interval.
Why is impermanent loss critical for LPs?
For liquidity provider positions, yield cannot be calculated without impermanent loss (IL). The IL formula for Uniswap v2:
IL = 2 * sqrt(priceRatio) / (1 + priceRatio) - 1 If an ETH/USDC pool: ETH entered at $2000, now $3000. priceRatio = 1.5. IL ≈ -2.02%.
For Uniswap v3 with concentrated liquidity, IL is calculated differently — it depends on the position's range. If the price exits the range, the position becomes 100% in one asset (full IL, no fees earned). The math is more complex but implementable: you need to know tickLower, tickUpper, and the current tick.
Real components of yield for a full calculation
interface YieldComponents { baseApr: number; // Lending APR or trading fees rewardApr: number; // Emission rewards in protocol tokens compoundBonus: number; // Gain from reinvestment impermanentLoss: number; // LP only (negative) tradingFees: number; // Accumulated fees over period gasCosts: number; // All on-chain operations in USD tokenPriceImpact: number; // Change in reward token price realYield: number; // Total in USD } Step-by-step calculator development
- Requirements gathering and protocol selection for integration
- Development of a mathematical library in TypeScript
- Connecting data sources: The Graph, RPC, APIs
- Implementing scenario simulation and gas calculator
- UI/UX design with Recharts for visualization
- Wallet integration via wagmi
- Testing on testnet and mainnet
- Documentation and team training
Data sources
- Aave v3:
getReserveData()returnscurrentLiquidityRate(RAY = 1e27). Conversion to APY:(1 + rate/SECONDS_PER_YEAR)^SECONDS_PER_YEAR - 1 - Compound v3:
getUtilization()→getSupplyRate(utilization)→ linear APR calculation - Uniswap v3: fees APR is computed via subgraph or
positions()NFT — volume over 24h × fee tier / TVL × 365 - Curve:
get_virtual_price()for base APY + gauge reward APR via CRV emission schedule - Balancer: vault API or subgraph for
swapFeeand volume
The Graph subgraph is the preferred source for historical data. It fetches data 5 times faster than direct RPC calls. Direct RPC calls are used for real-time current rates.
Simulation over a time horizon
The calculator not only calculates current APY but also projects over the user's horizon (30/90/365 days) with several scenarios:
| Scenario | Assumptions | Purpose |
|---|---|---|
| Optimistic | APR does not drop, rewards +50% | Maximum potential |
| Baseline | APR drops 20% per quarter (TVL growth) | Realistic estimate |
| Conservative | APR -50%, rewards -70% | Protection from false expectations |
| Bear market | APR minimal, all assets -50% | Stress test |
Gas cost calculation
Each operation has a measurable gas cost. Below are typical costs:
| Operation | Gas (units) |
|---|---|
| aaveDeposit | 180,000 |
| aaveWithdraw | 210,000 |
| uniswapV3Mint | 450,000 |
| uniswapV3Collect | 280,000 |
| curveDeposit | 320,000 |
| rewardClaim | 150,000 |
const GAS_ESTIMATES = { aaveDeposit: 180_000, aaveWithdraw: 210_000, uniswapV3Mint: 450_000, uniswapV3Collect: 280_000, curveDeposit: 320_000, rewardClaim: 150_000, } as const; function calcGasCost(operation: keyof typeof GAS_ESTIMATES, gasPriceGwei: number): number { const gasUnits = GAS_ESTIMATES[operation]; const ethPrice = getCurrentEthPrice(); return (gasUnits * gasPriceGwei * 1e-9) * ethPrice; // USD } Historical gas price data from Etherscan API or The Graph — for average cost calculation under a given rebalancing/harvesting strategy.
Functionality and UX
Minimum set:
- Input amount and period
- Protocol/strategy selection (search by name)
- Real-time fetch of current APR from protocols
- Three scenarios (optimistic/baseline/conservative)
- Breakdown: base yield, rewards, impermanent loss, gas costs, net yield
- Side-by-side comparison of multiple strategies
Additionally — a ROI breakeven calculator: at what minimum amount and duration does the strategy cover gas costs? This is especially important for small investors on Ethereum mainnet.
Technology stack
Frontend: React + TypeScript, Recharts for yield graphs, wagmi for wallet connection. Data: The Graph (APR histories), Alchemy/Infura (real-time chain data), CoinGecko API (token prices). Logic: TypeScript utility library with pure functions for all financial calculations — easy to test and reuse.
Timelines
Basic calculator for 2-3 protocols — 3-5 days. Multi-protocol with historical data, IL for LP, and gas optimizer — 1-2 weeks. Cost is calculated individually. Over 5 years in the DeFi market, 20+ completed projects — our experience guarantees calculation accuracy and stable performance.
What's included in the work
- Requirements analysis and protocol selection
- Development of calculation logic (TypeScript)
- Integration with real-time data (The Graph, RPC)
- UI/UX interface design
- Testing on testnets and mainnet
- Documentation and team training
- Two months of support
The simulation uses historical APR data, models pool changes, token prices, and gas. For each scenario, 1000 Monte Carlo iterations run with varying key parameters. The result is a distribution of possible yields.
Contact us for a consultation and get a demo version of the calculator for your project. Order calculator development — we'll assess the project and propose a solution.







