Defi-portfolio-manager
AI-powered DeFi portfolio manager using Chainlink oracles & Gemini on Base.
What it is
AutoPortfolio is an autonomous DeFi portfolio management system that continuously monitors, analyzes, and rebalances your crypto holdings — without any manual intervention.
The Problem Most retail crypto investors set up a portfolio and forget it. Over time, winning assets grow overweight while others shrink, silently increasing risk and drifting far from the investor's original strategy. Manually rebalancing requires constant market monitoring, emotional discipline, and technical knowledge that most people simply don't have. Institutional traders solve this with algorithmic systems — but those tools have never been accessible to everyday DeFi users.
What AutoPortfolio Does AutoPortfolio brings institutional-grade automated rebalancing to anyone with a MetaMask wallet. You connect your wallet, define your target allocations (e.g. 50% ETH, 30% BTC, 20% USDC), and the system handles everything from there — 24 hours a day, 7 days a week, fully on-chain.
How It Works The system runs a four-stage autonomous pipeline. First, Chainlink Data Streams deliver cryptographically verified, tamper-proof live prices for every asset in your portfolio. Second, the Chainlink Runtime Environment (CRE) Workflow Engine continuously checks whether any asset has drifted more than 5% from its target weight — and fires a trigger when action is needed. Third, Google Gemini AI receives the full portfolio context and reasons about the best rebalancing action, returning a structured decision with confidence scoring and plain-English reasoning. Finally, if the confidence threshold is met and all safety checks pass, the approved swap executes on Base Sepolia via Uniswap V3 and is permanently recorded on-chain.
Why It Matters Every decision is verifiable, every execution is auditable, and your assets never leave your custody. AutoPortfolio is the first system to combine Chainlink's trust-minimized oracle infrastructure with LLM-powered reasoning to create a portfolio manager that is simultaneously autonomous, transparent, and safe.
How it Works
AutoPortfolio is built as a full-stack Web3 application using modern JavaScript tooling, decentralized infrastructure, and AI APIs — all working together as a single cohesive system.
Frontend The interface is built with Next.js 14 using the App Router and TypeScript for type safety throughout. The UI is written entirely in React with custom inline styles and CSS animations — no UI library dependencies — giving full control over the dark futuristic aesthetic. Wallet connectivity is handled directly via the EIP-1193 MetaMask API using wallet_requestPermissions to always prompt explicit user approval.
Backend & API Layer Next.js API routes serve as the serverless backend. The /api/prices route fetches live ETH, BTC, and USDC prices from CoinGecko, structured to mirror the Chainlink Data Streams feed format. The /api/analyze route sends portfolio state to the Gemini 1.5 Flash API and parses the structured JSON response containing rebalancing decisions, confidence scores, and reasoning.
Chainlink Integration Chainlink Data Streams provide the price oracle layer, delivering cryptographically signed asset prices verified by the Decentralized Oracle Network. The Chainlink Runtime Environment (CRE) acts as the automation backbone — an event-driven workflow engine that monitors drift thresholds and triggers the rebalancing pipeline only when genuinely needed, avoiding unnecessary on-chain activity.
AI Reasoning Google Gemini 1.5 Flash is integrated via the Gemini API. The model receives a structured prompt containing current prices, target allocations, drift percentages, and market context. It returns a JSON object with a recommended action, per-asset trade instructions, a confidence score, and a natural language explanation — making every AI decision fully explainable.
Smart Contract Execution Trade execution happens on Base Sepolia, an Ethereum Layer 2 network chosen for its low gas costs and EVM compatibility. Swaps route through Uniswap V3, with every transaction hash recorded and verifiable on Basescan.
Safety Architecture Four independent safety layers run before any trade executes: a minimum 75% AI confidence threshold, a maximum 0.5% slippage guard, a 4-hour cooldown period between rebalancing events, and a human override that lets the wallet owner cancel any operation at any time.
Deployment The application is deployed on Vercel using serverless functions for the API layer, with environment variables securing all API keys. The repository is version-controlled on GitHub with a full CI/CD pipeline — every push to main triggers an automatic production deployment.
Links
Created by
- Divyansh Gautam
- Vaibhwi Kumari