# Epic 3: Trading Intelligence **Status:** πŸ“‹ PLANNED **Phase:** Phase 3 **Duration:** 2 weeks **Priority:** P1 (High - Value Add) --- ## Epic Overview Cung cαΊ₯p AI-powered trading insights để giΓΊp users make better trading decisions. TαΊ­p trung vΓ o **comprehensive analysis**, **entry/exit suggestions**, vΓ  **portfolio tracking**. **Business Value:** - **Better Decisions:** AI-generated insights giΓΊp users trade smarter - **Time Savings:** One-click analysis thay vΓ¬ hours of research - **Portfolio Management:** Track performance vΓ  optimize holdings - **Competitive Advantage:** AI predictions vs static data (DexScreener/DexTools) **Key Differentiator:** AI-first analysis vα»›i natural language explanations. --- ## User Stories ### Story 3.1: One-Click Token Analysis **[FR-EXT-10]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** analyze token vα»›i mα»™t click, **Để** tΓ΄i cΓ³ comprehensive insights mΓ  khΓ΄ng cαΊ§n research thα»§ cΓ΄ng. **Acceptance Criteria:** - [ ] "Analyze This Token" button trΓͺn Token Info Card - [ ] Comprehensive analysis includes: - **Contract Analysis:** - Verified/unverified - Renounced ownership - Proxy contract detection - Source code availability - **Holder Distribution:** - Top 10 holders percentage - Holder count - Whale concentration - Distribution chart - **Liquidity Analysis:** - Total liquidity (USD) - LP lock status & duration - Liquidity history (7d, 30d) - Liquidity/Market cap ratio - **Trading Volume:** - 24h volume - Volume trend (increasing/decreasing) - Volume/Liquidity ratio - Unusual volume spikes - **Price History:** - All-time high/low - 7d, 30d performance - Price volatility - Support/resistance levels - **Social Sentiment:** - Twitter mentions - Telegram activity - Reddit discussions - Sentiment score (positive/negative/neutral) - [ ] AI-Generated Summary: - 2-3 sentence summary - Key insights highlighted - Risk assessment - Trading recommendation - [ ] Analysis caching: - Cache for 5 minutes - Show "Last updated" timestamp - Refresh button **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ πŸ“Š Token Analysis β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ AI Summary: β”‚ β”‚ "BULLA shows strong holder β”‚ β”‚ distribution with verified β”‚ β”‚ contract. Volume increasing β”‚ β”‚ 200% in 24h. Moderate risk."β”‚ β”‚ β”‚ β”‚ Contract: βœ… Verified β”‚ β”‚ Ownership: βœ… Renounced β”‚ β”‚ β”‚ β”‚ Holders: 1,234 β”‚ β”‚ Top 10: 35% (Good) β”‚ β”‚ β”‚ β”‚ Liquidity: $50K β”‚ β”‚ LP Lock: 90 days β”‚ β”‚ β”‚ β”‚ Volume 24h: $100K (+200%) β”‚ β”‚ Price: $0.0001 (+15%) β”‚ β”‚ β”‚ β”‚ Sentiment: 😊 Positive β”‚ β”‚ Twitter: 500 mentions β”‚ β”‚ β”‚ β”‚ Recommendation: BUY β”‚ β”‚ Confidence: 75% β”‚ β”‚ β”‚ β”‚ [View Full Report] β”‚ β”‚ Last updated: 2 min ago β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface TokenAnalysis { tokenAddress: string; chain: string; timestamp: number; contract: { verified: boolean; renounced: boolean; isProxy: boolean; sourceCode: boolean; }; holders: { count: number; top10Percent: number; distribution: { address: string; percent: number }[]; }; liquidity: { totalUSD: number; lpLocked: boolean; lpLockDuration?: number; history7d: number[]; liquidityMcapRatio: number; }; volume: { volume24h: number; trend: 'increasing' | 'decreasing' | 'stable'; volumeLiquidityRatio: number; spikes: { timestamp: number; volume: number }[]; }; price: { current: number; ath: number; atl: number; change7d: number; change30d: number; volatility: number; supportLevels: number[]; resistanceLevels: number[]; }; social: { twitterMentions: number; telegramActivity: number; redditDiscussions: number; sentimentScore: number; // -1 to 1 sentiment: 'positive' | 'negative' | 'neutral'; }; aiSummary: string; recommendation: 'buy' | 'hold' | 'sell' | 'avoid'; confidence: number; // 0-100 } async function analyzeToken(tokenAddress: string, chain: string): Promise { // Parallel data fetching const [contract, holders, liquidity, volume, price, social] = await Promise.all([ analyzeContract(tokenAddress, chain), analyzeHolders(tokenAddress, chain), analyzeLiquidity(tokenAddress, chain), analyzeVolume(tokenAddress, chain), analyzePrice(tokenAddress, chain), analyzeSocial(tokenAddress, chain), ]); // AI-generated summary const aiSummary = await generateAISummary({ contract, holders, liquidity, volume, price, social, }); return { tokenAddress, chain, timestamp: Date.now(), contract, holders, liquidity, volume, price, social, aiSummary, recommendation: getRecommendation(/* ... */), confidence: calculateConfidence(/* ... */), }; } ``` **Files:** - `lib/analysis/token-analyzer.ts` (new) - `sidepanel/analysis/TokenAnalysisPanel.tsx` (new) - `sidepanel/analysis/AnalysisSummary.tsx` (new) --- ### Story 3.2: Smart Entry/Exit Suggestions **[FR-EXT-11]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** AI suggest entry/exit points, **Để** tΓ΄i maximize profits vΓ  minimize losses. **Acceptance Criteria:** - [ ] Technical analysis: - Support/Resistance levels (3 levels each) - Fibonacci retracement levels - Volume profile analysis - Moving averages (20, 50, 200) - [ ] AI predictions: - Predicted price targets (3 levels) - Time horizon (1h, 4h, 24h) - Confidence score per prediction - [ ] Risk/Reward calculation: - Suggested entry range - Stop loss level - Take profit levels (3 targets) - Risk/Reward ratio - [ ] Visual representation: - Price chart with levels marked - Entry/exit zones highlighted - Risk/reward visualization - [ ] Explanation: - Why these levels? - What signals support this? - What could invalidate this? **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ πŸ’‘ AI Trading Suggestion β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Current Price: $0.00010 β”‚ β”‚ β”‚ β”‚ Entry Zone: 🟒 β”‚ β”‚ $0.00010 - $0.00012 β”‚ β”‚ β”‚ β”‚ Targets: β”‚ β”‚ 🎯 Target 1: $0.00015 (+25%)β”‚ β”‚ 🎯 Target 2: $0.00018 (+50%)β”‚ β”‚ 🎯 Target 3: $0.00022 (+83%)β”‚ β”‚ β”‚ β”‚ Stop Loss: πŸ”΄ β”‚ β”‚ $0.00008 (-20%) β”‚ β”‚ β”‚ β”‚ Risk/Reward: 1:3.3 (Good) β”‚ β”‚ Confidence: 75% β”‚ β”‚ β”‚ β”‚ Why? β”‚ β”‚ β€’ Strong support at $0.0001 β”‚ β”‚ β€’ Volume increasing β”‚ β”‚ β€’ Fibonacci 0.618 at $0.00015β”‚ β”‚ β”‚ β”‚ [View Chart] [Set Alerts] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface TradingSuggestion { tokenAddress: string; chain: string; currentPrice: number; timestamp: number; entry: { min: number; max: number; reasoning: string; }; targets: { level: number; price: number; percentGain: number; confidence: number; }[]; stopLoss: { price: number; percentLoss: number; reasoning: string; }; riskReward: number; overallConfidence: number; technicalLevels: { support: number[]; resistance: number[]; fibonacci: { level: number; price: number }[]; movingAverages: { period: number; price: number }[]; }; reasoning: string[]; invalidationConditions: string[]; } ``` **Files:** - `lib/analysis/trading-suggestions.ts` (new) - `sidepanel/analysis/TradingSuggestionPanel.tsx` (new) --- ### Story 3.3: Portfolio Tracker Integration **[FR-EXT-12]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** track portfolio trong extension, **Để** tΓ΄i biαΊΏt P&L real-time mΓ  khΓ΄ng cαΊ§n mở nhiều tabs. **Acceptance Criteria:** - [ ] Wallet connection: - Support MetaMask, Phantom, Coinbase Wallet - Multi-wallet support - Auto-detect holdings - [ ] Portfolio overview: - Total value (USD) - 24h P&L ($ and %) - All-time P&L - Asset allocation chart - [ ] Holdings list: - Token symbol/name - Amount held - Current value - 24h change - P&L per token - Entry price (if available) - [ ] Performance analytics: - Best/worst performers - Win rate - Average hold time - Total trades - [ ] Quick actions: - Analyze token - Set price alert - View on DexScreener - Sell (link to DEX) **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ πŸ’Ό Portfolio β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Total Value: $5,234 β”‚ β”‚ 24h P&L: +$234 (+4.7%) πŸ“ˆ β”‚ β”‚ β”‚ β”‚ Holdings (5 tokens): β”‚ β”‚ β”‚ β”‚ BULLA/SOL β”‚ β”‚ 1,000,000 tokens β”‚ β”‚ $1,234 (+15%) πŸ“ˆ β”‚ β”‚ [Analyze] [Alert] [Sell] β”‚ β”‚ β”‚ β”‚ PEPE/ETH β”‚ β”‚ 500,000,000 tokens β”‚ β”‚ $2,100 (-5%) πŸ“‰ β”‚ β”‚ [Analyze] [Alert] [Sell] β”‚ β”‚ β”‚ β”‚ [+ Add Manual Position] β”‚ β”‚ β”‚ β”‚ Performance: β”‚ β”‚ Best: BULLA (+15%) β”‚ β”‚ Worst: PEPE (-5%) β”‚ β”‚ Win Rate: 60% β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface Portfolio { wallets: { address: string; chain: string; type: 'metamask' | 'phantom' | 'coinbase'; }[]; totalValue: number; change24h: number; change24hPercent: number; holdings: { tokenAddress: string; chain: string; symbol: string; name: string; amount: string; currentPrice: number; currentValue: number; change24h: number; change24hPercent: number; entryPrice?: number; pnl?: number; pnlPercent?: number; }[]; analytics: { bestPerformer: { symbol: string; change: number }; worstPerformer: { symbol: string; change: number }; winRate: number; avgHoldTime: number; totalTrades: number; }; } ``` **Files:** - `lib/wallet/wallet-connector.ts` (new) - `lib/portfolio/portfolio-tracker.ts` (new) - `sidepanel/portfolio/PortfolioPanel.tsx` (new) --- ## Technical Dependencies ### Backend APIs ``` POST /api/analysis/token GET /api/analysis/suggestions POST /api/portfolio/connect GET /api/portfolio/holdings GET /api/portfolio/analytics ``` ### External APIs - **Blockchain Data:** Helius, Alchemy, QuickNode - **Price Data:** DexScreener API - **Social Data:** Twitter API, LunarCrush - **Technical Analysis:** TradingView indicators ### Wallet Integration - MetaMask SDK - Phantom SDK - Coinbase Wallet SDK --- ## Testing Strategy ### Unit Tests - [ ] Token analysis calculation - [ ] Trading suggestion algorithm - [ ] Portfolio P&L calculation ### Integration Tests - [ ] Wallet connection flow - [ ] Portfolio data fetching - [ ] Analysis generation ### Manual Testing - [ ] Analyze live token - [ ] Connect wallet and view portfolio - [ ] Verify trading suggestions accuracy --- ## Definition of Done - [ ] All 3 stories completed - [ ] All acceptance criteria met - [ ] Unit tests passing - [ ] Integration tests passing - [ ] Manual testing completed - [ ] Wallet integrations working - [ ] Code reviewed - [ ] Documentation updated --- ## Notes **Next Epic:** Epic 4 - Content Creation & Productivity (Phase 4)