LiquidityGuard
DeFi insurance protecting Curve LPs & Aave from stablecoin depegs with verifiable claims
Problem Statement
LiquidityGuard is a decentralized insurance protocol that protects DeFi users from two critical stablecoin-related risks:Stablecoin Depeg Protection for Curve LPs: Protects liquidity providers in Curve Finance stablecoin pools (e.g., USDC/USDF) against losses when stablecoins deviate from their $1.00 peg. Users can insure their LP positions and receive automated payouts when depegs occur.Liquidation Cascade Protection for Aave Borrowers: Protects borrowers on Aave from liquidation events triggered by stablecoin collateral depegging (e.g., PYUSD). When a collateral asset depegs, the health factor drops, potentially causing liquidation-our insurance covers these losses.The Problem: Stablecoins are exploding in both supply and yield opportunities. Today, you can lock in 15%+ APY on stablecoins like Falcon USD (USDf), or even 30%+ with leveraged loops. But chasing these yields can just as easily wipe your deposit. Real Case: USDf Depeg - July 8, 2025 On July 8, 2025, Falcon USD (USDf) experienced a catastrophic depeg event.Liquidation Cascade Risk for Aave Borrowers: When stablecoin collateral (e.g., PYUSD) depegs, borrowers' health factors drop below liquidation thresholds, triggering forced position closures with liquidation penalties (~5-13% loss). This creates a domino effect as cascading liquidations further depeg the asset.Our Solution: LiquidityGuard provides two types of insurance coverage:Stablecoin Depeg Protection for Curve LPs:Protects liquidity providers in Curve stablecoin pools (e.g., USDf/USDC) against losses when stablecoins deviate from their $1.00 pegDuring the July 8 USDf crisis, insured LPs would have received automatic payouts covering up to 90% of their lossesCoverage includes liquidity freeze scenarios where exiting becomes impossible.Liquidation Cascade Protection for Aave Borrowers:Protects borrowers using stablecoin collateral (e.g., PYUSD) from liquidation events triggered by depegsWhen collateral depegs, health factors drop, causing forced liquidations with 5-13% penaltiesOur insurance covers these liquidation losses.How it works:Users browse available insurance pools and get instant premium quotesThey purchase policies by minting an NFT on-chain that represents their coverageA separate validator service monitors prices in real-time (using on-chain pool data and oracle price)When depeg or liquidation events occur, users submit claimsThe validator cryptographically signs claim payouts using EIP-712 signaturesUsers redeem these signatures on-chain to receive USDC payouts from the reserve poolReal-Time Monitoring System:Validator monitors pool reserves every 60 seconds using dual oracles (Chainlink + Pyth)Detects liquidity anomalies: When USDC reserves drop below 33% of total pool (like the 6:00 AM USDf signal)15-minute grace period: Filters noise while catching sustained depegsAutomatic depeg window opening: Records exact timestamps when reserve ratio breaches thresholdIPFS evidence capture: Uploads pool snapshots for cryptographic proofPayout calculation: Analyzes maximum loss during depeg windowEIP-712 signing: Validator cryptographically signs claim payoutsOn-chain settlement: Users submit signatures to smart contracts for USDC payoutsKey features:Coverage caps (90% for LP depeg, 10% for Aave liquidation)5% deductible to reduce moral hazard24-hour cliff period to prevent front-runningDynamic risk-based pricing with pool state classification (Red/Yellow/Green zones)Claim queueing system when reserves are under stress (>80% utilization)Multiple oracle support (Chainlink primary, Pyth fallback)What Makes Us Different:Provable Claims: All payouts require validator-signed EIP-712 messages with IPFS-anchored evidence. You don't trust us—you verify the math cryptographically.Real-Time Detection: Our validator caught the USDf depeg at 6:18 AM when reserves hit 33%, 1 hour before major lossesDual-Oracle Security: Chainlink primary + Pyth fallback (400ms latency) prevents oracle manipulationDynamic Risk Pricing: Premiums automatically increase 25-40% when pools enter danger zones (reserve ratio < 33-38%)Claim Queue System: When reserve utilization >80%, claims queue FIFO to prevent bank runsNo False Alarms: 15-minute sustained breach required (not flash crashes)For Liquidity Providers (Reserve Depositors):Deposit USDC into our reserve poolReceive lgUSD share tokens representing fractional ownershipEarn yield from premiums collected (like earning from the 1-2% APR premiums users pay) (in future versions)Share protocol risk/reward with 7-day lock periodWithdraw anytime after lock expires (or queue if reserves are stressed)
Solution
Smart Contracts (Solidity 0.8.28 + Hardhat) Core Contracts:PolicyNFT: ERC-721 representing insurance policies with transfer locks until expiration. Tracks claim history and supports two product types (Curve LP, Aave liquidation).ReservePool: Capital vault with NAV-based share pricing: sharePrice = (assets - pendingClaims - pendingRedemptions) / totalSupply. Features FIFO queues for claims/redemptions during liquidity stress, 80% buffer enforcement, and strategy manager integration.PolicyDistributor: Purchase gateway validating backend-signed EIP-712 quotes. Routes premiums to ReservePool with automatic 2% protocol fee.PayoutModule: Claim verification engine. Validates validator signatures, oracle anchor timestamps (depeg windows), and enforces coverage caps before settlement.OracleAnchors: Immutable registry storing depeg windows (like July 8, 6:18-9:45 AM), TWAP values, and IPFS snapshot CIDs.Key Innovations:Multi-domain EIP-712 signatures prevent cross-context reuseFIFO Queue Settlement processes claims without expensive array operationsTransfer-Locked NFTs prevent front-running depegsNAV Liability Tracking prevents reserve runs during mass claimsDeployment: Base Sepolia with OpenZeppelin 5.0.2 security primitivesValidator Service - Real-Time Monitoring (TypeScript + ClickHouse)The 24/7 monitoring backend that would have caught USDf depeg 1 hour before major losses.Tech Stack: ClickHouse: Time-series database (1,440 samples/day, sub-100ms queries) Grafana: Real-time dashboards with PagerDuty phone alerts Chainstack: Archive node access for historical analysis Dual Oracles: Chainlink primary + Pyth fallback (400ms latency)Detection Algorithm: Polls every 60 seconds to calculate:Reserve Ratio: rBps = (USDC / (USDC + USDf)) × 10,000 Threshold: 3,300 bps (33%) triggers alert July 8, 6:18 AM: Breached at 33% - Detection pointSwap Quote Simulation: Tests actual exit via get_dy(500K_USDf) 6:00 AM: -0.1% loss 7:18 AM: -0.5% loss (validator detected 1h earlier) 30-min TWAP: Smooths flash crashes, prevents manipulationState Machine: NORMAL → [rBps < 3300] → BREACHED (6:18 AM) → [sustained 15 min] → DEPEG_ACTIVE (6:33 AM, emit webhook) → [rBps ≥ 3300] → RESOLVED (9:45 AM)July 8 Timeline: 6:18 AM: Reserve ratio hits 33% → Validator detects 6:33 AM: 15-min grace ends → PagerDuty calls phone + IPFS snapshot uploaded 7:18 AM: Users hit 0.5% losses (detected 1h early) 9:45 AM: Recovery → DEPEG_END webhookClaim Signing: // Payout formula: severity = max(lossQuoteBps - deductibleBps, 0) payout = (coverageCap × 9000 × severity) / 100,000,000// July 8 example: $500K insured, 10% loss, 5% deductible // Payout: ($450K × 9000 × 500) / 100M = $20,250 Returns EIP-712 signed payload with nonce for on-chain redemption.Backend API (Fastify + PostgreSQL) Dynamic Pricing Engine: premium = baseValue × baseRate × stressMultiplier// Stress multipliers based on reserve ratio: RED (r_bps < 3300): 1.4× multiplier (+40% premium) YELLOW (r_bps < 3800): 1.25× (+25%) GREEN (r_bps ≥ 3800): 1.0× (base rate)// Prevents adverse selection: Users can't buy cheap insurance during depegsKey Features: Policy drafts with 1-hour expiry Two-phase commit (draft → on-chain mint → finalize) HMAC-authenticated validator webhooks Claim coordination (preview → sign → settle) PostgreSQL schema: policies, drafts, claims, anchorsFrontend (Next.js 14 + wagmi + viem) Real-Time Risk UI: Pool status indicators: 🟢 GREEN / 🟡 YELLOW / 🔴 RED with live reserve ratios Dynamic premiums: Updates instantly when pool state changes Historical depeg viewer: Shows the July 8 event with an annotated timeline Liquidity charts: Recharts visualization matching Grafana dashboardsKey Pages: Dashboard: Purchase insurance with live risk warnings My Insurances: Real-time policy status + pool health Claims: Preview payouts with depeg window visualizationSmart Contract Integration: // Purchase flow:GET /v1/pools → Check current pool risk statusPOST /v1/policies → Get EIP-712 signed quoteUSDC.approve() → PolicyDistributor.buyPolicy()POST /finalize → Link on-chain NFT to backend// Claim flow:GET /v1/claim/preview → Calculate payoutPOST /v1/claim/sign → Get validator signaturePayoutModule.executeClaim() → Receive USDCJuly 8, 2025 Outcome Uninsured User: Loss: $50,000 (10% depeg) Stuck for 24 hours with no exitInsured User: Premium: $821 (30-day policy) Loss: $50,000 (10%) Deductible: $25,000 (5%) Payout: $20,250 Net Loss: $29,750 (5.95%) vs $50,000 Saved: $20,250 (40% reduction)System Performance: Detected at 6:18 AM (r_bps = 3300) Phone alert at 6:33 AM (15-min grace) Users had 1 hour before 0.5% losses 0 false positives in 12-month backtest
Hackathon
ETHOnline 2025
2025
Contributors
- craterface77
3 contributions