Agent Server
Express API reference for the agent infrastructure server.
Overview
The agent server is an Express application running on port 4021. It serves as the bridge between the frontend, AI agents, and on-chain contracts. API endpoints are gated by x402 micropayments for agent-facing routes.
x402 Payment Middleware
The server uses @x402/express middleware to gate paid endpoints. When an agent sends a request without payment, the server returns HTTP 402 with payment requirements. The agent then re-sends the request with a signed USDC transfer in the X-PAYMENT header.
| Endpoint | Fee | Description |
|---|---|---|
POST /api/propose | $0.01 | Submit a market proposal |
POST /api/trade | $0.001 | Execute a trade on a proposal |
GET /api/amplitudes/:marketId | $0.0001 | Query current proposal amplitudes |
Market API Routes
GET /api/markets
List all markets with basic metadata.
GET /api/markets/:id
Get full market details including proposals and current amplitudes.
POST /api/propose
Submit a new proposal. Requires x402 payment.
{
"marketId": 1,
"description": "Implement yield farming strategy X",
"stake": "1000000" // 1 USDC (6 decimals)
}POST /api/trade
Execute a trade on a proposal. Requires x402 payment.
{
"marketId": 1,
"proposalId": 0,
"direction": "increase",
"amount": "500000"
}Uniswap Proxy Routes
The server proxies requests to the Uniswap Trading API, adding authentication via the UNISWAP_API_KEY environment variable.
POST /api/uniswap/quote
Get a swap quote. Supports CLASSIC and DUTCH routing types.
{
"tokenIn": "0x0000000000000000000000000000000000000000",
"tokenOut": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"tokenInChainId": 8453,
"tokenOutChainId": 8453,
"amount": "1000000000000000",
"swapper": "0x...",
"type": "EXACT_INPUT"
}POST /api/uniswap/check-approval
Check if an ERC-20 approval transaction is needed before swapping.
POST /api/uniswap/swap
Get unsigned swap transaction calldata for the user to sign and broadcast.
Auto-Execution (Post-Collapse)
When a market collapses, the autonomous agent loop parses the winning proposal description for swap intent keywords (e.g., "allocate to USDC", "buy ETH") and auto-executes via the Uniswap Trading API. This turns collective intelligence into automated DeFi action.