Health Score Engine
How Aquarius computes, interprets, and caches deterministic health scores with AI-augmented context.
The Health Engine is the foundation layer of the Aquarius intelligence stack. It converts raw protocol state into structured, interpretable risk scores that drive every downstream system — escalation logic, agent decisions, action dispatch, and user-facing risk displays.
Two independent scores are produced:
Both scores are deterministic, reproducible, and auditable. The optional AI layer interprets but never controls.
For Aave validation, the Health Engine is now chain-aware end-to-end.
ethereum, polygonethereum400)This prevents cross-chain cache bleed and ensures every score reflects the selected chain context.
| Layer | Responsibility | Latency | Required |
|---|---|---|---|
| Layer 1 | Weighted risk computation from on-chain signals | < 10ms | Yes |
| Layer 2 | Regime classification, dominant risk identification, bounded score adjustment | < 8s | No |
| Layer 3 | Stress simulation via Tenderly (future) | Variable | No |
Layer 1 always runs and always produces a valid score. Layer 2 may adjust the score within strict bounds. If Layer 2 fails for any reason — API timeout, invalid response, missing credentials — the system falls back to the Layer 1 result with zero downtime.
Layer 1 computes a composite health score from four normalized risk dimensions. Each dimension is scored 0–100 (higher = more risk).
| Dimension | Weight | Signal Source |
|---|---|---|
| Liquidation Risk | 30% | Proximity of positions to liquidation thresholds |
| Volatility | 25% | Health factor pressure and price movement exposure |
| Liquidity Risk | 25% | Market concentration and utilization depth |
| Smart Contract / Governance Risk | 20% | Debt-to-collateral ratio and protocol parameter stability |
Formula:
Score = 100 - Σ(weight_i × risk_dimension_i)
The result is clamped to 0–100 and rounded to the nearest integer.
| Score Range | Category | Meaning |
|---|---|---|
| 75–100 | Stable | All risk dimensions within safe bounds |
| 50–74 | Watch | Elevated risk in one or more dimensions — monitoring advised |
| 0–49 | High Risk | Significant risk detected — mitigation may be required |
These bands are used consistently across the protocol health score, user health score, and the downstream escalation engine.
The protocol-level score assesses the aggregate risk posture of a protocol across all tracked positions on a chain.
Pipeline:
Chain is part of the protocol-health cache key and source path, so Ethereum and Polygon produce independent score timelines.
Response shape:
interface ProtocolHealthScore {
protocol: string;
score: number; // 0–100
category: HealthCategory; // "stable" | "watch" | "high_risk"
confidence: number; // 0–1
breakdown: {
liquidity: number; // 0–100 (inverted: higher = healthier)
riskConcentration: number;
liquidationRisk: number;
smartContractRisk: number;
};
reasoning: string;
regime?: MarketRegime; // "normal" | "elevated" | "stressed"
dominantRisk?: string;
metadata: {
block: number | null;
timestamp: string; // ISO-8601
sources: string[];
};
}Confidence is derived from sample size and signal clarity. A larger position sample and stronger signal agreement produce higher confidence.
The user-level score assesses a specific wallet's position risk. It uses a penalty-based model built on the health factor.
Pipeline:
Base - Penalties, clamped 0–100User health now resolves on-chain position data by selected chain. If a wallet has no active position on the selected chain, the route returns a chain-specific not-found response rather than falling back to another chain.
Health factor normalization:
| Health Factor | Base Score |
|---|---|
| <= 1.0 | 0 |
| 1.5 | 50 |
| 2.0 | 75 |
| >= 3.0 | 100 |
Penalty model:
| Penalty | Trigger | Max Impact |
|---|---|---|
| Volatility | HF slope < -0.1 (declining trajectory) | Up to 15 points |
| Concentration | Largest collateral asset > 70% of total | Variable |
| Correlation | Collateral assets are price-correlated (e.g., ETH + stETH) | 5 points |
Response shape:
interface UserHealthScore {
user: string;
protocol: string;
score: number;
category: HealthCategory;
confidence: number;
base: number; // HF-derived base before penalties
penalties: {
volatility: number;
concentration: number;
correlation: number;
};
reasoning: string;
regime?: MarketRegime;
dominantRisk?: string;
metadata: HealthScoreMetadata;
}The AI Context Engine is an interpretive layer that sits on top of the deterministic score. It does not recompute risk — it contextualizes it.
Capabilities:
normal, elevated, or stressed based on the combination of risk dimensionsSafety guarantees:
| Constraint | Enforcement |
|---|---|
| Maximum adjustment | ±10 points from deterministic base |
| Score bounds | Clamped 0–100 after adjustment |
| Category derivation | Always re-derived from adjusted score, never from LLM output |
| Schema validation | Strict JSON schema check on every LLM response |
| Fallback | Any failure (timeout, invalid response, missing API key) returns deterministic score |
The AI layer uses Groq (llama-3.3-70b-versatile) with temperature: 0 for deterministic inference. A hard timeout of 8 seconds prevents the AI layer from blocking the pipeline.
AI Never Controls
The AI context layer enhances interpretation. It does not control escalation, agent decisions, or action dispatch. If the AI layer is unavailable, the system operates at full capacity on deterministic logic alone.
The Health Engine feeds structured context into the agent decision layer. The agent receives:
{
healthScore: number,
riskDimensions: RiskInputs,
dominantRisk: string,
escalationStage: "info" | "confirm" | "invalidate",
convergenceSignals: string[],
stressTestResults?: StressScenario[],
volatilityRegime: MarketRegime
}Agent decisions are stage-aware:
| Escalation Stage | Agent Behavior |
|---|---|
| INFO | Observe only — no mitigation actions |
| CONFIRM | Protect — dispatch bounded mitigation (partial repay, collateral top-up) |
| INVALIDATE | Escalate — emergency action, circuit breaker, alert escalation |
The agent may also fall back to composite threshold logic if escalation state is unavailable. The separation is clear:
Health scores are cached in-memory to prevent redundant recomputation on every request.
| Score Type | TTL | Rationale |
|---|---|---|
| Protocol Health | 30 seconds | Protocol state changes slowly relative to polling |
| User Health | 10 seconds | User positions can shift with each block |
The cache uses a simple TTL-based eviction strategy with no external dependencies (no Redis required). Entries are lazily evicted on read.
For chain-aware routing, cache keys include chain context:
protocol:{protocol}:{chain}user:{address}:{protocol}:{chain}The Health Score is the entry point for the entire downstream pipeline. Without it, escalation has no signal, the agent has no context, and execution has no trigger.
Deterministic Core
The full deterministic path — from on-chain state to agent decision — completes in under 100ms. The AI context layer runs asynchronously and never blocks the critical path.