QuotaDEX is an Agent-to-Agent (A2A) secondary market for AI compute. The MVP uses a Gateway + Supabase + Redis + Escrow design so AI agents can buy and sell idle model quota through HTTP 402 interception and Web3 micro-payments on Kite AI.
AgentBazaar is the planned parent Agent Marketplace for the broader vision. Its positioning is an Agent Marketplace that showcases the Accountable Agent Commerce Layer. QuotaDEX is the first vertical service planned inside that future AgentBazaar marketplace.
当前仓库已经完成 Phase 7:Gateway 骨架、Supabase schema、Seller 生命周期、quote、verify(Mock)、Seller worker、Buyer demo、Escrow 合约骨架、真实 deposit、receipt 校验、release、refund 都已落地。当前黑客松主线已切换到 Phase 8:支付迁移到 Pieverse Facilitator,SDK 提炼顺延到迁移完成之后。
Before writing code, read these documents in order:
- docs/project/QuotaDEX 技术规格说明书 v3.0 (Final).md
- docs/mvp-rules(swen).md
- docs/development-order(swen).md
- docs/phase-tracker(swen).md
- docs/frontend-requirements(swen).md
- docs/payment-migration-pieverse-facilitator(swen).md
Current delivery summary:
- Current phase:
Phase 8 - Payment Migration - Current step:
Step 3/5align quote metadata with facilitator route - Next milestone: add facilitator-backed verify flow
- Latest checkpoint:
Mock E2E passedquote -> verify(mock) -> seller done -> buyer final result
Phase 0 - project skeletonNext.js,app/api,lib,env
Phase 1 - data layerSupabase,sellers,jobs,events,migration
Phase 2 - seller lifecycleregister,heartbeat,offline
Phase 3 - quote- request validation, seller reservation,
fingerprint, Redis quote context,402
- request validation, seller reservation,
Phase 4 - verify (Mock)- recompute
fingerprint, load quote context, mocktx_hash, createpaidjob, move seller tobusy
- recompute
Phase 5 - seller worker- self-check, register, heartbeat, Realtime subscribe,
start,complete,fail
- self-check, register, heartbeat, Realtime subscribe,
Phase 6 - buyer demoquote, mock pay,verify, Realtime wait, polling fallback
Phase 7 - custom Escrow real-chain prototype- Escrow contract, real
deposit, receipt validation,release,refund
- Escrow contract, real
Mock E2E checkpoint- local Gateway + Supabase + Redis + seller worker + buyer demo passed end to end
For the full phase path, step progress, and unfinished tasks:
The repo now contains the current gateway project structure:
app/
api/v1/
sellers/
register/
heartbeat/
offline/
jobs/
quote/
verify/
[id]/
start/
complete/
fail/
lib/
env.ts
errors.ts
fingerprint.ts
jobs.ts
chain/
redis.ts
sellers.ts
supabase.ts
supabase/
migrations/
docs/
scripts/
contracts/
app/api/v1/*Gateway HTTP entrypoints for seller registration, buyer quote/verify, and seller job status callbacks.lib/*Shared server helpers for env loading, error responses, fingerprint generation, Redis, and Supabase.lib/chain/*Shared chain helpers for Escrow ABI, payment ID normalization, and on-chain amount conversion.supabase/migrations/*Database schema forsellers,jobs, andevents.docs/*Product spec, MVP rules, and development sequence.scripts/*Local demo helpers such as the seller worker and later buyer happy-path scripts.contracts/*Solidity escrow contracts for on-chain payment funding, release, and refund.
- A minimal
Next.js App Routergateway application is in place. - Seller lifecycle routes are implemented:
POST /api/v1/sellers/registerPOST /api/v1/sellers/heartbeatPOST /api/v1/sellers/offline
- The
POST /api/v1/jobs/quoteroute is implemented:- validates
buyer_id / capability / prompt - reserves a seller with a conditional database update
- builds
fingerprintand reuses it aspayment_id - stores
quote:{payment_id}in Redis - returns
402 Payment Required
- validates
- The
POST /api/v1/jobs/verifyroute is implemented:- recomputes
fingerprintfrom the payload - loads
quote:{payment_id}from Redis - verifies real Escrow deposit receipts for full transaction hashes
- keeps mock
tx_hashvalidation as a local fallback - creates a formal
paidjob - moves the seller from
reservedtobusy
- recomputes
- The seller execution callbacks are implemented:
POST /api/v1/jobs/:id/startPOST /api/v1/jobs/:id/completePOST /api/v1/jobs/:id/failcompletenow triggers Gateway-sideEscrow.release(payment_id)failnow triggers Gateway-sideEscrow.refund(payment_id)
- A minimal seller worker script exists:
scripts/seller-worker.mjs- local self-check before startup
- seller register and heartbeat
- Supabase Realtime subscription for seller-assigned jobs
- Gateway callbacks for
start / complete / fail
- The polling fallback endpoint is implemented:
GET /api/v1/jobs/:id
- A minimal buyer demo script exists:
scripts/buyer-demo.mjsquote -> mock pay or real approve+deposit -> verify -> wait result- Supabase Realtime result subscription
- polling fallback through
GET /api/v1/jobs/:id
- A minimal escrow contract skeleton exists:
contracts/QuotaDEXEscrow.soldeposit(paymentId, seller, amount)release(paymentId)refund(paymentId)
- The Escrow ABI and chain helpers already exist:
contracts/QuotaDEXEscrow.abi.jsonlib/chain/escrow.ts
- Shared helpers already exist for:
- env loading
- error responses
- fingerprint generation
- quote and verify parsing
- quote context storage and loading
- seller reservation and busy/idle transitions
- seller execution status transitions
- Redis access
- Supabase access
- seller request parsing
- The initial Supabase migration is in place, including
payment_id. - A minimal landing page exists so the app can build and run locally.
- A basic contract note exists in
contracts/README.md.
Copy .env.example and fill the required values.
These variables come from four places:
-
SupabaseThis is the hosted online database and Realtime service used by the project. Get these values from your Supabase project dashboard.NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEY
-
Upstash RedisThis is the hosted online cache used for short-lived quote context. Get these values from your Upstash Redis database dashboard.UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
-
Gateway server configGATEWAY_SALTis a random secret string generated by your team. It is used when building the request fingerprint and should stay server-side only. -
Blockchain configThese values are used later for real payment verification, Facilitator-based payment migration, and Escrow contract operations.KITE_RPC_URL: the RPC endpoint for the Kite networkPIEVERSE_FACILITATOR_BASE_URL: the Pieverse facilitator base URLKITE_PAYMENT_ASSET_ADDRESS: the payment asset address used for the facilitator/x402 pathGATEWAY_MERCHANT_WALLET: the merchant wallet address that receives facilitator-settled fundsPYUSD_CONTRACT_ADDRESS: the PYUSD token contract addressPYUSD_DECIMALS: token decimals, default6for PYUSD in the demo flowESCROW_CONTRACT_ADDRESS: your deployed Escrow contract addressGATEWAY_PRIVATE_KEY: the private key of the Gateway walletBUYER_PRIVATE_KEY: optional buyer wallet private key for realapprove + deposit
Important:
GATEWAY_PRIVATE_KEYis the private key of a normal wallet controlled by the Gateway.- It is not the "private key" of
ESCROW_CONTRACT_ADDRESS. - Contracts do not have private keys.
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
GATEWAY_SALT=
KITE_RPC_URL=
PIEVERSE_FACILITATOR_BASE_URL=https://facilitator.pieverse.io
KITE_PAYMENT_ASSET_ADDRESS=
GATEWAY_MERCHANT_WALLET=
PYUSD_CONTRACT_ADDRESS=
PYUSD_DECIMALS=6
ESCROW_CONTRACT_ADDRESS=
GATEWAY_PRIVATE_KEY=
BUYER_PRIVATE_KEY=Install dependencies and start the gateway:
npm install
npm run devType-check once dependencies are installed:
npm run typecheckpayment_idandjob_idare intentionally separate.fingerprintis reused aspayment_idin the MVP.Supabaseis the single source of truth for formal state.Redisonly stores short-lived quote context and optional short-term dedupe state.- Seller state changes should flow through Gateway APIs rather than direct client-side writes.