@tetherto/wdk-wallet 1.0.0-beta.1 → 1.0.0-beta.10

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.
@@ -0,0 +1,400 @@
1
+ /** @interface */
2
+ export interface ISwidgeProtocol extends ISwapProtocol, IBridgeProtocol {
3
+ /**
4
+ * Quotes the estimated costs and output of a cross-chain swap/bridge operation.
5
+ * Returns a non-binding quote; the actual execution is performed
6
+ * by {@link swidge}.
7
+ *
8
+ * @param {SwidgeOptions} options - The swidge options.
9
+ * @returns {Promise<SwidgeQuote>} The quoted swidge details.
10
+ */
11
+ quoteSwidge(options: SwidgeOptions): Promise<SwidgeQuote>;
12
+ /**
13
+ * Executes a swidge operation.
14
+ *
15
+ * @param {SwidgeOptions} options - The swidge options.
16
+ * @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
17
+ * @returns {Promise<SwidgeResult>} The swidge execution result.
18
+ */
19
+ swidge(options: SwidgeOptions, config?: SwidgeProtocolConfig): Promise<SwidgeResult>;
20
+ /**
21
+ * Retrieves the current status of an in-flight swidge.
22
+ *
23
+ * @param {string} id - The swidge execution identifier returned by swidge.
24
+ * @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
25
+ * @returns {Promise<SwidgeStatusResult>} The current swidge status.
26
+ * @throws {Error} If the id is invalid, or no swidge exists with the given identifier.
27
+ */
28
+ getSwidgeStatus(id: string, options?: SwidgeStatusOptions): Promise<SwidgeStatusResult>;
29
+ /**
30
+ * Retrieves the chains supported by the provider for swidge operations.
31
+ *
32
+ * @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
33
+ */
34
+ getSupportedChains(): Promise<SwidgeSupportedChain[]>;
35
+ /**
36
+ * Retrieves the tokens supported by the provider for swidge operations.
37
+ *
38
+ * @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
39
+ * @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
40
+ */
41
+ getSupportedTokens(options?: SwidgeSupportedTokensOptions): Promise<SwidgeSupportedToken[]>;
42
+ }
43
+ /** @abstract */
44
+ export default abstract class SwidgeProtocol implements ISwidgeProtocol, ISwapProtocol, IBridgeProtocol {
45
+ /**
46
+ * Creates a new swidge protocol without binding it to a wallet account.
47
+ *
48
+ * @overload
49
+ * @param {undefined} [account] - The wallet account to use to interact with the protocol.
50
+ * @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
51
+ */
52
+ constructor(account?: undefined, config?: SwidgeProtocolConfig | undefined);
53
+ /**
54
+ * Creates a new read-only swidge protocol.
55
+ *
56
+ * @overload
57
+ * @param {IWalletAccountReadOnly} account - The wallet account to use to interact with the protocol.
58
+ * @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
59
+ */
60
+ constructor(account: IWalletAccountReadOnly, config?: SwidgeProtocolConfig | undefined);
61
+ /**
62
+ * Creates a new swidge protocol.
63
+ *
64
+ * @overload
65
+ * @param {IWalletAccount} account - The wallet account to use to interact with the protocol.
66
+ * @param {SwidgeProtocolConfig} [config] - The swidge protocol configuration.
67
+ */
68
+ constructor(account: IWalletAccount, config?: SwidgeProtocolConfig | undefined);
69
+ /**
70
+ * The wallet account to use to interact with the protocol.
71
+ *
72
+ * @protected
73
+ * @type {IWalletAccountReadOnly | IWalletAccount | undefined}
74
+ */
75
+ protected _account: IWalletAccountReadOnly | IWalletAccount | undefined;
76
+ /**
77
+ * The swidge protocol configuration.
78
+ *
79
+ * @protected
80
+ * @type {SwidgeProtocolConfig}
81
+ */
82
+ protected _config: SwidgeProtocolConfig;
83
+ /**
84
+ * Swaps a pair of tokens by delegating to {@link swidge}.
85
+ *
86
+ * @param {SwapOptions} options - The swap's options.
87
+ * @returns {Promise<SwapResult>} The swap's result.
88
+ */
89
+ swap(options: SwapOptions): Promise<SwapResult>;
90
+ /**
91
+ * Quotes the costs of a swap operation by delegating to {@link quoteSwidge}.
92
+ *
93
+ * @param {SwapOptions} options - The swap's options.
94
+ * @returns {Promise<Omit<SwapResult, 'hash'>>} The swap's quotes.
95
+ */
96
+ quoteSwap(options: SwapOptions): Promise<Omit<SwapResult, "hash">>;
97
+ /**
98
+ * Bridges a token to a different blockchain by delegating to {@link swidge}.
99
+ *
100
+ * @param {BridgeOptions} options - The bridge's options.
101
+ * @returns {Promise<BridgeResult>} The bridge's result.
102
+ */
103
+ bridge(options: BridgeOptions): Promise<BridgeResult>;
104
+ /**
105
+ * Quotes the costs of a bridge operation by delegating to {@link quoteSwidge}.
106
+ *
107
+ * @param {BridgeOptions} options - The bridge's options.
108
+ * @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
109
+ */
110
+ quoteBridge(options: BridgeOptions): Promise<Omit<BridgeResult, "hash">>;
111
+ /**
112
+ * Quotes the estimated costs and output of a swidge operation.
113
+ * Returns a non-binding quote; the actual execution is performed
114
+ * by {@link swidge}.
115
+ *
116
+ * @abstract
117
+ * @param {SwidgeOptions} options - The swidge options.
118
+ * @returns {Promise<SwidgeQuote>} The quoted swidge details.
119
+ */
120
+ abstract quoteSwidge(options: SwidgeOptions): Promise<SwidgeQuote>;
121
+ /**
122
+ * Executes a swidge operation.
123
+ *
124
+ * @abstract
125
+ * @param {SwidgeOptions} options - The swidge options.
126
+ * @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
127
+ * @returns {Promise<SwidgeResult>} The swidge execution result.
128
+ */
129
+ abstract swidge(options: SwidgeOptions, config?: SwidgeProtocolConfig): Promise<SwidgeResult>;
130
+ /**
131
+ * Retrieves the current status of an in-flight swidge.
132
+ *
133
+ * @abstract
134
+ * @param {string} id - The swidge execution identifier returned by swidge.
135
+ * @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
136
+ * @returns {Promise<SwidgeStatusResult>} The current swidge status.
137
+ * @throws {Error} If the id is invalid, or no swidge exists with the given identifier.
138
+ */
139
+ abstract getSwidgeStatus(id: string, options?: SwidgeStatusOptions): Promise<SwidgeStatusResult>;
140
+ /**
141
+ * Retrieves the chains supported by the provider for swidge operations.
142
+ *
143
+ * @abstract
144
+ * @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
145
+ */
146
+ abstract getSupportedChains(): Promise<SwidgeSupportedChain[]>;
147
+ /**
148
+ * Retrieves the tokens supported by the provider for swidge operations.
149
+ *
150
+ * @abstract
151
+ * @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
152
+ * @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
153
+ */
154
+ abstract getSupportedTokens(options?: SwidgeSupportedTokensOptions): Promise<SwidgeSupportedToken[]>;
155
+ }
156
+ export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
157
+ export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
158
+ export type ISwapProtocol = import("./swap-protocol.js").ISwapProtocol;
159
+ export type SwapOptions = import("./swap-protocol.js").SwapOptions;
160
+ export type SwapResult = import("./swap-protocol.js").SwapResult;
161
+ export type IBridgeProtocol = import("./bridge-protocol.js").IBridgeProtocol;
162
+ export type BridgeOptions = import("./bridge-protocol.js").BridgeOptions;
163
+ export type BridgeResult = import("./bridge-protocol.js").BridgeResult;
164
+ export type SwidgeStatus = "pending" | "action-required" | "completed" | "failed" | "refund-pending" | "refunded" | "cancelled" | "expired" | "partial";
165
+ export type SwidgeFeeType = "network" | "protocol" | "affiliate" | "other";
166
+ export type SwidgeProtocolConfig = {
167
+ /**
168
+ * - Maximum acceptable network fee in basis points of the input amount.
169
+ */
170
+ maxNetworkFeeBps?: number | bigint | undefined;
171
+ /**
172
+ * - Maximum acceptable protocol fee in basis points of the input amount.
173
+ */
174
+ maxProtocolFeeBps?: number | bigint | undefined;
175
+ };
176
+ export type SwidgeOptions = SwidgeCommonOptions & (SwidgeExactInOptions | SwidgeExactOutOptions);
177
+ export type SwidgeCommonOptions = {
178
+ /**
179
+ * - The provider-specific identifier or address of the source token.
180
+ */
181
+ fromToken: string;
182
+ /**
183
+ * - The provider-specific identifier or address of the destination token.
184
+ */
185
+ toToken: string;
186
+ /**
187
+ * - The identifier of the destination chain. If omitted, defaults to the source chain (same-chain swap).
188
+ */
189
+ toChain?: string | number | undefined;
190
+ /**
191
+ * - The address that will receive the output tokens.
192
+ */
193
+ recipient?: string | undefined;
194
+ /**
195
+ * - The address that will receive refunds if the tx cannot complete.
196
+ */
197
+ refundAddress?: string | undefined;
198
+ /**
199
+ * - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%).
200
+ */
201
+ slippage?: number | undefined;
202
+ };
203
+ export type SwidgeExactInOptions = {
204
+ /**
205
+ * - The exact amount of source tokens to spend (in base unit).
206
+ */
207
+ fromTokenAmount: number | bigint;
208
+ /**
209
+ * - Not applicable for exact-in operations.
210
+ */
211
+ toTokenAmount?: undefined;
212
+ };
213
+ export type SwidgeExactOutOptions = {
214
+ /**
215
+ * - Not applicable for exact-out operations.
216
+ */
217
+ fromTokenAmount?: undefined;
218
+ /**
219
+ * - The exact amount of destination tokens to receive (in base unit).
220
+ */
221
+ toTokenAmount: number | bigint;
222
+ };
223
+ export type SwidgeFee = {
224
+ /**
225
+ * - The category of the fee.
226
+ */
227
+ type: SwidgeFeeType;
228
+ /**
229
+ * - The fee amount in base units.
230
+ */
231
+ amount: bigint;
232
+ /**
233
+ * - The token in which the fee is denominated.
234
+ */
235
+ token: string;
236
+ /**
237
+ * - The chain on which the fee is charged.
238
+ */
239
+ chain?: string | number | undefined;
240
+ /**
241
+ * - Whether the fee is already included in the quoted amounts.
242
+ */
243
+ included?: boolean | undefined;
244
+ /**
245
+ * - A human-readable description of the fee.
246
+ */
247
+ description?: string | undefined;
248
+ };
249
+ export type SwidgeTransaction = {
250
+ /**
251
+ * - The transaction hash.
252
+ */
253
+ hash: string;
254
+ /**
255
+ * - The chain on which the transaction occurred.
256
+ */
257
+ chain?: string | number | undefined;
258
+ /**
259
+ * - The role of the transaction within the swidge.
260
+ */
261
+ type?: "other" | "source" | "destination" | "approval" | "refund" | undefined;
262
+ };
263
+ export type SwidgeQuote = {
264
+ /**
265
+ * - The amount of source tokens to spend.
266
+ */
267
+ fromTokenAmount: bigint;
268
+ /**
269
+ * - The estimated amount of destination tokens to receive.
270
+ */
271
+ toTokenAmount: bigint;
272
+ /**
273
+ * - The minimum guaranteed amount after slippage.
274
+ */
275
+ toTokenAmountMin: bigint;
276
+ /**
277
+ * - Itemised fee breakdown.
278
+ */
279
+ fees: SwidgeFee[];
280
+ /**
281
+ * - Estimated duration in seconds.
282
+ */
283
+ estimatedDuration?: number | undefined;
284
+ /**
285
+ * - Unix timestamp (seconds) at which the quote expires.
286
+ */
287
+ expiry?: number | undefined;
288
+ /**
289
+ * - Provider-reported estimated price impact as a decimal (e.g., 0.01 for 1%).
290
+ */
291
+ priceImpact?: number | undefined;
292
+ };
293
+ export type SwidgeResult = {
294
+ /**
295
+ * - The unique swidge execution identifier.
296
+ */
297
+ id: string;
298
+ /**
299
+ * - The primary transaction hash (if available immediately).
300
+ */
301
+ hash?: string | undefined;
302
+ /**
303
+ * - Itemised fee breakdown.
304
+ */
305
+ fees: SwidgeFee[];
306
+ /**
307
+ * - Transactions produced by the swidge execution.
308
+ */
309
+ transactions?: SwidgeTransaction[] | undefined;
310
+ /**
311
+ * - The actual amount of source tokens spent.
312
+ */
313
+ fromTokenAmount: bigint;
314
+ /**
315
+ * - The actual or expected amount of destination tokens.
316
+ */
317
+ toTokenAmount: bigint;
318
+ /**
319
+ * - The minimum guaranteed amount after slippage.
320
+ */
321
+ toTokenAmountMin?: bigint | undefined;
322
+ };
323
+ export type SwidgeStatusOptions = {
324
+ /**
325
+ * - The source chain identifier.
326
+ */
327
+ fromChain?: string | number | undefined;
328
+ /**
329
+ * - The destination chain identifier.
330
+ */
331
+ toChain?: string | number | undefined;
332
+ };
333
+ export type SwidgeStatusResult = {
334
+ /**
335
+ * - The current status of the swidge.
336
+ */
337
+ status: SwidgeStatus;
338
+ /**
339
+ * - Transactions associated with the swidge.
340
+ */
341
+ transactions?: SwidgeTransaction[] | undefined;
342
+ };
343
+ export type SwidgeSupportedChain = {
344
+ /**
345
+ * - The provider-specific chain identifier.
346
+ */
347
+ id: string | number;
348
+ /**
349
+ * - The human-readable chain name.
350
+ */
351
+ name: string;
352
+ /**
353
+ * - The chain or virtual machine type (e.g., 'evm', 'svm', 'utxo').
354
+ */
355
+ type: string;
356
+ /**
357
+ * - The symbol of the chain's native token.
358
+ */
359
+ nativeToken: string;
360
+ };
361
+ export type SwidgeSupportedToken = {
362
+ /**
363
+ * - The provider-specific token identifier to use in swidge operations.
364
+ */
365
+ token: string;
366
+ /**
367
+ * - The chain on which the token is available.
368
+ */
369
+ chain: string | number;
370
+ /**
371
+ * - The token symbol.
372
+ */
373
+ symbol: string;
374
+ /**
375
+ * - The number of decimal places for the token's base unit.
376
+ */
377
+ decimals: number;
378
+ /**
379
+ * - The token contract address, if applicable.
380
+ */
381
+ address?: string | undefined;
382
+ /**
383
+ * - The token's full name.
384
+ */
385
+ name?: string | undefined;
386
+ };
387
+ export type SwidgeSupportedTokensOptions = {
388
+ /**
389
+ * - The optional source chain for route-scoped discovery.
390
+ */
391
+ fromChain?: string | number | undefined;
392
+ /**
393
+ * - The optional source token for route-scoped discovery.
394
+ */
395
+ fromToken?: string | undefined;
396
+ /**
397
+ * - The optional destination chain for route-scoped discovery.
398
+ */
399
+ toChain?: string | number | undefined;
400
+ };
@@ -6,6 +6,15 @@ export interface IWalletAccountReadOnly {
6
6
  * @returns {Promise<string>} The account's address.
7
7
  */
8
8
  getAddress(): Promise<string>;
9
+ /**
10
+ * Verifies a message's signature.
11
+ *
12
+ * @param {string} message - The original message.
13
+ * @param {string} signature - The signature to verify.
14
+ * @returns {Promise<boolean>} True if the signature is valid.
15
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
16
+ */
17
+ verify(message: string, signature: string): Promise<boolean>;
9
18
  /**
10
19
  * Returns the account's native token balance.
11
20
  *
@@ -67,6 +76,16 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
67
76
  * @returns {Promise<string>} The account's address.
68
77
  */
69
78
  getAddress(): Promise<string>;
79
+ /**
80
+ * Verifies a message's signature.
81
+ *
82
+ * @abstract
83
+ * @param {string} message - The original message.
84
+ * @param {string} signature - The signature to verify.
85
+ * @returns {Promise<boolean>} True if the signature is valid.
86
+ * @throws {Error} If the read-only wallet account class is not able to provide an implementation for the method.
87
+ */
88
+ abstract verify(message: string, signature: string): Promise<boolean>;
70
89
  /**
71
90
  * Returns the account's native token balance.
72
91
  *
@@ -25,6 +25,13 @@ export interface IWalletAccount extends IWalletAccountReadOnly {
25
25
  * @returns {Promise<string>} The message's signature.
26
26
  */
27
27
  sign(message: string): Promise<string>;
28
+ /**
29
+ * Signs a transaction.
30
+ *
31
+ * @param {Transaction} tx - The transaction to sign.
32
+ * @returns {Promise<unknown>} The signed transaction.
33
+ */
34
+ signTransaction(tx: Transaction): Promise<unknown>;
28
35
  /**
29
36
  * Verifies a message's signature.
30
37
  *
@@ -3,9 +3,10 @@ export default abstract class WalletManager {
3
3
  /**
4
4
  * Returns a random [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
5
5
  *
6
+ * @param {12 | 24} [wordCount=12] - The number of words in the seed phrase.
6
7
  * @returns {string} The seed phrase.
7
8
  */
8
- static getRandomSeedPhrase(): string;
9
+ static getRandomSeedPhrase(wordCount?: 12 | 24): string;
9
10
  /**
10
11
  * Checks if a seed phrase is valid.
11
12
  *
@@ -78,6 +79,10 @@ export type WalletConfig = {
78
79
  * - The maximum fee amount for transfer operations.
79
80
  */
80
81
  transferMaxFee?: number | bigint;
82
+ /**
83
+ * - The maximum fee amount for sendTransaction and signTransaction operations.
84
+ */
85
+ transactionMaxFee?: number | bigint;
81
86
  };
82
87
  export type FeeRates = {
83
88
  /**