LiquiGuard transforms predatory DeFi liquidations into an automated, self-healing micro-hedge on Somnia. By combining Somnia's sub-100ms finality and 100k+ TPS with DreamDEX's central limit order book (CLOB), LiquiGuard intercepts undercollateralized positions before liquidators can extract value, executing binary
DOWNhedges that automatically repay debt and restore vault health.
- Predatory Liquidations: When market crashes occur, third-party liquidators seize collateral with steep 5% to 15% liquidation penalties.
- Sluggish Block Times (12s): Slow block times prevent automated defense mechanisms from reacting before liquidations trigger.
- Cascading Insolvency: Flash crashes cause cascading liquidations, draining liquidity pools and user funds.
-
Sub-100ms Reactive Sentinel: Leverages Somnia's sub-second block times to detect Health Factor degradation (
$HF < 1.30$ ) within milliseconds. -
DreamDEX Binary Outcome Hedging: Dispatches an Immediate-or-Cancel (IOC)
DOWNorder into DreamDEX's CLOB at entry price $P \approx$0.40$ . -
Automated Self-Healing Payout: Winning hedge payouts ($1.00 - P_{\text{entry}} =
$0.60$ profit per contract) are routed straight intoLiquiGuardVault.executeProtectionHedge(), which invokesMockLendingPool.repay()to restore$HF > 1.50$ with $0 liquidation penalty to the user.
sequenceDiagram
autonumber
actor User as ๐ค User Wallet
participant Vault as ๐ก๏ธ LiquiGuardVault.sol
participant Pool as ๐ฆ MockLendingPool.sol
participant Oracle as ๐ฎ MockPriceOracle.sol
participant Daemon as ๐ก Sentinel Daemon
participant DreamDEX as ๐ DreamDEX CLOB
User->>Vault: Deposit WETH Collateral
Vault->>Pool: Supply WETH & Borrow tUSDC (50% LTV)
Note over Vault,Pool: Initial Health Factor = 1.60 (Safe)
Oracle-->>Pool: Market Crash (ETH Price Drops)
Note over Pool: Health Factor Drops < 1.30 (Critical)
Daemon->>Vault: Poll getHealthFactor(user) (< 100ms)
Daemon->>DreamDEX: Place IOC DOWN Binary Hedge Order
DreamDEX-->>Daemon: Price Drops: DOWN Contract Settles (+$ Payout)
Daemon->>Vault: executeProtectionHedge(user, payoutAmount)
Vault->>Pool: lendingPool.repay(tUSDC, payoutAmount)
Note over Vault,Pool: Health Factor Self-Heals > 1.50 (Protected)
-
$HF \ge 1.50$ : ๐ข SAFE (Normal Operations) -
$1.30 \le HF < 1.50$ : ๐ก WARNING (Volatility Watch) -
$HF < 1.30$ : ๐จ CRITICAL / HEDGE TRIGGER -
$HF \le 1.00$ : โ LIQUIDATION THRESHOLD (Intercepted & Prevented)
To restore the Health Factor from critical (
Given DreamDEX binary contract entry price
All smart contracts are verified and live on Somnia Shannon Testnet (Chain ID: 50312):
| Contract | Address | Explorer |
|---|---|---|
LiquiGuardVault |
0x14b2bb3f8a25301d6ea944d571f0e7608d36c095 |
View on Explorer |
MockLendingPool |
0x96b90274a27d7c933816ae6eae9959b3be05d260 |
View on Explorer |
MockPriceOracle |
0xDD2A460Bfe22BfA7c757A35F6d68813770d39712 |
View on Explorer |
MockERC20 (WETH) |
0x36971ac6e98aafde5c0e2ee8d55abd6c45db8283 |
View on Explorer |
MockERC20 (tUSDC) |
0x734a4b4d43aec0d7d58e3bae6e7b4a8fa253fd5e |
View on Explorer |
- 80-Frame Quantum Prism Sequence: Built with HTML5 Canvas hardware acceleration and cubic ease-out curve, providing an Apple AirPods Pro-style scroll-driven experience.
- Glassmorphic Bento Grid: Real-time radial Health Factor gauge, DreamDEX CLOB order book depth visualizer, and live on-chain event stream.
- Interactive Crash Simulator Arena: Allows hackathon judges to trigger market crashes from
-5%to-35%and observe sub-second on-chain micro-hedging live.
- Node.js:
v18.0.0+ - Foundry:
forge/cast - Python:
3.10+(optional, for frame generation pipeline)
git clone https://github.com/Adityakk9031/liquiguard-somnia.git
cd liquiguard-somnia
npm installcp .env.example .env
# Pre-configured with deployed contract addressescd contracts
forge test -vvvFrom the root directory:
npm run dev- Next.js Web Dashboard: http://localhost:3000
- Sentinel Daemon REST API: http://localhost:3001/api/status
liquiguard-somnia/
โโโ contracts/ # Solidity 0.8.24 Smart Contracts
โ โโโ src/
โ โ โโโ LiquiGuardVault.sol # Core autonomous vault with operator hedge execution
โ โ โโโ MockLendingPool.sol # Aave V2 style pool with liquidation threshold
โ โ โโโ MockPriceOracle.sol # Dynamic oracle with simulator hooks
โ โ โโโ MockERC20.sol # WETH (18 dec) & tUSDC (6 dec) tokens
โ โโโ test/ # Comprehensive Foundry test suites
โ โโโ script/ # Somnia deployment scripts
โโโ daemon/ # TypeScript Sentinel Keeper Service
โ โโโ src/
โ โ โโโ monitor.ts # Real-time Health Factor polling engine
โ โ โโโ executor.ts # DreamDEX IOC order placement & keeper relayer
โ โ โโโ dreamdex.ts # DreamDEX SDK client (Mock + Live GraphQL)
โ โ โโโ store.ts # Fast SQLite & in-memory session cache
โ โ โโโ api.ts # REST API & simulation telemetry endpoints
โโโ frontend/ # Next.js 14 Web Application
โ โโโ src/
โ โ โโโ components/ # Scrollytelling canvas, Bento grid, Gauges
โ โ โโโ lib/ # Wagmi, Viem, Somnia chain configs
โ โ โโโ app/ # Layout, pages, and Tailwind styling
โโโ scripts/ # Frame extraction and AI video generation tools
- Track: DeFi & Infrastructure
- Network Alignment: Demonstrates how Somnia's unique sub-100ms finality makes previously impossible financial primitives (like automated micro-hedging before liquidation) a reality on-chain.
MIT License. Built with โค๏ธ for the Somnia Network Ecosystem.