Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Settle

Autonomous OTC derivatives settlement inside an Intel TDX TEE on Eigen Compute.

Two parties draft a custom yes/no contract. Settle prices it, holds both sides' USDC collateral, watches a pre-agreed signed oracle, and settles automatically at expiry. The agent's wallet key is derived from the sealed image digest — neither counterparty nor the operator can move funds outside the sealed code path.


Why

Two guilds want to bet 500 USDC on a tournament bracket. A farmer wants a 2 000 USDC rainfall hedge. Two traders want a swap on an illiquid token. Today those trades don't happen. The alternatives are all broken:

  • Centralized custodians (Betfair, brokers): won't list long-tail risks, 5–10% fees, KYC-heavy.
  • Smart contracts: can't run discretionary pricing, can't consume arbitrary signed oracles cheaply, leak the book on-chain.
  • Legal contracts: cost > notional for anything under ~$50 k.

Settle fills the gap: arbitrary code + a self-controlled wallet + a hardware-backed proof, all running in a TDX enclave that neither side — nor the operator — can tamper with.

Trust model

Four guarantees, each coming directly from the TEE:

  1. Collateral can't be rugged. The wallet key is derived from a sealed secret bound to the image digest. The operator never sees it.
  2. Pricing can't be rigged. Pricing code is baked into the signed image. Any change means a new digest; counterparties can refuse to accept against an unfamiliar digest.
  3. Oracle inputs can't be faked. The feed is chosen at origination, frozen for the contract lifetime, and signatures are verified on every read.
  4. Settlement can't be delayed. The settlement timer runs inside sealed code. The operator can't "pause for maintenance" selectively.

Every state transition emits a signed event carrying the agent's wallet address and the KMS public-key digest. The public contract page renders the full hash-chained log. A verifier script can recover each signer from the canonical bytes + signature and confirm the chain head.

Architecture

 ┌─────────┐                                              ┌────────────┐
 │ Party A │─┐                                       ┌───▶│ OpenRouter │
 └─────────┘ │   ┌──────────────────────────────┐    │    │   (LLM +   │
             ├──▶│ Settle agent (TDX TEE)       │────┤    │ web search)│
 ┌─────────┐ │   │  • pricing                   │    │    └────────────┘
 │ Party B │─┘   │  • collateral vault wallet   │────┤
 └─────────┘     │  • LLM oracle resolver       │    │    ┌────────────┐
                 │  • settlement + fee logic    │────┼───▶│ Base L2    │
                 │  • signed event log          │    │    │  (USDC)    │
                 └──────────────────────────────┘    │    └────────────┘
                          (attested image)           │
                                                     │    ┌────────────┐
                                                     └───▶│ contract   │
                                                          │  page      │
                                                          └────────────┘
  • Container: Node 22 · Hono · viem · zod
  • Runtime: Eigen Compute (Intel TDX), g1-standard-4t
  • Settlement chain: Base (USDC, low gas)
  • Oracle: OpenRouter LLM with live web search (default: perplexity/sonar)
  • Frontend: Next.js 14 on Vercel, with server-side API routes proxying through to the enclave so HTTPS browsers can reach the HTTP TEE cleanly

Layout

agent/       Hono service that runs inside the TEE (Dockerfile, state machine, pricing, wallet, OpenRouter oracle).
cli/         `settle` commander CLI for originators.
web/         Next.js contract page — form to originate, accept flow, live attestation chain.
deploy/      `ecloud` deploy scripts and .env template.
data/        Local event log + state (gitignored, TEE holds the authoritative copy).

Quick start

Run the agent locally

cd agent
npm install
cp ../deploy/.env.example .env           # local dev
SETTLE_ALLOW_DEV_WALLET=1 npm run dev    # hono on :8080

Run the CLI against it

cd cli
npm install && npm run build
./dist/settle.js originate \
  --yes-party 0x…        --no-party 0x…     \
  --question "Will team X win tournament Y?" \
  --yes-price 0.4 --notional 10             \
  --expiry 2026-05-01T00:00:00Z
./dist/settle.js status <contract_id>

Run the web UI

cd web
npm install
AGENT_URL=http://localhost:8080 npm run dev
# http://localhost:3000

Deploy the agent to Eigen Compute

# Build + push amd64 image
cd agent
docker buildx build --platform linux/amd64 -t <registry>/settle:v0.3 --push .

# Deploy (non-interactive flags cover all prompts)
cd ../deploy
./deploy.sh <registry>/settle:v0.3

Deploy the frontend

cd web
npx vercel@latest deploy --prod --yes -e AGENT_URL=http://<tee-ip>:8080

Contract templates

Template Inputs Oracle Settlement
Binary (MVP) question, yes_price, notional, expiry UMA OOv3 winner takes pot − fee
Vanilla option strike, expiry, call/put, notional Chainlink cash-settled delta
Rainfall cap location, threshold, period NOAA-signed stepwise payout
Price range asset, upper, lower, expiry Chainlink inside/outside

MVP ships binary only. Others live in the roadmap.

State machine

  draft
    │ originate()
    ▼
  pending_accept ── atomic verify of both USDC deposits ──┐
                                                          ▼
                                                         live
                                                          │  expiry → LLM oracle → payout
                                                          ▼
                                                        settled

Transitions that don't match raise StateError. A refund escape hatch exists for the freeze-and-return case if a TEE vulnerability is disclosed — it only ever returns collateral pro-rata, never to a third address.

Pricing

Deterministic, no LLM surface:

YES side posts  p · notional          NO side posts  (1 − p) · notional
Fee = 50 bps of pot, split across sides at settlement

Winner receives pot × (1 − fee_bps/10_000); the remainder accrues to the agent wallet.

Limits (MVP)

  • USDC only, Base only
  • Notional ≥ $1, ≤ $50 000 per contract
  • Fully collateralized — no margin calls
  • Non-US addresses and non-securities underlyings only (pending legal review)

Why Eigen Compute

A plain cloud deployment can't give any of the four guarantees above — the operator can always swap the binary, read the wallet key, stall the oracle poll. A smart contract can't do discretionary pricing or pull from arbitrary signed oracles cheaply. Eigen Compute sits in the gap: arbitrary code, a sealed wallet, and an attestation both counterparties can verify out-of-band before they deposit a dollar.

Status

MVP v0.5 — TypeScript end-to-end (Node 22 + Hono + viem on the agent, Next.js + wagmi on the web, commander on the CLI). Binary contracts live on Base sepolia, oracle resolution via OpenRouter (LLM with live web search), frontend on Vercel.

Roadmap: options + rainfall + range templates, multi-model oracle quorum for contracts > $10 k notional, ERC-8004 reputation, append-only event-log mirror on Base L2 (so upgrade doesn't wipe history), threshold KMS.

License

MIT.

About

Autonomous OTC derivatives settlement on Eigen Compute TDX TEE

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages