everyblock-mcp 0.5.2 → 0.6.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 +1 -1
- package/dist/abi.js +50 -1
- package/dist/chain.js +5 -4
- package/dist/market.js +31 -0
- package/dist/server.js +7 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ With neither `RPC_URL` nor `EVERYBLOCK` set it talks to the live Monad testnet d
|
|
|
30
30
|
| `cancel_quote` | yes | Takes a quote off (not during the window it sits in) and credits what it holds. |
|
|
31
31
|
| `withdraw_quote_cash` | yes | Collects the cash a market's quotes earned. |
|
|
32
32
|
| `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. |
|
|
33
|
-
| `settle` | yes | Proves a market's price to beat and/or its result with signed
|
|
33
|
+
| `settle` | yes | Proves a market's price to beat and/or its result with signed oracle prices from the app's `/api/proof` (RedStone on testnet, Pyth on mainnet; no key needed), paying the oracle's update fee if it has one. |
|
|
34
34
|
|
|
35
35
|
Every write returns the transaction hash and the decoded result (events and amounts). Writes run one at a time.
|
|
36
36
|
|
package/dist/abi.js
CHANGED
|
@@ -553,6 +553,11 @@ export const everyblockAbi = [
|
|
|
553
553
|
"type": "int32",
|
|
554
554
|
"internalType": "int32"
|
|
555
555
|
},
|
|
556
|
+
{
|
|
557
|
+
"name": "feeBps",
|
|
558
|
+
"type": "uint16",
|
|
559
|
+
"internalType": "uint16"
|
|
560
|
+
},
|
|
556
561
|
{
|
|
557
562
|
"name": "strikeSum",
|
|
558
563
|
"type": "int128",
|
|
@@ -750,7 +755,7 @@ export const everyblockAbi = [
|
|
|
750
755
|
"name": "marketFeeBps",
|
|
751
756
|
"inputs": [
|
|
752
757
|
{
|
|
753
|
-
"name": "",
|
|
758
|
+
"name": "marketId",
|
|
754
759
|
"type": "uint256",
|
|
755
760
|
"internalType": "uint256"
|
|
756
761
|
}
|
|
@@ -788,6 +793,19 @@ export const everyblockAbi = [
|
|
|
788
793
|
],
|
|
789
794
|
"stateMutability": "view"
|
|
790
795
|
},
|
|
796
|
+
{
|
|
797
|
+
"type": "function",
|
|
798
|
+
"name": "maxOrderSize",
|
|
799
|
+
"inputs": [],
|
|
800
|
+
"outputs": [
|
|
801
|
+
{
|
|
802
|
+
"name": "",
|
|
803
|
+
"type": "uint64",
|
|
804
|
+
"internalType": "uint64"
|
|
805
|
+
}
|
|
806
|
+
],
|
|
807
|
+
"stateMutability": "view"
|
|
808
|
+
},
|
|
791
809
|
{
|
|
792
810
|
"type": "function",
|
|
793
811
|
"name": "merge",
|
|
@@ -1119,6 +1137,19 @@ export const everyblockAbi = [
|
|
|
1119
1137
|
"outputs": [],
|
|
1120
1138
|
"stateMutability": "nonpayable"
|
|
1121
1139
|
},
|
|
1140
|
+
{
|
|
1141
|
+
"type": "function",
|
|
1142
|
+
"name": "setMaxOrderSize",
|
|
1143
|
+
"inputs": [
|
|
1144
|
+
{
|
|
1145
|
+
"name": "size",
|
|
1146
|
+
"type": "uint64",
|
|
1147
|
+
"internalType": "uint64"
|
|
1148
|
+
}
|
|
1149
|
+
],
|
|
1150
|
+
"outputs": [],
|
|
1151
|
+
"stateMutability": "nonpayable"
|
|
1152
|
+
},
|
|
1122
1153
|
{
|
|
1123
1154
|
"type": "function",
|
|
1124
1155
|
"name": "setStrike",
|
|
@@ -1415,6 +1446,19 @@ export const everyblockAbi = [
|
|
|
1415
1446
|
],
|
|
1416
1447
|
"anonymous": false
|
|
1417
1448
|
},
|
|
1449
|
+
{
|
|
1450
|
+
"type": "event",
|
|
1451
|
+
"name": "MaxOrderSizeUpdated",
|
|
1452
|
+
"inputs": [
|
|
1453
|
+
{
|
|
1454
|
+
"name": "maxOrderSize",
|
|
1455
|
+
"type": "uint64",
|
|
1456
|
+
"indexed": false,
|
|
1457
|
+
"internalType": "uint64"
|
|
1458
|
+
}
|
|
1459
|
+
],
|
|
1460
|
+
"anonymous": false
|
|
1461
|
+
},
|
|
1418
1462
|
{
|
|
1419
1463
|
"type": "event",
|
|
1420
1464
|
"name": "Merged",
|
|
@@ -1942,6 +1986,11 @@ export const everyblockAbi = [
|
|
|
1942
1986
|
"name": "SettlementClosed",
|
|
1943
1987
|
"inputs": []
|
|
1944
1988
|
},
|
|
1989
|
+
{
|
|
1990
|
+
"type": "error",
|
|
1991
|
+
"name": "SizeAboveCap",
|
|
1992
|
+
"inputs": []
|
|
1993
|
+
},
|
|
1945
1994
|
{
|
|
1946
1995
|
"type": "error",
|
|
1947
1996
|
"name": "StrikeAlreadySet",
|
package/dist/chain.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { BaseError, ContractFunctionRevertedError, createPublicClient, createWalletClient, defineChain, http, parseAbi, parseEventLogs, parseUnits, } from "viem";
|
|
4
4
|
import { privateKeyToAccount } from "viem/accounts";
|
|
5
5
|
import { everyblockAbi, testUsdAbi } from "./abi.js";
|
|
6
|
+
import { readMarket } from "./market.js";
|
|
6
7
|
export const FEED_NAMES = {
|
|
7
8
|
"0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43": "BTC/USD",
|
|
8
9
|
"0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace": "ETH/USD",
|
|
@@ -14,7 +15,7 @@ export const MONAD_MAINNET = 143;
|
|
|
14
15
|
const MONAD_TESTNET = 10143;
|
|
15
16
|
/** The live Monad testnet deployment (docs/SUBMISSION.md, "Deployed contracts"). */
|
|
16
17
|
const TESTNET_RPC = "https://testnet-rpc.monad.xyz";
|
|
17
|
-
const TESTNET_EVERYBLOCK = "
|
|
18
|
+
const TESTNET_EVERYBLOCK = "0x7580F8f3094D3e9067942D08997096AA23A1bD22";
|
|
18
19
|
/** The hosted web app's proof endpoint for the testnet deployment. */
|
|
19
20
|
const TESTNET_PROOF_URL = "https://everyblock-gray.vercel.app/api/proof";
|
|
20
21
|
const ANVIL = 31337;
|
|
@@ -33,8 +34,8 @@ const isLocalRpc = (url) => /^https?:\/\/(127\.0\.0\.1|localhost)(:|\/|$)/.test(
|
|
|
33
34
|
* MCP_MAX_SPEND_USD collateral one write call may commit, in dollars (default 50)
|
|
34
35
|
* FEEDS comma-separated Pyth feed ids (default BTC, ETH, SOL, MON)
|
|
35
36
|
* MCP_LOG_RANGE, MCP_LOG_LOOKBACK blocks per eth_getLogs call (100) and how far back to look (2000)
|
|
36
|
-
* EVERYBLOCK_PROOF_URL the web app's /api/proof, where `settle` gets signed
|
|
37
|
-
* key of its own (default on Monad testnet: the hosted app; set "" to disable)
|
|
37
|
+
* EVERYBLOCK_PROOF_URL the web app's /api/proof, where `settle` gets signed oracle prices without an
|
|
38
|
+
* oracle key of its own (default on Monad testnet: the hosted app; set "" to disable)
|
|
38
39
|
*/
|
|
39
40
|
export function configFromEnv(env = process.env) {
|
|
40
41
|
const need = (name) => {
|
|
@@ -220,7 +221,7 @@ const CLEAR_MARGIN_S = 2n;
|
|
|
220
221
|
async function lazyClearGas(ctx, marketId) {
|
|
221
222
|
if (!ctx.batchSeconds)
|
|
222
223
|
return 0n;
|
|
223
|
-
const [m, block] = await Promise.all([
|
|
224
|
+
const [m, block] = await Promise.all([readMarket(ctx.pub, ctx.everyblock, marketId), ctx.pub.getBlock({ blockTag: "latest" })]);
|
|
224
225
|
const pending = BigInt(m.pendingBatch);
|
|
225
226
|
const end = (pending + 1n) * BigInt(ctx.batchSeconds);
|
|
226
227
|
if (pending === 0n || block.timestamp >= end || end - block.timestamp > CLEAR_MARGIN_S)
|
package/dist/market.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// getMarket on any deployment. The market fee moved into the market header (`feeBps`) on 3 Oct, after the 30 Sep
|
|
2
|
+
// testnet deployment, which still returns the struct without it; decoding that with the current ABI runs off the end
|
|
3
|
+
// of the data. So the first read of a contract tries the current layout, falls back to the old one only on that
|
|
4
|
+
// overrun, and remembers which it has. The same fallback is in web/lib/market.ts.
|
|
5
|
+
import { BaseError, parseAbi } from "viem";
|
|
6
|
+
import { everyblockAbi } from "./abi.js";
|
|
7
|
+
const legacyAbi = parseAbi([
|
|
8
|
+
"struct Market { bytes32 feedId; uint64 openTime; uint64 closeTime; uint64 pendingBatch; uint8 outcome; bool strikeSet; int32 expo; int128 strikeSum; int128 closeSum; }",
|
|
9
|
+
"function getMarket(uint256 marketId) view returns (Market)",
|
|
10
|
+
]);
|
|
11
|
+
/** Per contract: true once it is known to return the pre-3-Oct struct, false once it is known not to. */
|
|
12
|
+
const legacy = new Map();
|
|
13
|
+
const overran = (e) => e instanceof BaseError && !!e.walk((x) => x.name === "PositionOutOfBoundsError");
|
|
14
|
+
/** The market struct, without `feeBps` on old deployments; typed loosely like the other reads. */
|
|
15
|
+
export async function readMarket(pub, address, marketId) {
|
|
16
|
+
const key = address.toLowerCase();
|
|
17
|
+
if (legacy.get(key) !== true) {
|
|
18
|
+
try {
|
|
19
|
+
const m = await pub.readContract({ address, abi: everyblockAbi, functionName: "getMarket", args: [marketId] });
|
|
20
|
+
legacy.set(key, false);
|
|
21
|
+
return m;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (legacy.get(key) === false || !overran(e))
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const m = await pub.readContract({ address, abi: legacyAbi, functionName: "getMarket", args: [marketId] });
|
|
29
|
+
legacy.set(key, true);
|
|
30
|
+
return m;
|
|
31
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -4,11 +4,12 @@ import { isAddress } from "viem";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { everyblockAbi } from "./abi.js";
|
|
6
6
|
import { FEED_NAMES, feeBps, MONAD_MAINNET, now, read, readToken, reason, send, serialize, writeBlocker, batchAt, } from "./chain.js";
|
|
7
|
+
import { readMarket } from "./market.js";
|
|
7
8
|
import { centsToUsd, clearBatch, describeKind, escrowOf, feeOn, GRACE, isBid, kindOf, KINDS, marketStatus, meanPrice, OUTCOMES, ownPriceAt, priceOf, scenarios, tickOf, usd, WINDOW, } from "./orders.js";
|
|
8
9
|
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
10
|
|
|
10
11
|
How it works:
|
|
11
|
-
- Each market has an open and a close time (5 minutes on the live schedule). The strike is the mean of 12
|
|
12
|
+
- Each market has an open and a close time (5 minutes on the live schedule). The strike is the mean of 12 signed oracle prices over the 60 s before the open (RedStone on testnet, Pyth on mainnet); the closing price is the mean of 12 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
13
|
- 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
14
|
- 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
15
|
- 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).
|
|
@@ -64,7 +65,7 @@ async function lastClearing(ctx, marketId, latest) {
|
|
|
64
65
|
}
|
|
65
66
|
async function marketView(ctx, marketId, t, latestBlock) {
|
|
66
67
|
const [m, outcome, fee] = await Promise.all([
|
|
67
|
-
|
|
68
|
+
readMarket(ctx.pub, ctx.everyblock, marketId),
|
|
68
69
|
read(ctx, "outcome", [marketId]),
|
|
69
70
|
feeBps(ctx, marketId),
|
|
70
71
|
]);
|
|
@@ -173,7 +174,7 @@ async function quote(ctx, a) {
|
|
|
173
174
|
const kind = kindOf(a.side, a.outcome);
|
|
174
175
|
const { timestamp } = await now(ctx);
|
|
175
176
|
const [m, outcome, fee] = await Promise.all([
|
|
176
|
-
|
|
177
|
+
readMarket(ctx.pub, ctx.everyblock, marketId),
|
|
177
178
|
read(ctx, "outcome", [marketId]),
|
|
178
179
|
feeBps(ctx, marketId),
|
|
179
180
|
]);
|
|
@@ -587,7 +588,7 @@ export function createServer(ctx) {
|
|
|
587
588
|
}));
|
|
588
589
|
server.registerTool("settle", {
|
|
589
590
|
title: "Prove the price to beat or the result",
|
|
590
|
-
description: "Submits the signed
|
|
591
|
+
description: "Submits the signed oracle prices (RedStone on testnet, Pyth on mainnet) that set a market's strike (after its open) or resolve it (about 75 s after its close), when no keeper has. Anyone may do this; it costs gas plus the oracle's update fee, if any (Pyth's is tiny, RedStone's is 0). The prices come from the Everyblock app's proof endpoint, so no oracle key is needed. Proves the strike first if it is missing.",
|
|
591
592
|
inputSchema: {
|
|
592
593
|
marketId: id.describe("Market id."),
|
|
593
594
|
what: z.enum(["strike", "result"]).optional().describe("strike: only the price to beat. result (default): the result, and the strike first if missing."),
|
|
@@ -599,7 +600,7 @@ export function createServer(ctx) {
|
|
|
599
600
|
return fail(blocked);
|
|
600
601
|
if (!ctx.proofUrl)
|
|
601
602
|
return fail("no proof endpoint configured (set EVERYBLOCK_PROOF_URL to the app's /api/proof)");
|
|
602
|
-
const m = (await
|
|
603
|
+
const m = (await readMarket(ctx.pub, ctx.everyblock, BigInt(marketId)));
|
|
603
604
|
if (m.outcome !== 0)
|
|
604
605
|
return ok({ settled: false, alreadyResolved: true, marketId });
|
|
605
606
|
const steps = what === "strike" ? (m.strikeSet ? [] : ["strike"]) : m.strikeSet ? ["close"] : ["strike", "close"];
|
|
@@ -619,7 +620,7 @@ export function createServer(ctx) {
|
|
|
619
620
|
const sent = await send(ctx, "everyblock", w === "strike" ? "setStrike" : "resolve", [BigInt(marketId), body.updates], fee);
|
|
620
621
|
done.push({ step: w === "strike" ? "strike" : "result", ...tx(sent) });
|
|
621
622
|
}
|
|
622
|
-
const after = (await
|
|
623
|
+
const after = (await readMarket(ctx.pub, ctx.everyblock, BigInt(marketId)));
|
|
623
624
|
return ok({
|
|
624
625
|
settled: true,
|
|
625
626
|
marketId,
|