everyblock-mcp 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,7 @@ With neither `RPC_URL` nor `EVERYBLOCK` set it talks to the live Monad testnet d
26
26
  | `split` / `merge` | yes | Mints complete sets (1 UP + 1 DOWN for $1.00), or burns them back into collateral. |
27
27
  | `faucet` | yes | Mints TestUSD collateral (testnet and local only). |
28
28
  | `open_market` | yes | Opens the current (or next) market for a feed when no keeper has; returns the existing id if it is open. |
29
+ | `register_agent` | signs | Signs "I am an agent called X" with the wallet and registers it with the app, so the leaderboard shows the name with an Agent badge. No transaction. |
29
30
  | `settle` | yes | Proves a market's price to beat and/or its result with signed Pyth prices from the app's `/api/proof` (no Pyth key needed), paying Pyth's update fee. |
30
31
 
31
32
  Every write returns the transaction hash and the decoded result (events and amounts). Writes run one at a time.
package/dist/abi.js CHANGED
@@ -22,10 +22,28 @@ export const everyblockAbi = [
22
22
  "name": "owner_",
23
23
  "type": "address",
24
24
  "internalType": "address"
25
+ },
26
+ {
27
+ "name": "batchSeconds_",
28
+ "type": "uint256",
29
+ "internalType": "uint256"
25
30
  }
26
31
  ],
27
32
  "stateMutability": "nonpayable"
28
33
  },
34
+ {
35
+ "type": "function",
36
+ "name": "BATCH_SECONDS",
37
+ "inputs": [],
38
+ "outputs": [
39
+ {
40
+ "name": "",
41
+ "type": "uint256",
42
+ "internalType": "uint256"
43
+ }
44
+ ],
45
+ "stateMutability": "view"
46
+ },
29
47
  {
30
48
  "type": "function",
31
49
  "name": "CENT",
@@ -130,6 +148,30 @@ export const everyblockAbi = [
130
148
  ],
131
149
  "stateMutability": "view"
132
150
  },
151
+ {
152
+ "type": "function",
153
+ "name": "batchWindow",
154
+ "inputs": [
155
+ {
156
+ "name": "batchId",
157
+ "type": "uint256",
158
+ "internalType": "uint256"
159
+ }
160
+ ],
161
+ "outputs": [
162
+ {
163
+ "name": "start",
164
+ "type": "uint256",
165
+ "internalType": "uint256"
166
+ },
167
+ {
168
+ "name": "end",
169
+ "type": "uint256",
170
+ "internalType": "uint256"
171
+ }
172
+ ],
173
+ "stateMutability": "view"
174
+ },
133
175
  {
134
176
  "type": "function",
135
177
  "name": "claim",
@@ -238,6 +280,19 @@ export const everyblockAbi = [
238
280
  ],
239
281
  "stateMutability": "nonpayable"
240
282
  },
