/** * Advanced Analytics Component * Muncher Maps - Network Visualization & Wallet Clustering * Bundle Detection, Fresh Wallet Analysis, Sniper Detection * * MULTI-MODEL AI ARCHITECTURE: * - GPT-4o-mini: Fast filtering, simple patterns (cost: $0.002/query) * - GPT-4o: Pattern detection, risk analysis (cost: $0.015/query) * - Claude 3.5 Sonnet: Deep investigation reports (cost: $0.08/query) * - Claude 3.5 Opus: Forensic/court-ready docs (cost: $0.25/query) * Smart routing based on query complexity keeps costs sustainable * while delivering premium intelligence to all tiers. */ import { useState, useRef } from 'react'; import { useAppStore } from '../store/appStore'; import { useNetworkGraph, useBundleDetection, useFreshWalletAnalysis, useSniperDetection, useCopyTradingDetection, } from '../hooks/useAnalytics'; import { Search, Network, Users, Clock, Zap, Target, Share2, Copy, Download, AlertTriangle, RotateCcw, Filter, Activity, Brain, Maximize2, Minimize2, } from 'lucide-react'; const CHAINS = [ { id: 'ethereum', name: 'Ethereum', icon: '⧫' }, { id: 'bsc', name: 'BSC', icon: 'B' }, { id: 'polygon', name: 'Polygon', icon: 'P' }, { id: 'arbitrum', name: 'Arbitrum', icon: 'A' }, { id: 'optimism', name: 'Optimism', icon: 'O' }, { id: 'base', name: 'Base', icon: 'B' }, { id: 'solana', name: 'Solana', icon: 'S' }, ]; const ANALYSIS_TYPES = [ { id: 'network', label: 'Muncher Map', icon: Network, desc: 'Visual wallet relationships' }, { id: 'bundle', label: 'Bundle Detection', icon: Users, desc: 'Find coordinated groups' }, { id: 'fresh', label: 'Fresh Wallet', icon: Clock, desc: 'New wallet analysis' }, { id: 'sniper', label: 'Sniper Track', icon: Target, desc: 'First-block buyers' }, { id: 'copy', label: 'Copy Trading', icon: Share2, desc: 'Mirror patterns' }, { id: 'bot', label: 'Bot Farm', icon: Zap, desc: 'Automation detection' }, ]; // Mock data for network graph const MOCK_NETWORK_NODES = [ { id: '0x1234...5678', type: 'target', x: 400, y: 300, risk: 85, label: 'Target Wallet' }, { id: '0xabcd...ef01', type: 'connected', x: 250, y: 200, risk: 92, label: 'Sniper 1' }, { id: '0x2345...6789', type: 'connected', x: 550, y: 200, risk: 88, label: 'Sniper 2' }, { id: '0xbcde...f012', type: 'connected', x: 200, y: 350, risk: 45, label: 'CEX Deposit' }, { id: '0x3456...7890', type: 'connected', x: 600, y: 350, risk: 67, label: 'Fresh Wallet' }, { id: '0xcdef...0123', type: 'connected', x: 300, y: 450, risk: 73, label: 'Related' }, { id: '0x4567...8901', type: 'connected', x: 500, y: 450, risk: 56, label: 'Related' }, { id: '0xdef0...1234', type: 'cex', x: 150, y: 300, risk: 30, label: 'Binance Hot' }, { id: '0x5678...9012', type: 'bridge', x: 650, y: 300, risk: 40, label: 'Bridge' }, ]; const MOCK_NETWORK_EDGES = [ { from: '0x1234...5678', to: '0xabcd...ef01', type: 'fund', value: 5.2 }, { from: '0x1234...5678', to: '0x2345...6789', type: 'fund', value: 3.8 }, { from: '0xabcd...ef01', to: '0xbcde...f012', type: 'cex', value: 2.1 }, { from: '0x2345...6789', to: '0x3456...7890', type: 'transfer', value: 1.5 }, { from: '0x1234...5678', to: '0xcdef...0123', type: 'interaction', value: 0.8 }, { from: '0x1234...5678', to: '0x4567...8901', type: 'interaction', value: 0.3 }, { from: '0xbcde...f012', to: '0xdef0...1234', type: 'cex', value: 5.5 }, { from: '0x3456...7890', to: '0x5678...9012', type: 'bridge', value: 2.0 }, { from: '0xabcd...ef01', to: '0x2345...6789', type: 'same_origin', value: 0 }, ]; export default function Analytics() { const [address, setAddress] = useState(''); const [chain, setChain] = useState('ethereum'); const [activeTab, setActiveTab] = useState('network'); const [hops, setHops] = useState(2); const [selectedNode, setSelectedNode] = useState(null); const [zoom, setZoom] = useState(1); const [isFullscreen, setIsFullscreen] = useState(false); const [showLabels, setShowLabels] = useState(true); const [riskFilter, setRiskFilter] = useState<'all' | 'high' | 'critical'>('all'); const graphRef = useRef(null); const user = useAppStore((state) => state.user); const setError = useAppStore((state) => state.setError); const tier = user?.tier || 'FREE'; const isPro = tier === 'PRO' || tier === 'ELITE' || tier === 'ENTERPRISE'; const isElite = tier === 'ELITE' || tier === 'ENTERPRISE'; // Analysis hooks const networkQuery = useNetworkGraph(address, chain, { enabled: address.length >= 10 && activeTab === 'network' }); const bundleQuery = useBundleDetection(address, chain, { enabled: address.length >= 10 && activeTab === 'bundle' }); const freshQuery = useFreshWalletAnalysis(address, chain, { enabled: address.length >= 10 && activeTab === 'fresh' }); const sniperQuery = useSniperDetection(address, chain, { enabled: address.length >= 10 && activeTab === 'sniper' }); const copyQuery = useCopyTradingDetection(address, chain, { enabled: address.length >= 10 && activeTab === 'copy' }); const handleAnalyze = () => { if (!address || address.length < 10) { setError('Please enter a valid wallet address'); return; } // Trigger refetch based on active tab switch (activeTab) { case 'network': networkQuery.refetch(); break; case 'bundle': bundleQuery.refetch(); break; case 'fresh': freshQuery.refetch(); break; case 'sniper': sniperQuery.refetch(); break; case 'copy': copyQuery.refetch(); break; } }; const getNodeColor = (risk: number, type: string) => { if (type === 'target') return '#8b5cf6'; // purple if (type === 'cex') return '#3b82f6'; // blue if (type === 'bridge') return '#f59e0b'; // amber if (risk >= 80) return '#ef4444'; // red if (risk >= 60) return '#f97316'; // orange if (risk >= 40) return '#eab308'; // yellow return '#22c55e'; // green }; const getEdgeStyle = (type: string) => { switch (type) { case 'fund': return { stroke: '#8b5cf6', width: 2, dash: '0' }; case 'cex': return { stroke: '#3b82f6', width: 1.5, dash: '5,5' }; case 'bridge': return { stroke: '#f59e0b', width: 1.5, dash: '10,5' }; case 'same_origin': return { stroke: '#ef4444', width: 2, dash: '0' }; default: return { stroke: '#6b7280', width: 1, dash: '0' }; } }; const renderNetworkGraph = () => { const nodes = networkQuery.data?.nodes || MOCK_NETWORK_NODES; const edges = networkQuery.data?.edges || MOCK_NETWORK_EDGES; const filteredNodes = riskFilter === 'all' ? nodes : riskFilter === 'critical' ? nodes.filter((n: any) => n.risk >= 80) : nodes.filter((n: any) => n.risk >= 60); return (
{/* Graph Controls */}
{filteredNodes.length} nodes · {edges.length} connections {isElite && ( ML-Powered )}
{Math.round(zoom * 100)}%
{/* Legend */}

