Mandate

Project name

Mandate

Tagline

We built the trust and governance layer for autonomous prediction market trading agents, so you can create guidelines and policies for your prediction market trading agents to follow.

Submission fields

Inspiration

Giving an AI agent access to a trading account today is all or nothing. An exchange API key with trading rights can trade every product with every dollar in the account, and the only limit on the agent is its own instructions, which any text it reads can try to override. We wanted the limits to sit outside the model, in a place the agent cannot edit: a contract that the agent's key can only send proposals to. We picked a job for the agent that does not depend on beating the market: protecting a crypto holding through a risky week with Gemini's strike ladders, where buying NO contracts below the current price pays out as the price falls.

What it does

An owner writes the rules once in a Policy contract: a total budget, a maximum per order, an approval threshold, a daily loss limit, the allowed market categories, and a pause switch. The owner then asks Grok Bot in plain words, for example "Protect my 0.05 BTC down to 10% below today's price this week, for at most $50".

Grok Bot works only through our remote MCP server. It reads the rules and the holding, can pay $0.001 in testnet USDC over x402 for a pricing signal that rates each strike as cheap, fair or expensive, and plans a ladder of NO orders on Gemini's live prediction-market data. The plan states its cost, how much of the loss at the floor it covers, which order will wait for the owner, and, plainly, what it cannot cover, for example that nothing protects the fall below the ladder's lowest strike.

When the owner agrees, each order is proposed to the contract with a hash of the agent's sealed reason (the request, the plan, the prices it saw and any signal it paid for). The contract answers every proposal in the same transaction: approved, held for the owner, or rejected with the rule that stopped it. A held order waits on the console's Approvals page until the owner approves or rejects it; a rejected one is final, and the agent is told never to resize, split or retry it. The executor places only approved orders, records each fill onchain, and at expiry settles each position from the outcome Gemini publishes.

The console shows the rules, the hedge and its cover, every intent with its evidence chain, the Audit page built from the contract's events, signal payments, and a pause control that makes the contract reject every new proposal. Grok Bot also runs on its own: a scheduled routine checks the standing goals, and the console posts wake-ups to the routine's webhook when the price falls below the floor, the owner decides on a held order, or a ladder settles. There is one goal per ladder, and the server computes whether each is already covered, so repeated or overlapping runs never buy the same protection twice. A workspace signs in with passkeys and can run up to five mandates by default, each with its own contract, agent key, token and rules. A public scorecard shows the agent's record: verdicts, blocked attempts and owner decisions read from the chain, and settled results from the executor's signed records.

What is real and what is simulated. The Policy contract and its checks, Grok Bot's planning and proposals, Gemini's market data, the owner's approvals and the x402 signal payments are real. Since 18 Nov 14:28 UTC the hosted demo's executor places every approved order on Gemini's sandbox, with test funds, through Gemini's signed order API. The first hedge placed that way, four orders that Grok Bot proposed on the daily BTC ladder (intents #9 to #12), filled on the sandbox. Three are recorded exactly as the venue filled them. The fourth, #12, is recorded onchain as a partial fill (5 of 11.81 contracts, $1.05), but Gemini filled the rest 34 seconds later: our executor had read an in-between status as final (see Challenges). The eight fills before that (intents #0 to #7) were simulated against Gemini's live listings, and the console labels every fill "Simulated fill" or "Sandbox fill". Gemini's sandbox has almost no resting orders of its own, so a second sandbox account of ours runs a maker that copies production's quotes onto the sandbox (gemini/src/maker/); the executor's orders then match on Gemini's sandbox engine at production's prices. One x402 signal purchase is on the hosted demo's record (0.001 USDC, 17 Nov); the 18 Nov plan used Gemini's quotes only, so no order on the demo cites a paid signal yet. No real-money trade has been made.

How we built it

Mandate is a TypeScript monorepo with one Solidity contract.

  • Policy contract (contracts/, Solidity and Foundry, written by Ryan): three roles (owner, agent, executor), the rule checks in proposeTrade and again in approveIntent, and an event for every proposal and verdict.
  • MCP server (agent/): a remote MCP server over Streamable HTTP with per-agent bearer tokens, 16 tools, and server instructions sent on every connection. No tool can call an owner or executor function, and agent/test/no-owner-calls.test.ts checks that from the source.
  • Planner (planner/): sizes the NO staircase between the floor and the price, measures the cover already held, and buys only the missing part; property tests use fast-check.
  • Signal API (signals/): a Hono service behind the x402 payment middleware, paid through Circle Gateway on Arc testnet.
  • Executor (devchain/): watches for approvals, checks each one again against Gemini's listing, places it through one venue interface (simulated, or Gemini's sandbox), records the result with recordResult, and signs each settlement.
  • Console (dashboard/): Next.js with wagmi and viem, passkeys through SimpleWebAuthn, and SQLite; it follows the contract's events and sends the wake-ups to Grok Bot.
  • Hosting (deploy/): Docker Compose and Caddy on one small machine.
  • Testing: unit and property tests with Vitest, Foundry tests for the contract, end-to-end tests of the agent flow against a real local chain, Playwright tests of the console in a real browser, and a red-team suite (redteam/).

Challenges we ran into

  • Grok Bot read its tool list once. After our server grew from 3 to 16 tools, Grok kept seeing 3 until we added the connector again under a changed URL with a smaller tool list (docs/grok-bot.md). We now freeze tool names and schemas before the final connector is added.
  • The model double-bought. On 17 Nov an hourly run judged a holding about 99% covered as "not yet fully" covered and bought a second ladder. We moved the question into the server: plan_hedge computes the cover, answers ALREADY_COVERED when the goal is met, and execute_plan re-reads positions before each order (docs/cover.md).
  • The contract cannot hold a payout. recordResult runs when an order fills, days before the market resolves, so the executor signs a settlement document at expiry, and the console stores it only when the signer is the contract's executor and the numbers match the fill (docs/order-lifecycle.md).
  • Sandbox liquidity. Gemini's sandbox has almost no resting orders, so an approved order had nothing to fill against. We wrote a maker that mirrors production's quotes onto the sandbox from a second test account, replaces a quote before cancelling the old one so no strike is ever empty, and keeps its quote opposite the executor's resting orders (gemini/src/maker/, docs/gemini-venue.md).
  • A partial fill that was not final. The top of the book is thin, so an order can fill in part and then finish. On 18 Nov the executor recorded intent #12 as "5 of 11.81 contracts filled, the rest cancelled" while the order was still live, and Gemini filled the rest 34 seconds later. We found it after settlement by reconciling the sandbox balance against our records to the cent: the account held $5.31 more than #12's record explained. The onchain record of #12 cannot be rewritten, so the console still shows 5 contracts for it. The fix was merged and deployed to the hosted executor the same night: an order now counts as closed only when Gemini reports it filled or cancelled, or has answered our cancel and no longer lists it, and the executor reads the order again after every cancel (devchain/src/gemini-venue.ts, docs/gemini-venue.md).
  • Hostile numbers. The red team found that a number above 2^53 sent with the agent key stalled the console's event reader for good; readers now decode such values as out of range and keep working (redteam/README.md).

