web3-tools-mcp 2.0.2 → 3.1.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 +182 -1
- package/README.md +76 -47
- 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/chain-meta.d.ts.map +1 -1
- package/dist/chain-meta.js +19 -8
- package/dist/chain-meta.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/clear-signing.d.ts.map +1 -1
- package/dist/clear-signing.js +17 -6
- package/dist/clear-signing.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 +22 -7
- package/dist/http-server.js.map +1 -1
- package/dist/index.js +20 -12
- package/dist/index.js.map +1 -1
- package/dist/kv-storage.d.ts +2 -1
- package/dist/kv-storage.d.ts.map +1 -1
- package/dist/kv-storage.js +5 -2
- package/dist/kv-storage.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/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 +57 -8
- package/dist/oauth.d.ts.map +1 -1
- package/dist/oauth.js +133 -63
- 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 +21 -7
- 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 +50 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/{advanced.d.ts → read/advanced.d.ts} +39 -30
- package/dist/tools/read/advanced.d.ts.map +1 -0
- package/dist/tools/{advanced.js → read/advanced.js} +53 -41
- 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} +18 -33
- package/dist/tools/read/balance.js.map +1 -0
- package/dist/tools/{contract-info.d.ts → read/contract-info.d.ts} +20 -15
- package/dist/tools/read/contract-info.d.ts.map +1 -0
- package/dist/tools/{contract-info.js → read/contract-info.js} +54 -123
- 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} +3 -2
- package/dist/tools/read/contract.js.map +1 -0
- package/dist/tools/read/ens.d.ts +104 -0
- package/dist/tools/read/ens.d.ts.map +1 -0
- package/dist/tools/{ens.js → read/ens.js} +25 -33
- 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 +333 -0
- package/dist/tools/read/gas.js.map +1 -0
- package/dist/tools/read/logs.d.ts +101 -0
- package/dist/tools/read/logs.d.ts.map +1 -0
- package/dist/tools/read/logs.js +211 -0
- 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} +4 -3
- 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 +81 -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/sign/transactions.d.ts +141 -0
- package/dist/tools/sign/transactions.d.ts.map +1 -0
- package/dist/tools/sign/transactions.js +361 -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 +23 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +48 -3
- package/dist/utils.js.map +1 -1
- package/dist/wallet-client.d.ts +34 -4
- package/dist/wallet-client.d.ts.map +1 -1
- package/dist/wallet-client.js +106 -27
- package/dist/wallet-client.js.map +1 -1
- package/dist/walletconnect.d.ts +100 -13
- package/dist/walletconnect.d.ts.map +1 -1
- package/dist/walletconnect.js +215 -50
- package/dist/walletconnect.js.map +1 -1
- package/package.json +12 -9
- package/src/anvil.ts +150 -271
- package/src/chain-meta.ts +16 -7
- package/src/chains.ts +14 -2
- package/src/clear-signing.ts +15 -9
- package/src/client.ts +0 -1
- package/src/context.ts +27 -0
- package/src/hosted.ts +11 -0
- package/src/http-server.ts +38 -8
- package/src/index.ts +20 -13
- package/src/kv-storage.ts +6 -3
- package/src/lib.ts +24 -0
- package/src/mcp-server.ts +47 -0
- package/src/oauth.ts +181 -69
- package/src/preview.ts +28 -7
- package/src/signing-requests.ts +198 -0
- package/src/tools/index.ts +78 -16
- package/src/tools/{advanced.ts → read/advanced.ts} +74 -43
- package/src/tools/{balance.ts → read/balance.ts} +20 -35
- package/src/tools/{contract-info.ts → read/contract-info.ts} +66 -146
- package/src/tools/{contract.ts → read/contract.ts} +4 -3
- package/src/tools/{ens.ts → read/ens.ts} +27 -34
- package/src/tools/read/gas.ts +443 -0
- package/src/tools/read/logs.ts +281 -0
- package/src/tools/{signatures.ts → read/signatures.ts} +5 -5
- package/src/tools/read/signing.ts +92 -0
- package/src/tools/sign/errors.ts +28 -0
- package/src/tools/sign/transactions.ts +479 -0
- package/src/tools/sign/wallet.ts +216 -0
- package/src/utils.ts +52 -3
- package/src/wallet-client.ts +107 -24
- package/src/walletconnect.ts +250 -48
- 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 +0 -119
- 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 +0 -39
- package/dist/tools/logs.d.ts.map +0 -1
- package/dist/tools/logs.js +0 -230
- 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 +0 -155
- package/dist/tools/transactions.d.ts.map +0 -1
- package/dist/tools/transactions.js +0 -365
- package/dist/tools/transactions.js.map +0 -1
- package/src/tools/gas.ts +0 -219
- package/src/tools/logs.ts +0 -293
- package/src/tools/transactions.ts +0 -456
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isAddress, namehash } from 'viem';
|
|
2
2
|
import { normalize } from 'viem/ens';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { getClientManager
|
|
5
|
-
import { createTool, formatResponse } from '
|
|
4
|
+
import { getClientManager } from '../../client.js';
|
|
5
|
+
import { createTool, formatResponse, MAX_BATCH } from '../../utils.js';
|
|
6
6
|
// Base ENS Contract Addresses
|
|
7
7
|
const BASE_ENS_CONTRACTS = {
|
|
8
8
|
registry: '0xb94704422c2a1e396835a571837aa5ae53285a95',
|
|
@@ -143,29 +143,28 @@ async function getTextRecordBase(name, key) {
|
|
|
143
143
|
return null;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
/** Where a name service is deployed: ENS on mainnet, Linea Names on Linea, Basenames on Base. */
|
|
147
|
+
const ENS_CHAINS = ['mainnet', 'linea', 'base'];
|
|
148
|
+
const ensChain = z
|
|
149
|
+
.enum(ENS_CHAINS)
|
|
150
|
+
.default('mainnet')
|
|
151
|
+
.describe('Where the name lives: mainnet for .eth (ENS), linea for Linea Names, base for Basenames. Defaults to mainnet.');
|
|
146
152
|
const EnsResolveSchema = z.object({
|
|
147
|
-
chain:
|
|
148
|
-
|
|
149
|
-
.default('mainnet')
|
|
150
|
-
.describe('Blockchain network (defaults to mainnet, as ENS is primarily on Ethereum)'),
|
|
151
|
-
name: z.string().describe("ENS name to resolve to an address (e.g., 'vitalik.eth', 'example.eth')"),
|
|
152
|
-
universalResolver: z.boolean().optional().describe('Use universal resolver for cross-chain resolution (defaults to true)')
|
|
153
|
+
chain: ensChain,
|
|
154
|
+
name: z.string().describe("ENS name to resolve to an address (e.g., 'vitalik.eth', 'example.eth')")
|
|
153
155
|
});
|
|
154
156
|
const EnsReverseResolveSchema = z.object({
|
|
155
|
-
chain:
|
|
156
|
-
address: z.string().describe('Ethereum address to resolve to an ENS name')
|
|
157
|
-
universalResolver: z.boolean().optional().describe('Use universal resolver for cross-chain resolution (defaults to true)')
|
|
157
|
+
chain: ensChain,
|
|
158
|
+
address: z.string().describe('Ethereum address to resolve to an ENS name')
|
|
158
159
|
});
|
|
159
160
|
const EnsTextRecordSchema = z.object({
|
|
160
|
-
chain:
|
|
161
|
+
chain: ensChain,
|
|
161
162
|
name: z.string().describe('ENS name to query text records from'),
|
|
162
|
-
key: z.string().describe("Text record key (e.g., 'avatar', 'description', 'email', 'url', 'com.twitter', 'com.github')")
|
|
163
|
-
universalResolver: z.boolean().optional().describe('Use universal resolver for cross-chain resolution (defaults to true)')
|
|
163
|
+
key: z.string().describe("Text record key (e.g., 'avatar', 'description', 'email', 'url', 'com.twitter', 'com.github')")
|
|
164
164
|
});
|
|
165
165
|
const EnsBatchResolveSchema = z.object({
|
|
166
|
-
chain:
|
|
167
|
-
names: z.array(z.string()).describe('Array of ENS names to resolve to addresses in a single batch')
|
|
168
|
-
universalResolver: z.boolean().optional().describe('Use universal resolver for cross-chain resolution (defaults to true)')
|
|
166
|
+
chain: ensChain,
|
|
167
|
+
names: z.array(z.string()).max(MAX_BATCH).describe('Array of ENS names to resolve to addresses in a single batch')
|
|
169
168
|
});
|
|
170
169
|
export default {
|
|
171
170
|
resolve_ens_name: createTool('Resolve ENS Name to Address', 'Resolve an ENS name to its Ethereum address. ENS names are human-readable identifiers (like vitalik.eth) that resolve to Ethereum addresses.', EnsResolveSchema, async (args) => {
|
|
@@ -181,8 +180,7 @@ export default {
|
|
|
181
180
|
const clientManager = getClientManager();
|
|
182
181
|
const client = clientManager.getClient(args.chain);
|
|
183
182
|
address = await client.getEnsAddress({
|
|
184
|
-
name: normalizedName
|
|
185
|
-
universalResolverAddress: args.universalResolver !== false ? undefined : undefined
|
|
183
|
+
name: normalizedName
|
|
186
184
|
});
|
|
187
185
|
}
|
|
188
186
|
if (!address) {
|
|
@@ -217,8 +215,7 @@ export default {
|
|
|
217
215
|
const clientManager = getClientManager();
|
|
218
216
|
const client = clientManager.getClient(args.chain);
|
|
219
217
|
ensName = await client.getEnsName({
|
|
220
|
-
address: args.address
|
|
221
|
-
universalResolverAddress: args.universalResolver !== false ? undefined : undefined
|
|
218
|
+
address: args.address
|
|
222
219
|
});
|
|
223
220
|
}
|
|
224
221
|
if (!ensName) {
|
|
@@ -251,8 +248,7 @@ export default {
|
|
|
251
248
|
const client = clientManager.getClient(args.chain);
|
|
252
249
|
textRecord = await client.getEnsText({
|
|
253
250
|
name: normalizedName,
|
|
254
|
-
key: args.key
|
|
255
|
-
universalResolverAddress: args.universalResolver !== false ? undefined : undefined
|
|
251
|
+
key: args.key
|
|
256
252
|
});
|
|
257
253
|
}
|
|
258
254
|
if (!textRecord) {
|
|
@@ -275,10 +271,9 @@ export default {
|
|
|
275
271
|
chain: args.chain
|
|
276
272
|
});
|
|
277
273
|
}),
|
|
278
|
-
get_ens_avatar: createTool('Get ENS Avatar', 'Get the avatar
|
|
279
|
-
chain:
|
|
280
|
-
name: z.string().describe('ENS name to get avatar from')
|
|
281
|
-
universalResolver: z.boolean().optional().describe('Use universal resolver for cross-chain resolution (defaults to true)')
|
|
274
|
+
get_ens_avatar: createTool('Get ENS Avatar', 'Get the raw avatar text record for an ENS name: an https/ipfs URL, a data URI, or an NFT reference (eip155:1/erc721:0x…/1). It is not fetched or resolved to an image.', z.object({
|
|
275
|
+
chain: ensChain,
|
|
276
|
+
name: z.string().describe('ENS name to get avatar from')
|
|
282
277
|
}), async (args) => {
|
|
283
278
|
// Normalize the ENS name
|
|
284
279
|
const normalizedName = normalize(args.name);
|
|
@@ -291,10 +286,8 @@ export default {
|
|
|
291
286
|
// Use viem's built-in ENS resolution for other chains
|
|
292
287
|
const clientManager = getClientManager();
|
|
293
288
|
const client = clientManager.getClient(args.chain);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
universalResolverAddress: args.universalResolver !== false ? undefined : undefined
|
|
297
|
-
});
|
|
289
|
+
// getEnsAvatar would fetch the record's URL (or the NFT's metadata) from this server.
|
|
290
|
+
avatar = await client.getEnsText({ name: normalizedName, key: 'avatar' });
|
|
298
291
|
}
|
|
299
292
|
if (!avatar) {
|
|
300
293
|
return formatResponse({
|
|
@@ -328,8 +321,7 @@ export default {
|
|
|
328
321
|
const clientManager = getClientManager();
|
|
329
322
|
const client = clientManager.getClient(args.chain);
|
|
330
323
|
address = await client.getEnsAddress({
|
|
331
|
-
name: normalizedName
|
|
332
|
-
universalResolverAddress: args.universalResolver !== false ? undefined : undefined
|
|
324
|
+
name: normalizedName
|
|
333
325
|
});
|
|
334
326
|
}
|
|
335
327
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ens.js","sourceRoot":"","sources":["../../../src/tools/read/ens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEtE,8BAA8B;AAC9B,MAAM,kBAAkB,GAAG;IACzB,QAAQ,EAAE,4CAAuD;IACjE,gBAAgB,EAAE,4CAAuD;IACzE,UAAU,EAAE,4CAAuD;CACpE,CAAA;AAED,kDAAkD;AAClD,KAAK,UAAU,kBAAkB,CAAC,OAAgB;IAChD,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IACxC,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAE9C,IAAI,CAAC;QACH,6CAA6C;QAC7C,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;YAC5C,OAAO,EAAE,kBAAkB,CAAC,gBAAgB;YAC5C,GAAG,EAAE;gBACH;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,UAAU;oBAChB,eAAe,EAAE,MAAM;oBACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAA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,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YAC7B,kBAAkB,EAAE,YAAY;YAChC,cAAc,EAAE,SAAS;YACzB,OAAO,EAAE,QAAQ;SAClB,CAAC,CAAA;IACJ,CAAC,CACF;CACF,CAAA"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const _default: {
|
|
3
|
+
simulate_contract: {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: z.ZodObject<{
|
|
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
|
+
contractAddress: z.ZodString;
|
|
9
|
+
functionAbi: z.ZodString;
|
|
10
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>;
|
|
11
|
+
from: z.ZodOptional<z.ZodString>;
|
|
12
|
+
value: z.ZodOptional<z.ZodString>;
|
|
13
|
+
blockNumber: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
functionAbi: string;
|
|
18
|
+
blockNumber?: string | undefined;
|
|
19
|
+
from?: string | undefined;
|
|
20
|
+
value?: string | undefined;
|
|
21
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
24
|
+
contractAddress: string;
|
|
25
|
+
functionAbi: string;
|
|
26
|
+
blockNumber?: string | undefined;
|
|
27
|
+
from?: string | undefined;
|
|
28
|
+
value?: string | undefined;
|
|
29
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
30
|
+
}>;
|
|
31
|
+
handler: (args: {
|
|
32
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
33
|
+
contractAddress: string;
|
|
34
|
+
functionAbi: string;
|
|
35
|
+
blockNumber?: string | undefined;
|
|
36
|
+
from?: string | undefined;
|
|
37
|
+
value?: string | undefined;
|
|
38
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
39
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
40
|
+
available: (() => boolean) | undefined;
|
|
41
|
+
};
|
|
42
|
+
simulate_bundle: {
|
|
43
|
+
title: string;
|
|
44
|
+
description: string;
|
|
45
|
+
schema: z.ZodObject<{
|
|
46
|
+
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")[]]>;
|
|
47
|
+
from: z.ZodOptional<z.ZodString>;
|
|
48
|
+
calls: z.ZodArray<z.ZodObject<{
|
|
49
|
+
to: z.ZodString;
|
|
50
|
+
functionAbi: z.ZodOptional<z.ZodString>;
|
|
51
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>;
|
|
52
|
+
data: z.ZodOptional<z.ZodString>;
|
|
53
|
+
value: z.ZodOptional<z.ZodString>;
|
|
54
|
+
from: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, "strip", z.ZodTypeAny, {
|
|
56
|
+
to: string;
|
|
57
|
+
from?: string | undefined;
|
|
58
|
+
value?: string | undefined;
|
|
59
|
+
data?: string | undefined;
|
|
60
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
61
|
+
functionAbi?: string | undefined;
|
|
62
|
+
}, {
|
|
63
|
+
to: string;
|
|
64
|
+
from?: string | undefined;
|
|
65
|
+
value?: string | undefined;
|
|
66
|
+
data?: string | undefined;
|
|
67
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
68
|
+
functionAbi?: string | undefined;
|
|
69
|
+
}>, "many">;
|
|
70
|
+
blockNumber: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, "strip", z.ZodTypeAny, {
|
|
72
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
73
|
+
calls: {
|
|
74
|
+
to: string;
|
|
75
|
+
from?: string | undefined;
|
|
76
|
+
value?: string | undefined;
|
|
77
|
+
data?: string | undefined;
|
|
78
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
79
|
+
functionAbi?: string | undefined;
|
|
80
|
+
}[];
|
|
81
|
+
blockNumber?: string | undefined;
|
|
82
|
+
from?: string | undefined;
|
|
83
|
+
}, {
|
|
84
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
85
|
+
calls: {
|
|
86
|
+
to: string;
|
|
87
|
+
from?: string | undefined;
|
|
88
|
+
value?: string | undefined;
|
|
89
|
+
data?: string | undefined;
|
|
90
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
91
|
+
functionAbi?: string | undefined;
|
|
92
|
+
}[];
|
|
93
|
+
blockNumber?: string | undefined;
|
|
94
|
+
from?: string | undefined;
|
|
95
|
+
}>;
|
|
96
|
+
handler: (args: {
|
|
97
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
98
|
+
calls: {
|
|
99
|
+
to: string;
|
|
100
|
+
from?: string | undefined;
|
|
101
|
+
value?: string | undefined;
|
|
102
|
+
data?: string | undefined;
|
|
103
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
104
|
+
functionAbi?: string | undefined;
|
|
105
|
+
}[];
|
|
106
|
+
blockNumber?: string | undefined;
|
|
107
|
+
from?: string | undefined;
|
|
108
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
109
|
+
available: (() => boolean) | undefined;
|
|
110
|
+
};
|
|
111
|
+
estimate_gas: {
|
|
112
|
+
title: string;
|
|
113
|
+
description: string;
|
|
114
|
+
schema: z.ZodObject<{
|
|
115
|
+
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")[]]>;
|
|
116
|
+
to: z.ZodOptional<z.ZodString>;
|
|
117
|
+
from: z.ZodOptional<z.ZodString>;
|
|
118
|
+
value: z.ZodOptional<z.ZodString>;
|
|
119
|
+
data: z.ZodOptional<z.ZodString>;
|
|
120
|
+
functionAbi: z.ZodOptional<z.ZodString>;
|
|
121
|
+
args: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>;
|
|
122
|
+
}, "strip", z.ZodTypeAny, {
|
|
123
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
124
|
+
from?: string | undefined;
|
|
125
|
+
to?: string | undefined;
|
|
126
|
+
value?: string | undefined;
|
|
127
|
+
data?: string | undefined;
|
|
128
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
129
|
+
functionAbi?: string | undefined;
|
|
130
|
+
}, {
|
|
131
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
132
|
+
from?: string | undefined;
|
|
133
|
+
to?: string | undefined;
|
|
134
|
+
value?: string | undefined;
|
|
135
|
+
data?: string | undefined;
|
|
136
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
137
|
+
functionAbi?: string | undefined;
|
|
138
|
+
}>;
|
|
139
|
+
handler: (args: {
|
|
140
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
141
|
+
from?: string | undefined;
|
|
142
|
+
to?: string | undefined;
|
|
143
|
+
value?: string | undefined;
|
|
144
|
+
data?: string | undefined;
|
|
145
|
+
args?: (string | number | boolean | null)[] | undefined;
|
|
146
|
+
functionAbi?: string | undefined;
|
|
147
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
148
|
+
available: (() => boolean) | undefined;
|
|
149
|
+
};
|
|
150
|
+
get_gas_price: {
|
|
151
|
+
title: string;
|
|
152
|
+
description: string;
|
|
153
|
+
schema: z.ZodObject<{
|
|
154
|
+
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")[]]>;
|
|
155
|
+
formatted: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
156
|
+
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
158
|
+
formatted: boolean;
|
|
159
|
+
}, {
|
|
160
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
161
|
+
formatted?: boolean | undefined;
|
|
162
|
+
}>;
|
|
163
|
+
handler: (args: {
|
|
164
|
+
chain: "mainnet" | "arbitrum" | "avalanche" | "base" | "bnb" | "gnosis" | "sonic" | "optimism" | "polygon" | "zksync" | "linea" | "unichain" | "localhost";
|
|
165
|
+
formatted: boolean;
|
|
166
|
+
}, identity: string) => Promise<import("../../types.js").ToolResult>;
|
|
167
|
+
available: (() => boolean) | undefined;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
export default _default;
|
|
171
|
+
//# sourceMappingURL=gas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../../src/tools/read/gas.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwKvB,wBAqQC"}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { decodeFunctionResult, encodeFunctionData, formatEther, formatGwei, isAddress, parseAbiItem, toHex } from 'viem';
|
|
2
|
+
import { simulateBlocks } from 'viem/actions';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { getClientManager, SUPPORTED_CHAINS } from '../../client.js';
|
|
5
|
+
import { enrichTransfers } from '../../preview.js';
|
|
6
|
+
import { convertArgumentsToTypes, createTool, formatResponse, MAX_BATCH, rpcReason } from '../../utils.js';
|
|
7
|
+
/** Alchemy's bundle method takes at most this many transactions. */
|
|
8
|
+
const ALCHEMY_BUNDLE_LIMIT = 3;
|
|
9
|
+
/** Where eth_simulateV1's traced native transfers say they come from. */
|
|
10
|
+
const NATIVE_TOKEN = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
11
|
+
const argsSchema = z.array(z.union([z.string(), z.number(), z.boolean(), z.null()]));
|
|
12
|
+
function bundleCall(call, from, index) {
|
|
13
|
+
const sender = call.from ?? from;
|
|
14
|
+
if (!isAddress(call.to))
|
|
15
|
+
throw new Error(`Call ${index}: invalid to address ${call.to}`);
|
|
16
|
+
if (sender && !isAddress(sender))
|
|
17
|
+
throw new Error(`Call ${index}: invalid from address ${sender}`);
|
|
18
|
+
if (call.functionAbi && call.data)
|
|
19
|
+
throw new Error(`Call ${index}: give functionAbi and args, or data — not both`);
|
|
20
|
+
const abi = call.functionAbi ? parseAbiItem(call.functionAbi) : undefined;
|
|
21
|
+
const data = abi
|
|
22
|
+
? encodeFunctionData({ abi: [abi], functionName: abi.name, args: convertArgumentsToTypes(call.args ?? [], abi.inputs) })
|
|
23
|
+
: call.data;
|
|
24
|
+
return { from: sender, to: call.to, data, value: call.value ? BigInt(call.value) : undefined, abi };
|
|
25
|
+
}
|
|
26
|
+
/** Native, ERC20, ERC721 and ERC1155 changes with token metadata — on Alchemy's paid plans only. */
|
|
27
|
+
async function viaAlchemy(chain, calls, blockNumber) {
|
|
28
|
+
const client = getClientManager().getClient(chain);
|
|
29
|
+
const transactions = calls.map((call) => ({
|
|
30
|
+
from: call.from,
|
|
31
|
+
to: call.to,
|
|
32
|
+
data: call.data,
|
|
33
|
+
value: call.value !== undefined ? toHex(call.value) : undefined
|
|
34
|
+
}));
|
|
35
|
+
const params = blockNumber === undefined ? [transactions] : [transactions, toHex(blockNumber)];
|
|
36
|
+
const outcomes = (await client.request({ method: 'alchemy_simulateAssetChangesBundle', params }));
|
|
37
|
+
return outcomes.map((outcome) => ({
|
|
38
|
+
status: outcome.error ? 'failure' : 'success',
|
|
39
|
+
gasUsed: outcome.gasUsed ? BigInt(outcome.gasUsed).toString() : undefined,
|
|
40
|
+
error: outcome.error?.message,
|
|
41
|
+
assetChanges: outcome.changes.map((change) => ({
|
|
42
|
+
assetType: change.assetType,
|
|
43
|
+
token: change.contractAddress,
|
|
44
|
+
symbol: change.symbol,
|
|
45
|
+
tokenId: change.tokenId,
|
|
46
|
+
from: change.from,
|
|
47
|
+
to: change.to,
|
|
48
|
+
amount: change.amount,
|
|
49
|
+
rawAmount: change.rawAmount
|
|
50
|
+
}))
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function decodeResult(abi, data) {
|
|
54
|
+
if (!abi?.outputs.length)
|
|
55
|
+
return data;
|
|
56
|
+
try {
|
|
57
|
+
return decodeFunctionResult({ abi: [abi], functionName: abi.name, data });
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Any RPC with eth_simulateV1: decoded return values, and native, ERC20 and ERC721 transfers.
|
|
65
|
+
*
|
|
66
|
+
* ponytail: ERC1155 moves tokens with TransferSingle / TransferBatch, which are not read
|
|
67
|
+
* here, so those changes are missing on this path. Parse them if 1155 bundles matter.
|
|
68
|
+
*/
|
|
69
|
+
async function viaSimulateV1(chain, calls, blockNumber) {
|
|
70
|
+
const client = getClientManager().getClient(chain);
|
|
71
|
+
const [block] = await simulateBlocks(client, {
|
|
72
|
+
blocks: [{ calls: calls.map((call) => ({ account: call.from, to: call.to, data: call.data, value: call.value })) }],
|
|
73
|
+
traceTransfers: true,
|
|
74
|
+
validation: false,
|
|
75
|
+
...(blockNumber !== undefined && { blockNumber })
|
|
76
|
+
});
|
|
77
|
+
if (!block)
|
|
78
|
+
throw new Error('The RPC returned no simulated block');
|
|
79
|
+
const nativeSymbol = client.chain?.nativeCurrency.symbol;
|
|
80
|
+
return Promise.all(block.calls.map(async (call, index) => {
|
|
81
|
+
const error = call.error;
|
|
82
|
+
const transfers = await enrichTransfers(chain, (call.logs ?? []));
|
|
83
|
+
return {
|
|
84
|
+
status: call.status,
|
|
85
|
+
gasUsed: call.gasUsed.toString(),
|
|
86
|
+
error: call.status === 'success' ? undefined : (error?.shortMessage ?? error?.message ?? 'execution reverted'),
|
|
87
|
+
result: call.status === 'success' ? decodeResult(calls[index]?.abi, call.data) : undefined,
|
|
88
|
+
assetChanges: transfers.map((transfer) => {
|
|
89
|
+
if (transfer.tokenId !== undefined) {
|
|
90
|
+
return {
|
|
91
|
+
assetType: 'ERC721',
|
|
92
|
+
token: transfer.token,
|
|
93
|
+
symbol: transfer.symbol,
|
|
94
|
+
tokenId: transfer.tokenId,
|
|
95
|
+
from: transfer.from,
|
|
96
|
+
to: transfer.to,
|
|
97
|
+
amount: '1',
|
|
98
|
+
rawAmount: '1'
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const native = transfer.token.toLowerCase() === NATIVE_TOKEN;
|
|
102
|
+
return {
|
|
103
|
+
assetType: native ? 'NATIVE' : 'ERC20',
|
|
104
|
+
token: native ? undefined : transfer.token,
|
|
105
|
+
symbol: native ? nativeSymbol : transfer.symbol,
|
|
106
|
+
from: transfer.from,
|
|
107
|
+
to: transfer.to,
|
|
108
|
+
amount: native ? formatEther(BigInt(transfer.amount)) : transfer.humanAmount,
|
|
109
|
+
rawAmount: transfer.amount
|
|
110
|
+
};
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
export default {
|
|
116
|
+
simulate_contract: createTool('Simulate Contract Call', 'Simulate a contract call (including state-changing functions) without broadcasting. Returns simulation result and estimated gas.', z.object({
|
|
117
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network to simulate on'),
|
|
118
|
+
contractAddress: z.string().describe('Contract address to call'),
|
|
119
|
+
functionAbi: z
|
|
120
|
+
.string()
|
|
121
|
+
.describe('Function ABI signature (e.g., "function transfer(address to, uint256 amount)"). Can be any function type.'),
|
|
122
|
+
args: z
|
|
123
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
124
|
+
.optional()
|
|
125
|
+
.describe('Function arguments in order matching the ABI signature'),
|
|
126
|
+
from: z.string().optional().describe('Sender address (defaults to zero address)'),
|
|
127
|
+
value: z.string().optional().describe('ETH value to send with the transaction (in wei as string)'),
|
|
128
|
+
blockNumber: z.string().optional().describe('Block number for simulation (defaults to latest)')
|
|
129
|
+
}), async (args) => {
|
|
130
|
+
if (!isAddress(args.contractAddress)) {
|
|
131
|
+
throw new Error(`Invalid contract address: ${args.contractAddress}`);
|
|
132
|
+
}
|
|
133
|
+
if (args.from && !isAddress(args.from)) {
|
|
134
|
+
throw new Error(`Invalid from address: ${args.from}`);
|
|
135
|
+
}
|
|
136
|
+
const clientManager = getClientManager();
|
|
137
|
+
const client = clientManager.getClient(args.chain);
|
|
138
|
+
try {
|
|
139
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
140
|
+
const convertedArgs = convertArgumentsToTypes(args.args || [], abiItem.inputs);
|
|
141
|
+
const tx = {
|
|
142
|
+
to: args.contractAddress,
|
|
143
|
+
data: encodeFunctionData({ abi: [abiItem], functionName: abiItem.name, args: convertedArgs }),
|
|
144
|
+
account: args.from ? args.from : undefined,
|
|
145
|
+
value: args.value ? BigInt(args.value) : undefined,
|
|
146
|
+
blockNumber: args.blockNumber ? BigInt(args.blockNumber) : undefined
|
|
147
|
+
};
|
|
148
|
+
const result = await client.call(tx);
|
|
149
|
+
const gasEstimate = await client.estimateGas(tx);
|
|
150
|
+
// Decode the result if the function has outputs
|
|
151
|
+
let decodedResult = result.data;
|
|
152
|
+
if (abiItem.outputs && abiItem.outputs.length > 0 && result.data) {
|
|
153
|
+
decodedResult = decodeFunctionResult({
|
|
154
|
+
abi: [abiItem],
|
|
155
|
+
functionName: abiItem.name,
|
|
156
|
+
data: result.data
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return formatResponse({
|
|
160
|
+
success: true,
|
|
161
|
+
chain: args.chain,
|
|
162
|
+
contractAddress: args.contractAddress,
|
|
163
|
+
functionName: abiItem.name,
|
|
164
|
+
result: decodedResult,
|
|
165
|
+
rawData: result.data,
|
|
166
|
+
gasEstimate: gasEstimate.toString(),
|
|
167
|
+
blockNumber: args.blockNumber || 'latest'
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
return formatResponse({
|
|
172
|
+
success: false,
|
|
173
|
+
chain: args.chain,
|
|
174
|
+
contractAddress: args.contractAddress,
|
|
175
|
+
error: rpcReason(error),
|
|
176
|
+
reverted: String(error instanceof Error ? error.message : error).includes('revert')
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}),
|
|
180
|
+
simulate_bundle: createTool('Simulate Transaction Bundle', 'Simulate several transactions in order, in one block, each seeing the state the previous ones left — e.g. ' +
|
|
181
|
+
'approve then swap, or deposit then borrow. Nothing is broadcast. Returns per transaction whether it ' +
|
|
182
|
+
'succeeded, gas used, the revert reason, and the assets that moved. Up to 3 transactions go through ' +
|
|
183
|
+
"Alchemy's asset-change simulation (native, ERC20, ERC721, ERC1155, with symbols) where the plan allows it; " +
|
|
184
|
+
'otherwise eth_simulateV1, which adds decoded return values but reports only native and ERC20 transfers.', z.object({
|
|
185
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network to simulate on'),
|
|
186
|
+
from: z.string().optional().describe('Sender for every transaction that does not name its own'),
|
|
187
|
+
calls: z
|
|
188
|
+
.array(z.object({
|
|
189
|
+
to: z.string().describe('Contract or recipient address'),
|
|
190
|
+
functionAbi: z
|
|
191
|
+
.string()
|
|
192
|
+
.optional()
|
|
193
|
+
.describe('Function signature to encode the call, e.g. "function approve(address spender, uint256 amount)"'),
|
|
194
|
+
args: argsSchema.optional().describe('Arguments for functionAbi, in order'),
|
|
195
|
+
data: z.string().optional().describe('Raw calldata, instead of functionAbi and args'),
|
|
196
|
+
value: z.string().optional().describe('Native value to send, in wei'),
|
|
197
|
+
from: z.string().optional().describe('Sender of this transaction, if not the bundle-wide from')
|
|
198
|
+
}))
|
|
199
|
+
.min(1)
|
|
200
|
+
.max(MAX_BATCH)
|
|
201
|
+
.describe('Transactions to run, in order'),
|
|
202
|
+
blockNumber: z.string().optional().describe('Block to simulate on top of (defaults to latest)')
|
|
203
|
+
}), async (args) => {
|
|
204
|
+
const chain = args.chain;
|
|
205
|
+
const calls = args.calls.map((call, index) => bundleCall(call, args.from, index));
|
|
206
|
+
const blockNumber = args.blockNumber ? BigInt(args.blockNumber) : undefined;
|
|
207
|
+
let outcomes;
|
|
208
|
+
let via = 'alchemy_simulateAssetChangesBundle';
|
|
209
|
+
let fallbackReason;
|
|
210
|
+
if (calls.length <= ALCHEMY_BUNDLE_LIMIT) {
|
|
211
|
+
try {
|
|
212
|
+
outcomes = await viaAlchemy(chain, calls, blockNumber);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
// A free plan, a chain Alchemy does not simulate on, or a custom RPC that is not Alchemy.
|
|
216
|
+
fallbackReason = rpcReason(error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
fallbackReason = `Alchemy simulates at most ${ALCHEMY_BUNDLE_LIMIT} transactions per bundle`;
|
|
221
|
+
}
|
|
222
|
+
if (!outcomes) {
|
|
223
|
+
via = 'eth_simulateV1';
|
|
224
|
+
try {
|
|
225
|
+
outcomes = await viaSimulateV1(chain, calls, blockNumber);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
return formatResponse({ success: false, chain, error: rpcReason(error), alchemyBundleError: fallbackReason });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return formatResponse({
|
|
232
|
+
success: outcomes.every((outcome) => outcome.status === 'success'),
|
|
233
|
+
chain,
|
|
234
|
+
via,
|
|
235
|
+
...(fallbackReason && { fallbackReason }),
|
|
236
|
+
totalGasUsed: outcomes.reduce((sum, outcome) => sum + BigInt(outcome.gasUsed ?? 0), 0n),
|
|
237
|
+
calls: outcomes.map((outcome, index) => ({
|
|
238
|
+
index,
|
|
239
|
+
to: calls[index]?.to,
|
|
240
|
+
...(calls[index]?.abi && { functionName: calls[index].abi.name }),
|
|
241
|
+
...outcome
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
// Offered only where a provider RPC backs it: public endpoints rarely serve eth_simulateV1.
|
|
246
|
+
() => Boolean(getClientManager().getConfig().alchemyApiKey)),
|
|
247
|
+
estimate_gas: createTool('Estimate Gas', 'Estimate gas required for a transaction. Supports contract calls, transfers, and deployments.', z.object({
|
|
248
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network'),
|
|
249
|
+
to: z.string().optional().describe('Recipient address (omit for contract deployment)'),
|
|
250
|
+
from: z.string().optional().describe('Sender address (optional)'),
|
|
251
|
+
value: z.string().optional().describe('ETH value to send (in wei as string)'),
|
|
252
|
+
data: z.string().optional().describe('Transaction data (hex string for contract calls or deployment bytecode)'),
|
|
253
|
+
functionAbi: z.string().optional().describe('Optional: Function ABI signature to encode call data automatically'),
|
|
254
|
+
args: z
|
|
255
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
256
|
+
.optional()
|
|
257
|
+
.describe('Optional: Function arguments (only used with functionAbi)')
|
|
258
|
+
}), async (args) => {
|
|
259
|
+
if (args.to && !isAddress(args.to)) {
|
|
260
|
+
throw new Error(`Invalid to address: ${args.to}`);
|
|
261
|
+
}
|
|
262
|
+
if (args.from && !isAddress(args.from)) {
|
|
263
|
+
throw new Error(`Invalid from address: ${args.from}`);
|
|
264
|
+
}
|
|
265
|
+
const clientManager = getClientManager();
|
|
266
|
+
const client = clientManager.getClient(args.chain);
|
|
267
|
+
let callData = args.data;
|
|
268
|
+
// If functionAbi is provided, encode the call data
|
|
269
|
+
if (args.functionAbi) {
|
|
270
|
+
const abiItem = parseAbiItem(args.functionAbi);
|
|
271
|
+
const convertedArgs = convertArgumentsToTypes(args.args || [], abiItem.inputs);
|
|
272
|
+
callData = encodeFunctionData({
|
|
273
|
+
abi: [abiItem],
|
|
274
|
+
functionName: abiItem.name,
|
|
275
|
+
args: convertedArgs
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
const gasEstimate = await client.estimateGas({
|
|
279
|
+
to: args.to ? args.to : undefined,
|
|
280
|
+
account: args.from ? args.from : undefined,
|
|
281
|
+
value: args.value ? BigInt(args.value) : undefined,
|
|
282
|
+
data: callData
|
|
283
|
+
});
|
|
284
|
+
return formatResponse({
|
|
285
|
+
success: true,
|
|
286
|
+
chain: args.chain,
|
|
287
|
+
gasEstimate: gasEstimate.toString(),
|
|
288
|
+
to: args.to,
|
|
289
|
+
from: args.from,
|
|
290
|
+
value: args.value
|
|
291
|
+
});
|
|
292
|
+
}),
|
|
293
|
+
get_gas_price: createTool('Get Gas Price', 'Get current gas prices for a chain. Returns both legacy gasPrice and EIP-1559 fees (maxFeePerGas, maxPriorityFeePerGas).', z.object({
|
|
294
|
+
chain: z.enum(SUPPORTED_CHAINS).describe('Blockchain network'),
|
|
295
|
+
formatted: z.boolean().optional().default(true).describe('Return prices in Gwei (default: true). If false, returns wei.')
|
|
296
|
+
}), async (args) => {
|
|
297
|
+
const clientManager = getClientManager();
|
|
298
|
+
const client = clientManager.getClient(args.chain);
|
|
299
|
+
// Get both legacy and EIP-1559 gas prices
|
|
300
|
+
const [gasPrice, feeData] = await Promise.all([
|
|
301
|
+
client.getGasPrice(),
|
|
302
|
+
client.estimateFeesPerGas().catch(() => null) // Some chains don't support EIP-1559
|
|
303
|
+
]);
|
|
304
|
+
const formatPrice = (wei) => `${formatGwei(wei)} Gwei`;
|
|
305
|
+
const response = {
|
|
306
|
+
chain: args.chain,
|
|
307
|
+
timestamp: new Date().toISOString(),
|
|
308
|
+
legacy: {
|
|
309
|
+
gasPrice: args.formatted ? formatPrice(gasPrice) : gasPrice.toString(),
|
|
310
|
+
gasPriceWei: gasPrice.toString()
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
// Add EIP-1559 data if available
|
|
314
|
+
if (feeData) {
|
|
315
|
+
response.eip1559 = {
|
|
316
|
+
maxFeePerGas: args.formatted ? formatPrice(feeData.maxFeePerGas) : feeData.maxFeePerGas.toString(),
|
|
317
|
+
maxPriorityFeePerGas: args.formatted
|
|
318
|
+
? formatPrice(feeData.maxPriorityFeePerGas)
|
|
319
|
+
: feeData.maxPriorityFeePerGas.toString(),
|
|
320
|
+
maxFeePerGasWei: feeData.maxFeePerGas.toString(),
|
|
321
|
+
maxPriorityFeePerGasWei: feeData.maxPriorityFeePerGas.toString()
|
|
322
|
+
};
|
|
323
|
+
// Calculate estimated total cost for a standard 21000 gas transaction
|
|
324
|
+
const standardGasLimit = 21000n;
|
|
325
|
+
const estimatedCost = feeData.maxFeePerGas * standardGasLimit;
|
|
326
|
+
response.eip1559.estimatedCostFor21kGas = args.formatted
|
|
327
|
+
? `${formatEther(estimatedCost)} ${client.chain?.nativeCurrency.symbol ?? 'ETH'}`
|
|
328
|
+
: estimatedCost.toString();
|
|
329
|
+
}
|
|
330
|
+
return formatResponse(response);
|
|
331
|
+
})
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=gas.js.map
|