@t402/mcp 2.7.0 → 2.8.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/dist/cjs/index.js +1401 -185
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/index.d.ts +36 -0
- package/dist/cjs/server/index.js +1401 -185
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/tools/index.d.ts +689 -12
- package/dist/cjs/tools/index.js +1155 -29
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/esm/{chunk-B7X7H6NV.mjs → chunk-SUDCVXHQ.mjs} +1120 -30
- package/dist/esm/chunk-SUDCVXHQ.mjs.map +1 -0
- package/dist/esm/{chunk-3PMBXSJ3.mjs → chunk-XOPD7VTU.mjs} +195 -2
- package/dist/esm/chunk-XOPD7VTU.mjs.map +1 -0
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/server/index.d.mts +36 -0
- package/dist/esm/server/index.mjs +2 -2
- package/dist/esm/tools/index.d.mts +689 -12
- package/dist/esm/tools/index.mjs +70 -1
- package/package.json +14 -14
- package/dist/esm/chunk-3PMBXSJ3.mjs.map +0 -1
- package/dist/esm/chunk-B7X7H6NV.mjs.map +0 -1
package/dist/cjs/tools/index.js
CHANGED
|
@@ -38,30 +38,49 @@ __export(tools_exports, {
|
|
|
38
38
|
WDK_TOOL_DEFINITIONS: () => WDK_TOOL_DEFINITIONS,
|
|
39
39
|
autoPayInputSchema: () => autoPayInputSchema,
|
|
40
40
|
bridgeInputSchema: () => bridgeInputSchema,
|
|
41
|
+
clearPriceCache: () => clearPriceCache,
|
|
42
|
+
clearQuoteStore: () => clearQuoteStore,
|
|
43
|
+
compareNetworkFeesInputSchema: () => compareNetworkFeesInputSchema,
|
|
44
|
+
createQuote: () => createQuote,
|
|
41
45
|
createTonBridgeToolSet: () => createTonBridgeToolSet,
|
|
46
|
+
deleteQuote: () => deleteQuote,
|
|
42
47
|
erc8004CheckReputationInputSchema: () => erc8004CheckReputationInputSchema,
|
|
43
48
|
erc8004ResolveAgentInputSchema: () => erc8004ResolveAgentInputSchema,
|
|
44
49
|
erc8004VerifyWalletInputSchema: () => erc8004VerifyWalletInputSchema,
|
|
50
|
+
estimatePaymentFeeInputSchema: () => estimatePaymentFeeInputSchema,
|
|
45
51
|
executeAutoPay: () => executeAutoPay,
|
|
46
52
|
executeAutoPayDemo: () => executeAutoPayDemo,
|
|
47
53
|
executeBridge: () => executeBridge,
|
|
54
|
+
executeBridgeFromQuoteInputSchema: () => executeBridgeFromQuoteInputSchema,
|
|
55
|
+
executeCompareNetworkFees: () => executeCompareNetworkFees,
|
|
48
56
|
executeErc8004CheckReputation: () => executeErc8004CheckReputation,
|
|
49
57
|
executeErc8004ResolveAgent: () => executeErc8004ResolveAgent,
|
|
50
58
|
executeErc8004VerifyWallet: () => executeErc8004VerifyWallet,
|
|
59
|
+
executeEstimatePaymentFee: () => executeEstimatePaymentFee,
|
|
60
|
+
executeExecuteBridgeFromQuote: () => executeExecuteBridgeFromQuote,
|
|
61
|
+
executeExecuteBridgeFromQuoteDemo: () => executeExecuteBridgeFromQuoteDemo,
|
|
51
62
|
executeGetAllBalances: () => executeGetAllBalances,
|
|
52
63
|
executeGetBalance: () => executeGetBalance,
|
|
53
64
|
executeGetBridgeFee: () => executeGetBridgeFee,
|
|
65
|
+
executeGetGasPrice: () => executeGetGasPrice,
|
|
66
|
+
executeGetTokenPrice: () => executeGetTokenPrice,
|
|
54
67
|
executePay: () => executePay,
|
|
55
68
|
executePayGasless: () => executePayGasless,
|
|
56
69
|
executePaymentPlan: () => executePaymentPlan,
|
|
57
70
|
executePaymentPlanDemo: () => executePaymentPlanDemo,
|
|
71
|
+
executeQuoteBridge: () => executeQuoteBridge,
|
|
72
|
+
executeQuoteBridgeDemo: () => executeQuoteBridgeDemo,
|
|
58
73
|
executeSmartPay: () => executeSmartPay,
|
|
59
74
|
executeSmartPayDemo: () => executeSmartPayDemo,
|
|
60
75
|
executeTonBridgeTool: () => executeTonBridgeTool,
|
|
76
|
+
executeWdkExecuteSwap: () => executeWdkExecuteSwap,
|
|
77
|
+
executeWdkExecuteSwapDemo: () => executeWdkExecuteSwapDemo,
|
|
61
78
|
executeWdkGetBalances: () => executeWdkGetBalances,
|
|
62
79
|
executeWdkGetBalancesDemo: () => executeWdkGetBalancesDemo,
|
|
63
80
|
executeWdkGetWallet: () => executeWdkGetWallet,
|
|
64
81
|
executeWdkGetWalletDemo: () => executeWdkGetWalletDemo,
|
|
82
|
+
executeWdkQuoteSwap: () => executeWdkQuoteSwap,
|
|
83
|
+
executeWdkQuoteSwapDemo: () => executeWdkQuoteSwapDemo,
|
|
65
84
|
executeWdkSwap: () => executeWdkSwap,
|
|
66
85
|
executeWdkSwapDemo: () => executeWdkSwapDemo,
|
|
67
86
|
executeWdkTransfer: () => executeWdkTransfer,
|
|
@@ -70,14 +89,22 @@ __export(tools_exports, {
|
|
|
70
89
|
formatAutoPayResult: () => formatAutoPayResult,
|
|
71
90
|
formatBalanceResult: () => formatBalanceResult,
|
|
72
91
|
formatBridgeFeeResult: () => formatBridgeFeeResult,
|
|
92
|
+
formatBridgeQuoteResult: () => formatBridgeQuoteResult,
|
|
73
93
|
formatBridgeResult: () => formatBridgeResult,
|
|
74
94
|
formatErc8004CheckReputationResult: () => formatErc8004CheckReputationResult,
|
|
75
95
|
formatErc8004ResolveAgentResult: () => formatErc8004ResolveAgentResult,
|
|
76
96
|
formatErc8004VerifyWalletResult: () => formatErc8004VerifyWalletResult,
|
|
97
|
+
formatExecuteBridgeFromQuoteResult: () => formatBridgeResult,
|
|
98
|
+
formatExecuteSwapResult: () => formatExecuteSwapResult,
|
|
99
|
+
formatGasPriceResult: () => formatGasPriceResult,
|
|
77
100
|
formatGaslessPaymentResult: () => formatGaslessPaymentResult,
|
|
101
|
+
formatNetworkFeeComparison: () => formatNetworkFeeComparison,
|
|
102
|
+
formatPaymentFeeEstimate: () => formatPaymentFeeEstimate,
|
|
78
103
|
formatPaymentPlanResult: () => formatPaymentPlanResult,
|
|
79
104
|
formatPaymentResult: () => formatPaymentResult,
|
|
80
105
|
formatSmartPayResult: () => formatSmartPayResult,
|
|
106
|
+
formatSwapQuoteResult: () => formatSwapQuoteResult,
|
|
107
|
+
formatTokenPriceResult: () => formatTokenPriceResult,
|
|
81
108
|
formatWdkBalancesResult: () => formatWdkBalancesResult,
|
|
82
109
|
formatWdkSwapResult: () => formatWdkSwapResult,
|
|
83
110
|
formatWdkTransferResult: () => formatWdkTransferResult,
|
|
@@ -85,12 +112,20 @@ __export(tools_exports, {
|
|
|
85
112
|
getAllBalancesInputSchema: () => getAllBalancesInputSchema,
|
|
86
113
|
getBalanceInputSchema: () => getBalanceInputSchema,
|
|
87
114
|
getBridgeFeeInputSchema: () => getBridgeFeeInputSchema,
|
|
115
|
+
getGasPriceInputSchema: () => getGasPriceInputSchema,
|
|
116
|
+
getQuote: () => getQuote,
|
|
117
|
+
getTokenPriceInputSchema: () => getTokenPriceInputSchema,
|
|
118
|
+
getTokenPrices: () => getTokenPrices,
|
|
119
|
+
getTokenPricesDemo: () => getTokenPricesDemo,
|
|
88
120
|
payGaslessInputSchema: () => payGaslessInputSchema,
|
|
89
121
|
payInputSchema: () => payInputSchema,
|
|
90
122
|
paymentPlanInputSchema: () => paymentPlanInputSchema,
|
|
123
|
+
quoteBridgeInputSchema: () => quoteBridgeInputSchema,
|
|
91
124
|
smartPayInputSchema: () => smartPayInputSchema,
|
|
125
|
+
wdkExecuteSwapInputSchema: () => wdkExecuteSwapInputSchema,
|
|
92
126
|
wdkGetBalancesInputSchema: () => wdkGetBalancesInputSchema,
|
|
93
127
|
wdkGetWalletInputSchema: () => wdkGetWalletInputSchema,
|
|
128
|
+
wdkQuoteSwapInputSchema: () => wdkQuoteSwapInputSchema,
|
|
94
129
|
wdkSwapInputSchema: () => wdkSwapInputSchema,
|
|
95
130
|
wdkTransferInputSchema: () => wdkTransferInputSchema
|
|
96
131
|
});
|
|
@@ -518,7 +553,8 @@ var payInputSchema = import_zod3.z.object({
|
|
|
518
553
|
"berachain",
|
|
519
554
|
"unichain"
|
|
520
555
|
]).describe("Network to execute payment on"),
|
|
521
|
-
memo: import_zod3.z.string().optional().describe("Optional memo/reference for the payment")
|
|
556
|
+
memo: import_zod3.z.string().optional().describe("Optional memo/reference for the payment"),
|
|
557
|
+
confirmed: import_zod3.z.boolean().optional().describe("Set to true to confirm and execute this payment")
|
|
522
558
|
});
|
|
523
559
|
function getViemChain2(network) {
|
|
524
560
|
switch (network) {
|
|
@@ -547,6 +583,13 @@ function getViemChain2(network) {
|
|
|
547
583
|
async function executePay(input, options) {
|
|
548
584
|
const { to, amount, token, network, memo: _memo } = input;
|
|
549
585
|
const { privateKey, rpcUrl, demoMode } = options;
|
|
586
|
+
if (!input.confirmed) {
|
|
587
|
+
return {
|
|
588
|
+
needsConfirmation: true,
|
|
589
|
+
summary: `Send ${amount} ${token} on ${network} to ${to}`,
|
|
590
|
+
details: { to, amount, token, network }
|
|
591
|
+
};
|
|
592
|
+
}
|
|
550
593
|
if (!supportsToken(network, token)) {
|
|
551
594
|
throw new Error(`Token ${token} is not supported on ${network}`);
|
|
552
595
|
}
|
|
@@ -631,7 +674,8 @@ var payGaslessInputSchema = import_zod4.z.object({
|
|
|
631
674
|
to: import_zod4.z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address"),
|
|
632
675
|
amount: import_zod4.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to pay (e.g., '10.50' for 10.50 USDC)"),
|
|
633
676
|
token: import_zod4.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment"),
|
|
634
|
-
network: import_zod4.z.enum(["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"]).describe("Network to execute gasless payment on (must support ERC-4337)")
|
|
677
|
+
network: import_zod4.z.enum(["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"]).describe("Network to execute gasless payment on (must support ERC-4337)"),
|
|
678
|
+
confirmed: import_zod4.z.boolean().optional().describe("Set to true to confirm and execute this payment")
|
|
635
679
|
});
|
|
636
680
|
var GASLESS_SUPPORTED_NETWORKS = [
|
|
637
681
|
"ethereum",
|
|
@@ -668,6 +712,13 @@ function getViemChain3(network) {
|
|
|
668
712
|
async function executePayGasless(input, options) {
|
|
669
713
|
const { to, amount, token, network } = input;
|
|
670
714
|
const { privateKey, bundlerUrl, paymasterUrl: _paymasterUrl, rpcUrl, demoMode } = options;
|
|
715
|
+
if (!input.confirmed) {
|
|
716
|
+
return {
|
|
717
|
+
needsConfirmation: true,
|
|
718
|
+
summary: `Send ${amount} ${token} gasless on ${network} to ${to}`,
|
|
719
|
+
details: { to, amount, token, network }
|
|
720
|
+
};
|
|
721
|
+
}
|
|
671
722
|
if (!GASLESS_SUPPORTED_NETWORKS.includes(network)) {
|
|
672
723
|
throw new Error(
|
|
673
724
|
`Network ${network} does not support ERC-4337 gasless transactions. Supported: ${GASLESS_SUPPORTED_NETWORKS.join(", ")}`
|
|
@@ -953,7 +1004,8 @@ var bridgeInputSchema = import_zod6.z.object({
|
|
|
953
1004
|
fromChain: import_zod6.z.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Source chain to bridge from"),
|
|
954
1005
|
toChain: import_zod6.z.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Destination chain to bridge to"),
|
|
955
1006
|
amount: import_zod6.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"),
|
|
956
|
-
recipient: import_zod6.z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain")
|
|
1007
|
+
recipient: import_zod6.z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain"),
|
|
1008
|
+
confirmed: import_zod6.z.boolean().optional().describe("Set to true to confirm and execute this bridge")
|
|
957
1009
|
});
|
|
958
1010
|
var LAYERZERO_ENDPOINT_IDS2 = {
|
|
959
1011
|
ethereum: 30101,
|
|
@@ -1080,6 +1132,13 @@ function addressToBytes322(address) {
|
|
|
1080
1132
|
async function executeBridge(input, options) {
|
|
1081
1133
|
const { fromChain, toChain, amount, recipient } = input;
|
|
1082
1134
|
const { privateKey, rpcUrl, demoMode, slippageTolerance = 0.5 } = options;
|
|
1135
|
+
if (!input.confirmed) {
|
|
1136
|
+
return {
|
|
1137
|
+
needsConfirmation: true,
|
|
1138
|
+
summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
|
|
1139
|
+
details: { fromChain, toChain, amount, recipient }
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1083
1142
|
if (fromChain === toChain) {
|
|
1084
1143
|
throw new Error("Source and destination chains must be different");
|
|
1085
1144
|
}
|
|
@@ -1209,10 +1268,10 @@ var import_zod7 = require("zod");
|
|
|
1209
1268
|
var wdkGetWalletInputSchema = import_zod7.z.object({});
|
|
1210
1269
|
async function executeWdkGetWallet(_input, wdk) {
|
|
1211
1270
|
const signer = await wdk.getSigner("ethereum");
|
|
1212
|
-
const
|
|
1271
|
+
const chains9 = wdk.getConfiguredChains();
|
|
1213
1272
|
return {
|
|
1214
1273
|
evmAddress: signer.address,
|
|
1215
|
-
chains:
|
|
1274
|
+
chains: chains9.length > 0 ? chains9 : ["ethereum"]
|
|
1216
1275
|
};
|
|
1217
1276
|
}
|
|
1218
1277
|
function executeWdkGetWalletDemo() {
|
|
@@ -1244,14 +1303,14 @@ function findTokenFormatted(tokens, symbol) {
|
|
|
1244
1303
|
}
|
|
1245
1304
|
async function executeWdkGetBalances(input, wdk) {
|
|
1246
1305
|
const balances = await wdk.getAggregatedBalances();
|
|
1247
|
-
const
|
|
1306
|
+
const chains9 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
|
|
1248
1307
|
chain: c.chain,
|
|
1249
1308
|
usdt0: findTokenFormatted(c.tokens, "USDT0"),
|
|
1250
1309
|
usdc: findTokenFormatted(c.tokens, "USDC"),
|
|
1251
1310
|
native: (0, import_viem6.formatUnits)(c.native, 18)
|
|
1252
1311
|
}));
|
|
1253
1312
|
return {
|
|
1254
|
-
chains:
|
|
1313
|
+
chains: chains9,
|
|
1255
1314
|
totalUsdt0: (0, import_viem6.formatUnits)(balances.totalUsdt0, 6),
|
|
1256
1315
|
totalUsdc: (0, import_viem6.formatUnits)(balances.totalUsdc, 6)
|
|
1257
1316
|
};
|
|
@@ -1293,9 +1352,17 @@ var wdkTransferInputSchema = import_zod9.z.object({
|
|
|
1293
1352
|
to: import_zod9.z.string().describe("Recipient address"),
|
|
1294
1353
|
amount: import_zod9.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
|
|
1295
1354
|
token: import_zod9.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
|
|
1296
|
-
chain: import_zod9.z.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
|
|
1355
|
+
chain: import_zod9.z.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")'),
|
|
1356
|
+
confirmed: import_zod9.z.boolean().optional().describe("Set to true to confirm and execute this transfer")
|
|
1297
1357
|
});
|
|
1298
1358
|
async function executeWdkTransfer(input, wdk) {
|
|
1359
|
+
if (!input.confirmed) {
|
|
1360
|
+
return {
|
|
1361
|
+
needsConfirmation: true,
|
|
1362
|
+
summary: `Transfer ${input.amount} ${input.token} on ${input.chain} to ${input.to}`,
|
|
1363
|
+
details: { to: input.to, amount: input.amount, token: input.token, chain: input.chain }
|
|
1364
|
+
};
|
|
1365
|
+
}
|
|
1299
1366
|
const signer = await wdk.getSigner(input.chain);
|
|
1300
1367
|
const result = await signer.sendTransaction({
|
|
1301
1368
|
to: input.to
|
|
@@ -1312,6 +1379,13 @@ async function executeWdkTransfer(input, wdk) {
|
|
|
1312
1379
|
};
|
|
1313
1380
|
}
|
|
1314
1381
|
function executeWdkTransferDemo(input) {
|
|
1382
|
+
if (!input.confirmed) {
|
|
1383
|
+
return {
|
|
1384
|
+
needsConfirmation: true,
|
|
1385
|
+
summary: `Transfer ${input.amount} ${input.token} on ${input.chain} to ${input.to}`,
|
|
1386
|
+
details: { to: input.to, amount: input.amount, token: input.token, chain: input.chain }
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1315
1389
|
const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
|
|
1316
1390
|
return {
|
|
1317
1391
|
txHash: demoTxHash,
|
|
@@ -1341,9 +1415,22 @@ var wdkSwapInputSchema = import_zod10.z.object({
|
|
|
1341
1415
|
fromToken: import_zod10.z.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
|
|
1342
1416
|
toToken: import_zod10.z.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
|
|
1343
1417
|
amount: import_zod10.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
|
|
1344
|
-
chain: import_zod10.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
|
|
1418
|
+
chain: import_zod10.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")'),
|
|
1419
|
+
confirmed: import_zod10.z.boolean().optional().describe("Set to true to confirm and execute this swap")
|
|
1345
1420
|
});
|
|
1346
1421
|
async function executeWdkSwap(input, wdk) {
|
|
1422
|
+
if (!input.confirmed) {
|
|
1423
|
+
return {
|
|
1424
|
+
needsConfirmation: true,
|
|
1425
|
+
summary: `Swap ${input.amount} ${input.fromToken} to ${input.toToken} on ${input.chain}`,
|
|
1426
|
+
details: {
|
|
1427
|
+
fromToken: input.fromToken,
|
|
1428
|
+
toToken: input.toToken,
|
|
1429
|
+
amount: input.amount,
|
|
1430
|
+
chain: input.chain
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1347
1434
|
const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
|
|
1348
1435
|
const amountBigInt = (0, import_viem7.parseUnits)(input.amount, decimals);
|
|
1349
1436
|
const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
|
|
@@ -1364,6 +1451,18 @@ async function executeWdkSwap(input, wdk) {
|
|
|
1364
1451
|
};
|
|
1365
1452
|
}
|
|
1366
1453
|
function executeWdkSwapDemo(input) {
|
|
1454
|
+
if (!input.confirmed) {
|
|
1455
|
+
return {
|
|
1456
|
+
needsConfirmation: true,
|
|
1457
|
+
summary: `Swap ${input.amount} ${input.fromToken} to ${input.toToken} on ${input.chain}`,
|
|
1458
|
+
details: {
|
|
1459
|
+
fromToken: input.fromToken,
|
|
1460
|
+
toToken: input.toToken,
|
|
1461
|
+
amount: input.amount,
|
|
1462
|
+
chain: input.chain
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1367
1466
|
const inputAmount = parseFloat(input.amount);
|
|
1368
1467
|
const outputAmount = (inputAmount * 0.997).toFixed(6);
|
|
1369
1468
|
return {
|
|
@@ -1396,12 +1495,24 @@ var autoPayInputSchema = import_zod11.z.object({
|
|
|
1396
1495
|
maxAmount: import_zod11.z.string().regex(/^\d+(\.\d+)?$/).optional().describe('Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'),
|
|
1397
1496
|
preferredChain: import_zod11.z.string().optional().describe(
|
|
1398
1497
|
'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
|
|
1399
|
-
)
|
|
1498
|
+
),
|
|
1499
|
+
confirmed: import_zod11.z.boolean().optional().describe("Set to true to confirm and execute this payment")
|
|
1400
1500
|
});
|
|
1401
1501
|
async function executeAutoPay(input, wdk) {
|
|
1402
|
-
|
|
1502
|
+
if (!input.confirmed) {
|
|
1503
|
+
return {
|
|
1504
|
+
needsConfirmation: true,
|
|
1505
|
+
summary: `Auto-pay for ${input.url}${input.maxAmount ? ` (max ${input.maxAmount})` : ""}`,
|
|
1506
|
+
details: {
|
|
1507
|
+
url: input.url,
|
|
1508
|
+
...input.maxAmount ? { maxAmount: input.maxAmount } : {},
|
|
1509
|
+
...input.preferredChain ? { preferredChain: input.preferredChain } : {}
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
const chains9 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
|
|
1403
1514
|
const { T402Protocol } = await import("@t402/wdk-protocol");
|
|
1404
|
-
const protocol = await T402Protocol.create(wdk, { chains:
|
|
1515
|
+
const protocol = await T402Protocol.create(wdk, { chains: chains9 });
|
|
1405
1516
|
const { response, receipt } = await protocol.fetch(input.url);
|
|
1406
1517
|
if (receipt && input.maxAmount) {
|
|
1407
1518
|
const paidAmount = parseFloat(receipt.amount) / 1e6;
|
|
@@ -1439,6 +1550,17 @@ async function executeAutoPay(input, wdk) {
|
|
|
1439
1550
|
};
|
|
1440
1551
|
}
|
|
1441
1552
|
function executeAutoPayDemo(input) {
|
|
1553
|
+
if (!input.confirmed) {
|
|
1554
|
+
return {
|
|
1555
|
+
needsConfirmation: true,
|
|
1556
|
+
summary: `Auto-pay for ${input.url}${input.maxAmount ? ` (max ${input.maxAmount})` : ""}`,
|
|
1557
|
+
details: {
|
|
1558
|
+
url: input.url,
|
|
1559
|
+
...input.maxAmount ? { maxAmount: input.maxAmount } : {},
|
|
1560
|
+
...input.preferredChain ? { preferredChain: input.preferredChain } : {}
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1442
1564
|
return {
|
|
1443
1565
|
success: true,
|
|
1444
1566
|
statusCode: 200,
|
|
@@ -1890,22 +2012,744 @@ function formatErc8004VerifyWalletResult(result) {
|
|
|
1890
2012
|
return lines.join("\n");
|
|
1891
2013
|
}
|
|
1892
2014
|
|
|
1893
|
-
// src/tools/
|
|
2015
|
+
// src/tools/priceService.ts
|
|
2016
|
+
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
2017
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
|
|
2018
|
+
var TOKEN_TO_COINGECKO_ID = {
|
|
2019
|
+
ETH: "ethereum",
|
|
2020
|
+
MATIC: "matic-network",
|
|
2021
|
+
AVAX: "avalanche-2",
|
|
2022
|
+
BERA: "berachain-bera",
|
|
2023
|
+
USDC: "usd-coin",
|
|
2024
|
+
USDT: "tether",
|
|
2025
|
+
USDT0: "tether"
|
|
2026
|
+
};
|
|
2027
|
+
var cache = /* @__PURE__ */ new Map();
|
|
2028
|
+
async function getTokenPrices(tokens, currency = "usd") {
|
|
2029
|
+
const cacheKey = `${currency}:${tokens.sort().join(",")}`;
|
|
2030
|
+
const cached = cache.get(cacheKey);
|
|
2031
|
+
if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
|
|
2032
|
+
return cached.prices;
|
|
2033
|
+
}
|
|
2034
|
+
const coinIds = /* @__PURE__ */ new Set();
|
|
2035
|
+
const tokenToCoinId = /* @__PURE__ */ new Map();
|
|
2036
|
+
for (const token of tokens) {
|
|
2037
|
+
const coinId = TOKEN_TO_COINGECKO_ID[token.toUpperCase()] ?? token.toLowerCase();
|
|
2038
|
+
coinIds.add(coinId);
|
|
2039
|
+
tokenToCoinId.set(token.toUpperCase(), coinId);
|
|
2040
|
+
}
|
|
2041
|
+
const url = `${COINGECKO_API}?ids=${[...coinIds].join(",")}&vs_currencies=${currency}`;
|
|
2042
|
+
const response = await fetch(url);
|
|
2043
|
+
if (!response.ok) {
|
|
2044
|
+
throw new Error(`CoinGecko API error: ${response.status} ${response.statusText}`);
|
|
2045
|
+
}
|
|
2046
|
+
const data = await response.json();
|
|
2047
|
+
const prices = {};
|
|
2048
|
+
for (const token of tokens) {
|
|
2049
|
+
const coinId = tokenToCoinId.get(token.toUpperCase()) ?? token.toLowerCase();
|
|
2050
|
+
prices[token.toUpperCase()] = data[coinId]?.[currency] ?? 0;
|
|
2051
|
+
}
|
|
2052
|
+
cache.set(cacheKey, { prices, timestamp: Date.now() });
|
|
2053
|
+
return prices;
|
|
2054
|
+
}
|
|
2055
|
+
function getTokenPricesDemo(tokens) {
|
|
2056
|
+
const demoPrices = {
|
|
2057
|
+
ETH: 3250.42,
|
|
2058
|
+
MATIC: 0.58,
|
|
2059
|
+
AVAX: 24.15,
|
|
2060
|
+
BERA: 3.82,
|
|
2061
|
+
USDC: 1,
|
|
2062
|
+
USDT: 1,
|
|
2063
|
+
USDT0: 1
|
|
2064
|
+
};
|
|
2065
|
+
const prices = {};
|
|
2066
|
+
for (const token of tokens) {
|
|
2067
|
+
prices[token.toUpperCase()] = demoPrices[token.toUpperCase()] ?? 0;
|
|
2068
|
+
}
|
|
2069
|
+
return prices;
|
|
2070
|
+
}
|
|
2071
|
+
function clearPriceCache() {
|
|
2072
|
+
cache.clear();
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
// src/tools/getTokenPrice.ts
|
|
1894
2076
|
var import_zod15 = require("zod");
|
|
1895
|
-
var
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
2077
|
+
var getTokenPriceInputSchema = import_zod15.z.object({
|
|
2078
|
+
tokens: import_zod15.z.array(import_zod15.z.string()).min(1).describe('Token symbols to get prices for (e.g., ["ETH", "MATIC", "USDC"])'),
|
|
2079
|
+
currency: import_zod15.z.string().optional().describe('Target currency (default: "usd"). Supports: usd, eur, gbp, etc.')
|
|
2080
|
+
});
|
|
2081
|
+
async function executeGetTokenPrice(input, options) {
|
|
2082
|
+
const currency = input.currency ?? "usd";
|
|
2083
|
+
const prices = options.demoMode ? getTokenPricesDemo(input.tokens) : await getTokenPrices(input.tokens, currency);
|
|
2084
|
+
return { prices, currency };
|
|
2085
|
+
}
|
|
2086
|
+
function formatTokenPriceResult(result) {
|
|
2087
|
+
const lines = ["## Token Prices", ""];
|
|
2088
|
+
const currencyUpper = result.currency.toUpperCase();
|
|
2089
|
+
for (const [token, price] of Object.entries(result.prices)) {
|
|
2090
|
+
if (price > 0) {
|
|
2091
|
+
lines.push(`- **${token}:** ${price.toLocaleString()} ${currencyUpper}`);
|
|
2092
|
+
} else {
|
|
2093
|
+
lines.push(`- **${token}:** Price unavailable`);
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
return lines.join("\n");
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
// src/tools/getGasPrice.ts
|
|
2100
|
+
var import_zod16 = require("zod");
|
|
2101
|
+
var import_viem9 = require("viem");
|
|
2102
|
+
var chains7 = __toESM(require("viem/chains"));
|
|
2103
|
+
var getGasPriceInputSchema = import_zod16.z.object({
|
|
2104
|
+
network: import_zod16.z.enum([
|
|
2105
|
+
"ethereum",
|
|
2106
|
+
"base",
|
|
2107
|
+
"arbitrum",
|
|
2108
|
+
"optimism",
|
|
2109
|
+
"polygon",
|
|
2110
|
+
"avalanche",
|
|
2111
|
+
"ink",
|
|
2112
|
+
"berachain",
|
|
2113
|
+
"unichain"
|
|
2114
|
+
]).describe("Blockchain network to check gas price on")
|
|
2115
|
+
});
|
|
2116
|
+
function getViemChain6(network) {
|
|
2117
|
+
switch (network) {
|
|
2118
|
+
case "ethereum":
|
|
2119
|
+
return chains7.mainnet;
|
|
2120
|
+
case "base":
|
|
2121
|
+
return chains7.base;
|
|
2122
|
+
case "arbitrum":
|
|
2123
|
+
return chains7.arbitrum;
|
|
2124
|
+
case "optimism":
|
|
2125
|
+
return chains7.optimism;
|
|
2126
|
+
case "polygon":
|
|
2127
|
+
return chains7.polygon;
|
|
2128
|
+
case "avalanche":
|
|
2129
|
+
return chains7.avalanche;
|
|
2130
|
+
case "ink":
|
|
2131
|
+
return chains7.ink;
|
|
2132
|
+
case "berachain":
|
|
2133
|
+
return chains7.berachain;
|
|
2134
|
+
case "unichain":
|
|
2135
|
+
return chains7.unichain;
|
|
2136
|
+
default:
|
|
2137
|
+
return chains7.mainnet;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
async function executeGetGasPrice(input, options) {
|
|
2141
|
+
const { network } = input;
|
|
2142
|
+
if (options.demoMode) {
|
|
2143
|
+
const demoGasPrices = {
|
|
2144
|
+
ethereum: 25000000000n,
|
|
2145
|
+
// 25 gwei
|
|
2146
|
+
base: 50000000n,
|
|
2147
|
+
// 0.05 gwei
|
|
2148
|
+
arbitrum: 100000000n,
|
|
2149
|
+
// 0.1 gwei
|
|
2150
|
+
optimism: 50000000n,
|
|
2151
|
+
// 0.05 gwei
|
|
2152
|
+
polygon: 30000000000n,
|
|
2153
|
+
// 30 gwei
|
|
2154
|
+
avalanche: 25000000000n,
|
|
2155
|
+
// 25 nAVAX
|
|
2156
|
+
ink: 50000000n,
|
|
2157
|
+
// 0.05 gwei
|
|
2158
|
+
berachain: 1000000000n,
|
|
2159
|
+
// 1 gwei
|
|
2160
|
+
unichain: 50000000n
|
|
2161
|
+
// 0.05 gwei
|
|
2162
|
+
};
|
|
2163
|
+
const gasPrice2 = demoGasPrices[network] ?? 1000000000n;
|
|
2164
|
+
return {
|
|
2165
|
+
network,
|
|
2166
|
+
gasPriceWei: gasPrice2.toString(),
|
|
2167
|
+
gasPriceGwei: (0, import_viem9.formatGwei)(gasPrice2),
|
|
2168
|
+
nativeSymbol: NATIVE_SYMBOLS[network]
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
const chain = getViemChain6(network);
|
|
2172
|
+
const transport = (0, import_viem9.http)(options.rpcUrl ?? DEFAULT_RPC_URLS[network]);
|
|
2173
|
+
const client = (0, import_viem9.createPublicClient)({ chain, transport });
|
|
2174
|
+
const gasPrice = await client.getGasPrice();
|
|
2175
|
+
return {
|
|
2176
|
+
network,
|
|
2177
|
+
gasPriceWei: gasPrice.toString(),
|
|
2178
|
+
gasPriceGwei: (0, import_viem9.formatGwei)(gasPrice),
|
|
2179
|
+
nativeSymbol: NATIVE_SYMBOLS[network]
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
function formatGasPriceResult(result) {
|
|
2183
|
+
return [
|
|
2184
|
+
"## Gas Price",
|
|
2185
|
+
"",
|
|
2186
|
+
`- **Network:** ${result.network}`,
|
|
2187
|
+
`- **Gas Price:** ${result.gasPriceGwei} gwei`,
|
|
2188
|
+
`- **Native Token:** ${result.nativeSymbol}`
|
|
2189
|
+
].join("\n");
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// src/tools/estimatePaymentFee.ts
|
|
2193
|
+
var import_zod17 = require("zod");
|
|
2194
|
+
var import_viem10 = require("viem");
|
|
2195
|
+
var chains8 = __toESM(require("viem/chains"));
|
|
2196
|
+
var estimatePaymentFeeInputSchema = import_zod17.z.object({
|
|
2197
|
+
network: import_zod17.z.enum([
|
|
2198
|
+
"ethereum",
|
|
2199
|
+
"base",
|
|
2200
|
+
"arbitrum",
|
|
2201
|
+
"optimism",
|
|
2202
|
+
"polygon",
|
|
2203
|
+
"avalanche",
|
|
2204
|
+
"ink",
|
|
2205
|
+
"berachain",
|
|
2206
|
+
"unichain"
|
|
2207
|
+
]).describe("Network to estimate fee on"),
|
|
2208
|
+
amount: import_zod17.z.string().regex(/^\d+(\.\d+)?$/).describe("Payment amount (e.g., '100')"),
|
|
2209
|
+
token: import_zod17.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment")
|
|
2210
|
+
});
|
|
2211
|
+
function getViemChain7(network) {
|
|
2212
|
+
switch (network) {
|
|
2213
|
+
case "ethereum":
|
|
2214
|
+
return chains8.mainnet;
|
|
2215
|
+
case "base":
|
|
2216
|
+
return chains8.base;
|
|
2217
|
+
case "arbitrum":
|
|
2218
|
+
return chains8.arbitrum;
|
|
2219
|
+
case "optimism":
|
|
2220
|
+
return chains8.optimism;
|
|
2221
|
+
case "polygon":
|
|
2222
|
+
return chains8.polygon;
|
|
2223
|
+
case "avalanche":
|
|
2224
|
+
return chains8.avalanche;
|
|
2225
|
+
case "ink":
|
|
2226
|
+
return chains8.ink;
|
|
2227
|
+
case "berachain":
|
|
2228
|
+
return chains8.berachain;
|
|
2229
|
+
case "unichain":
|
|
2230
|
+
return chains8.unichain;
|
|
2231
|
+
default:
|
|
2232
|
+
return chains8.mainnet;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
async function executeEstimatePaymentFee(input, options) {
|
|
2236
|
+
const { network, amount, token } = input;
|
|
2237
|
+
const nativeSymbol = NATIVE_SYMBOLS[network];
|
|
2238
|
+
if (options.demoMode) {
|
|
2239
|
+
const demoEstimates = {
|
|
2240
|
+
ethereum: { gasLimit: 65000n, gasPrice: 25000000000n, nativePrice: 3250.42 },
|
|
2241
|
+
base: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
|
|
2242
|
+
arbitrum: { gasLimit: 65000n, gasPrice: 100000000n, nativePrice: 3250.42 },
|
|
2243
|
+
optimism: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
|
|
2244
|
+
polygon: { gasLimit: 65000n, gasPrice: 30000000000n, nativePrice: 0.58 },
|
|
2245
|
+
avalanche: { gasLimit: 65000n, gasPrice: 25000000000n, nativePrice: 24.15 },
|
|
2246
|
+
ink: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
|
|
2247
|
+
berachain: { gasLimit: 65000n, gasPrice: 1000000000n, nativePrice: 3.82 },
|
|
2248
|
+
unichain: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 }
|
|
2249
|
+
};
|
|
2250
|
+
const est = demoEstimates[network] ?? demoEstimates["ethereum"];
|
|
2251
|
+
const nativeCost2 = est.gasLimit * est.gasPrice;
|
|
2252
|
+
const usdCost2 = Number(nativeCost2) / 1e18 * est.nativePrice;
|
|
2253
|
+
return {
|
|
2254
|
+
network,
|
|
2255
|
+
gasLimit: est.gasLimit.toString(),
|
|
2256
|
+
gasPriceGwei: (0, import_viem10.formatGwei)(est.gasPrice),
|
|
2257
|
+
nativeCost: (0, import_viem10.formatEther)(nativeCost2),
|
|
2258
|
+
nativeSymbol,
|
|
2259
|
+
usdCost: `$${usdCost2.toFixed(4)}`
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
const tokenAddress = getTokenAddress(network, token);
|
|
2263
|
+
if (!tokenAddress) {
|
|
2264
|
+
throw new Error(`Token ${token} is not supported on ${network}`);
|
|
2265
|
+
}
|
|
2266
|
+
const chain = getViemChain7(network);
|
|
2267
|
+
const transport = (0, import_viem10.http)(options.rpcUrl ?? DEFAULT_RPC_URLS[network]);
|
|
2268
|
+
const client = (0, import_viem10.createPublicClient)({ chain, transport });
|
|
2269
|
+
const amountBigInt = (0, import_viem10.parseUnits)(amount, 6);
|
|
2270
|
+
const dummyTo = "0x000000000000000000000000000000000000dEaD";
|
|
2271
|
+
let gasLimit;
|
|
2272
|
+
try {
|
|
2273
|
+
gasLimit = await client.estimateGas({
|
|
2274
|
+
to: tokenAddress,
|
|
2275
|
+
data: `0xa9059cbb${dummyTo.slice(2).padStart(64, "0")}${amountBigInt.toString(16).padStart(64, "0")}`
|
|
2276
|
+
});
|
|
2277
|
+
} catch {
|
|
2278
|
+
gasLimit = 65000n;
|
|
2279
|
+
}
|
|
2280
|
+
const gasPrice = await client.getGasPrice();
|
|
2281
|
+
const nativeCost = gasLimit * gasPrice;
|
|
2282
|
+
let usdCost;
|
|
2283
|
+
try {
|
|
2284
|
+
const prices = await getTokenPrices([nativeSymbol]);
|
|
2285
|
+
const nativePrice = prices[nativeSymbol] ?? 0;
|
|
2286
|
+
const cost = Number(nativeCost) / 1e18 * nativePrice;
|
|
2287
|
+
usdCost = `$${cost.toFixed(4)}`;
|
|
2288
|
+
} catch {
|
|
2289
|
+
usdCost = "N/A";
|
|
2290
|
+
}
|
|
2291
|
+
return {
|
|
2292
|
+
network,
|
|
2293
|
+
gasLimit: gasLimit.toString(),
|
|
2294
|
+
gasPriceGwei: (0, import_viem10.formatGwei)(gasPrice),
|
|
2295
|
+
nativeCost: (0, import_viem10.formatEther)(nativeCost),
|
|
2296
|
+
nativeSymbol,
|
|
2297
|
+
usdCost
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
function formatPaymentFeeEstimate(result) {
|
|
2301
|
+
return [
|
|
2302
|
+
"## Payment Fee Estimate",
|
|
2303
|
+
"",
|
|
2304
|
+
`- **Network:** ${result.network}`,
|
|
2305
|
+
`- **Estimated Gas:** ${result.gasLimit}`,
|
|
2306
|
+
`- **Gas Price:** ${result.gasPriceGwei} gwei`,
|
|
2307
|
+
`- **Native Cost:** ${result.nativeCost} ${result.nativeSymbol}`,
|
|
2308
|
+
`- **USD Cost:** ${result.usdCost}`
|
|
2309
|
+
].join("\n");
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2312
|
+
// src/tools/compareNetworkFees.ts
|
|
2313
|
+
var import_zod18 = require("zod");
|
|
2314
|
+
var compareNetworkFeesInputSchema = import_zod18.z.object({
|
|
2315
|
+
amount: import_zod18.z.string().regex(/^\d+(\.\d+)?$/).describe("Payment amount (e.g., '100')"),
|
|
2316
|
+
token: import_zod18.z.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment"),
|
|
2317
|
+
networks: import_zod18.z.array(import_zod18.z.string()).optional().describe(
|
|
2318
|
+
"Networks to compare. If not provided, compares all networks that support the token."
|
|
2319
|
+
)
|
|
1899
2320
|
});
|
|
1900
|
-
var
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
2321
|
+
var ALL_NETWORKS2 = [
|
|
2322
|
+
"ethereum",
|
|
2323
|
+
"base",
|
|
2324
|
+
"arbitrum",
|
|
2325
|
+
"optimism",
|
|
2326
|
+
"polygon",
|
|
2327
|
+
"avalanche",
|
|
2328
|
+
"ink",
|
|
2329
|
+
"berachain",
|
|
2330
|
+
"unichain"
|
|
2331
|
+
];
|
|
2332
|
+
async function executeCompareNetworkFees(input, options) {
|
|
2333
|
+
const { amount, token } = input;
|
|
2334
|
+
const requestedNetworks = input.networks ? input.networks : ALL_NETWORKS2;
|
|
2335
|
+
const networks = requestedNetworks.filter((n) => supportsToken(n, token));
|
|
2336
|
+
if (networks.length === 0) {
|
|
2337
|
+
throw new Error(`No supported networks found for token ${token}`);
|
|
2338
|
+
}
|
|
2339
|
+
const results = await Promise.allSettled(
|
|
2340
|
+
networks.map(
|
|
2341
|
+
(network) => executeEstimatePaymentFee(
|
|
2342
|
+
{ network, amount, token },
|
|
2343
|
+
{
|
|
2344
|
+
rpcUrl: options.rpcUrls?.[network],
|
|
2345
|
+
demoMode: options.demoMode
|
|
2346
|
+
}
|
|
2347
|
+
)
|
|
2348
|
+
)
|
|
2349
|
+
);
|
|
2350
|
+
const fees = [];
|
|
2351
|
+
for (const result of results) {
|
|
2352
|
+
if (result.status === "fulfilled") {
|
|
2353
|
+
fees.push(result.value);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
if (fees.length === 0) {
|
|
2357
|
+
throw new Error("Failed to estimate fees on any network");
|
|
2358
|
+
}
|
|
2359
|
+
fees.sort((a, b) => {
|
|
2360
|
+
const costA = parseFloat(a.nativeCost) || Infinity;
|
|
2361
|
+
const costB = parseFloat(b.nativeCost) || Infinity;
|
|
2362
|
+
const usdA = parseFloat(a.usdCost.replace("$", "")) || Infinity;
|
|
2363
|
+
const usdB = parseFloat(b.usdCost.replace("$", "")) || Infinity;
|
|
2364
|
+
return usdA - usdB || costA - costB;
|
|
2365
|
+
});
|
|
2366
|
+
return {
|
|
2367
|
+
token,
|
|
2368
|
+
amount,
|
|
2369
|
+
fees,
|
|
2370
|
+
cheapest: fees[0].network
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2373
|
+
function formatNetworkFeeComparison(result) {
|
|
2374
|
+
const lines = [
|
|
2375
|
+
"## Network Fee Comparison",
|
|
2376
|
+
"",
|
|
2377
|
+
`**Token:** ${result.token} | **Amount:** ${result.amount}`,
|
|
2378
|
+
`**Cheapest:** ${result.cheapest}`,
|
|
2379
|
+
"",
|
|
2380
|
+
"| Network | Gas Price | Native Cost | USD Cost |",
|
|
2381
|
+
"|---------|----------|-------------|----------|"
|
|
2382
|
+
];
|
|
2383
|
+
for (const fee of result.fees) {
|
|
2384
|
+
const marker = fee.network === result.cheapest ? " *" : "";
|
|
2385
|
+
lines.push(
|
|
2386
|
+
`| ${fee.network}${marker} | ${fee.gasPriceGwei} gwei | ${fee.nativeCost} ${fee.nativeSymbol} | ${fee.usdCost} |`
|
|
2387
|
+
);
|
|
2388
|
+
}
|
|
2389
|
+
return lines.join("\n");
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
// src/tools/quoteStore.ts
|
|
2393
|
+
var import_crypto = require("crypto");
|
|
2394
|
+
var DEFAULT_TTL_MS = 5 * 60 * 1e3;
|
|
2395
|
+
var quotes = /* @__PURE__ */ new Map();
|
|
2396
|
+
var cleanupInterval = null;
|
|
2397
|
+
function ensureCleanup() {
|
|
2398
|
+
if (cleanupInterval) return;
|
|
2399
|
+
cleanupInterval = setInterval(() => {
|
|
2400
|
+
const now = Date.now();
|
|
2401
|
+
for (const [id, quote] of quotes) {
|
|
2402
|
+
if (now > quote.expiresAt) {
|
|
2403
|
+
quotes.delete(id);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
}, 6e4);
|
|
2407
|
+
if (cleanupInterval.unref) {
|
|
2408
|
+
cleanupInterval.unref();
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
function createQuote(type, data, ttlMs = DEFAULT_TTL_MS) {
|
|
2412
|
+
ensureCleanup();
|
|
2413
|
+
const id = (0, import_crypto.randomUUID)();
|
|
2414
|
+
const now = Date.now();
|
|
2415
|
+
quotes.set(id, {
|
|
2416
|
+
id,
|
|
2417
|
+
type,
|
|
2418
|
+
createdAt: now,
|
|
2419
|
+
expiresAt: now + ttlMs,
|
|
2420
|
+
data
|
|
2421
|
+
});
|
|
2422
|
+
return id;
|
|
2423
|
+
}
|
|
2424
|
+
function getQuote(quoteId) {
|
|
2425
|
+
const quote = quotes.get(quoteId);
|
|
2426
|
+
if (!quote) return null;
|
|
2427
|
+
if (Date.now() > quote.expiresAt) {
|
|
2428
|
+
quotes.delete(quoteId);
|
|
2429
|
+
return null;
|
|
2430
|
+
}
|
|
2431
|
+
return quote;
|
|
2432
|
+
}
|
|
2433
|
+
function deleteQuote(quoteId) {
|
|
2434
|
+
quotes.delete(quoteId);
|
|
2435
|
+
}
|
|
2436
|
+
function clearQuoteStore() {
|
|
2437
|
+
quotes.clear();
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
// src/tools/wdkQuoteSwap.ts
|
|
2441
|
+
var import_zod19 = require("zod");
|
|
2442
|
+
var import_viem11 = require("viem");
|
|
2443
|
+
var wdkQuoteSwapInputSchema = import_zod19.z.object({
|
|
2444
|
+
fromToken: import_zod19.z.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
|
|
2445
|
+
toToken: import_zod19.z.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
|
|
2446
|
+
amount: import_zod19.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
|
|
2447
|
+
chain: import_zod19.z.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
|
|
2448
|
+
});
|
|
2449
|
+
async function executeWdkQuoteSwap(input, wdk) {
|
|
2450
|
+
const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
|
|
2451
|
+
const amountBigInt = (0, import_viem11.parseUnits)(input.amount, decimals);
|
|
2452
|
+
const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
|
|
2453
|
+
const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
|
|
2454
|
+
const outputDivisor = 10 ** outputDecimals;
|
|
2455
|
+
const toAmount = (Number(quote.outputAmount) / outputDivisor).toFixed(outputDecimals === 6 ? 6 : 8);
|
|
2456
|
+
const inputAmount = parseFloat(input.amount);
|
|
2457
|
+
const outputAmount = parseFloat(toAmount);
|
|
2458
|
+
const exchangeRate = inputAmount > 0 ? (outputAmount / inputAmount).toFixed(6) : "0";
|
|
2459
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
|
|
2460
|
+
const quoteId = createQuote("swap", {
|
|
2461
|
+
fromToken: input.fromToken,
|
|
2462
|
+
toToken: input.toToken,
|
|
2463
|
+
fromAmount: input.amount,
|
|
2464
|
+
toAmount,
|
|
2465
|
+
chain: input.chain,
|
|
2466
|
+
exchangeRate
|
|
2467
|
+
});
|
|
2468
|
+
return {
|
|
2469
|
+
quoteId,
|
|
2470
|
+
fromToken: input.fromToken,
|
|
2471
|
+
toToken: input.toToken,
|
|
2472
|
+
fromAmount: input.amount,
|
|
2473
|
+
toAmount,
|
|
2474
|
+
exchangeRate,
|
|
2475
|
+
fee: "0.3%",
|
|
2476
|
+
priceImpact: "< 0.1%",
|
|
2477
|
+
expiresAt,
|
|
2478
|
+
chain: input.chain
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
function executeWdkQuoteSwapDemo(input) {
|
|
2482
|
+
const inputAmount = parseFloat(input.amount);
|
|
2483
|
+
const toAmount = (inputAmount * 0.997).toFixed(6);
|
|
2484
|
+
const exchangeRate = 0.997.toFixed(6);
|
|
2485
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
|
|
2486
|
+
const quoteId = createQuote("swap", {
|
|
2487
|
+
fromToken: input.fromToken,
|
|
2488
|
+
toToken: input.toToken,
|
|
2489
|
+
fromAmount: input.amount,
|
|
2490
|
+
toAmount,
|
|
2491
|
+
chain: input.chain,
|
|
2492
|
+
exchangeRate
|
|
2493
|
+
});
|
|
2494
|
+
return {
|
|
2495
|
+
quoteId,
|
|
2496
|
+
fromToken: input.fromToken,
|
|
2497
|
+
toToken: input.toToken,
|
|
2498
|
+
fromAmount: input.amount,
|
|
2499
|
+
toAmount,
|
|
2500
|
+
exchangeRate,
|
|
2501
|
+
fee: "0.3%",
|
|
2502
|
+
priceImpact: "< 0.1%",
|
|
2503
|
+
expiresAt,
|
|
2504
|
+
chain: input.chain
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
function formatSwapQuoteResult(result) {
|
|
2508
|
+
return [
|
|
2509
|
+
"## Swap Quote",
|
|
2510
|
+
"",
|
|
2511
|
+
`- **Quote ID:** \`${result.quoteId}\``,
|
|
2512
|
+
`- **From:** ${result.fromAmount} ${result.fromToken}`,
|
|
2513
|
+
`- **To:** ${result.toAmount} ${result.toToken}`,
|
|
2514
|
+
`- **Exchange Rate:** ${result.exchangeRate}`,
|
|
2515
|
+
`- **Fee:** ${result.fee}`,
|
|
2516
|
+
`- **Price Impact:** ${result.priceImpact}`,
|
|
2517
|
+
`- **Chain:** ${result.chain}`,
|
|
2518
|
+
`- **Expires:** ${result.expiresAt}`,
|
|
2519
|
+
"",
|
|
2520
|
+
"_Call `wdk/executeSwap` with the quoteId to execute this swap._"
|
|
2521
|
+
].join("\n");
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// src/tools/wdkExecuteSwap.ts
|
|
2525
|
+
var import_zod20 = require("zod");
|
|
2526
|
+
var import_viem12 = require("viem");
|
|
2527
|
+
var wdkExecuteSwapInputSchema = import_zod20.z.object({
|
|
2528
|
+
quoteId: import_zod20.z.string().uuid().describe("Quote ID from wdk/quoteSwap"),
|
|
2529
|
+
confirmed: import_zod20.z.boolean().optional().describe("Set to true to confirm and execute this swap")
|
|
2530
|
+
});
|
|
2531
|
+
async function executeWdkExecuteSwap(input, wdk) {
|
|
2532
|
+
const quote = getQuote(input.quoteId);
|
|
2533
|
+
if (!quote) {
|
|
2534
|
+
throw new Error("Quote not found or expired. Please request a new quote.");
|
|
2535
|
+
}
|
|
2536
|
+
if (quote.type !== "swap") {
|
|
2537
|
+
throw new Error("Invalid quote type. Expected a swap quote.");
|
|
2538
|
+
}
|
|
2539
|
+
const { fromToken, toToken, fromAmount, toAmount, chain } = quote.data;
|
|
2540
|
+
if (!input.confirmed) {
|
|
2541
|
+
return {
|
|
2542
|
+
needsConfirmation: true,
|
|
2543
|
+
summary: `Swap ${fromAmount} ${fromToken} to ${toAmount} ${toToken} on ${chain}`,
|
|
2544
|
+
details: { fromToken, toToken, fromAmount, toAmount, chain, quoteId: input.quoteId }
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
const decimals = ["USDC", "USDT", "USDT0"].includes(fromToken.toUpperCase()) ? 6 : 18;
|
|
2548
|
+
const amountBigInt = (0, import_viem12.parseUnits)(fromAmount, decimals);
|
|
2549
|
+
const result = await wdk.swapAndPay({
|
|
2550
|
+
chain,
|
|
2551
|
+
fromToken,
|
|
2552
|
+
amount: amountBigInt
|
|
2553
|
+
});
|
|
2554
|
+
deleteQuote(input.quoteId);
|
|
2555
|
+
return {
|
|
2556
|
+
fromAmount,
|
|
2557
|
+
fromToken,
|
|
2558
|
+
toAmount,
|
|
2559
|
+
toToken,
|
|
2560
|
+
chain,
|
|
2561
|
+
txHash: result?.txHash ?? "0x"
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
function executeWdkExecuteSwapDemo(input) {
|
|
2565
|
+
const quote = getQuote(input.quoteId);
|
|
2566
|
+
if (!quote) {
|
|
2567
|
+
throw new Error("Quote not found or expired. Please request a new quote.");
|
|
2568
|
+
}
|
|
2569
|
+
if (quote.type !== "swap") {
|
|
2570
|
+
throw new Error("Invalid quote type. Expected a swap quote.");
|
|
2571
|
+
}
|
|
2572
|
+
const { fromToken, toToken, fromAmount, toAmount, chain } = quote.data;
|
|
2573
|
+
if (!input.confirmed) {
|
|
2574
|
+
return {
|
|
2575
|
+
needsConfirmation: true,
|
|
2576
|
+
summary: `Swap ${fromAmount} ${fromToken} to ${toAmount} ${toToken} on ${chain}`,
|
|
2577
|
+
details: { fromToken, toToken, fromAmount, toAmount, chain, quoteId: input.quoteId }
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
deleteQuote(input.quoteId);
|
|
2581
|
+
return {
|
|
2582
|
+
fromAmount,
|
|
2583
|
+
fromToken,
|
|
2584
|
+
toAmount,
|
|
2585
|
+
toToken,
|
|
2586
|
+
chain,
|
|
2587
|
+
txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
function formatExecuteSwapResult(result) {
|
|
2591
|
+
return [
|
|
2592
|
+
"## Swap Executed",
|
|
2593
|
+
"",
|
|
2594
|
+
`- **From:** ${result.fromAmount} ${result.fromToken}`,
|
|
2595
|
+
`- **To:** ${result.toAmount} ${result.toToken}`,
|
|
2596
|
+
`- **Chain:** ${result.chain}`,
|
|
2597
|
+
`- **Tx Hash:** \`${result.txHash}\``
|
|
2598
|
+
].join("\n");
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
// src/tools/quoteBridge.ts
|
|
2602
|
+
var import_zod21 = require("zod");
|
|
2603
|
+
var quoteBridgeInputSchema = import_zod21.z.object({
|
|
2604
|
+
fromChain: import_zod21.z.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Source chain to bridge from"),
|
|
2605
|
+
toChain: import_zod21.z.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Destination chain to bridge to"),
|
|
2606
|
+
amount: import_zod21.z.string().regex(/^\d+(\.\d+)?$/).describe("Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"),
|
|
2607
|
+
recipient: import_zod21.z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain")
|
|
2608
|
+
});
|
|
2609
|
+
async function executeQuoteBridge(input, rpcUrls) {
|
|
2610
|
+
const feeResult = await executeGetBridgeFee(input, rpcUrls);
|
|
2611
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
|
|
2612
|
+
const quoteId = createQuote("bridge", {
|
|
2613
|
+
fromChain: input.fromChain,
|
|
2614
|
+
toChain: input.toChain,
|
|
2615
|
+
amount: input.amount,
|
|
2616
|
+
recipient: input.recipient,
|
|
2617
|
+
nativeFee: feeResult.nativeFee,
|
|
2618
|
+
nativeFeeFormatted: feeResult.nativeFeeFormatted,
|
|
2619
|
+
estimatedTime: feeResult.estimatedTime
|
|
2620
|
+
});
|
|
2621
|
+
return {
|
|
2622
|
+
quoteId,
|
|
2623
|
+
fromChain: input.fromChain,
|
|
2624
|
+
toChain: input.toChain,
|
|
2625
|
+
amount: input.amount,
|
|
2626
|
+
recipient: input.recipient,
|
|
2627
|
+
nativeFee: feeResult.nativeFee,
|
|
2628
|
+
nativeFeeFormatted: feeResult.nativeFeeFormatted,
|
|
2629
|
+
estimatedTime: feeResult.estimatedTime,
|
|
2630
|
+
expiresAt
|
|
2631
|
+
};
|
|
2632
|
+
}
|
|
2633
|
+
function executeQuoteBridgeDemo(input) {
|
|
2634
|
+
const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
|
|
2635
|
+
const estimatedTime = input.toChain === "ethereum" ? 900 : 300;
|
|
2636
|
+
const quoteId = createQuote("bridge", {
|
|
2637
|
+
fromChain: input.fromChain,
|
|
2638
|
+
toChain: input.toChain,
|
|
2639
|
+
amount: input.amount,
|
|
2640
|
+
recipient: input.recipient,
|
|
2641
|
+
nativeFee: "1000000000000000",
|
|
2642
|
+
nativeFeeFormatted: "0.001 ETH",
|
|
2643
|
+
estimatedTime
|
|
2644
|
+
});
|
|
2645
|
+
return {
|
|
2646
|
+
quoteId,
|
|
2647
|
+
fromChain: input.fromChain,
|
|
2648
|
+
toChain: input.toChain,
|
|
2649
|
+
amount: input.amount,
|
|
2650
|
+
recipient: input.recipient,
|
|
2651
|
+
nativeFee: "1000000000000000",
|
|
2652
|
+
nativeFeeFormatted: "0.001 ETH",
|
|
2653
|
+
estimatedTime,
|
|
2654
|
+
expiresAt
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
function formatBridgeQuoteResult(result) {
|
|
2658
|
+
const minutes = Math.ceil(result.estimatedTime / 60);
|
|
2659
|
+
return [
|
|
2660
|
+
"## Bridge Quote",
|
|
2661
|
+
"",
|
|
2662
|
+
`- **Quote ID:** \`${result.quoteId}\``,
|
|
2663
|
+
`- **Route:** ${result.fromChain} -> ${result.toChain}`,
|
|
2664
|
+
`- **Amount:** ${result.amount} USDT0`,
|
|
2665
|
+
`- **Recipient:** \`${result.recipient}\``,
|
|
2666
|
+
`- **Fee:** ${result.nativeFeeFormatted}`,
|
|
2667
|
+
`- **Estimated Time:** ~${minutes} minutes`,
|
|
2668
|
+
`- **Expires:** ${result.expiresAt}`,
|
|
2669
|
+
"",
|
|
2670
|
+
"_Call `t402/executeBridge` with the quoteId to execute this bridge._"
|
|
2671
|
+
].join("\n");
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2674
|
+
// src/tools/executeBridgeFromQuote.ts
|
|
2675
|
+
var import_zod22 = require("zod");
|
|
2676
|
+
var executeBridgeFromQuoteInputSchema = import_zod22.z.object({
|
|
2677
|
+
quoteId: import_zod22.z.string().uuid().describe("Quote ID from t402/quoteBridge"),
|
|
2678
|
+
confirmed: import_zod22.z.boolean().optional().describe("Set to true to confirm and execute this bridge")
|
|
2679
|
+
});
|
|
2680
|
+
async function executeExecuteBridgeFromQuote(input, options) {
|
|
2681
|
+
const quote = getQuote(input.quoteId);
|
|
2682
|
+
if (!quote) {
|
|
2683
|
+
throw new Error("Quote not found or expired. Please request a new quote.");
|
|
2684
|
+
}
|
|
2685
|
+
if (quote.type !== "bridge") {
|
|
2686
|
+
throw new Error("Invalid quote type. Expected a bridge quote.");
|
|
2687
|
+
}
|
|
2688
|
+
const { fromChain, toChain, amount, recipient } = quote.data;
|
|
2689
|
+
if (!input.confirmed) {
|
|
2690
|
+
return {
|
|
2691
|
+
needsConfirmation: true,
|
|
2692
|
+
summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
|
|
2693
|
+
details: { fromChain, toChain, amount, recipient, quoteId: input.quoteId }
|
|
2694
|
+
};
|
|
2695
|
+
}
|
|
2696
|
+
const result = await executeBridge(
|
|
2697
|
+
{ fromChain, toChain, amount, recipient, confirmed: true },
|
|
2698
|
+
options
|
|
2699
|
+
);
|
|
2700
|
+
if ("needsConfirmation" in result) {
|
|
2701
|
+
return result;
|
|
2702
|
+
}
|
|
2703
|
+
deleteQuote(input.quoteId);
|
|
2704
|
+
return result;
|
|
2705
|
+
}
|
|
2706
|
+
function executeExecuteBridgeFromQuoteDemo(input) {
|
|
2707
|
+
const quote = getQuote(input.quoteId);
|
|
2708
|
+
if (!quote) {
|
|
2709
|
+
throw new Error("Quote not found or expired. Please request a new quote.");
|
|
2710
|
+
}
|
|
2711
|
+
if (quote.type !== "bridge") {
|
|
2712
|
+
throw new Error("Invalid quote type. Expected a bridge quote.");
|
|
2713
|
+
}
|
|
2714
|
+
const { fromChain, toChain, amount, recipient } = quote.data;
|
|
2715
|
+
if (!input.confirmed) {
|
|
2716
|
+
return {
|
|
2717
|
+
needsConfirmation: true,
|
|
2718
|
+
summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
|
|
2719
|
+
details: { fromChain, toChain, amount, recipient, quoteId: input.quoteId }
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
deleteQuote(input.quoteId);
|
|
2723
|
+
const fakeTxHash = `0x${"a".repeat(64)}`;
|
|
2724
|
+
const fakeGuid = `0x${"b".repeat(64)}`;
|
|
2725
|
+
return {
|
|
2726
|
+
txHash: fakeTxHash,
|
|
2727
|
+
messageGuid: fakeGuid,
|
|
2728
|
+
amount,
|
|
2729
|
+
fromChain,
|
|
2730
|
+
toChain,
|
|
2731
|
+
estimatedTime: quote.data.estimatedTime ?? 300,
|
|
2732
|
+
trackingUrl: `https://layerzeroscan.com/tx/${fakeGuid}`
|
|
2733
|
+
};
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
// src/tools/unified.ts
|
|
2737
|
+
var import_zod23 = require("zod");
|
|
2738
|
+
var smartPayInputSchema = import_zod23.z.object({
|
|
2739
|
+
url: import_zod23.z.string().url().describe("URL of the 402-protected resource"),
|
|
2740
|
+
maxBridgeFee: import_zod23.z.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
|
|
2741
|
+
preferredNetwork: import_zod23.z.string().optional().describe("Preferred network for payment (optional)"),
|
|
2742
|
+
confirmed: import_zod23.z.boolean().optional().describe("Set to true to confirm and execute this payment")
|
|
2743
|
+
});
|
|
2744
|
+
var paymentPlanInputSchema = import_zod23.z.object({
|
|
2745
|
+
paymentRequired: import_zod23.z.object({
|
|
2746
|
+
scheme: import_zod23.z.string().optional(),
|
|
2747
|
+
network: import_zod23.z.string().optional(),
|
|
2748
|
+
maxAmountRequired: import_zod23.z.string().optional(),
|
|
2749
|
+
resource: import_zod23.z.string().optional(),
|
|
2750
|
+
description: import_zod23.z.string().optional(),
|
|
2751
|
+
payTo: import_zod23.z.string().optional(),
|
|
2752
|
+
maxDeadline: import_zod23.z.number().optional()
|
|
1909
2753
|
}).passthrough().describe("The 402 PaymentRequired response")
|
|
1910
2754
|
});
|
|
1911
2755
|
var UNIFIED_TOOL_DEFINITIONS = {
|
|
@@ -1923,6 +2767,10 @@ var UNIFIED_TOOL_DEFINITIONS = {
|
|
|
1923
2767
|
preferredNetwork: {
|
|
1924
2768
|
type: "string",
|
|
1925
2769
|
description: "Preferred network for payment (optional)"
|
|
2770
|
+
},
|
|
2771
|
+
confirmed: {
|
|
2772
|
+
type: "boolean",
|
|
2773
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
1926
2774
|
}
|
|
1927
2775
|
},
|
|
1928
2776
|
required: ["url"]
|
|
@@ -1944,15 +2792,26 @@ var UNIFIED_TOOL_DEFINITIONS = {
|
|
|
1944
2792
|
}
|
|
1945
2793
|
};
|
|
1946
2794
|
async function executeSmartPay(input, wdk) {
|
|
2795
|
+
if (!input.confirmed) {
|
|
2796
|
+
return {
|
|
2797
|
+
needsConfirmation: true,
|
|
2798
|
+
summary: `Smart-pay for ${input.url}${input.preferredNetwork ? ` on ${input.preferredNetwork}` : ""}`,
|
|
2799
|
+
details: {
|
|
2800
|
+
url: input.url,
|
|
2801
|
+
...input.maxBridgeFee ? { maxBridgeFee: input.maxBridgeFee } : {},
|
|
2802
|
+
...input.preferredNetwork ? { preferredNetwork: input.preferredNetwork } : {}
|
|
2803
|
+
}
|
|
2804
|
+
};
|
|
2805
|
+
}
|
|
1947
2806
|
const steps = [];
|
|
1948
|
-
const
|
|
2807
|
+
const chains9 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
|
|
1949
2808
|
steps.push({
|
|
1950
2809
|
action: "check_balance",
|
|
1951
2810
|
status: "success",
|
|
1952
|
-
detail: `Checking balances on ${
|
|
2811
|
+
detail: `Checking balances on ${chains9.join(", ")}`
|
|
1953
2812
|
});
|
|
1954
2813
|
const { T402Protocol } = await import("@t402/wdk-protocol");
|
|
1955
|
-
const protocol = await T402Protocol.create(wdk, { chains:
|
|
2814
|
+
const protocol = await T402Protocol.create(wdk, { chains: chains9 });
|
|
1956
2815
|
steps.push({
|
|
1957
2816
|
action: "fetch",
|
|
1958
2817
|
status: "success",
|
|
@@ -1991,6 +2850,17 @@ async function executeSmartPay(input, wdk) {
|
|
|
1991
2850
|
};
|
|
1992
2851
|
}
|
|
1993
2852
|
function executeSmartPayDemo(input) {
|
|
2853
|
+
if (!input.confirmed) {
|
|
2854
|
+
return {
|
|
2855
|
+
needsConfirmation: true,
|
|
2856
|
+
summary: `Smart-pay for ${input.url}${input.preferredNetwork ? ` on ${input.preferredNetwork}` : ""}`,
|
|
2857
|
+
details: {
|
|
2858
|
+
url: input.url,
|
|
2859
|
+
...input.maxBridgeFee ? { maxBridgeFee: input.maxBridgeFee } : {},
|
|
2860
|
+
...input.preferredNetwork ? { preferredNetwork: input.preferredNetwork } : {}
|
|
2861
|
+
}
|
|
2862
|
+
};
|
|
2863
|
+
}
|
|
1994
2864
|
const network = input.preferredNetwork ?? "arbitrum";
|
|
1995
2865
|
return {
|
|
1996
2866
|
success: true,
|
|
@@ -2244,6 +3114,10 @@ var TOOL_DEFINITIONS = {
|
|
|
2244
3114
|
memo: {
|
|
2245
3115
|
type: "string",
|
|
2246
3116
|
description: "Optional memo/reference for the payment"
|
|
3117
|
+
},
|
|
3118
|
+
confirmed: {
|
|
3119
|
+
type: "boolean",
|
|
3120
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2247
3121
|
}
|
|
2248
3122
|
},
|
|
2249
3123
|
required: ["to", "amount", "token", "network"]
|
|
@@ -2274,6 +3148,10 @@ var TOOL_DEFINITIONS = {
|
|
|
2274
3148
|
type: "string",
|
|
2275
3149
|
enum: ["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"],
|
|
2276
3150
|
description: "Network to execute gasless payment on (must support ERC-4337)"
|
|
3151
|
+
},
|
|
3152
|
+
confirmed: {
|
|
3153
|
+
type: "boolean",
|
|
3154
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2277
3155
|
}
|
|
2278
3156
|
},
|
|
2279
3157
|
required: ["to", "amount", "token", "network"]
|
|
@@ -2334,10 +3212,166 @@ var TOOL_DEFINITIONS = {
|
|
|
2334
3212
|
type: "string",
|
|
2335
3213
|
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
2336
3214
|
description: "Recipient address on destination chain"
|
|
3215
|
+
},
|
|
3216
|
+
confirmed: {
|
|
3217
|
+
type: "boolean",
|
|
3218
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2337
3219
|
}
|
|
2338
3220
|
},
|
|
2339
3221
|
required: ["fromChain", "toChain", "amount", "recipient"]
|
|
2340
3222
|
}
|
|
3223
|
+
},
|
|
3224
|
+
"t402/getTokenPrice": {
|
|
3225
|
+
name: "t402/getTokenPrice",
|
|
3226
|
+
description: "Get current market prices for tokens (ETH, MATIC, AVAX, USDC, etc.) via CoinGecko. Cached for 5 minutes.",
|
|
3227
|
+
inputSchema: {
|
|
3228
|
+
type: "object",
|
|
3229
|
+
properties: {
|
|
3230
|
+
tokens: {
|
|
3231
|
+
type: "array",
|
|
3232
|
+
items: { type: "string" },
|
|
3233
|
+
description: 'Token symbols to get prices for (e.g., ["ETH", "MATIC", "USDC"])'
|
|
3234
|
+
},
|
|
3235
|
+
currency: {
|
|
3236
|
+
type: "string",
|
|
3237
|
+
description: 'Target currency (default: "usd")'
|
|
3238
|
+
}
|
|
3239
|
+
},
|
|
3240
|
+
required: ["tokens"]
|
|
3241
|
+
}
|
|
3242
|
+
},
|
|
3243
|
+
"t402/getGasPrice": {
|
|
3244
|
+
name: "t402/getGasPrice",
|
|
3245
|
+
description: "Get the current gas price on a specific blockchain network. Returns the price in gwei.",
|
|
3246
|
+
inputSchema: {
|
|
3247
|
+
type: "object",
|
|
3248
|
+
properties: {
|
|
3249
|
+
network: {
|
|
3250
|
+
type: "string",
|
|
3251
|
+
enum: [
|
|
3252
|
+
"ethereum",
|
|
3253
|
+
"base",
|
|
3254
|
+
"arbitrum",
|
|
3255
|
+
"optimism",
|
|
3256
|
+
"polygon",
|
|
3257
|
+
"avalanche",
|
|
3258
|
+
"ink",
|
|
3259
|
+
"berachain",
|
|
3260
|
+
"unichain"
|
|
3261
|
+
],
|
|
3262
|
+
description: "Blockchain network to check gas price on"
|
|
3263
|
+
}
|
|
3264
|
+
},
|
|
3265
|
+
required: ["network"]
|
|
3266
|
+
}
|
|
3267
|
+
},
|
|
3268
|
+
"t402/estimatePaymentFee": {
|
|
3269
|
+
name: "t402/estimatePaymentFee",
|
|
3270
|
+
description: "Estimate the gas cost (in native token and USD) for a stablecoin payment on a specific network.",
|
|
3271
|
+
inputSchema: {
|
|
3272
|
+
type: "object",
|
|
3273
|
+
properties: {
|
|
3274
|
+
network: {
|
|
3275
|
+
type: "string",
|
|
3276
|
+
enum: [
|
|
3277
|
+
"ethereum",
|
|
3278
|
+
"base",
|
|
3279
|
+
"arbitrum",
|
|
3280
|
+
"optimism",
|
|
3281
|
+
"polygon",
|
|
3282
|
+
"avalanche",
|
|
3283
|
+
"ink",
|
|
3284
|
+
"berachain",
|
|
3285
|
+
"unichain"
|
|
3286
|
+
],
|
|
3287
|
+
description: "Network to estimate fee on"
|
|
3288
|
+
},
|
|
3289
|
+
amount: {
|
|
3290
|
+
type: "string",
|
|
3291
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
3292
|
+
description: "Payment amount (e.g., '100')"
|
|
3293
|
+
},
|
|
3294
|
+
token: {
|
|
3295
|
+
type: "string",
|
|
3296
|
+
enum: ["USDC", "USDT", "USDT0"],
|
|
3297
|
+
description: "Token to use for payment"
|
|
3298
|
+
}
|
|
3299
|
+
},
|
|
3300
|
+
required: ["network", "amount", "token"]
|
|
3301
|
+
}
|
|
3302
|
+
},
|
|
3303
|
+
"t402/compareNetworkFees": {
|
|
3304
|
+
name: "t402/compareNetworkFees",
|
|
3305
|
+
description: "Compare payment fees across multiple networks for the same token. Returns a sorted table from cheapest to most expensive.",
|
|
3306
|
+
inputSchema: {
|
|
3307
|
+
type: "object",
|
|
3308
|
+
properties: {
|
|
3309
|
+
amount: {
|
|
3310
|
+
type: "string",
|
|
3311
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
3312
|
+
description: "Payment amount (e.g., '100')"
|
|
3313
|
+
},
|
|
3314
|
+
token: {
|
|
3315
|
+
type: "string",
|
|
3316
|
+
enum: ["USDC", "USDT", "USDT0"],
|
|
3317
|
+
description: "Token to use for payment"
|
|
3318
|
+
},
|
|
3319
|
+
networks: {
|
|
3320
|
+
type: "array",
|
|
3321
|
+
items: { type: "string" },
|
|
3322
|
+
description: "Networks to compare. If not provided, compares all networks that support the token."
|
|
3323
|
+
}
|
|
3324
|
+
},
|
|
3325
|
+
required: ["amount", "token"]
|
|
3326
|
+
}
|
|
3327
|
+
},
|
|
3328
|
+
"t402/quoteBridge": {
|
|
3329
|
+
name: "t402/quoteBridge",
|
|
3330
|
+
description: "Get a bridge fee quote with a quoteId for later execution. Like getBridgeFee but returns a reusable quoteId. Call t402/executeBridge with the quoteId to execute.",
|
|
3331
|
+
inputSchema: {
|
|
3332
|
+
type: "object",
|
|
3333
|
+
properties: {
|
|
3334
|
+
fromChain: {
|
|
3335
|
+
type: "string",
|
|
3336
|
+
enum: ["ethereum", "arbitrum", "ink", "berachain", "unichain"],
|
|
3337
|
+
description: "Source chain to bridge from"
|
|
3338
|
+
},
|
|
3339
|
+
toChain: {
|
|
3340
|
+
type: "string",
|
|
3341
|
+
enum: ["ethereum", "arbitrum", "ink", "berachain", "unichain"],
|
|
3342
|
+
description: "Destination chain to bridge to"
|
|
3343
|
+
},
|
|
3344
|
+
amount: {
|
|
3345
|
+
type: "string",
|
|
3346
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
3347
|
+
description: "Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"
|
|
3348
|
+
},
|
|
3349
|
+
recipient: {
|
|
3350
|
+
type: "string",
|
|
3351
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
3352
|
+
description: "Recipient address on destination chain"
|
|
3353
|
+
}
|
|
3354
|
+
},
|
|
3355
|
+
required: ["fromChain", "toChain", "amount", "recipient"]
|
|
3356
|
+
}
|
|
3357
|
+
},
|
|
3358
|
+
"t402/executeBridgeQuote": {
|
|
3359
|
+
name: "t402/executeBridgeQuote",
|
|
3360
|
+
description: "Execute a bridge using a quoteId from t402/quoteBridge. Requires confirmation.",
|
|
3361
|
+
inputSchema: {
|
|
3362
|
+
type: "object",
|
|
3363
|
+
properties: {
|
|
3364
|
+
quoteId: {
|
|
3365
|
+
type: "string",
|
|
3366
|
+
description: "Quote ID from t402/quoteBridge"
|
|
3367
|
+
},
|
|
3368
|
+
confirmed: {
|
|
3369
|
+
type: "boolean",
|
|
3370
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
3371
|
+
}
|
|
3372
|
+
},
|
|
3373
|
+
required: ["quoteId"]
|
|
3374
|
+
}
|
|
2341
3375
|
}
|
|
2342
3376
|
};
|
|
2343
3377
|
var WDK_TOOL_DEFINITIONS = {
|
|
@@ -2388,6 +3422,10 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
2388
3422
|
chain: {
|
|
2389
3423
|
type: "string",
|
|
2390
3424
|
description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
|
|
3425
|
+
},
|
|
3426
|
+
confirmed: {
|
|
3427
|
+
type: "boolean",
|
|
3428
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2391
3429
|
}
|
|
2392
3430
|
},
|
|
2393
3431
|
required: ["to", "amount", "token", "chain"]
|
|
@@ -2415,6 +3453,10 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
2415
3453
|
chain: {
|
|
2416
3454
|
type: "string",
|
|
2417
3455
|
description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
|
|
3456
|
+
},
|
|
3457
|
+
confirmed: {
|
|
3458
|
+
type: "boolean",
|
|
3459
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2418
3460
|
}
|
|
2419
3461
|
},
|
|
2420
3462
|
required: ["fromToken", "toToken", "amount", "chain"]
|
|
@@ -2438,10 +3480,59 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
2438
3480
|
preferredChain: {
|
|
2439
3481
|
type: "string",
|
|
2440
3482
|
description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
|
|
3483
|
+
},
|
|
3484
|
+
confirmed: {
|
|
3485
|
+
type: "boolean",
|
|
3486
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
2441
3487
|
}
|
|
2442
3488
|
},
|
|
2443
3489
|
required: ["url"]
|
|
2444
3490
|
}
|
|
3491
|
+
},
|
|
3492
|
+
"wdk/quoteSwap": {
|
|
3493
|
+
name: "wdk/quoteSwap",
|
|
3494
|
+
description: "Get a swap quote with a quoteId for later execution. Returns exchange rate, fee, and price impact. Call wdk/executeSwap with the quoteId to execute.",
|
|
3495
|
+
inputSchema: {
|
|
3496
|
+
type: "object",
|
|
3497
|
+
properties: {
|
|
3498
|
+
fromToken: {
|
|
3499
|
+
type: "string",
|
|
3500
|
+
description: 'Token to swap from (e.g., "ETH", "USDC")'
|
|
3501
|
+
},
|
|
3502
|
+
toToken: {
|
|
3503
|
+
type: "string",
|
|
3504
|
+
description: 'Token to swap to (e.g., "USDT0", "USDC")'
|
|
3505
|
+
},
|
|
3506
|
+
amount: {
|
|
3507
|
+
type: "string",
|
|
3508
|
+
pattern: "^\\d+(\\.\\d+)?$",
|
|
3509
|
+
description: "Amount to swap (e.g., '1.0')"
|
|
3510
|
+
},
|
|
3511
|
+
chain: {
|
|
3512
|
+
type: "string",
|
|
3513
|
+
description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
|
|
3514
|
+
}
|
|
3515
|
+
},
|
|
3516
|
+
required: ["fromToken", "toToken", "amount", "chain"]
|
|
3517
|
+
}
|
|
3518
|
+
},
|
|
3519
|
+
"wdk/executeSwap": {
|
|
3520
|
+
name: "wdk/executeSwap",
|
|
3521
|
+
description: "Execute a swap using a quoteId from wdk/quoteSwap. Requires confirmation.",
|
|
3522
|
+
inputSchema: {
|
|
3523
|
+
type: "object",
|
|
3524
|
+
properties: {
|
|
3525
|
+
quoteId: {
|
|
3526
|
+
type: "string",
|
|
3527
|
+
description: "Quote ID from wdk/quoteSwap"
|
|
3528
|
+
},
|
|
3529
|
+
confirmed: {
|
|
3530
|
+
type: "boolean",
|
|
3531
|
+
description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
|
|
3532
|
+
}
|
|
3533
|
+
},
|
|
3534
|
+
required: ["quoteId"]
|
|
3535
|
+
}
|
|
2445
3536
|
}
|
|
2446
3537
|
};
|
|
2447
3538
|
var ERC8004_TOOL_DEFINITIONS = {
|
|
@@ -2529,30 +3620,49 @@ var ERC8004_TOOL_DEFINITIONS = {
|
|
|
2529
3620
|
WDK_TOOL_DEFINITIONS,
|
|
2530
3621
|
autoPayInputSchema,
|
|
2531
3622
|
bridgeInputSchema,
|
|
3623
|
+
clearPriceCache,
|
|
3624
|
+
clearQuoteStore,
|
|
3625
|
+
compareNetworkFeesInputSchema,
|
|
3626
|
+
createQuote,
|
|
2532
3627
|
createTonBridgeToolSet,
|
|
3628
|
+
deleteQuote,
|
|
2533
3629
|
erc8004CheckReputationInputSchema,
|
|
2534
3630
|
erc8004ResolveAgentInputSchema,
|
|
2535
3631
|
erc8004VerifyWalletInputSchema,
|
|
3632
|
+
estimatePaymentFeeInputSchema,
|
|
2536
3633
|
executeAutoPay,
|
|
2537
3634
|
executeAutoPayDemo,
|
|
2538
3635
|
executeBridge,
|
|
3636
|
+
executeBridgeFromQuoteInputSchema,
|
|
3637
|
+
executeCompareNetworkFees,
|
|
2539
3638
|
executeErc8004CheckReputation,
|
|
2540
3639
|
executeErc8004ResolveAgent,
|
|
2541
3640
|
executeErc8004VerifyWallet,
|
|
3641
|
+
executeEstimatePaymentFee,
|
|
3642
|
+
executeExecuteBridgeFromQuote,
|
|
3643
|
+
executeExecuteBridgeFromQuoteDemo,
|
|
2542
3644
|
executeGetAllBalances,
|
|
2543
3645
|
executeGetBalance,
|
|
2544
3646
|
executeGetBridgeFee,
|
|
3647
|
+
executeGetGasPrice,
|
|
3648
|
+
executeGetTokenPrice,
|
|
2545
3649
|
executePay,
|
|
2546
3650
|
executePayGasless,
|
|
2547
3651
|
executePaymentPlan,
|
|
2548
3652
|
executePaymentPlanDemo,
|
|
3653
|
+
executeQuoteBridge,
|
|
3654
|
+
executeQuoteBridgeDemo,
|
|
2549
3655
|
executeSmartPay,
|
|
2550
3656
|
executeSmartPayDemo,
|
|
2551
3657
|
executeTonBridgeTool,
|
|
3658
|
+
executeWdkExecuteSwap,
|
|
3659
|
+
executeWdkExecuteSwapDemo,
|
|
2552
3660
|
executeWdkGetBalances,
|
|
2553
3661
|
executeWdkGetBalancesDemo,
|
|
2554
3662
|
executeWdkGetWallet,
|
|
2555
3663
|
executeWdkGetWalletDemo,
|
|
3664
|
+
executeWdkQuoteSwap,
|
|
3665
|
+
executeWdkQuoteSwapDemo,
|
|
2556
3666
|
executeWdkSwap,
|
|
2557
3667
|
executeWdkSwapDemo,
|
|
2558
3668
|
executeWdkTransfer,
|
|
@@ -2561,14 +3671,22 @@ var ERC8004_TOOL_DEFINITIONS = {
|
|
|
2561
3671
|
formatAutoPayResult,
|
|
2562
3672
|
formatBalanceResult,
|
|
2563
3673
|
formatBridgeFeeResult,
|
|
3674
|
+
formatBridgeQuoteResult,
|
|
2564
3675
|
formatBridgeResult,
|
|
2565
3676
|
formatErc8004CheckReputationResult,
|
|
2566
3677
|
formatErc8004ResolveAgentResult,
|
|
2567
3678
|
formatErc8004VerifyWalletResult,
|
|
3679
|
+
formatExecuteBridgeFromQuoteResult,
|
|
3680
|
+
formatExecuteSwapResult,
|
|
3681
|
+
formatGasPriceResult,
|
|
2568
3682
|
formatGaslessPaymentResult,
|
|
3683
|
+
formatNetworkFeeComparison,
|
|
3684
|
+
formatPaymentFeeEstimate,
|
|
2569
3685
|
formatPaymentPlanResult,
|
|
2570
3686
|
formatPaymentResult,
|
|
2571
3687
|
formatSmartPayResult,
|
|
3688
|
+
formatSwapQuoteResult,
|
|
3689
|
+
formatTokenPriceResult,
|
|
2572
3690
|
formatWdkBalancesResult,
|
|
2573
3691
|
formatWdkSwapResult,
|
|
2574
3692
|
formatWdkTransferResult,
|
|
@@ -2576,12 +3694,20 @@ var ERC8004_TOOL_DEFINITIONS = {
|
|
|
2576
3694
|
getAllBalancesInputSchema,
|
|
2577
3695
|
getBalanceInputSchema,
|
|
2578
3696
|
getBridgeFeeInputSchema,
|
|
3697
|
+
getGasPriceInputSchema,
|
|
3698
|
+
getQuote,
|
|
3699
|
+
getTokenPriceInputSchema,
|
|
3700
|
+
getTokenPrices,
|
|
3701
|
+
getTokenPricesDemo,
|
|
2579
3702
|
payGaslessInputSchema,
|
|
2580
3703
|
payInputSchema,
|
|
2581
3704
|
paymentPlanInputSchema,
|
|
3705
|
+
quoteBridgeInputSchema,
|
|
2582
3706
|
smartPayInputSchema,
|
|
3707
|
+
wdkExecuteSwapInputSchema,
|
|
2583
3708
|
wdkGetBalancesInputSchema,
|
|
2584
3709
|
wdkGetWalletInputSchema,
|
|
3710
|
+
wdkQuoteSwapInputSchema,
|
|
2585
3711
|
wdkSwapInputSchema,
|
|
2586
3712
|
wdkTransferInputSchema
|
|
2587
3713
|
});
|