@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.
@@ -435,7 +435,8 @@ var payInputSchema = z3.object({
435
435
  "berachain",
436
436
  "unichain"
437
437
  ]).describe("Network to execute payment on"),
438
- memo: z3.string().optional().describe("Optional memo/reference for the payment")
438
+ memo: z3.string().optional().describe("Optional memo/reference for the payment"),
439
+ confirmed: z3.boolean().optional().describe("Set to true to confirm and execute this payment")
439
440
  });
440
441
  function getViemChain2(network) {
441
442
  switch (network) {
@@ -464,6 +465,13 @@ function getViemChain2(network) {
464
465
  async function executePay(input, options) {
465
466
  const { to, amount, token, network, memo: _memo } = input;
466
467
  const { privateKey, rpcUrl, demoMode } = options;
468
+ if (!input.confirmed) {
469
+ return {
470
+ needsConfirmation: true,
471
+ summary: `Send ${amount} ${token} on ${network} to ${to}`,
472
+ details: { to, amount, token, network }
473
+ };
474
+ }
467
475
  if (!supportsToken(network, token)) {
468
476
  throw new Error(`Token ${token} is not supported on ${network}`);
469
477
  }
@@ -548,7 +556,8 @@ var payGaslessInputSchema = z4.object({
548
556
  to: z4.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address"),
549
557
  amount: z4.string().regex(/^\d+(\.\d+)?$/).describe("Amount to pay (e.g., '10.50' for 10.50 USDC)"),
550
558
  token: z4.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment"),
551
- network: z4.enum(["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"]).describe("Network to execute gasless payment on (must support ERC-4337)")
559
+ network: z4.enum(["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"]).describe("Network to execute gasless payment on (must support ERC-4337)"),
560
+ confirmed: z4.boolean().optional().describe("Set to true to confirm and execute this payment")
552
561
  });
553
562
  var GASLESS_SUPPORTED_NETWORKS = [
554
563
  "ethereum",
@@ -585,6 +594,13 @@ function getViemChain3(network) {
585
594
  async function executePayGasless(input, options) {
586
595
  const { to, amount, token, network } = input;
587
596
  const { privateKey, bundlerUrl, paymasterUrl: _paymasterUrl, rpcUrl, demoMode } = options;
597
+ if (!input.confirmed) {
598
+ return {
599
+ needsConfirmation: true,
600
+ summary: `Send ${amount} ${token} gasless on ${network} to ${to}`,
601
+ details: { to, amount, token, network }
602
+ };
603
+ }
588
604
  if (!GASLESS_SUPPORTED_NETWORKS.includes(network)) {
589
605
  throw new Error(
590
606
  `Network ${network} does not support ERC-4337 gasless transactions. Supported: ${GASLESS_SUPPORTED_NETWORKS.join(", ")}`
@@ -876,7 +892,8 @@ var bridgeInputSchema = z6.object({
876
892
  fromChain: z6.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Source chain to bridge from"),
877
893
  toChain: z6.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Destination chain to bridge to"),
878
894
  amount: z6.string().regex(/^\d+(\.\d+)?$/).describe("Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"),
879
- recipient: z6.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain")
895
+ recipient: z6.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain"),
896
+ confirmed: z6.boolean().optional().describe("Set to true to confirm and execute this bridge")
880
897
  });
881
898
  var LAYERZERO_ENDPOINT_IDS2 = {
882
899
  ethereum: 30101,
@@ -1003,6 +1020,13 @@ function addressToBytes322(address) {
1003
1020
  async function executeBridge(input, options) {
1004
1021
  const { fromChain, toChain, amount, recipient } = input;
1005
1022
  const { privateKey, rpcUrl, demoMode, slippageTolerance = 0.5 } = options;
1023
+ if (!input.confirmed) {
1024
+ return {
1025
+ needsConfirmation: true,
1026
+ summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
1027
+ details: { fromChain, toChain, amount, recipient }
1028
+ };
1029
+ }
1006
1030
  if (fromChain === toChain) {
1007
1031
  throw new Error("Source and destination chains must be different");
1008
1032
  }
@@ -1132,10 +1156,10 @@ import { z as z7 } from "zod";
1132
1156
  var wdkGetWalletInputSchema = z7.object({});
1133
1157
  async function executeWdkGetWallet(_input, wdk) {
1134
1158
  const signer = await wdk.getSigner("ethereum");
1135
- const chains7 = wdk.getConfiguredChains();
1159
+ const chains9 = wdk.getConfiguredChains();
1136
1160
  return {
1137
1161
  evmAddress: signer.address,
1138
- chains: chains7.length > 0 ? chains7 : ["ethereum"]
1162
+ chains: chains9.length > 0 ? chains9 : ["ethereum"]
1139
1163
  };
1140
1164
  }
1141
1165
  function executeWdkGetWalletDemo() {
@@ -1167,14 +1191,14 @@ function findTokenFormatted(tokens, symbol) {
1167
1191
  }
1168
1192
  async function executeWdkGetBalances(input, wdk) {
1169
1193
  const balances = await wdk.getAggregatedBalances();
1170
- const chains7 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
1194
+ const chains9 = balances.chains.filter((c) => !input.chains || input.chains.includes(c.chain)).map((c) => ({
1171
1195
  chain: c.chain,
1172
1196
  usdt0: findTokenFormatted(c.tokens, "USDT0"),
1173
1197
  usdc: findTokenFormatted(c.tokens, "USDC"),
1174
1198
  native: formatUnits2(c.native, 18)
1175
1199
  }));
1176
1200
  return {
1177
- chains: chains7,
1201
+ chains: chains9,
1178
1202
  totalUsdt0: formatUnits2(balances.totalUsdt0, 6),
1179
1203
  totalUsdc: formatUnits2(balances.totalUsdc, 6)
1180
1204
  };
@@ -1216,9 +1240,17 @@ var wdkTransferInputSchema = z9.object({
1216
1240
  to: z9.string().describe("Recipient address"),
1217
1241
  amount: z9.string().regex(/^\d+(\.\d+)?$/).describe("Amount to send (e.g., '10.50')"),
1218
1242
  token: z9.enum(["USDC", "USDT", "USDT0"]).describe("Token to transfer"),
1219
- chain: z9.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")')
1243
+ chain: z9.string().describe('Chain to execute transfer on (e.g., "ethereum", "arbitrum")'),
1244
+ confirmed: z9.boolean().optional().describe("Set to true to confirm and execute this transfer")
1220
1245
  });
1221
1246
  async function executeWdkTransfer(input, wdk) {
1247
+ if (!input.confirmed) {
1248
+ return {
1249
+ needsConfirmation: true,
1250
+ summary: `Transfer ${input.amount} ${input.token} on ${input.chain} to ${input.to}`,
1251
+ details: { to: input.to, amount: input.amount, token: input.token, chain: input.chain }
1252
+ };
1253
+ }
1222
1254
  const signer = await wdk.getSigner(input.chain);
1223
1255
  const result = await signer.sendTransaction({
1224
1256
  to: input.to
@@ -1235,6 +1267,13 @@ async function executeWdkTransfer(input, wdk) {
1235
1267
  };
1236
1268
  }
1237
1269
  function executeWdkTransferDemo(input) {
1270
+ if (!input.confirmed) {
1271
+ return {
1272
+ needsConfirmation: true,
1273
+ summary: `Transfer ${input.amount} ${input.token} on ${input.chain} to ${input.to}`,
1274
+ details: { to: input.to, amount: input.amount, token: input.token, chain: input.chain }
1275
+ };
1276
+ }
1238
1277
  const demoTxHash = "0xdemo" + Math.random().toString(16).slice(2, 10);
1239
1278
  return {
1240
1279
  txHash: demoTxHash,
@@ -1264,9 +1303,22 @@ var wdkSwapInputSchema = z10.object({
1264
1303
  fromToken: z10.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
1265
1304
  toToken: z10.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
1266
1305
  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")')
1306
+ chain: z10.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")'),
1307
+ confirmed: z10.boolean().optional().describe("Set to true to confirm and execute this swap")
1268
1308
  });
1269
1309
  async function executeWdkSwap(input, wdk) {
1310
+ if (!input.confirmed) {
1311
+ return {
1312
+ needsConfirmation: true,
1313
+ summary: `Swap ${input.amount} ${input.fromToken} to ${input.toToken} on ${input.chain}`,
1314
+ details: {
1315
+ fromToken: input.fromToken,
1316
+ toToken: input.toToken,
1317
+ amount: input.amount,
1318
+ chain: input.chain
1319
+ }
1320
+ };
1321
+ }
1270
1322
  const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
1271
1323
  const amountBigInt = parseUnits3(input.amount, decimals);
1272
1324
  const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
@@ -1287,6 +1339,18 @@ async function executeWdkSwap(input, wdk) {
1287
1339
  };
1288
1340
  }
1289
1341
  function executeWdkSwapDemo(input) {
1342
+ if (!input.confirmed) {
1343
+ return {
1344
+ needsConfirmation: true,
1345
+ summary: `Swap ${input.amount} ${input.fromToken} to ${input.toToken} on ${input.chain}`,
1346
+ details: {
1347
+ fromToken: input.fromToken,
1348
+ toToken: input.toToken,
1349
+ amount: input.amount,
1350
+ chain: input.chain
1351
+ }
1352
+ };
1353
+ }
1290
1354
  const inputAmount = parseFloat(input.amount);
1291
1355
  const outputAmount = (inputAmount * 0.997).toFixed(6);
1292
1356
  return {
@@ -1319,12 +1383,24 @@ var autoPayInputSchema = z11.object({
1319
1383
  maxAmount: z11.string().regex(/^\d+(\.\d+)?$/).optional().describe('Maximum amount willing to pay (e.g., "10.00"). If not set, pays any amount.'),
1320
1384
  preferredChain: z11.string().optional().describe(
1321
1385
  'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
1322
- )
1386
+ ),
1387
+ confirmed: z11.boolean().optional().describe("Set to true to confirm and execute this payment")
1323
1388
  });
1324
1389
  async function executeAutoPay(input, wdk) {
1325
- const chains7 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
1390
+ if (!input.confirmed) {
1391
+ return {
1392
+ needsConfirmation: true,
1393
+ summary: `Auto-pay for ${input.url}${input.maxAmount ? ` (max ${input.maxAmount})` : ""}`,
1394
+ details: {
1395
+ url: input.url,
1396
+ ...input.maxAmount ? { maxAmount: input.maxAmount } : {},
1397
+ ...input.preferredChain ? { preferredChain: input.preferredChain } : {}
1398
+ }
1399
+ };
1400
+ }
1401
+ const chains9 = input.preferredChain ? [input.preferredChain] : ["ethereum", "arbitrum", "base"];
1326
1402
  const { T402Protocol } = await import("@t402/wdk-protocol");
1327
- const protocol = await T402Protocol.create(wdk, { chains: chains7 });
1403
+ const protocol = await T402Protocol.create(wdk, { chains: chains9 });
1328
1404
  const { response, receipt } = await protocol.fetch(input.url);
1329
1405
  if (receipt && input.maxAmount) {
1330
1406
  const paidAmount = parseFloat(receipt.amount) / 1e6;
@@ -1362,6 +1438,17 @@ async function executeAutoPay(input, wdk) {
1362
1438
  };
1363
1439
  }
1364
1440
  function executeAutoPayDemo(input) {
1441
+ if (!input.confirmed) {
1442
+ return {
1443
+ needsConfirmation: true,
1444
+ summary: `Auto-pay for ${input.url}${input.maxAmount ? ` (max ${input.maxAmount})` : ""}`,
1445
+ details: {
1446
+ url: input.url,
1447
+ ...input.maxAmount ? { maxAmount: input.maxAmount } : {},
1448
+ ...input.preferredChain ? { preferredChain: input.preferredChain } : {}
1449
+ }
1450
+ };
1451
+ }
1365
1452
  return {
1366
1453
  success: true,
1367
1454
  statusCode: 200,
@@ -1813,22 +1900,744 @@ function formatErc8004VerifyWalletResult(result) {
1813
1900
  return lines.join("\n");
1814
1901
  }
1815
1902
 
1816
- // src/tools/unified.ts
1903
+ // src/tools/priceService.ts
1904
+ var CACHE_TTL_MS = 5 * 60 * 1e3;
1905
+ var COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
1906
+ var TOKEN_TO_COINGECKO_ID = {
1907
+ ETH: "ethereum",
1908
+ MATIC: "matic-network",
1909
+ AVAX: "avalanche-2",
1910
+ BERA: "berachain-bera",
1911
+ USDC: "usd-coin",
1912
+ USDT: "tether",
1913
+ USDT0: "tether"
1914
+ };
1915
+ var cache = /* @__PURE__ */ new Map();
1916
+ async function getTokenPrices(tokens, currency = "usd") {
1917
+ const cacheKey = `${currency}:${tokens.sort().join(",")}`;
1918
+ const cached = cache.get(cacheKey);
1919
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
1920
+ return cached.prices;
1921
+ }
1922
+ const coinIds = /* @__PURE__ */ new Set();
1923
+ const tokenToCoinId = /* @__PURE__ */ new Map();
1924
+ for (const token of tokens) {
1925
+ const coinId = TOKEN_TO_COINGECKO_ID[token.toUpperCase()] ?? token.toLowerCase();
1926
+ coinIds.add(coinId);
1927
+ tokenToCoinId.set(token.toUpperCase(), coinId);
1928
+ }
1929
+ const url = `${COINGECKO_API}?ids=${[...coinIds].join(",")}&vs_currencies=${currency}`;
1930
+ const response = await fetch(url);
1931
+ if (!response.ok) {
1932
+ throw new Error(`CoinGecko API error: ${response.status} ${response.statusText}`);
1933
+ }
1934
+ const data = await response.json();
1935
+ const prices = {};
1936
+ for (const token of tokens) {
1937
+ const coinId = tokenToCoinId.get(token.toUpperCase()) ?? token.toLowerCase();
1938
+ prices[token.toUpperCase()] = data[coinId]?.[currency] ?? 0;
1939
+ }
1940
+ cache.set(cacheKey, { prices, timestamp: Date.now() });
1941
+ return prices;
1942
+ }
1943
+ function getTokenPricesDemo(tokens) {
1944
+ const demoPrices = {
1945
+ ETH: 3250.42,
1946
+ MATIC: 0.58,
1947
+ AVAX: 24.15,
1948
+ BERA: 3.82,
1949
+ USDC: 1,
1950
+ USDT: 1,
1951
+ USDT0: 1
1952
+ };
1953
+ const prices = {};
1954
+ for (const token of tokens) {
1955
+ prices[token.toUpperCase()] = demoPrices[token.toUpperCase()] ?? 0;
1956
+ }
1957
+ return prices;
1958
+ }
1959
+ function clearPriceCache() {
1960
+ cache.clear();
1961
+ }
1962
+
1963
+ // src/tools/getTokenPrice.ts
1817
1964
  import { z as z15 } from "zod";
1818
- var smartPayInputSchema = z15.object({
1819
- url: z15.string().url().describe("URL of the 402-protected resource"),
1820
- maxBridgeFee: z15.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
1821
- preferredNetwork: z15.string().optional().describe("Preferred network for payment (optional)")
1965
+ var getTokenPriceInputSchema = z15.object({
1966
+ tokens: z15.array(z15.string()).min(1).describe('Token symbols to get prices for (e.g., ["ETH", "MATIC", "USDC"])'),
1967
+ currency: z15.string().optional().describe('Target currency (default: "usd"). Supports: usd, eur, gbp, etc.')
1968
+ });
1969
+ async function executeGetTokenPrice(input, options) {
1970
+ const currency = input.currency ?? "usd";
1971
+ const prices = options.demoMode ? getTokenPricesDemo(input.tokens) : await getTokenPrices(input.tokens, currency);
1972
+ return { prices, currency };
1973
+ }
1974
+ function formatTokenPriceResult(result) {
1975
+ const lines = ["## Token Prices", ""];
1976
+ const currencyUpper = result.currency.toUpperCase();
1977
+ for (const [token, price] of Object.entries(result.prices)) {
1978
+ if (price > 0) {
1979
+ lines.push(`- **${token}:** ${price.toLocaleString()} ${currencyUpper}`);
1980
+ } else {
1981
+ lines.push(`- **${token}:** Price unavailable`);
1982
+ }
1983
+ }
1984
+ return lines.join("\n");
1985
+ }
1986
+
1987
+ // src/tools/getGasPrice.ts
1988
+ import { z as z16 } from "zod";
1989
+ import { createPublicClient as createPublicClient7, http as http7, formatGwei } from "viem";
1990
+ import * as chains7 from "viem/chains";
1991
+ var getGasPriceInputSchema = z16.object({
1992
+ network: z16.enum([
1993
+ "ethereum",
1994
+ "base",
1995
+ "arbitrum",
1996
+ "optimism",
1997
+ "polygon",
1998
+ "avalanche",
1999
+ "ink",
2000
+ "berachain",
2001
+ "unichain"
2002
+ ]).describe("Blockchain network to check gas price on")
2003
+ });
2004
+ function getViemChain6(network) {
2005
+ switch (network) {
2006
+ case "ethereum":
2007
+ return chains7.mainnet;
2008
+ case "base":
2009
+ return chains7.base;
2010
+ case "arbitrum":
2011
+ return chains7.arbitrum;
2012
+ case "optimism":
2013
+ return chains7.optimism;
2014
+ case "polygon":
2015
+ return chains7.polygon;
2016
+ case "avalanche":
2017
+ return chains7.avalanche;
2018
+ case "ink":
2019
+ return chains7.ink;
2020
+ case "berachain":
2021
+ return chains7.berachain;
2022
+ case "unichain":
2023
+ return chains7.unichain;
2024
+ default:
2025
+ return chains7.mainnet;
2026
+ }
2027
+ }
2028
+ async function executeGetGasPrice(input, options) {
2029
+ const { network } = input;
2030
+ if (options.demoMode) {
2031
+ const demoGasPrices = {
2032
+ ethereum: 25000000000n,
2033
+ // 25 gwei
2034
+ base: 50000000n,
2035
+ // 0.05 gwei
2036
+ arbitrum: 100000000n,
2037
+ // 0.1 gwei
2038
+ optimism: 50000000n,
2039
+ // 0.05 gwei
2040
+ polygon: 30000000000n,
2041
+ // 30 gwei
2042
+ avalanche: 25000000000n,
2043
+ // 25 nAVAX
2044
+ ink: 50000000n,
2045
+ // 0.05 gwei
2046
+ berachain: 1000000000n,
2047
+ // 1 gwei
2048
+ unichain: 50000000n
2049
+ // 0.05 gwei
2050
+ };
2051
+ const gasPrice2 = demoGasPrices[network] ?? 1000000000n;
2052
+ return {
2053
+ network,
2054
+ gasPriceWei: gasPrice2.toString(),
2055
+ gasPriceGwei: formatGwei(gasPrice2),
2056
+ nativeSymbol: NATIVE_SYMBOLS[network]
2057
+ };
2058
+ }
2059
+ const chain = getViemChain6(network);
2060
+ const transport = http7(options.rpcUrl ?? DEFAULT_RPC_URLS[network]);
2061
+ const client = createPublicClient7({ chain, transport });
2062
+ const gasPrice = await client.getGasPrice();
2063
+ return {
2064
+ network,
2065
+ gasPriceWei: gasPrice.toString(),
2066
+ gasPriceGwei: formatGwei(gasPrice),
2067
+ nativeSymbol: NATIVE_SYMBOLS[network]
2068
+ };
2069
+ }
2070
+ function formatGasPriceResult(result) {
2071
+ return [
2072
+ "## Gas Price",
2073
+ "",
2074
+ `- **Network:** ${result.network}`,
2075
+ `- **Gas Price:** ${result.gasPriceGwei} gwei`,
2076
+ `- **Native Token:** ${result.nativeSymbol}`
2077
+ ].join("\n");
2078
+ }
2079
+
2080
+ // src/tools/estimatePaymentFee.ts
2081
+ import { z as z17 } from "zod";
2082
+ import { createPublicClient as createPublicClient8, http as http8, formatEther as formatEther3, formatGwei as formatGwei2, parseUnits as parseUnits4 } from "viem";
2083
+ import * as chains8 from "viem/chains";
2084
+ var estimatePaymentFeeInputSchema = z17.object({
2085
+ network: z17.enum([
2086
+ "ethereum",
2087
+ "base",
2088
+ "arbitrum",
2089
+ "optimism",
2090
+ "polygon",
2091
+ "avalanche",
2092
+ "ink",
2093
+ "berachain",
2094
+ "unichain"
2095
+ ]).describe("Network to estimate fee on"),
2096
+ amount: z17.string().regex(/^\d+(\.\d+)?$/).describe("Payment amount (e.g., '100')"),
2097
+ token: z17.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment")
2098
+ });
2099
+ function getViemChain7(network) {
2100
+ switch (network) {
2101
+ case "ethereum":
2102
+ return chains8.mainnet;
2103
+ case "base":
2104
+ return chains8.base;
2105
+ case "arbitrum":
2106
+ return chains8.arbitrum;
2107
+ case "optimism":
2108
+ return chains8.optimism;
2109
+ case "polygon":
2110
+ return chains8.polygon;
2111
+ case "avalanche":
2112
+ return chains8.avalanche;
2113
+ case "ink":
2114
+ return chains8.ink;
2115
+ case "berachain":
2116
+ return chains8.berachain;
2117
+ case "unichain":
2118
+ return chains8.unichain;
2119
+ default:
2120
+ return chains8.mainnet;
2121
+ }
2122
+ }
2123
+ async function executeEstimatePaymentFee(input, options) {
2124
+ const { network, amount, token } = input;
2125
+ const nativeSymbol = NATIVE_SYMBOLS[network];
2126
+ if (options.demoMode) {
2127
+ const demoEstimates = {
2128
+ ethereum: { gasLimit: 65000n, gasPrice: 25000000000n, nativePrice: 3250.42 },
2129
+ base: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
2130
+ arbitrum: { gasLimit: 65000n, gasPrice: 100000000n, nativePrice: 3250.42 },
2131
+ optimism: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
2132
+ polygon: { gasLimit: 65000n, gasPrice: 30000000000n, nativePrice: 0.58 },
2133
+ avalanche: { gasLimit: 65000n, gasPrice: 25000000000n, nativePrice: 24.15 },
2134
+ ink: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 },
2135
+ berachain: { gasLimit: 65000n, gasPrice: 1000000000n, nativePrice: 3.82 },
2136
+ unichain: { gasLimit: 65000n, gasPrice: 50000000n, nativePrice: 3250.42 }
2137
+ };
2138
+ const est = demoEstimates[network] ?? demoEstimates["ethereum"];
2139
+ const nativeCost2 = est.gasLimit * est.gasPrice;
2140
+ const usdCost2 = Number(nativeCost2) / 1e18 * est.nativePrice;
2141
+ return {
2142
+ network,
2143
+ gasLimit: est.gasLimit.toString(),
2144
+ gasPriceGwei: formatGwei2(est.gasPrice),
2145
+ nativeCost: formatEther3(nativeCost2),
2146
+ nativeSymbol,
2147
+ usdCost: `$${usdCost2.toFixed(4)}`
2148
+ };
2149
+ }
2150
+ const tokenAddress = getTokenAddress(network, token);
2151
+ if (!tokenAddress) {
2152
+ throw new Error(`Token ${token} is not supported on ${network}`);
2153
+ }
2154
+ const chain = getViemChain7(network);
2155
+ const transport = http8(options.rpcUrl ?? DEFAULT_RPC_URLS[network]);
2156
+ const client = createPublicClient8({ chain, transport });
2157
+ const amountBigInt = parseUnits4(amount, 6);
2158
+ const dummyTo = "0x000000000000000000000000000000000000dEaD";
2159
+ let gasLimit;
2160
+ try {
2161
+ gasLimit = await client.estimateGas({
2162
+ to: tokenAddress,
2163
+ data: `0xa9059cbb${dummyTo.slice(2).padStart(64, "0")}${amountBigInt.toString(16).padStart(64, "0")}`
2164
+ });
2165
+ } catch {
2166
+ gasLimit = 65000n;
2167
+ }
2168
+ const gasPrice = await client.getGasPrice();
2169
+ const nativeCost = gasLimit * gasPrice;
2170
+ let usdCost;
2171
+ try {
2172
+ const prices = await getTokenPrices([nativeSymbol]);
2173
+ const nativePrice = prices[nativeSymbol] ?? 0;
2174
+ const cost = Number(nativeCost) / 1e18 * nativePrice;
2175
+ usdCost = `$${cost.toFixed(4)}`;
2176
+ } catch {
2177
+ usdCost = "N/A";
2178
+ }
2179
+ return {
2180
+ network,
2181
+ gasLimit: gasLimit.toString(),
2182
+ gasPriceGwei: formatGwei2(gasPrice),
2183
+ nativeCost: formatEther3(nativeCost),
2184
+ nativeSymbol,
2185
+ usdCost
2186
+ };
2187
+ }
2188
+ function formatPaymentFeeEstimate(result) {
2189
+ return [
2190
+ "## Payment Fee Estimate",
2191
+ "",
2192
+ `- **Network:** ${result.network}`,
2193
+ `- **Estimated Gas:** ${result.gasLimit}`,
2194
+ `- **Gas Price:** ${result.gasPriceGwei} gwei`,
2195
+ `- **Native Cost:** ${result.nativeCost} ${result.nativeSymbol}`,
2196
+ `- **USD Cost:** ${result.usdCost}`
2197
+ ].join("\n");
2198
+ }
2199
+
2200
+ // src/tools/compareNetworkFees.ts
2201
+ import { z as z18 } from "zod";
2202
+ var compareNetworkFeesInputSchema = z18.object({
2203
+ amount: z18.string().regex(/^\d+(\.\d+)?$/).describe("Payment amount (e.g., '100')"),
2204
+ token: z18.enum(["USDC", "USDT", "USDT0"]).describe("Token to use for payment"),
2205
+ networks: z18.array(z18.string()).optional().describe(
2206
+ "Networks to compare. If not provided, compares all networks that support the token."
2207
+ )
1822
2208
  });
1823
- var paymentPlanInputSchema = z15.object({
1824
- paymentRequired: z15.object({
1825
- scheme: z15.string().optional(),
1826
- network: z15.string().optional(),
1827
- maxAmountRequired: z15.string().optional(),
1828
- resource: z15.string().optional(),
1829
- description: z15.string().optional(),
1830
- payTo: z15.string().optional(),
1831
- maxDeadline: z15.number().optional()
2209
+ var ALL_NETWORKS2 = [
2210
+ "ethereum",
2211
+ "base",
2212
+ "arbitrum",
2213
+ "optimism",
2214
+ "polygon",
2215
+ "avalanche",
2216
+ "ink",
2217
+ "berachain",
2218
+ "unichain"
2219
+ ];
2220
+ async function executeCompareNetworkFees(input, options) {
2221
+ const { amount, token } = input;
2222
+ const requestedNetworks = input.networks ? input.networks : ALL_NETWORKS2;
2223
+ const networks = requestedNetworks.filter((n) => supportsToken(n, token));
2224
+ if (networks.length === 0) {
2225
+ throw new Error(`No supported networks found for token ${token}`);
2226
+ }
2227
+ const results = await Promise.allSettled(
2228
+ networks.map(
2229
+ (network) => executeEstimatePaymentFee(
2230
+ { network, amount, token },
2231
+ {
2232
+ rpcUrl: options.rpcUrls?.[network],
2233
+ demoMode: options.demoMode
2234
+ }
2235
+ )
2236
+ )
2237
+ );
2238
+ const fees = [];
2239
+ for (const result of results) {
2240
+ if (result.status === "fulfilled") {
2241
+ fees.push(result.value);
2242
+ }
2243
+ }
2244
+ if (fees.length === 0) {
2245
+ throw new Error("Failed to estimate fees on any network");
2246
+ }
2247
+ fees.sort((a, b) => {
2248
+ const costA = parseFloat(a.nativeCost) || Infinity;
2249
+ const costB = parseFloat(b.nativeCost) || Infinity;
2250
+ const usdA = parseFloat(a.usdCost.replace("$", "")) || Infinity;
2251
+ const usdB = parseFloat(b.usdCost.replace("$", "")) || Infinity;
2252
+ return usdA - usdB || costA - costB;
2253
+ });
2254
+ return {
2255
+ token,
2256
+ amount,
2257
+ fees,
2258
+ cheapest: fees[0].network
2259
+ };
2260
+ }
2261
+ function formatNetworkFeeComparison(result) {
2262
+ const lines = [
2263
+ "## Network Fee Comparison",
2264
+ "",
2265
+ `**Token:** ${result.token} | **Amount:** ${result.amount}`,
2266
+ `**Cheapest:** ${result.cheapest}`,
2267
+ "",
2268
+ "| Network | Gas Price | Native Cost | USD Cost |",
2269
+ "|---------|----------|-------------|----------|"
2270
+ ];
2271
+ for (const fee of result.fees) {
2272
+ const marker = fee.network === result.cheapest ? " *" : "";
2273
+ lines.push(
2274
+ `| ${fee.network}${marker} | ${fee.gasPriceGwei} gwei | ${fee.nativeCost} ${fee.nativeSymbol} | ${fee.usdCost} |`
2275
+ );
2276
+ }
2277
+ return lines.join("\n");
2278
+ }
2279
+
2280
+ // src/tools/quoteStore.ts
2281
+ import { randomUUID } from "crypto";
2282
+ var DEFAULT_TTL_MS = 5 * 60 * 1e3;
2283
+ var quotes = /* @__PURE__ */ new Map();
2284
+ var cleanupInterval = null;
2285
+ function ensureCleanup() {
2286
+ if (cleanupInterval) return;
2287
+ cleanupInterval = setInterval(() => {
2288
+ const now = Date.now();
2289
+ for (const [id, quote] of quotes) {
2290
+ if (now > quote.expiresAt) {
2291
+ quotes.delete(id);
2292
+ }
2293
+ }
2294
+ }, 6e4);
2295
+ if (cleanupInterval.unref) {
2296
+ cleanupInterval.unref();
2297
+ }
2298
+ }
2299
+ function createQuote(type, data, ttlMs = DEFAULT_TTL_MS) {
2300
+ ensureCleanup();
2301
+ const id = randomUUID();
2302
+ const now = Date.now();
2303
+ quotes.set(id, {
2304
+ id,
2305
+ type,
2306
+ createdAt: now,
2307
+ expiresAt: now + ttlMs,
2308
+ data
2309
+ });
2310
+ return id;
2311
+ }
2312
+ function getQuote(quoteId) {
2313
+ const quote = quotes.get(quoteId);
2314
+ if (!quote) return null;
2315
+ if (Date.now() > quote.expiresAt) {
2316
+ quotes.delete(quoteId);
2317
+ return null;
2318
+ }
2319
+ return quote;
2320
+ }
2321
+ function deleteQuote(quoteId) {
2322
+ quotes.delete(quoteId);
2323
+ }
2324
+ function clearQuoteStore() {
2325
+ quotes.clear();
2326
+ }
2327
+
2328
+ // src/tools/wdkQuoteSwap.ts
2329
+ import { z as z19 } from "zod";
2330
+ import { parseUnits as parseUnits5 } from "viem";
2331
+ var wdkQuoteSwapInputSchema = z19.object({
2332
+ fromToken: z19.string().describe('Token to swap from (e.g., "ETH", "USDC")'),
2333
+ toToken: z19.string().describe('Token to swap to (e.g., "USDT0", "USDC")'),
2334
+ amount: z19.string().regex(/^\d+(\.\d+)?$/).describe("Amount to swap (e.g., '1.0')"),
2335
+ chain: z19.string().describe('Chain to execute swap on (e.g., "ethereum", "arbitrum")')
2336
+ });
2337
+ async function executeWdkQuoteSwap(input, wdk) {
2338
+ const decimals = ["USDC", "USDT", "USDT0"].includes(input.fromToken.toUpperCase()) ? 6 : 18;
2339
+ const amountBigInt = parseUnits5(input.amount, decimals);
2340
+ const quote = await wdk.getSwapQuote(input.chain, input.fromToken, amountBigInt);
2341
+ const outputDecimals = ["USDC", "USDT", "USDT0"].includes(input.toToken.toUpperCase()) ? 6 : 18;
2342
+ const outputDivisor = 10 ** outputDecimals;
2343
+ const toAmount = (Number(quote.outputAmount) / outputDivisor).toFixed(outputDecimals === 6 ? 6 : 8);
2344
+ const inputAmount = parseFloat(input.amount);
2345
+ const outputAmount = parseFloat(toAmount);
2346
+ const exchangeRate = inputAmount > 0 ? (outputAmount / inputAmount).toFixed(6) : "0";
2347
+ const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
2348
+ const quoteId = createQuote("swap", {
2349
+ fromToken: input.fromToken,
2350
+ toToken: input.toToken,
2351
+ fromAmount: input.amount,
2352
+ toAmount,
2353
+ chain: input.chain,
2354
+ exchangeRate
2355
+ });
2356
+ return {
2357
+ quoteId,
2358
+ fromToken: input.fromToken,
2359
+ toToken: input.toToken,
2360
+ fromAmount: input.amount,
2361
+ toAmount,
2362
+ exchangeRate,
2363
+ fee: "0.3%",
2364
+ priceImpact: "< 0.1%",
2365
+ expiresAt,
2366
+ chain: input.chain
2367
+ };
2368
+ }
2369
+ function executeWdkQuoteSwapDemo(input) {
2370
+ const inputAmount = parseFloat(input.amount);
2371
+ const toAmount = (inputAmount * 0.997).toFixed(6);
2372
+ const exchangeRate = 0.997.toFixed(6);
2373
+ const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
2374
+ const quoteId = createQuote("swap", {
2375
+ fromToken: input.fromToken,
2376
+ toToken: input.toToken,
2377
+ fromAmount: input.amount,
2378
+ toAmount,
2379
+ chain: input.chain,
2380
+ exchangeRate
2381
+ });
2382
+ return {
2383
+ quoteId,
2384
+ fromToken: input.fromToken,
2385
+ toToken: input.toToken,
2386
+ fromAmount: input.amount,
2387
+ toAmount,
2388
+ exchangeRate,
2389
+ fee: "0.3%",
2390
+ priceImpact: "< 0.1%",
2391
+ expiresAt,
2392
+ chain: input.chain
2393
+ };
2394
+ }
2395
+ function formatSwapQuoteResult(result) {
2396
+ return [
2397
+ "## Swap Quote",
2398
+ "",
2399
+ `- **Quote ID:** \`${result.quoteId}\``,
2400
+ `- **From:** ${result.fromAmount} ${result.fromToken}`,
2401
+ `- **To:** ${result.toAmount} ${result.toToken}`,
2402
+ `- **Exchange Rate:** ${result.exchangeRate}`,
2403
+ `- **Fee:** ${result.fee}`,
2404
+ `- **Price Impact:** ${result.priceImpact}`,
2405
+ `- **Chain:** ${result.chain}`,
2406
+ `- **Expires:** ${result.expiresAt}`,
2407
+ "",
2408
+ "_Call `wdk/executeSwap` with the quoteId to execute this swap._"
2409
+ ].join("\n");
2410
+ }
2411
+
2412
+ // src/tools/wdkExecuteSwap.ts
2413
+ import { z as z20 } from "zod";
2414
+ import { parseUnits as parseUnits6 } from "viem";
2415
+ var wdkExecuteSwapInputSchema = z20.object({
2416
+ quoteId: z20.string().uuid().describe("Quote ID from wdk/quoteSwap"),
2417
+ confirmed: z20.boolean().optional().describe("Set to true to confirm and execute this swap")
2418
+ });
2419
+ async function executeWdkExecuteSwap(input, wdk) {
2420
+ const quote = getQuote(input.quoteId);
2421
+ if (!quote) {
2422
+ throw new Error("Quote not found or expired. Please request a new quote.");
2423
+ }
2424
+ if (quote.type !== "swap") {
2425
+ throw new Error("Invalid quote type. Expected a swap quote.");
2426
+ }
2427
+ const { fromToken, toToken, fromAmount, toAmount, chain } = quote.data;
2428
+ if (!input.confirmed) {
2429
+ return {
2430
+ needsConfirmation: true,
2431
+ summary: `Swap ${fromAmount} ${fromToken} to ${toAmount} ${toToken} on ${chain}`,
2432
+ details: { fromToken, toToken, fromAmount, toAmount, chain, quoteId: input.quoteId }
2433
+ };
2434
+ }
2435
+ const decimals = ["USDC", "USDT", "USDT0"].includes(fromToken.toUpperCase()) ? 6 : 18;
2436
+ const amountBigInt = parseUnits6(fromAmount, decimals);
2437
+ const result = await wdk.swapAndPay({
2438
+ chain,
2439
+ fromToken,
2440
+ amount: amountBigInt
2441
+ });
2442
+ deleteQuote(input.quoteId);
2443
+ return {
2444
+ fromAmount,
2445
+ fromToken,
2446
+ toAmount,
2447
+ toToken,
2448
+ chain,
2449
+ txHash: result?.txHash ?? "0x"
2450
+ };
2451
+ }
2452
+ function executeWdkExecuteSwapDemo(input) {
2453
+ const quote = getQuote(input.quoteId);
2454
+ if (!quote) {
2455
+ throw new Error("Quote not found or expired. Please request a new quote.");
2456
+ }
2457
+ if (quote.type !== "swap") {
2458
+ throw new Error("Invalid quote type. Expected a swap quote.");
2459
+ }
2460
+ const { fromToken, toToken, fromAmount, toAmount, chain } = quote.data;
2461
+ if (!input.confirmed) {
2462
+ return {
2463
+ needsConfirmation: true,
2464
+ summary: `Swap ${fromAmount} ${fromToken} to ${toAmount} ${toToken} on ${chain}`,
2465
+ details: { fromToken, toToken, fromAmount, toAmount, chain, quoteId: input.quoteId }
2466
+ };
2467
+ }
2468
+ deleteQuote(input.quoteId);
2469
+ return {
2470
+ fromAmount,
2471
+ fromToken,
2472
+ toAmount,
2473
+ toToken,
2474
+ chain,
2475
+ txHash: "0xdemo" + Math.random().toString(16).slice(2, 10)
2476
+ };
2477
+ }
2478
+ function formatExecuteSwapResult(result) {
2479
+ return [
2480
+ "## Swap Executed",
2481
+ "",
2482
+ `- **From:** ${result.fromAmount} ${result.fromToken}`,
2483
+ `- **To:** ${result.toAmount} ${result.toToken}`,
2484
+ `- **Chain:** ${result.chain}`,
2485
+ `- **Tx Hash:** \`${result.txHash}\``
2486
+ ].join("\n");
2487
+ }
2488
+
2489
+ // src/tools/quoteBridge.ts
2490
+ import { z as z21 } from "zod";
2491
+ var quoteBridgeInputSchema = z21.object({
2492
+ fromChain: z21.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Source chain to bridge from"),
2493
+ toChain: z21.enum(["ethereum", "arbitrum", "ink", "berachain", "unichain"]).describe("Destination chain to bridge to"),
2494
+ amount: z21.string().regex(/^\d+(\.\d+)?$/).describe("Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"),
2495
+ recipient: z21.string().regex(/^0x[a-fA-F0-9]{40}$/).describe("Recipient address on destination chain")
2496
+ });
2497
+ async function executeQuoteBridge(input, rpcUrls) {
2498
+ const feeResult = await executeGetBridgeFee(input, rpcUrls);
2499
+ const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
2500
+ const quoteId = createQuote("bridge", {
2501
+ fromChain: input.fromChain,
2502
+ toChain: input.toChain,
2503
+ amount: input.amount,
2504
+ recipient: input.recipient,
2505
+ nativeFee: feeResult.nativeFee,
2506
+ nativeFeeFormatted: feeResult.nativeFeeFormatted,
2507
+ estimatedTime: feeResult.estimatedTime
2508
+ });
2509
+ return {
2510
+ quoteId,
2511
+ fromChain: input.fromChain,
2512
+ toChain: input.toChain,
2513
+ amount: input.amount,
2514
+ recipient: input.recipient,
2515
+ nativeFee: feeResult.nativeFee,
2516
+ nativeFeeFormatted: feeResult.nativeFeeFormatted,
2517
+ estimatedTime: feeResult.estimatedTime,
2518
+ expiresAt
2519
+ };
2520
+ }
2521
+ function executeQuoteBridgeDemo(input) {
2522
+ const expiresAt = new Date(Date.now() + 5 * 60 * 1e3).toISOString();
2523
+ const estimatedTime = input.toChain === "ethereum" ? 900 : 300;
2524
+ const quoteId = createQuote("bridge", {
2525
+ fromChain: input.fromChain,
2526
+ toChain: input.toChain,
2527
+ amount: input.amount,
2528
+ recipient: input.recipient,
2529
+ nativeFee: "1000000000000000",
2530
+ nativeFeeFormatted: "0.001 ETH",
2531
+ estimatedTime
2532
+ });
2533
+ return {
2534
+ quoteId,
2535
+ fromChain: input.fromChain,
2536
+ toChain: input.toChain,
2537
+ amount: input.amount,
2538
+ recipient: input.recipient,
2539
+ nativeFee: "1000000000000000",
2540
+ nativeFeeFormatted: "0.001 ETH",
2541
+ estimatedTime,
2542
+ expiresAt
2543
+ };
2544
+ }
2545
+ function formatBridgeQuoteResult(result) {
2546
+ const minutes = Math.ceil(result.estimatedTime / 60);
2547
+ return [
2548
+ "## Bridge Quote",
2549
+ "",
2550
+ `- **Quote ID:** \`${result.quoteId}\``,
2551
+ `- **Route:** ${result.fromChain} -> ${result.toChain}`,
2552
+ `- **Amount:** ${result.amount} USDT0`,
2553
+ `- **Recipient:** \`${result.recipient}\``,
2554
+ `- **Fee:** ${result.nativeFeeFormatted}`,
2555
+ `- **Estimated Time:** ~${minutes} minutes`,
2556
+ `- **Expires:** ${result.expiresAt}`,
2557
+ "",
2558
+ "_Call `t402/executeBridge` with the quoteId to execute this bridge._"
2559
+ ].join("\n");
2560
+ }
2561
+
2562
+ // src/tools/executeBridgeFromQuote.ts
2563
+ import { z as z22 } from "zod";
2564
+ var executeBridgeFromQuoteInputSchema = z22.object({
2565
+ quoteId: z22.string().uuid().describe("Quote ID from t402/quoteBridge"),
2566
+ confirmed: z22.boolean().optional().describe("Set to true to confirm and execute this bridge")
2567
+ });
2568
+ async function executeExecuteBridgeFromQuote(input, options) {
2569
+ const quote = getQuote(input.quoteId);
2570
+ if (!quote) {
2571
+ throw new Error("Quote not found or expired. Please request a new quote.");
2572
+ }
2573
+ if (quote.type !== "bridge") {
2574
+ throw new Error("Invalid quote type. Expected a bridge quote.");
2575
+ }
2576
+ const { fromChain, toChain, amount, recipient } = quote.data;
2577
+ if (!input.confirmed) {
2578
+ return {
2579
+ needsConfirmation: true,
2580
+ summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
2581
+ details: { fromChain, toChain, amount, recipient, quoteId: input.quoteId }
2582
+ };
2583
+ }
2584
+ const result = await executeBridge(
2585
+ { fromChain, toChain, amount, recipient, confirmed: true },
2586
+ options
2587
+ );
2588
+ if ("needsConfirmation" in result) {
2589
+ return result;
2590
+ }
2591
+ deleteQuote(input.quoteId);
2592
+ return result;
2593
+ }
2594
+ function executeExecuteBridgeFromQuoteDemo(input) {
2595
+ const quote = getQuote(input.quoteId);
2596
+ if (!quote) {
2597
+ throw new Error("Quote not found or expired. Please request a new quote.");
2598
+ }
2599
+ if (quote.type !== "bridge") {
2600
+ throw new Error("Invalid quote type. Expected a bridge quote.");
2601
+ }
2602
+ const { fromChain, toChain, amount, recipient } = quote.data;
2603
+ if (!input.confirmed) {
2604
+ return {
2605
+ needsConfirmation: true,
2606
+ summary: `Bridge ${amount} USDT0 from ${fromChain} to ${toChain}`,
2607
+ details: { fromChain, toChain, amount, recipient, quoteId: input.quoteId }
2608
+ };
2609
+ }
2610
+ deleteQuote(input.quoteId);
2611
+ const fakeTxHash = `0x${"a".repeat(64)}`;
2612
+ const fakeGuid = `0x${"b".repeat(64)}`;
2613
+ return {
2614
+ txHash: fakeTxHash,
2615
+ messageGuid: fakeGuid,
2616
+ amount,
2617
+ fromChain,
2618
+ toChain,
2619
+ estimatedTime: quote.data.estimatedTime ?? 300,
2620
+ trackingUrl: `https://layerzeroscan.com/tx/${fakeGuid}`
2621
+ };
2622
+ }
2623
+
2624
+ // src/tools/unified.ts
2625
+ import { z as z23 } from "zod";
2626
+ var smartPayInputSchema = z23.object({
2627
+ url: z23.string().url().describe("URL of the 402-protected resource"),
2628
+ maxBridgeFee: z23.string().regex(/^\d+(\.\d+)?$/).optional().describe("Maximum acceptable bridge fee in native token (optional)"),
2629
+ preferredNetwork: z23.string().optional().describe("Preferred network for payment (optional)"),
2630
+ confirmed: z23.boolean().optional().describe("Set to true to confirm and execute this payment")
2631
+ });
2632
+ var paymentPlanInputSchema = z23.object({
2633
+ paymentRequired: z23.object({
2634
+ scheme: z23.string().optional(),
2635
+ network: z23.string().optional(),
2636
+ maxAmountRequired: z23.string().optional(),
2637
+ resource: z23.string().optional(),
2638
+ description: z23.string().optional(),
2639
+ payTo: z23.string().optional(),
2640
+ maxDeadline: z23.number().optional()
1832
2641
  }).passthrough().describe("The 402 PaymentRequired response")
1833
2642
  });
1834
2643
  var UNIFIED_TOOL_DEFINITIONS = {
@@ -1846,6 +2655,10 @@ var UNIFIED_TOOL_DEFINITIONS = {
1846
2655
  preferredNetwork: {
1847
2656
  type: "string",
1848
2657
  description: "Preferred network for payment (optional)"
2658
+ },
2659
+ confirmed: {
2660
+ type: "boolean",
2661
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
1849
2662
  }
1850
2663
  },
1851
2664
  required: ["url"]
@@ -1867,15 +2680,26 @@ var UNIFIED_TOOL_DEFINITIONS = {
1867
2680
  }
1868
2681
  };
1869
2682
  async function executeSmartPay(input, wdk) {
2683
+ if (!input.confirmed) {
2684
+ return {
2685
+ needsConfirmation: true,
2686
+ summary: `Smart-pay for ${input.url}${input.preferredNetwork ? ` on ${input.preferredNetwork}` : ""}`,
2687
+ details: {
2688
+ url: input.url,
2689
+ ...input.maxBridgeFee ? { maxBridgeFee: input.maxBridgeFee } : {},
2690
+ ...input.preferredNetwork ? { preferredNetwork: input.preferredNetwork } : {}
2691
+ }
2692
+ };
2693
+ }
1870
2694
  const steps = [];
1871
- const chains7 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
2695
+ const chains9 = input.preferredNetwork ? [input.preferredNetwork] : ["ethereum", "arbitrum", "base"];
1872
2696
  steps.push({
1873
2697
  action: "check_balance",
1874
2698
  status: "success",
1875
- detail: `Checking balances on ${chains7.join(", ")}`
2699
+ detail: `Checking balances on ${chains9.join(", ")}`
1876
2700
  });
1877
2701
  const { T402Protocol } = await import("@t402/wdk-protocol");
1878
- const protocol = await T402Protocol.create(wdk, { chains: chains7 });
2702
+ const protocol = await T402Protocol.create(wdk, { chains: chains9 });
1879
2703
  steps.push({
1880
2704
  action: "fetch",
1881
2705
  status: "success",
@@ -1914,6 +2738,17 @@ async function executeSmartPay(input, wdk) {
1914
2738
  };
1915
2739
  }
1916
2740
  function executeSmartPayDemo(input) {
2741
+ if (!input.confirmed) {
2742
+ return {
2743
+ needsConfirmation: true,
2744
+ summary: `Smart-pay for ${input.url}${input.preferredNetwork ? ` on ${input.preferredNetwork}` : ""}`,
2745
+ details: {
2746
+ url: input.url,
2747
+ ...input.maxBridgeFee ? { maxBridgeFee: input.maxBridgeFee } : {},
2748
+ ...input.preferredNetwork ? { preferredNetwork: input.preferredNetwork } : {}
2749
+ }
2750
+ };
2751
+ }
1917
2752
  const network = input.preferredNetwork ?? "arbitrum";
1918
2753
  return {
1919
2754
  success: true,
@@ -2167,6 +3002,10 @@ var TOOL_DEFINITIONS = {
2167
3002
  memo: {
2168
3003
  type: "string",
2169
3004
  description: "Optional memo/reference for the payment"
3005
+ },
3006
+ confirmed: {
3007
+ type: "boolean",
3008
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2170
3009
  }
2171
3010
  },
2172
3011
  required: ["to", "amount", "token", "network"]
@@ -2197,6 +3036,10 @@ var TOOL_DEFINITIONS = {
2197
3036
  type: "string",
2198
3037
  enum: ["ethereum", "base", "arbitrum", "optimism", "polygon", "avalanche"],
2199
3038
  description: "Network to execute gasless payment on (must support ERC-4337)"
3039
+ },
3040
+ confirmed: {
3041
+ type: "boolean",
3042
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2200
3043
  }
2201
3044
  },
2202
3045
  required: ["to", "amount", "token", "network"]
@@ -2257,10 +3100,166 @@ var TOOL_DEFINITIONS = {
2257
3100
  type: "string",
2258
3101
  pattern: "^0x[a-fA-F0-9]{40}$",
2259
3102
  description: "Recipient address on destination chain"
3103
+ },
3104
+ confirmed: {
3105
+ type: "boolean",
3106
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2260
3107
  }
2261
3108
  },
2262
3109
  required: ["fromChain", "toChain", "amount", "recipient"]
2263
3110
  }
3111
+ },
3112
+ "t402/getTokenPrice": {
3113
+ name: "t402/getTokenPrice",
3114
+ description: "Get current market prices for tokens (ETH, MATIC, AVAX, USDC, etc.) via CoinGecko. Cached for 5 minutes.",
3115
+ inputSchema: {
3116
+ type: "object",
3117
+ properties: {
3118
+ tokens: {
3119
+ type: "array",
3120
+ items: { type: "string" },
3121
+ description: 'Token symbols to get prices for (e.g., ["ETH", "MATIC", "USDC"])'
3122
+ },
3123
+ currency: {
3124
+ type: "string",
3125
+ description: 'Target currency (default: "usd")'
3126
+ }
3127
+ },
3128
+ required: ["tokens"]
3129
+ }
3130
+ },
3131
+ "t402/getGasPrice": {
3132
+ name: "t402/getGasPrice",
3133
+ description: "Get the current gas price on a specific blockchain network. Returns the price in gwei.",
3134
+ inputSchema: {
3135
+ type: "object",
3136
+ properties: {
3137
+ network: {
3138
+ type: "string",
3139
+ enum: [
3140
+ "ethereum",
3141
+ "base",
3142
+ "arbitrum",
3143
+ "optimism",
3144
+ "polygon",
3145
+ "avalanche",
3146
+ "ink",
3147
+ "berachain",
3148
+ "unichain"
3149
+ ],
3150
+ description: "Blockchain network to check gas price on"
3151
+ }
3152
+ },
3153
+ required: ["network"]
3154
+ }
3155
+ },
3156
+ "t402/estimatePaymentFee": {
3157
+ name: "t402/estimatePaymentFee",
3158
+ description: "Estimate the gas cost (in native token and USD) for a stablecoin payment on a specific network.",
3159
+ inputSchema: {
3160
+ type: "object",
3161
+ properties: {
3162
+ network: {
3163
+ type: "string",
3164
+ enum: [
3165
+ "ethereum",
3166
+ "base",
3167
+ "arbitrum",
3168
+ "optimism",
3169
+ "polygon",
3170
+ "avalanche",
3171
+ "ink",
3172
+ "berachain",
3173
+ "unichain"
3174
+ ],
3175
+ description: "Network to estimate fee on"
3176
+ },
3177
+ amount: {
3178
+ type: "string",
3179
+ pattern: "^\\d+(\\.\\d+)?$",
3180
+ description: "Payment amount (e.g., '100')"
3181
+ },
3182
+ token: {
3183
+ type: "string",
3184
+ enum: ["USDC", "USDT", "USDT0"],
3185
+ description: "Token to use for payment"
3186
+ }
3187
+ },
3188
+ required: ["network", "amount", "token"]
3189
+ }
3190
+ },
3191
+ "t402/compareNetworkFees": {
3192
+ name: "t402/compareNetworkFees",
3193
+ description: "Compare payment fees across multiple networks for the same token. Returns a sorted table from cheapest to most expensive.",
3194
+ inputSchema: {
3195
+ type: "object",
3196
+ properties: {
3197
+ amount: {
3198
+ type: "string",
3199
+ pattern: "^\\d+(\\.\\d+)?$",
3200
+ description: "Payment amount (e.g., '100')"
3201
+ },
3202
+ token: {
3203
+ type: "string",
3204
+ enum: ["USDC", "USDT", "USDT0"],
3205
+ description: "Token to use for payment"
3206
+ },
3207
+ networks: {
3208
+ type: "array",
3209
+ items: { type: "string" },
3210
+ description: "Networks to compare. If not provided, compares all networks that support the token."
3211
+ }
3212
+ },
3213
+ required: ["amount", "token"]
3214
+ }
3215
+ },
3216
+ "t402/quoteBridge": {
3217
+ name: "t402/quoteBridge",
3218
+ 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.",
3219
+ inputSchema: {
3220
+ type: "object",
3221
+ properties: {
3222
+ fromChain: {
3223
+ type: "string",
3224
+ enum: ["ethereum", "arbitrum", "ink", "berachain", "unichain"],
3225
+ description: "Source chain to bridge from"
3226
+ },
3227
+ toChain: {
3228
+ type: "string",
3229
+ enum: ["ethereum", "arbitrum", "ink", "berachain", "unichain"],
3230
+ description: "Destination chain to bridge to"
3231
+ },
3232
+ amount: {
3233
+ type: "string",
3234
+ pattern: "^\\d+(\\.\\d+)?$",
3235
+ description: "Amount of USDT0 to bridge (e.g., '100' for 100 USDT0)"
3236
+ },
3237
+ recipient: {
3238
+ type: "string",
3239
+ pattern: "^0x[a-fA-F0-9]{40}$",
3240
+ description: "Recipient address on destination chain"
3241
+ }
3242
+ },
3243
+ required: ["fromChain", "toChain", "amount", "recipient"]
3244
+ }
3245
+ },
3246
+ "t402/executeBridgeQuote": {
3247
+ name: "t402/executeBridgeQuote",
3248
+ description: "Execute a bridge using a quoteId from t402/quoteBridge. Requires confirmation.",
3249
+ inputSchema: {
3250
+ type: "object",
3251
+ properties: {
3252
+ quoteId: {
3253
+ type: "string",
3254
+ description: "Quote ID from t402/quoteBridge"
3255
+ },
3256
+ confirmed: {
3257
+ type: "boolean",
3258
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
3259
+ }
3260
+ },
3261
+ required: ["quoteId"]
3262
+ }
2264
3263
  }
2265
3264
  };
2266
3265
  var WDK_TOOL_DEFINITIONS = {
@@ -2311,6 +3310,10 @@ var WDK_TOOL_DEFINITIONS = {
2311
3310
  chain: {
2312
3311
  type: "string",
2313
3312
  description: 'Chain to execute transfer on (e.g., "ethereum", "arbitrum")'
3313
+ },
3314
+ confirmed: {
3315
+ type: "boolean",
3316
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2314
3317
  }
2315
3318
  },
2316
3319
  required: ["to", "amount", "token", "chain"]
@@ -2338,6 +3341,10 @@ var WDK_TOOL_DEFINITIONS = {
2338
3341
  chain: {
2339
3342
  type: "string",
2340
3343
  description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
3344
+ },
3345
+ confirmed: {
3346
+ type: "boolean",
3347
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2341
3348
  }
2342
3349
  },
2343
3350
  required: ["fromToken", "toToken", "amount", "chain"]
@@ -2361,10 +3368,59 @@ var WDK_TOOL_DEFINITIONS = {
2361
3368
  preferredChain: {
2362
3369
  type: "string",
2363
3370
  description: 'Preferred chain for payment (e.g., "arbitrum"). If not specified, uses first available.'
3371
+ },
3372
+ confirmed: {
3373
+ type: "boolean",
3374
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
2364
3375
  }
2365
3376
  },
2366
3377
  required: ["url"]
2367
3378
  }
3379
+ },
3380
+ "wdk/quoteSwap": {
3381
+ name: "wdk/quoteSwap",
3382
+ 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.",
3383
+ inputSchema: {
3384
+ type: "object",
3385
+ properties: {
3386
+ fromToken: {
3387
+ type: "string",
3388
+ description: 'Token to swap from (e.g., "ETH", "USDC")'
3389
+ },
3390
+ toToken: {
3391
+ type: "string",
3392
+ description: 'Token to swap to (e.g., "USDT0", "USDC")'
3393
+ },
3394
+ amount: {
3395
+ type: "string",
3396
+ pattern: "^\\d+(\\.\\d+)?$",
3397
+ description: "Amount to swap (e.g., '1.0')"
3398
+ },
3399
+ chain: {
3400
+ type: "string",
3401
+ description: 'Chain to execute swap on (e.g., "ethereum", "arbitrum")'
3402
+ }
3403
+ },
3404
+ required: ["fromToken", "toToken", "amount", "chain"]
3405
+ }
3406
+ },
3407
+ "wdk/executeSwap": {
3408
+ name: "wdk/executeSwap",
3409
+ description: "Execute a swap using a quoteId from wdk/quoteSwap. Requires confirmation.",
3410
+ inputSchema: {
3411
+ type: "object",
3412
+ properties: {
3413
+ quoteId: {
3414
+ type: "string",
3415
+ description: "Quote ID from wdk/quoteSwap"
3416
+ },
3417
+ confirmed: {
3418
+ type: "boolean",
3419
+ description: "Set to true to confirm and execute. Omit for a preview/confirmation prompt."
3420
+ }
3421
+ },
3422
+ required: ["quoteId"]
3423
+ }
2368
3424
  }
2369
3425
  };
2370
3426
  var ERC8004_TOOL_DEFINITIONS = {
@@ -2510,6 +3566,40 @@ export {
2510
3566
  erc8004VerifyWalletInputSchema,
2511
3567
  executeErc8004VerifyWallet,
2512
3568
  formatErc8004VerifyWalletResult,
3569
+ getTokenPrices,
3570
+ getTokenPricesDemo,
3571
+ clearPriceCache,
3572
+ getTokenPriceInputSchema,
3573
+ executeGetTokenPrice,
3574
+ formatTokenPriceResult,
3575
+ getGasPriceInputSchema,
3576
+ executeGetGasPrice,
3577
+ formatGasPriceResult,
3578
+ estimatePaymentFeeInputSchema,
3579
+ executeEstimatePaymentFee,
3580
+ formatPaymentFeeEstimate,
3581
+ compareNetworkFeesInputSchema,
3582
+ executeCompareNetworkFees,
3583
+ formatNetworkFeeComparison,
3584
+ createQuote,
3585
+ getQuote,
3586
+ deleteQuote,
3587
+ clearQuoteStore,
3588
+ wdkQuoteSwapInputSchema,
3589
+ executeWdkQuoteSwap,
3590
+ executeWdkQuoteSwapDemo,
3591
+ formatSwapQuoteResult,
3592
+ wdkExecuteSwapInputSchema,
3593
+ executeWdkExecuteSwap,
3594
+ executeWdkExecuteSwapDemo,
3595
+ formatExecuteSwapResult,
3596
+ quoteBridgeInputSchema,
3597
+ executeQuoteBridge,
3598
+ executeQuoteBridgeDemo,
3599
+ formatBridgeQuoteResult,
3600
+ executeBridgeFromQuoteInputSchema,
3601
+ executeExecuteBridgeFromQuote,
3602
+ executeExecuteBridgeFromQuoteDemo,
2513
3603
  smartPayInputSchema,
2514
3604
  paymentPlanInputSchema,
2515
3605
  UNIFIED_TOOL_DEFINITIONS,
@@ -2523,4 +3613,4 @@ export {
2523
3613
  WDK_TOOL_DEFINITIONS,
2524
3614
  ERC8004_TOOL_DEFINITIONS
2525
3615
  };
2526
- //# sourceMappingURL=chunk-B7X7H6NV.mjs.map
3616
+ //# sourceMappingURL=chunk-SUDCVXHQ.mjs.map