Cadence Mechanism
What It Is
Cadence is a high-performance, Rust-based monitoring and alerting system designed for real-time DeFi protocol analysis. Its core function is to detect market anomalies, volatility spikes, and other critical events, and to proactively notify the Neko DeFAI Multiagent System.
It is not a passive data pipeline. Instead of providing raw market data, Cadence performs its own sophisticated analysis and sends structured, high-signal alerts only when specific, actionable conditions are met.
Your Benefit
Cadence acts as the nervous system for the Neko agent swarm. It handles the intensive, millisecond-grade task of monitoring market conditions, allowing the DeFAI Multiagent System to focus on high-level strategy, planning, and execution. This separation of concerns ensures the agent remains efficient and can react instantly to critical events without the overhead of constant market scanning.
System Architecture
The integration between Cadence and the Neko agent is event-driven and uses a push-based webhook model, not polling or WebSockets. This ensures minimal latency from detection to action.
Alert Workflow:
Continuous Monitoring: The standalone Cadence system continuously ingests and analyzes real-time data from HyperEVM protocols (AMMs, lending venues) and the Hyperliquid order book. It uses specialized services like
Volatility Monitor,Anomaly Detector, andHealth Score Monitorto score market conditions.Anomaly Detection: When a predefined condition is met (e.g., volatility spikes beyond a threshold, a pool's health score drops), Cadence generates a structured
Alertobject. This object contains the severity, alert type, and a snapshot of relevantpool_metricsat the moment of detection.Webhook Notification: Cadence immediately sends the
Alertobject via an HTTPPOSTrequest to a dedicated endpoint on the agent's API server:POST /webhook/cadence/alertAlert Reception & Triage: The agent's
handle_cadence_alertfunction receives the alert and checks itsseverity.Non-Critical Alerts (
Warning,Info): The alert is logged for auditing and an acknowledgment is sent back to Cadence. No automated action is taken.Critical Alerts (
Critical): The agent immediately escalates the alert for processing by the DeFAI Multiagent System.
Prompt Formatting: For a critical alert, the agent transforms the structured JSON data into a natural language prompt, prefixed with "URGENT ALERT from Cadence monitoring system". This prompt includes all the
pool_metricsprovided by Cadence, which the agent trusts as the real-time state of the market.Example Formatted Query:
URGENT ALERT from Cadence monitoring system: Alert Type: volatility_spike Severity: critical Pool ID: pool_0xffaa4a3d97fe9107cef8a3f48c069f577ff76cc1 Message: Extreme volatility detected in WHYPE/USDC pool - 85% spike Pool Metrics: - Price: $1.8505 - Volume 24h: $1,500,000.00 - Liquidity: $5,000,000.00 - Volatility: 85.00% - Health Score: 3.20 Please analyze this alert and determine if any immediate action is needed...Defensive Workflow Execution: This urgent prompt is passed to the
run_agent_workflow. The system's prompts (PLANNER_SYSTEM_PROMPT,REPLANNER_PROMPT,ACTION_PLANNER_PROMPT) are specifically enhanced to:Prioritize these alerts over standard tasks.
Shift from yield optimization to capital preservation.
Generate a streamlined, time-sensitive plan that may involve immediate liquidity removal or range adjustments.
Execute actions with a higher slippage tolerance (e.g., 1-2%) to ensure transaction success in volatile conditions.

Last updated