283
+ {
284
+ "type": "function",
285
+ "name": "currentBatch",
286
+ "inputs": [],
287
+ "outputs": [
288
+ {
289
+ "name": "",
290
+ "type": "uint256",
291
+ "internalType": "uint256"
292
+ }
293
+ ],
294
+ "stateMutability": "view"
295
+ },
241
296
  {
242
297
  "type": "function",
243
298
  "name": "downBalance",
@@ -1358,6 +1413,11 @@ export const everyblockAbi = [
1358
1413
  "name": "AlreadyResolved",
1359
1414
  "inputs": []
1360
1415
  },
1416
+ {
1417
+ "type": "error",
1418
+ "name": "BadBatchSeconds",
1419
+ "inputs": []
1420
+ },
1361
1421
  {
1362
1422
  "type": "error",
1363
1423
  "name": "BadPrice",
package/dist/chain.js CHANGED
@@ -14,7 +14,7 @@ export const MONAD_MAINNET = 143;
14
14
  export const MONAD_TESTNET = 10143;
15
15
  /** The live Monad testnet deployment (docs/SUBMISSION.md, "Deployed contracts"). */
16
16
  export const TESTNET_RPC = "https://testnet-rpc.monad.xyz";
17
- export const TESTNET_EVERYBLOCK = "0x034ebcA29FcAdDF0F434Dd63C75e719b1dC62dB5";
17
+ export const TESTNET_EVERYBLOCK = "0x3aB7904B9Be8c70f2084082b0230238727cC8C3B";
18
18
  /** The hosted web app's proof endpoint for the testnet deployment. */
19
19
  export const TESTNET_PROOF_URL = "https://everyblock-gray.vercel.app/api/proof";
20
20
  export const ANVIL = 31337;
@@ -87,9 +87,11 @@ export async function connect(cfg) {
87
87
  account = cfg.unlockedAccount;
88
88
  }
89
89
  const wallet = account ? createWalletClient({ transport: http(cfg.rpcUrl) }) : null;
90
- const [collateral, cent] = await Promise.all([
90
+ const [collateral, cent, batchSeconds] = await Promise.all([
91
91
  pub.readContract({ address: cfg.everyblock, abi: everyblockAbi, functionName: "collateral" }),
92
92
  pub.readContract({ address: cfg.everyblock, abi: everyblockAbi, functionName: "CENT" }),
93
+ // Deployments from before batch windows have no BATCH_SECONDS: there a batch is one block.
94
+ pub.readContract({ address: cfg.everyblock, abi: everyblockAbi, functionName: "BATCH_SECONDS" }).catch(() => 0n),
93
95
  ]);
94
96
  const share = 100n * cent;
95
97
  const digits = String(share).length - 1;
@@ -112,6 +114,7 @@ export async function connect(cfg) {
112
114
  maxSpend,
113
115
  logRange: cfg.logRange,
114
116
  logLookback: cfg.logLookback,
117
+ batchSeconds: Number(batchSeconds),
115
118
  proofUrl: cfg.proofUrl === undefined ? (chainId === MONAD_TESTNET ? TESTNET_PROOF_URL : undefined) : cfg.proofUrl || undefined,
116
119
  queue: Promise.resolve(),
117
120
  };
@@ -200,3 +203,5 @@ export function reason(e) {
200
203
  }
201
204
  return e instanceof Error ? e.message.split("\n")[0] : String(e);
202
205
  }
206
+ /** The batch an order sent now joins: the time window, or the block on per-block deployments. */
207
+ export const batchAt = (ctx, t) => ctx.batchSeconds ? t.timestamp / BigInt(ctx.batchSeconds) : t.number;
package/dist/server.js CHANGED
@@ -3,15 +3,15 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { isAddress } from "viem";
4
4
  import { z } from "zod";
5
5
  import { everyblockAbi } from "./abi.js";
6
- import { FEED_NAMES, feeBps, MONAD_MAINNET, now, read, readToken, reason, send, serialize, writeBlocker, } from "./chain.js";
6
+ import { FEED_NAMES, feeBps, MONAD_MAINNET, now, read, readToken, reason, send, serialize, writeBlocker, batchAt, } from "./chain.js";
7
7
  import { centsToUsd, clearBatch, describeKind, escrowOf, feeOn, GRACE, isBid, kindOf, KINDS, marketStatus, meanPrice, OUTCOMES, ownPriceAt, priceOf, scenarios, tickOf, usd, WINDOW, } from "./orders.js";
8
8
  export const INSTRUCTIONS = `Everyblock runs short crypto UP/DOWN markets (e.g. "is BTC/USD higher at the close than at the open?") on Monad.
9
9
 
10
10
  How it works:
11
11
  - Each market has an open and a close time (5 minutes on the live schedule). The strike is the mean of 12 Pyth prices over the 60 s before the open; the closing price is the mean of 12 Pyth prices over the 60 s from the close. UP wins if the closing mean is above the strike, DOWN if below; a tie, or no proof within an hour, voids the market and every share redeems for $0.50.
12
12
  - A winning share pays $1.00. Prices are in cents (1-99): buying UP at 60 means paying at most $0.60 per share.
13
- - There is no continuous order book. All orders sent in the same block form one batch that clears at ONE uniform price after the block ends, so being first or fast in a block gives no advantage. Orders better than the clearing price fill fully, orders at it may fill pro rata, worse ones do not fill. Buyers never pay more than their limit and get back any price improvement.
14
- - Orders live for one block. After it, call claim with the order's nonce to collect the fill, the refund of anything unfilled and the price improvement. Claiming is required even if the order did not fill (that returns the escrow).
13
+ - There is no continuous order book. All orders sent in the same batch window (a few seconds: the contract's BATCH_SECONDS; one block on older deployments) form one batch that clears at ONE uniform price after the window ends, so being first or fast inside it gives no advantage. Orders better than the clearing price fill fully, orders at it may fill pro rata, worse ones do not fill. Buyers never pay more than their limit and get back any price improvement.
14
+ - Orders live for one batch. After its window ends, call claim with the order's nonce to collect the fill, the refund of anything unfilled and the price improvement. Claiming is required even if the order did not fill (that returns the escrow).
15
15
  - After a market resolves, call redeem to turn winning shares into collateral. Claim open orders first.
16
16
  - split turns $1 of collateral into 1 UP + 1 DOWN (needed before you can sell shares you do not own); merge does the reverse.
17
17
 
@@ -231,7 +231,7 @@ async function quote(ctx, a) {
231
231
  wallet,
232
232
  ok: problems.length === 0,
233
233
  problems,
234
- note: "The order joins the current block's batch and clears at one price for everyone once the block ends; you never pay more than your limit. Claim it with its nonce afterwards.",
234
+ note: "The order joins the current batch and clears at one price for everyone once the batch's window ends; you never pay more than your limit. Claim it with its nonce afterwards.",
235
235
  },
236
236
  };
237
237
  }
@@ -298,8 +298,8 @@ export function createServer(ctx) {
298
298
  }));
299
299
  server.registerTool("get_batch", {
300
300
  title: "Get batch",
301
- description: "The order book of one batch (a market's orders from one block, batchId = block number): size resting at each tick on each side, and the clearing result (price, volume, fills at the clearing tick). A batch not cleared yet shows the indicative clearing price.",
302
- inputSchema: { marketId: id.describe("Market id."), batchId: id.describe("Block number of the batch (from place_order or get_positions).") },
301
+ description: "The order book of one batch (a market's orders from one batch window: batchId = floor(time / BATCH_SECONDS), or the block number on older deployments): size resting at each tick on each side, and the clearing result (price, volume, fills at the clearing tick). A batch not cleared yet shows the indicative clearing price.",
302
+ inputSchema: { marketId: id.describe("Market id."), batchId: id.describe("The batch id (from place_order or get_positions).") },
303
303
  annotations: readOnly,
304
304
  }, guarded(async ({ marketId, batchId }) => ok(await batchView(ctx, BigInt(marketId), BigInt(batchId)))));
305
305
  server.registerTool("get_positions", {
@@ -354,7 +354,7 @@ export function createServer(ctx) {
354
354
  kind: KINDS[kind],
355
355
  limitCents: priceOf(kind, o.tick),
356
356
  size: o.size,
357
- status: cleared ? "cleared: claim it" : batchId === number ? "in the current block's batch" : "waiting to clear",
357
+ status: cleared ? "cleared: claim it" : BigInt(batchId) === batchAt(ctx, { timestamp, number }) ? "in the current batch" : "waiting to clear (claiming clears it)",
358
358
  claim,
359
359
  });
360
360
  }
@@ -400,7 +400,7 @@ export function createServer(ctx) {
400
400
  }, guarded(async (a) => ok((await quote(ctx, a)).view)));
401
401
  server.registerTool("place_order", {
402
402
  title: "Place order",
403
- description: "Sends a limit order into the current block's batch (one transaction; plus a collateral approval first if needed, capped at this server's per-call spend limit). Returns the tx hash, the order's nonce and batchId (block). The order lives one block: afterwards call claim with its nonce to collect fills and refunds. Refused if over the server's size or spend limits, on a chain not allowed for writes, or if the market is not trading.",
403
+ description: "Sends a limit order into the current batch (one transaction; plus a collateral approval first if needed, capped at this server's per-call spend limit). Returns the tx hash, the order's nonce and batchId. The order lives one batch: once its window ends, call claim with its nonce to collect fills and refunds. Refused if over the server's size or spend limits, on a chain not allowed for writes, or if the market is not trading.",
404
404
  inputSchema: orderShape,
405
405
  annotations: writes,
406
406
  }, guarded(async (a) => {
@@ -423,13 +423,13 @@ export function createServer(ctx) {
423
423
  approval,
424
424
  order: { ...q.view.order, nonce: ev?.nonce, batchId: ev?.batchId, upBookTick: ev?.tick },
425
425
  escrow: q.view.escrow,
426
- next: `Batch ${ev?.batchId} clears once its block has passed. Then call claim with nonces [${ev?.nonce}] (get_batch shows the clearing price).`,
426
+ next: `Batch ${ev?.batchId} clears once its window has passed${ctx.batchSeconds ? ` (${ctx.batchSeconds} s batches)` : ""}. Then call claim with nonces [${ev?.nonce}] (get_batch shows the clearing price).`,
427
427
  });
428
428
  });
429
429
  }));
430
430
  server.registerTool("claim", {
431
431
  title: "Claim orders",
432
- description: "Settles your orders whose batch has cleared (the block after they were placed or later): credits the UP/DOWN shares bought, pays the cash from sales, refunds anything unfilled plus price improvement. One transaction per nonce; returns each tx hash and what it paid. Order nonces come from place_order or get_positions.",
432
+ description: "Settles your orders whose batch window has ended (clearing the batch first if nobody has): credits the UP/DOWN shares bought, pays the cash from sales, refunds anything unfilled plus price improvement. One transaction per nonce; returns each tx hash and what it paid. Order nonces come from place_order or get_positions.",
433
433
  inputSchema: { nonces: z.array(z.number().int().min(0)).min(1).max(20).describe("Order nonces to claim.") },
434
434
  annotations: writes,
435
435
  }, guarded(async ({ nonces }) => {
@@ -613,8 +613,37 @@ export function createServer(ctx) {
613
613
  });
614
614
  });
615
615
  }));
616
+ server.registerTool("register_agent", {
617
+ title: "Register as an agent",
618
+ description: "Signs a message with this server's wallet saying it is an AI agent with the given name, and registers it with the Everyblock app, so the leaderboard shows the name with an Agent badge and in the Agents tab. Costs nothing (a signature, not a transaction). Run it again to change the name.",
619
+ inputSchema: { name: z.string().describe("2-32 characters: letters, digits, spaces, _ . or -. Shown on the leaderboard.") },
620
+ annotations: { ...writes, idempotentHint: true },
621
+ }, guarded(async ({ name }) => {
622
+ if (!ctx.wallet || !ctx.account || !ctx.address)
623
+ return fail("this server is read-only: set MCP_PRIVATE_KEY to register a wallet");
624
+ if (!ctx.proofUrl)
625
+ return fail("no app endpoint configured (set EVERYBLOCK_PROOF_URL to the app's /api/proof)");
626
+ const clean = name.trim();
627
+ if (!AGENT_NAME_RE.test(clean))
628
+ return fail("name must be 2-32 letters, digits, spaces, _ . or -");
629
+ const message = `Register on Everyblock as an AI agent\nName: ${clean}\nAddress: ${ctx.address.toLowerCase()}`;
630
+ const signature = await ctx.wallet.signMessage({ account: ctx.account, message });
631
+ const url = new URL("/api/agents", ctx.proofUrl).toString();
632
+ const res = await fetch(url, {
633
+ method: "POST",
634
+ headers: { "content-type": "application/json" },
635
+ body: JSON.stringify({ address: ctx.address, name: clean, signature }),
636
+ signal: AbortSignal.timeout(20_000),
637
+ });
638
+ const body = (await res.json().catch(() => ({})));
639
+ if (!res.ok)
640
+ return fail(`registry: ${body.error ?? `HTTP ${res.status}`}`);
641
+ return ok({ registered: true, agent: body.agent, leaderboard: new URL("/leaderboard", ctx.proofUrl).toString() });
642
+ }));
616
643
  return server;
617
644
  }
645
+ /** Mirrors web/lib/agents.ts NAME_RE; the app checks again. The signed message must match agentMessage() there. */
646
+ const AGENT_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9 _.\-]{1,31}$/;
618
647
  const PYTH_FEE_ABI = [
619
648
  {
620
649
  type: "function",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "everyblock-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "MCP server that lets any AI agent read, quote and trade Everyblock's per-block UP/DOWN markets.",
6
6
  "engines": {