@t402/mcp 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1127,6 +1127,779 @@ function formatBridgeResult(result) {
1127
1127
  ].join("\n");
1128
1128
  }
1129
1129
 
1130
+ // src/tools/wdkGetWallet.ts
1131
+ import { z as z7 } from "zod";
1132
+ var wdkGetWalletInputSchema = z7.object({});
1133
+ async function executeWdkGetWallet(_input, wdk) {
1134
+ const signer = await wdk.getSigner("ethereum");
1135
+ const chains6 = wdk.getConfiguredChains();
1136
+ return {
1137
+ evmAddress: signer.address,
1138
+ chains: chains6.length > 0 ? chains6 : ["ethereum"]
1139
+ };
1140
+ }
1141
+ function executeWdkGetWalletDemo() {
1142
+ return {
1143
+ evmAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
1144
+ chains: ["ethereum", "arbitrum", "base", "optimism"]
1145
+ };
1146
+ }
1147
+ function formatWdkWalletResult(info) {
1148
+ const lines = [
1149
+ "## WDK Wallet Info",
1150
+ "",
1151
+ `**EVM Address:** \`${info.evmAddress}\``,
1152
+ "",
1153
+ "### Supported Chains",
1154
+ ...info.chains.map((c) => `- ${c}`)
1155
+ ];
1156
+ return lines.join("\n");
1157
+ }
1158
+
1159
+ // src/tools/wdkGetBalances.ts
1160
+ import { z as z8 } from "zod";
1161
+ import { formatUnits as formatUnits2 } from "viem";
1162
+ var wdkGetBalancesInputSchema = z8.object({
1163
+ chains: z8.array(z8.string()).optional().describe("Optional list of chains to check. If not provided, checks all configured chains.")
1164
+ });
1165
+ function findTokenFormatted(tokens, symbol) {
1166
+ return tokens.find((t) => t.symbol === symbol)?.formatted ?? "0";
1167
+ }
1168
+ async function executeWdkGetBalances(input, wdk) {
1169
+ const balances = await wdk.getAggregatedBalances();
1170
+ const chains6 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
1171
+ chain: c.chain,
1172
+ usdt0: findTokenFormatted(c.tokens, "USDT0"),
1173
+ usdc: findTokenFormatted(c.tokens, "USDC"),
1174
+ native: formatUnits2(c.native, 18)
1175
+ }));
1176
+ return {
1177
+ chains: chains6,
1178
+ totalUsdt0: formatUnits2(balances.totalUsdt0, 6),
1179
+ totalUsdc: formatUnits2(balances.totalUsdc, 6)
1180
+ };
1181
+ }
1182
+ function executeWdkGetBalancesDemo() {
1183
+ return {
1184
+ chains: [
1185
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00", native: "0.5" },
1186
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0", native: "0.01" },
1187
+ { chain: "base", usdt0: "200.00", usdc: "100.00", native: "0.02" }
1188
+ ],
1189
+ totalUsdt0: "800.00",
1190
+ totalUsdc: "350.00"
1191
+ };
1192
+ }
1193
+ function formatWdkBalancesResult(result) {
1194
+ const lines = [
1195
+ "## WDK Multi-Chain Balances",
1196
+ "",
1197
+ `**Total USDT0:** ${result.totalUsdt0}`,
1198
+ `**Total USDC:** ${result.totalUsdc}`,
1199
+ "",
1200
+ "### Per-Chain Breakdown",
1201
+ ""
1202
+ ];
1203
+ for (const chain of result.chains) {
1204
+ lines.push(`**${chain.chain}**`);
1205
+ lines.push(`- USDT0: ${chain.usdt0}`);
1206
+ lines.push(`- USDC: ${chain.usdc}`);
1207
+ lines.push(`- Native: ${chain.native}`);
1208
+ lines.push("");
1209
+ }
1210
+ return lines.join("\n");
1211
+ }
1212
+
1213
+ // src/tools/wdkTransfer.ts
1214
+ import { z as z9 } from "zod";
1215
+ var wdkTransferInputSchema = z9.object({
1216
+ to: z9.string().describe("Recipient address"),
1217
+ amount: z9.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
1218
+ token: z9.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
1219
+ chain: z9.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
1220
+ });
1221
+ async function executeWdkTransfer(input, wdk) {
1222
+ const signer = await wdk.getSigner(input.chain);
1223
+ const result = await signer.sendTransaction({
1224
+ to: input.to
1225
+ });
1226
+ const txHash = result.hash;
1227
+ const explorerUrl = getExplorerTxUrl(input.chain, txHash);
1228
+ return {
1229
+ txHash,
1230
+ amount: input.amount,
1231
+ token: input.token,
1232
+ chain: input.chain,
1233
+ to: input.to,
1234
+ explorerUrl
1235
+ };
1236
+ }
1237
+ function executeWdkTransferDemo(input) {
1238
+ const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
1239
+ return {
1240
+ txHash: demoTxHash,
1241
+ amount: input.amount,
1242
+ token: input.token,
1243
+ chain: input.chain,
1244
+ to: input.to,
1245
+ explorerUrl: `https://etherscan.io/tx/${demoTxHash}`
1246
+ };
1247
+ }
1248
+ function formatWdkTransferResult(result) {
1249
+ return [
1250
+ "## WDK Transfer Complete",
1251
+ "",
1252
+ `**Amount:** ${result.amount} ${result.token}`,
1253
+ `**Chain:** ${result.chain}`,
1254
+ `**To:** \`${result.to}\``,
1255
+ `**Tx Hash:** \`${result.txHash}\``,
1256
+ `**Explorer:** [View Transaction](${result.explorerUrl})`
1257
+ ].join("\n");
1258
+ }
1259
+
1260
+ // src/tools/wdkSwap.ts
1261
+ import { z as z10 } from "zod";
1262
+ import { formatUnits as formatUnits3, parseUnits as parseUnits3 } from "viem";
1263
+ var wdkSwapInputSchema = z10.object({
1264
+ fromToken: z10.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
1265
+ toToken: z10.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
1266
+ amount: z10.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
1267
+ chain: z10.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
1268
+ });
1269
+ async function executeWdkSwap(input, wdk) {
1270
+ const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
1271
+ const amountBigInt = parseUnits3(input.amount, decimals);
1272
+ const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
1273
+ const result = await wdk.swapAndPay({
1274
+ chain: input.chain,
1275
+ fromToken: input.fromToken,
1276
+ amount: amountBigInt
1277
+ });
1278
+ const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
1279
+ const toAmount = formatUnits3(result?.outputAmount ?? quote.outputAmount, outputDecimals);
1280
+ return {
1281
+ fromAmount: input.amount,
1282
+ fromToken: input.fromToken,
1283
+ toAmount,
1284
+ toToken: input.toToken,
1285
+ chain: input.chain,
1286
+ txHash: result?.txHash
1287
+ };
1288
+ }
1289
+ function executeWdkSwapDemo(input) {
1290
+ const inputAmount = parseFloat(input.amount);
1291
+ const outputAmount = (inputAmount * 0.997).toFixed(6);
1292
+ return {
1293
+ fromAmount: input.amount,
1294
+ fromToken: input.fromToken,
1295
+ toAmount: outputAmount,
1296
+ toToken: input.toToken,
1297
+ chain: input.chain,
1298
+ txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
1299
+ };
1300
+ }
1301
+ function formatWdkSwapResult(result) {
1302
+ const lines = [
1303
+ "## WDK Swap Result",
1304
+ "",
1305
+ `**From:** ${result.fromAmount} ${result.fromToken}`,
1306
+ `**To:** ${result.toAmount} ${result.toToken}`,
1307
+ `**Chain:** ${result.chain}`
1308
+ ];
1309
+ if (result.txHash) {
1310
+ lines.push(`**Tx Hash:** \`${result.txHash}\``);
1311
+ }
1312
+ return lines.join("\n");
1313
+ }
1314
+
1315
+ // src/tools/autoPay.ts
1316
+ import { z as z11 } from "zod";
1317
+ import { T402Protocol } from "@t402/wdk-protocol";
1318
+ var autoPayInputSchema = z11.object({
1319
+ url: z11.string().url().describe("URL to fetch (may return 402 Payment Required)"),
1320
+ maxAmount: z11.string().regex(/^\d+(\.\d+)?$/).optional().describe('Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'),
1321
+ preferredChain: z11.string().optional().describe(
1322
+ 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
1323
+ )
1324
+ });
1325
+ async function executeAutoPay(input, wdk) {
1326
+ const chains6 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
1327
+ const protocol = await T402Protocol.create(wdk, { chains: chains6 });
1328
+ const { response, receipt } = await protocol.fetch(input.url);
1329
+ if (receipt && input.maxAmount) {
1330
+ const paidAmount = parseFloat(receipt.amount) / 1e6;
1331
+ const maxAmount = parseFloat(input.maxAmount);
1332
+ if (paidAmount > maxAmount) {
1333
+ return {
1334
+ success: false,
1335
+ statusCode: 402,
1336
+ body: "",
1337
+ error: `Payment amount (${paidAmount}) exceeds max allowed (${maxAmount})`
1338
+ };
1339
+ }
1340
+ }
1341
+ const contentType = response.headers.get("content-type") ?? void 0;
1342
+ let body = "";
1343
+ try {
1344
+ body = await response.text();
1345
+ if (body.length > 1e4) {
1346
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1347
+ }
1348
+ } catch {
1349
+ body = "[Could not read response body]";
1350
+ }
1351
+ return {
1352
+ success: response.ok,
1353
+ statusCode: response.status,
1354
+ body,
1355
+ contentType,
1356
+ payment: receipt ? {
1357
+ network: receipt.network,
1358
+ scheme: receipt.scheme,
1359
+ amount: receipt.amount,
1360
+ payTo: receipt.payTo
1361
+ } : void 0
1362
+ };
1363
+ }
1364
+ function executeAutoPayDemo(input) {
1365
+ return {
1366
+ success: true,
1367
+ statusCode: 200,
1368
+ body: `[Demo] Premium content from ${input.url}
1369
+
1370
+ This is simulated content that would be returned after payment.`,
1371
+ contentType: "text/plain",
1372
+ payment: {
1373
+ network: "eip155:42161",
1374
+ scheme: "exact",
1375
+ amount: "1000000",
1376
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1377
+ }
1378
+ };
1379
+ }
1380
+ function formatAutoPayResult(result) {
1381
+ const lines = ["## AutoPay Result", ""];
1382
+ if (result.success) {
1383
+ lines.push(`**Status:** Success (${result.statusCode})`);
1384
+ } else {
1385
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1386
+ }
1387
+ if (result.payment) {
1388
+ lines.push("");
1389
+ lines.push("### Payment Details");
1390
+ lines.push(`- **Network:** ${result.payment.network}`);
1391
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1392
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1393
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1394
+ }
1395
+ if (result.error) {
1396
+ lines.push("");
1397
+ lines.push(`**Error:** ${result.error}`);
1398
+ }
1399
+ if (result.body) {
1400
+ lines.push("");
1401
+ lines.push("### Response Content");
1402
+ if (result.contentType) {
1403
+ lines.push(`_Content-Type: ${result.contentType}_`);
1404
+ }
1405
+ lines.push("");
1406
+ lines.push("```");
1407
+ lines.push(result.body);
1408
+ lines.push("```");
1409
+ }
1410
+ return lines.join("\n");
1411
+ }
1412
+
1413
+ // src/tools/ton-bridge.ts
1414
+ var TON_BRIDGE_TOOLS = {
1415
+ "ton/getBalance": {
1416
+ name: "ton/getBalance",
1417
+ description: "Get TON and Jetton balances for a wallet address on the TON blockchain.",
1418
+ inputSchema: {
1419
+ type: "object",
1420
+ properties: {
1421
+ address: {
1422
+ type: "string",
1423
+ description: "TON wallet address (friendly or raw format)"
1424
+ }
1425
+ },
1426
+ required: ["address"]
1427
+ }
1428
+ },
1429
+ "ton/transfer": {
1430
+ name: "ton/transfer",
1431
+ description: "Send TON to a recipient address on the TON blockchain.",
1432
+ inputSchema: {
1433
+ type: "object",
1434
+ properties: {
1435
+ to: {
1436
+ type: "string",
1437
+ description: "Recipient TON address"
1438
+ },
1439
+ amount: {
1440
+ type: "string",
1441
+ description: 'Amount of TON to send (e.g., "1.5")'
1442
+ },
1443
+ memo: {
1444
+ type: "string",
1445
+ description: "Optional memo/comment for the transfer"
1446
+ }
1447
+ },
1448
+ required: ["to", "amount"]
1449
+ }
1450
+ },
1451
+ "ton/getJettonBalance": {
1452
+ name: "ton/getJettonBalance",
1453
+ description: "Get the balance of a specific Jetton (TON token) for a wallet address.",
1454
+ inputSchema: {
1455
+ type: "object",
1456
+ properties: {
1457
+ address: {
1458
+ type: "string",
1459
+ description: "TON wallet address"
1460
+ },
1461
+ jettonMaster: {
1462
+ type: "string",
1463
+ description: "Jetton master contract address"
1464
+ }
1465
+ },
1466
+ required: ["address", "jettonMaster"]
1467
+ }
1468
+ },
1469
+ "ton/swapJettons": {
1470
+ name: "ton/swapJettons",
1471
+ description: "Swap Jettons (TON tokens) using DEX aggregation on the TON network. Returns a raw transaction JSON to be sent via sendTransaction.",
1472
+ inputSchema: {
1473
+ type: "object",
1474
+ properties: {
1475
+ from: {
1476
+ type: "string",
1477
+ description: 'Source Jetton master address (or "TON" for native TON)'
1478
+ },
1479
+ to: {
1480
+ type: "string",
1481
+ description: 'Destination Jetton master address (or "TON" for native TON)'
1482
+ },
1483
+ amount: {
1484
+ type: "string",
1485
+ description: 'Amount to swap in human-readable format (e.g., "1.5")'
1486
+ },
1487
+ slippage: {
1488
+ type: "string",
1489
+ description: 'Slippage tolerance (e.g., "0.5" for 0.5%)'
1490
+ }
1491
+ },
1492
+ required: ["from", "to", "amount"]
1493
+ }
1494
+ },
1495
+ "ton/getTransactionStatus": {
1496
+ name: "ton/getTransactionStatus",
1497
+ description: "Check the status and details of a TON transaction by its hash.",
1498
+ inputSchema: {
1499
+ type: "object",
1500
+ properties: {
1501
+ txHash: {
1502
+ type: "string",
1503
+ description: "Transaction hash (BOC hash or message hash)"
1504
+ }
1505
+ },
1506
+ required: ["txHash"]
1507
+ }
1508
+ }
1509
+ };
1510
+ async function executeTonBridgeTool(toolName, args, config) {
1511
+ if (config.demoMode) {
1512
+ return executeTonBridgeToolDemo(toolName, args);
1513
+ }
1514
+ if (config.tonMcpEndpoint) {
1515
+ return proxyToTonMcp(toolName, args, config.tonMcpEndpoint);
1516
+ }
1517
+ if (config.tonApiKey) {
1518
+ return executeTonBridgeToolDirect(toolName, args, config.tonApiKey);
1519
+ }
1520
+ return {
1521
+ content: [
1522
+ {
1523
+ type: "text",
1524
+ text: `Error: TON MCP bridge not configured. Set tonMcpEndpoint or tonApiKey.`
1525
+ }
1526
+ ],
1527
+ isError: true
1528
+ };
1529
+ }
1530
+ function executeTonBridgeToolDemo(toolName, args) {
1531
+ const responses = {
1532
+ "ton/getBalance": `[DEMO] TON Balance for ${args.address ?? "unknown"}:
1533
+ - TON: 5.25
1534
+ - USDT0: 100.00`,
1535
+ "ton/transfer": `[DEMO] Transfer sent:
1536
+ - To: ${args.to ?? "unknown"}
1537
+ - Amount: ${args.amount ?? "0"} TON
1538
+ - TX: demo-ton-tx-hash-${Date.now().toString(36)}`,
1539
+ "ton/getJettonBalance": `[DEMO] Jetton Balance:
1540
+ - Address: ${args.address ?? "unknown"}
1541
+ - Jetton: ${args.jettonMaster ?? "unknown"}
1542
+ - Balance: 50.00`,
1543
+ "ton/swapJettons": `[DEMO] Swap quote received:
1544
+ - From: ${args.from ?? "unknown"}
1545
+ - To: ${args.to ?? "unknown"}
1546
+ - Amount: ${args.amount ?? "0"}
1547
+ - Transaction: {"validUntil":${Math.floor(Date.now() / 1e3) + 300},"messages":[{"address":"EQDemo...","amount":"${args.amount ?? "0"}","payload":"base64..."}]}`,
1548
+ "ton/getTransactionStatus": `[DEMO] Transaction Status:
1549
+ - Hash: ${args.txHash ?? "unknown"}
1550
+ - Status: Confirmed
1551
+ - Block: 12345678`
1552
+ };
1553
+ return {
1554
+ content: [
1555
+ {
1556
+ type: "text",
1557
+ text: responses[toolName] ?? `[DEMO] Unknown TON tool: ${toolName}`
1558
+ }
1559
+ ]
1560
+ };
1561
+ }
1562
+ async function proxyToTonMcp(toolName, args, endpoint) {
1563
+ try {
1564
+ const response = await fetch(endpoint, {
1565
+ method: "POST",
1566
+ headers: { "Content-Type": "application/json" },
1567
+ body: JSON.stringify({
1568
+ jsonrpc: "2.0",
1569
+ id: 1,
1570
+ method: "tools/call",
1571
+ params: { name: toolName, arguments: args }
1572
+ })
1573
+ });
1574
+ if (!response.ok) {
1575
+ throw new Error(`TON MCP server returned ${response.status}`);
1576
+ }
1577
+ const result = await response.json();
1578
+ if (result.error) {
1579
+ throw new Error(result.error.message);
1580
+ }
1581
+ return result.result ?? { content: [{ type: "text", text: "No result" }] };
1582
+ } catch (error) {
1583
+ const message = error instanceof Error ? error.message : String(error);
1584
+ return {
1585
+ content: [{ type: "text", text: `Error proxying to @ton/mcp: ${message}` }],
1586
+ isError: true
1587
+ };
1588
+ }
1589
+ }
1590
+ async function executeTonBridgeToolDirect(toolName, args, apiKey) {
1591
+ const baseUrl = "https://toncenter.com/api/v2";
1592
+ try {
1593
+ switch (toolName) {
1594
+ case "ton/getBalance": {
1595
+ const response = await fetch(
1596
+ `${baseUrl}/getAddressBalance?address=${encodeURIComponent(String(args.address))}&api_key=${apiKey}`
1597
+ );
1598
+ const data = await response.json();
1599
+ const balanceNano = BigInt(data.result);
1600
+ const balanceTon = Number(balanceNano) / 1e9;
1601
+ return {
1602
+ content: [{ type: "text", text: `TON Balance: ${balanceTon.toFixed(4)} TON` }]
1603
+ };
1604
+ }
1605
+ case "ton/getTransactionStatus": {
1606
+ const response = await fetch(
1607
+ `${baseUrl}/getTransactions?hash=${encodeURIComponent(String(args.txHash))}&limit=1&api_key=${apiKey}`
1608
+ );
1609
+ const data = await response.json();
1610
+ if (data.result.length === 0) {
1611
+ return {
1612
+ content: [{ type: "text", text: "Transaction not found" }]
1613
+ };
1614
+ }
1615
+ return {
1616
+ content: [
1617
+ {
1618
+ type: "text",
1619
+ text: `Transaction found:
1620
+ ${JSON.stringify(data.result[0], null, 2)}`
1621
+ }
1622
+ ]
1623
+ };
1624
+ }
1625
+ default:
1626
+ return {
1627
+ content: [
1628
+ {
1629
+ type: "text",
1630
+ text: `Direct execution of ${toolName} is not supported. Configure tonMcpEndpoint to proxy to @ton/mcp.`
1631
+ }
1632
+ ],
1633
+ isError: true
1634
+ };
1635
+ }
1636
+ } catch (error) {
1637
+ const message = error instanceof Error ? error.message : String(error);
1638
+ return {
1639
+ content: [{ type: "text", text: `Error executing TON API call: ${message}` }],
1640
+ isError: true
1641
+ };
1642
+ }
1643
+ }
1644
+ function createTonBridgeToolSet(config) {
1645
+ return {
1646
+ definitions: TON_BRIDGE_TOOLS,
1647
+ async handleToolCall(name, args) {
1648
+ return executeTonBridgeTool(name, args, config);
1649
+ }
1650
+ };
1651
+ }
1652
+
1653
+ // src/tools/unified.ts
1654
+ import { z as z12 } from "zod";
1655
+ import { T402Protocol as T402Protocol2 } from "@t402/wdk-protocol";
1656
+ var smartPayInputSchema = z12.object({
1657
+ url: z12.string().url().describe("URL of the 402-protected resource"),
1658
+ maxBridgeFee: z12.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
1659
+ preferredNetwork: z12.string().optional().describe("Preferred network for payment (optional)")
1660
+ });
1661
+ var paymentPlanInputSchema = z12.object({
1662
+ paymentRequired: z12.object({
1663
+ scheme: z12.string().optional(),
1664
+ network: z12.string().optional(),
1665
+ maxAmountRequired: z12.string().optional(),
1666
+ resource: z12.string().optional(),
1667
+ description: z12.string().optional(),
1668
+ payTo: z12.string().optional(),
1669
+ maxDeadline: z12.number().optional()
1670
+ }).passthrough().describe("The 402 PaymentRequired response")
1671
+ });
1672
+ var UNIFIED_TOOL_DEFINITIONS = {
1673
+ "t402/smartPay": {
1674
+ name: "t402/smartPay",
1675
+ description: "Intelligent payment that automatically checks balance, bridges if needed, and pays. Handles the entire payment flow for 402-protected resources.",
1676
+ inputSchema: {
1677
+ type: "object",
1678
+ properties: {
1679
+ url: { type: "string", description: "URL of the 402-protected resource" },
1680
+ maxBridgeFee: {
1681
+ type: "string",
1682
+ description: "Maximum acceptable bridge fee in native token (optional)"
1683
+ },
1684
+ preferredNetwork: {
1685
+ type: "string",
1686
+ description: "Preferred network for payment (optional)"
1687
+ }
1688
+ },
1689
+ required: ["url"]
1690
+ }
1691
+ },
1692
+ "t402/paymentPlan": {
1693
+ name: "t402/paymentPlan",
1694
+ description: "Analyze a 402 response and create an optimal payment plan considering balances across all chains. Returns recommended network, bridge requirements, and balance overview.",
1695
+ inputSchema: {
1696
+ type: "object",
1697
+ properties: {
1698
+ paymentRequired: {
1699
+ type: "object",
1700
+ description: "The 402 PaymentRequired response"
1701
+ }
1702
+ },
1703
+ required: ["paymentRequired"]
1704
+ }
1705
+ }
1706
+ };
1707
+ async function executeSmartPay(input, wdk) {
1708
+ const steps = [];
1709
+ const chains6 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
1710
+ steps.push({
1711
+ action: "check_balance",
1712
+ status: "success",
1713
+ detail: `Checking balances on ${chains6.join(", ")}`
1714
+ });
1715
+ const protocol = await T402Protocol2.create(wdk, { chains: chains6 });
1716
+ steps.push({
1717
+ action: "fetch",
1718
+ status: "success",
1719
+ detail: `Fetching ${input.url}`
1720
+ });
1721
+ const { response, receipt } = await protocol.fetch(input.url);
1722
+ if (receipt) {
1723
+ steps.push({
1724
+ action: "pay",
1725
+ status: "success",
1726
+ detail: `Payment made: ${receipt.amount} on ${receipt.network}`
1727
+ });
1728
+ }
1729
+ const contentType = response.headers.get("content-type") ?? void 0;
1730
+ let body = "";
1731
+ try {
1732
+ body = await response.text();
1733
+ if (body.length > 1e4) {
1734
+ body = body.slice(0, 1e4) + "\n... (truncated)";
1735
+ }
1736
+ } catch {
1737
+ body = "[Could not read response body]";
1738
+ }
1739
+ return {
1740
+ success: response.ok,
1741
+ statusCode: response.status,
1742
+ body,
1743
+ contentType,
1744
+ steps,
1745
+ payment: receipt ? {
1746
+ network: receipt.network,
1747
+ scheme: receipt.scheme,
1748
+ amount: receipt.amount,
1749
+ payTo: receipt.payTo
1750
+ } : void 0
1751
+ };
1752
+ }
1753
+ function executeSmartPayDemo(input) {
1754
+ const network = input.preferredNetwork ?? "arbitrum";
1755
+ return {
1756
+ success: true,
1757
+ statusCode: 200,
1758
+ body: `[Demo] Premium content from ${input.url}
1759
+
1760
+ This is simulated content returned after smart payment.`,
1761
+ contentType: "text/plain",
1762
+ steps: [
1763
+ { action: "check_balance", status: "success", detail: `Checked balances on ${network}` },
1764
+ { action: "check_price", status: "success", detail: "Resource costs 1.00 USDT0" },
1765
+ { action: "pay", status: "success", detail: `Paid 1000000 USDT0 on eip155:42161` },
1766
+ { action: "fetch", status: "success", detail: `Fetched ${input.url}` }
1767
+ ],
1768
+ payment: {
1769
+ network: "eip155:42161",
1770
+ scheme: "exact",
1771
+ amount: "1000000",
1772
+ payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
1773
+ }
1774
+ };
1775
+ }
1776
+ async function executePaymentPlan(input, wdk) {
1777
+ const targetNetwork = input.paymentRequired.network;
1778
+ const requiredAmount = input.paymentRequired.maxAmountRequired;
1779
+ const aggregated = await wdk.getAggregatedBalances();
1780
+ const balances = aggregated.chains.map((chain) => {
1781
+ const usdt0 = chain.tokens.find((t) => t.symbol === "USDT0");
1782
+ const usdc = chain.tokens.find((t) => t.symbol === "USDC");
1783
+ return {
1784
+ chain: chain.chain,
1785
+ usdt0: usdt0?.formatted ?? "0",
1786
+ usdc: usdc?.formatted ?? "0"
1787
+ };
1788
+ });
1789
+ const requiredBigint = requiredAmount ? BigInt(requiredAmount) : 0n;
1790
+ const bestChain = await wdk.findBestChainForPayment(requiredBigint);
1791
+ if (bestChain) {
1792
+ const needsBridge = targetNetwork ? !bestChain.chain.includes(targetNetwork) : false;
1793
+ return {
1794
+ viable: true,
1795
+ recommendedNetwork: bestChain.chain,
1796
+ availableBalance: bestChain.balance.toString(),
1797
+ bridgeRequired: needsBridge,
1798
+ bridgeDetails: needsBridge ? {
1799
+ fromChain: bestChain.chain,
1800
+ toChain: targetNetwork ?? bestChain.chain,
1801
+ amount: requiredAmount ?? "0",
1802
+ estimatedFee: "0.001"
1803
+ } : void 0,
1804
+ balances
1805
+ };
1806
+ }
1807
+ return {
1808
+ viable: false,
1809
+ bridgeRequired: false,
1810
+ balances,
1811
+ reason: "Insufficient balance across all chains"
1812
+ };
1813
+ }
1814
+ function executePaymentPlanDemo(_input) {
1815
+ return {
1816
+ viable: true,
1817
+ recommendedNetwork: "arbitrum",
1818
+ availableBalance: "500000000",
1819
+ bridgeRequired: false,
1820
+ balances: [
1821
+ { chain: "ethereum", usdt0: "100.00", usdc: "250.00" },
1822
+ { chain: "arbitrum", usdt0: "500.00", usdc: "0" },
1823
+ { chain: "base", usdt0: "50.00", usdc: "100.00" }
1824
+ ]
1825
+ };
1826
+ }
1827
+ function formatSmartPayResult(result) {
1828
+ const lines = ["## SmartPay Result", ""];
1829
+ if (result.success) {
1830
+ lines.push(`**Status:** Success (${result.statusCode})`);
1831
+ } else {
1832
+ lines.push(`**Status:** Failed (${result.statusCode})`);
1833
+ }
1834
+ if (result.steps.length > 0) {
1835
+ lines.push("");
1836
+ lines.push("### Steps");
1837
+ for (const step of result.steps) {
1838
+ const icon = step.status === "success" ? "[OK]" : step.status === "skipped" ? "[SKIP]" : "[FAIL]";
1839
+ lines.push(`- ${icon} **${step.action}**: ${step.detail}`);
1840
+ }
1841
+ }
1842
+ if (result.payment) {
1843
+ lines.push("");
1844
+ lines.push("### Payment Details");
1845
+ lines.push(`- **Network:** ${result.payment.network}`);
1846
+ lines.push(`- **Scheme:** ${result.payment.scheme}`);
1847
+ lines.push(`- **Amount:** ${result.payment.amount}`);
1848
+ lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
1849
+ }
1850
+ if (result.error) {
1851
+ lines.push("");
1852
+ lines.push(`**Error:** ${result.error}`);
1853
+ }
1854
+ if (result.body) {
1855
+ lines.push("");
1856
+ lines.push("### Response Content");
1857
+ if (result.contentType) {
1858
+ lines.push(`_Content-Type: ${result.contentType}_`);
1859
+ }
1860
+ lines.push("");
1861
+ lines.push("```");
1862
+ lines.push(result.body);
1863
+ lines.push("```");
1864
+ }
1865
+ return lines.join("\n");
1866
+ }
1867
+ function formatPaymentPlanResult(result) {
1868
+ const lines = ["## Payment Plan", ""];
1869
+ if (result.viable) {
1870
+ lines.push(`**Viable:** Yes`);
1871
+ if (result.recommendedNetwork) {
1872
+ lines.push(`**Recommended Network:** ${result.recommendedNetwork}`);
1873
+ }
1874
+ if (result.availableBalance) {
1875
+ lines.push(`**Available Balance:** ${result.availableBalance}`);
1876
+ }
1877
+ } else {
1878
+ lines.push(`**Viable:** No`);
1879
+ if (result.reason) {
1880
+ lines.push(`**Reason:** ${result.reason}`);
1881
+ }
1882
+ }
1883
+ if (result.bridgeRequired && result.bridgeDetails) {
1884
+ lines.push("");
1885
+ lines.push("### Bridge Required");
1886
+ lines.push(`- **From:** ${result.bridgeDetails.fromChain}`);
1887
+ lines.push(`- **To:** ${result.bridgeDetails.toChain}`);
1888
+ lines.push(`- **Amount:** ${result.bridgeDetails.amount}`);
1889
+ lines.push(`- **Estimated Fee:** ${result.bridgeDetails.estimatedFee}`);
1890
+ }
1891
+ if (result.balances.length > 0) {
1892
+ lines.push("");
1893
+ lines.push("### Chain Balances");
1894
+ lines.push("| Chain | USDT0 | USDC |");
1895
+ lines.push("|-------|-------|------|");
1896
+ for (const b of result.balances) {
1897
+ lines.push(`| ${b.chain} | ${b.usdt0} | ${b.usdc} |`);
1898
+ }
1899
+ }
1900
+ return lines.join("\n");
1901
+ }
1902
+
1130
1903
  // src/tools/index.ts
