<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DeFi Liquidity Fragmentation Risk Monitor</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #070b12;
--bg-secondary: #0d1420;
--bg-card: #111927;
--border: #1e2d3d;
--text-primary: #e8f0f8;
--text-secondary: #7a8fa6;
--accent-cyan: #00d4ff;
--accent-green: #00ff88;
--accent-orange: #ff9500;
--accent-red: #ff3366;
--accent-purple: #a855f7;
}
body {
font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
.dashboard {
display: grid;
grid-template-columns: 320px 1fr 340px;
grid-template-rows: auto 1fr auto;
gap: 16px;
padding: 16px;
min-height: 100vh;
}
.header {
grid-column: 1 / -1;
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px 24px;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 12px;
}
.header h1 {
font-size: 18px;
font-weight: 600;
letter-spacing: 1px;
background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.header-stats {
display: flex;
gap: 32px;
}
.header-stat {
text-align: center;
}
.header-stat-value {
font-size: 20px;
font-weight: 700;
color: var(--accent-cyan);
}
.header-stat-label {
font-size: 10px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
}
.status-indicator {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 16px;
background: rgba(0, 255, 136, 0.1);
border: 1px solid rgba(0, 255, 136, 0.3);
border-radius: 20px;
}
.status-dot {
width: 8px;
height: 8px;
background: var(--accent-green);
border-radius: 50%;
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(1.2); }
}
.panel {
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
}
.panel-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
justify-content: space-between;
align-items: center;
}
.panel-title {
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-secondary);
}
.panel-content {
padding: 16px;
}
/* Left Panel - Risk Signals */
.risk-panel {
grid-row: 2 / 4;
display: flex;
flex-direction: column;
}
.risk-gauge {
position: relative;
width: 100%;
height: 140px;
margin-bottom: 16px;
}
.gauge-canvas {
width: 100%;
height: 100%;
}
.gauge-value {
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
font-size: 28px;
font-weight: 700;
}
.gauge-label {
position: absolute;
bottom: -5px;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 1px;
}
.risk-metrics {
flex: 1;
overflow-y: auto;
}
.metric-item {
padding: 14px;
margin-bottom: 8px;
background: var(--bg-card);
border-radius: 8px;
border-left: 3px solid var(--accent-cyan);
transition: all 0.3s ease;
}
.metric-item:hover {
transform: translateX(4px);
background: rgba(0, 212, 255, 0.05);
}
.metric-item.critical {
border-left-color: var(--accent-red);
}
.metric-item.warning {
border-left-color: var(--accent-orange);
}
.metric-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.metric-name {
font-size: 11px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.metric-value {
font-size: 16px;
font-weight: 600;
}
.metric-bar {
height: 4px;
background: var(--border);
border-radius: 2px;
overflow: hidden;
}
.metric-bar-fill {
height: 100%;
border-radius: 2px;
transition: width 0.5s ease;
}
/* Center - Network Graph */
.network-panel {
grid-row: 2;
position: relative;
}
.network-canvas {
width: 100%;
height: 100%;
display: block;
}
.network-tooltip {
position: absolute;
padding: 12px 16px;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s ease;
z-index: 100;
max-width: 280px;
}
.network-tooltip.visible {
opacity: 1;
}
.tooltip-title {
font-size: 13px;
font-weight: 600;
margin-bottom: 8px;
color: var(--accent-cyan);
}
.tooltip-row {
display: flex;
justify-content: space-between;
font-size: 11px;
margin-bottom: 4px;
}
.tooltip-label {
color: var(--text-secondary);
}
/* Chain Legend */
.chain-legend {
position: absolute;
bottom: 16px;
left: 16px;
display: flex;
gap: 12px;
padding: 10px 16px;
background: rgba(7, 11, 18, 0.9);
border-radius: 8px;
border: 1px solid var(--border);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 10px;
color: var(--text-secondary);
}
.legend-dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
/* Right Panel - Pool Details & Alerts */
.details-panel {
grid-row: 2;
display: flex;
flex-direction: column;
}
.pool-list {
max-height: 200px;
overflow-y: auto;
}
.pool-item {
padding: 12px;
margin-bottom: 6px;
background: var(--bg-card);
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
border: 1px solid transparent;
}
.pool-item:hover {
border-color: var(--accent-cyan);
background: rgba(0, 212, 255, 0.05);
}
.pool-item.selected {
border-color: var(--accent-cyan);
background: rgba(0, 212, 255, 0.1);
}
.pool-name {
font-size: 12px;
font-weight: 600;
margin-bottom: 4px;
}
.pool-info {
display: flex;
justify-content: space-between;
font-size: 10px;
color: var(--text-secondary);
}
.alerts-container {
flex: 1;
overflow-y: auto;
margin-top: 16px;
}
.alert-item {
padding: 12px;
margin-bottom: 8px;
background: var(--bg-card);
border-radius: 6px;
border-left: 3px solid;
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.alert-item.critical {
border-left-color: var(--accent-red);
background: rgba(255, 51, 102, 0.1);
}
.alert-item.warning {
border-left-color: var(--accent-orange);
background: rgba(255, 149, 0, 0.1);
}
.alert-item.info {
border-left-color: var(--accent-cyan);
background: rgba(0, 212, 255, 0.1);
}
.alert-time {
font-size: 9px;
color: var(--text-secondary);
margin-bottom: 4px;
}
.alert-message {
font-size: 11px;
line-height: 1.4;
}
/* Bottom Panel - Bridge Flows */
.flows-panel {
grid-column: 2 / 4;
}
.flows-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
.flow-card {
padding: 16px;
background: var(--bg-card);
border-radius: 8px;
border: 1px solid var(--border);
transition: all 0.3s ease;
}
.flow-card:hover {
border-color: var(--accent-cyan);
transform: translateY(-2px);
}
.flow-route {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
}
.flow-chain {
font-size: 11px;
font-weight: 600;
padding: 4px 8px;
background: var(--bg-secondary);
border-radius: 4px;
}
.flow-arrow {
color: var(--accent-cyan);
}
.flow-volume {
font-size: 18px;
font-weight: 700;
margin-bottom: 4px;
}
.flow-change {
font-size: 11px;
display: flex;
align-items: center;
gap: 4px;
}
.flow-change.positive {
color: var(--accent-green);
}
.flow-change.negative {
color: var(--accent-red);
}
.flow-latency {
font-size: 10px;
color: var(--text-secondary);
margin-top: 8px;
}
/* Scrollbar styling */
::-webkit-scrollbar {
width: 6px;
}
::-webkit-scrollbar-track {
background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
background: var(--border);
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: var(--text-secondary);
}
@media (max-width: 1400px) {
.dashboard {
grid-template-columns: 280px 1fr 300px;
}
}
@media (max-width: 1200px) {
.dashboard {
grid-template-columns: 1fr;
grid-template-rows: auto auto auto auto auto;
}
.risk-panel {
grid-row: auto;
}
.network-panel {
min-height: 500px;
grid-row: auto;
}
.details-panel {
grid-row: auto;
}
.flows-panel {
grid-column: 1;
}
.flows-grid {
grid-template-columns: repeat(2, 1fr);
}
}
</style>
</head>
<body>
<div class="dashboard">
<header class="header">
<h1>DeFi Liquidity Fragmentation Monitor</h1>
<div class="header-stats">
<div class="header-stat">
<div class="header-stat-value" id="total-tvl">$4.82B</div>
<div class="header-stat-label">Total TVL</div>
</div>
<div class="header-stat">
<div class="header-stat-value" id="active-chains">8</div>
<div class="header-stat-label">Active Chains</div>
</div>
<div class="header-stat">
<div class="header-stat-value" id="pool-count">156</div>
<div class="header-stat-label">Pools Tracked</div>
</div>
</div>
<div class="status-indicator">
<div class="status-dot"></div>
<span style="font-size: 11px;">Live</span>
</div>
</header>
<div class="panel risk-panel">
<div class="panel-header">
<span class="panel-title">Systemic Risk Signals</span>
</div>
<div class="panel-content">
<div class="risk-gauge">
<canvas class="gauge-canvas" id="fragmentation-gauge"></canvas>
<div class="gauge-value" id="frag-value">67</div>
<div class="gauge-label">Fragmentation Index</div>
</div>
<div class="risk-metrics">
<div class="metric-item warning" id="metric-concentration">
<div class="metric-header">
<span class="metric-name">Concentration Risk</span>
<span class="metric-value" style="color: var(--accent-orange)">72%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 72%; background: var(--accent-orange)"></div>
</div>
</div>
<div class="metric-item critical" id="metric-correlation">
<div class="metric-header">
<span class="metric-name">Cross-Chain Correlation</span>
<span class="metric-value" style="color: var(--accent-red)">89%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 89%; background: var(--accent-red)"></div>
</div>
</div>
<div class="metric-item" id="metric-slippage">
<div class="metric-header">
<span class="metric-name">Avg Cross-Chain Slippage</span>
<span class="metric-value" style="color: var(--accent-cyan)">2.4%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 24%; background: var(--accent-cyan)"></div>
</div>
</div>
<div class="metric-item warning" id="metric-bridge">
<div class="metric-header">
<span class="metric-name">Bridge Latency Stress</span>
<span class="metric-value" style="color: var(--accent-orange)">58%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 58%; background: var(--accent-orange)"></div>
</div>
</div>
<div class="metric-item" id="metric-depth">
<div class="metric-header">
<span class="metric-name">Liquidity Depth Score</span>
<span class="metric-value" style="color: var(--accent-green)">81%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 81%; background: var(--accent-green)"></div>
</div>
</div>
<div class="metric-item warning" id="metric-impermanent">
<div class="metric-header">
<span class="metric-name">Impermanent Loss Risk</span>
<span class="metric-value" style="color: var(--accent-orange)">45%</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" style="width: 45%; background: var(--accent-orange)"></div>
</div>
</div>
</div>
</div>
</div>
<div class="panel network-panel">
<div class="panel-header">
<span class="panel-title">Liquidity Network Map</span>
<span style="font-size: 10px; color: var(--text-secondary)">Click nodes to inspect</span>
</div>
<canvas class="network-canvas" id="network-canvas"></canvas>
<div class="network-tooltip" id="network-tooltip">
<div class="tooltip-title">ETH/USDC Pool</div>
<div class="tooltip-row">
<span class="tooltip-label">Chain</span>
<span>Ethereum</span>
</div>
<div class="tooltip-row">
<span class="tooltip-label">TVL</span>
<span>$245.8M</span>
</div>
<div class="tooltip-row">
<span class="tooltip-label">24h Volume</span>
<span>$89.2M</span>
</div>
</div>
<div class="chain-legend">
<div class="legend-item">
<div class="legend-dot" style="background: #627eea"></div>
<span>Ethereum</span>
</div>
<div class="legend-item">
<div class="legend-dot" style="background: #8247e5"></div>
<span>Polygon</span>
</div>
<div class="legend-item">
<div class="legend-dot" style="background: #ff0420"></div>
<span>Optimism</span>
</div>
<div class="legend-item">
<div class="legend-dot" style="background: #28a0f0"></div>
<span>Arbitrum</span>
</div>
<div class="legend-item">
<div class="legend-dot" style="background: #f0b90b"></div>
<span>BNB Chain</span>
</div>
</div>
</div>
<div class="panel details-panel">
<div class="panel-header">
<span class="panel-title">Top Pools by Fragmentation</span>
</div>
<div class="panel-content">
<div class="pool-list" id="pool-list"></div>
<div class="alerts-container" id="alerts-container">
<div class="panel-title" style="margin-bottom: 12px;">Live Alerts</div>
</div>
</div>
</div>
<div class="panel flows-panel">
<div class="panel-header">
<span class="panel-title">Cross-Chain Bridge Flows</span>
<span style="font-size: 10px; color: var(--text-secondary)">Last 24 hours</span>
</div>
<div class="panel-content">
<div class="flows-grid" id="flows-grid"></div>
</div>
</div>
</div>
<script>
// Chain colors
const chainColors = {
'Ethereum': '#627eea',
'Polygon': '#8247e5',
'Optimism': '#ff0420',
'Arbitrum': '#28a0f0',
'BNB': '#f0b90b',
'Avalanche': '#e84142',
'Base': '#0052ff',
'Solana': '#14f195'
};
// Pool data
const pools = [
{ id: 1, name: 'ETH/USDC', chain: 'Ethereum', tvl: 245.8, volume: 89.2, risk: 23, x: 0, y: 0 },
{ id: 2, name: 'ETH/USDT', chain: 'Ethereum', tvl: 198.4, volume: 67.8, risk: 31, x: 0, y: 0 },
{ id: 3, name: 'WBTC/ETH', chain: 'Ethereum', tvl: 312.5, volume: 45.3, risk: 18, x: 0, y: 0 },
{ id: 4, name: 'ETH/USDC', chain: 'Arbitrum', tvl: 89.3, volume: 34.2, risk: 42, x: 0, y: 0 },
{ id: 5, name: 'ETH/USDT', chain: 'Arbitrum', tvl: 67.2, volume: 28.9, risk: 38, x: 0, y: 0 },
{ id: 6, name: 'ARB/ETH', chain: 'Arbitrum', tvl: 45.6, volume: 19.4, risk: 55, x: 0, y: 0 },
{ id: 7, name: 'ETH/USDC', chain: 'Optimism', tvl: 78.4, volume: 29.8, risk: 47, x: 0, y: 0 },
{ id: 8, name: 'OP/ETH', chain: 'Optimism', tvl: 34.2, volume: 15.6, risk: 61, x: 0, y: 0 },
{ id: 9, name: 'ETH/USDC', chain: 'Polygon', tvl: 56.8, volume: 22.4, risk: 52, x: 0, y: 0 },
{ id: 10, name: 'MATIC/USDC', chain: 'Polygon', tvl: 78.3, volume: 31.2, risk: 44, x: 0, y: 0 },
{ id: 11, name: 'ETH/USDT', chain: 'Polygon', tvl: 45.2, volume: 18.7, risk: 49, x: 0, y: 0 },
{ id: 12, name: 'BNB/USDT', chain: 'BNB', tvl: 156.7, volume: 58.3, risk: 36, x: 0, y: 0 },
{ id: 13, name: 'ETH/BNB', chain: 'BNB', tvl: 98.4, volume: 42.1, risk: 41, x: 0, y: 0 },
{ id: 14, name: 'ETH/USDC', chain: 'Base', tvl: 67.9, volume: 24.6, risk: 58, x: 0, y: 0 },
{ id: 15, name: 'AVAX/USDC', chain: 'Avalanche', tvl: 45.3, volume: 19.8, risk: 53, x: 0, y: 0 },
{ id: 16, name: 'SOL/USDC', chain: 'Solana', tvl: 134.6, volume: 78.4, risk: 47, x: 0, y: 0 }
];
// Bridge connections
const bridges = [
{ from: 1, to: 4, flow: 12.4, latency: 8, status: 'healthy' },
{ from: 1, to: 7, flow: 8.7, latency: 6, status: 'healthy' },
{ from: 1, to: 9, flow: 5.2, latency: 12, status: 'warning' },
{ from: 1, to: 12, flow: 15.8, latency: 5, status: 'healthy' },
{ from: 2, to: 5, flow: 7.3, latency: 9, status: 'healthy' },
{ from: 3, to: 6, flow: 4.1, latency: 15, status: 'critical' },
{ from: 4, to: 7, flow: 3.2, latency: 4, status: 'healthy' },
{ from: 7, to: 14, flow: 6.8, latency: 3, status: 'healthy' },
{ from: 9, to: 11, flow: 2.1, latency: 8, status: 'healthy' },
{ from: 4, to: 14, flow: 4.5, latency: 5, status: 'healthy' },
{ from: 1, to: 15, flow: 3.9, latency: 18, status: 'critical' },
{ from: 1, to: 16, flow: 8.2, latency: 22, status: 'warning' }
];
// Alerts
const alerts = [
{ type: 'critical', message: 'Ethereum-Avalanche bridge experiencing high latency (18min). Liquidity rebalancing recommended.', time: '2 min ago' },
{ type: 'warning', message: 'ETH/USDC pool on Optimism showing 47% fragmentation. Consider consolidation.', time: '5 min ago' },
{ type: 'info', message: 'Arbitrum TVL increased by 12% in last hour. New liquidity inflow detected.', time: '12 min ago' },
{ type: 'critical', message: 'Cross-chain correlation at 89% - systemic contagion risk elevated.', time: '18 min ago' },
{ type: 'warning', message: 'Bridge latency stress at 58%. Multi-chain arbitrage opportunities decreasing.', time: '25 min ago' }
];
// Network visualization
class NetworkGraph {
constructor(canvas) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.nodes = [];
this.particles = [];
this.selectedNode = null;
this.hoveredNode = null;
this.animationId = null;
this.resize();
this.initNodes();
this.initParticles();
this.bindEvents();
this.animate();
}
resize() {
const rect = this.canvas.parentElement.getBoundingClientRect();
this.canvas.width = rect.width;
this.canvas.height = rect.height - 50;
this.width = this.canvas.width;
this.height = this.canvas.height;
}
initNodes() {
const chainGroups = {};
pools.forEach(pool => {
if (!chainGroups[pool.chain]) chainGroups[pool.chain] = [];
chainGroups[pool.chain].push(pool);
});
const chains = Object.keys(chainGroups);
const centerX = this.width / 2;
const centerY = this.height / 2;
const radius = Math.min(this.width, this.height) * 0.35;
chains.forEach((chain, i) => {
const angle = (i / chains.length) * Math.PI * 2 - Math.PI / 2;
const chainX = centerX + Math.cos(angle) * radius;
const chainY = centerY + Math.sin(angle) * radius;
chainGroups[chain].forEach((pool, j) => {
const offsetAngle = (j / chainGroups[chain].length) * Math.PI * 2;
const offsetRadius = 40 + j * 15;
pool.x = chainX + Math.cos(offsetAngle) * offsetRadius;
pool.y = chainY + Math.sin(offsetAngle) * offsetRadius;
pool.targetX = pool.x;
pool.targetY = pool.y;
pool.vx = 0;
pool.vy = 0;
pool.radius = Math.max(12, Math.sqrt(pool.tvl) * 1.8);
this.nodes.push(pool);
});
});
}
initParticles() {
bridges.forEach(bridge => {
const fromNode = this.nodes.find(n => n.id === bridge.from);
const toNode = this.nodes.find(n => n.id === bridge.to);
if (fromNode && toNode) {
const count = Math.ceil(bridge.flow / 3);
for (let i = 0; i < count; i++) {
this.particles.push({
from: fromNode,
to: toNode,
progress: Math.random(),
speed: 0.002 + Math.random() * 0.003,
flow: bridge.flow,
status: bridge.status
});
}
}
});
}
bindEvents() {
this.canvas.addEventListener('mousemove', (e) => {
const rect = this.canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
this.hoveredNode = null;
for (const node of this.nodes) {
const dist = Math.hypot(x - node.x, y - node.y);
if (dist < node.radius + 5) {
this.hoveredNode = node;
break;
}
}
this.canvas.style.cursor = this.hoveredNode ? 'pointer' : 'default';
this.updateTooltip(e, x, y);
});
this.canvas.addEventListener('click', () => {
if (this.hoveredNode) {
this.selectedNode = this.hoveredNode;
updatePoolSelection(this.hoveredNode.id);
}
});
window.addEventListener('resize', () => {
this.resize();
this.nodes = [];
this.particles = [];
this.initNodes();
this.initParticles();
});
}
updateTooltip(e, x, y) {
const tooltip = document.getElementById('network-tooltip');
if (this.hoveredNode) {
const node = this.hoveredNode;
tooltip.innerHTML = `
<div class="tooltip-title">${node.name}</div>
<div class="tooltip-row">
<span class="tooltip-label">Chain</span>
<span>${node.chain}</span>
</div>
<div class="tooltip-row">
<span class="tooltip-label">TVL</span>
<span>$${node.tvl}M</span>
</div>
<div class="tooltip-row">
<span class="tooltip-label">24h Volume</span>
<span>$${node.volume}M</span>
</div>
<div class="tooltip-row">
<span class="tooltip-label">Risk Score</span>
<span style="color: ${this.getRiskColor(node.risk)}">${node.risk}%</span>
</div>
`;
tooltip.style.left = `${x + 15}px`;
tooltip.style.top = `${y + 15}px`;
tooltip.classList.add('visible');
} else {
tooltip.classList.remove('visible');
}
}
getRiskColor(risk) {
if (risk < 30) return '#00ff88';
if (risk < 50) return '#ff9500';
return '#ff3366';
}
draw() {
this.ctx.clearRect(0, 0, this.width, this.height);
// Draw grid
this.ctx.strokeStyle = 'rgba(30, 45, 61, 0.3)';
this.ctx.lineWidth = 1;
for (let i = 0; i < this.width; i += 40) {
this.ctx.beginPath();
this.ctx.moveTo(i, 0);
this.ctx.lineTo(i, this.height);
this.ctx.stroke();
}
for (let i = 0; i < this.height; i += 40) {
this.ctx.beginPath();
this.ctx.moveTo(0, i);
this.ctx.lineTo(this.width, i);
this.ctx.stroke();
}
// Draw bridges
bridges.forEach(bridge => {
const fromNode = this.nodes.find(n => n.id === bridge.from);
const toNode = this.nodes.find(n => n.id === bridge.to);
if (fromNode && toNode) {
this.ctx.beginPath();
this.ctx.moveTo(fromNode.x, fromNode.y);
this.ctx.lineTo(toNode.x, toNode.y);
let color = 'rgba(0, 255, 136, 0.15)';
if (bridge.status === 'warning') color = 'rgba(255, 149, 0, 0.2)';
if (bridge.status === 'critical') color = 'rgba(255, 51, 102, 0.2)';
this.ctx.strokeStyle = color;
this.ctx.lineWidth = Math.max(1, bridge.flow / 5);
this.ctx.stroke();
}
});
// Draw particles
this.particles.forEach(particle => {
particle.progress += particle.speed;
if (particle.progress > 1) particle.progress = 0;
const x = particle.from.x + (particle.to.x - particle.from.x) * particle.progress;
const y = particle.from.y + (particle.to.y - particle.from.y) * particle.progress;
let color = '#00ff88';
if (particle.status === 'warning') color = '#ff9500';
if (particle.status === 'critical') color = '#ff3366';
this.ctx.beginPath();
this.ctx.arc(x, y, 2, 0, Math.PI * 2);
this.ctx.fillStyle = color;
this.ctx.fill();
// Glow
const gradient = this.ctx.createRadialGradient(x, y, 0, x, y, 6);
gradient.addColorStop(0, color);
gradient.addColorStop(1, 'transparent');
this.ctx.beginPath();
this.ctx.arc(x, y, 6, 0, Math.PI * 2);
this.ctx.fillStyle = gradient;
this.ctx.fill();
});
// Draw nodes
this.nodes.forEach(node => {
const isHovered = node === this.hoveredNode;
const isSelected = node === this.selectedNode;
const color = chainColors[node.chain];
// Outer glow
if (isHovered || isSelected) {
const glowGradient = this.ctx.createRadialGradient(
node.x, node.y, node.radius,
node.x, node.y, node.radius + 20
);
glowGradient.addColorStop(0, color);
glowGradient.addColorStop(1, 'transparent');
this.ctx.beginPath();
this.ctx.arc(node.x, node.y, node.radius + 20, 0, Math.PI * 2);
this.ctx.fillStyle = glowGradient;
this.ctx.fill();
}
// Risk indicator ring
this.ctx.beginPath();
this.ctx.arc(node.x, node.y, node.radius + 4, 0, Math.PI * 2);
this.ctx.strokeStyle = this.getRiskColor(node.risk);
this.ctx.lineWidth = 2;
this.ctx.stroke();
// Main node
const gradient = this.ctx.createRadialGradient(
node.x - node.radius * 0.3, node.y - node.radius * 0.3, 0,
node.x, node.y, node.radius
);
gradient.addColorStop(0, color);
gradient.addColorStop(1, this.adjustColor(color, -40));
this.ctx.beginPath();
this.ctx.arc(node.x, node.y, node.radius, 0, Math.PI * 2);
this.ctx.fillStyle = gradient;
this.ctx.fill();
// Node border
this.ctx.strokeStyle = isHovered || isSelected ? '#ffffff' : 'rgba(255,255,255,0.3)';
this.ctx.lineWidth = isHovered || isSelected ? 2 : 1;
this.ctx.stroke();
// Pulsing animation for high risk
if (node.risk > 50) {
const pulse = Math.sin(Date.now() * 0.005) * 0.3 + 0.7;
this.ctx.beginPath();
this.ctx.arc(node.x, node.y, node.radius + 8 + Math.sin(Date.now() * 0.003) * 3, 0, Math.PI * 2);
this.ctx.strokeStyle = `rgba(255, 51, 102, ${pulse * 0.3})`;
this.ctx.lineWidth = 2;
this.ctx.stroke();
}
});
}
adjustColor(hex, amount) {
const num = parseInt(hex.replace('#', ''), 16);
const r = Math.max(0, Math.min(255, (num >> 16) + amount));
const g = Math.max(0, Math.min(255, ((num >> 8) & 0x00FF) + amount));
const b = Math.max(0, Math.min(255, (num & 0x0000FF) + amount));
return `#${(1 << 24 | r << 16 | g << 8 | b).toString(16).slice(1)}`;
}
animate() {
this.draw();
this.animationId = requestAnimationFrame(() => this.animate());
}
}
// Fragmentation Gauge
class Gauge {
constructor(canvas, value) {
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.value = value;
this.targetValue = value;
this.resize();
this.animate();
}
resize() {
const rect = this.canvas.parentElement.getBoundingClientRect();
this.canvas.width = rect.width;
this.canvas.height = rect.height;
}
setValue(val) {
this.targetValue = val;
}
getColor(val) {
if (val < 40) return '#00ff88';
if (val < 60) return '#ff9500';
return '#ff3366';
}
draw() {
const width = this.canvas.width;
const height = this.canvas.height;
const centerX = width / 2;
const centerY = height - 10;
const radius = Math.min(width, height) * 0.45;
this.ctx.clearRect(0, 0, width, height);
// Background arc
this.ctx.beginPath();
this.ctx.arc(centerX, centerY, radius, Math.PI, 0, false);
this.ctx.strokeStyle = '#1e2d3d';
this.ctx.lineWidth = 12;
this.ctx.lineCap = 'round';
this.ctx.stroke();
// Value arc
const progress = this.value / 100;
const endAngle = Math.PI + (Math.PI * progress);
const gradient = this.ctx.createLinearGradient(centerX - radius, centerY, centerX + radius, centerY);
gradient.addColorStop(0, '#00ff88');
gradient.addColorStop(0.5, '#ff9500');
gradient.addColorStop(1, '#ff3366');
this.ctx.beginPath();
this.ctx.arc(centerX, centerY, radius, Math.PI, endAngle, false);
this.ctx.strokeStyle = gradient;
this.ctx.lineWidth = 12;
this.ctx.lineCap = 'round';
this.ctx.stroke();
// Tick marks
for (let i = 0; i <= 10; i++) {
const angle = Math.PI + (Math.PI * i / 10);
const innerR = radius - 20;
const outerR = radius - 25;
this.ctx.beginPath();
this.ctx.moveTo(
centerX + Math.cos(angle) * innerR,
centerY + Math.sin(angle) * innerR
);
this.ctx.lineTo(
centerX + Math.cos(angle) * outerR,
centerY + Math.sin(angle) * outerR
);
this.ctx.strokeStyle = '#3a4d5f';
this.ctx.lineWidth = 2;
this.ctx.stroke();
}
// Needle
const needleAngle = Math.PI + (Math.PI * this.value / 100);
const needleLength = radius - 30;
this.ctx.beginPath();
this.ctx.moveTo(centerX, centerY);
this.ctx.lineTo(
centerX + Math.cos(needleAngle) * needleLength,
centerY + Math.sin(needleAngle) * needleLength
);
this.ctx.strokeStyle = this.getColor(this.value);
this.ctx.lineWidth = 3;
this.ctx.lineCap = 'round';
this.ctx.stroke();
// Center dot
this.ctx.beginPath();
this.ctx.arc(centerX, centerY, 8, 0, Math.PI * 2);
this.ctx.fillStyle = this.getColor(this.value);
this.ctx.fill();
}
animate() {
if (Math.abs(this.value - this.targetValue) > 0.5) {
this.value += (this.targetValue - this.value) * 0.1;
}
this.draw();
requestAnimationFrame(() => this.animate());
}
}
// Initialize components
let networkGraph;
let gauge;
function init() {
networkGraph = new NetworkGraph(document.getElementById('network-canvas'));
gauge = new Gauge(document.getElementById('fragmentation-gauge'), 67);
renderPoolList();
renderAlerts();
renderFlows();
startDataSimulation();
}
function renderPoolList() {
const container = document.getElementById('pool-list');
const sortedPools = [...pools].sort((a, b) => b.risk - a.risk).slice(0, 6);
container.innerHTML = sortedPools.map(pool => `
<div class="pool-item" data-id="${pool.id}" onclick="selectPool(${pool.id})">
<div class="pool-name">${pool.name} <span style="color: ${chainColors[pool.chain]}">• ${pool.chain}</span></div>
<div class="pool-info">
<span>TVL: $${pool.tvl}M</span>
<span style="color: ${getRiskColor(pool.risk)}">Risk: ${pool.risk}%</span>
</div>
</div>
`).join('');
}
function getRiskColor(risk) {
if (risk < 30) return '#00ff88';
if (risk < 50) return '#ff9500';
return '#ff3366';
}
function selectPool(id) {
document.querySelectorAll('.pool-item').forEach(el => el.classList.remove('selected'));
document.querySelector(`.pool-item[data-id="${id}"]`)?.classList.add('selected');
if (networkGraph) {
const node = networkGraph.nodes.find(n => n.id === id);
if (node) networkGraph.selectedNode = node;
}
}
function updatePoolSelection(id) {
document.querySelectorAll('.pool-item').forEach(el => el.classList.remove('selected'));
const item = document.querySelector(`.pool-item[data-id="${id}"]`);
if (item) item.classList.add('selected');
}
function renderAlerts() {
const container = document.getElementById('alerts-container');
container.innerHTML = `
<div class="panel-title" style="margin-bottom: 12px;">Live Alerts</div>
${alerts.map(alert => `
<div class="alert-item ${alert.type}">
<div class="alert-time">${alert.time}</div>
<div class="alert-message">${alert.message}</div>
</div>
`).join('')}
`;
}
function renderFlows() {
const container = document.getElementById('flows-grid');
const topFlows = bridges.sort((a, b) => b.flow - a.flow).slice(0, 4);
container.innerHTML = topFlows.map(flow => {
const fromPool = pools.find(p => p.id === flow.from);
const toPool = pools.find(p => p.id === flow.to);
const change = (Math.random() * 20 - 10).toFixed(1);
const isPositive = change > 0;
return `
<div class="flow-card">
<div class="flow-route">
<span class="flow-chain" style="color: ${chainColors[fromPool.chain]}">${fromPool.chain.slice(0, 3)}</span>
<span class="flow-arrow">→</span>
<span class="flow-chain" style="color: ${chainColors[toPool.chain]}">${toPool.chain.slice(0, 3)}</span>
</div>
<div class="flow-volume">$${flow.flow}M</div>
<div class="flow-change ${isPositive ? 'positive' : 'negative'}">
<span>${isPositive ? '↑' : '↓'}</span>
<span>${Math.abs(change)}%</span>
</div>
<div class="flow-latency">Latency: ${flow.latency} min ${flow.status === 'critical' ? '⚠️' : ''}</div>
</div>
`;
}).join('');
}
function startDataSimulation() {
setInterval(() => {
// Update fragmentation index
const newFrag = Math.max(30, Math.min(90, 67 + (Math.random() - 0.5) * 10));
gauge.setValue(newFrag);
document.getElementById('frag-value').textContent = Math.round(newFrag);
// Update metrics
updateMetric('metric-concentration', 72 + (Math.random() - 0.5) * 8);
updateMetric('metric-correlation', 89 + (Math.random() - 0.5) * 5);
updateMetric('metric-slippage', 2.4 + (Math.random() - 0.5) * 0.8, true);
updateMetric('metric-bridge', 58 + (Math.random() - 0.5) * 10);
updateMetric('metric-depth', 81 + (Math.random() - 0.5) * 6);
updateMetric('metric-impermanent', 45 + (Math.random() - 0.5) * 10);
// Update TVL
const tvl = 4.82 + (Math.random() - 0.5) * 0.2;
document.getElementById('total-tvl').textContent = `$${tvl.toFixed(2)}B`;
}, 3000);
// Add new alerts periodically
setInterval(() => {
const newAlerts = [
{ type: 'warning', message: 'Liquidity imbalance detected in ETH/USDC pools across 3 chains.', time: 'Just now' },
{ type: 'info', message: 'New liquidity pool detected on Base chain. Monitoring fragmentation.', time: 'Just now' },
{ type: 'critical', message: 'Sudden TVL drop (-8%) on Polygon bridge. Investigating.', time: 'Just now' }
];
alerts.unshift(newAlerts[Math.floor(Math.random() * newAlerts.length)]);
if (alerts.length > 8) alerts.pop();
renderAlerts();
}, 15000);
}
function updateMetric(id, value, isPercent = false) {
const el = document.getElementById(id);
if (!el) return;
const displayValue = isPercent ? value.toFixed(1) + '%' : Math.round(value) + '%';
el.querySelector('.metric-value').textContent = displayValue;
el.querySelector('.metric-bar-fill').style.width = (isPercent ? value * 10 : value) + '%';
// Update color based on value
const numValue = isPercent ? value * 10 : value;
let color = '#00d4ff';
if (numValue > 70) color = '#ff3366';
else if (numValue > 50) color = '#ff9500';
else if (numValue < 30) color = '#00ff88';
el.querySelector('.metric-value').style.color = color;
el.querySelector('.metric-bar-fill').style.background = color;
// Update class
el.classList.remove('critical', 'warning');
if (numValue > 70) el.classList.add('critical');
else if (numValue > 50) el.classList.add('warning');
}
// Initialize on load
document.addEventListener('DOMContentLoaded', init);
</script>
</body>
</html>