Skip to content

Boomchainlab/ai-powered-defi-yield-optimizer

Repository files navigation

AI-Powered DeFi Yield Optimizer for Aerodrome Finance

An AI-powered DeFi yield farming optimizer that helps users build personalized portfolio strategies across Aerodrome Finance pools on Base network.

πŸš€ Features

Core Functionality

  • Real-time Pool Data: Fetches live pool data from QuickNode's Aerodrome API
  • AI-Powered Optimization: Uses Claude AI for intelligent portfolio recommendations
  • Risk Assessment: Comprehensive 5-step quiz to determine user risk profile
  • Smart Allocation: Automated portfolio diversification with percentage allocations
  • Detailed Reasoning: AI-generated explanations for each pool recommendation

Pool Analysis

  • Multi-criteria: TVL, APR, and volume analysis
  • Pool Type Support: Stable pairs, volatile pairs, and concentrated liquidity pools
  • Token Verification: Integration with verified token lists for safety
  • Real-time Metrics: Live APR, TVL, and trading volume data

User Experience

  • 3-Step Workflow: Pool overview β†’ Risk assessment β†’ Strategy results
  • Interactive Quiz: Investment amount, risk tolerance, time horizon, and preferences
  • Visual Portfolio: Pie charts and detailed breakdowns of recommendations

πŸ—οΈ Architecture

System Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User Input    β”‚    β”‚   AI Processing  β”‚    β”‚  Pool Data API  β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β”‚ β€’ Risk Quiz     │───▢│  Claude AI API   │◀───│ QuickNode API   β”‚
β”‚ β€’ Preferences   β”‚    β”‚  β€’ Analysis      β”‚    β”‚ β€’ Live Pools    β”‚
β”‚ β€’ Investment $  β”‚    β”‚  β€’ Optimization  β”‚    β”‚ β€’ Token Data    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  β€’ Reasoning     β”‚    β”‚ β€’ Verification  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚ Optimized Strategyβ”‚
                       β”‚                  β”‚
                       β”‚ β€’ Pool Selection β”‚
                       β”‚ β€’ Allocations    β”‚
                       β”‚ β€’ Risk Scores    β”‚
                       β”‚ β€’ Reasoning      β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Architecture

β”œβ”€β”€ app
β”‚   β”œβ”€β”€ api
β”‚   β”‚   └── optimize              # Server-side API route for AI optimization
β”‚   β”œβ”€β”€ globals.css               # Global styles and CSS variables
β”‚   β”œβ”€β”€ layout.tsx                # Root layout with providers and metadata
β”‚   └── page.tsx                  # Main orchestrator component for the 3-phase flow
β”œβ”€β”€ components
β”‚   β”œβ”€β”€ pools
β”‚   β”‚   β”œβ”€β”€ enhanced-pool-card.tsx    # Rich pool data display with metrics
β”‚   β”‚   └── pool-overview.tsx         # Pool grid with sorting and filtering
β”‚   β”œβ”€β”€ quiz
β”‚   β”‚   └── risk-assessment-quiz.tsx  # Multi-step risk profiling interface
β”‚   β”œβ”€β”€ strategy
β”‚   β”‚   └── strategy-results.tsx      # AI-generated strategy visualization
β”‚   β”œβ”€β”€ theme-provider.tsx            # Theme context for dark/light mode
β”‚   └── ui                           # Reusable UI components (shadcn/ui)
β”œβ”€β”€ hooks
β”‚   β”œβ”€β”€ use-mobile.tsx               # Responsive design hook
β”‚   └── use-toast.ts                 # Toast notification system
β”œβ”€β”€ lib
β”‚   β”œβ”€β”€ ai-optimizer.ts              # Claude AI integration and prompt engineering
β”‚   β”œβ”€β”€ api.ts                       # Aerodrome API client and data fetching
β”‚   β”œβ”€β”€ mock-data.ts                 # Fallback data for demo mode
β”‚   β”œβ”€β”€ optimizer.ts                 # Portfolio optimization orchestrator
β”‚   └── utils.ts                     # Utility functions and formatting
β”œβ”€β”€ types
β”‚   β”œβ”€β”€ pool.ts                      # Pool data structures and API responses
β”‚   β”œβ”€β”€ strategy.ts                  # Strategy and risk profile interfaces
β”‚   └── token.ts                     # Token metadata and verification types

πŸ“‹ Prerequisites

Required Accounts & APIs

  1. Anthropic Claude API:

  2. QuickNode Account:

    • Sign up at quicknode.com
    • Subscribe to Aerodrome API add-on
    • Get endpoint URL

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/quiknode-labs/qn-guide-examples.git
cd qn-guide-examples/sample-dapps/ai-powered-defi-yield-optimizer

2. Install Dependencies

pnpm install
# or
npm install

3. Environment Configuration

cp .env.example .env

Edit .env:

# Required for AI optimization
ANTHROPIC_API_KEY=your_claude_api_key_here

# Optional for live data (falls back to demo data)
NEXT_PUBLIC_QUICKNODE_ENDPOINT=https://your-quicknode-endpoint.com/your-api-key/

4. Run Development Server

pnpm dev
# or
npm run dev

Visit http://localhost:3000 to see the application.

5. Production Build

pnpm build
pnpm start

πŸ”§ Configuration Options

Environment Variables

Variable Required Description
ANTHROPIC_API_KEY Yes Claude AI API key for optimization
NEXT_PUBLIC_QUICKNODE_ENDPOINT Yes QuickNode Aerodrome API endpoint

API Endpoints

/api/optimize (POST)

Generates AI-powered portfolio optimization.

Request:

{
  pools: DetailedPool[],
  riskProfile: RiskProfile
}

Response:

{
  success: boolean,
  optimization: {
    recommendations: PoolRecommendation[],
    portfolioSummary: PortfolioMetrics
  },
  usedAI: boolean
}

🎯 Usage Guide

Step 1: Pool Overview

  • Browse real-time Aerodrome pools
  • Filter by pool type, tokens, or characteristics
  • Sort by TVL, APR, or volume
  • Click "Build My Strategy" to start

Step 2: Risk Assessment

Complete the 5-step questionnaire:

  1. Investment Amount: $1,000 - $100,000+
  2. Risk Tolerance: Conservative, Moderate, or Aggressive
  3. Time Horizon: Short (1-3mo), Medium (3-6mo), or Long (6mo+)
  4. Pool Preferences: Stable, Major tokens, Volatile, Concentrated liquidity
  5. Minimum TVL: $100K - $10M+ for liquidity requirements

Step 3: Strategy Results

View your personalized recommendations:

  • Portfolio Overview: Expected APR, risk score, diversification
  • Allocation Chart: Visual breakdown of recommended investments
  • Pool Details: Specific reasoning for each recommendation
  • Implementation Guide: Step-by-step instructions

Getting Help

Releases

No releases published

Packages

 
 
 

Contributors