@t402/wdk 2.3.0 → 2.4.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.
Files changed (40) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/adapters/index.d.ts +5 -0
  3. package/dist/cjs/adapters/index.js +455 -0
  4. package/dist/cjs/adapters/index.js.map +1 -0
  5. package/dist/cjs/adapters/svm-adapter.d.ts +125 -0
  6. package/dist/cjs/adapters/svm-adapter.js +132 -0
  7. package/dist/cjs/adapters/svm-adapter.js.map +1 -0
  8. package/dist/cjs/adapters/ton-adapter.d.ts +139 -0
  9. package/dist/cjs/adapters/ton-adapter.js +152 -0
  10. package/dist/cjs/adapters/ton-adapter.js.map +1 -0
  11. package/dist/cjs/adapters/tron-adapter.d.ts +139 -0
  12. package/dist/cjs/adapters/tron-adapter.js +221 -0
  13. package/dist/cjs/adapters/tron-adapter.js.map +1 -0
  14. package/dist/cjs/index.d.ts +292 -217
  15. package/dist/cjs/index.js +1042 -23
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/types-V7c-qhn6.d.ts +489 -0
  18. package/dist/esm/adapters/index.d.mts +5 -0
  19. package/dist/esm/adapters/index.mjs +21 -0
  20. package/dist/esm/adapters/index.mjs.map +1 -0
  21. package/dist/esm/adapters/svm-adapter.d.mts +125 -0
  22. package/dist/esm/adapters/svm-adapter.mjs +9 -0
  23. package/dist/esm/adapters/svm-adapter.mjs.map +1 -0
  24. package/dist/esm/adapters/ton-adapter.d.mts +139 -0
  25. package/dist/esm/adapters/ton-adapter.mjs +9 -0
  26. package/dist/esm/adapters/ton-adapter.mjs.map +1 -0
  27. package/dist/esm/adapters/tron-adapter.d.mts +139 -0
  28. package/dist/esm/adapters/tron-adapter.mjs +9 -0
  29. package/dist/esm/adapters/tron-adapter.mjs.map +1 -0
  30. package/dist/esm/chunk-HB2DGKQ3.mjs +196 -0
  31. package/dist/esm/chunk-HB2DGKQ3.mjs.map +1 -0
  32. package/dist/esm/chunk-MCFHZSF7.mjs +107 -0
  33. package/dist/esm/chunk-MCFHZSF7.mjs.map +1 -0
  34. package/dist/esm/chunk-YWBJJV5M.mjs +117 -0
  35. package/dist/esm/chunk-YWBJJV5M.mjs.map +1 -0
  36. package/dist/esm/index.d.mts +292 -217
  37. package/dist/esm/index.mjs +640 -23
  38. package/dist/esm/index.mjs.map +1 -1
  39. package/dist/esm/types-V7c-qhn6.d.mts +489 -0
  40. package/package.json +70 -6
@@ -1,3 +1,16 @@
1
+ import {
2
+ WDKSvmSignerAdapter,
3
+ createWDKSvmSigner
4
+ } from "./chunk-MCFHZSF7.mjs";
5
+ import {
6
+ WDKTonSignerAdapter,
7
+ createWDKTonSigner
8
+ } from "./chunk-YWBJJV5M.mjs";
9
+ import {
10
+ WDKTronSignerAdapter,
11
+ createWDKTronSigner
12
+ } from "./chunk-HB2DGKQ3.mjs";
13
+
1
14
  // src/cache.ts
2
15
  var DEFAULT_CACHE_CONFIG = {
3
16
  defaultTTL: 3e4,
@@ -487,6 +500,11 @@ var DEFAULT_CHAINS = {
487
500
  network: "eip155:130",
488
501
  name: "unichain"
489
502
  },
503
+ optimism: {
504
+ chainId: 10,
505
+ network: "eip155:10",
506
+ name: "optimism"
507
+ },
490
508
  polygon: {
491
509
  chainId: 137,
492
510
  network: "eip155:137",
@@ -498,6 +516,7 @@ var DEFAULT_RPC_ENDPOINTS = {
498
516
  arbitrum: "https://arb1.arbitrum.io/rpc",
499
517
  base: "https://mainnet.base.org",
500
518
  ink: "https://rpc-gel.inkonchain.com",
519
+ optimism: "https://mainnet.optimism.io",
501
520
  polygon: "https://polygon-rpc.com"
502
521
  };
503
522
  var USDT0_ADDRESSES = {
@@ -505,7 +524,7 @@ var USDT0_ADDRESSES = {
505
524
  arbitrum: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
506
525
  ink: "0x0200C29006150606B650577BBE7B6248F58470c1",
507
526
  berachain: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
508
- unichain: "0x588ce4F028D8e7B53B687865d6A67b3A54C75518"
527
+ unichain: "0x9151434b16b9763660705744891fA906F660EcC5"
509
528
  };
510
529
  var USDC_ADDRESSES = {
511
530
  ethereum: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
@@ -684,6 +703,9 @@ var WDKErrorCode = /* @__PURE__ */ ((WDKErrorCode2) => {
684
703
  WDKErrorCode2[WDKErrorCode2["RPC_TIMEOUT"] = 8002] = "RPC_TIMEOUT";
685
704
  WDKErrorCode2[WDKErrorCode2["RPC_RATE_LIMITED"] = 8003] = "RPC_RATE_LIMITED";
686
705
  WDKErrorCode2[WDKErrorCode2["RPC_CONNECTION_FAILED"] = 8004] = "RPC_CONNECTION_FAILED";
706
+ WDKErrorCode2[WDKErrorCode2["PROTOCOL_NOT_REGISTERED"] = 8101] = "PROTOCOL_NOT_REGISTERED";
707
+ WDKErrorCode2[WDKErrorCode2["PROTOCOL_EXECUTION_FAILED"] = 8102] = "PROTOCOL_EXECUTION_FAILED";
708
+ WDKErrorCode2[WDKErrorCode2["INVALID_PARAMETER"] = 8103] = "INVALID_PARAMETER";
687
709
  WDKErrorCode2[WDKErrorCode2["UNKNOWN_ERROR"] = 9999] = "UNKNOWN_ERROR";
688
710
  return WDKErrorCode2;
689
711
  })(WDKErrorCode || {});
@@ -1265,6 +1287,13 @@ var WDKSigner = class {
1265
1287
  }
1266
1288
  try {
1267
1289
  const account = await this.getAccount();
1290
+ if (!account.estimateGas) {
1291
+ throw new TransactionError(
1292
+ 6002 /* GAS_ESTIMATION_FAILED */,
1293
+ `Gas estimation is not supported by this WDK account on ${this._chain}`,
1294
+ { chain: this._chain, context: { to: params.to } }
1295
+ );
1296
+ }
1268
1297
  return await withRetry(async () => {
1269
1298
  const estimatePromise = account.estimateGas({
1270
1299
  to: params.to,
@@ -1369,24 +1398,45 @@ var T402WDK = class _T402WDK {
1369
1398
  static _WDK = null;
1370
1399
  static _WalletManagerEvm = null;
1371
1400
  static _BridgeUsdt0Evm = null;
1401
+ // Multi-chain wallet module storage
1402
+ static _WalletModules = {};
1403
+ static _ProtocolModules = {};
1404
+ // Multi-chain signer caches
1405
+ _tonSignerCache = /* @__PURE__ */ new Map();
1406
+ _svmSignerCache = /* @__PURE__ */ new Map();
1407
+ _tronSignerCache = /* @__PURE__ */ new Map();
1372
1408
  /**
1373
1409
  * Register the Tether WDK modules
1374
1410
  *
1375
1411
  * This must be called before creating T402WDK instances if you want
1376
1412
  * to use the actual WDK. Otherwise, a mock implementation is used.
1377
1413
  *
1378
- * @throws {WDKInitializationError} If registration fails
1414
+ * Supports two registration patterns:
1379
1415
  *
1380
- * @example
1381
- * ```typescript
1382
- * import WDK from '@tetherto/wdk';
1383
- * import WalletManagerEvm from '@tetherto/wdk-wallet-evm';
1384
- * import BridgeUsdt0Evm from '@tetherto/wdk-protocol-bridge-usdt0-evm';
1416
+ * 1. Legacy (EVM-only):
1417
+ * ```typescript
1418
+ * T402WDK.registerWDK(WDK, WalletManagerEvm, BridgeUsdt0Evm);
1419
+ * ```
1385
1420
  *
1386
- * T402WDK.registerWDK(WDK, WalletManagerEvm, BridgeUsdt0Evm);
1387
- * ```
1421
+ * 2. Unified (multi-chain):
1422
+ * ```typescript
1423
+ * T402WDK.registerWDK(WDK, {
1424
+ * wallets: {
1425
+ * evm: WalletManagerEvm,
1426
+ * ton: WalletManagerTon,
1427
+ * solana: WalletManagerSolana,
1428
+ * tron: WalletManagerTron,
1429
+ * },
1430
+ * protocols: {
1431
+ * bridgeUsdt0Evm: BridgeUsdt0Evm,
1432
+ * bridgeUsdt0Ton: BridgeUsdt0Ton,
1433
+ * }
1434
+ * });
1435
+ * ```
1436
+ *
1437
+ * @throws {WDKInitializationError} If registration fails
1388
1438
  */
1389
- static registerWDK(WDK, WalletManagerEvm, BridgeUsdt0Evm) {
1439
+ static registerWDK(WDK, modulesOrWalletManager, BridgeUsdt0Evm) {
1390
1440
  if (!WDK) {
1391
1441
  throw new WDKInitializationError("WDK constructor is required");
1392
1442
  }
@@ -1394,8 +1444,18 @@ var T402WDK = class _T402WDK {
1394
1444
  throw new WDKInitializationError("WDK must be a constructor function");
1395
1445
  }
1396
1446
  _T402WDK._WDK = WDK;
1397
- _T402WDK._WalletManagerEvm = WalletManagerEvm ?? null;
1398
- _T402WDK._BridgeUsdt0Evm = BridgeUsdt0Evm ?? null;
1447
+ if (modulesOrWalletManager && typeof modulesOrWalletManager === "object" && ("wallets" in modulesOrWalletManager || "protocols" in modulesOrWalletManager)) {
1448
+ const modules = modulesOrWalletManager;
1449
+ _T402WDK._WalletModules = modules.wallets ?? {};
1450
+ _T402WDK._ProtocolModules = modules.protocols ?? {};
1451
+ _T402WDK._WalletManagerEvm = modules.wallets?.evm ?? null;
1452
+ _T402WDK._BridgeUsdt0Evm = modules.protocols?.bridgeUsdt0Evm ?? null;
1453
+ } else {
1454
+ _T402WDK._WalletManagerEvm = modulesOrWalletManager ?? null;
1455
+ _T402WDK._BridgeUsdt0Evm = BridgeUsdt0Evm ?? null;
1456
+ _T402WDK._WalletModules = { evm: modulesOrWalletManager };
1457
+ _T402WDK._ProtocolModules = { bridgeUsdt0Evm: BridgeUsdt0Evm };
1458
+ }
1399
1459
  }
1400
1460
  /**
1401
1461
  * Check if WDK is registered
@@ -1415,6 +1475,40 @@ var T402WDK = class _T402WDK {
1415
1475
  static isBridgeRegistered() {
1416
1476
  return _T402WDK._BridgeUsdt0Evm !== null;
1417
1477
  }
1478
+ /**
1479
+ * Check if TON wallet manager is registered
1480
+ */
1481
+ static isTonRegistered() {
1482
+ return _T402WDK._WalletModules.ton !== void 0;
1483
+ }
1484
+ /**
1485
+ * Check if Solana wallet manager is registered
1486
+ */
1487
+ static isSolanaRegistered() {
1488
+ return _T402WDK._WalletModules.solana !== void 0;
1489
+ }
1490
+ /**
1491
+ * Check if TRON wallet manager is registered
1492
+ */
1493
+ static isTronRegistered() {
1494
+ return _T402WDK._WalletModules.tron !== void 0;
1495
+ }
1496
+ /**
1497
+ * Get all registered wallet modules
1498
+ */
1499
+ static getRegisteredWalletModules() {
1500
+ return Object.keys(_T402WDK._WalletModules).filter(
1501
+ (key) => _T402WDK._WalletModules[key] !== void 0
1502
+ );
1503
+ }
1504
+ /**
1505
+ * Get all registered protocol modules
1506
+ */
1507
+ static getRegisteredProtocolModules() {
1508
+ return Object.keys(_T402WDK._ProtocolModules).filter(
1509
+ (key) => _T402WDK._ProtocolModules[key] !== void 0
1510
+ );
1511
+ }
1418
1512
  /**
1419
1513
  * Generate a new random seed phrase
1420
1514
  *
@@ -1436,6 +1530,124 @@ var T402WDK = class _T402WDK {
1436
1530
  );
1437
1531
  }
1438
1532
  }
1533
+ /**
1534
+ * Quick setup: seed phrase + chains + modules → ready-to-use T402WDK.
1535
+ *
1536
+ * Registers all provided wallet/protocol modules and creates a fully
1537
+ * configured instance in a single call.
1538
+ *
1539
+ * @example
1540
+ * ```typescript
1541
+ * import WDK from '@tetherto/wdk';
1542
+ * import WalletManagerEvm from '@tetherto/wdk-wallet-evm';
1543
+ * import BridgeUsdt0Evm from '@tetherto/wdk-protocol-bridge-usdt0-evm';
1544
+ *
1545
+ * const wallet = T402WDK.create({
1546
+ * seedPhrase: 'your twelve word seed phrase ...',
1547
+ * chains: {
1548
+ * arbitrum: 'https://arb1.arbitrum.io/rpc',
1549
+ * base: 'https://mainnet.base.org',
1550
+ * },
1551
+ * modules: {
1552
+ * wallets: { evm: WalletManagerEvm },
1553
+ * protocols: { bridgeUsdt0Evm: BridgeUsdt0Evm },
1554
+ * },
1555
+ * });
1556
+ * ```
1557
+ */
1558
+ static create(WDK, config) {
1559
+ _T402WDK.registerWDK(WDK, config.modules);
1560
+ return new _T402WDK(config.seedPhrase, config.chains, config.options);
1561
+ }
1562
+ /**
1563
+ * Create a T402WDK from a pre-configured @tetherto/wdk instance.
1564
+ *
1565
+ * Wraps an existing WDK instance (already has wallets/protocols registered)
1566
+ * into a T402WDK without re-registering modules.
1567
+ *
1568
+ * @param wdkInstance - A pre-configured WDK instance
1569
+ * @param config - EVM chain configuration (RPC endpoints)
1570
+ * @param options - Additional options
1571
+ */
1572
+ static fromWDK(wdkInstance, config = {}, options) {
1573
+ if (!wdkInstance) {
1574
+ throw new WDKInitializationError("WDK instance is required");
1575
+ }
1576
+ const instance = new _T402WDK("__from_wdk__", config, options);
1577
+ instance._wdk = wdkInstance;
1578
+ instance._initializationError = null;
1579
+ return instance;
1580
+ }
1581
+ /**
1582
+ * Get all signers as an array ready for T402 HTTP clients.
1583
+ *
1584
+ * Returns signer entries for all configured EVM chains, plus any
1585
+ * registered non-EVM chains (TON, Solana, TRON).
1586
+ *
1587
+ * @example
1588
+ * ```typescript
1589
+ * const signers = await wallet.getAllSigners();
1590
+ * const client = createT402HTTPClient({ signers });
1591
+ * ```
1592
+ */
1593
+ async getAllSigners(options) {
1594
+ const accountIndex = options?.accountIndex ?? 0;
1595
+ const schemes = options?.schemes ?? ["exact"];
1596
+ const includeNonEvm = options?.includeNonEvm ?? true;
1597
+ const entries = [];
1598
+ for (const chain of this.getConfiguredChains()) {
1599
+ const config = this._normalizedChains.get(chain);
1600
+ if (!config) continue;
1601
+ try {
1602
+ const signer = await this.getSigner(chain, accountIndex);
1603
+ for (const scheme of schemes) {
1604
+ entries.push({
1605
+ scheme,
1606
+ network: config.network,
1607
+ signer,
1608
+ family: "evm"
1609
+ });
1610
+ }
1611
+ } catch {
1612
+ }
1613
+ }
1614
+ if (!includeNonEvm) {
1615
+ return entries;
1616
+ }
1617
+ if (_T402WDK.isTonRegistered()) {
1618
+ try {
1619
+ const signer = await this.getTonSigner(accountIndex);
1620
+ for (const scheme of schemes) {
1621
+ entries.push({ scheme, network: "ton:mainnet", signer, family: "ton" });
1622
+ }
1623
+ } catch {
1624
+ }
1625
+ }
1626
+ if (_T402WDK.isSolanaRegistered()) {
1627
+ try {
1628
+ const signer = await this.getSvmSigner(accountIndex);
1629
+ for (const scheme of schemes) {
1630
+ entries.push({
1631
+ scheme,
1632
+ network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
1633
+ signer,
1634
+ family: "svm"
1635
+ });
1636
+ }
1637
+ } catch {
1638
+ }
1639
+ }
1640
+ if (_T402WDK.isTronRegistered()) {
1641
+ try {
1642
+ const signer = await this.getTronSigner(accountIndex);
1643
+ for (const scheme of schemes) {
1644
+ entries.push({ scheme, network: "tron:mainnet", signer, family: "tron" });
1645
+ }
1646
+ } catch {
1647
+ }
1648
+ }
1649
+ return entries;
1650
+ }
1439
1651
  /**
1440
1652
  * Create a new T402WDK instance
1441
1653
  *
@@ -1445,16 +1657,19 @@ var T402WDK = class _T402WDK {
1445
1657
  * @throws {WDKInitializationError} If seed phrase is invalid
1446
1658
  */
1447
1659
  constructor(seedPhrase, config = {}, options = {}) {
1448
- if (!seedPhrase || typeof seedPhrase !== "string") {
1449
- throw new WDKInitializationError("Seed phrase is required and must be a string");
1450
- }
1451
- const words = seedPhrase.trim().split(/\s+/);
1452
- const validWordCounts = [12, 15, 18, 21, 24];
1453
- if (!validWordCounts.includes(words.length)) {
1454
- throw new WDKInitializationError(
1455
- `Invalid seed phrase: expected 12, 15, 18, 21, or 24 words, got ${words.length}`,
1456
- { context: { wordCount: words.length } }
1457
- );
1660
+ const isFromWDK = seedPhrase === "__from_wdk__";
1661
+ if (!isFromWDK) {
1662
+ if (!seedPhrase || typeof seedPhrase !== "string") {
1663
+ throw new WDKInitializationError("Seed phrase is required and must be a string");
1664
+ }
1665
+ const words = seedPhrase.trim().split(/\s+/);
1666
+ const validWordCounts = [12, 15, 18, 21, 24];
1667
+ if (!validWordCounts.includes(words.length)) {
1668
+ throw new WDKInitializationError(
1669
+ `Invalid seed phrase: expected 12, 15, 18, 21, or 24 words, got ${words.length}`,
1670
+ { context: { wordCount: words.length } }
1671
+ );
1672
+ }
1458
1673
  }
1459
1674
  this._seedPhrase = seedPhrase;
1460
1675
  this._balanceCache = new BalanceCache(options.cache);
@@ -1472,7 +1687,7 @@ var T402WDK = class _T402WDK {
1472
1687
  }
1473
1688
  }
1474
1689
  this._addDefaultChainsIfNeeded();
1475
- if (_T402WDK._WDK) {
1690
+ if (!isFromWDK && _T402WDK._WDK) {
1476
1691
  this._initializeWDK();
1477
1692
  }
1478
1693
  }
@@ -1634,6 +1849,195 @@ var T402WDK = class _T402WDK {
1634
1849
  */
1635
1850
  clearSignerCache() {
1636
1851
  this._signerCache.clear();
1852
+ this._tonSignerCache.clear();
1853
+ this._svmSignerCache.clear();
1854
+ this._tronSignerCache.clear();
1855
+ }
1856
+ // ========== Multi-Chain Signers ==========
1857
+ /**
1858
+ * Get a TON signer for T402 payments
1859
+ *
1860
+ * @param accountIndex - HD wallet account index (default: 0)
1861
+ * @throws {ChainError} If TON wallet manager is not registered
1862
+ * @returns An initialized ClientTonSigner
1863
+ *
1864
+ * @example
1865
+ * ```typescript
1866
+ * const tonSigner = await wallet.getTonSigner();
1867
+ *
1868
+ * const client = createT402HTTPClient({
1869
+ * signers: [{ scheme: 'exact', network: 'ton:mainnet', signer: tonSigner }]
1870
+ * });
1871
+ * ```
1872
+ */
1873
+ async getTonSigner(accountIndex = 0) {
1874
+ const cached = this._tonSignerCache.get(accountIndex);
1875
+ if (cached) {
1876
+ return cached;
1877
+ }
1878
+ if (!_T402WDK._WalletModules.ton) {
1879
+ throw new ChainError(
1880
+ 2002 /* CHAIN_NOT_SUPPORTED */,
1881
+ "TON wallet manager not registered. Call T402WDK.registerWDK(WDK, { wallets: { ton: WalletManagerTon } }).",
1882
+ { chain: "ton" }
1883
+ );
1884
+ }
1885
+ try {
1886
+ const account = await this.wdk.getAccount("ton", accountIndex);
1887
+ const signer = await createWDKTonSigner(account);
1888
+ this._tonSignerCache.set(accountIndex, signer);
1889
+ return signer;
1890
+ } catch (error) {
1891
+ if (isWDKError(error)) {
1892
+ throw error;
1893
+ }
1894
+ throw wrapError(error, 3001 /* SIGNER_NOT_INITIALIZED */, "Failed to create TON signer", {
1895
+ chain: "ton",
1896
+ accountIndex
1897
+ });
1898
+ }
1899
+ }
1900
+ /**
1901
+ * Get a Solana (SVM) signer for T402 payments
1902
+ *
1903
+ * @param accountIndex - HD wallet account index (default: 0)
1904
+ * @throws {ChainError} If Solana wallet manager is not registered
1905
+ * @returns An initialized TransactionSigner (ClientSvmSigner)
1906
+ *
1907
+ * @example
1908
+ * ```typescript
1909
+ * const svmSigner = await wallet.getSvmSigner();
1910
+ *
1911
+ * const client = createT402HTTPClient({
1912
+ * signers: [{ scheme: 'exact', network: 'solana:mainnet', signer: svmSigner }]
1913
+ * });
1914
+ * ```
1915
+ */
1916
+ async getSvmSigner(accountIndex = 0) {
1917
+ const cached = this._svmSignerCache.get(accountIndex);
1918
+ if (cached) {
1919
+ return cached;
1920
+ }
1921
+ if (!_T402WDK._WalletModules.solana) {
1922
+ throw new ChainError(
1923
+ 2002 /* CHAIN_NOT_SUPPORTED */,
1924
+ "Solana wallet manager not registered. Call T402WDK.registerWDK(WDK, { wallets: { solana: WalletManagerSolana } }).",
1925
+ { chain: "solana" }
1926
+ );
1927
+ }
1928
+ try {
1929
+ const account = await this.wdk.getAccount(
1930
+ "solana",
1931
+ accountIndex
1932
+ );
1933
+ const signer = await createWDKSvmSigner(account);
1934
+ this._svmSignerCache.set(accountIndex, signer);
1935
+ return signer;
1936
+ } catch (error) {
1937
+ if (isWDKError(error)) {
1938
+ throw error;
1939
+ }
1940
+ throw wrapError(
1941
+ error,
1942
+ 3001 /* SIGNER_NOT_INITIALIZED */,
1943
+ "Failed to create Solana signer",
1944
+ { chain: "solana", accountIndex }
1945
+ );
1946
+ }
1947
+ }
1948
+ /**
1949
+ * Get a TRON signer for T402 payments
1950
+ *
1951
+ * @param accountIndex - HD wallet account index (default: 0)
1952
+ * @param rpcUrl - Optional custom RPC URL (default: https://api.trongrid.io)
1953
+ * @throws {ChainError} If TRON wallet manager is not registered
1954
+ * @returns An initialized ClientTronSigner
1955
+ *
1956
+ * @example
1957
+ * ```typescript
1958
+ * const tronSigner = await wallet.getTronSigner();
1959
+ *
1960
+ * const client = createT402HTTPClient({
1961
+ * signers: [{ scheme: 'exact', network: 'tron:mainnet', signer: tronSigner }]
1962
+ * });
1963
+ * ```
1964
+ */
1965
+ async getTronSigner(accountIndex = 0, rpcUrl) {
1966
+ if (!rpcUrl) {
1967
+ const cached = this._tronSignerCache.get(accountIndex);
1968
+ if (cached) {
1969
+ return cached;
1970
+ }
1971
+ }
1972
+ if (!_T402WDK._WalletModules.tron) {
1973
+ throw new ChainError(
1974
+ 2002 /* CHAIN_NOT_SUPPORTED */,
1975
+ "TRON wallet manager not registered. Call T402WDK.registerWDK(WDK, { wallets: { tron: WalletManagerTron } }).",
1976
+ { chain: "tron" }
1977
+ );
1978
+ }
1979
+ try {
1980
+ const account = await this.wdk.getAccount("tron", accountIndex);
1981
+ const signer = await createWDKTronSigner(account, rpcUrl);
1982
+ if (!rpcUrl) {
1983
+ this._tronSignerCache.set(accountIndex, signer);
1984
+ }
1985
+ return signer;
1986
+ } catch (error) {
1987
+ if (isWDKError(error)) {
1988
+ throw error;
1989
+ }
1990
+ throw wrapError(error, 3001 /* SIGNER_NOT_INITIALIZED */, "Failed to create TRON signer", {
1991
+ chain: "tron",
1992
+ accountIndex
1993
+ });
1994
+ }
1995
+ }
1996
+ /**
1997
+ * Get a signer for a specific chain family
1998
+ *
1999
+ * @param family - Chain family (evm, svm, ton, tron)
2000
+ * @param chainOrIndex - Chain name for EVM, or account index for others
2001
+ * @param accountIndex - Account index (only used for EVM)
2002
+ * @throws {ChainError} If chain family is not supported or not configured
2003
+ * @returns An appropriate signer for the chain family
2004
+ *
2005
+ * @example
2006
+ * ```typescript
2007
+ * // Get EVM signer for Arbitrum
2008
+ * const evmSigner = await wallet.getSignerByFamily('evm', 'arbitrum');
2009
+ *
2010
+ * // Get TON signer
2011
+ * const tonSigner = await wallet.getSignerByFamily('ton');
2012
+ *
2013
+ * // Get Solana signer with account index 1
2014
+ * const svmSigner = await wallet.getSignerByFamily('svm', 1);
2015
+ * ```
2016
+ */
2017
+ async getSignerByFamily(family, chainOrIndex, accountIndex = 0) {
2018
+ switch (family) {
2019
+ case "evm":
2020
+ if (typeof chainOrIndex !== "string") {
2021
+ throw new ChainError(
2022
+ 2003 /* INVALID_CHAIN_CONFIG */,
2023
+ 'EVM signers require a chain name (e.g., "arbitrum", "ethereum")',
2024
+ { chain: family }
2025
+ );
2026
+ }
2027
+ return this.getSigner(chainOrIndex, accountIndex);
2028
+ case "ton":
2029
+ return this.getTonSigner(typeof chainOrIndex === "number" ? chainOrIndex : accountIndex);
2030
+ case "svm":
2031
+ return this.getSvmSigner(typeof chainOrIndex === "number" ? chainOrIndex : accountIndex);
2032
+ case "tron":
2033
+ return this.getTronSigner(typeof chainOrIndex === "number" ? chainOrIndex : accountIndex);
2034
+ default:
2035
+ throw new ChainError(
2036
+ 2002 /* CHAIN_NOT_SUPPORTED */,
2037
+ `Chain family "${family}" is not supported. Available: evm, ton, svm, tron`,
2038
+ { chain: family }
2039
+ );
2040
+ }
1637
2041
  }
1638
2042
  /**
1639
2043
  * Get wallet address for a chain
@@ -1981,6 +2385,118 @@ var T402WDK = class _T402WDK {
1981
2385
  }
1982
2386
  return getBridgeableChains().filter((chain) => chain !== fromChain);
1983
2387
  }
2388
+ // ========== Swap Protocol ==========
2389
+ /**
2390
+ * Check if the Velora swap protocol is registered and available
2391
+ */
2392
+ canSwap() {
2393
+ return _T402WDK._ProtocolModules.swapVeloraEvm !== void 0;
2394
+ }
2395
+ /**
2396
+ * Get a swap quote for converting a token to USDT0
2397
+ *
2398
+ * @param chain - Chain name (e.g., "ethereum", "arbitrum")
2399
+ * @param fromToken - Input token address
2400
+ * @param amount - Amount to swap in smallest units
2401
+ * @throws {WDKError} If swap protocol is not registered or quote fails
2402
+ */
2403
+ async getSwapQuote(chain, fromToken, amount) {
2404
+ if (!this.canSwap()) {
2405
+ throw new WDKError(
2406
+ 8101 /* PROTOCOL_NOT_REGISTERED */,
2407
+ "Velora swap protocol not registered. Call T402WDK.registerWDK(WDK, { protocols: { swapVeloraEvm: SwapVeloraEvm } })."
2408
+ );
2409
+ }
2410
+ const usdt0Address = USDT0_ADDRESSES[chain];
2411
+ if (!usdt0Address) {
2412
+ throw new ChainError(
2413
+ 2002 /* CHAIN_NOT_SUPPORTED */,
2414
+ `Chain "${chain}" does not have a known USDT0 address`,
2415
+ { chain }
2416
+ );
2417
+ }
2418
+ try {
2419
+ const result = await this.wdk.executeProtocol("swap-velora", {
2420
+ action: "quote",
2421
+ chain,
2422
+ fromToken,
2423
+ toToken: usdt0Address,
2424
+ amount: amount.toString()
2425
+ });
2426
+ return result;
2427
+ } catch (error) {
2428
+ throw wrapError(
2429
+ error,
2430
+ 8102 /* PROTOCOL_EXECUTION_FAILED */,
2431
+ `Failed to get swap quote on ${chain}`,
2432
+ { chain, fromToken, amount: amount.toString() }
2433
+ );
2434
+ }
2435
+ }
2436
+ /**
2437
+ * Swap any token to USDT0 for payment
2438
+ *
2439
+ * Uses the Velora protocol to execute a token swap on the specified chain.
2440
+ *
2441
+ * @param params - Swap parameters
2442
+ * @throws {WDKError} If swap protocol is not registered or swap fails
2443
+ *
2444
+ * @example
2445
+ * ```typescript
2446
+ * // Swap 0.1 WETH to USDT0 on Arbitrum
2447
+ * const result = await wallet.swapAndPay({
2448
+ * chain: 'arbitrum',
2449
+ * fromToken: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', // WETH
2450
+ * amount: 100000000000000000n, // 0.1 WETH
2451
+ * maxSlippage: 0.005,
2452
+ * });
2453
+ * ```
2454
+ */
2455
+ async swapAndPay(params) {
2456
+ if (!this.canSwap()) {
2457
+ throw new WDKError(
2458
+ 8101 /* PROTOCOL_NOT_REGISTERED */,
2459
+ "Velora swap protocol not registered. Call T402WDK.registerWDK(WDK, { protocols: { swapVeloraEvm: SwapVeloraEvm } })."
2460
+ );
2461
+ }
2462
+ const usdt0Address = USDT0_ADDRESSES[params.chain];
2463
+ if (!usdt0Address) {
2464
+ throw new ChainError(
2465
+ 2002 /* CHAIN_NOT_SUPPORTED */,
2466
+ `Chain "${params.chain}" does not have a known USDT0 address`,
2467
+ { chain: params.chain }
2468
+ );
2469
+ }
2470
+ if (params.maxSlippage !== void 0 && (params.maxSlippage < 0 || params.maxSlippage > 0.5)) {
2471
+ throw new WDKError(
2472
+ 8103 /* INVALID_PARAMETER */,
2473
+ "maxSlippage must be between 0 and 0.5 (0% to 50%)"
2474
+ );
2475
+ }
2476
+ try {
2477
+ const result = await this.wdk.executeProtocol("swap-velora", {
2478
+ action: "swap",
2479
+ chain: params.chain,
2480
+ fromToken: params.fromToken,
2481
+ toToken: usdt0Address,
2482
+ amount: params.amount.toString(),
2483
+ maxSlippage: params.maxSlippage ?? 5e-3
2484
+ });
2485
+ this._balanceCache.invalidateChain(params.chain);
2486
+ return result;
2487
+ } catch (error) {
2488
+ throw wrapError(
2489
+ error,
2490
+ 8102 /* PROTOCOL_EXECUTION_FAILED */,
2491
+ `Failed to execute swap on ${params.chain}`,
2492
+ {
2493
+ chain: params.chain,
2494
+ fromToken: params.fromToken,
2495
+ amount: params.amount.toString()
2496
+ }
2497
+ );
2498
+ }
2499
+ }
1984
2500
  // ========== Cache Management ==========
1985
2501
  /**
1986
2502
  * Check if balance caching is enabled
@@ -2034,6 +2550,9 @@ var T402WDK = class _T402WDK {
2034
2550
  dispose() {
2035
2551
  this._balanceCache.dispose();
2036
2552
  this._signerCache.clear();
2553
+ this._tonSignerCache.clear();
2554
+ this._svmSignerCache.clear();
2555
+ this._tronSignerCache.clear();
2037
2556
  }
2038
2557
  };
2039
2558
  function formatTokenAmount(amount, decimals) {
@@ -2123,6 +2642,94 @@ import {
2123
2642
  Usdt0Bridge as Usdt0Bridge2
2124
2643
  } from "@t402/evm";
2125
2644
 
2645
+ // src/compatibility.ts
2646
+ var WDK_COMPATIBILITY = {
2647
+ /** Minimum supported @tetherto/wdk version */
2648
+ minVersion: "1.0.0-beta.0",
2649
+ /** Versions that have been tested */
2650
+ testedVersions: ["1.0.0-beta.3", "1.0.0-beta.4", "1.0.0-beta.5"],
2651
+ /** Tested wallet-evm module versions */
2652
+ walletEvmVersions: ["1.0.0-beta.5", "2.0.0-rc.1"],
2653
+ /** Feature availability by @tetherto/wdk core version */
2654
+ features: {
2655
+ signTypedData: "1.0.0-beta.0",
2656
+ estimateGas: "1.0.0-beta.3",
2657
+ multiChainWallets: "1.0.0-beta.0",
2658
+ bridgeProtocol: "1.0.0-beta.3",
2659
+ swapProtocol: "1.0.0-beta.4"
2660
+ },
2661
+ /** Known wallet module minimum versions */
2662
+ walletModuleVersions: {
2663
+ evm: "1.0.0-beta.5",
2664
+ ton: "1.0.0-beta.7",
2665
+ btc: "1.0.0-beta.5",
2666
+ tron: "1.0.0-beta.4",
2667
+ solana: "1.0.0-beta.5",
2668
+ spark: "1.0.0-beta.6"
2669
+ }
2670
+ };
2671
+ function parseVersion(version) {
2672
+ const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
2673
+ if (!match) {
2674
+ return { major: 0, minor: 0, patch: 0, prerelease: "" };
2675
+ }
2676
+ return {
2677
+ major: parseInt(match[1], 10),
2678
+ minor: parseInt(match[2], 10),
2679
+ patch: parseInt(match[3], 10),
2680
+ prerelease: match[4] ?? ""
2681
+ };
2682
+ }
2683
+ function compareVersions(a, b) {
2684
+ const va = parseVersion(a);
2685
+ const vb = parseVersion(b);
2686
+ if (va.major !== vb.major) return va.major < vb.major ? -1 : 1;
2687
+ if (va.minor !== vb.minor) return va.minor < vb.minor ? -1 : 1;
2688
+ if (va.patch !== vb.patch) return va.patch < vb.patch ? -1 : 1;
2689
+ if (va.prerelease && !vb.prerelease) return -1;
2690
+ if (!va.prerelease && vb.prerelease) return 1;
2691
+ if (va.prerelease && vb.prerelease) {
2692
+ return va.prerelease < vb.prerelease ? -1 : va.prerelease > vb.prerelease ? 1 : 0;
2693
+ }
2694
+ return 0;
2695
+ }
2696
+ function checkWdkCompatibility(version) {
2697
+ const warnings = [];
2698
+ if (compareVersions(version, WDK_COMPATIBILITY.minVersion) < 0) {
2699
+ return {
2700
+ compatible: false,
2701
+ warnings: [
2702
+ `@tetherto/wdk ${version} is below minimum supported version ${WDK_COMPATIBILITY.minVersion}`
2703
+ ]
2704
+ };
2705
+ }
2706
+ const isTested = WDK_COMPATIBILITY.testedVersions.includes(version);
2707
+ if (!isTested) {
2708
+ warnings.push(
2709
+ `@tetherto/wdk ${version} has not been explicitly tested. Tested versions: ${WDK_COMPATIBILITY.testedVersions.join(", ")}`
2710
+ );
2711
+ }
2712
+ for (const [feature, minFeatureVersion] of Object.entries(WDK_COMPATIBILITY.features)) {
2713
+ if (compareVersions(version, minFeatureVersion) < 0) {
2714
+ warnings.push(`Feature '${feature}' requires @tetherto/wdk >= ${minFeatureVersion}`);
2715
+ }
2716
+ }
2717
+ return { compatible: true, warnings };
2718
+ }
2719
+ function checkWalletEvmCompatibility(version) {
2720
+ const warnings = [];
2721
+ const isTested = WDK_COMPATIBILITY.walletEvmVersions.includes(version);
2722
+ if (!isTested) {
2723
+ warnings.push(
2724
+ `@tetherto/wdk-wallet-evm ${version} has not been explicitly tested. Tested versions: ${WDK_COMPATIBILITY.walletEvmVersions.join(", ")}`
2725
+ );
2726
+ }
2727
+ return { compatible: true, warnings };
2728
+ }
2729
+ function getWalletModuleMinVersion(module) {
2730
+ return WDK_COMPATIBILITY.walletModuleVersions[module];
2731
+ }
2732
+
2126
2733
  // src/hardware/types.ts
2127
2734
  var HardwareWalletErrorCode = /* @__PURE__ */ ((HardwareWalletErrorCode2) => {
2128
2735
  HardwareWalletErrorCode2["DEVICE_NOT_FOUND"] = "DEVICE_NOT_FOUND";
@@ -2777,11 +3384,20 @@ export {
2777
3384
  WDKErrorCode,
2778
3385
  WDKInitializationError,
2779
3386
  WDKSigner,
3387
+ WDKSvmSignerAdapter,
3388
+ WDKTonSignerAdapter,
3389
+ WDKTronSignerAdapter,
3390
+ WDK_COMPATIBILITY,
2780
3391
  WdkBridge,
3392
+ checkWalletEvmCompatibility,
3393
+ checkWdkCompatibility,
2781
3394
  createDirectBridge,
2782
3395
  createLedgerSigner,
2783
3396
  createTrezorSigner,
2784
3397
  createWDKSigner,
3398
+ createWDKSvmSigner,
3399
+ createWDKTonSigner,
3400
+ createWDKTronSigner,
2785
3401
  detectHardwareWalletSupport,
2786
3402
  getBridgeableChains3 as getBridgeableChains,
2787
3403
  getChainFromNetwork,
@@ -2789,6 +3405,7 @@ export {
2789
3405
  getNetworkFromChain,
2790
3406
  getPreferredToken,
2791
3407
  getUsdt0Chains,
3408
+ getWalletModuleMinVersion,
2792
3409
  hasErrorCode,
2793
3410
  isHardwareWalletSupported,
2794
3411
  isWDKError,