Search projects, hackathons, sponsors and tech

    ← All projects

    edgraph

    Autonomous depeg coverage: AI buys evidence when justified, transparent rules recommend approval.

    Demo

    About

    EdGraph is an autonomous stablecoin depeg coverage system that detects potential depeg events, autonomously purchases additional evidence using HBAR micropayments, and uses an AI agent to evaluate the evidence and decide claim outcomes. Traditional insurance and coverage systems face three major problems: detection is slow, evidence is difficult to verify, and claim decisions are often opaque. EdGraph approaches the problem differently by giving an AI agent the ability to autonomously investigate and resolve claims while keeping its actions bounded by transparent, predefined policy rules. The core idea is simple: AI detects the opportunity, decides whether evidence is worth paying for, purchases the evidence, evaluates it against the policy, and decides the claim outcome. A user first connects their HashPack wallet and creates a coverage policy. The policy defines the covered stablecoin, depeg threshold, required duration, payout amount, and maximum evidence budget. These terms are registered through the Policy API into EdGraph's PolicyRegistry.sol smart contract on Hedera, creating an immutable on-chain reference for the coverage conditions and the maximum amount the AI can spend on evidence. Once a policy is active, EdGraph continuously monitors market conditions. A background Monitoring Worker queries The Graph for Base market data every 60 seconds and stores timestamped observations in SQLite. The Candidate Detector analyzes these observations to identify potential depeg events. It checks whether the price has remained below the policy threshold for the required duration, whether the observation window is complete, and whether there are significant monitoring gaps. When a potential claim is detected, the AI Claims Agent takes over the investigation. The first decision the agent makes is whether additional evidence is worth purchasing. It reads a live Graph risk snapshot containing information such as current price, liquidity, liquidity changes, and trading volume. Instead of blindly purchasing evidence for every potential claim, the agent performs a cost-benefit decision: "Is this event significant enough that I should spend HBAR to investigate it further?" If the agent determines that deeper evidence is justified, it autonomously purchases the evidence through x402 micropayments. The AI calls EdGraph's Evidence API, which responds with HTTP 402 Payment Required and specifies the required HBAR payment. The agent creates and signs a partial HBAR transfer, while the Blocky402 facilitator co-signs as the fee payer and submits the transaction to Hedera. Once the payment is verified, the Evidence API returns the requested evidence. The evidence contains deeper market information retrieved through The Graph, including historical prices, pool liquidity, swap activity, volume information, and provenance metadata such as the query hash, block range, and deployment ID. The AI Claims Agent then uses this evidence to evaluate the claim. Instead of relying purely on an LLM's subjective judgment, the agent is provided with transparent policy rules as guardrails. These rules describe the conditions that must be satisfied, such as the required depeg threshold, minimum duration, evidence completeness, provenance requirements, and allowed evidence budget. The AI reasons over the evidence while remaining constrained by the policy defined by the user. The agent ultimately produces one of three outcomes: - ELIGIBLE — the evidence satisfies the coverage policy and the claim qualifies for payout. - INELIGIBLE — the evidence does not demonstrate that the policy conditions were satisfied. - NEEDS_HUMAN_REVIEW — the agent encounters an ambiguous, anomalous, or suspicious situation that should be escalated rather than resolved automatically. The important distinction is that the AI itself makes the final claim decision. The deterministic policy logic provides transparent constraints and structured checks, but the agent is responsible for interpreting the evidence, combining the available information, and deciding the outcome. Every step is recorded in SQLite, including market observations, claim state, the AI's evidence-purchase decision, x402 payment information, Hedera transaction hashes, Graph provenance, evidence reports, policy checks, and the final AI decision. This creates a complete audit trail showing what the AI observed, what it purchased, how much it spent, what evidence it received, and why it reached its final outcome. EdGraph therefore creates an autonomous coverage loop: Detect → Decide → Pay → Verify → Evaluate → Resolve The system also demonstrates multi-chain coordination without requiring a bridge. Base provides access to liquid DeFi markets, The Graph provides indexed and verifiable market data, while Hedera provides the policy registry and HBAR settlement layer. The result is an insurance-like system where AI autonomously pays for the information it needs and uses that information to make bounded, auditable claim decisions.

    How it's made

    EdGraph is built as a full-stack TypeScript monorepo using Scaffold-HBAR as the foundation, with custom services for The Graph integration, AI agents, x402 micropayments, policy management, and autonomous claim evaluation. The architecture is designed around a single autonomous agent loop. The monitoring infrastructure identifies potential events, while the AI Claims Agent handles the investigation and final claim decision. On-chain policy rules act as transparent constraints that bound what the agent can do. 1. Policy Registry Coverage policies are implemented through PolicyRegistry.sol, written in Solidity 0.8.28 and deployed on Hedera testnet. Each policy stores the covered stablecoin, depeg threshold in basis points, minimum depeg duration, payout amount, and maximum evidence budget in tinybars. Users connect HashPack and create policies through the Policy API. The policy is then registered on-chain through the Hedera smart contract. This gives the AI agent a reliable source of truth for the coverage terms and establishes a hard upper limit on how much HBAR it can spend on evidence. The application mirrors these policies into SQLite for efficient monitoring and claim processing, while the on-chain contract remains the authoritative policy registry. 2. The Graph Monitoring Layer EdGraph uses The Graph as its market observation and evidence layer. A custom GraphQL client queries a Uniswap V3 USDC/WETH pool on Base approximately every 60 seconds. The Monitoring Worker retrieves the pool information, calculates the current price, and stores timestamped observations in SQLite. The price calculation handles Uniswap V3's sqrtPriceX96 Q64.96 fixed-point representation. EdGraph converts the value into a human-readable USD price while accounting for token decimal differences and using BigInt to avoid JavaScript floating-point precision problems. Each observation can also retain Graph provenance information such as the query hash, block range, and deployment ID. This gives the AI agent access to both current market conditions and verifiable historical data. 3. Candidate Detection The Candidate Detector continuously analyzes the accumulated observations. It checks whether there are enough observations, whether the observations are complete, whether prices remain below the policy threshold, whether the required duration has been reached, and whether there are monitoring gaps larger than the permitted interval. For example, if a policy requires the stablecoin to remain below $0.98 for 30 minutes, the detector verifies that the observed price stayed below that threshold throughout the required window. If there is a significant data gap, the system does not simply assume that the missing period satisfies the condition. Once the conditions indicate a potential depeg event, the detector creates a POTENTIAL_CLAIM and passes it to the AI Claims Agent. 4. AI Claims Agent The AI Claims Agent is the core of EdGraph. It is an autonomous Node.js service responsible for both evidence acquisition and claim resolution. The agent first receives the potential claim and obtains a live Graph risk snapshot containing the current price, liquidity, liquidity changes, and trading volume. It then decides whether purchasing deeper evidence is justified. For example, a potential depeg accompanied by a significant liquidity drop and unusual trading volume may cause the agent to determine that additional evidence is valuable. Conversely, if the event appears to be a weak or temporary signal, the agent can avoid spending the evidence budget. Before making a purchase, the agent checks the maximum evidence budget defined by the on-chain policy. This creates an important safety boundary: - The AI can decide how to investigate, but it cannot exceed the spending limit defined by the policy. - After purchasing the evidence, the agent receives the detailed report and evaluates it against the policy. The agent is given structured policy constraints such as: - required depeg threshold - minimum duration - required evidence fields - provenance requirements - liquidity anomaly conditions - maximum evidence budget - payout amount The deterministic policy logic provides these rules as structured checks and guardrails. The AI then reasons over the evidence and determines the final outcome. This means the AI is not simply returning an unconstrained LLM answer. It operates within a clearly defined policy boundary while retaining the ability to reason over multiple pieces of evidence. 5. x402 Micropayment Flow EdGraph uses x402 to allow the AI agent to purchase evidence on demand. When the agent requests deeper evidence, the Evidence API responds with: 402 Payment Required The response specifies the required HBAR payment and payment information. The AI agent then creates a partial Hedera TransferTransaction and signs it using its ECDSA key. The transaction is sent to the Blocky402 facilitator, which verifies the buyer's signature, co-signs as the fee payer, and submits the transaction to Hedera. The facilitator does not receive unrestricted control over the buyer's funds. It can only co-sign the transaction that the AI agent has already authorized. Once the payment is confirmed, the Evidence API returns the requested evidence. Payment amounts are represented in tinybars rather than floating-point HBAR values. Since one HBAR equals 100,000,000 tinybars, this avoids precision problems when constructing transactions. Every successful payment produces a Hedera transaction hash, which is stored in SQLite as part of the claim's audit trail. 6. Evidence API The EdGraph Evidence API acts as a paid evidence service. After receiving a verified x402 payment, it performs deeper queries against The Graph. The resulting evidence report can contain: - historical price observations - depeg duration - pool liquidity - liquidity changes - swap activity - trading volume - Graph query information - block ranges - deployment identifiers - evidence timestamps This transforms The Graph from simply being a data source into a verifiable evidence layer that the AI can purchase on demand. The AI therefore does not need to permanently consume expensive or deep data queries. It can pay for additional evidence only when a potential claim justifies the cost. 7. AI Policy Evaluation After receiving the evidence, the AI Claims Agent evaluates the complete claim. The policy rules are exposed to the agent as deterministic constraints. For example, the agent can verify: Depeg condition: Did the stablecoin remain below the required threshold? Duration condition: Did the depeg persist for the required amount of time? Evidence condition: Does the purchased evidence contain the required information? Provenance condition: Can the evidence be traced to the expected Graph deployment and block range? Anomaly condition: Are there unusual liquidity or market conditions that make the result ambiguous? The AI combines these structured checks with the actual evidence and makes the final decision. The outcome is: ELIGIBLE when the evidence supports the claim, INELIGIBLE when the policy conditions are not satisfied, or NEEDS_HUMAN_REVIEW when the situation is too ambiguous or anomalous for safe autonomous resolution. The normal path is therefore fully autonomous. Human review is not the approval mechanism. It is only an exception mechanism. Particularly Hacky / Notable 1. Autonomous evidence purchasing The most important feature is that the AI agent does not simply consume unlimited data. It makes an economic decision about whether evidence is worth purchasing. This turns the AI into an active economic participant rather than a passive chatbot. 2. AI-driven claim resolution The AI Claims Agent is responsible for the complete investigation lifecycle. It can detect the significance of an event, purchase additional evidence, interpret the evidence, apply policy constraints, and decide the final claim outcome. The deterministic rules provide guardrails, while the AI provides the reasoning. 3. Hedera-native x402 EdGraph uses native HBAR rather than ERC-20 payments for its x402 evidence marketplace. The payment flow uses Hedera's partial-signature model, where the AI authorizes the transfer and Blocky402 acts as the fee payer. This allows an autonomous agent to pay for a service without giving the facilitator unrestricted access to its funds. 4. Uniswap V3 price calculation EdGraph calculates prices from Uniswap V3's sqrtPriceX96 Q64.96 representation. The system must carefully handle BigInt precision, token decimal differences, and fixed-point conversion to produce accurate prices. 5. Continuous depeg validation The Candidate Detector does not simply look for a single price below the threshold. It validates a continuous observation window and rejects windows containing gaps larger than the permitted interval. This prevents monitoring failures from being incorrectly interpreted as sustained depeg events. 6. On-chain AI spending limits The maximum evidence budget is part of the policy stored on Hedera. This means the AI agent cannot arbitrarily increase its spending allowance through an application configuration change. The policy defines the economic boundary within which the autonomous agent operates. 7. Multi-chain coordination without a bridge EdGraph observes Base DeFi markets, uses The Graph as its indexed data layer, and uses Hedera for policy registration and HBAR settlement. The system therefore coordinates activity across ecosystems without requiring a token bridge for its core evidence-payment workflow. 8. Complete auditability Every major action can be traced through the system: Market observation → potential claim → AI decision → x402 payment → Hedera transaction → Graph evidence → AI evaluation → claim outcome This gives the autonomous system an auditable history instead of relying on an opaque AI response. Partner Technologies The Graph provides the market observation and evidence layer. EdGraph uses GraphQL queries to monitor Base liquidity pools and retrieve deeper historical evidence when the AI purchases it. Hedera provides the immutable policy registry and HBAR settlement layer. Coverage terms and evidence budgets are anchored on-chain, while x402 payments settle using native HBAR. Blocky402 provides the x402 facilitator infrastructure. It verifies the AI agent's payment authorization, provides the network fee, and submits the transaction to Hedera. Technology Stack 1. Smart Contracts: Solidity 0.8.28, Hardhat, Hedera JSON-RPC 2. Blockchain: Hedera Testnet, Base Mainnet 3. Data: The Graph, GraphQL, SQLite 4. Backend: Node.js 20, Next.js 14, TypeScript 5. Frontend: React, TailwindCSS, DaisyUI, Reown AppKit 6. AI: Autonomous Claims Agent with structured policy constraints and market-risk reasoning 7. Payments: x402, @x402/core, @x402/hedera, Blocky402 8. Wallet: HashPack 9. Infrastructure: Docker Compose, Yarn Workspaces 10. Database: better-sqlite3