AI-Powered DeFi Yield Optimization Platform
YieldGuard is an advanced DeFi analytics and automation platform that leverages autonomous AI agents to help users optimize their yield farming strategies. By combining real-time market data, risk analysis, and Large Language Models (LLMs) via Groq, YieldGuard provides personalized, risk-adjusted investment recommendations through an interactive chat interface and a comprehensive dashboard.
- Natural Language Interface: Chat with the agent to request strategies, analyze pools, or ask about market conditions.
- ReAct Pattern: The agent uses a "Reasoning + Acting" loop to break down complex queries, plan steps, and execute tools (e.g., "Fetch yields", "Check gas", "Analyze risk") to generate accurate answers.
- Memory & Context: Remembers your risk tolerance, capital constraints, and previous interactions to provide tailored advice.
- Trend Detection: Automatically identifies rising or falling yield trends using linear regression.
- Volatility Scoring: Categorizes pools into Low, Moderate, High, or Extreme volatility buckets.
- Market Stance: Computes a global "Stance" (Favorable, Neutral, Caution, Wait) based on aggregated trends, volatility, and gas costs.
- Risk Profiling: Customizes strategies for Conservative, Moderate, or Aggressive risk profiles.
- Gas Optimization: Factors in real-time gas prices (Ethereum L1) to ensure strategies are profitable net of fees.
- Safety Scores: Evaluates pools based on TVL, Impermanent Loss (IL) risk, and protocol maturity.
- Real-time Metrics: View live APY, TVL, and gas prices.
- Visualizations: Interactive charts for yield history and portfolio composition.
- Wallet Connection: Seamlessly connect via RainbowKit (MetaMask, WalletConnect, etc.) to manage your portfolio.
YieldGuard operates as a modern full-stack application:
├── backend/ # Python FastAPI Backend
│ ├── src/
│ │ ├── services/ # Core Logic
│ │ │ ├── agent.py # AI Agent (Groq integration, Tool Registry)
│ │ │ ├── analyzer.py # Statistical Analysis Engine
│ │ │ ├── data_service.py # Data fetching (DeFiLlama, etc.)
│ │ │ └── model_runner.py # Strategy Execution
│ │ ├── models/ # Pydantic Models
│ │ └── test/ # Test files
│ ├── main.py # Application Entry Point
│ └── requirements.txt
│
├── frontend/ # Next.js 15 Frontend
│ ├── src/
│ │ ├── app/ # App Router Pages
│ │ ├── components/ # React Components (Shadcn UI)
│ │ ├── contexts/ # App Context (Theme)
│ │ └── lib/ # Utilities
│ ├── package.json
│ └── next.config.ts
│
└── database/ # Database Resources
└── schema.sql # PostgreSQL Schema
- Framework: FastAPI (Python)
- AI/LLM: Groq API (Llama 3 / Mixtral)
- Data Processing: Pandas, NumPy
- Async I/O:
httpx,asyncio
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- Styling: TailwindCSS, Shadcn UI
- Web3: RainbowKit, Wagmi, Viem
- State/Query: React Query (TanStack Query)
- Charts: Recharts
- Token Prices: CoinGecko
- DeFi Data: DeFiLlama API
- Gas Data: Etherscan / Owlracle
- Node.js: v18+
- Python: v3.9+
- API Keys:
- Groq API Key: For the AI agent.
- WalletConnect Project ID: For the frontend wallet connection.
- Etherscan API Key: For precise gas data.
git clone <repository-url>
cd yieldguardcd backend
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip3 install -r requirements.txt
# Configure Environment
cp .env.example .env
# ⚠️ Open .env and add your GROQ_API_KEYcd ../frontend
# Install dependencies
npm install
# Configure Environment
# Create a .env.local file or update providers.tsx with your WalletConnect IDTerminal 1 (Backend):
cd backend
source venv/bin/activate
python3 main.py
# Server runs at http://localhost:8000
# API Docs at http://localhost:8000/docsTerminal 2 (Frontend):
cd frontend
npm run dev
# App runs at http://localhost:3000- Backend Tests: Run
pytestin thebackend/directory. - Linting:
- Backend: Uses
ruff. - Frontend: Uses
eslint.
- Backend: Uses
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.