Fairtown

An onchain auction market for perishables: AI agents and people bid, sellers get paid in stages.

Fairtown

Created At

ETHGlobal Mumbai

Project Description

Fairtown is an open market for anything that loses its value at a known time: a morning catch of cod, an empty truck heading home, an idle GPU hour, flowers before Diwali. In each case the deadline is the seller's problem. Fairtown lets them list in one message, then AI agents and people bid in an open onchain auction, and the money moves under rules that are set before the sale.

The auction. Each lot is its own Uniswap Continuous Clearing Auction (CCA v2.1.0) on Base Sepolia, created by our LotFactory with an end-weighted supply schedule. Every bidder in a block pays the same clearing price for that block. Bids pull test USD or EUR through Permit2, and a validation hook only lets registered agents bid. A keeper checkpoints prices, exits bids and claims tokens.

Getting paid in stages. When the auction ends, MarketSettlement pays the seller an advance: 50% for new sellers and 90% for proven ones, after a 1% fee. The rest is held until the buyer scans the seller's QR code at handover. If a truck is needed, a second auction books one, and the driver gets 10% up front and the rest when the buyer scans at drop-off. Every stage has a deadline and a set money outcome. If the seller doesn't show up, the buyer gets the held money back automatically and the seller gets a public no-show record. If the buyer goes silent, the seller is paid.

AI agents with guardrails. 27 agents (fishmongers, kitchens, truckers, compute buyers) bid on their own. LLM output is always schema-checked, and every bid passes hard guardrails before it reaches the chain.

Public record on Arkiv. Every lot, bid, cleared price, seller record and demand signal is written to Arkiv. Agents read past prices from it to set floors and advise sellers.

Chainlink CRE workflows write FX rates, reference prices and demand signals (weather, holidays) onchain.

Add-ons:

0G: lot photos are graded on the 0G Router with TEE verification requested, and the request ID is stored so anyone can check which model graded a lot. ENS: each agent has a name like ingrid.fairtown.eth, and a no-show revokes the seller's verified role. Hedera: buyer agents pay for market intel over x402 with spending caps, with no human involved. Swarm: lot photos are also stored on Swarm. The town. A live 3D town shows the market: every footstep is a real bid, and a world clock counts down to each expiry.

All money is test money on testnets.

How it's Made

Fairtown is a pnpm monorepo in TypeScript and Solidity. It has five parts that share one package of types, zod schemas and generated ABIs.

Contracts (Foundry, Base Sepolia). LotFactory creates a Uniswap Continuous Clearing Auction (CCA v2.1.0) and an ERC-20 lot token for each lot, then funds and activates the auction in the same transaction. We run our own CCA factory with a zero protocol fee and code against the v2.1.0 source, not the docs. Every CCA call site is mapped to the exact source line in our README. Bids pull currency through canonical Permit2. A validation hook on the CCA checks our AgentRegistry, so only registered agents can bid. MarketSettlement sweeps the auction's money and unsold tokens, then pays out in stages: a 1% fee, a 50% or 90% advance depending on the seller's tier, the held share released by a signed QR handover, truck advances, refunds after a no-show, and expiry paths. An invariant suite runs random handovers, no-shows, disputes and expiries against real CCA lots. It checks that no money gets stuck and that seller + buyers + treasury always equals the amount raised.

Keeper and relay (Node, viem, Fastify, WebSockets). The keeper checkpoints auctions, settles them, exits bids, claims tokens and enforces every deadline. The relay watches the chain and streams events to the town over WebSockets.

Agents service (Fastify, Vercel AI SDK). It runs 27 personas: sellers, buyers, truckers, cold stores and a compute provider. The AI provider is never hard-wired. Any OpenAI-compatible endpoint comes from env, and we used a LiteLLM gateway with Gemini Flash Lite. The model returns advice in display units. Our code converts that to bigint base units and Q96 prices, and guardrails check every bid against the agent's mandate, its budget and the seller's ENS status. If the model takes more than 4 s, a deterministic rule-based strategy bids instead. We cache responses and stay inside a shared limit of 60 requests a minute.

Frontend (React, Vite, Tailwind, three.js). The town is a 3D scene built from CC0 Quaternius models, with easystar pathfinding, zustand for state and uPlot for price charts. Phones scan handover QR codes in the browser with zxing-wasm. Camera access needs HTTPS, so we serve the demo through a Cloudflare tunnel.

Partner tech:

Uniswap CCA gives every bidder in a block one fair clearing price, with no order book to run ourselves. Arkiv is the market's public memory: lots, bids, prices, seller records and signals. Agents query it to set floors and advise sellers. Smart contracts can't read Arkiv, so an onchain counter decides payouts and Arkiv mirrors it as the public record. Chainlink CRE workflows write FX rates (Frankfurter v2, because v1 lacks KES and NGN), reference prices and demand signals from weather (Open-Meteo) and festival dates to our receiver contracts. 0G grades lot photos with TEE verification requested. ENS (v2, Sepolia) gives agents expiring names and lets us revoke a seller's verified role. Hedera x402 lets agents pay for market intel on their own, within spending caps. Swarm stores lot photos. Hacky bits:

Blocks were faster than we planned for. Base Sepolia measured about 200 ms blocks, not the 2 s we designed for, so every block-based window was rescaled. Most demand comes at the end. CCA spreads clearing over the whole auction, so we put 75% of supply in the last block to keep the final price close to real demand. Contracts that point at each other. LotFactory and MarketSettlement hold each other's address as immutables. The deploy script predicts settlement's CREATE address before deploying it. Public RPCs drop filters. The keeper polls eth_getLogs in chunks, and on restart it rebuilds its state from contract views. CRE ran in the simulator, not on a network. We have no CRE deploy access, so a bridge runs the simulator with --broadcast to send real Base Sepolia transactions. "Written" from the simulator isn't proof. The mock forwarder swallows reverts in our receivers, so we wrote a script that checks receipts and stored values after each run. Our 0G badge stays honest. The 0G Router returns no TEE attestation today, so the badge says "logged", not "verified".

background image mobile

Join the mailing list

Get the latest news and updates