All projects

SafetyNet Ai

A marketplace of specialized AI agents that collaborate to protect your DeFi positions across chains. Free monitoring, pay-per-analysis

CRE & AI Risk & Compliance DeFi & Tokenization

What it is

SafetyNet AI                               
                               
 What It Is                                
                                      
 SafetyNet AI is a decentralized risk monitoring system that uses a    
 marketplace of specialized AI agents to protect DeFi positions from    
 liquidation. It combines Chainlink's Compute Runtime Environment (CRE),  
 x402 HTTP micropayments, and OpenAI to deliver automated, pay-per-use
 threat detection for Aave V3 positions on Base Sepolia.

 The Problem

 DeFi liquidations happen in minutes. ETH drops 8%, pool utilization
 spikes to 95%, your health factor collapses — and your position gets
 liquidated while you sleep. Existing monitoring tools are either
 expensive subscriptions, require constant manual checking, or lack the
 analytical depth to distinguish noise from genuine risk. There is no
 free-to-monitor, pay-only-when-threatened system that writes verified
 alerts on-chain.

 How It Works

 1. Free continuous monitoring via Chainlink CRE
 A cron workflow runs every 15 minutes. It reads live Chainlink price
 feeds (ETH/USD, LINK/USD) and Aave pool state directly on-chain, then
 checks for anomalies: price movement >5%, utilization rate >85%, or
 oracle discrepancy >3%. This monitoring costs the user nothing.

 2. Paid AI analysis via x402 micropayments
 When an anomaly is detected, the CRE workflow dispatches two specialist
 AI agents : a Price Agent and a Liquidity Agnt each behind an HTTP 402
  paywall. The agent wallet automatically pays $0.01–$0.02 USDC per agent
 via the x402 protocol (EIP-3009 transfer authorization, settled on Base
 Sepolia by the facilitator). Total cost per full analysis: $0.04 USDC.

 3. Onchain alert storage
 If the aggregated risk score from both agents exceeds 70/100, the CRE
 workflow writes a signed alert to AlertRegistry.sol (deployed at
 0x8c2a7e4Ee53c583b7bC4ca3210ba893CaB4DA538 on Base Sepolia) and sends an
 instant push notification via Pushover.

 4. Real-time dashboard
 A Next.js dashboard connects via SSE to stream agent activity live. Users
  connect their wallet, see their Aave positions, and can manually trigger
  a full crisis simulation watching the x402 payment flow, AI reasoning,
  and risk score appear in real time.

 Chainlink Integration

 - CRE Cron Trigger — schedules the monitoring loop every 15 minutes
 - CRE EVM Read — reads Chainlink ETH/USD and LINK/USD price feeds
 on-chain
 - CRE EVM Write — writes risk alerts to AlertRegistry.sol via CRE signed
 reports
 - CRE HTTP Client — calls the AI agent server endpoints from within the
 workflow

 x402 Integration

 Every AI agent endpoint is protected by an HTTP 402 paywall using
 x402-express. The CRE workflow (and demo simulation) uses x402-fetch to
 automatically handle the 402 challenge signing an EIP-3009 USDC
 transfer authorization, having the facilitator settle it on Base Sepolia,
  then retrying the request. No manual payment UX required.

What Makes It Novel

 Most DeFi alerts are off-chain webhooks with no verifiability. SafetyNet
 AI's alerts are written onchain by a Chainlink CRE workflow
 cryptographically signed, tamper-proof, and readable by any contract or
 frontend. The x402 payment model means the AI infrastructur is
 self-funding: the system only spends compute when there is a credible
 threat, and the cost is borne per-analysis rather than as a flat
 subscription.

How it Works

  1. CRE Workflow (cre/monitor/)
     Built with the @chainlink/cre-sdk TypeScript SDK. The workflow registers
     two triggers a cron trigger (every 15 minutes) and an HTTP trigger
     (manual submissions). The cron callback (cron-callback.ts) orchestrates
     the full monitoring loop: EVM reads via EVMClient.callContract(), HTTP
     calls via HTTPClient.sendRequest(), risk aggregation, and finally
     EVMClient.writeReport() to push the signed alert on-chain. Configuration
     is declared in workflow.yaml and config.staging.json, secrets in
     secrets.yaml.

  2. Smart Contract (contracts/)                      
     Written in Solidity, AlertRegistry.sol extends Chainlink CRE's
     ReceiverTemplate the standard base contract for CRE-writable onchain
     storage. It receives signed reports from the CRE forwarder via onReport()
      → _processReport(), decodes the ABI-encoded payload (alert ID, user
     address, protocol, risk score, reasoning, timestamp), and stores it in a
     mapping. It doubles as the x402 USDC payment receiver so the same
     deployed address handles both roles. Deployed using Foundry (forge
     script) with via_ir enabled to handle OpenZeppelin v5's stack depth
     requirements.

 3. Agent Server (server/src/)
 An Express.js API with three x402-protected endpoints (/analyze/price,
 /analyze/liquidity, /analyze/full) using the x402-express middleware.
 Each endpoint calls OpenAI GPT-4o-mini with a structured system prompt,
 fetches supporting data from CoinGecko and DeFi Llama, and returns a
 riskScore (0–100) with reasoning. The x402-client.ts module wraps
 x402-fetch for outbound payments (used by the demo simulation). A
 Server-Sent Events manager broadcasts agent logs in real time to
 connected dashboards.

 4. Frontend (frontend/)
 Next.js 14 App Router with RainbowKit + Wagmi for wallet connection.
 Reads live Aave V3 position data on-chain via a getUserAccountData
 contract call. Subscribes to the SSE stream via a custom useAnalysisSSE
 hook. The AlertFeed component reads from AlertRegistry.sol directly
 onchain.

Tech Stack

 ┌────────────────┬─────────────────────────────────────────────┐
 │   Layer   │         Technology         │
 ├────────────────┼─────────────────────────────────────────────┤
 │ Orchestration │ Chainlink CRE (TypeScript SDK)       │
 ├────────────────┼─────────────────────────────────────────────┤
 │ Payments    │ x402 (x402-express + x402-fetch)      │
 ├────────────────┼─────────────────────────────────────────────┤
 │ AI       │ OpenAI GPT-4o-mini             │
 ├────────────────┼─────────────────────────────────────────────┤
 │ Smart Contract │ Solidity — AlertRegistry.sol (Base Sepolia) │
 ├────────────────┼─────────────────────────────────────────────┤
 │ DeFi Protocol │ Aave V3                   │
 ├────────────────┼─────────────────────────────────────────────┤
 │ Server     │ Express.js + TypeScript           │
 ├────────────────┼─────────────────────────────────────────────┤
 │ Frontend    │ Next.js 14 + RainbowKit + Wagmi       │
 └────────────────┴─────────────────────────────────────────────┘

Links

Created by

  • Francis