Skip to content

flexyledger/defi-yield-aggregator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DeFi Yield Aggregator

A decentralized finance platform that automatically optimizes yield farming strategies across multiple protocols to maximize returns.

Solidity Hardhat License


πŸ“‹ Table of Contents


🎯 Overview

The DeFi Yield Aggregator is an automated cross-protocol yield optimization platform built on Ethereum. It intelligently distributes user funds across multiple DeFi protocols (Aave, Compound, Curve) to maximize yield while minimizing risk and gas costs.

Key Objectives

  • 30%+ APY Improvement: Achieve higher yields compared to single-protocol staking
  • $5M+ TVL Target: Scale to significant total value locked within first month
  • Multi-Protocol Integration: Seamlessly aggregate yields from top DeFi protocols
  • Gas Optimization: Minimize transaction costs through efficient smart contract design

✨ Features

Implemented (Phase 1) βœ…

  • ERC-4626 Compliant Vault: Standard tokenized vault implementation
  • Multi-Strategy Management: Orchestrate multiple yield strategies with custom allocations
  • Aave V3 Integration: Automated deposits and interest harvesting
  • Compound V3 Integration: Supply assets and claim COMP rewards
  • Security Controls: Role-based access control, pausability, reentrancy protection
  • Gas Optimization: Efficient storage packing and viaIR compilation

Planned Features

  • Curve Finance Integration: LP provision and gauge staking
  • Automated Rebalancing: Dynamic allocation based on real-time APY
  • Frontend Dashboard: React-based UI for vault management
  • Performance Analytics: Historical yield tracking and reporting
  • Multi-Network Support: Deploy to L2s (Arbitrum, Optimism, Polygon)

πŸ›  Technology Stack

Layer Technology Purpose
Smart Contracts Solidity ^0.8.24 Core protocol logic
Development Hardhat 2.22.17 Testing & deployment
Blockchain Ethereum Mainnet & testnets
Standards ERC-4626, ERC-20 Tokenized vault
Security OpenZeppelin Secure contract libraries
Testing Hardhat Toolbox Chai, Ethers, Coverage

πŸ“ Project Structure

defi-yield-aggregator/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ Vault.sol                    # ERC-4626 main vault
β”‚   β”‚   └── StrategyManager.sol          # Multi-strategy orchestration
β”‚   β”œβ”€β”€ strategies/
β”‚   β”‚   β”œβ”€β”€ BaseStrategy.sol             # Abstract strategy base
β”‚   β”‚   β”œβ”€β”€ AaveStrategy.sol             # Aave V3 integration
β”‚   β”‚   └── CompoundStrategy.sol         # Compound V3 integration
β”‚   β”œβ”€β”€ interfaces/
β”‚   β”‚   β”œβ”€β”€ IVault.sol                   # Vault interface
β”‚   β”‚   β”œβ”€β”€ IStrategy.sol                # Strategy interface
β”‚   β”‚   β”œβ”€β”€ IStrategyManager.sol         # Manager interface
β”‚   β”‚   └── external/
β”‚   β”‚       β”œβ”€β”€ IAave.sol                # Aave V3 interfaces
β”‚   β”‚       └── ICompound.sol            # Compound V3 interfaces
β”‚   └── libraries/
β”‚       └── MathUtils.sol                # Math utilities
β”œβ”€β”€ scripts/
β”‚   └── deploy.ts                        # Deployment script
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ CODE_REVIEW_PHASES_INDEX.md      # Master phase index
β”‚   β”œβ”€β”€ CODE_REVIEW_PHASE1_SMART_CONTRACT_DEVELOPMENT.md
β”‚   β”œβ”€β”€ CODE_REVIEW_PHASE2_FRONTEND_DEVELOPMENT.md
β”‚   β”œβ”€β”€ CODE_REVIEW_PHASE3_INTEGRATION_TESTING.md
β”‚   └── CODE_REVIEW_PHASE4_DEPLOYMENT_LAUNCH.md
β”œβ”€β”€ hardhat.config.js                    # Hardhat configuration
β”œβ”€β”€ .env.example                         # Environment template
└── package.json                         # Dependencies

πŸ“œ Smart Contracts

Core Contracts

Vault.sol

The main entry point for user interactions. An ERC-4626 compliant tokenized vault that:

  • Accepts deposits and mints shares
  • Handles withdrawals and burns shares
  • Integrates with StrategyManager for yield optimization
  • Implements role-based access control (Admin, Strategist, Guardian)
  • Includes pausability and emergency withdrawal mechanisms

Key Functions:

function deposit(uint256 assets, address receiver) returns (uint256 shares)
function withdraw(uint256 assets, address receiver, address owner) returns (uint256 shares)
function totalAssets() returns (uint256)
function convertToShares(uint256 assets) returns (uint256 shares)

StrategyManager.sol

Orchestrates multiple yield strategies with custom allocations:

  • Registers and manages up to 10 strategies
  • Allocates funds based on basis point percentages
  • Executes automated rebalancing
  • Harvests rewards from all strategies
  • Emergency withdrawal capabilities

Key Functions:

