Developing a Yield Vault: Multi-Strategy, ERC-4626, Gas Optimization

How to build a DeFi yield aggregator? Yearn Finance formulated an idea that remains relevant: users should not manually monitor dozens of protocols for the best APY. We design a vault that accepts a deposit, and the strategy automatically places funds in the best protocol, reinvests yield, and sw

Blockchain Development Services

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1310
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1270
  • image_logo-advance_0.webp
    B2B Advance company logo design
    719
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    1012
  • image_logo-aider_0.webp
    AIDER company logo development
    955
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1063

How to build a DeFi yield aggregator?

Yearn Finance formulated an idea that remains relevant: users should not manually monitor dozens of protocols for the best APY. We design a vault that accepts a deposit, and the strategy automatically places funds in the best protocol, reinvests yield, and switches when conditions change. The user receives a yvToken and doesn't need to think about anything else. Our experience shows that building an aggregator means solving several unrelated engineering challenges simultaneously: an on-chain vault with multiple strategies, an off-chain keeper for automation, an APY comparison system with normalization, and gas optimization that doesn't eat up all the yield. We guarantee high code quality and security at every stage.

How is the multi-strategy vault architecture structured?

Basic ERC-4626 vault

ERC-4626 is the modern standard for tokenized vaults. It defines a unified interface: deposit(), withdraw(), convertToShares(), convertToAssets(). The vault issues shares (ERC-20 tokens), and the price per share increases as yield accumulates. The key advantage of ERC-4626 is compatibility: any protocol supporting this standard can use your vault as a building block. Yearn V3 reworked everything around it. Building a vault today means implementing ERC-4626.

// Minimal interface interface IERC4626 { function deposit(uint256 assets, address receiver) external returns (uint256 shares); function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); function totalAssets() external view returns (uint256); function convertToShares(uint256 assets) external view returns (uint256); function convertToAssets(uint256 shares) external view returns (uint256); } 

Multi-strategy allocation

One vault — several strategies. The vault distributes funds among them according to weights (allocator). Each strategy is a separate contract implementing the IStrategy interface with methods harvest(), report(), withdraw(). Typical strategies for a USDC vault:

Strategy Base APY Additional Rewards Risk
Aave V3 lending ~5% None Low (proven protocol)
Compound V3 ~4-6% COMP (separate claim) Low
Curve 3pool ~2-4% CRV, CVX Medium (gauge changes)
Morpho ~6-8% None Medium (peer-to-peer layer)

The allocator decides how much to keep in each strategy. The simplest approach is to put everything into the one with the highest APY. A more mature approach is diversification with max_allocation_per_strategy (no more than 50% in one protocol) and consideration of liquidity.

Why is ERC-4626 the foundation of a modern vault?

The standard allows easy integration with any DeFi protocol. A vault that complies with ERC-4626 can be used as a building block for other products: collateral in lending, backing for StableSwap, a component of a yield-bearing portfolio. We use the OpenZeppelin implementation for a reliable base.

Gas optimization for small positions

The harvest operation (claim rewards + swap + reinvest) costs $5-20 on Ethereum mainnet. For a vault with $10K TVL, daily harvest consumes 1-2% of annual yield. Solutions:

  • Batch harvesting: triggered when unrealized profit exceeds a threshold of gas cost × multiplier. If expected profit is $50 and harvest costs $15 — execute. If profit is smaller — wait.
  • L2-first strategy: On Arbitrum or Base, gas per harvest is 100-500 times cheaper. A $50K TVL on Arbitrum can harvest hourly without losses. Gas savings for $1M TVL can reach $5000 per month.
  • Gas optimization: batching via Multicall3, using ERC-2612 (permit), packed storage.
Network Approx gas per harvest TVL for profitability
Ethereum $10-25 >$200K
Arbitrum $0.05-0.1 >$10K
Base $0.02-0.05 >$5K

Why is APY comparison a nontrivial task?

The APY displayed on Aave, Compound, Curve is not the same metric. Aave: supplyAPY = (1 + supplyRatePerSecond)^(seconds_per_year) - 1, does not include AAVE emissions. Compound: supplyRate in wei per second, COMP reward separately. Curve + Convex: base APY from trading fees + CRV + CVX + extra rewards — totaling 4-5 streams. Morpho: APY higher than base due to peer-to-peer matching.

Normalization: convert all rewards to USD via Chainlink oracle, compute total_yield_per_day / tvl * 365. This gives a comparable APY. For forward-looking estimates, we use a 7-day moving average.

What risks and protections do we provide?

  • Strategy loss: a strategy may lose funds (exploit). The vault has a report() mechanism with emergency exit if losses exceed X%.
  • Withdrawal queue: a user withdrawing $1M — first from free balance, then gradual withdrawal from strategies in priority order.
  • Rugpull via governance: all strategy changes go through a 48-hour timelock. Emergency functions are limited to a pre-approved multisig.

What tools do we use?

Foundry for contracts and tests. OpenZeppelin (ERC-4626, AccessControl, ReentrancyGuard). The Graph for indexing events. Off-chain keeper: TypeScript + viem, deployed on Railway or VPS. Tenderly for simulation.

How do we work?

  1. Architecture and strategies (1 week): selecting protocols, allocation logic, gas threshold.
  2. Core vault + basic strategy (2 weeks): ERC-4626, Aave/Compound, keeper.
  3. Additional strategies (1 week per strategy): Curve, Morpho, Convex.
  4. APY engine + frontend data (1 week): normalization service, API.
  5. Audit (optional).

Timelines and cost vary: from 2 weeks to 3 months, price from $15,000 to $60,000 depending on number of strategies and networks. We give an exact estimate after agreeing on the technical specification.

What is included in the work

  • Architecture and interface documentation.
  • Source code for smart contracts and keeper.
  • Tests (unit, integration, fuzzing) with >90% coverage.
  • Deployment and operation instructions.
  • Technical support during launch.
  • Option to train your team.

We have over five years of DeFi development experience, delivered 30+ projects, and launched 10+ vaults on mainnet. Gas optimization and rebalancing are our core competencies.

Order a DeFi yield aggregator development — contact us to discuss the technical specification. Get a consultation on architecture and timelines.