# x402 + CDP wallet — dossier screening CLI (target architecture)

**Status:** Demo simulation on `/#agents` · production not wired

## Flow you described

```mermaid
sequenceDiagram
  participant CLI as lfi CLI
  participant CDP as CDP Wallet (buyer)
  participant API as LFI Screening API
  participant Pool as Counsel bid pool
  participant DAO as LFI Treasury

  CLI->>API: POST /v1/screen (no payment)
  API-->>CLI: 402 + PAYMENT-REQUIRED (50 USDC)
  CLI->>CDP: sign EIP-3009 / Permit2
  CLI->>API: retry + PAYMENT-SIGNATURE + multipart zip
  API->>API: unzip, virus scan, index, merits-agent
  API-->>CLI: 202 {ref, status: processing}
  API-->>CLI: webhook/poll {merits: 0.71, status: ready}
  Pool-->>CLI: bids (RVG bands, success fee %)
  CLI->>DAO: fund --tranche USDC --pps 24%
```

## What you need (production)

| Layer | Component | Notes |
|-------|-----------|--------|
| **Payments** | [x402](https://docs.x402.org/faq) + [CDP facilitator](https://docs.cdp.coinbase.com/x402/welcome) | HTTP `402` → `PAYMENT-SIGNATURE` → USDC on Base (EIP-3009). Budget caps per dossier. |
| **Wallet** | CDP Wallet API / Server Wallet | Programmatic signer for CLI; separate treasury wallet for fund-out. |
| **Ingress** | `POST /v1/screen` | Multipart zip + manifest.json; max size; ClamAV; sandbox unzip. |
| **Compute** | Worker queue | S3/GCS blob → unzip → OCR/index → merits model → human counsel gate. |
| **Identity** | Case ref `REF-YYYY-NNN` | Tie payment tx hash, zip SHA-256, and bid pool. |
| **Bid market** | Off-chain DB + optional on-chain commit | Firms stake quote: RVG cap, hours, success %, jurisdiction. |
| **Funding** | USDC tranche contract or multisig | Profit participation (PPS) watermark in term sheet hash; counsel signs. |
| **Legal** | KYC/AML, privilege, GDPR | Dossier = personal data; EU counsel sign-off before fund-out. |

## Suggested API surface

```
POST /v1/screen          → 402 or 202 Accepted
GET  /v1/screen/{ref}    → {status, merits_score, burn_band, flags}
GET  /v1/screen/{ref}/bids
POST /v1/fund/{ref}      → {counsel_id, amount_usdc, pps_percent, tranche}
```

## Open source (closest matches)

| Project | Relevance |
|---------|-----------|
| [coinbase/x402](https://github.com/coinbase/x402) / [x402-foundation](https://github.com/x402-foundation/x402) | Protocol spec + facilitators |
| [xenarch-ai/x402-agent](https://github.com/xenarch-ai/x402-agent) | Python pay loop for agents |
| [kmatthewsio/langchain-x402](https://github.com/kmatthewsio/langchain-x402) | LangChain tool paying 402 APIs |
| [naividh/agent-procure](https://github.com/naividh/agent-procure) | Discover → budget → pay → synthesize |
| [Optilex-Labs/brolli-x402](https://github.com/Optilex-Labs/brolli-x402) | **Litigation finance + x402** (Optilex/Brolli) |
| [kalashshah/tribunal](https://github.com/kalashshah/tribunal) | Agent disputes / escrow (adjacent) |

**No single OSS repo** does zip → merit score → counsel bidding → LFI USDC fund in one CLI; closest vertical is **brolli-x402** (litfi infra), plus generic x402 payers.

## Demo on this site

The homepage CLI **simulates** payment, unzip, merit score, three counsel bids, and USDC tranche funding. No chain calls.
