⭐ If this project inspires you, please give it a star on GitHub — it fuels open-source innovation!
King Yield Aggregator (KYA) is a modular, role-secured yield vault designed to automatically deploy user deposits into external strategies to earn optimized yield.
It follows a clean separation of concerns across vault logic, strategy management, access control, and safety modules.
- Automated Yield Deployment: Deposits can be routed through a Strategy Manager into yield strategies (e.g., Aave, Compound).
- Share-Based Accounting: Users receive vault shares representing their proportional ownership of total assets (on-vault + deployed).
- Modular Architecture: Vault, Strategy Manager, Rebalancer and Strategy contracts are separated for extensibility and composability.
- Secure Access Control: Powered by the custom Kingable access control suite with pausing, roles, and non-zero address checks.
- Safe Withdrawals: Withdrawals pull liquidity from on-vault balance and fallback to strategy withdrawal when needed.
- Switchable Strategies: Strategy Manager can switch strategies without affecting user deposits or share balances.
┌────────────────────┐
│ VaultCore │ <-- User-facing, handles deposits/withdrawals
│--------------------│
│ - Share accounting │
│ - Deposit/Withdraw │
│ - Calls |
| StrategyManager │
└─────────┬──────────┘
│
▼
┌────────────────────────┐
│ StrategyManager │ <-- Handles strategy orchestration
│------------------------│
│ - Active strategy list │
│ - APR tracking │
│ - Deposit to / Withdraw|
| from strategy │
│ - Exposes interface for|
| Rebalancer │
└─────────┬──────────────┘
│
▼
┌───────────────────┐ ┌─────────────────────┐
│ Strategy A │ │ Strategy B │
│-------------------│ │---------------------│
│ - Protocol logic │ │ - Protocol logic │
│ - Yield tracking │ │ - Yield tracking │
└───────────────────┘ └─────────────────────┘
┌────────────────────────┐
│ Rebalancer │ <-- Independent module
│------------------------│
│ - Reads StrategyManager│
│ - Moves funds A → B │
│ - Cooldowns, limits │
└────────────────────────┘
All inter-module interactions occur through interfaces to reduce coupling.
- Core Concepts - Start here if you're new
- Architecture Deep Dive - Technical details
- Usage Guide - Deployment walkthrough
├── src
│ ├── Rebalancer.sol
│ ├── StrategyManager.sol
│ ├── Utils.sol
│ ├── VaultCore.sol
│ ├── interfaces
│ │ ├── IStrategy.sol
│ │ ├── IStrategyManager.sol
│ │ ├── IStrategyManagerRebalancer.sol
│ │ └── IStrategyManagerVault.sol
│ ├── mocks
│ │ ├── AaveStrategyMock.sol
│ │ └── CompoundStrategyMock.sol
│ └── types
│ ├── ManagerTypes.sol
│ ├── StrategyTypes.sol
│ └── VaultTypes.sol
└── test
├── BadStrategyMock.t.sol
├── BadTokenTest.t.sol
├── BaseTest.t.sol
├── DummyContract.t.sol
├── MockTokenTest.t.sol
├── fuzz
│ └── VaultCoreFuzzTest.t.sol
└── unit
├── AaveStrategyMockTest.t.sol
├── CompoundStrategyMockTest.t.sol
├── RebalanacerTest.t.sol
├── StrategyManagerTest.t.sol
└── VaultCoreTest.t.sol
King Yield Aggregator (KYA) is a fully-tested modular vault system that aggregates yield from multiple DeFi lending protocols. The architecture separates concerns cleanly through VaultCore, StrategyManager, and Rebalancer contracts, allowing easy addition of new strategies while maintaining security through role-based access control.
This project demonstrates advanced Solidity principles, including:
- Share-based accounting for fair yield distribution
- Multi-strategy support with dynamic switching
- Role-based access control (King/Admin separation)
- Custom errors and events for gas efficiency
- Modifiers and helper functions for code reusability
- Reentrancy guards on critical functions
- Comprehensive validation (zero checks, balance checks, etc.)
- Test coverage including fuzz testing
- Gas optimization through efficient state management
- KingClaimMistakenETH allows recovery of mistakenly sent ETH.
This project is designed as a modular reference implementation.
You can interact with it in three ways:
- Via Foundry tests (recommended for developers)
- Via Remix using mock strategies
- Via custom scripts or frontend integration
➡️ See USAGE.md for a step-by-step Remix walkthrough.
- Language: Solidity
^0.8.30 - IDE: Remix & VS Code
- Framework: Foundry
- Version Control: Git + GitHub (SSH)
- Libraries: BuildsWithKing Security
Full unit and fuzz test coverage for all logic paths:
- VaultCore: Deposit, withdraw, withdrawAll, share calculations, conversions
- StrategyManager: Add/remove strategies, set active strategy, fund deployment
- Rebalancer: APR monitoring, rebalance triggers, threshold checks
- Edge cases: Zero amounts, insufficient shares, bad token transfers, reentrancy
- Access control: King-only, admin-only, role-based functions
- Custom error reverts: ZeroAmount, InsufficientShares, TokenTransferFailed, etc.
- Fuzz testing: Random deposits, withdrawals, and yield scenarios
Note: Static analysis (Aderyn) used. High-severity findings addressed. Remaining low-severity findings were assessed as acceptable design tradeoffs.
To run locally:
- Install Foundry
- Clone repo
git clone https://github.com/BuildsWithKing/king-yield-aggregator.git
cd king-yield-aggregator
- Run:
forge install
forge compile || forge build
forge test
forge coverage
forge snapshot
Note: Remapping enabled in foundry.toml
remappings = [ "buildswithking-security/=lib/buildswithking-security/contracts/access/" ]
MIT License — Feel free to fork, learn, and build with it.
Built by Michealking
Created: Nov 24 - Dec 21, 2025
This project was built as part of the Contract.dev Hackathon.
🤝 Contributing: Issues and pull requests welcome! Please ensure all tests pass and maintain 100% coverage for new features.
✅ King Yield Aggregator — Full Coverage Achieved!
