MultiHopper Build & Route Challenge

Agent Treasury

A policy gate between what an AI agent wants to pay and what it is allowed to pay. Budget rules live outside the model; routing and signing happen on Solana through MultiHopper; the ledger records everything.

The gap this fills

Giving an agent a wallet is easy. Giving it a wallet it cannot misuse is not.

Without a gate

Either a human approves every transfer, so the agent is a script with extra steps, or the agent holds the key and one bad prompt drains the treasury.

What MultiHopper provides

Programmable, compliance-screened multi-hop routing. It makes the route a product decision. It does not decide who may spend what.

What this adds

Per-transaction and daily limits, recipient allowlists and an approval band, evaluated as a pure function before any network call, with the reason returned every time.

Request path

One intent in, one routed transfer out, with the decision attached to it.

agent POST /spend { agentId, recipient, amountUsd, amountRaw }   │   ├─▶ policy gate pure function of request + limits + ledger   │     ├── denied   over per-tx or daily limit, recipient not allowed   │     ├── needs_approval within limits but above the auto-approve band   │     └── approved   │   ├─▶ MultiHopper estimate → create → prepare   ├─▶ local signer keeper funding → route init → orchestrator → sessions   ├─▶ confirm-broadcast every signature, once on chain   └─▶ ledger + webhooks HMAC-verified events, terminal status

Verified on devnet

Numbers below come from live runs of this code against devnet.multihopper.com/api/v1. Devnet and mainnet are separate deployments, so they do not count as production volume.

CheckResult
npm test34 passed
Product run, 0.1 SOL over 3 hopstransfer 1738 · completed
Quote accuracy99502487 lamports delivered
Integrator share, per route248756 lamports
Credited across completed routes995024 lamports · 4 payouts
On-chain settlementfinalized · no errors

A three-hop devnet route reaches its terminal status in about five minutes and moves through processing, active then completed.

Contract

Small surface, typed end to end, and the reasons travel with the decision.

// POST /spend
{
  "agentId":   "research-agent",
  "recipient": "<pubkey>",
  "amountUsd": 40,
  "amountRaw": "100000000",
  "memo":      "compute credits for 200 research tasks"
}

// 200
{
  "decision": { "outcome": "approved",
                "reasons": ["within per-transaction and daily limits"] },
  "transfer": { "id": 1738, "status": "processing" },
  "signatures": ["5miGBFNN...", "435o9rzw..."]
}

Batch payouts reuse the same path: one route pays up to 20 wallets, and hops dominate cost, so extra destinations are nearly free.

What the live API actually does

The published docs and the running service disagree in a few places. Each difference is handled here and pinned with a regression test.

amountTokens is required

POST /transfers answers BAD_REQUEST: amountTokens: Required even though it reads as optional. Derived from the raw amount and decimals.

Idempotency on prepare

Every mutation needs the header, prepare included, or the API answers MH_070.

Bodyless POSTs

Declaring JSON with no body is refused by the API's Fastify layer, which is exactly what prepare looks like.

Confirmation in one call

confirm-broadcast demands routeInitSignatures even in the first call, so the documented split confirmation fails.

Inconsistent envelopes

create returns the transfer flat, prepare wraps it, and routeInitTxs arrives as { base64 } objects. Normalised at the client.

Signer detects the type

orchestratorInitTx arrives as a versioned v0 message although the docs promise a legacy transaction.

Run it

cp .env.example .env   # MH_API_KEY, TREASURY_KEYPAIR_B58, MH_WEBHOOK_SECRET
npm install
npm run typecheck
npm test
RECIPIENT=<devnet-pubkey> npm run demo   # policy → estimate → routed transfer
npm run dev                             # agent HTTP API on :8787

TypeScript Solana MultiHopper API v1 key custody local CI green MIT