OG yield aggregator. Yearn V3 vaults are ERC-4626 tokenized vaults that allocate deposits across multiple `Strategies` to optimize risk-adjusted yield on stablecoins, ETH, and LSTs.
- 01auto-compounded stablecoin yield
- 02ERC-4626 vault integrations
- 03yvTokens as collateral
- 04passive treasury management
- pnpm add viem
| Variable | Scope | Description |
|---|---|---|
| NEXT_PUBLIC_YEARN_REGISTRY | Client | Yearn V3 Release Registry on Ethereum mainnet: 0xff31A1B020c868F6eA3f61Eb953344920EeCA3af. Use this to enumerate canonical yvVaults. |
Integrate Yearn V3 yield. Each yvVault is an ERC-4626 token. To deposit: `IERC20(asset).approve(vault, amount)` then `IVault(vault).deposit(uint256 assets, address receiver)` — receiver gets yvShares whose price (`pricePerShare()` / `convertToAssets(1e18)`) only goes up as the vault auto-compounds. To withdraw: `IVault(vault).redeem(uint256 shares, address receiver, address owner, uint256 maxLoss)` — `maxLoss` is in basis points (use 1 for ~0.01% slippage tolerance from idle/strategy losses). Read available APY from the public `https://api.yearn.fi/v1/chains/{chainId}/vaults/all` endpoint and discover live vaults from the V3 Release Registry. For V2 legacy vaults the function names differ slightly (`deposit(amount)` / `withdraw(shares)`).
- ⚑yvTokens are NON-rebasing; `pricePerShare` increases over time. Compute earned yield as `currentShares * pricePerShare - depositedAssets` — do not assume share count grows.
- ⚑V3 `redeem` takes a `maxLoss` parameter in BPS; passing 0 will revert if any strategy reports a tiny rounding loss. Use `maxLoss = 1` (0.01%) as a safe default and surface this to users.
- ⚑Vaults can have idle strategies that deploy capital lazily — instant withdrawals may be partially served from idle, but if illiquid strategies need to unwind you can hit `INSUFFICIENT_LIQUIDITY` and have to wait or accept a loss.
- ⚑Each `Strategy` underlying a vault is itself a smart contract with separate risk (Compound, Aave, Pendle, Curve gauge, etc.) — Yearn risk = vault code risk + sum of strategy risks.
- ⚑V2 and V3 vaults coexist; the same asset (e.g. USDC) may have multiple vaults with different risk profiles. Always pin to a specific vault address from the registry rather than asset symbol.
- ⚑Withdrawals do not have a queue, but performance fees (10% default) and management fees are deducted from yield before users see APY.
- ⚑Yearn vault addresses are NOT the same across chains — yvUSDC on mainnet ≠ yvUSDC on Polygon/Optimism/Arbitrum.