Live Protocol Flow · End-to-End
Sonder Protocol
Complete user journey — from deposit & borrowing through autonomous CRE
monitoring to AI-driven liquidation
1
User Onboarding & Collateral Deposit
👤
User
Alice Holds YES Tokens
Alice holds ERC-1155 YES tokens from a Polymarket prediction market (e.g. "DEMS
2028"). Value is locked until market resolution.
🔒
Vault.sol
Deposit Collateral
Alice calls Vault.deposit(tokenId, amount).
The Vault takes custody of her ERC-1155 YES tokens.
📋
MarketRegistry.sol
Market Config Checked
Protocol looks up the market: max LTV 40%, liquidation threshold 45%, liquidation
bonus 8%, resolution deadline enforced.
Collateral secured in Vault
▼
2
Borrowing USDC — Interest Rate Model
💸
LendingPool.sol · borrow()
Alice Borrows USDC
LendingPool reads her Vault balance, reads the current market probability from
PriceOracle, then calculates her max borrow limit: 40% of
collateral value. USDC is transferred to Alice.
📈
Novel: Probability-Based Rate
Interest Rate Calculated
Rate = 5% + (1 − P) × 20%
P=0.90 → 7% (safe collateral)
P=0.65 → 12% (moderate risk)
P=0.10 → 23% (high risk)
Loan active — CRE monitoring begins
▼
3
Chainlink CRE — Autonomous 6-Step Cycle (Every N Minutes)
1
HTTPClient
Fetch Polymarket Price
GET /midpoint?token_id=… → float mid-price converted to 6-decimal
integer. Pulled live from Polymarket CLOB inside the DON — no centralized server.
2
EVMClient
Read On-Chain Price
PriceOracle.getPrice(marketId) → ABI-decode Uint8Array → compute % swing
between fetched and stored price.
3
DON Signed Write
Update Oracle On-Chain
runtime.report() + writeReport() → multi-node DON consensus → broadcasts
updatePrice(). Oracle updated without a single centralized hot wallet.
4
AI Guardian · Gemini Flash 2.0
Anomaly Detection
If swing ≥ 10%: fetch 20 Polymarket community comments → call Gemini API
with Google Search grounding → structured verdict: REAL / NOISE / UNCERTAIN.
5
EVMClient
Health Factor Check
LendingPool.getHealthFactor() for every active borrower. Loops all
positions — no off-chain tracking database needed.
6
Structured Output
Return Report
"price=…, anomaly=1, drop=…%" → watcher.ts reads output → decides whether
to liquidate or monitor.
Health Factor Classification (Step 5 Output)
HF > 1.1 — HealthyNo action.
Continue monitoring.
HF < 1.1 — At RiskFlag
borrower. Send alert email.
HF < 1.0 — LiquidatableTrigger
liquidation pipeline.
watcher.ts reads CRE output
▼
4
AI Guardian — Anomaly Analysis Detail (Triggered by Step
4)
📡
Input Context
Data Assembled
Market ID, current price, previous price, % swing, up to 20 community
comments fetched from Polymarket Gamma API.
🤖
Gemini Flash 2.0 + Google Search
AI Analysis
Real-time web search for related news. Comment sentiment processed. Structured
system prompt forces deterministic JSON output.
📋
JSON Verdict
Structured Decision
verdict: REAL | NOISE | UNCERTAIN
confidence: 0.0 – 1.0
action: LIQUIDATE | MONITOR
sources: [...]
5
Risk Outcomes & Automated Actions
🟢
Position Healthy
HF > 1.1. No action taken. CRE continues its next schedule cycle. Alice's loan
accrues interest normally.
🟡
At-Risk Alert
HF between 1.0–1.1. watcher.ts sends email alert via Resend API.
Alice has time to repay or add collateral.
🔴
Liquidation Triggered
HF < 1.0. watcher.ts calls seizeCollateral() → Vault releases Alice's YES
tokens → debt cleared → email sent.
Normal flow: loan repaid
▼
6
Loan Repayment & Collateral Return
💳
LendingPool.sol · repay()
Alice Repays Debt
Alice calls repay() with USDC covering principal + accrued interest. LendingPool
marks the position as closed.
🔓
Vault.sol · withdraw()
Collateral Released
Vault transfers Alice's YES tokens back to her wallet. Full ERC-1155 collateral
returned on full repayment.
🏆
Market Resolved
Alice Redeems on Polymarket
When the prediction market resolves, Alice redeems her YES tokens for USDC on
Polymarket. She borrowed against her position while waiting.
Smart Contracts (Polygon)