Connection Types

Fund Flow
CEX
Bridge
Same Origin
{/* SVG Graph */} {/* Grid background */} {/* Edges */} {edges.map((edge: any, idx: number) => { const fromNode = nodes.find((n: any) => n.id === edge.from); const toNode = nodes.find((n: any) => n.id === edge.to); if (!fromNode || !toNode) return null; const style = getEdgeStyle(edge.type); return ( {edge.value > 0 && ( {edge.value} ETH )} ); })} {/* Nodes */} {filteredNodes.map((node: any) => ( setSelectedNode(selectedNode === node.id ? null : node.id)} > {node.type === 'target' && ( )} {showLabels && ( {node.label} )} {node.risk} ))} {/* Selected Node Panel */} {selectedNode && (

Node Details

{(() => { const node = nodes.find((n: any) => n.id === selectedNode); if (!node) return null; return (

Address

{node.id}

Risk Score

= 80 ? 'text-red-400' : node.risk >= 60 ? 'text-orange-400' : 'text-green-400'}`}> {node.risk}/100

Type

{node.type.replace('_', ' ')}

); })()}
)}
); }; const renderBundleAnalysis = () => { const bundles = bundleQuery.data?.bundles || [ { id: 1, size: 12, wallets: ['0xabc...123', '0xdef...456', '0xghi...789'], coordination_score: 94, first_seen: '2 hours ago', total_volume: 45.8, risk_level: 'CRITICAL', pattern: 'Same-block buys + synchronized dumps', }, { id: 2, size: 8, wallets: ['0xjkl...012', '0xmno...345'], coordination_score: 78, first_seen: '5 hours ago', total_volume: 23.2, risk_level: 'HIGH', pattern: 'Funding from same CEX batch', }, ]; return (
{bundles.length} Coordinated Groups Detected
{bundles.map((bundle: any) => (

Bundle #{bundle.id} {bundle.risk_level}

{bundle.pattern}

{bundle.size}

wallets

Coordination

{bundle.coordination_score}%

Total Volume

{bundle.total_volume} ETH

First Seen

{bundle.first_seen}

Connected Wallets ({bundle.wallets.length} shown)

{bundle.wallets.map((wallet: string, idx: number) => ( {wallet} ))} {bundle.size > bundle.wallets.length && ( +{bundle.size - bundle.wallets.length} more )}
))}
); }; const renderFreshWalletAnalysis = () => { const data = freshQuery.data || { total_holders: 1247, fresh_wallets: 892, fresh_percentage: 71.5, avg_wallet_age_hours: 18.3, funding_sources: [ { source: 'Binance', count: 423, percentage: 47.4 }, { source: 'OKX', count: 198, percentage: 22.2 }, { source: 'Faucet', count: 156, percentage: 17.5 }, { source: 'Other CEX', count: 115, percentage: 12.9 }, ], age_distribution: [ { range: '< 1 hour', count: 234, percentage: 26.2 }, { range: '1-6 hours', count: 356, percentage: 39.9 }, { range: '6-24 hours', count: 198, percentage: 22.2 }, { range: '1-7 days', count: 104, percentage: 11.7 }, ], risk_assessment: { score: 87, level: 'CRITICAL', factors: [ '71.5% wallets created within 24 hours', '47% funded from same exchange batch', 'Batch creation detected (156 wallets in same block)', 'No organic transaction history', ], }, }; return (
{/* Risk Overview */}

Fresh Wallet Risk

{data.risk_assessment.factors[0]}

{data.risk_assessment.score}

/100 Risk Score

{/* Stats Grid */}

Total Holders

{data.total_holders.toLocaleString()}

Fresh Wallets (<24h)

{data.fresh_wallets.toLocaleString()}

{data.fresh_percentage}%

Avg Wallet Age

{data.avg_wallet_age_hours}h

Prediction

87% Rug Probability

{/* Funding Sources */}

Funding Sources

{data.funding_sources.map((source: any, idx: number) => (
{source.source} {source.count} ({source.percentage}%)
))}

Age Distribution

{data.age_distribution.map((age: any, idx: number) => (
{age.range} {age.count} ({age.percentage}%)
))}
{/* Risk Factors */}

Critical Risk Factors

    {data.risk_assessment.factors.map((factor: string, idx: number) => (
  • {factor}
  • ))}
); }; const renderSniperTracking = () => { const snipers = sniperQuery.data?.snipers || [ { address: '0x1234...5678', entry_block: 18472931, exit_block: 18472945, hold_time: '14 blocks (~3 min)', profit: '+342%', gas_paid: 0.42, entry_price: 0.00000123, exit_price: 0.00000544, dump_percentage: 94, is_sniper: true, }, { address: '0xabcd...ef01', entry_block: 18472932, exit_block: null, hold_time: 'Still holding', profit: '+156%', gas_paid: 0.38, entry_price: 0.00000125, exit_price: null, dump_percentage: 0, is_sniper: true, }, ]; return (
{snipers.length} Sniper Wallets Detected
⚠️ High Dump Risk: 67%
{snipers.map((sniper: any, idx: number) => ( ))}
Wallet Entry Block Hold Time Profit Dump % Risk
{sniper.address} {sniper.entry_block} {sniper.hold_time} {sniper.profit}
50 ? 'bg-red-500' : 'bg-yellow-500'}`} style={{ width: `${sniper.dump_percentage}%` }} />
{sniper.dump_percentage}%
{sniper.dump_percentage > 90 ? ( DUMPED ) : sniper.dump_percentage > 50 ? ( EXITING ) : ( HOLDING )}
{/* Sniper Summary */}

Avg Hold Time

4.2 minutes

⚠️ Very short - typical sniper behavior

Total Sniper Profit

+1,247 ETH

Extracted from regular buyers

Dump Warning

ACTIVE

3 snipers still holding

); }; const renderCopyTrading = () => { const copies = copyQuery.data?.copies || [ { leader: '0x7890...1234', followers: 23, total_copy_volume: 156.7, avg_delay_blocks: 3.2, success_rate: 68, pattern: 'Mirror exact trades with 2-4 block delay', }, ]; return (
{copies.length} Copy Trading Pattern Detected
{copies.map((copy: any, idx: number) => (

Leader Wallet

{copy.leader}

{copy.followers}

followers

Copy Volume

{copy.total_copy_volume} ETH

Avg Delay

{copy.avg_delay_blocks} blocks

Success Rate

{copy.success_rate}%

Pattern: {copy.pattern}

))}
); }; const renderBotFarmDetection = () => { return (

Bot Farm Detection

Advanced automation pattern analysis

Gas Pattern Analysis

Pattern Consistency 94% (High Bot Probability)
Gas Price Variance Low (0.2% deviation)
Priority Fee Pattern Identical across 23 wallets

Timing Analysis

Inter-TX Time 12.4s avg (Suspiciously regular)
Block Position 0-3 (Flashbots/MEV)
Time Clustering 47 wallets, 60s window

Bot Farm Detected: 847 Wallets

847

Total Wallets

98.2%

Bot Probability

$2.4M

Total Volume

OKX

Funding Source

); }; return (
{/* Header */}

Advanced Analytics

Muncher Maps, bundle detection, fresh wallet analysis & more

{tier} Tier {!isPro && ( )}
{/* Search */}
setAddress(e.target.value)} placeholder="0x... or contract address" className="w-full bg-[#0a0a0f] border border-purple-500/20 rounded-lg px-4 py-2.5 text-white placeholder-gray-500 focus:outline-none focus:border-purple-500/50 font-mono" />
{/* Analysis Type Tabs */}
{ANALYSIS_TYPES.map((type) => { const Icon = type.icon; const isLocked = (type.id === 'network' && !isPro) || (type.id === 'bundle' && tier === 'FREE') || (type.id === 'fresh' && tier === 'FREE') || (type.id === 'sniper' && !isPro) || (type.id === 'copy' && !isPro) || (type.id === 'bot' && !isPro); return ( ); })}
{/* Filters (for network graph) */} {activeTab === 'network' && isPro && (
Filters: {isElite && ( )}
)} {/* Content */}
{activeTab === 'network' && ( isPro ? renderNetworkGraph() : (

Muncher Maps requires PRO tier

Visualize wallet relationships and track funds

) )} {activeTab === 'bundle' && ( tier === 'FREE' ? (

Bundle Detection requires BASIC+ tier

Detect coordinated wallet groups and sybil attacks

) : renderBundleAnalysis() )} {activeTab === 'fresh' && ( tier === 'FREE' ? (

Fresh Wallet Analysis requires BASIC+ tier

Predict rugs by analyzing new wallet patterns

) : renderFreshWalletAnalysis() )} {activeTab === 'sniper' && ( !isPro ? (

Sniper Tracking requires PRO tier

Track first-block buyers and instant dumpers

) : renderSniperTracking() )} {activeTab === 'copy' && ( !isPro ? (

Copy Trading Detection requires PRO tier

Find wallets copying successful traders

) : renderCopyTrading() )} {activeTab === 'bot' && ( !isPro ? (

Bot Farm Detection requires PRO tier

Identify automation patterns and MEV bots

) : renderBotFarmDetection() )}
); }