Accomplishments that we're proud of

  • A real Grok Bot plans and proposes through our MCP server, and every order it proposes gets the contract's verdict on Arc testnet: 13 intents so far, 11 approved at proposal, 1 held and then approved from the owner's wallet, 1 rejected for "over max trade size".
  • On 18 Nov, one plain request to Grok Bot became four approved orders ($13.18) placed on Gemini's sandbox by the hosted executor and recorded onchain within a minute. At the 22:00 UTC expiry BTC settled at $62,239.35, below every strike held, and the executor settled all four from the outcome Gemini published: by the console's records they paid $33.66 against a cost of $10.85 and $0.52 in estimated fees, a net of +$22.29 in sandbox test funds (#9 +$2.55, #10 +$7.46, #11 +$8.39, #12 +$3.89). The venue itself paid $6.81 more than that on #12, for $1.50 more cost, because of the partial-fill record described under Challenges; with that, the sandbox balance reconciles exactly. That is the hedge doing its job: the payout offsets part of what 0.05 BTC lost on the way down.
  • A paid x402 run on Arc testnet bought a signal for 0.001 USDC, settled by Circle Gateway in batch transaction 0xa99bcd21ab5a60c3749c1c9fcb743768e6cffb5513a3dd7d3ab87d541e5ec12b.
  • On Gemini's sandbox, with test funds, an approved $9.73 order filled 10 contracts at 0.97 with a $0.03 fee, paid $10.00 at expiry, and the recorded net of +$0.27 matched the sandbox balance to the cent.
  • The red-team suite ran 47 scripted attacks against the contract and the MCP server on a local chain: 42 held, 5 bounded (they went through but stayed within a limit the report names, such as the total budget), and 0 breaches (redteam/REPORT.md).
  • On the console's own contracts, each owner action needs a fresh passkey confirmation bound to that exact call, while a pause needs only the session, so stopping the agent never waits on a device.

What we learned

  • An agent platform's own approval prompt is a model's judgement; a contract is a rule. They work together, but only the rule guarantees the outcome.
  • Anything the agent would otherwise add up (cover, the day's spend, what settled) should be computed by the server and handed over as a fact.
  • A rejection has to be final in two places: the instructions tell the agent never to retry, and the contract rejects every retry anyway.
  • Per-order rules are not enough on their own: splitting a $30 order into two $15 orders passes the $25 limit, and only the total budget bounds it.

What's next

  • Record settlements onchain (a recordSettlement call), so the daily loss limit also counts losses at expiry.
  • A daily spend cap in the contract, to bound order splitting tighter than the lifetime budget.
  • A factory contract, so one owner transaction deploys and registers a mandate.
  • A separate Gemini account or subaccount per mandate, and agent keys in a custody provider or HSM, before any real funds.
  • The QuickNode Stream as the console's live event source on Arc.
  • Plans that price a whole order against the depth of the book, not only its best level.
  • Workspace members with roles, and a wake-up webhook per agent.

Built with

solidity, foundry, arc, circle-gateway, usdc, x402, quicknode-streams, gemini-prediction-markets-api, grok-bot, model-context-protocol, typescript, node.js, next.js, react, viem, wagmi, hono, zod, sqlite, webauthn, docker, caddy, vitest, playwright

How each sponsor technology is used

Arc and Circle

The Policy contract (contracts/src/Policy.sol) holds the owner's rules and judges every order: the agent's key can only call proposeTrade, and the contract approves it, holds it for the owner, or rejects it with a recorded reason. The hosted demo's mandate is its own deployment of Policy v2 on Arc testnet at 0x9a240b2aaa2a936DBf4543940341Bb725C92412d (deploy block 72777078), owned by the demo owner's MetaMask wallet; the first deployment is at 0x571D8ea7C86c80a230C10818743f8861084F82f3 (contracts/README.md). Every proposal, owner approval and fill record in the video is an Arc testnet transaction, and the owner signs with MetaMask (docs/hosting.md, "Arc testnet"). On Arc, gas is paid in USDC, so the agent and the executor pay for their transactions in the same dollar unit as the signal payments.

Circle Gateway and x402

The agent pays for each pricing signal it uses. The signal API answers 402 Payment Required (signals/src/paid-route.ts); the MCP server signs a USDC transfer authorization offchain with Circle's @circle-fin/x402-batching client (agent/src/x402/buyer.ts), and Circle Gateway verifies it and settles many payments later in one batch transaction on Arc testnet. Spend is capped by a daily budget and a price cap per purchase in the MCP server (agent/src/x402/spend-ledger.ts), and when a plan uses a signal, the payment's receipt id is sealed into the reason of every order it informed. A recorded paid run is in docs/x402.md.

Gemini Prediction Markets

Gemini's public prediction-market API supplies the strike ladders the planner sizes, each market's category (taken from Gemini, never from the agent), the prices the signal rates, and the published outcomes used for settlement (gemini/src/client.ts, planner/). The executor places approved orders through Gemini's signed order API (gemini/src/private.ts, devchain/src/gemini-venue.ts) on the sandbox only, and refuses any order the MCP server could not have sent. The hosted demo has placed orders on the sandbox since 18 Nov; before that its fills were simulated against Gemini's live listings (devchain/src/venue.ts), and the console labels each fill with its venue. A maker on a second sandbox account mirrors production's quotes so that sandbox orders have something to fill against (gemini/src/maker/). The sandbox fill and settlement measured on 17 Nov are in docs/gemini-venue.md.

Grok Bot

Grok Bot is the agent: it connects to our MCP server as a custom connector and uses its tools to read the mandate, plan a hedge, buy a signal and propose orders, in chat with the owner or in a scheduled routine. It holds no keys and has no direct access to Gemini or the contract, so the contract judges everything it does. The server instructions are in agent/src/instructions.ts, the routine, skill and daily digest in agent/grok/, and the console's webhook wake-ups in dashboard/src/server/wake.ts; docs/grok-bot.md records what was verified by hand.

QuickNode Streams

The Stream is designed as the console's source of Policy events on Arc testnet (network arc-testnet, dataset logs), and its pieces are built and tested: the filter that keeps only the Policy contract's logs (streams/filter.js), the webhook that verifies the X-QN-Signature HMAC and stores each event once (dashboard/src/app/api/webhooks/quicknode/route.ts), and the script that creates, pauses and deletes it (streams/scripts/quicknode-stream.ts).

Not used

Solana and ElevenLabs, the other sponsors named on the hackathon page, are not part of Mandate.

Built With

Share this project:

Updates

Submission history