web3-tools-mcp 2.0.1 → 3.0.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/CHANGELOG.md +117 -0
- package/README.md +5 -0
- package/dist/anvil.d.ts +17 -19
- package/dist/anvil.d.ts.map +1 -1
- package/dist/anvil.js +124 -228
- package/dist/anvil.js.map +1 -1
- package/dist/chains.d.ts +9 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +11 -2
- package/dist/chains.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +22 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +24 -0
- package/dist/context.js.map +1 -0
- package/dist/hosted.d.ts +12 -0
- package/dist/hosted.d.ts.map +1 -0
- package/dist/hosted.js +12 -0
- package/dist/hosted.js.map +1 -0
- package/dist/http-server.d.ts +13 -0
- package/dist/http-server.d.ts.map +1 -1
- package/dist/http-server.js +13 -4
- package/dist/http-server.js.map +1 -1
- package/dist/index.js +19 -15
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +24 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +23 -0
- package/dist/lib.js.map +1 -0
- package/dist/log.d.ts +16 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +20 -0
- package/dist/log.js.map +1 -0
- package/dist/mcp-server.d.ts +4 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +43 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/oauth.d.ts +41 -6
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +75 -41
- package/dist/oauth.js.map +1 -1
- package/dist/preview.d.ts +7 -0
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +14 -2
- package/dist/preview.js.map +1 -1
- package/dist/signing-requests.d.ts +81 -0
- package/dist/signing-requests.d.ts.map +1 -0
- package/dist/signing-requests.js +138 -0
- package/dist/signing-requests.js.map +1 -0
- package/dist/tools/index.d.ts +27 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +37 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/{advanced.d.ts → read/advanced.d.ts} +30 -26
- package/dist/tools/read/advanced.d.ts.map +1 -0
- package/dist/tools/{advanced.js → read/advanced.js} +10 -10
- package/dist/tools/read/advanced.js.map +1 -0
- package/dist/tools/{balance.d.ts → read/balance.d.ts} +8 -7
- package/dist/tools/read/balance.d.ts.map +1 -0
- package/dist/tools/{balance.js → read/balance.js} +2 -2
- package/dist/tools/read/balance.js.map +1 -0
- package/dist/tools/{contract-info.d.ts → read/contract-info.d.ts} +18 -15
- package/dist/tools/read/contract-info.d.ts.map +1 -0
- package/dist/tools/{contract-info.js → read/contract-info.js} +2 -2
- package/dist/tools/read/contract-info.js.map +1 -0
- package/dist/tools/{contract.d.ts → read/contract.d.ts} +14 -12
- package/dist/tools/read/contract.d.ts.map +1 -0
- package/dist/tools/{contract.js → read/contract.js} +2 -2
- package/dist/tools/read/contract.js.map +1 -0
- package/dist/tools/{ens.d.ts → read/ens.d.ts} +30 -25
- package/dist/tools/read/ens.d.ts.map +1 -0
- package/dist/tools/{ens.js → read/ens.js} +2 -2
- package/dist/tools/read/ens.js.map +1 -0
- package/dist/tools/read/gas.d.ts +171 -0
- package/dist/tools/read/gas.d.ts.map +1 -0
- package/dist/tools/read/gas.js +368 -0
- package/dist/tools/read/gas.js.map +1 -0
- package/dist/tools/{logs.d.ts → read/logs.d.ts} +6 -5
- package/dist/tools/read/logs.d.ts.map +1 -0
- package/dist/tools/{logs.js → read/logs.js} +2 -2
- package/dist/tools/read/logs.js.map +1 -0
- package/dist/tools/{signatures.d.ts → read/signatures.d.ts} +8 -4
- package/dist/tools/read/signatures.d.ts.map +1 -0
- package/dist/tools/{signatures.js → read/signatures.js} +1 -1
- package/dist/tools/read/signatures.js.map +1 -0
- package/dist/tools/read/signing.d.ts +27 -0
- package/dist/tools/read/signing.d.ts.map +1 -0
- package/dist/tools/read/signing.js +75 -0
- package/dist/tools/read/signing.js.map +1 -0
- package/dist/tools/sign/errors.d.ts +9 -0
- package/dist/tools/sign/errors.d.ts.map +1 -0
- package/dist/tools/sign/errors.js +29 -0
- package/dist/tools/sign/errors.js.map +1 -0
- package/dist/tools/{transactions.d.ts → sign/transactions.d.ts} +48 -62
- package/dist/tools/sign/transactions.d.ts.map +1 -0
- package/dist/tools/sign/transactions.js +316 -0
- package/dist/tools/sign/transactions.js.map +1 -0
- package/dist/tools/sign/wallet.d.ts +50 -0
- package/dist/tools/sign/wallet.d.ts.map +1 -0
- package/dist/tools/sign/wallet.js +180 -0
- package/dist/tools/sign/wallet.js.map +1 -0
- package/dist/utils.d.ts +5 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +5 -2
- package/dist/utils.js.map +1 -1
- package/dist/wallet-client.d.ts +33 -4
- package/dist/wallet-client.d.ts.map +1 -1
- package/dist/wallet-client.js +90 -24
- package/dist/wallet-client.js.map +1 -1
- package/dist/walletconnect.d.ts +111 -13
- package/dist/walletconnect.d.ts.map +1 -1
- package/dist/walletconnect.js +248 -68
- package/dist/walletconnect.js.map +1 -1
- package/package.json +10 -4
- package/src/anvil.ts +150 -271
- package/src/chains.ts +14 -2
- package/src/client.ts +0 -1
- package/src/context.ts +27 -0
- package/src/hosted.ts +11 -0
- package/src/http-server.ts +30 -5
- package/src/index.ts +19 -16
- package/src/lib.ts +24 -0
- package/src/log.ts +25 -0
- package/src/mcp-server.ts +47 -0
- package/src/oauth.ts +98 -45
- package/src/preview.ts +21 -2
- package/src/signing-requests.ts +198 -0
- package/src/tools/index.ts +67 -16
- package/src/tools/{advanced.ts → read/advanced.ts} +13 -11
- package/src/tools/{balance.ts → read/balance.ts} +3 -3
- package/src/tools/{contract-info.ts → read/contract-info.ts} +3 -3
- package/src/tools/{contract.ts → read/contract.ts} +3 -3
- package/src/tools/{ens.ts → read/ens.ts} +3 -3
- package/src/tools/read/gas.ts +480 -0
- package/src/tools/{logs.ts → read/logs.ts} +3 -3
- package/src/tools/{signatures.ts → read/signatures.ts} +2 -2
- package/src/tools/read/signing.ts +86 -0
- package/src/tools/sign/errors.ts +28 -0
- package/src/tools/sign/transactions.ts +428 -0
- package/src/tools/sign/wallet.ts +216 -0
- package/src/utils.ts +5 -2
- package/src/wallet-client.ts +91 -22
- package/src/walletconnect.ts +286 -66
- package/dist/tools/advanced.d.ts.map +0 -1
- package/dist/tools/advanced.js.map +0 -1
- package/dist/tools/balance.d.ts.map +0 -1
- package/dist/tools/balance.js.map +0 -1
- package/dist/tools/contract-info.d.ts.map +0 -1
- package/dist/tools/contract-info.js.map +0 -1
- package/dist/tools/contract.d.ts.map +0 -1
- package/dist/tools/contract.js.map +0 -1
- package/dist/tools/ens.d.ts.map +0 -1
- package/dist/tools/ens.js.map +0 -1
- package/dist/tools/gas.d.ts +0 -99
- package/dist/tools/gas.d.ts.map +0 -1
- package/dist/tools/gas.js +0 -181
- package/dist/tools/gas.js.map +0 -1
- package/dist/tools/logs.d.ts.map +0 -1
- package/dist/tools/logs.js.map +0 -1
- package/dist/tools/signatures.d.ts.map +0 -1
- package/dist/tools/signatures.js.map +0 -1
- package/dist/tools/transactions.d.ts.map +0 -1
- package/dist/tools/transactions.js +0 -361
- package/dist/tools/transactions.js.map +0 -1
- package/src/tools/gas.ts +0 -219
- package/src/tools/transactions.ts +0 -452
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { log } from './log.js';
|
|
3
|
+
/**
|
|
4
|
+
* A signature that outlives the tool call that asked for it.
|
|
5
|
+
*
|
|
6
|
+
* Approving happens on a human's schedule. A browser signer is told to come — the tab opens
|
|
7
|
+
* and the badge flashes — but a phone wallet is only as loud as the wallet itself, and some
|
|
8
|
+
* send no notification at all. So the wait routinely outlives whatever timeout the MCP
|
|
9
|
+
* client applies, and the agent is left holding a tool call that never returns while the
|
|
10
|
+
* request is still perfectly alive in the wallet.
|
|
11
|
+
*
|
|
12
|
+
* Each request gets an id and outlives its call. Settling quickly still returns inline, so
|
|
13
|
+
* the common case — a browser tab that pops up and is approved in seconds — is unchanged.
|
|
14
|
+
* Past that the call hands back the id and the agent collects the result later.
|
|
15
|
+
*
|
|
16
|
+
* Held in memory on purpose: a request is only meaningful while the socket or WalletConnect
|
|
17
|
+
* session that carries it is alive, and both die with the process anyway.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* How long to wait on a signer that has been told to come — the browser page, whose tab
|
|
21
|
+
* opens and whose title flashes. Comfortably under any MCP client's tool timeout.
|
|
22
|
+
*
|
|
23
|
+
* A signer that cannot raise the alarm does not use this at all: it calls `waiting()` the
|
|
24
|
+
* moment the request is with the wallet, and the call returns then. Waiting on a phone that
|
|
25
|
+
* never buzzed is dead time either way.
|
|
26
|
+
*/
|
|
27
|
+
export const GRACE_MS = 25_000;
|
|
28
|
+
/** How long a finished result stays collectable. */
|
|
29
|
+
const RESULT_TTL = 15 * 60_000;
|
|
30
|
+
const requests = new Map();
|
|
31
|
+
function sweep() {
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
for (const [id, request] of requests) {
|
|
34
|
+
if (request.settledAt && now - request.settledAt > RESULT_TTL)
|
|
35
|
+
requests.delete(id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function view(request) {
|
|
39
|
+
const { settled: _settled, ...rest } = request;
|
|
40
|
+
return rest;
|
|
41
|
+
}
|
|
42
|
+
/** Resolves when the request settles, or when the grace runs out — whichever comes first. */
|
|
43
|
+
function race(request, graceMs, handoff) {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
const timer = setTimeout(resolve, graceMs);
|
|
46
|
+
// A request nobody is waiting for must not keep a stdio server alive after its client
|
|
47
|
+
// has gone; shutdown is what ends it.
|
|
48
|
+
timer.unref?.();
|
|
49
|
+
const done = () => {
|
|
50
|
+
clearTimeout(timer);
|
|
51
|
+
resolve();
|
|
52
|
+
};
|
|
53
|
+
request.settled.then(done);
|
|
54
|
+
handoff?.then(done);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Run a signing request, waiting only as long as a tool call reasonably can.
|
|
59
|
+
*
|
|
60
|
+
* The work starts here either way — returning `done: false` means nobody has approved yet,
|
|
61
|
+
* never that nothing was asked.
|
|
62
|
+
*/
|
|
63
|
+
export async function signingCall(context, run) {
|
|
64
|
+
sweep();
|
|
65
|
+
const id = randomBytes(16).toString('hex');
|
|
66
|
+
// Ends the wait: until it is called, a failure is a real error the caller should see
|
|
67
|
+
// rather than something to be collected later.
|
|
68
|
+
let handedOff;
|
|
69
|
+
const handoff = new Promise((resolve) => {
|
|
70
|
+
handedOff = resolve;
|
|
71
|
+
});
|
|
72
|
+
// Built before `run` starts, because a signer is free to report progress synchronously.
|
|
73
|
+
const request = {
|
|
74
|
+
id,
|
|
75
|
+
identity: context.identity,
|
|
76
|
+
summary: context.summary,
|
|
77
|
+
signer: context.signer,
|
|
78
|
+
stage: 'approval',
|
|
79
|
+
startedAt: Date.now(),
|
|
80
|
+
state: 'pending',
|
|
81
|
+
settled: Promise.resolve()
|
|
82
|
+
};
|
|
83
|
+
// Broadcasting does not end the wait. On a fast chain the receipt is seconds away, and a
|
|
84
|
+
// caller still inside its grace would rather have the mined result than a request id.
|
|
85
|
+
const started = run({
|
|
86
|
+
waiting: () => handedOff(),
|
|
87
|
+
mining: (txHash) => {
|
|
88
|
+
request.stage = 'mining';
|
|
89
|
+
request.txHash = txHash;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
request.settled = started.then((result) => {
|
|
93
|
+
request.state = 'done';
|
|
94
|
+
request.result = result;
|
|
95
|
+
request.settledAt = Date.now();
|
|
96
|
+
}, (error) => {
|
|
97
|
+
request.state = 'failed';
|
|
98
|
+
request.error = error instanceof Error ? error.message : String(error);
|
|
99
|
+
request.settledAt = Date.now();
|
|
100
|
+
});
|
|
101
|
+
requests.set(id, request);
|
|
102
|
+
await race(request, context.graceMs ?? GRACE_MS, handoff);
|
|
103
|
+
if (request.state === 'done') {
|
|
104
|
+
requests.delete(id);
|
|
105
|
+
return { done: true, result: request.result };
|
|
106
|
+
}
|
|
107
|
+
if (request.state === 'failed') {
|
|
108
|
+
requests.delete(id);
|
|
109
|
+
throw new Error(request.error);
|
|
110
|
+
}
|
|
111
|
+
log('info', 'Signing', `${context.summary} is still waiting for approval — handed back as ${id.slice(0, 8)}`);
|
|
112
|
+
return { done: false, request: view(request) };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Collect a request handed back earlier, waiting out another grace period if it is still
|
|
116
|
+
* pending — so an agent that checks in a loop paces itself rather than spinning.
|
|
117
|
+
*
|
|
118
|
+
* Scoped to the caller: an id is unguessable, but on a server carrying several people that
|
|
119
|
+
* is not the reason one of them cannot read another's signature.
|
|
120
|
+
*/
|
|
121
|
+
export async function collectSigningRequest(id, identity, graceMs = GRACE_MS) {
|
|
122
|
+
sweep();
|
|
123
|
+
const request = requests.get(id);
|
|
124
|
+
if (!request || request.identity !== identity) {
|
|
125
|
+
throw new Error(`No signing request ${id} is waiting. It may have been collected already, or it expired.`);
|
|
126
|
+
}
|
|
127
|
+
if (request.state === 'pending')
|
|
128
|
+
await race(request, graceMs);
|
|
129
|
+
if (request.state !== 'pending')
|
|
130
|
+
requests.delete(id);
|
|
131
|
+
return view(request);
|
|
132
|
+
}
|
|
133
|
+
/** Everything this identity still has in front of a wallet. */
|
|
134
|
+
export function pendingSigningRequests(identity) {
|
|
135
|
+
sweep();
|
|
136
|
+
return [...requests.values()].filter((request) => request.identity === identity && request.state === 'pending').map(view);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=signing-requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signing-requests.js","sourceRoot":"","sources":["../src/signing-requests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;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OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,sBAAsB,EAAE,iEAAiE,CAAC,CAAA;IAC5G,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC7D,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAEpD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAA;AACtB,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,sBAAsB,CAAC,QAAgB;IACrD,KAAK,EAAE,CAAA;IACP,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAC3H,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
|
|
2
|
+
import type { ToolResult } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a tool does with a wallet, which is the line everything else divides along.
|
|
5
|
+
*
|
|
6
|
+
* `read` answers questions about a chain and costs an RPC call. `sign` puts a transaction
|
|
7
|
+
* in front of somebody's wallet, and is the reason identity and rooms exist. A host pricing
|
|
8
|
+
* or rate-limiting tool calls almost always wants this distinction, and taking it from the
|
|
9
|
+
* folder a tool lives in means it cannot drift from a hand-kept list.
|
|
10
|
+
*/
|
|
11
|
+
export type ToolGroup = 'read' | 'sign';
|
|
12
|
+
/** The group a tool belongs to, for a host deciding what it costs or who may call it. */
|
|
13
|
+
export declare function toolGroup(name: string): ToolGroup | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Wraps every tool call, for a host that needs to say who may run what.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately only the tool's name, its group and who is calling: enough to count calls,
|
|
18
|
+
* refuse them past a limit and record what was used, without this package taking a view on
|
|
19
|
+
* any of it. Throwing refuses the call, and the message reaches the agent — so it should
|
|
20
|
+
* say what to do about it. Whatever the returned promise settles as is what the caller
|
|
21
|
+
* sees, so a host can also time a call or meter it once it has succeeded.
|
|
22
|
+
*/
|
|
23
|
+
export type ToolMiddleware = (call: {
|
|
24
|
+
tool: string;
|
|
25
|
+
group: ToolGroup;
|
|
26
|
+
identity: string;
|
|
27
|
+
}, run: () => Promise<ToolResult>) => Promise<ToolResult>;
|
|
28
|
+
export declare function registerAllTools(server: McpServer, middleware?: ToolMiddleware): void;
|
|
3
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AAIxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAa7C;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAA;AA2BvC,yFAAyF;AACzF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAE7D;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC1D,GAAG,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,KAC3B,OAAO,CAAC,UAAU,CAAC,CAAA;AAExB,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,cAAc,QAoB9E"}
|
package/dist/tools/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
1
|
+
import { identityFrom } from '../context.js';
|
|
2
|
+
import advancedTools from './read/advanced.js';
|
|
3
|
+
import balanceTools from './read/balance.js';
|
|
4
|
+
import contractTools from './read/contract.js';
|
|
5
|
+
import contractInfoTools from './read/contract-info.js';
|
|
6
|
+
import ensTools from './read/ens.js';
|
|
7
|
+
import gasTools from './read/gas.js';
|
|
8
|
+
import logTools from './read/logs.js';
|
|
9
|
+
import signatureTools from './read/signatures.js';
|
|
10
|
+
import signingRequestTools from './read/signing.js';
|
|
11
|
+
import transactionTools from './sign/transactions.js';
|
|
12
|
+
import walletTools from './sign/wallet.js';
|
|
13
|
+
const readTools = {
|
|
11
14
|
...signatureTools,
|
|
12
15
|
...contractTools,
|
|
13
16
|
...contractInfoTools,
|
|
@@ -16,17 +19,36 @@ const allToolDefinitions = {
|
|
|
16
19
|
...advancedTools,
|
|
17
20
|
...ensTools,
|
|
18
21
|
...gasTools,
|
|
19
|
-
|
|
22
|
+
// A signature already asked for and paid for; collecting it is not a second request.
|
|
23
|
+
...signingRequestTools
|
|
20
24
|
};
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const signTools = {
|
|
26
|
+
...transactionTools,
|
|
27
|
+
...walletTools
|
|
28
|
+
};
|
|
29
|
+
const allToolDefinitions = { ...readTools, ...signTools };
|
|
30
|
+
const groups = new Map([
|
|
31
|
+
...Object.keys(readTools).map((name) => [name, 'read']),
|
|
32
|
+
...Object.keys(signTools).map((name) => [name, 'sign'])
|
|
33
|
+
]);
|
|
34
|
+
/** The group a tool belongs to, for a host deciding what it costs or who may call it. */
|
|
35
|
+
export function toolGroup(name) {
|
|
36
|
+
return groups.get(name);
|
|
37
|
+
}
|
|
38
|
+
export function registerAllTools(server, middleware) {
|
|
23
39
|
Object.entries(allToolDefinitions).forEach(([name, tool]) => {
|
|
40
|
+
if (tool.available && !tool.available())
|
|
41
|
+
return;
|
|
24
42
|
server.registerTool(name, {
|
|
25
43
|
title: tool.title,
|
|
26
44
|
description: tool.description,
|
|
27
45
|
inputSchema: tool.schema.shape
|
|
28
|
-
}, async (args,
|
|
29
|
-
|
|
46
|
+
}, async (args, extra) => {
|
|
47
|
+
// Passed to every handler; the ones that reach a signer must say whose it is.
|
|
48
|
+
const identity = identityFrom(extra.authInfo);
|
|
49
|
+
const run = () => tool.handler(args, identity);
|
|
50
|
+
const group = toolGroup(name);
|
|
51
|
+
return await (middleware ? middleware({ tool: name, group, identity }, run) : run());
|
|
30
52
|
});
|
|
31
53
|
});
|
|
32
54
|
}
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,YAAY,MAAM,mBAAmB,CAAA;AAC5C,OAAO,aAAa,MAAM,oBAAoB,CAAA;AAC9C,OAAO,iBAAiB,MAAM,yBAAyB,CAAA;AACvD,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,QAAQ,MAAM,eAAe,CAAA;AACpC,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,cAAc,MAAM,sBAAsB,CAAA;AAC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AAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK;SAC/B,EACD,KAAK,EAAE,IAAS,EAAE,KAA6D,EAAE,EAAE;YACjF,8EAA8E;YAC9E,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAC7C,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;YAC9C,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAc,CAAA;YAC1C,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;QACtF,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -4,85 +4,88 @@ declare const _default: {
|
|
|
4
4
|
title: string;
|
|
5
5
|
description: string;
|
|
6
6
|
schema: z.ZodObject<{
|
|
7
|
-
chain: z.ZodEnum<["
|
|
7
|
+
chain: z.ZodEnum<["mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost", ...("mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost")[]]>;
|
|
8
8
|
address: z.ZodString;
|
|
9
9
|
slot: z.ZodString;
|
|
10
10
|
abiType: z.ZodString;
|
|
11
11
|
blockNumber: z.ZodOptional<z.ZodString>;
|
|
12
12
|
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
13
14
|
address: string;
|
|
14
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
15
15
|
slot: string;
|
|
16
16
|
abiType: string;
|
|
17
17
|
blockNumber?: string | undefined;
|
|
18
18
|
}, {
|
|
19
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
19
20
|
address: string;
|
|
20
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
21
21
|
slot: string;
|
|
22
22
|
abiType: string;
|
|
23
23
|
blockNumber?: string | undefined;
|
|
24
24
|
}>;
|
|
25
25
|
handler: (args: {
|
|
26
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
26
27
|
address: string;
|
|
27
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
28
28
|
slot: string;
|
|
29
29
|
abiType: string;
|
|
30
30
|
blockNumber?: string | undefined;
|
|
31
|
-
}) => Promise<import("
|
|
31
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
32
|
+
available: (() => boolean) | undefined;
|
|
32
33
|
};
|
|
33
34
|
get_block_info: {
|
|
34
35
|
title: string;
|
|
35
36
|
description: string;
|
|
36
37
|
schema: z.ZodObject<{
|
|
37
|
-
chain: z.ZodEnum<["
|
|
38
|
+
chain: z.ZodEnum<["mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost", ...("mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost")[]]>;
|
|
38
39
|
blockNumber: z.ZodOptional<z.ZodString>;
|
|
39
40
|
}, "strip", z.ZodTypeAny, {
|
|
40
|
-
chain: "
|
|
41
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
41
42
|
blockNumber?: string | undefined;
|
|
42
43
|
}, {
|
|
43
|
-
chain: "
|
|
44
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
44
45
|
blockNumber?: string | undefined;
|
|
45
46
|
}>;
|
|
46
47
|
handler: (args: {
|
|
47
|
-
chain: "
|
|
48
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
48
49
|
blockNumber?: string | undefined;
|
|
49
|
-
}) => Promise<import("
|
|
50
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
51
|
+
available: (() => boolean) | undefined;
|
|
50
52
|
};
|
|
51
53
|
trace_transaction: {
|
|
52
54
|
title: string;
|
|
53
55
|
description: string;
|
|
54
56
|
schema: z.ZodObject<{
|
|
55
|
-
chain: z.ZodEnum<["
|
|
57
|
+
chain: z.ZodEnum<["mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost", ...("mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost")[]]>;
|
|
56
58
|
transactionHash: z.ZodString;
|
|
57
59
|
traceType: z.ZodDefault<z.ZodOptional<z.ZodEnum<["trace", "vmTrace", "stateDiff"]>>>;
|
|
58
60
|
useAnvil: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
59
61
|
summarize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
60
62
|
}, "strip", z.ZodTypeAny, {
|
|
61
|
-
chain: "
|
|
63
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
62
64
|
transactionHash: string;
|
|
63
65
|
traceType: "trace" | "vmTrace" | "stateDiff";
|
|
64
66
|
useAnvil: boolean;
|
|
65
67
|
summarize: boolean;
|
|
66
68
|
}, {
|
|
67
|
-
chain: "
|
|
69
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
68
70
|
transactionHash: string;
|
|
69
71
|
traceType?: "trace" | "vmTrace" | "stateDiff" | undefined;
|
|
70
72
|
useAnvil?: boolean | undefined;
|
|
71
73
|
summarize?: boolean | undefined;
|
|
72
74
|
}>;
|
|
73
75
|
handler: (args: {
|
|
74
|
-
chain: "
|
|
76
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
75
77
|
transactionHash: string;
|
|
76
78
|
traceType: "trace" | "vmTrace" | "stateDiff";
|
|
77
79
|
useAnvil: boolean;
|
|
78
80
|
summarize: boolean;
|
|
79
|
-
}) => Promise<import("
|
|
81
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
82
|
+
available: (() => boolean) | undefined;
|
|
80
83
|
};
|
|
81
84
|
debug_call: {
|
|
82
85
|
title: string;
|
|
83
86
|
description: string;
|
|
84
87
|
schema: z.ZodObject<{
|
|
85
|
-
chain: z.ZodEnum<["
|
|
88
|
+
chain: z.ZodEnum<["mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost", ...("mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost")[]]>;
|
|
86
89
|
to: z.ZodString;
|
|
87
90
|
data: z.ZodOptional<z.ZodString>;
|
|
88
91
|
functionAbi: z.ZodOptional<z.ZodString>;
|
|
@@ -93,40 +96,41 @@ declare const _default: {
|
|
|
93
96
|
traceType: z.ZodDefault<z.ZodOptional<z.ZodEnum<["callTracer", "prestateTracer"]>>>;
|
|
94
97
|
summarize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
95
98
|
}, "strip", z.ZodTypeAny, {
|
|
96
|
-
chain: "
|
|
99
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
97
100
|
to: string;
|
|
98
101
|
traceType: "callTracer" | "prestateTracer";
|
|
99
102
|
summarize: boolean;
|
|
100
|
-
|
|
103
|
+
blockNumber?: string | undefined;
|
|
101
104
|
from?: string | undefined;
|
|
102
105
|
value?: string | undefined;
|
|
103
|
-
|
|
106
|
+
data?: string | undefined;
|
|
104
107
|
args?: (string | number | boolean)[] | undefined;
|
|
105
108
|
functionAbi?: string | undefined;
|
|
106
109
|
}, {
|
|
107
|
-
chain: "
|
|
110
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
108
111
|
to: string;
|
|
109
|
-
|
|
112
|
+
blockNumber?: string | undefined;
|
|
110
113
|
from?: string | undefined;
|
|
111
114
|
value?: string | undefined;
|
|
112
|
-
|
|
115
|
+
data?: string | undefined;
|
|
113
116
|
args?: (string | number | boolean)[] | undefined;
|
|
114
117
|
traceType?: "callTracer" | "prestateTracer" | undefined;
|
|
115
118
|
summarize?: boolean | undefined;
|
|
116
119
|
functionAbi?: string | undefined;
|
|
117
120
|
}>;
|
|
118
121
|
handler: (args: {
|
|
119
|
-
chain: "
|
|
122
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
120
123
|
to: string;
|
|
121
124
|
traceType: "callTracer" | "prestateTracer";
|
|
122
125
|
summarize: boolean;
|
|
123
|
-
|
|
126
|
+
blockNumber?: string | undefined;
|
|
124
127
|
from?: string | undefined;
|
|
125
128
|
value?: string | undefined;
|
|
126
|
-
|
|
129
|
+
data?: string | undefined;
|
|
127
130
|
args?: (string | number | boolean)[] | undefined;
|
|
128
131
|
functionAbi?: string | undefined;
|
|
129
|
-
}) => Promise<import("
|
|
132
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
133
|
+
available: (() => boolean) | undefined;
|
|
130
134
|
};
|
|
131
135
|
};
|
|
132
136
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../../src/tools/read/advanced.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMvB,wBAuZC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { decodeAbiParameters, isAddress, parseAbiParameters } from 'viem';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import { getClientManager, SUPPORTED_CHAINS } from '
|
|
5
|
-
import { createTool, formatResponse, summarizeTrace } from '
|
|
3
|
+
import { isDebugNodeAvailable, simulateCallWithTrace, traceTransactionWithAnvil } from '../../anvil.js';
|
|
4
|
+
import { getClientManager, SUPPORTED_CHAINS } from '../../client.js';
|
|
5
|
+
import { createTool, formatResponse, summarizeTrace } from '../../utils.js';
|
|
6
6
|
export default {
|
|
7
7
|
get_storage_at: createTool('Read Contract Storage', '⚠️ ADVANCED: Direct storage slot access with type decoding. Use for low-level contract inspection.', z.object({
|
|
8
8
|
chain: z.enum(SUPPORTED_CHAINS).describe('The blockchain network to use'),
|
|
@@ -132,7 +132,7 @@ export default {
|
|
|
132
132
|
useAnvil: z
|
|
133
133
|
.boolean()
|
|
134
134
|
.optional()
|
|
135
|
-
.describe('Force
|
|
135
|
+
.describe('Force tracing through the debug node (ANVIL_RPC_URL). Used automatically as a fallback when the RPC cannot trace.')
|
|
136
136
|
.default(false),
|
|
137
137
|
summarize: z
|
|
138
138
|
.boolean()
|
|
@@ -182,13 +182,13 @@ export default {
|
|
|
182
182
|
if (traceResult === null ||
|
|
183
183
|
(traceResult && typeof traceResult === 'object' && 'rpcError' in traceResult) ||
|
|
184
184
|
args.useAnvil) {
|
|
185
|
-
const anvilAvailable = await
|
|
185
|
+
const anvilAvailable = await isDebugNodeAvailable();
|
|
186
186
|
if (anvilAvailable) {
|
|
187
187
|
usedAnvil = true; // Mark as used before attempting (even if it fails)
|
|
188
188
|
try {
|
|
189
189
|
const forkUrl = clientManager.getRpcUrl(args.chain);
|
|
190
190
|
const blockNumber = transaction.blockNumber ?? 0n;
|
|
191
|
-
traceResult = await traceTransactionWithAnvil(forkUrl, args.transactionHash, blockNumber, tracer
|
|
191
|
+
traceResult = await traceTransactionWithAnvil(forkUrl, args.transactionHash, blockNumber, tracer);
|
|
192
192
|
}
|
|
193
193
|
catch (anvilError) {
|
|
194
194
|
// Anvil tracing also failed
|
|
@@ -203,7 +203,7 @@ export default {
|
|
|
203
203
|
else if (!traceResult || (typeof traceResult === 'object' && 'rpcError' in traceResult)) {
|
|
204
204
|
// Anvil not available and RPC failed
|
|
205
205
|
traceResult = {
|
|
206
|
-
error: 'Tracing not available.
|
|
206
|
+
error: 'Tracing not available. Point ANVIL_RPC_URL at a node exposing debug_traceCall — a local Anvil on 127.0.0.1:8545 is picked up automatically.',
|
|
207
207
|
rpcError: traceResult && typeof traceResult === 'object' && 'rpcError' in traceResult
|
|
208
208
|
? traceResult.rpcError
|
|
209
209
|
: 'RPC does not support debug_traceTransaction'
|
|
@@ -256,7 +256,7 @@ export default {
|
|
|
256
256
|
};
|
|
257
257
|
return formatResponse(result);
|
|
258
258
|
}),
|
|
259
|
-
debug_call: createTool('Debug Contract Call', 'Simulate a contract call with full trace output.
|
|
259
|
+
debug_call: createTool('Debug Contract Call', 'Simulate a contract call with full trace output. Needs a node exposing debug_traceCall (a local Anvil, or ANVIL_RPC_URL). Useful for debugging reverts and understanding call execution.', z.object({
|
|
260
260
|
chain: z.enum(SUPPORTED_CHAINS).describe('The blockchain network to fork'),
|
|
261
261
|
to: z.string().describe('Contract address to call'),
|
|
262
262
|
data: z.string().optional().describe('Calldata (hex encoded). Either provide this or functionAbi + args.'),
|
|
@@ -283,9 +283,9 @@ export default {
|
|
|
283
283
|
.default(false)
|
|
284
284
|
}), async (args) => {
|
|
285
285
|
// Check if Anvil is installed
|
|
286
|
-
const anvilAvailable = await
|
|
286
|
+
const anvilAvailable = await isDebugNodeAvailable();
|
|
287
287
|
if (!anvilAvailable) {
|
|
288
|
-
throw new Error('
|
|
288
|
+
throw new Error('No tracing node reachable. Run a local Anvil, or set ANVIL_RPC_URL to a node exposing debug_traceCall.');
|
|
289
289
|
}
|
|
290
290
|
const clientManager = getClientManager();
|
|
291
291
|
const forkUrl = clientManager.getRpcUrl(args.chain);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.js","sourceRoot":"","sources":["../../../src/tools/read/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAE,SAAS,EAAE,k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,QAAQ,IAAI,CAAC,iBAAiB;YAChG,CAAC,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC;YACnC,CAAC,CAAC,IAAI,CAAA;QAEV,MAAM,MAAM,GACV,IAAI,CAAC,SAAS,IAAI,YAAY;YAC5B,CAAC,CAAC;gBACE,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE;gBACvC,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,GAAG,YAAY,CAAC,mCAAmC;aACpD;YACH,CAAC,CAAC;gBACE,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,4CAA4C;gBAC/D,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,GAAG;gBAC/B,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,QAAQ;gBAChD,MAAM,EAAE,WAAW,CAAC,MAAM;gBAC1B,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE;gBACvC,YAAY,EAAE,WAAW,CAAC,YAAY;gBACtC,KAAK,EAAE,WAAW,CAAC,KAAK;aACzB,CAAA;QAEP,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC,CACF;CACF,CAAA"}
|
|
@@ -5,36 +5,36 @@ declare const _default: {
|
|
|
5
5
|
description: string;
|
|
6
6
|
schema: z.ZodObject<{
|
|
7
7
|
queries: z.ZodArray<z.ZodObject<{
|
|
8
|
-
chain: z.ZodEnum<["
|
|
8
|
+
chain: z.ZodEnum<["mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost", ...("mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost")[]]>;
|
|
9
9
|
address: z.ZodString;
|
|
10
10
|
tokenAddress: z.ZodOptional<z.ZodString>;
|
|
11
11
|
blockNumber: z.ZodOptional<z.ZodString>;
|
|
12
12
|
label: z.ZodOptional<z.ZodString>;
|
|
13
13
|
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
14
15
|
address: string;
|
|
15
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
16
16
|
blockNumber?: string | undefined;
|
|
17
17
|
tokenAddress?: string | undefined;
|
|
18
18
|
label?: string | undefined;
|
|
19
19
|
}, {
|
|
20
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
20
21
|
address: string;
|
|
21
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
22
22
|
blockNumber?: string | undefined;
|
|
23
23
|
tokenAddress?: string | undefined;
|
|
24
24
|
label?: string | undefined;
|
|
25
25
|
}>, "many">;
|
|
26
26
|
}, "strip", z.ZodTypeAny, {
|
|
27
27
|
queries: {
|
|
28
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
28
29
|
address: string;
|
|
29
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
30
30
|
blockNumber?: string | undefined;
|
|
31
31
|
tokenAddress?: string | undefined;
|
|
32
32
|
label?: string | undefined;
|
|
33
33
|
}[];
|
|
34
34
|
}, {
|
|
35
35
|
queries: {
|
|
36
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
36
37
|
address: string;
|
|
37
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
38
38
|
blockNumber?: string | undefined;
|
|
39
39
|
tokenAddress?: string | undefined;
|
|
40
40
|
label?: string | undefined;
|
|
@@ -42,13 +42,14 @@ declare const _default: {
|
|
|
42
42
|
}>;
|
|
43
43
|
handler: (args: {
|
|
44
44
|
queries: {
|
|
45
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
45
46
|
address: string;
|
|
46
|
-
chain: "arbitrum" | "mainnet" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
47
47
|
blockNumber?: string | undefined;
|
|
48
48
|
tokenAddress?: string | undefined;
|
|
49
49
|
label?: string | undefined;
|
|
50
50
|
}[];
|
|
51
|
-
}) => Promise<import("
|
|
51
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
52
|
+
available: (() => boolean) | undefined;
|
|
52
53
|
};
|
|
53
54
|
};
|
|
54
55
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../../src/tools/read/balance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAavB,wBA4JC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatEther, formatUnits, isAddress } from 'viem';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { getClientManager, SUPPORTED_CHAINS } from '
|
|
4
|
-
import { createTool, formatResponse } from '
|
|
3
|
+
import { getClientManager, SUPPORTED_CHAINS } from '../../client.js';
|
|
4
|
+
import { createTool, formatResponse } from '../../utils.js';
|
|
5
5
|
const BalanceQuerySchema = z.object({
|
|
6
6
|
chain: z.enum(SUPPORTED_CHAINS).describe('The blockchain network to use'),
|
|
7
7
|
address: z.string().describe('The address to check balance for'),
|