# Epic 2: Smart Monitoring & Alerts **Status:** πŸ“‹ PLANNED **Phase:** Phase 2 **Duration:** 2 weeks **Priority:** P0 (Critical - Risk Protection) --- ## Epic Overview XΓ’y dα»±ng hệ thα»‘ng monitoring vΓ  alerts thΓ΄ng minh để bαΊ£o vệ users khỏi rα»§i ro vΓ  giΓΊp họ khΓ΄ng bỏ lα»‘ cΖ‘ hα»™i. TαΊ­p trung vΓ o **risk protection** (rug pull detection) vΓ  **opportunity alerts** (whale activity, price movements). **Business Value:** - **Risk Protection:** GiΓΊp users trΓ‘nh mαΊ₯t tiền vΓ o rug pulls - **Opportunity Alerts:** KhΓ΄ng bỏ lα»‘ whale movements vΓ  price spikes - **Always-On Monitoring:** Background monitoring ngay cαΊ£ khi browser Δ‘Γ³ng - **Competitive Advantage:** Proactive alerts vs passive dashboards (DexScreener/DexTools) **Key Differentiator:** AI-driven anomaly detection, khΓ΄ng chỉ lΓ  threshold alerts. --- ## User Stories ### Story 2.1: Real-time Price Alerts **[FR-EXT-07]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** set price alerts cho tokens trong watchlist, **Để** tΓ΄i được notify khi price hit target mΓ  khΓ΄ng cαΊ§n stare vΓ o chart cαΊ£ ngΓ y. **Acceptance Criteria:** - [ ] Watchlist management trong side panel - Add token to watchlist (from DexScreener page) - Remove token from watchlist - View all watchlist tokens - Edit token alerts - [ ] Alert types: - Price above threshold (e.g., > $0.001) - Price below threshold (e.g., < $0.0005) - Price change % (e.g., +20% in 1h) - Volume spike (e.g., 3x average volume) - Liquidity change (e.g., -50% liquidity) - [ ] Browser notifications: - Work even when tab closed - Show token symbol, price, change % - Click notification β†’ Open DexScreener page - [ ] Sound alerts (optional): - Enable/disable per alert - Different sounds for different alert types - [ ] Alert history: - View past alerts - Mark as read/unread **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ πŸ“Š Watchlist (5 tokens) β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ BULLA/SOL $0.0001 +15% β”‚ β”‚ πŸ”” Alert: Price > $0.00015 β”‚ β”‚ [Edit] [Remove] β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ PEPE/ETH $0.000001 -5% β”‚ β”‚ πŸ”• No alerts β”‚ β”‚ [Add Alert] β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ [+ Add Token to Watchlist] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface PriceAlert { id: string; tokenAddress: string; chain: string; alertType: 'above' | 'below' | 'change_percent' | 'volume_spike' | 'liquidity_change'; threshold: number; enabled: boolean; soundEnabled: boolean; lastTriggered?: number; } // Background service worker chrome.alarms.create('checkPriceAlerts', { periodInMinutes: 1 }); chrome.alarms.onAlarm.addListener(async (alarm) => { if (alarm.name === 'checkPriceAlerts') { await checkAllPriceAlerts(); } }); ``` **Backend API:** ``` POST /api/watchlist/add DELETE /api/watchlist/:id GET /api/watchlist POST /api/alerts/create GET /api/alerts/check // Returns triggered alerts ``` **Files:** - `background/alerts/price-alerts.ts` (new) - `sidepanel/watchlist/WatchlistPanel.tsx` (new) - `sidepanel/watchlist/AddAlertModal.tsx` (new) --- ### Story 2.2: Whale Activity Tracker **[FR-EXT-08]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** được notify khi cΓ³ whale buy/sell lα»›n, **Để** tΓ΄i cΓ³ thể follow smart money vΓ  trΓ‘nh bα»‹ dumped. **Acceptance Criteria:** - [ ] Monitor large transactions: - Configurable thresholds: $10K, $50K, $100K - Detect buy vs sell - Show transaction size in USD - [ ] Wallet clustering detection: - Identify same entity (multiple wallets) - Show total holdings across wallets - [ ] Smart money tracking: - Track specific wallet addresses - Alert on their activities - Show their historical performance - [ ] Transaction details: - Wallet address - Transaction hash - Amount (tokens + USD) - Time - Link to explorer - [ ] Notification: - Browser notification for whale activity - Show in side panel feed - Filter by token (only watchlist or all) **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ πŸ‹ Whale Activity β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ 2 min ago β”‚ β”‚ 🟒 BUY $100K BULLA/SOL β”‚ β”‚ Wallet: 0x1234...5678 β”‚ β”‚ Amount: 1B tokens β”‚ β”‚ [View on Explorer] β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ 5 min ago β”‚ β”‚ πŸ”΄ SELL $50K PEPE/ETH β”‚ β”‚ Wallet: 0xabcd...ef01 β”‚ β”‚ ⚠️ Smart Money Wallet β”‚ β”‚ [Track This Wallet] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface WhaleTransaction { id: string; tokenAddress: string; chain: string; type: 'buy' | 'sell'; amountUSD: number; amountTokens: string; walletAddress: string; txHash: string; timestamp: number; isSmartMoney: boolean; } // Poll blockchain for large transactions async function monitorWhaleActivity() { const watchlistTokens = await getWatchlistTokens(); for (const token of watchlistTokens) { const largeTxs = await fetchLargeTransactions(token, threshold); for (const tx of largeTxs) { await notifyWhaleActivity(tx); } } } ``` **Data Sources:** - Solana: Helius API / QuickNode - Ethereum: Etherscan API / Alchemy - Base: BaseScan API **Files:** - `background/alerts/whale-tracker.ts` (new) - `sidepanel/whale/WhaleActivityFeed.tsx` (new) - `lib/blockchain/transaction-monitor.ts` (new) --- ### Story 2.3: Rug Pull Early Warning System **[FR-EXT-09]** **LΓ  mα»™t** crypto trader, **TΓ΄i muα»‘n** được cαΊ£nh bΓ‘o sα»›m về rug pull risks, **Để** tΓ΄i khΓ΄ng mαΊ₯t tiền vΓ o scam tokens. **Acceptance Criteria:** - [ ] Risk indicators monitored: - LP removal (liquidity pulled) - Mint authority changes (can mint more tokens) - Suspicious holder patterns (top 10 holders > 80%) - Contract ownership (not renounced) - Honeypot detection (can't sell) - [ ] Risk score calculation: - 0-3: Low risk (green) - 4-6: Medium risk (yellow) - 7-10: High risk (red) - [ ] Risk score display: - Show on Token Info Card - Update in real-time - Explain each risk factor - [ ] Recommendations: - SAFE: "Low risk, proceed with caution" - CAUTION: "Medium risk, do your own research" - AVOID: "High risk, likely scam" - [ ] Alerts: - Notify when risk score increases - Notify on LP removal - Notify on mint authority changes **UI Design:** ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ ⚠️ RUG PULL WARNING β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Risk Score: 7/10 (High) β”‚ β”‚ β”‚ β”‚ πŸ”΄ LP unlocked (High Risk) β”‚ β”‚ 🟑 Top holder owns 40% β”‚ β”‚ 🟒 Contract verified β”‚ β”‚ 🟒 Mint authority renounced β”‚ β”‚ β”‚ β”‚ Recommendation: AVOID β”‚ β”‚ This token shows signs of β”‚ β”‚ potential rug pull. β”‚ β”‚ β”‚ β”‚ [View Full Analysis] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Technical Implementation:** ```typescript interface RiskAssessment { tokenAddress: string; chain: string; riskScore: number; // 0-10 riskLevel: 'low' | 'medium' | 'high'; indicators: { lpLocked: boolean; lpLockDuration?: number; // days mintAuthority: 'renounced' | 'active' | 'unknown'; topHolderPercent: number; contractVerified: boolean; isHoneypot: boolean; }; recommendation: 'safe' | 'caution' | 'avoid'; explanation: string; timestamp: number; } async function assessRugPullRisk(tokenAddress: string, chain: string): Promise { // Check LP lock status const lpLocked = await checkLPLock(tokenAddress, chain); // Check mint authority const mintAuthority = await checkMintAuthority(tokenAddress, chain); // Check holder distribution const holders = await getTopHolders(tokenAddress, chain); const topHolderPercent = calculateTopHolderPercent(holders); // Check contract verification const contractVerified = await isContractVerified(tokenAddress, chain); // Check honeypot const isHoneypot = await checkHoneypot(tokenAddress, chain); // Calculate risk score const riskScore = calculateRiskScore({ lpLocked, mintAuthority, topHolderPercent, contractVerified, isHoneypot, }); return { tokenAddress, chain, riskScore, riskLevel: getRiskLevel(riskScore), indicators: { lpLocked, mintAuthority, topHolderPercent, contractVerified, isHoneypot, }, recommendation: getRecommendation(riskScore), explanation: generateExplanation(riskScore, indicators), timestamp: Date.now(), }; } ``` **Data Sources:** - LP Lock: RugCheck API, Token Sniffer - Mint Authority: On-chain data (Solana/Ethereum) - Holders: Blockchain explorers - Contract Verification: Etherscan, Solscan - Honeypot: Honeypot.is API **Files:** - `lib/risk/rug-pull-detector.ts` (new) - `sidepanel/risk/RiskScoreCard.tsx` (new) - `background/alerts/risk-monitor.ts` (new) --- ## Technical Dependencies ### Backend APIs ``` POST /api/watchlist/add GET /api/watchlist POST /api/alerts/create GET /api/alerts/check GET /api/whale/transactions GET /api/risk/assess ``` ### External APIs - **Helius API** (Solana transactions) - **Alchemy** (Ethereum transactions) - **RugCheck API** (LP lock status) - **Token Sniffer** (Contract analysis) - **Honeypot.is** (Honeypot detection) ### Chrome APIs - `chrome.alarms` - Periodic checks - `chrome.notifications` - Browser notifications - `chrome.storage` - Watchlist persistence --- ## Testing Strategy ### Unit Tests - [ ] Risk score calculation - [ ] Whale transaction detection - [ ] Alert triggering logic ### Integration Tests - [ ] Price alerts trigger correctly - [ ] Whale activity notifications work - [ ] Risk assessment updates in real-time ### Manual Testing - [ ] Add token to watchlist - [ ] Set price alert and verify notification - [ ] Monitor whale activity on live token - [ ] Check rug pull warning on known scam token --- ## Definition of Done - [ ] All 3 stories completed - [ ] All acceptance criteria met - [ ] Unit tests passing - [ ] Integration tests passing - [ ] Manual testing completed - [ ] External API integrations working - [ ] Code reviewed - [ ] Documentation updated --- ## Notes **Priority Justification:** Risk protection (rug pull detection) is CRITICAL for user trust. Users will not use the product if they lose money to scams. **Next Epic:** Epic 3 - Trading Intelligence (Phase 3)