Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClauseGuard

AI-powered P2P trade escrow protocol built on GenLayer Bradbury Testnet. Deal terms are written in plain English, funds lock in escrow, and GenLayer's AI validators autonomously verify whether conditions are met by fetching web evidence and reasoning about the terms.

Why ClauseGuard

Every existing escrow protocol on any blockchain relies on binary oracle feeds or a centralized arbitrator. ClauseGuard is the first escrow that can read and understand deal terms and evidence, because GenLayer validators can reason about subjective conditions via LLMs and verify them against live web data.

Traditional smart contract escrow requires rigid boolean logic: "if X address calls release(), funds move." ClauseGuard replaces that with natural language: "Release payment when the shipment clears customs and buyer confirms quality." The intelligent contract does the rest.

How It Works

Seller creates deal         Buyer funds escrow         Either party submits
with plain English    --->  locking tokens into   ---> evidence (URLs to
terms and price             the contract               tracking, reports, etc.)

         |                        |                           |
         v                        v                           v

AI validators fetch        Validators reason about     Consensus via Optimistic
web evidence from          whether evidence satisfies  Democracy: majority vote
submitted URLs             the natural-language terms  determines the outcome

         |
         v

Funds auto-release to seller (conditions met)
   or refund to buyer (conditions not met)
   or escalate to larger validator pool (disputed)

GenLayer Capabilities Used

  • gl.nondet.web.render() — Validators crawl tracking pages, delivery confirmations, and inspection reports
  • gl.nondet.exec_prompt() — LLM reasons about whether evidence satisfies the deal terms
  • gl.eq_principle.strict_eq() — Validators reach consensus on the subjective assessment
  • Optimistic Democracy appeals — Disputed verdicts escalate to larger validator pools automatically

Project Structure

clauseguard/
├── contracts/
│   └── clauseguard.py            # Intelligent contract (deploy via GenLayer Studio)
├── frontend/
│   ├── src/
│   │   ├── components/
│   │   │   ├── CreateDealForm.jsx # Deal creation with natural language terms
│   │   │   ├── DealCard.jsx       # Deal card for marketplace grid
│   │   │   ├── DealDetail.jsx     # Full deal view with actions
│   │   │   ├── EvidencePanel.jsx  # Evidence submission and display
│   │   │   ├── StatusBadge.jsx    # Status indicator component
│   │   │   ├── StatusTimeline.jsx # Visual deal progress tracker
│   │   │   └── VerdictPanel.jsx   # AI verdict display
│   │   ├── lib/
│   │   │   ├── constants.js       # Shared config and enums
│   │   │   └── genlayer-integration.js  # GenLayer JS SDK bridge
│   │   └── frontend.jsx           # Main app (self-contained demo version)
│   ├── .env.example
│   └── package.json
├── deploy/
│   └── deploy.js                  # Deployment helper script
└── docs/
    └── deal-flow.md               # Detailed deal lifecycle documentation

Quick Start

1. Deploy the Contract

Open GenLayer Studio, paste the contents of contracts/clauseguard.py, and deploy to Bradbury testnet. Copy the contract address.

2. Set Up the Frontend

cd frontend
cp .env.example .env.local
# Edit .env.local and set your contract address
npm install
npm run dev

3. Connect and Trade

Open http://localhost:3000, connect your wallet, and create your first deal.

Contract API

Write Methods

Method Description
create_deal(terms, price_description, deadline_description, verification_urls) Seller creates a deal with natural language terms
fund_deal(deal_id) Buyer deposits funds into escrow
submit_evidence(deal_id, evidence_type, evidence_url, description) Either party submits proof
request_verification(deal_id) Triggers AI verification by validators
settle_deal(deal_id) Releases funds to seller after verification
claim_refund(deal_id) Buyer reclaims funds from a rejected deal
cancel_deal(deal_id) Seller cancels an unfunded deal

Read Methods

Method Description
get_deal(deal_id) Full deal data as JSON
get_open_deals() All open deals (marketplace view)
get_all_deals() All deals (dashboard view)
get_deal_status(deal_id) Current status string
get_deal_verdict(deal_id) AI verification verdict details
get_user_deals(user_address) Deal IDs for a specific user
get_deal_count() Total deals created

Deal Lifecycle

open  -->  funded  -->  evidence_submitted  -->  verified  -->  settled
  |                                                  |
  v                                                  v
cancelled                                    rejected --> refunded
                                                |
                                                v
                                            disputed (escalates)

Status Definitions

  • open — Deal listed, waiting for buyer to fund
  • funded — Buyer has deposited, escrow is active
  • evidence_submitted — One or both parties have submitted proof
  • verified — AI validators confirm conditions are met
  • settled — Funds released to seller, deal complete
  • rejected — AI validators determine conditions are not met
  • refunded — Buyer has reclaimed funds from a rejected deal
  • disputed — Low-confidence verdict, escalated to larger validator pool
  • cancelled — Seller withdrew an unfunded deal

Evidence Types

When submitting evidence, use one of these categories:

  • delivery_proof — Shipping confirmations, delivery receipts
  • quality_report — Inspection results, lab analyses, certifications
  • tracking — Live tracking page URLs
  • receipt — Purchase receipts, invoices
  • other — Any other supporting evidence

AI Verification Deep Dive

When request_verification() is called, each GenLayer validator independently:

  1. Fetches all submitted evidence URLs using gl.nondet.web.render()
  2. Fetches all verification URLs specified when the deal was created
  3. Constructs a prompt with the deal terms + all fetched web content
  4. Asks the LLM to assess whether every condition in the terms is satisfied
  5. Returns a structured verdict with conditions_met, confidence, reasoning, and unmet_conditions

Validators then vote via Optimistic Democracy. If the majority agrees, the verdict stands. If contested, it escalates through appeal rounds with progressively larger validator pools.

The LLM prompt is designed to be rigorous: it only returns conditions_met: true if ALL terms are clearly satisfied by the evidence. Ambiguous or unverified conditions result in rejection.

Growth Roadmap

  • Multi-milestone deals with partial fund releases
  • Reputation scoring based on completed deal history
  • Invoice factoring module for business-to-business finance
  • Escrow templates for common trade types (freelance, commodity, digital goods)
  • DAO governance for protocol parameter tuning
  • Cross-chain settlement bridges

Built With

  • GenLayer — AI-native blockchain with Intelligent Contracts
  • GenLayer JS SDK — Frontend contract interaction
  • GenVM — Python execution environment for Intelligent Contracts
  • React / Next.js — Frontend framework

License

MIT

About

AI-powered P2P trade escrow on GenLayer Bradbury Testnet

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages