@t402/mcp 2.5.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.
- package/bin/t402-mcp.js +9 -3
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +569 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server/index.d.ts +22 -2
- package/dist/cjs/server/index.js +551 -1
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/{types-CwwW_c2B.d.ts → ton-bridge-BN3RKhNy.d.ts} +89 -1
- package/dist/cjs/tools/index.d.ts +219 -2
- package/dist/cjs/tools/index.js +514 -0
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/esm/{chunk-KTG47TRY.mjs → chunk-3FGPOVUZ.mjs} +82 -3
- package/dist/esm/chunk-3FGPOVUZ.mjs.map +1 -0
- package/dist/esm/{chunk-5UOBQKXW.mjs → chunk-RDQ7AMR4.mjs} +503 -1
- package/dist/esm/chunk-RDQ7AMR4.mjs.map +1 -0
- package/dist/esm/index.d.mts +3 -3
- package/dist/esm/index.mjs +20 -2
- package/dist/esm/server/index.d.mts +22 -2
- package/dist/esm/server/index.mjs +2 -2
- package/dist/esm/{types-CwwW_c2B.d.mts → ton-bridge-BN3RKhNy.d.mts} +89 -1
- package/dist/esm/tools/index.d.mts +219 -2
- package/dist/esm/tools/index.mjs +25 -1
- package/package.json +20 -12
- package/dist/esm/chunk-5UOBQKXW.mjs.map +0 -1
- package/dist/esm/chunk-KTG47TRY.mjs.map +0 -1
package/dist/cjs/tools/index.js
CHANGED
|
@@ -31,10 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var tools_exports = {};
|
|
32
32
|
__export(tools_exports, {
|
|
33
33
|
GASLESS_SUPPORTED_NETWORKS: () => GASLESS_SUPPORTED_NETWORKS,
|
|
34
|
+
TON_BRIDGE_TOOLS: () => TON_BRIDGE_TOOLS,
|
|
34
35
|
TOOL_DEFINITIONS: () => TOOL_DEFINITIONS,
|
|
36
|
+
UNIFIED_TOOL_DEFINITIONS: () => UNIFIED_TOOL_DEFINITIONS,
|
|
35
37
|
WDK_TOOL_DEFINITIONS: () => WDK_TOOL_DEFINITIONS,
|
|
36
38
|
autoPayInputSchema: () => autoPayInputSchema,
|
|
37
39
|
bridgeInputSchema: () => bridgeInputSchema,
|
|
40
|
+
createTonBridgeToolSet: () => createTonBridgeToolSet,
|
|
38
41
|
executeAutoPay: () => executeAutoPay,
|
|
39
42
|
executeAutoPayDemo: () => executeAutoPayDemo,
|
|
40
43
|
executeBridge: () => executeBridge,
|
|
@@ -43,6 +46,11 @@ __export(tools_exports, {
|
|
|
43
46
|
executeGetBridgeFee: () => executeGetBridgeFee,
|
|
44
47
|
executePay: () => executePay,
|
|
45
48
|
executePayGasless: () => executePayGasless,
|
|
49
|
+
executePaymentPlan: () => executePaymentPlan,
|
|
50
|
+
executePaymentPlanDemo: () => executePaymentPlanDemo,
|
|
51
|
+
executeSmartPay: () => executeSmartPay,
|
|
52
|
+
executeSmartPayDemo: () => executeSmartPayDemo,
|
|
53
|
+
executeTonBridgeTool: () => executeTonBridgeTool,
|
|
46
54
|
executeWdkGetBalances: () => executeWdkGetBalances,
|
|
47
55
|
executeWdkGetBalancesDemo: () => executeWdkGetBalancesDemo,
|
|
48
56
|
executeWdkGetWallet: () => executeWdkGetWallet,
|
|
@@ -57,7 +65,9 @@ __export(tools_exports, {
|
|
|
57
65
|
formatBridgeFeeResult: () => formatBridgeFeeResult,
|
|
58
66
|
formatBridgeResult: () => formatBridgeResult,
|
|
59
67
|
formatGaslessPaymentResult: () => formatGaslessPaymentResult,
|
|
68
|
+
formatPaymentPlanResult: () => formatPaymentPlanResult,
|
|
60
69
|
formatPaymentResult: () => formatPaymentResult,
|
|
70
|
+
formatSmartPayResult: () => formatSmartPayResult,
|
|
61
71
|
formatWdkBalancesResult: () => formatWdkBalancesResult,
|
|
62
72
|
formatWdkSwapResult: () => formatWdkSwapResult,
|
|
63
73
|
formatWdkTransferResult: () => formatWdkTransferResult,
|
|
@@ -67,6 +77,8 @@ __export(tools_exports, {
|
|
|
67
77
|
getBridgeFeeInputSchema: () => getBridgeFeeInputSchema,
|
|
68
78
|
payGaslessInputSchema: () => payGaslessInputSchema,
|
|
69
79
|
payInputSchema: () => payInputSchema,
|
|
80
|
+
paymentPlanInputSchema: () => paymentPlanInputSchema,
|
|
81
|
+
smartPayInputSchema: () => smartPayInputSchema,
|
|
70
82
|
wdkGetBalancesInputSchema: () => wdkGetBalancesInputSchema,
|
|
71
83
|
wdkGetWalletInputSchema: () => wdkGetWalletInputSchema,
|
|
72
84
|
wdkSwapInputSchema: () => wdkSwapInputSchema,
|
|
@@ -1465,6 +1477,496 @@ function formatAutoPayResult(result) {
|
|
|
1465
1477
|
return lines.join("\n");
|
|
1466
1478
|
}
|
|
1467
1479
|
|
|
1480
|
+
// src/tools/ton-bridge.ts
|
|
1481
|
+
var TON_BRIDGE_TOOLS = {
|
|
1482
|
+
"ton/getBalance": {
|
|
1483
|
+
name: "ton/getBalance",
|
|
1484
|
+
description: "Get TON and Jetton balances for a wallet address on the TON blockchain.",
|
|
1485
|
+
inputSchema: {
|
|
1486
|
+
type: "object",
|
|
1487
|
+
properties: {
|
|
1488
|
+
address: {
|
|
1489
|
+
type: "string",
|
|
1490
|
+
description: "TON wallet address (friendly or raw format)"
|
|
1491
|
+
}
|
|
1492
|
+
},
|
|
1493
|
+
required: ["address"]
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
"ton/transfer": {
|
|
1497
|
+
name: "ton/transfer",
|
|
1498
|
+
description: "Send TON to a recipient address on the TON blockchain.",
|
|
1499
|
+
inputSchema: {
|
|
1500
|
+
type: "object",
|
|
1501
|
+
properties: {
|
|
1502
|
+
to: {
|
|
1503
|
+
type: "string",
|
|
1504
|
+
description: "Recipient TON address"
|
|
1505
|
+
},
|
|
1506
|
+
amount: {
|
|
1507
|
+
type: "string",
|
|
1508
|
+
description: 'Amount of TON to send (e.g., "1.5")'
|
|
1509
|
+
},
|
|
1510
|
+
memo: {
|
|
1511
|
+
type: "string",
|
|
1512
|
+
description: "Optional memo/comment for the transfer"
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
required: ["to", "amount"]
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
"ton/getJettonBalance": {
|
|
1519
|
+
name: "ton/getJettonBalance",
|
|
1520
|
+
description: "Get the balance of a specific Jetton (TON token) for a wallet address.",
|
|
1521
|
+
inputSchema: {
|
|
1522
|
+
type: "object",
|
|
1523
|
+
properties: {
|
|
1524
|
+
address: {
|
|
1525
|
+
type: "string",
|
|
1526
|
+
description: "TON wallet address"
|
|
1527
|
+
},
|
|
1528
|
+
jettonMaster: {
|
|
1529
|
+
type: "string",
|
|
1530
|
+
description: "Jetton master contract address"
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
required: ["address", "jettonMaster"]
|
|
1534
|
+
}
|
|
1535
|
+
},
|
|
1536
|
+
"ton/swapJettons": {
|
|
1537
|
+
name: "ton/swapJettons",
|
|
1538
|
+
description: "Swap Jettons (TON tokens) using DEX aggregation on the TON network. Returns a raw transaction JSON to be sent via sendTransaction.",
|
|
1539
|
+
inputSchema: {
|
|
1540
|
+
type: "object",
|
|
1541
|
+
properties: {
|
|
1542
|
+
from: {
|
|
1543
|
+
type: "string",
|
|
1544
|
+
description: 'Source Jetton master address (or "TON" for native TON)'
|
|
1545
|
+
},
|
|
1546
|
+
to: {
|
|
1547
|
+
type: "string",
|
|
1548
|
+
description: 'Destination Jetton master address (or "TON" for native TON)'
|
|
1549
|
+
},
|
|
1550
|
+
amount: {
|
|
1551
|
+
type: "string",
|
|
1552
|
+
description: 'Amount to swap in human-readable format (e.g., "1.5")'
|
|
1553
|
+
},
|
|
1554
|
+
slippage: {
|
|
1555
|
+
type: "string",
|
|
1556
|
+
description: 'Slippage tolerance (e.g., "0.5" for 0.5%)'
|
|
1557
|
+
}
|
|
1558
|
+
},
|
|
1559
|
+
required: ["from", "to", "amount"]
|
|
1560
|
+
}
|
|
1561
|
+
},
|
|
1562
|
+
"ton/getTransactionStatus": {
|
|
1563
|
+
name: "ton/getTransactionStatus",
|
|
1564
|
+
description: "Check the status and details of a TON transaction by its hash.",
|
|
1565
|
+
inputSchema: {
|
|
1566
|
+
type: "object",
|
|
1567
|
+
properties: {
|
|
1568
|
+
txHash: {
|
|
1569
|
+
type: "string",
|
|
1570
|
+
description: "Transaction hash (BOC hash or message hash)"
|
|
1571
|
+
}
|
|
1572
|
+
},
|
|
1573
|
+
required: ["txHash"]
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
async function executeTonBridgeTool(toolName, args, config) {
|
|
1578
|
+
if (config.demoMode) {
|
|
1579
|
+
return executeTonBridgeToolDemo(toolName, args);
|
|
1580
|
+
}
|
|
1581
|
+
if (config.tonMcpEndpoint) {
|
|
1582
|
+
return proxyToTonMcp(toolName, args, config.tonMcpEndpoint);
|
|
1583
|
+
}
|
|
1584
|
+
if (config.tonApiKey) {
|
|
1585
|
+
return executeTonBridgeToolDirect(toolName, args, config.tonApiKey);
|
|
1586
|
+
}
|
|
1587
|
+
return {
|
|
1588
|
+
content: [
|
|
1589
|
+
{
|
|
1590
|
+
type: "text",
|
|
1591
|
+
text: `Error: TON MCP bridge not configured. Set tonMcpEndpoint or tonApiKey.`
|
|
1592
|
+
}
|
|
1593
|
+
],
|
|
1594
|
+
isError: true
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
function executeTonBridgeToolDemo(toolName, args) {
|
|
1598
|
+
const responses = {
|
|
1599
|
+
"ton/getBalance": `[DEMO] TON Balance for ${args.address ?? "unknown"}:
|
|
1600
|
+
- TON: 5.25
|
|
1601
|
+
- USDT0: 100.00`,
|
|
1602
|
+
"ton/transfer": `[DEMO] Transfer sent:
|
|
1603
|
+
- To: ${args.to ?? "unknown"}
|
|
1604
|
+
- Amount: ${args.amount ?? "0"} TON
|
|
1605
|
+
- TX: demo-ton-tx-hash-${Date.now().toString(36)}`,
|
|
1606
|
+
"ton/getJettonBalance": `[DEMO] Jetton Balance:
|
|
1607
|
+
- Address: ${args.address ?? "unknown"}
|
|
1608
|
+
- Jetton: ${args.jettonMaster ?? "unknown"}
|
|
1609
|
+
- Balance: 50.00`,
|
|
1610
|
+
"ton/swapJettons": `[DEMO] Swap quote received:
|
|
1611
|
+
- From: ${args.from ?? "unknown"}
|
|
1612
|
+
- To: ${args.to ?? "unknown"}
|
|
1613
|
+
- Amount: ${args.amount ?? "0"}
|
|
1614
|
+
- Transaction: {"validUntil":${Math.floor(Date.now() / 1e3) + 300},"messages":[{"address":"EQDemo...","amount":"${args.amount ?? "0"}","payload":"base64..."}]}`,
|
|
1615
|
+
"ton/getTransactionStatus": `[DEMO] Transaction Status:
|
|
1616
|
+
- Hash: ${args.txHash ?? "unknown"}
|
|
1617
|
+
- Status: Confirmed
|
|
1618
|
+
- Block: 12345678`
|
|
1619
|
+
};
|
|
1620
|
+
return {
|
|
1621
|
+
content: [
|
|
1622
|
+
{
|
|
1623
|
+
type: "text",
|
|
1624
|
+
text: responses[toolName] ?? `[DEMO] Unknown TON tool: ${toolName}`
|
|
1625
|
+
}
|
|
1626
|
+
]
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
async function proxyToTonMcp(toolName, args, endpoint) {
|
|
1630
|
+
try {
|
|
1631
|
+
const response = await fetch(endpoint, {
|
|
1632
|
+
method: "POST",
|
|
1633
|
+
headers: { "Content-Type": "application/json" },
|
|
1634
|
+
body: JSON.stringify({
|
|
1635
|
+
jsonrpc: "2.0",
|
|
1636
|
+
id: 1,
|
|
1637
|
+
method: "tools/call",
|
|
1638
|
+
params: { name: toolName, arguments: args }
|
|
1639
|
+
})
|
|
1640
|
+
});
|
|
1641
|
+
if (!response.ok) {
|
|
1642
|
+
throw new Error(`TON MCP server returned ${response.status}`);
|
|
1643
|
+
}
|
|
1644
|
+
const result = await response.json();
|
|
1645
|
+
if (result.error) {
|
|
1646
|
+
throw new Error(result.error.message);
|
|
1647
|
+
}
|
|
1648
|
+
return result.result ?? { content: [{ type: "text", text: "No result" }] };
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1651
|
+
return {
|
|
1652
|
+
content: [{ type: "text", text: `Error proxying to @ton/mcp: ${message}` }],
|
|
1653
|
+
isError: true
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
async function executeTonBridgeToolDirect(toolName, args, apiKey) {
|
|
1658
|
+
const baseUrl = "https://toncenter.com/api/v2";
|
|
1659
|
+
try {
|
|
1660
|
+
switch (toolName) {
|
|
1661
|
+
case "ton/getBalance": {
|
|
1662
|
+
const response = await fetch(
|
|
1663
|
+
`${baseUrl}/getAddressBalance?address=${encodeURIComponent(String(args.address))}&api_key=${apiKey}`
|
|
1664
|
+
);
|
|
1665
|
+
const data = await response.json();
|
|
1666
|
+
const balanceNano = BigInt(data.result);
|
|
1667
|
+
const balanceTon = Number(balanceNano) / 1e9;
|
|
1668
|
+
return {
|
|
1669
|
+
content: [{ type: "text", text: `TON Balance: ${balanceTon.toFixed(4)} TON` }]
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
case "ton/getTransactionStatus": {
|
|
1673
|
+
const response = await fetch(
|
|
1674
|
+
`${baseUrl}/getTransactions?hash=${encodeURIComponent(String(args.txHash))}&limit=1&api_key=${apiKey}`
|
|
1675
|
+
);
|
|
1676
|
+
const data = await response.json();
|
|
1677
|
+
if (data.result.length === 0) {
|
|
1678
|
+
return {
|
|
1679
|
+
content: [{ type: "text", text: "Transaction not found" }]
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
return {
|
|
1683
|
+
content: [
|
|
1684
|
+
{
|
|
1685
|
+
type: "text",
|
|
1686
|
+
text: `Transaction found:
|
|
1687
|
+
${JSON.stringify(data.result[0], null, 2)}`
|
|
1688
|
+
}
|
|
1689
|
+
]
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
default:
|
|
1693
|
+
return {
|
|
1694
|
+
content: [
|
|
1695
|
+
{
|
|
1696
|
+
type: "text",
|
|
1697
|
+
text: `Direct execution of ${toolName} is not supported. Configure tonMcpEndpoint to proxy to @ton/mcp.`
|
|
1698
|
+
}
|
|
1699
|
+
],
|
|
1700
|
+
isError: true
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
} catch (error) {
|
|
1704
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1705
|
+
return {
|
|
1706
|
+
content: [{ type: "text", text: `Error executing TON API call: ${message}` }],
|
|
1707
|
+
isError: true
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
function createTonBridgeToolSet(config) {
|
|
1712
|
+
return {
|
|
1713
|
+
definitions: TON_BRIDGE_TOOLS,
|
|
1714
|
+
async handleToolCall(name, args) {
|
|
1715
|
+
return executeTonBridgeTool(name, args, config);
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
// src/tools/unified.ts
|
|
1721
|
+
var import_zod12 = require("zod");
|
|
1722
|
+
var import_wdk_protocol2 = require("@t402/wdk-protocol");
|
|
1723
|
+
var smartPayInputSchema = import_zod12.z.object({
|
|
1724
|
+
url: import_zod12.z.string().url().describe("URL of the 402-protected resource"),
|
|
1725
|
+
maxBridgeFee: import_zod12.z.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
|
|
1726
|
+
preferredNetwork: import_zod12.z.string().optional().describe("Preferred network for payment (optional)")
|
|
1727
|
+
});
|
|
1728
|
+
var paymentPlanInputSchema = import_zod12.z.object({
|
|
1729
|
+
paymentRequired: import_zod12.z.object({
|
|
1730
|
+
scheme: import_zod12.z.string().optional(),
|
|
1731
|
+
network: import_zod12.z.string().optional(),
|
|
1732
|
+
maxAmountRequired: import_zod12.z.string().optional(),
|
|
1733
|
+
resource: import_zod12.z.string().optional(),
|
|
1734
|
+
description: import_zod12.z.string().optional(),
|
|
1735
|
+
payTo: import_zod12.z.string().optional(),
|
|
1736
|
+
maxDeadline: import_zod12.z.number().optional()
|
|
1737
|
+
}).passthrough().describe("The 402 PaymentRequired response")
|
|
1738
|
+
});
|
|
1739
|
+
var UNIFIED_TOOL_DEFINITIONS = {
|
|
1740
|
+
"t402/smartPay": {
|
|
1741
|
+
name: "t402/smartPay",
|
|
1742
|
+
description: "Intelligent payment that automatically checks balance, bridges if needed, and pays. Handles the entire payment flow for 402-protected resources.",
|
|
1743
|
+
inputSchema: {
|
|
1744
|
+
type: "object",
|
|
1745
|
+
properties: {
|
|
1746
|
+
url: { type: "string", description: "URL of the 402-protected resource" },
|
|
1747
|
+
maxBridgeFee: {
|
|
1748
|
+
type: "string",
|
|
1749
|
+
description: "Maximum acceptable bridge fee in native token (optional)"
|
|
1750
|
+
},
|
|
1751
|
+
preferredNetwork: {
|
|
1752
|
+
type: "string",
|
|
1753
|
+
description: "Preferred network for payment (optional)"
|
|
1754
|
+
}
|
|
1755
|
+
},
|
|
1756
|
+
required: ["url"]
|
|
1757
|
+
}
|
|
1758
|
+
},
|
|
1759
|
+
"t402/paymentPlan": {
|
|
1760
|
+
name: "t402/paymentPlan",
|
|
1761
|
+
description: "Analyze a 402 response and create an optimal payment plan considering balances across all chains. Returns recommended network, bridge requirements, and balance overview.",
|
|
1762
|
+
inputSchema: {
|
|
1763
|
+
type: "object",
|
|
1764
|
+
properties: {
|
|
1765
|
+
paymentRequired: {
|
|
1766
|
+
type: "object",
|
|
1767
|
+
description: "The 402 PaymentRequired response"
|
|
1768
|
+
}
|
|
1769
|
+
},
|
|
1770
|
+
required: ["paymentRequired"]
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
async function executeSmartPay(input, wdk) {
|
|
1775
|
+
const steps = [];
|
|
1776
|
+
const chains6 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
|
|
1777
|
+
steps.push({
|
|
1778
|
+
action: "check_balance",
|
|
1779
|
+
status: "success",
|
|
1780
|
+
detail: `Checking balances on ${chains6.join(", ")}`
|
|
1781
|
+
});
|
|
1782
|
+
const protocol = await import_wdk_protocol2.T402Protocol.create(wdk, { chains: chains6 });
|
|
1783
|
+
steps.push({
|
|
1784
|
+
action: "fetch",
|
|
1785
|
+
status: "success",
|
|
1786
|
+
detail: `Fetching ${input.url}`
|
|
1787
|
+
});
|
|
1788
|
+
const { response, receipt } = await protocol.fetch(input.url);
|
|
1789
|
+
if (receipt) {
|
|
1790
|
+
steps.push({
|
|
1791
|
+
action: "pay",
|
|
1792
|
+
status: "success",
|
|
1793
|
+
detail: `Payment made: ${receipt.amount} on ${receipt.network}`
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
const contentType = response.headers.get("content-type") ?? void 0;
|
|
1797
|
+
let body = "";
|
|
1798
|
+
try {
|
|
1799
|
+
body = await response.text();
|
|
1800
|
+
if (body.length > 1e4) {
|
|
1801
|
+
body = body.slice(0, 1e4) + "\n... (truncated)";
|
|
1802
|
+
}
|
|
1803
|
+
} catch {
|
|
1804
|
+
body = "[Could not read response body]";
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
success: response.ok,
|
|
1808
|
+
statusCode: response.status,
|
|
1809
|
+
body,
|
|
1810
|
+
contentType,
|
|
1811
|
+
steps,
|
|
1812
|
+
payment: receipt ? {
|
|
1813
|
+
network: receipt.network,
|
|
1814
|
+
scheme: receipt.scheme,
|
|
1815
|
+
amount: receipt.amount,
|
|
1816
|
+
payTo: receipt.payTo
|
|
1817
|
+
} : void 0
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
function executeSmartPayDemo(input) {
|
|
1821
|
+
const network = input.preferredNetwork ?? "arbitrum";
|
|
1822
|
+
return {
|
|
1823
|
+
success: true,
|
|
1824
|
+
statusCode: 200,
|
|
1825
|
+
body: `[Demo] Premium content from ${input.url}
|
|
1826
|
+
|
|
1827
|
+
This is simulated content returned after smart payment.`,
|
|
1828
|
+
contentType: "text/plain",
|
|
1829
|
+
steps: [
|
|
1830
|
+
{ action: "check_balance", status: "success", detail: `Checked balances on ${network}` },
|
|
1831
|
+
{ action: "check_price", status: "success", detail: "Resource costs 1.00 USDT0" },
|
|
1832
|
+
{ action: "pay", status: "success", detail: `Paid 1000000 USDT0 on eip155:42161` },
|
|
1833
|
+
{ action: "fetch", status: "success", detail: `Fetched ${input.url}` }
|
|
1834
|
+
],
|
|
1835
|
+
payment: {
|
|
1836
|
+
network: "eip155:42161",
|
|
1837
|
+
scheme: "exact",
|
|
1838
|
+
amount: "1000000",
|
|
1839
|
+
payTo: "0xC88f67e776f16DcFBf42e6bDda1B82604448899B"
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
async function executePaymentPlan(input, wdk) {
|
|
1844
|
+
const targetNetwork = input.paymentRequired.network;
|
|
1845
|
+
const requiredAmount = input.paymentRequired.maxAmountRequired;
|
|
1846
|
+
const aggregated = await wdk.getAggregatedBalances();
|
|
1847
|
+
const balances = aggregated.chains.map((chain) => {
|
|
1848
|
+
const usdt0 = chain.tokens.find((t) => t.symbol === "USDT0");
|
|
1849
|
+
const usdc = chain.tokens.find((t) => t.symbol === "USDC");
|
|
1850
|
+
return {
|
|
1851
|
+
chain: chain.chain,
|
|
1852
|
+
usdt0: usdt0?.formatted ?? "0",
|
|
1853
|
+
usdc: usdc?.formatted ?? "0"
|
|
1854
|
+
};
|
|
1855
|
+
});
|
|
1856
|
+
const requiredBigint = requiredAmount ? BigInt(requiredAmount) : 0n;
|
|
1857
|
+
const bestChain = await wdk.findBestChainForPayment(requiredBigint);
|
|
1858
|
+
if (bestChain) {
|
|
1859
|
+
const needsBridge = targetNetwork ? !bestChain.chain.includes(targetNetwork) : false;
|
|
1860
|
+
return {
|
|
1861
|
+
viable: true,
|
|
1862
|
+
recommendedNetwork: bestChain.chain,
|
|
1863
|
+
availableBalance: bestChain.balance.toString(),
|
|
1864
|
+
bridgeRequired: needsBridge,
|
|
1865
|
+
bridgeDetails: needsBridge ? {
|
|
1866
|
+
fromChain: bestChain.chain,
|
|
1867
|
+
toChain: targetNetwork ?? bestChain.chain,
|
|
1868
|
+
amount: requiredAmount ?? "0",
|
|
1869
|
+
estimatedFee: "0.001"
|
|
1870
|
+
} : void 0,
|
|
1871
|
+
balances
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
return {
|
|
1875
|
+
viable: false,
|
|
1876
|
+
bridgeRequired: false,
|
|
1877
|
+
balances,
|
|
1878
|
+
reason: "Insufficient balance across all chains"
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
function executePaymentPlanDemo(_input) {
|
|
1882
|
+
return {
|
|
1883
|
+
viable: true,
|
|
1884
|
+
recommendedNetwork: "arbitrum",
|
|
1885
|
+
availableBalance: "500000000",
|
|
1886
|
+
bridgeRequired: false,
|
|
1887
|
+
balances: [
|
|
1888
|
+
{ chain: "ethereum", usdt0: "100.00", usdc: "250.00" },
|
|
1889
|
+
{ chain: "arbitrum", usdt0: "500.00", usdc: "0" },
|
|
1890
|
+
{ chain: "base", usdt0: "50.00", usdc: "100.00" }
|
|
1891
|
+
]
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
function formatSmartPayResult(result) {
|
|
1895
|
+
const lines = ["## SmartPay Result", ""];
|
|
1896
|
+
if (result.success) {
|
|
1897
|
+
lines.push(`**Status:** Success (${result.statusCode})`);
|
|
1898
|
+
} else {
|
|
1899
|
+
lines.push(`**Status:** Failed (${result.statusCode})`);
|
|
1900
|
+
}
|
|
1901
|
+
if (result.steps.length > 0) {
|
|
1902
|
+
lines.push("");
|
|
1903
|
+
lines.push("### Steps");
|
|
1904
|
+
for (const step of result.steps) {
|
|
1905
|
+
const icon = step.status === "success" ? "[OK]" : step.status === "skipped" ? "[SKIP]" : "[FAIL]";
|
|
1906
|
+
lines.push(`- ${icon} **${step.action}**: ${step.detail}`);
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
if (result.payment) {
|
|
1910
|
+
lines.push("");
|
|
1911
|
+
lines.push("### Payment Details");
|
|
1912
|
+
lines.push(`- **Network:** ${result.payment.network}`);
|
|
1913
|
+
lines.push(`- **Scheme:** ${result.payment.scheme}`);
|
|
1914
|
+
lines.push(`- **Amount:** ${result.payment.amount}`);
|
|
1915
|
+
lines.push(`- **Pay To:** \`${result.payment.payTo}\``);
|
|
1916
|
+
}
|
|
1917
|
+
if (result.error) {
|
|
1918
|
+
lines.push("");
|
|
1919
|
+
lines.push(`**Error:** ${result.error}`);
|
|
1920
|
+
}
|
|
1921
|
+
if (result.body) {
|
|
1922
|
+
lines.push("");
|
|
1923
|
+
lines.push("### Response Content");
|
|
1924
|
+
if (result.contentType) {
|
|
1925
|
+
lines.push(`_Content-Type: ${result.contentType}_`);
|
|
1926
|
+
}
|
|
1927
|
+
lines.push("");
|
|
1928
|
+
lines.push("```");
|
|
1929
|
+
lines.push(result.body);
|
|
1930
|
+
lines.push("```");
|
|
1931
|
+
}
|
|
1932
|
+
return lines.join("\n");
|
|
1933
|
+
}
|
|
1934
|
+
function formatPaymentPlanResult(result) {
|
|
1935
|
+
const lines = ["## Payment Plan", ""];
|
|
1936
|
+
if (result.viable) {
|
|
1937
|
+
lines.push(`**Viable:** Yes`);
|
|
1938
|
+
if (result.recommendedNetwork) {
|
|
1939
|
+
lines.push(`**Recommended Network:** ${result.recommendedNetwork}`);
|
|
1940
|
+
}
|
|
1941
|
+
if (result.availableBalance) {
|
|
1942
|
+
lines.push(`**Available Balance:** ${result.availableBalance}`);
|
|
1943
|
+
}
|
|
1944
|
+
} else {
|
|
1945
|
+
lines.push(`**Viable:** No`);
|
|
1946
|
+
if (result.reason) {
|
|
1947
|
+
lines.push(`**Reason:** ${result.reason}`);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
if (result.bridgeRequired && result.bridgeDetails) {
|
|
1951
|
+
lines.push("");
|
|
1952
|
+
lines.push("### Bridge Required");
|
|
1953
|
+
lines.push(`- **From:** ${result.bridgeDetails.fromChain}`);
|
|
1954
|
+
lines.push(`- **To:** ${result.bridgeDetails.toChain}`);
|
|
1955
|
+
lines.push(`- **Amount:** ${result.bridgeDetails.amount}`);
|
|
1956
|
+
lines.push(`- **Estimated Fee:** ${result.bridgeDetails.estimatedFee}`);
|
|
1957
|
+
}
|
|
1958
|
+
if (result.balances.length > 0) {
|
|
1959
|
+
lines.push("");
|
|
1960
|
+
lines.push("### Chain Balances");
|
|
1961
|
+
lines.push("| Chain | USDT0 | USDC |");
|
|
1962
|
+
lines.push("|-------|-------|------|");
|
|
1963
|
+
for (const b of result.balances) {
|
|
1964
|
+
lines.push(`| ${b.chain} | ${b.usdt0} | ${b.usdc} |`);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
return lines.join("\n");
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1468
1970
|
// src/tools/index.ts
|
|
1469
1971
|
var TOOL_DEFINITIONS = {
|
|
1470
1972
|
"t402/getBalance": {
|
|
@@ -1772,10 +2274,13 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
1772
2274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1773
2275
|
0 && (module.exports = {
|
|
1774
2276
|
GASLESS_SUPPORTED_NETWORKS,
|
|
2277
|
+
TON_BRIDGE_TOOLS,
|
|
1775
2278
|
TOOL_DEFINITIONS,
|
|
2279
|
+
UNIFIED_TOOL_DEFINITIONS,
|
|
1776
2280
|
WDK_TOOL_DEFINITIONS,
|
|
1777
2281
|
autoPayInputSchema,
|
|
1778
2282
|
bridgeInputSchema,
|
|
2283
|
+
createTonBridgeToolSet,
|
|
1779
2284
|
executeAutoPay,
|
|
1780
2285
|
executeAutoPayDemo,
|
|
1781
2286
|
executeBridge,
|
|
@@ -1784,6 +2289,11 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
1784
2289
|
executeGetBridgeFee,
|
|
1785
2290
|
executePay,
|
|
1786
2291
|
executePayGasless,
|
|
2292
|
+
executePaymentPlan,
|
|
2293
|
+
executePaymentPlanDemo,
|
|
2294
|
+
executeSmartPay,
|
|
2295
|
+
executeSmartPayDemo,
|
|
2296
|
+
executeTonBridgeTool,
|
|
1787
2297
|
executeWdkGetBalances,
|
|
1788
2298
|
executeWdkGetBalancesDemo,
|
|
1789
2299
|
executeWdkGetWallet,
|
|
@@ -1798,7 +2308,9 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
1798
2308
|
formatBridgeFeeResult,
|
|
1799
2309
|
formatBridgeResult,
|
|
1800
2310
|
formatGaslessPaymentResult,
|
|
2311
|
+
formatPaymentPlanResult,
|
|
1801
2312
|
formatPaymentResult,
|
|
2313
|
+
formatSmartPayResult,
|
|
1802
2314
|
formatWdkBalancesResult,
|
|
1803
2315
|
formatWdkSwapResult,
|
|
1804
2316
|
formatWdkTransferResult,
|
|
@@ -1808,6 +2320,8 @@ var WDK_TOOL_DEFINITIONS = {
|
|
|
1808
2320
|
getBridgeFeeInputSchema,
|
|
1809
2321
|
payGaslessInputSchema,
|
|
1810
2322
|
payInputSchema,
|
|
2323
|
+
paymentPlanInputSchema,
|
|
2324
|
+
smartPayInputSchema,
|
|
1811
2325
|
wdkGetBalancesInputSchema,
|
|
1812
2326
|
wdkGetWalletInputSchema,
|
|
1813
2327
|
wdkSwapInputSchema,
|