function addStrategy(address strategy, uint256 allocationBps)
function depositToStrategies(uint256 amount)
function withdrawFromStrategies(uint256 amount) returns (uint256)
function rebalance()
function harvestAll()

Strategy Contracts

BaseStrategy.sol

Abstract base contract providing common functionality:

  • Standardized deposit/withdraw interface
  • Harvest and emergency withdrawal logic
  • Owner and vault access controls
  • Token rescue functionality

AaveStrategy.sol

Aave V3 lending integration:

  • Supplies assets to Aave lending pools
  • Earns interest on supplied assets (aTokens)
  • Calculates real-time APY from Aave
  • Emergency withdrawal to vault

CompoundStrategy.sol

Compound V3 (Comet) integration:

  • Supplies assets to Compound markets
  • Earns supply interest
  • Claims COMP token rewards
  • APY calculation from supply rate

πŸš€ Getting Started

Prerequisites

Important: Hardhat 2.22.x requires Node.js 18.x or 20.x LTS. Node.js 22.x is not yet fully supported.

Recommended Setup:

# Install Node.js 20 LTS using nvm-windows
nvm install 20
nvm use 20

Verify Installation:

node --version  # Should show v20.x.x
npm --version

Installation

  1. Clone the repository
git clone https://github.com/flexyledger/defi-yield-aggregator.git
cd defi-yield-aggregator
  1. Install dependencies
npm install
  1. Set up environment variables
cp .env.example .env
# Edit .env with your configuration:
# - PRIVATE_KEY: Your deployment wallet private key
# - SEPOLIA_RPC_URL: Infura/Alchemy Sepolia endpoint
# - MAINNET_RPC_URL: Mainnet RPC endpoint
# - ETHERSCAN_API_KEY: For contract verification

Compile Contracts

npm run compile
# or
npx hardhat compile

Run Tests

npm test
# or
npx hardhat test

Deploy

Local Network:

# Terminal 1: Start local node
npm run node

# Terminal 2: Deploy
npm run deploy:local

Sepolia Testnet:

npm run deploy:sepolia

πŸ—Ί Development Roadmap

βœ… Phase 1: Smart Contract Development (Completed)

  • Initialize Hardhat project
  • Implement ERC-4626 Vault
  • Create Strategy interfaces
  • Build StrategyManager
  • Implement Aave V3 strategy
  • Implement Compound V3 strategy
  • Add security controls
  • Create deployment scripts

πŸ”„ Phase 2: Frontend Development (In Progress)

  • Initialize React + Vite application
  • Configure Web3.js provider
  • Build dashboard UI
  • Implement vault interaction interface
  • Add transaction history
  • Mobile-responsive design

πŸ“‹ Phase 3: Integration & Testing (Planned)

  • Frontend-contract integration
  • Testnet deployment (Sepolia)
  • Mainnet fork testing
  • Security static analysis (Slither, Mythril)
  • Fuzz testing with Foundry
  • Gas optimization benchmarks

πŸš€ Phase 4: Deployment & Launch (Planned)

  • External security audit
  • Mainnet deployment
  • Multi-sig setup (Gnosis Safe)
  • Bug bounty program (Immunefi)
  • Launch announcement
  • 24/7 monitoring setup

πŸ“Š Progress: 1/4 phases complete (25%)


⚠️ Known Issues

Node.js 22 Compatibility

Issue: Hardhat 2.22.x has module resolution conflicts with Node.js 22.x Error: ERR_MODULE_NOT_FOUND: Cannot find module 'hardhat/types/network'

Solution: Downgrade to Node.js 20 LTS

nvm install 20
nvm use 20
npm install
npx hardhat compile

Pending Implementation

  • Curve Strategy: Not yet implemented (scheduled for Phase 1 completion)
  • Router Contract: Planned for DEX integration optimization
  • Unit Tests: Test suite to be added in Phase 3
  • Frontend: React dashboard in Phase 2

πŸ”’ Security

Implemented Security Measures

  • βœ… OpenZeppelin battle-tested contracts
  • βœ… ReentrancyGuard on all external functions
  • βœ… Pausable vault for emergency scenarios
  • βœ… Role-based access control (Admin, Strategist, Guardian)
  • βœ… Withdrawal fee limits (max 1%)
  • βœ… Performance fee limits (max 20%)

Pending Security Steps

  • ⏳ Comprehensive test coverage (>90% target)
  • ⏳ Static analysis (Slither, Mythril)
  • ⏳ Fuzz testing (Foundry)
  • ⏳ External security audit
  • ⏳ Bug bounty program

Warning: This code is NOT AUDITED. Do not use in production without proper security review.


🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow Solidity style guide
  • Add NatSpec documentation to all contracts
  • Write tests for new features
  • Optimize for gas efficiency
  • Use meaningful commit messages

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ“ž Contact & Links


πŸ™ Acknowledgments

  • OpenZeppelin - Secure smart contract libraries
  • Hardhat - Ethereum development environment
  • Aave - Lending protocol integration
  • Compound - Money market protocol
  • ERC-4626 - Tokenized vault standard

Built with ❀️ for the DeFi ecosystem

⬆ Back to Top

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors