@t402/wdk 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/adapters/index.d.ts +198 -1
  2. package/dist/cjs/adapters/index.js +255 -0
  3. package/dist/cjs/adapters/index.js.map +1 -1
  4. package/dist/cjs/adapters/svm-adapter.d.ts +146 -2
  5. package/dist/cjs/adapters/svm-adapter.js +255 -2
  6. package/dist/cjs/adapters/svm-adapter.js.map +1 -1
  7. package/dist/cjs/adapters/ton-adapter.d.ts +57 -2
  8. package/dist/cjs/adapters/ton-adapter.js +75 -2
  9. package/dist/cjs/adapters/ton-adapter.js.map +1 -1
  10. package/dist/cjs/adapters/tron-adapter.d.ts +57 -2
  11. package/dist/cjs/adapters/tron-adapter.js +101 -0
  12. package/dist/cjs/adapters/tron-adapter.js.map +1 -1
  13. package/dist/cjs/index-DnEI5M6d.d.ts +1798 -0
  14. package/dist/cjs/index.d.ts +702 -1118
  15. package/dist/cjs/index.js +3905 -246
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/cjs/integrations/index.d.ts +9 -0
  18. package/dist/cjs/integrations/index.js +249 -0
  19. package/dist/cjs/integrations/index.js.map +1 -0
  20. package/dist/cjs/testing/index.d.ts +62 -0
  21. package/dist/cjs/testing/index.js +129 -0
  22. package/dist/cjs/testing/index.js.map +1 -0
  23. package/dist/cjs/types-BwK8Xgvg.d.ts +967 -0
  24. package/dist/esm/adapters/index.d.mts +198 -1
  25. package/dist/esm/adapters/index.mjs +14 -3
  26. package/dist/esm/adapters/svm-adapter.d.mts +146 -2
  27. package/dist/esm/adapters/svm-adapter.mjs +18 -3
  28. package/dist/esm/adapters/ton-adapter.d.mts +57 -2
  29. package/dist/esm/adapters/ton-adapter.mjs +8 -3
  30. package/dist/esm/adapters/tron-adapter.d.mts +57 -2
  31. package/dist/esm/adapters/tron-adapter.mjs +2 -1
  32. package/dist/esm/chunk-2KWVW77U.mjs +353 -0
  33. package/dist/esm/chunk-2KWVW77U.mjs.map +1 -0
  34. package/dist/esm/chunk-7CG77QAN.mjs +153 -0
  35. package/dist/esm/chunk-7CG77QAN.mjs.map +1 -0
  36. package/dist/esm/chunk-BJTO5JO5.mjs +11 -0
  37. package/dist/esm/chunk-BJTO5JO5.mjs.map +1 -0
  38. package/dist/esm/{chunk-YWBJJV5M.mjs → chunk-KWX6CJIH.mjs} +72 -1
  39. package/dist/esm/chunk-KWX6CJIH.mjs.map +1 -0
  40. package/dist/esm/{chunk-HB2DGKQ3.mjs → chunk-QZKUU2O6.mjs} +102 -1
  41. package/dist/esm/chunk-QZKUU2O6.mjs.map +1 -0
  42. package/dist/esm/chunk-TVSNUSFZ.mjs +219 -0
  43. package/dist/esm/chunk-TVSNUSFZ.mjs.map +1 -0
  44. package/dist/esm/index-D5kvtDfm.d.mts +1798 -0
  45. package/dist/esm/index.d.mts +702 -1118
  46. package/dist/esm/index.mjs +2934 -70
  47. package/dist/esm/index.mjs.map +1 -1
  48. package/dist/esm/integrations/index.d.mts +9 -0
  49. package/dist/esm/integrations/index.mjs +16 -0
  50. package/dist/esm/integrations/index.mjs.map +1 -0
  51. package/dist/esm/testing/index.d.mts +62 -0
  52. package/dist/esm/testing/index.mjs +101 -0
  53. package/dist/esm/testing/index.mjs.map +1 -0
  54. package/dist/esm/types-BwK8Xgvg.d.mts +967 -0
  55. package/package.json +69 -20
  56. package/dist/cjs/types-V7c-qhn6.d.ts +0 -489
  57. package/dist/esm/chunk-HB2DGKQ3.mjs.map +0 -1
  58. package/dist/esm/chunk-MCFHZSF7.mjs +0 -107
  59. package/dist/esm/chunk-MCFHZSF7.mjs.map +0 -1
  60. package/dist/esm/chunk-YWBJJV5M.mjs.map +0 -1
  61. package/dist/esm/types-V7c-qhn6.d.mts +0 -489
@@ -0,0 +1,967 @@
1
+ import { Address } from 'viem';
2
+
3
+ /**
4
+ * Structured logging for @t402/wdk
5
+ *
6
+ * Provides a pluggable logger interface with console and noop implementations.
7
+ */
8
+ /**
9
+ * Logger interface for T402 WDK operations.
10
+ *
11
+ * Accepts an optional context object for structured metadata.
12
+ */
13
+ interface T402Logger {
14
+ debug(msg: string, ctx?: Record<string, unknown>): void;
15
+ info(msg: string, ctx?: Record<string, unknown>): void;
16
+ warn(msg: string, ctx?: Record<string, unknown>): void;
17
+ error(msg: string, ctx?: Record<string, unknown>): void;
18
+ }
19
+ /**
20
+ * Console-based logger that outputs structured JSON context.
21
+ */
22
+ declare const defaultLogger: T402Logger;
23
+ /**
24
+ * Silent logger that discards all messages.
25
+ */
26
+ declare const noopLogger: T402Logger;
27
+ /**
28
+ * Create a correlation ID for tracing operations across calls.
29
+ *
30
+ * Returns a compact random hex string suitable for log correlation.
31
+ */
32
+ declare function createCorrelationId(): string;
33
+ /**
34
+ * Metric callback signature for observability hooks.
35
+ */
36
+ type MetricCallback = (name: string, value: number, tags?: Record<string, string>) => void;
37
+
38
+ /**
39
+ * Error classes for T402 WDK integration
40
+ *
41
+ * Provides structured error handling with error codes for
42
+ * programmatic error handling and debugging.
43
+ */
44
+ /**
45
+ * Error codes for WDK operations
46
+ */
47
+ declare enum WDKErrorCode {
48
+ WDK_NOT_REGISTERED = 1001,
49
+ WDK_NOT_INITIALIZED = 1002,
50
+ INVALID_SEED_PHRASE = 1003,
51
+ WALLET_MANAGER_NOT_REGISTERED = 1004,
52
+ CHAIN_NOT_CONFIGURED = 2001,
53
+ CHAIN_NOT_SUPPORTED = 2002,
54
+ INVALID_CHAIN_CONFIG = 2003,
55
+ UNKNOWN_CHAIN_ID = 2004,
56
+ SIGNER_NOT_INITIALIZED = 3001,
57
+ ACCOUNT_FETCH_FAILED = 3002,
58
+ ADDRESS_FETCH_FAILED = 3003,
59
+ SIGN_TYPED_DATA_FAILED = 4001,
60
+ SIGN_MESSAGE_FAILED = 4002,
61
+ INVALID_TYPED_DATA = 4003,
62
+ INVALID_MESSAGE = 4004,
63
+ USER_REJECTED_SIGNATURE = 4005,
64
+ BALANCE_FETCH_FAILED = 5001,
65
+ TOKEN_BALANCE_FETCH_FAILED = 5002,
66
+ INVALID_TOKEN_ADDRESS = 5003,
67
+ TRANSACTION_FAILED = 6001,
68
+ GAS_ESTIMATION_FAILED = 6002,
69
+ INSUFFICIENT_BALANCE = 6003,
70
+ TRANSACTION_REVERTED = 6004,
71
+ TRANSACTION_TIMEOUT = 6005,
72
+ BRIDGE_NOT_AVAILABLE = 7001,
73
+ BRIDGE_NOT_SUPPORTED = 7002,
74
+ BRIDGE_FAILED = 7003,
75
+ INSUFFICIENT_BRIDGE_FEE = 7004,
76
+ RPC_ERROR = 8001,
77
+ RPC_TIMEOUT = 8002,
78
+ RPC_RATE_LIMITED = 8003,
79
+ RPC_CONNECTION_FAILED = 8004,
80
+ PROTOCOL_NOT_REGISTERED = 8101,
81
+ PROTOCOL_EXECUTION_FAILED = 8102,
82
+ INVALID_PARAMETER = 8103,
83
+ UNKNOWN_ERROR = 9999
84
+ }
85
+ /**
86
+ * Base error class for WDK operations
87
+ */
88
+ declare class WDKError extends Error {
89
+ readonly code: WDKErrorCode;
90
+ readonly cause?: Error;
91
+ readonly context?: Record<string, unknown>;
92
+ constructor(code: WDKErrorCode, message: string, options?: {
93
+ cause?: Error;
94
+ context?: Record<string, unknown>;
95
+ });
96
+ /**
97
+ * Create a JSON-serializable representation
98
+ */
99
+ toJSON(): Record<string, unknown>;
100
+ /**
101
+ * Check if error is retryable
102
+ */
103
+ isRetryable(): boolean;
104
+ }
105
+ /**
106
+ * Error thrown when WDK is not properly initialized
107
+ */
108
+ declare class WDKInitializationError extends WDKError {
109
+ constructor(message: string, options?: {
110
+ cause?: Error;
111
+ context?: Record<string, unknown>;
112
+ });
113
+ }
114
+ /**
115
+ * Error thrown for chain-related issues
116
+ */
117
+ declare class ChainError extends WDKError {
118
+ readonly chain?: string;
119
+ constructor(code: WDKErrorCode, message: string, options?: {
120
+ chain?: string;
121
+ cause?: Error;
122
+ context?: Record<string, unknown>;
123
+ });
124
+ }
125
+ /**
126
+ * Error thrown for signer-related issues
127
+ */
128
+ declare class SignerError extends WDKError {
129
+ readonly chain?: string;
130
+ readonly address?: string;
131
+ constructor(code: WDKErrorCode, message: string, options?: {
132
+ chain?: string;
133
+ address?: string;
134
+ cause?: Error;
135
+ context?: Record<string, unknown>;
136
+ });
137
+ }
138
+ /**
139
+ * Error thrown for signing operations
140
+ */
141
+ declare class SigningError extends WDKError {
142
+ readonly operation: 'signTypedData' | 'signMessage';
143
+ constructor(code: WDKErrorCode, message: string, options: {
144
+ operation: 'signTypedData' | 'signMessage';
145
+ cause?: Error;
146
+ context?: Record<string, unknown>;
147
+ });
148
+ }
149
+ /**
150
+ * Error thrown for balance operations
151
+ */
152
+ declare class BalanceError extends WDKError {
153
+ readonly chain?: string;
154
+ readonly token?: string;
155
+ constructor(code: WDKErrorCode, message: string, options?: {
156
+ chain?: string;
157
+ token?: string;
158
+ cause?: Error;
159
+ context?: Record<string, unknown>;
160
+ });
161
+ }
162
+ /**
163
+ * Error thrown for transaction operations
164
+ */
165
+ declare class TransactionError extends WDKError {
166
+ readonly chain?: string;
167
+ readonly txHash?: string;
168
+ constructor(code: WDKErrorCode, message: string, options?: {
169
+ chain?: string;
170
+ txHash?: string;
171
+ cause?: Error;
172
+ context?: Record<string, unknown>;
173
+ });
174
+ }
175
+ /**
176
+ * Error thrown for bridge operations
177
+ */
178
+ declare class BridgeError extends WDKError {
179
+ readonly fromChain?: string;
180
+ readonly toChain?: string;
181
+ constructor(code: WDKErrorCode, message: string, options?: {
182
+ fromChain?: string;
183
+ toChain?: string;
184
+ cause?: Error;
185
+ context?: Record<string, unknown>;
186
+ });
187
+ }
188
+ /**
189
+ * Error thrown for RPC-related issues
190
+ */
191
+ declare class RPCError extends WDKError {
192
+ readonly endpoint?: string;
193
+ readonly rpcCode?: number;
194
+ constructor(code: WDKErrorCode, message: string, options?: {
195
+ endpoint?: string;
196
+ rpcCode?: number;
197
+ cause?: Error;
198
+ context?: Record<string, unknown>;
199
+ });
200
+ }
201
+ /**
202
+ * Wrap an unknown error into a WDKError
203
+ */
204
+ declare function wrapError(error: unknown, defaultCode?: WDKErrorCode, defaultMessage?: string, context?: Record<string, unknown>): WDKError;
205
+ /**
206
+ * Type guard to check if an error is a WDKError
207
+ */
208
+ declare function isWDKError(error: unknown): error is WDKError;
209
+ /**
210
+ * Type guard to check if an error has a specific code
211
+ */
212
+ declare function hasErrorCode(error: unknown, code: WDKErrorCode): boolean;
213
+ /**
214
+ * Retry configuration
215
+ */
216
+ interface RetryConfig {
217
+ /** Maximum number of retries */
218
+ maxRetries: number;
219
+ /** Base delay in milliseconds */
220
+ baseDelay: number;
221
+ /** Maximum delay in milliseconds */
222
+ maxDelay: number;
223
+ /** Whether to use exponential backoff */
224
+ exponentialBackoff: boolean;
225
+ }
226
+ /**
227
+ * Default retry configuration
228
+ */
229
+ declare const DEFAULT_RETRY_CONFIG: RetryConfig;
230
+ /**
231
+ * Execute an async function with retry logic
232
+ */
233
+ declare function withRetry<T>(fn: () => Promise<T>, config?: Partial<RetryConfig>): Promise<T>;
234
+ /**
235
+ * Timeout wrapper for async operations
236
+ */
237
+ declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, operation?: string): Promise<T>;
238
+
239
+ /**
240
+ * WDK Failover Provider
241
+ *
242
+ * Automatic RPC failover support with health checking and
243
+ * configurable failure thresholds.
244
+ */
245
+ interface FailoverConfig {
246
+ /** RPC URLs in priority order */
247
+ urls: string[];
248
+ /** Health check interval in ms (default: 30000) */
249
+ healthCheckInterval?: number;
250
+ /** Request timeout in ms (default: 5000) */
251
+ requestTimeout?: number;
252
+ /** Max consecutive failures before marking unhealthy (default: 3) */
253
+ maxFailures?: number;
254
+ }
255
+ interface ProviderStatus {
256
+ url: string;
257
+ healthy: boolean;
258
+ lastChecked: number;
259
+ consecutiveFailures: number;
260
+ }
261
+ /**
262
+ * RPC failover provider with automatic health checking and failover.
263
+ *
264
+ * Manages a list of RPC URLs in priority order, automatically switching
265
+ * to the next healthy provider when failures exceed the threshold.
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * const provider = new FailoverProvider({
270
+ * urls: ['https://arb1.arbitrum.io/rpc', 'https://arb-fallback.example.com'],
271
+ * maxFailures: 3,
272
+ * })
273
+ *
274
+ * const url = provider.getCurrentUrl()
275
+ * try {
276
+ * await fetch(url)
277
+ * provider.reportSuccess()
278
+ * } catch {
279
+ * provider.reportFailure()
280
+ * }
281
+ * ```
282
+ */
283
+ declare class FailoverProvider {
284
+ private providers;
285
+ private currentIndex;
286
+ private healthCheckTimer?;
287
+ private readonly maxFailures;
288
+ private readonly requestTimeout;
289
+ constructor(config: FailoverConfig);
290
+ /**
291
+ * Get current active RPC URL
292
+ */
293
+ getCurrentUrl(): string;
294
+ /**
295
+ * Report a failure on the current URL.
296
+ * Auto-switches to next healthy provider if failure threshold is reached.
297
+ *
298
+ * @returns The new URL if switched, or null if no switch occurred
299
+ */
300
+ reportFailure(): string | null;
301
+ /**
302
+ * Report success on the current URL, reset failure counter.
303
+ */
304
+ reportSuccess(): void;
305
+ /**
306
+ * Get all provider statuses
307
+ */
308
+ getStatus(): ProviderStatus[];
309
+ /**
310
+ * Force switch to next healthy provider.
311
+ *
312
+ * @returns The new URL, or null if no healthy providers available
313
+ */
314
+ switchToNext(): string | null;
315
+ /**
316
+ * Get the request timeout in milliseconds
317
+ */
318
+ getRequestTimeout(): number;
319
+ /**
320
+ * Stop health checks and clean up resources
321
+ */
322
+ dispose(): void;
323
+ private startHealthChecks;
324
+ private checkHealth;
325
+ }
326
+ /**
327
+ * Normalize chain config that may contain failover arrays.
328
+ * Backward compatible: single string URL still works.
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * // Single URL (backward compatible)
333
+ * const provider = createFailoverProvider('https://arb1.arbitrum.io/rpc')
334
+ * // Returns null — no failover needed
335
+ *
336
+ * // Multiple URLs with failover
337
+ * const provider = createFailoverProvider(['https://arb1.arbitrum.io/rpc', 'https://fallback.example.com'])
338
+ * // Returns FailoverProvider
339
+ *
340
+ * // Full config
341
+ * const provider = createFailoverProvider({
342
+ * urls: ['https://arb1.arbitrum.io/rpc', 'https://fallback.example.com'],
343
+ * healthCheckInterval: 15000,
344
+ * })
345
+ * ```
346
+ */
347
+ declare function createFailoverProvider(config: string | string[] | FailoverConfig): FailoverProvider | null;
348
+ /**
349
+ * Resolve the primary RPC URL from a config that may be a string, array, or FailoverConfig.
350
+ */
351
+ declare function resolveRpcUrl(config: string | string[] | FailoverConfig): string;
352
+
353
+ /**
354
+ * EVM chain configuration
355
+ */
356
+ interface EvmChainConfig {
357
+ /** RPC endpoint URL or array of URLs for failover */
358
+ provider: string | string[];
359
+ /** Chain ID */
360
+ chainId?: number;
361
+ /** CAIP-2 network identifier */
362
+ network?: string;
363
+ /** Failover configuration (only used when provider is an array) */
364
+ failover?: Partial<FailoverConfig>;
365
+ }
366
+ /**
367
+ * T402 WDK configuration options
368
+ */
369
+ interface T402WDKConfig {
370
+ /** Ethereum mainnet configuration */
371
+ ethereum?: EvmChainConfig | string;
372
+ /** Arbitrum One configuration */
373
+ arbitrum?: EvmChainConfig | string;
374
+ /** Base mainnet configuration */
375
+ base?: EvmChainConfig | string;
376
+ /** Ink mainnet configuration */
377
+ ink?: EvmChainConfig | string;
378
+ /** Berachain mainnet configuration */
379
+ berachain?: EvmChainConfig | string;
380
+ /** Unichain mainnet configuration */
381
+ unichain?: EvmChainConfig | string;
382
+ /** Polygon mainnet configuration */
383
+ polygon?: EvmChainConfig | string;
384
+ /** Custom chains */
385
+ [key: string]: EvmChainConfig | string | undefined;
386
+ }
387
+ /**
388
+ * Normalized chain configuration
389
+ */
390
+ interface NormalizedChainConfig {
391
+ provider: string;
392
+ chainId: number;
393
+ network: string;
394
+ name: string;
395
+ }
396
+ /**
397
+ * Token balance information
398
+ */
399
+ interface TokenBalance {
400
+ /** Token contract address */
401
+ token: Address;
402
+ /** Token symbol */
403
+ symbol: string;
404
+ /** Balance in smallest units */
405
+ balance: bigint;
406
+ /** Formatted balance (human-readable) */
407
+ formatted: string;
408
+ /** Decimals */
409
+ decimals: number;
410
+ }
411
+ /**
412
+ * Chain balance information
413
+ */
414
+ interface ChainBalance {
415
+ /** Chain name (e.g., "arbitrum") */
416
+ chain: string;
417
+ /** CAIP-2 network identifier */
418
+ network: string;
419
+ /** Native token balance */
420
+ native: bigint;
421
+ /** Token balances */
422
+ tokens: TokenBalance[];
423
+ }
424
+ /**
425
+ * Aggregated balance across all chains
426
+ */
427
+ interface AggregatedBalance {
428
+ /** Total USDT0 balance across all chains */
429
+ totalUsdt0: bigint;
430
+ /** Total USDC balance across all chains */
431
+ totalUsdc: bigint;
432
+ /** Per-chain balances */
433
+ chains: ChainBalance[];
434
+ }
435
+ /**
436
+ * Bridge parameters for cross-chain transfers
437
+ */
438
+ interface BridgeParams {
439
+ /** Source chain name */
440
+ fromChain: string;
441
+ /** Destination chain name */
442
+ toChain: string;
443
+ /** Amount to bridge in smallest units */
444
+ amount: bigint;
445
+ /** Recipient address (optional, defaults to same wallet on target chain) */
446
+ recipient?: Address;
447
+ }
448
+ /**
449
+ * Bridge result
450
+ */
451
+ interface BridgeResult {
452
+ /** Transaction hash on source chain */
453
+ txHash: string;
454
+ /** Estimated time for bridge completion in seconds */
455
+ estimatedTime: number;
456
+ }
457
+ /**
458
+ * EIP-712 typed data domain
459
+ */
460
+ interface TypedDataDomain {
461
+ name: string;
462
+ version: string;
463
+ chainId: number;
464
+ verifyingContract: Address;
465
+ }
466
+ /**
467
+ * EIP-712 typed data types
468
+ */
469
+ type TypedDataTypes = Record<string, Array<{
470
+ name: string;
471
+ type: string;
472
+ }>>;
473
+ /**
474
+ * T402 Signer interface for WDK
475
+ * Compatible with @t402/core signer requirements
476
+ */
477
+ interface T402WDKSigner {
478
+ /** Get wallet address */
479
+ readonly address: Address;
480
+ /** Sign EIP-712 typed data */
481
+ signTypedData(params: {
482
+ domain: TypedDataDomain;
483
+ types: TypedDataTypes;
484
+ primaryType: string;
485
+ message: Record<string, unknown>;
486
+ }): Promise<`0x${string}`>;
487
+ /** Sign a message */
488
+ signMessage?(message: string | Uint8Array): Promise<`0x${string}`>;
489
+ /** Get token balance */
490
+ getTokenBalance?(tokenAddress: Address): Promise<bigint>;
491
+ }
492
+ /**
493
+ * WDK Account interface (matches @tetherto/wdk account structure)
494
+ *
495
+ * This is the canonical definition used across all @t402/wdk-* packages.
496
+ * Implementors (Tether WDK) provide these methods; T402 code consumes them.
497
+ */
498
+ interface WDKAccount {
499
+ /** Get the account's address */
500
+ getAddress(): Promise<string>;
501
+ /** Get the account's native balance */
502
+ getBalance(): Promise<bigint>;
503
+ /** Get the account's token balance */
504
+ getTokenBalance(tokenAddress: string): Promise<bigint>;
505
+ /** Sign a message */
506
+ signMessage(message: string): Promise<string>;
507
+ /** Sign typed data (EIP-712) */
508
+ signTypedData(params: {
509
+ domain: Record<string, unknown>;
510
+ types: Record<string, unknown>;
511
+ primaryType: string;
512
+ message: Record<string, unknown>;
513
+ }): Promise<string>;
514
+ /** Send a transaction */
515
+ sendTransaction(params: {
516
+ to: string;
517
+ value?: bigint;
518
+ data?: string;
519
+ }): Promise<string>;
520
+ /** Estimate gas for a transaction (optional — not all implementations support this) */
521
+ estimateGas?(params: {
522
+ to: string;
523
+ value?: bigint;
524
+ data?: string;
525
+ }): Promise<bigint>;
526
+ }
527
+ /**
528
+ * Alias for WDKAccount — preferred naming for use in @t402/wdk-* packages.
529
+ */
530
+ type WdkAccount = WDKAccount;
531
+ /**
532
+ * WDK instance interface (matches @tetherto/wdk structure)
533
+ */
534
+ interface WDKInstance {
535
+ registerWallet<T>(name: string, manager: T, config: Record<string, unknown>): WDKInstance;
536
+ registerProtocol<T>(name: string, protocol: T): WDKInstance;
537
+ getAccount(chain: string, index: number): Promise<WDKAccount>;
538
+ executeProtocol(name: string, params: Record<string, unknown>): Promise<{
539
+ txHash: string;
540
+ }>;
541
+ }
542
+ /**
543
+ * WDK constructor type
544
+ */
545
+ interface WDKConstructor {
546
+ new (seedPhrase: string): WDKInstance;
547
+ getRandomSeedPhrase(): string;
548
+ }
549
+ /**
550
+ * Balance cache configuration for T402WDK
551
+ */
552
+ interface T402BalanceCacheConfig {
553
+ /** Whether caching is enabled (default: true) */
554
+ enabled?: boolean;
555
+ /** TTL for native balance in milliseconds (default: 15000 = 15 seconds) */
556
+ nativeBalanceTTL?: number;
557
+ /** TTL for token balance in milliseconds (default: 30000 = 30 seconds) */
558
+ tokenBalanceTTL?: number;
559
+ /** TTL for aggregated balances in milliseconds (default: 60000 = 60 seconds) */
560
+ aggregatedBalanceTTL?: number;
561
+ /** Maximum cache entries (default: 500) */
562
+ maxSize?: number;
563
+ }
564
+ /**
565
+ * Extended T402 WDK configuration with cache options
566
+ */
567
+ interface T402WDKOptions {
568
+ /** Balance cache configuration */
569
+ cache?: T402BalanceCacheConfig;
570
+ /** Retry configuration for RPC-calling methods */
571
+ retry?: Partial<RetryConfig>;
572
+ /** WDK constructor (instance-level override) */
573
+ wdk?: WDKConstructor;
574
+ /** Wallet modules (instance-level override) */
575
+ wallets?: WDKWalletModules;
576
+ /** Protocol modules (instance-level override) */
577
+ protocols?: WDKProtocolModules;
578
+ /** Middleware hooks (instance-level override) */
579
+ middlewares?: Map<string, Array<(account: unknown) => Promise<void>>>;
580
+ /** Fiat on-ramp provider (instance-level override) */
581
+ fiatOnRampProvider?: FiatOnRampProvider;
582
+ /** Structured logger (default: noopLogger) */
583
+ logger?: T402Logger;
584
+ /** Metric callback for observability */
585
+ onMetric?: (name: string, value: number, tags?: Record<string, string>) => void;
586
+ }
587
+ /**
588
+ * Supported blockchain families
589
+ */
590
+ type ChainFamily = 'evm' | 'svm' | 'ton' | 'tron' | 'spark' | 'btc';
591
+ /**
592
+ * Solana chain configuration
593
+ */
594
+ interface SvmChainConfig {
595
+ /** RPC endpoint URL */
596
+ rpcUrl: string;
597
+ /** Commitment level */
598
+ commitment?: 'processed' | 'confirmed' | 'finalized';
599
+ /** Network type */
600
+ network?: 'mainnet' | 'testnet' | 'devnet';
601
+ }
602
+ /**
603
+ * TON chain configuration
604
+ */
605
+ interface TonChainConfig {
606
+ /** API endpoint URL */
607
+ endpoint: string;
608
+ /** Network type */
609
+ network?: 'mainnet' | 'testnet';
610
+ /** API key for TON Center */
611
+ apiKey?: string;
612
+ }
613
+ /**
614
+ * TRON chain configuration
615
+ */
616
+ interface TronChainConfig {
617
+ /** Full host URL (e.g., https://api.trongrid.io) */
618
+ fullHost: string;
619
+ /** Network type */
620
+ network?: 'mainnet' | 'shasta' | 'nile';
621
+ /** API key for TronGrid */
622
+ apiKey?: string;
623
+ }
624
+ /**
625
+ * Multi-chain configuration
626
+ */
627
+ interface MultiChainConfig {
628
+ /** EVM chains configuration */
629
+ evm?: Record<string, EvmChainConfig | string>;
630
+ /** Solana configuration */
631
+ svm?: SvmChainConfig;
632
+ /** TON configuration */
633
+ ton?: TonChainConfig;
634
+ /** TRON configuration */
635
+ tron?: TronChainConfig;
636
+ }
637
+ /**
638
+ * WDK wallet modules registry
639
+ * All modules are optional - only register what you need
640
+ */
641
+ interface WDKWalletModules {
642
+ /** EVM wallet manager (@tetherto/wdk-wallet-evm) */
643
+ evm?: unknown;
644
+ /** EVM ERC-4337 wallet manager (@tetherto/wdk-wallet-evm-erc4337) */
645
+ evmErc4337?: unknown;
646
+ /** Solana wallet manager (@tetherto/wdk-wallet-solana) */
647
+ solana?: unknown;
648
+ /** TON wallet manager (@tetherto/wdk-wallet-ton) */
649
+ ton?: unknown;
650
+ /** TON gasless wallet manager (@tetherto/wdk-wallet-ton-gasless) */
651
+ tonGasless?: unknown;
652
+ /** TRON wallet manager (@tetherto/wdk-wallet-tron) */
653
+ tron?: unknown;
654
+ /** TRON gas-free wallet manager (@tetherto/wdk-wallet-tron-gasfree) */
655
+ tronGasfree?: unknown;
656
+ /** Bitcoin wallet manager (@tetherto/wdk-wallet-btc) */
657
+ btc?: unknown;
658
+ /** Spark (Bitcoin L2) wallet manager (@buildonspark/spark-sdk) */
659
+ spark?: unknown;
660
+ }
661
+ /**
662
+ * WDK protocol modules registry
663
+ * All modules are optional - only register what you need
664
+ */
665
+ interface WDKProtocolModules {
666
+ /** USDT0 bridge for EVM (@tetherto/wdk-protocol-bridge-usdt0-evm) */
667
+ bridgeUsdt0Evm?: unknown;
668
+ /** USDT0 bridge for TON (@tetherto/wdk-protocol-bridge-usdt0-ton) */
669
+ bridgeUsdt0Ton?: unknown;
670
+ /** Velora swap for EVM (@tetherto/wdk-protocol-swap-velora-evm) */
671
+ swapVeloraEvm?: unknown;
672
+ /** Aave lending for EVM (@tetherto/wdk-protocol-lending-aave-evm) */
673
+ lendingAaveEvm?: unknown;
674
+ }
675
+ /**
676
+ * Unified WDK modules registration
677
+ */
678
+ interface WDKModulesConfig {
679
+ /** Wallet modules */
680
+ wallets?: WDKWalletModules;
681
+ /** Protocol modules */
682
+ protocols?: WDKProtocolModules;
683
+ }
684
+ /**
685
+ * WDK TON account interface (compatible with @tetherto/wdk-wallet-ton)
686
+ */
687
+ interface WDKTonAccount {
688
+ /** Get wallet address */
689
+ getAddress(): Promise<string>;
690
+ /** Get TON balance */
691
+ getBalance(): Promise<bigint>;
692
+ /** Get Jetton balance */
693
+ getJettonBalance(jettonMaster: string): Promise<bigint>;
694
+ /** Sign a message */
695
+ signMessage(message: Uint8Array): Promise<Uint8Array>;
696
+ /** Send TON transaction */
697
+ sendTransaction(params: {
698
+ to: string;
699
+ value: bigint;
700
+ body?: string;
701
+ bounce?: boolean;
702
+ }): Promise<string>;
703
+ /** Get current sequence number */
704
+ getSeqno(): Promise<number>;
705
+ /** Transfer Jettons */
706
+ transferJetton?(params: {
707
+ jettonMaster: string;
708
+ to: string;
709
+ amount: bigint;
710
+ forwardPayload?: string;
711
+ }): Promise<string>;
712
+ }
713
+ /**
714
+ * WDK Solana account interface (compatible with @tetherto/wdk-wallet-solana)
715
+ */
716
+ interface WDKSolanaAccount {
717
+ /** Get wallet address (base58) */
718
+ getAddress(): Promise<string>;
719
+ /** Get SOL balance */
720
+ getBalance(): Promise<bigint>;
721
+ /** Get SPL token balance */
722
+ getTokenBalance(mint: string): Promise<bigint>;
723
+ /** Sign a message */
724
+ sign(message: Uint8Array): Promise<Uint8Array>;
725
+ /** Sign a transaction */
726
+ signTransaction(transaction: Uint8Array): Promise<Uint8Array>;
727
+ /** Send SOL */
728
+ sendTransaction(params: {
729
+ recipient: string;
730
+ value: bigint;
731
+ }): Promise<string>;
732
+ /** Transfer SPL token */
733
+ transfer(params: {
734
+ token: string;
735
+ recipient: string;
736
+ amount: bigint;
737
+ }): Promise<string>;
738
+ /** Get token program for a mint (Token or Token-2022) — optional Token-2022 support */
739
+ getTokenProgram?(mint: string): Promise<'Token' | 'Token-2022'>;
740
+ /** Get transfer fee for a Token-2022 mint — optional Token-2022 support */
741
+ getTransferFee?(mint: string, amount: bigint): Promise<{
742
+ fee: bigint;
743
+ netAmount: bigint;
744
+ }>;
745
+ }
746
+ /**
747
+ * WDK TRON account interface (compatible with @tetherto/wdk-wallet-tron)
748
+ */
749
+ interface WDKTronAccount {
750
+ /** Get wallet address (base58) */
751
+ getAddress(): Promise<string>;
752
+ /** Get TRX balance */
753
+ getBalance(): Promise<bigint>;
754
+ /** Get TRC20 token balance */
755
+ getTrc20Balance(contractAddress: string): Promise<bigint>;
756
+ /** Sign a transaction */
757
+ signTransaction(transaction: unknown): Promise<unknown>;
758
+ /** Send signed transaction */
759
+ sendTransaction(signedTx: unknown): Promise<string>;
760
+ /** Transfer TRC20 token */
761
+ transferTrc20?(params: {
762
+ contractAddress: string;
763
+ to: string;
764
+ amount: bigint;
765
+ }): Promise<string>;
766
+ }
767
+ /**
768
+ * Extended WDK instance interface with multi-chain support
769
+ */
770
+ interface WDKInstanceMultiChain extends WDKInstance {
771
+ /** Get TON account */
772
+ getTonAccount?(index: number): Promise<WDKTonAccount>;
773
+ /** Get Solana account */
774
+ getSolanaAccount?(index: number): Promise<WDKSolanaAccount>;
775
+ /** Get TRON account */
776
+ getTronAccount?(index: number): Promise<WDKTronAccount>;
777
+ }
778
+ /**
779
+ * Result of WDK module auto-discovery
780
+ */
781
+ interface WDKAutoDiscoveryResult {
782
+ /** Discovered modules ready for registration */
783
+ discovered: WDKModulesConfig;
784
+ /** Package names that were found and loaded */
785
+ available: string[];
786
+ /** Package names that were not installed */
787
+ unavailable: string[];
788
+ }
789
+ /**
790
+ * Configuration for T402WDK.create() factory method
791
+ */
792
+ interface T402WDKCreateConfig {
793
+ /** BIP-39 mnemonic seed phrase */
794
+ seedPhrase: string;
795
+ /** Chain name → RPC URL mapping for EVM chains */
796
+ chains: Record<string, string>;
797
+ /** WDK modules to register */
798
+ modules: WDKModulesConfig;
799
+ /** Additional options */
800
+ options?: T402WDKOptions;
801
+ }
802
+ /**
803
+ * A signer entry for use with T402 HTTP clients
804
+ */
805
+ interface SignerEntry {
806
+ /** Payment scheme (e.g., "exact") */
807
+ scheme: string;
808
+ /** CAIP-2 network identifier (e.g., "eip155:42161") */
809
+ network: string;
810
+ /** The signer instance */
811
+ signer: unknown;
812
+ /** Chain family (evm, ton, svm, tron) */
813
+ family: ChainFamily;
814
+ }
815
+ /**
816
+ * Options for getAllSigners()
817
+ */
818
+ interface GetAllSignersOptions {
819
+ /** HD wallet account index (default: 0) */
820
+ accountIndex?: number;
821
+ /** Filter by payment schemes (default: ["exact"]) */
822
+ schemes?: string[];
823
+ /** Include non-EVM chain signers (default: true) */
824
+ includeNonEvm?: boolean;
825
+ }
826
+ /**
827
+ * Options for T402WDK.fromWDK()
828
+ */
829
+ interface FromWDKOptions {
830
+ /** HD wallet account index for auto-discovery (default: 0) */
831
+ defaultAccountIndex?: number;
832
+ }
833
+ /**
834
+ * Swap quote result
835
+ */
836
+ interface SwapQuote {
837
+ /** Input token address */
838
+ inputToken: string;
839
+ /** Output token address */
840
+ outputToken: string;
841
+ /** Input amount in smallest units */
842
+ inputAmount: bigint;
843
+ /** Expected output amount in smallest units */
844
+ outputAmount: bigint;
845
+ /** Price impact percentage */
846
+ priceImpact: number;
847
+ /** Swap route (token addresses) */
848
+ route: string[];
849
+ }
850
+ /**
851
+ * Swap execution result
852
+ */
853
+ interface SwapResult {
854
+ /** Transaction hash */
855
+ txHash: string;
856
+ /** Actual input amount */
857
+ inputAmount: bigint;
858
+ /** Actual output amount */
859
+ outputAmount: bigint;
860
+ }
861
+ /**
862
+ * Parameters for swap operations
863
+ */
864
+ interface SwapParams {
865
+ /** Chain name (e.g., "ethereum", "arbitrum") */
866
+ chain: string;
867
+ /** Input token address */
868
+ fromToken: string;
869
+ /** Amount to swap in smallest units */
870
+ amount: bigint;
871
+ /** Maximum slippage tolerance (0-1, default: 0.005 = 0.5%) */
872
+ maxSlippage?: number;
873
+ }
874
+ /**
875
+ * Parameters for borrow-and-pay operations
876
+ */
877
+ interface BorrowParams {
878
+ /** Chain name (e.g., "ethereum", "arbitrum") */
879
+ chain: string;
880
+ /** Collateral token address */
881
+ collateralToken: string;
882
+ /** Collateral amount in smallest units */
883
+ collateralAmount: bigint;
884
+ /** USDT0 amount to borrow in smallest units */
885
+ borrowAmount: bigint;
886
+ /** Interest rate mode: 1 = stable, 2 = variable (default: 2) */
887
+ interestRateMode?: number;
888
+ }
889
+ /**
890
+ * Result of a borrow-and-pay operation
891
+ */
892
+ interface BorrowResult {
893
+ /** Supply (deposit collateral) transaction hash */
894
+ supplyTxHash: string;
895
+ /** Borrow transaction hash */
896
+ borrowTxHash: string;
897
+ /** Actual borrowed amount in smallest units */
898
+ borrowedAmount: bigint;
899
+ }
900
+ /**
901
+ * Fiat on-ramp quote
902
+ */
903
+ interface FiatOnRampQuote {
904
+ /** Fiat amount to spend */
905
+ fiatAmount: number;
906
+ /** Fiat currency code (e.g., "USD", "EUR") */
907
+ fiatCurrency: string;
908
+ /** Crypto amount to receive */
909
+ cryptoAmount: string;
910
+ /** Crypto currency code (e.g., "USDT") */
911
+ cryptoCurrency: string;
912
+ /** Exchange rate (fiat per crypto) */
913
+ exchangeRate: number;
914
+ /** Fee breakdown */
915
+ fees: {
916
+ network: string;
917
+ service: string;
918
+ total: string;
919
+ };
920
+ /** Estimated time to complete in seconds */
921
+ estimatedTime: number;
922
+ }
923
+ /**
924
+ * Fiat on-ramp parameters
925
+ */
926
+ interface FiatOnRampParams {
927
+ /** Fiat amount to spend */
928
+ fiatAmount: number;
929
+ /** Fiat currency code (e.g., "USD") */
930
+ fiatCurrency: string;
931
+ /** Crypto currency to buy (default: "USDT") */
932
+ cryptoCurrency?: string;
933
+ /** Wallet address to receive funds */
934
+ walletAddress: string;
935
+ /** CAIP-2 network identifier */
936
+ network: string;
937
+ /** URL to redirect after purchase */
938
+ redirectUrl?: string;
939
+ }
940
+ /**
941
+ * Fiat on-ramp result
942
+ */
943
+ interface FiatOnRampResult {
944
+ /** Widget URL to open for the user */
945
+ widgetUrl: string;
946
+ /** Order ID for tracking */
947
+ orderId: string;
948
+ /** When the widget URL expires */
949
+ expiresAt: string;
950
+ }
951
+ /**
952
+ * Fiat on-ramp provider interface
953
+ */
954
+ interface FiatOnRampProvider {
955
+ /** Provider name */
956
+ name: string;
957
+ /** Get a quote for fiat-to-crypto conversion */
958
+ getQuote(params: Pick<FiatOnRampParams, 'fiatAmount' | 'fiatCurrency' | 'network'>): Promise<FiatOnRampQuote>;
959
+ /** Create a widget URL for the user to complete the purchase */
960
+ createWidget(params: FiatOnRampParams): FiatOnRampResult;
961
+ /** Get supported fiat currencies */
962
+ getSupportedCurrencies(): string[];
963
+ /** Get supported CAIP-2 network identifiers */
964
+ getSupportedNetworks(): string[];
965
+ }
966
+
967
+ export { WDKErrorCode as $, type AggregatedBalance as A, type BridgeResult as B, type ChainFamily as C, DEFAULT_RETRY_CONFIG as D, type EvmChainConfig as E, type FiatOnRampProvider as F, type GetAllSignersOptions as G, type T402WDKConfig as H, type T402WDKCreateConfig as I, type T402WDKOptions as J, type T402WDKSigner as K, type TokenBalance as L, type MetricCallback as M, type NormalizedChainConfig as N, type TonChainConfig as O, type ProviderStatus as P, TransactionError as Q, RPCError as R, type SignerEntry as S, type T402BalanceCacheConfig as T, type TronChainConfig as U, type TypedDataDomain as V, type WDKSolanaAccount as W, type TypedDataTypes as X, type WDKAutoDiscoveryResult as Y, type WDKConstructor as Z, WDKError as _, type WDKTonAccount as a, WDKInitializationError as a0, type WDKInstanceMultiChain as a1, type WDKModulesConfig as a2, type WDKProtocolModules as a3, type WDKWalletModules as a4, type WdkAccount as a5, createCorrelationId as a6, createFailoverProvider as a7, defaultLogger as a8, hasErrorCode as a9, isWDKError as aa, noopLogger as ab, resolveRpcUrl as ac, withRetry as ad, withTimeout as ae, wrapError as af, type WDKTronAccount as b, type WDKAccount as c, type WDKInstance as d, type FiatOnRampParams as e, type FiatOnRampQuote as f, type FiatOnRampResult as g, BalanceError as h, type BorrowParams as i, type BorrowResult as j, BridgeError as k, type BridgeParams as l, type ChainBalance as m, ChainError as n, type FailoverConfig as o, FailoverProvider as p, type FromWDKOptions as q, type MultiChainConfig as r, type RetryConfig as s, SignerError as t, SigningError as u, type SvmChainConfig as v, type SwapParams as w, type SwapQuote as x, type SwapResult as y, type T402Logger as z };