1131
1904
  var TOOL_DEFINITIONS = {
1132
1905
  "t402/getBalance": {
@@ -1327,6 +2100,110 @@ var TOOL_DEFINITIONS = {
1327
2100
  }
1328
2101
  }
1329
2102
  };
2103
+ var WDK_TOOL_DEFINITIONS = {
2104
+ "wdk/getWallet": {
2105
+ name: "wdk/getWallet",
2106
+ description: "Get wallet information from the configured WDK wallet. Returns EVM address and supported chains. No parameters needed.",
2107
+ inputSchema: {
2108
+ type: "object",
2109
+ properties: {},
2110
+ required: []
2111
+ }
2112
+ },
2113
+ "wdk/getBalances": {
2114
+ name: "wdk/getBalances",
2115
+ description: "Get multi-chain token balances from the WDK wallet. Returns USDT0, USDC, and native token balances per chain plus aggregated totals.",
2116
+ inputSchema: {
2117
+ type: "object",
2118
+ properties: {
2119
+ chains: {
2120
+ type: "array",
2121
+ items: { type: "string" },
2122
+ description: 'Optional list of chains to check (e.g., ["ethereum", "arbitrum"]). If not provided, checks all configured chains.'
2123
+ }
2124
+ },
2125
+ required: []
2126
+ }
2127
+ },
2128
+ "wdk/transfer": {
2129
+ name: "wdk/transfer",
2130
+ description: "Send stablecoins (USDC, USDT, USDT0) from the WDK wallet to a recipient address on a specific chain.",
2131
+ inputSchema: {
2132
+ type: "object",
2133
+ properties: {
2134
+ to: {
2135
+ type: "string",
2136
+ description: "Recipient address"
2137
+ },
2138
+ amount: {
2139
+ type: "string",
2140
+ pattern: "^\\d+(\\.\\d+)?$",
2141
+ description: "Amount to send (e.g., '10.50')"
2142
+ },
2143
+ token: {
2144
+ type: "string",
2145
+ enum: ["USDC", "USDT", "USDT0"],
2146
+ description: "Token to transfer"
2147
+ },
2148
+ chain: {
2149
+ type: "string",
2150
+ description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
2151
+ }
2152
+ },
2153
+ required: ["to", "amount", "token", "chain"]
2154
+ }
2155
+ },
2156
+ "wdk/swap": {
2157
+ name: "wdk/swap",
2158
+ description: "Swap tokens using the WDK Velora protocol. Supports swapping between stablecoins and native tokens.",
2159
+ inputSchema: {
2160
+ type: "object",
2161
+ properties: {
2162
+ fromToken: {
2163
+ type: "string",
2164
+ description: 'Token to swap from (e.g., "ETH", "USDC")'
2165
+ },
2166
+ toToken: {
2167
+ type: "string",
2168
+ description: 'Token to swap to (e.g., "USDT0", "USDC")'
2169
+ },
2170
+ amount: {
2171
+ type: "string",
2172
+ pattern: "^\\d+(\\.\\d+)?$",
2173
+ description: "Amount to swap (e.g., '1.0')"
2174
+ },
2175
+ chain: {
2176
+ type: "string",
2177
+ description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
2178
+ }
2179
+ },
2180
+ required: ["fromToken", "toToken", "amount", "chain"]
2181
+ }
2182
+ },
2183
+ "t402/autoPay": {
2184
+ name: "t402/autoPay",
2185
+ description: "Smart payment orchestrator. Fetches a URL, automatically handles HTTP 402 Payment Required responses by signing and submitting payment using the WDK wallet, and returns the paid content. The killer tool for AI agents.",
2186
+ inputSchema: {
2187
+ type: "object",
2188
+ properties: {
2189
+ url: {
2190
+ type: "string",
2191
+ description: "URL to fetch (may return 402 Payment Required)"
2192
+ },
2193
+ maxAmount: {
2194
+ type: "string",
2195
+ pattern: "^\\d+(\\.\\d+)?$",
2196
+ description: 'Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'
2197
+ },
2198
+ preferredChain: {
2199
+ type: "string",
2200
+ description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
2201
+ }
2202
+ },
2203
+ required: ["url"]
2204
+ }
2205
+ }
2206
+ };
1330
2207
 
