fusebox-mcp 0.0.0-stage → 0.2.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 +49 -2
- package/abi.json +1 -0
- package/index.mjs +146 -0
- package/package.json +38 -4
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# fusebox-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
MCP tools for an AI agent that pays through a [Fusebox](https://fusebox-xlayer.vercel.app) wallet on X Layer. Every payment runs through the wallet's fuses (TapeOut logic circuits on X Layer), and it only goes out if every fuse says yes.
|
|
4
|
+
|
|
5
|
+
| Tool | What it does |
|
|
6
|
+
|---|---|
|
|
7
|
+
| `fusebox_check` | Dry-runs a payment against every fuse and returns each verdict with its reason. It's free and read-only. |
|
|
8
|
+
| `fusebox_pay` | Pays in USDT0 through the fuses with the agent's key, and reports paid or stopped, which fuse said no, the fee and the transaction link. |
|
|
9
|
+
| `fusebox_status` | Returns the wallet's balance, prepaid fee balance, fuses (and whether any is blown), today's spend and the decision counts. |
|
|
10
|
+
|
|
11
|
+
Without a key the server is read-only, and by default it points at **Atlas**, the public demo wallet, so you can try `fusebox_check` right away.
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
**Claude Code**
|
|
16
|
+
```bash
|
|
17
|
+
claude mcp add fusebox -- npx -y fusebox-mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Claude Desktop, Cursor, Hermes, or any MCP client** (stdio):
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"fusebox": {
|
|
25
|
+
"command": "npx",
|
|
26
|
+
"args": ["-y", "fusebox-mcp"],
|
|
27
|
+
"env": {
|
|
28
|
+
"FUSEBOX_WALLET": "0xYourFuseboxWallet",
|
|
29
|
+
"FUSEBOX_AGENT_KEY": "0xYourAgentPrivateKey"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Variable | Default | Meaning |
|
|
37
|
+
|---|---|---|
|
|
38
|
+
| `FUSEBOX_WALLET` | Atlas `0x0Db0…6800` | The Fusebox wallet the agent pays from. Create one at [fusebox-xlayer.vercel.app/app/new](https://fusebox-xlayer.vercel.app/app/new). |
|
|
39
|
+
| `FUSEBOX_AGENT_KEY` | none (read-only) | The agent key you named when you wired up the wallet. It can only ask the wallet to pay; it can't change a fuse, a limit or a payee. |
|
|
40
|
+
| `FUSEBOX_RPC` | `https://rpc.xlayer.tech` | An X Layer RPC. |
|
|
41
|
+
|
|
42
|
+
## Try it
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
claude mcp add fusebox -- npx -y fusebox-mcp # read-only, against Atlas on X Layer mainnet
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Ask your agent: *"Pay 2.5 USDT0 to 0x1111…1111, it's an urgent refund."* It calls `fusebox_check` first, sees Payee Guard and the Breaker say no, and tells you why. No money moves.
|
|
49
|
+
|
|
50
|
+
When the wallet's Two of Three fuse is the only one saying no, `fusebox_check` and `fusebox_pay` return an `approval_url`: the page where two of the wallet's approvers sign that exact payment, after which the agent can retry. A wallet whose prepaid fee balance can't cover one decision is reported plainly instead of sending a transaction that would revert. Set `FUSEBOX_APP` to point the links at another deployment.
|
package/abi.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"wallet": [{"type": "function", "name": "allowedCount", "inputs": [], "outputs": [{"name": "", "type": "uint64", "internalType": "uint64"}], "stateMutability": "view"}, {"type": "function", "name": "approvalMaskOf", "inputs": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "amount", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "uint8", "internalType": "uint8"}], "stateMutability": "view"}, {"type": "function", "name": "blockedCount", "inputs": [], "outputs": [{"name": "", "type": "uint64", "internalType": "uint64"}], "stateMutability": "view"}, {"type": "function", "name": "check", "inputs": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "amount", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "allowed", "type": "bool", "internalType": "bool"}, {"name": "status", "type": "uint8[]", "internalType": "uint8[]"}, {"name": "inputs", "type": "bytes[]", "internalType": "bytes[]"}, {"name": "outputs", "type": "bytes[]", "internalType": "bytes[]"}], "stateMutability": "view"}, {"type": "function", "name": "decisionCount", "inputs": [], "outputs": [{"name": "", "type": "uint64", "internalType": "uint64"}], "stateMutability": "view"}, {"type": "function", "name": "fuseCount", "inputs": [], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "isAgent", "inputs": [{"name": "", "type": "address", "internalType": "address"}], "outputs": [{"name": "", "type": "bool", "internalType": "bool"}], "stateMutability": "view"}, {"type": "function", "name": "owner", "inputs": [], "outputs": [{"name": "", "type": "address", "internalType": "address"}], "stateMutability": "view"}, {"type": "function", "name": "paused", "inputs": [], "outputs": [{"name": "", "type": "bool", "internalType": "bool"}], "stateMutability": "view"}, {"type": "function", "name": "pay", "inputs": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "to", "type": "address", "internalType": "address"}, {"name": "amount", "type": "uint256", "internalType": "uint256"}, {"name": "memo", "type": "string", "internalType": "string"}], "outputs": [{"name": "allowed", "type": "bool", "internalType": "bool"}, {"name": "decisionId", "type": "uint256", "internalType": "uint256"}], "stateMutability": "nonpayable"}, {"type": "function", "name": "payeeAddedAt", "inputs": [{"name": "payee", "type": "address", "internalType": "address"}], "outputs": [{"name": "addedAt", "type": "uint64", "internalType": "uint64"}], "stateMutability": "view"}, {"type": "function", "name": "registry", "inputs": [], "outputs": [{"name": "", "type": "address", "internalType": "contract FuseRegistry"}], "stateMutability": "view"}, {"type": "function", "name": "slotAt", "inputs": [{"name": "slot", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "tuple", "internalType": "struct FuseboxWallet.Slot", "components": [{"name": "fuseId", "type": "uint256", "internalType": "uint256"}, {"name": "processor", "type": "address", "internalType": "address"}, {"name": "circuitId", "type": "uint64", "internalType": "uint64"}, {"name": "socket", "type": "uint32", "internalType": "uint32"}, {"name": "nOut", "type": "uint32", "internalType": "uint32"}, {"name": "nState", "type": "uint32", "internalType": "uint32"}, {"name": "maxFee", "type": "uint96", "internalType": "uint96"}, {"name": "params", "type": "tuple", "internalType": "struct Sockets.Params", "components": [{"name": "token", "type": "address", "internalType": "address"}, {"name": "unit", "type": "uint128", "internalType": "uint128"}, {"name": "a", "type": "uint8", "internalType": "uint8"}, {"name": "b", "type": "uint8", "internalType": "uint8"}]}, {"name": "spentDay", "type": "uint32", "internalType": "uint32"}, {"name": "spent", "type": "uint256", "internalType": "uint256"}, {"name": "state", "type": "bytes", "internalType": "bytes"}]}], "stateMutability": "view"}, {"type": "function", "name": "spentToday", "inputs": [{"name": "slot", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "event", "name": "Decision", "inputs": [{"name": "decisionId", "type": "uint256", "indexed": true, "internalType": "uint256"}, {"name": "agent", "type": "address", "indexed": true, "internalType": "address"}, {"name": "to", "type": "address", "indexed": true, "internalType": "address"}, {"name": "token", "type": "address", "indexed": false, "internalType": "address"}, {"name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256"}, {"name": "allowed", "type": "bool", "indexed": false, "internalType": "bool"}, {"name": "fuseIds", "type": "uint256[]", "indexed": false, "internalType": "uint256[]"}, {"name": "status", "type": "uint8[]", "indexed": false, "internalType": "uint8[]"}, {"name": "inputs", "type": "bytes[]", "indexed": false, "internalType": "bytes[]"}, {"name": "outputs", "type": "bytes[]", "indexed": false, "internalType": "bytes[]"}, {"name": "feePaid", "type": "uint256", "indexed": false, "internalType": "uint256"}, {"name": "intent", "type": "bytes32", "indexed": false, "internalType": "bytes32"}, {"name": "memo", "type": "string", "indexed": false, "internalType": "string"}], "anonymous": false}, {"type": "event", "name": "FuseBlew", "inputs": [{"name": "decisionId", "type": "uint256", "indexed": true, "internalType": "uint256"}, {"name": "fuseId", "type": "uint256", "indexed": true, "internalType": "uint256"}, {"name": "slot", "type": "uint256", "indexed": false, "internalType": "uint256"}, {"name": "status", "type": "uint8", "indexed": false, "internalType": "uint8"}], "anonymous": false}], "registry": [{"type": "function", "name": "feeBalance", "inputs": [{"name": "account", "type": "address", "internalType": "address"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "feeOf", "inputs": [{"name": "fuseId", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "", "type": "uint256", "internalType": "uint256"}], "stateMutability": "view"}, {"type": "function", "name": "fuse", "inputs": [{"name": "fuseId", "type": "uint256", "internalType": "uint256"}], "outputs": [{"name": "f", "type": "tuple", "internalType": "struct FuseRegistry.Fuse", "components": [{"name": "processor", "type": "address", "internalType": "address"}, {"name": "circuitId", "type": "uint64", "internalType": "uint64"}, {"name": "socket", "type": "uint32", "internalType": "uint32"}, {"name": "nIn", "type": "uint32", "internalType": "uint32"}, {"name": "nOut", "type": "uint32", "internalType": "uint32"}, {"name": "nState", "type": "uint32", "internalType": "uint32"}, {"name": "gateCount", "type": "uint32", "internalType": "uint32"}, {"name": "fee", "type": "uint96", "internalType": "uint96"}, {"name": "listed", "type": "bool", "internalType": "bool"}, {"name": "listedAt", "type": "uint64", "internalType": "uint64"}, {"name": "netlistHash", "type": "bytes32", "internalType": "bytes32"}]}], "stateMutability": "view"}]}
|
package/index.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// fusebox-mcp: MCP tools for an AI agent that pays through a Fusebox wallet on X Layer.
|
|
3
|
+
// fusebox_check dry-run a payment against every fuse (free, read-only)
|
|
4
|
+
// fusebox_pay pay through the fuses with the agent key (needs FUSEBOX_AGENT_KEY)
|
|
5
|
+
// fusebox_status the wallet's balance, fee balance, fuses and today's spend
|
|
6
|
+
// Env: FUSEBOX_WALLET (default: Atlas, the public demo wallet), FUSEBOX_AGENT_KEY (optional; without it the
|
|
7
|
+
// server is read-only), FUSEBOX_RPC (default https://rpc.xlayer.tech).
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { createPublicClient, createWalletClient, decodeEventLog, defineChain, formatUnits, getAddress, http, isAddress, parseUnits } from "viem";
|
|
13
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
14
|
+
|
|
15
|
+
const ABI = JSON.parse(readFileSync(new URL("./abi.json", import.meta.url), "utf8"));
|
|
16
|
+
const ATLAS = "0x0Db0457715a6445D8a65F820d717a6B39Be66800";
|
|
17
|
+
const USDT0 = "0x779Ded0c9e1022225f8E0630b35a9b54bE713736";
|
|
18
|
+
const RPC = process.env.FUSEBOX_RPC || "https://rpc.xlayer.tech";
|
|
19
|
+
const WALLET = getAddress(process.env.FUSEBOX_WALLET || ATLAS);
|
|
20
|
+
const KEY = process.env.FUSEBOX_AGENT_KEY;
|
|
21
|
+
const EXPLORER = "https://www.oklink.com/xlayer";
|
|
22
|
+
const APP = process.env.FUSEBOX_APP || "https://fusebox-xlayer.vercel.app";
|
|
23
|
+
/** where the wallet's approvers sign this exact payment (Two of Three) */
|
|
24
|
+
const approvalUrl = (to, amount) => `${APP}/app/approve?wallet=${WALLET}&to=${to}&amount=${amount}`;
|
|
25
|
+
const chain = defineChain({ id: 196, name: "X Layer", nativeCurrency: { name: "OKB", symbol: "OKB", decimals: 18 }, rpcUrls: { default: { http: [RPC] } }, contracts: { multicall3: { address: "0xcA11bde05977b3631167028862bE2a173976CA11" } } });
|
|
26
|
+
const pub = createPublicClient({ chain, transport: http(RPC), batch: { multicall: true } });
|
|
27
|
+
const agent = KEY ? privateKeyToAccount(KEY.startsWith("0x") ? KEY : `0x${KEY}`) : null;
|
|
28
|
+
const signer = agent ? createWalletClient({ chain, transport: http(RPC), account: agent }) : null;
|
|
29
|
+
const erc20 = [{ type: "function", name: "balanceOf", stateMutability: "view", inputs: [{ name: "a", type: "address" }], outputs: [{ type: "uint256" }] }];
|
|
30
|
+
const SOCKET = { 1: ["daily-cap", "Daily Cap"], 2: ["payee-guard", "Payee Guard"], 3: ["breaker", "Breaker"], 4: ["approval-2of3", "Two of Three"] };
|
|
31
|
+
const STATUS = ["pass", "blew", "failed", "untrusted"];
|
|
32
|
+
const W = { address: WALLET, abi: ABI.wallet };
|
|
33
|
+
const usd = (v) => formatUnits(v, 6);
|
|
34
|
+
|
|
35
|
+
async function fuses() {
|
|
36
|
+
const n = Number(await pub.readContract({ ...W, functionName: "fuseCount" }));
|
|
37
|
+
return Promise.all(Array.from({ length: n }, async (_, i) => {
|
|
38
|
+
const s = await pub.readContract({ ...W, functionName: "slotAt", args: [BigInt(i)] });
|
|
39
|
+
const registry = await pub.readContract({ ...W, functionName: "registry" });
|
|
40
|
+
const [spent, fee] = await Promise.all([
|
|
41
|
+
pub.readContract({ ...W, functionName: "spentToday", args: [BigInt(i)] }),
|
|
42
|
+
pub.readContract({ address: registry, abi: ABI.registry, functionName: "feeOf", args: [s.fuseId] }).catch(() => s.maxFee),
|
|
43
|
+
]);
|
|
44
|
+
const [key, name] = SOCKET[Number(s.socket)] ?? [`socket-${s.socket}`, `Fuse ${i + 1}`];
|
|
45
|
+
// what a check of this fuse costs: the lower of the designer's fee and the one the owner accepted
|
|
46
|
+
const feeCap = Number(usd(fee < s.maxFee ? fee : s.maxFee));
|
|
47
|
+
return { slot: i, key, name, circuitId: Number(s.circuitId), processor: s.processor, a: Number(s.params.a), b: Number(s.params.b), latched: s.nState > 0 && s.state !== "0x" && BigInt(s.state) !== 0n, spentToday: Number(usd(spent)), feeCap };
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Why each fuse answered the way it did, in plain words. */
|
|
52
|
+
async function explain(fs, status, to, amount) {
|
|
53
|
+
const [since, mask] = await Promise.all([
|
|
54
|
+
pub.readContract({ ...W, functionName: "payeeAddedAt", args: [to] }),
|
|
55
|
+
pub.readContract({ ...W, functionName: "approvalMaskOf", args: [USDT0, to, amount] }),
|
|
56
|
+
]);
|
|
57
|
+
const amt = Number(usd(amount)), hours = since ? (Date.now() / 1000 - Number(since)) / 3600 : 0;
|
|
58
|
+
const approvals = [0, 1, 2].filter((b) => (Number(mask) >> b) & 1).length;
|
|
59
|
+
return fs.map((f, i) => {
|
|
60
|
+
const st = STATUS[status[i]] ?? "failed", ok = st === "pass";
|
|
61
|
+
let why;
|
|
62
|
+
if (st === "failed") why = "the circuit call failed, so the fuse fails closed";
|
|
63
|
+
else if (st === "untrusted") why = "TapeOut's processor code changed and isn't attested, so the fuse fails closed";
|
|
64
|
+
else if (f.key === "daily-cap") why = ok ? `within today's cap (${Math.max(0, f.a - f.spentToday)} of ${f.a} USDT0 left)` : `${amt} USDT0 would pass today's ${f.a} USDT0 cap (${f.spentToday} spent)`;
|
|
65
|
+
else if (f.key === "payee-guard") why = ok ? (since && hours >= f.a ? "a saved payee, past its cooling-off" : `saved ${hours.toFixed(1)} h ago, still cooling off, but ${amt} USDT0 is within the ${f.b} USDT0 trial`) : !since ? "not a saved payee" : `saved ${hours.toFixed(1)} h ago and still cooling off (${f.a} h); ${amt} USDT0 is over the ${f.b} USDT0 trial`;
|
|
66
|
+
else if (f.key === "breaker") why = f.latched ? "already blown; nothing pays until the owner resets it" : ok ? "not tripped" : "a payment to a stranger trips it, and it stays blown until the owner resets it";
|
|
67
|
+
else if (f.key === "approval-2of3") why = ok ? (amt > f.a ? `over ${f.a} USDT0 and approved by ${approvals} of 3` : `under the ${f.a} USDT0 approval threshold`) : `over ${f.a} USDT0: needs two of three approvers, has ${approvals}`;
|
|
68
|
+
return { fuse: f.name, circuit: `#${f.circuitId}`, verdict: ok ? "holds" : "blew", why };
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const parseTo = (to) => { if (!isAddress(to, { strict: false })) throw new Error(`"${to}" isn't a valid 0x address.`); return getAddress(to.toLowerCase()); };
|
|
73
|
+
const parseAmount = (a) => { if (!/^\d{1,9}(\.\d{1,6})?$/.test(String(a)) || Number(a) <= 0) throw new Error(`"${a}" isn't an amount above 0 with up to 6 decimals.`); return parseUnits(String(a), 6); };
|
|
74
|
+
const text = (obj, summary) => ({ content: [{ type: "text", text: `${summary}\n\n${JSON.stringify(obj, null, 2)}` }], structuredContent: obj });
|
|
75
|
+
const fail = (e) => ({ isError: true, content: [{ type: "text", text: e.message || String(e) }] });
|
|
76
|
+
|
|
77
|
+
const server = new McpServer({ name: "fusebox", version: "0.2.0" });
|
|
78
|
+
|
|
79
|
+
server.registerTool("fusebox_check", {
|
|
80
|
+
title: "Check a payment against the fuses",
|
|
81
|
+
description: `Dry-run a USDT0 payment from the Fusebox wallet ${WALLET} on X Layer. Every fuse (TapeOut circuits) answers yes or no, with the reason. Free and read-only; nothing moves. Call this before fusebox_pay: a blocked payment still costs fees and can blow the Breaker.`,
|
|
82
|
+
inputSchema: { to: z.string().describe("Payee address (0x…)"), amount: z.string().describe("Amount in USDT0, e.g. \"2.5\"") },
|
|
83
|
+
}, async ({ to, amount }) => {
|
|
84
|
+
try {
|
|
85
|
+
const payee = parseTo(to), amt = parseAmount(amount);
|
|
86
|
+
const [[allowed, status], fs, block] = await Promise.all([pub.readContract({ ...W, functionName: "check", args: [USDT0, payee, amt] }), fuses(), pub.getBlockNumber()]);
|
|
87
|
+
const verdicts = await explain(fs, status, payee, amt);
|
|
88
|
+
const no = verdicts.filter((v) => v.verdict === "blew");
|
|
89
|
+
const needs = !allowed && fs.some((f, i) => f.key === "approval-2of3" && verdicts[i].verdict === "blew");
|
|
90
|
+
const summary = allowed ? `Every fuse holds: the wallet would pay ${amount} USDT0 to ${payee}.` : `Stopped: ${no.map((v) => `${v.fuse} (${v.why})`).join("; ")}. Nothing would move.${needs && no.length === 1 ? ` Two of the wallet's approvers can sign this exact payment at ${approvalUrl(payee, amount)}; retry once they have.` : ""}`;
|
|
91
|
+
return text({ allowed, wallet: WALLET, to: payee, amount, block: Number(block), fuses: verdicts, ...(needs ? { approval_url: approvalUrl(payee, amount) } : {}) }, summary);
|
|
92
|
+
} catch (e) { return fail(e); }
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
server.registerTool("fusebox_pay", {
|
|
96
|
+
title: "Pay through the fuses",
|
|
97
|
+
description: `Ask the Fusebox wallet ${WALLET} to pay in USDT0 on X Layer. Every fuse decides in the same transaction; the money moves only if all of them say yes. The memo is recorded on-chain but no fuse reads it. Requires FUSEBOX_AGENT_KEY.`,
|
|
98
|
+
inputSchema: { to: z.string().describe("Payee address (0x…)"), amount: z.string().describe("Amount in USDT0, e.g. \"0.05\""), memo: z.string().max(200).describe("One line: what this payment is for") },
|
|
99
|
+
}, async ({ to, amount, memo }) => {
|
|
100
|
+
try {
|
|
101
|
+
if (!signer) throw new Error("This server is read-only: set FUSEBOX_AGENT_KEY to the agent's private key to pay.");
|
|
102
|
+
const payee = parseTo(to), amt = parseAmount(amount);
|
|
103
|
+
if (!(await pub.readContract({ ...W, functionName: "isAgent", args: [agent.address] }))) throw new Error(`${agent.address} isn't an agent of ${WALLET}.`);
|
|
104
|
+
// decisions are charged from the prepaid fee balance: explain an empty one instead of sending a doomed tx
|
|
105
|
+
const registry = await pub.readContract({ ...W, functionName: "registry" });
|
|
106
|
+
const [fee, slots] = await Promise.all([pub.readContract({ address: registry, abi: ABI.registry, functionName: "feeBalance", args: [WALLET] }), fuses()]);
|
|
107
|
+
const per = slots.reduce((t, f) => t + Number(f.feeCap ?? 0), 0);
|
|
108
|
+
if (per > 0 && Number(usd(fee)) + 1e-9 < per) throw new Error(`The wallet's prepaid fee balance (${usd(fee)} USDT0) can't cover one decision (${per.toFixed(6)} USDT0): ask the owner to top it up.`);
|
|
109
|
+
const hash = await signer.writeContract({ ...W, functionName: "pay", args: [USDT0, payee, amt, memo], gas: 3_000_000n });
|
|
110
|
+
const r = await pub.waitForTransactionReceipt({ hash, timeout: 120_000 });
|
|
111
|
+
if (r.status !== "success") throw new Error(`The transaction reverted: ${EXPLORER}/tx/${hash}`);
|
|
112
|
+
let d;
|
|
113
|
+
for (const l of r.logs) { try { const ev = decodeEventLog({ abi: ABI.wallet, data: l.data, topics: l.topics }); if (ev.eventName === "Decision") d = ev.args; } catch {} }
|
|
114
|
+
const fs = await fuses();
|
|
115
|
+
const verdicts = fs.map((f, i) => ({ fuse: f.name, verdict: STATUS[d.status[i]] === "pass" ? "holds" : "blew" }));
|
|
116
|
+
const blew = verdicts.filter((v) => v.verdict === "blew").map((v) => v.fuse);
|
|
117
|
+
const needs = !d.allowed && fs.some((f, i) => f.key === "approval-2of3" && verdicts[i].verdict === "blew");
|
|
118
|
+
const out = { paid: d.allowed, decision: Number(d.decisionId), to: payee, amount, memo, fuses: verdicts, feePaid: usd(d.feePaid), tx: `${EXPLORER}/tx/${hash}`, ...(needs ? { approval_url: approvalUrl(payee, amount) } : {}) };
|
|
119
|
+
const summary = d.allowed ? `Paid ${amount} USDT0 to ${payee} (decision #${out.decision}). Fees ${out.feePaid} USDT0. ${out.tx}`
|
|
120
|
+
: `Stopped by ${blew.join(", ")}: nothing moved (decision #${out.decision}). ${needs && blew.length === 1 ? `It needs two of the wallet's approvers: they can sign at ${out.approval_url}, then retry.` : "Ask the wallet's owner before trying again."} ${out.tx}`;
|
|
121
|
+
return text(out, summary);
|
|
122
|
+
} catch (e) { return fail(e); }
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
server.registerTool("fusebox_status", {
|
|
126
|
+
title: "Wallet status",
|
|
127
|
+
description: `The Fusebox wallet ${WALLET}: USDT0 balance, prepaid fee balance, each fuse and whether it's blown, today's spend, and decision counts.`,
|
|
128
|
+
inputSchema: {},
|
|
129
|
+
}, async () => {
|
|
130
|
+
try {
|
|
131
|
+
const registry = await pub.readContract({ ...W, functionName: "registry" });
|
|
132
|
+
const [bal, fee, paused, n, ok, no, fs] = await Promise.all([
|
|
133
|
+
pub.readContract({ address: USDT0, abi: erc20, functionName: "balanceOf", args: [WALLET] }),
|
|
134
|
+
pub.readContract({ address: registry, abi: ABI.registry, functionName: "feeBalance", args: [WALLET] }),
|
|
135
|
+
pub.readContract({ ...W, functionName: "paused" }),
|
|
136
|
+
pub.readContract({ ...W, functionName: "decisionCount" }), pub.readContract({ ...W, functionName: "allowedCount" }), pub.readContract({ ...W, functionName: "blockedCount" }),
|
|
137
|
+
fuses(),
|
|
138
|
+
]);
|
|
139
|
+
const out = { wallet: WALLET, agent: agent?.address ?? null, balance: usd(bal), feeBalance: usd(fee), paused, decisions: Number(n), paid: Number(ok), stopped: Number(no),
|
|
140
|
+
fuses: fs.map((f) => ({ fuse: f.name, circuit: `#${f.circuitId} on ${f.processor}`, blown: f.latched, ...(f.key === "daily-cap" ? { spentToday: f.spentToday, cap: f.a } : {}) })) };
|
|
141
|
+
const blown = fs.filter((f) => f.latched).map((f) => f.name);
|
|
142
|
+
return text(out, `${out.balance} USDT0 in the wallet, ${out.feeBalance} USDT0 of prepaid fees. ${paused ? "Paused by the owner." : blown.length ? `${blown.join(", ")} blown: nothing pays until the owner resets it.` : "Every fuse is closed."}`);
|
|
143
|
+
} catch (e) { return fail(e); }
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await server.connect(new StdioServerTransport());
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fusebox-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "MCP tools for AI agents paying through a Fusebox wallet on X Layer: check a payment against TapeOut circuit fuses, pay, and read the wallet's state.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"fusebox-mcp": "index.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.mjs",
|
|
11
|
+
"abi.json",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/0xdopewilly/fusebox",
|
|
21
|
+
"directory": "mcp"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://fusebox-xlayer.vercel.app",
|
|
24
|
+
"keywords": [
|
|
25
|
+
"mcp",
|
|
26
|
+
"x-layer",
|
|
27
|
+
"tapeout",
|
|
28
|
+
"ai-agents",
|
|
29
|
+
"wallet",
|
|
30
|
+
"fusebox"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"test": "node test/smoke.mjs"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
37
|
+
"viem": "2.57.12",
|
|
38
|
+
"zod": "4.6.7"
|
|
39
|
+
}
|
|
40
|
+
}
|