LiqX

LiqX: Autonomous AI agents safeguard Users from liquidation while boosting yields on 95+ protocols.

LiqX

Created At

ETHOnline 2025

Project Description

The DeFi lending market has seen over $1.4 billion lost to liquidations in 2024. Users with leveraged positions on protocols like Aave, Compound, and Morpho face constant risk as markets operate 24/7, but manual monitoring is impractical. Additionally, users often remain locked in suboptimal yield positions, missing out on significantly better APYs available on other protocols or chains.

Our Solution: LiqX employs 4 specialized autonomous agents that work together to:

  1. Position Monitor - Continuously scans blockchain positions via The Graph subgraph, detecting health factors below 1.5 that indicate liquidation risk. Queries positions every 30 seconds with sub-100ms response times.

  2. Yield Optimizer - Analyzes 95+ DeFi lending protocols across Ethereum, Arbitrum, Optimism, Base, and Solana using real-time APY data from DeFi Llama. Uses MeTTa symbolic AI reasoning (not simple rule-based logic) to evaluate strategies based on APY improvement, gas costs, protocol risk scores, break-even time, and cross-chain complexity.

  3. Swap Optimizer - Plans optimal multi-step execution routes using 1inch Fusion+ API, enabling gasless cross-chain swaps where resolvers compete in Dutch auctions to fill orders and pay gas fees on behalf of users.

  4. Cross-Chain Executor - Executes the approved strategy with multi-step transaction coordination: debt repayment, collateral withdrawal, cross-chain bridging (via Wormhole/Stargate/LayerZero), and re-supply to the optimal protocol.

Key Innovations:

  • True AI Reasoning: Unlike competitors using simple if-then rules, we implement MeTTa symbolic AI (Hyperon framework) that provides explainable decision-making with confidence scores (0-100) and detailed reasoning explanations.

  • Gasless Cross-Chain: Integration with 1inch Fusion+ v2.0 SDK enables $0 gas cost swaps for users through competitive resolver networks, making cross-chain rebalancing economically viable even for smaller positions.

  • Multi-Chain Intelligence: We don't just compare protocols on one chain - we analyze opportunities across Ethereum AND Solana ecosystems, finding APY improvements of 80%+ when justified by position size and risk tolerance.

  • Real-Time Coordination: Agents communicate via Fetch.ai's uAgents framework with custom message protocols, enabling complex workflows without centralized coordination.

How it's Made

Architecture & Tech Stack:*

LiqX is built as a distributed multi-agent system with four specialized autonomous agents communicating via Fetch.ai's uAgents framework. Here's the technical breakdown:

  1. Backend Agents (Python)

All four agents run as independent processes with their own HTTP servers for monitoring and their own message queues for inter-agent communication:

Position Monitor (Port 8101):

Integrates with The Graph subgraph deployed on The Graph Studio Custom GraphQL schema indexing Aave V3 Pool events (Borrow, Repay, Liquidation, Supply, Withdraw) Subgraph written in AssemblyScript with custom event handlers Queries execute in <100ms vs 5-10 seconds with direct RPC calls (100x speedup) Real-time price feeds from CoinGecko API for health factor calculations Custom cooldown logic prevents alert spam (5-minute cooldowns per position)

Yield Optimizer (Port 8102):

Fetches from DeFi Llama's /pools endpoint returning 19,560+ pools Custom filtering: lending pools only, excludes staking/liquidity pools Protocol risk scoring based on TVL, age, audit status MeTTa AI Integration: Uses Hyperon Python bindings to run symbolic reasoning MeTTa files (risk_assessment.metta, strategy_selection.metta) define logical rules AI scores strategies 0-100 with explainable reasoning (not black-box ML) Considers: APY delta, break-even time, gas costs, cross-chain complexity, protocol maturity

Swap Optimizer (Port 8103):

Calls 1inch Fusion+ v2.0 API via custom TypeScript service TypeScript service (fusion_plus_service.ts) wraps @1inch/cross-chain-sdk Compiled to JavaScript, called from Python via subprocess Supports EVM→EVM (Ethereum, Arbitrum, Optimism, Base, Polygon) and EVM→Solana Creates multi-step execution plans: repay → withdraw → swap → bridge → supply Gas estimation per step (regular tx: ~150k gas, swaps: ~200k gas)

Cross-Chain Executor (Port 8122):

Currently in simulation mode for testnet safety Production-ready logic for multi-step transaction coordination Supports Wormhole (EVM→Solana), Stargate/LayerZero (EVM→EVM) Realistic timing delays: regular tx (2s), swaps (3s), bridges (10s compressed from 5-10min real) Transaction batching and error recovery with rollback capability

Inter-Agent Communication:

Custom message protocols defined in Pydantic models (PositionAlert, OptimizationStrategy, ExecutionPlan, ExecutionResult) Agents register on Fetch.ai Almanac with deterministic addresses from seeds Message logging with direction tracking (sent/received), timestamp, and detailed payloads Frontend aggregates messages via /api/agents/messages with deduplication logic

  1. Frontend (Next.js 15 + TypeScript)

Server-side rendering for SEO, client-side interactivity for real-time updates SWR for data fetching with automatic revalidation and caching API routes proxy to Python agents (avoiding CORS issues) Real-time WebSocket connections for agent communication feed Recharts for data visualization (health factor trends, price charts, yield comparisons) Framer Motion for smooth animations in demo mode Tailwind CSS for responsive design

  1. The Graph Subgraph (AssemblyScript)

Deployed to The Graph Studio, our subgraph indexes:

Aave V3 Pool contract on Sepolia (0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951) Events: Borrow, Repay, Supply, Withdraw, Liquidation Custom entities: Position, User, Transaction Health factor calculation in event handlers using BigInt arithmetic Automatic sync with 10-second block confirmation delay

  1. 1inch Fusion+ Integration (TypeScript → Python Bridge)

Particularly hacky but elegant solution:

1inch SDK only available in TypeScript Created Node.js service (fusion_plus_service.ts) that exposes CLI interface Python wrapper (fusion_plus_bridge.py) calls compiled JavaScript via subprocess Parses JSON from stdout, handles errors from stderr Enables Python agents to leverage TypeScript-only SDK without separate API server

  1. MeTTa Symbolic AI (Hyperon)

Most innovative component:

MeTTa is not machine learning - it's symbolic reasoning with logic rules .metta files define predicates, functions, and inference rules Example: (evaluate-yield-strategy $protocol $apy $gas $size) evaluates if APY improvement justifies gas cost for position size Returns not just boolean but confidence score + explanation string Fully explainable AI - judges can read the .metta files and understand exact decision logic Differentiator: competitors use simple sorting; we use actual AI reasoning

background image mobile

Join the mailing list

Get the latest news and updates