1331
2208
  export {
1332
2209
  __publicField,
@@ -1363,6 +2240,39 @@ export {
1363
2240
  bridgeInputSchema,
1364
2241
  executeBridge,
1365
2242
  formatBridgeResult,
1366
- TOOL_DEFINITIONS
2243
+ wdkGetWalletInputSchema,
2244
+ executeWdkGetWallet,
2245
+ executeWdkGetWalletDemo,
2246
+ formatWdkWalletResult,
2247
+ wdkGetBalancesInputSchema,
2248
+ executeWdkGetBalances,
2249
+ executeWdkGetBalancesDemo,
2250
+ formatWdkBalancesResult,
2251
+ wdkTransferInputSchema,
2252
+ executeWdkTransfer,
2253
+ executeWdkTransferDemo,
2254
+ formatWdkTransferResult,
2255
+ wdkSwapInputSchema,
2256
+ executeWdkSwap,
2257
+ executeWdkSwapDemo,
2258
+ formatWdkSwapResult,
2259
+ autoPayInputSchema,
2260
+ executeAutoPay,
2261
+ executeAutoPayDemo,
2262
+ formatAutoPayResult,
2263
+ TON_BRIDGE_TOOLS,
2264
+ executeTonBridgeTool,
2265
+ createTonBridgeToolSet,
2266
+ smartPayInputSchema,
2267
+ paymentPlanInputSchema,
2268
+ UNIFIED_TOOL_DEFINITIONS,
2269
+ executeSmartPay,
2270
+ executeSmartPayDemo,
2271
+ executePaymentPlan,
2272
+ executePaymentPlanDemo,
2273
+ formatSmartPayResult,
2274
+ formatPaymentPlanResult,
2275
+ TOOL_DEFINITIONS,
2276
+ WDK_TOOL_DEFINITIONS
1367
2277
  };
1368
- //# sourceMappingURL=chunk-5IVOABVF.mjs.map
2278
+ //# sourceMappingURL=chunk-RDQ7AMR4.mjs.map