@tetherto/wdk-wallet 1.0.0-beta.15 → 1.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -12
- package/package.json +5 -1
- package/src/errors.js +280 -19
- package/src/multisig/errors.js +54 -0
- package/src/multisig/index.js +42 -0
- package/src/multisig/multisig-message-signing-read-only.js +63 -0
- package/src/multisig/multisig-message-signing.js +64 -0
- package/src/multisig/multisig-owner-management.js +94 -0
- package/src/multisig/wallet-account-multisig.js +144 -0
- package/src/multisig/wallet-account-read-only-multisig.js +98 -0
- package/src/protocols/bridge-protocol.js +35 -1
- package/src/protocols/errors.js +510 -0
- package/src/protocols/fiat-protocol.js +104 -4
- package/src/protocols/index.js +13 -0
- package/src/protocols/lending-protocol.js +114 -2
- package/src/protocols/sda-protocol.js +103 -16
- package/src/protocols/swap-protocol.js +35 -1
- package/src/protocols/swidge-protocol.js +166 -55
- package/src/signer.js +8 -4
- package/src/wallet-account-read-only-simple.js +162 -0
- package/src/wallet-account-read-only.js +176 -55
- package/src/wallet-account.js +25 -1
- package/src/wallet-manager.js +38 -22
- package/types/index.d.ts +9 -2
- package/types/src/errors.d.ts +198 -14
- package/types/src/multisig/errors.d.ts +33 -0
- package/types/src/multisig/index.d.ts +15 -0
- package/types/src/multisig/multisig-message-signing-read-only.d.ts +53 -0
- package/types/src/multisig/multisig-message-signing.d.ts +40 -0
- package/types/src/multisig/multisig-owner-management.d.ts +65 -0
- package/types/src/multisig/wallet-account-multisig.d.ts +101 -0
- package/types/src/multisig/wallet-account-read-only-multisig.d.ts +83 -0
- package/types/src/protocols/bridge-protocol.d.ts +39 -3
- package/types/src/protocols/errors.d.ts +366 -0
- package/types/src/protocols/fiat-protocol.d.ts +103 -9
- package/types/src/protocols/index.d.ts +11 -0
- package/types/src/protocols/lending-protocol.d.ts +118 -4
- package/types/src/protocols/sda-protocol.d.ts +120 -23
- package/types/src/protocols/swap-protocol.d.ts +40 -4
- package/types/src/protocols/swidge-protocol.d.ts +106 -38
- package/types/src/signer.d.ts +6 -4
- package/types/src/wallet-account-read-only-simple.d.ts +144 -0
- package/types/src/wallet-account-read-only.d.ts +97 -39
- package/types/src/wallet-account.d.ts +27 -3
- package/types/src/wallet-manager.d.ts +37 -35
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
-
import { NotImplementedError } from '
|
|
16
|
+
import { BridgeError, NotImplementedError, SwapError, SwidgeError } from './errors.js'
|
|
17
17
|
|
|
18
18
|
/** @typedef {import('../wallet-account-read-only.js').IWalletAccountReadOnly} IWalletAccountReadOnly */
|
|
19
19
|
|
|
@@ -27,6 +27,15 @@ import { NotImplementedError } from '../errors.js'
|
|
|
27
27
|
/** @typedef {import('./bridge-protocol.js').BridgeOptions} BridgeOptions */
|
|
28
28
|
/** @typedef {import('./bridge-protocol.js').BridgeResult} BridgeResult */
|
|
29
29
|
|
|
30
|
+
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
31
|
+
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
32
|
+
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
33
|
+
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
34
|
+
/** @typedef {import('./errors.js').ReadOnlyAccountRequiredError} ReadOnlyAccountRequiredError */
|
|
35
|
+
/** @typedef {import('./errors.js').ProviderError} ProviderError */
|
|
36
|
+
/** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
|
|
37
|
+
/** @typedef {import('./errors.js').ValueError} ValueError */
|
|
38
|
+
|
|
30
39
|
/**
|
|
31
40
|
* @typedef {'pending' | 'action-required' | 'completed' | 'failed'
|
|
32
41
|
* | 'refund-pending' | 'refunded' | 'cancelled' | 'expired' | 'partial'} SwidgeStatus
|
|
@@ -151,8 +160,8 @@ import { NotImplementedError } from '../errors.js'
|
|
|
151
160
|
|
|
152
161
|
/**
|
|
153
162
|
* @interface
|
|
154
|
-
* @
|
|
155
|
-
* @
|
|
163
|
+
* @extends {ISwapProtocol}
|
|
164
|
+
* @extends {IBridgeProtocol}
|
|
156
165
|
*/
|
|
157
166
|
export class ISwidgeProtocol {
|
|
158
167
|
/**
|
|
@@ -162,6 +171,12 @@ export class ISwidgeProtocol {
|
|
|
162
171
|
*
|
|
163
172
|
* @param {SwidgeOptions} options - The swidge options.
|
|
164
173
|
* @returns {Promise<SwidgeQuote>} The quoted swidge details.
|
|
174
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swidge.
|
|
175
|
+
* @throws {ValueError} If the swidge options are not valid.
|
|
176
|
+
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
177
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
178
|
+
* @throws {ProviderError} If the provider fails to perform the swidge.
|
|
179
|
+
* @throws {SwidgeError} If the swidge fails with an error.
|
|
165
180
|
*/
|
|
166
181
|
async quoteSwidge (options) {
|
|
167
182
|
throw new NotImplementedError('quoteSwidge(options)')
|
|
@@ -173,6 +188,13 @@ export class ISwidgeProtocol {
|
|
|
173
188
|
* @param {SwidgeOptions} options - The swidge options.
|
|
174
189
|
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
175
190
|
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
191
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
|
|
192
|
+
* @throws {ValueError} If the swidge options are not valid.
|
|
193
|
+
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
194
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
195
|
+
* @throws {ProviderError} If the provider fails to perform the swidge.
|
|
196
|
+
* @throws {SwidgeError} If the swidge fails with an error.
|
|
197
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the max. network or protocol fee options.
|
|
176
198
|
*/
|
|
177
199
|
async swidge (options, config) {
|
|
178
200
|
throw new NotImplementedError('swidge(options, config)')
|
|
@@ -184,7 +206,10 @@ export class ISwidgeProtocol {
|
|
|
184
206
|
* @param {string} id - The swidge execution identifier returned by swidge.
|
|
185
207
|
* @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
|
|
186
208
|
* @returns {Promise<SwidgeStatusResult>} The current swidge status.
|
|
187
|
-
* @throws {
|
|
209
|
+
* @throws {ValueError} If the id is not valid.
|
|
210
|
+
* @throws {NoSuchElementError} If no swidge exists for the given id.
|
|
211
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
212
|
+
* @throws {ProviderError} If the provider fails to fetch the swidge's status.
|
|
188
213
|
*/
|
|
189
214
|
async getSwidgeStatus (id, options) {
|
|
190
215
|
throw new NotImplementedError('getSwidgeStatus(id, options)')
|
|
@@ -194,6 +219,8 @@ export class ISwidgeProtocol {
|
|
|
194
219
|
* Retrieves the chains supported by the provider for swidge operations.
|
|
195
220
|
*
|
|
196
221
|
* @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
|
|
222
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
223
|
+
* @throws {ProviderError} If the provider fails to fetch the available blockchains.
|
|
197
224
|
*/
|
|
198
225
|
async getSupportedChains () {
|
|
199
226
|
throw new NotImplementedError('getSupportedChains()')
|
|
@@ -204,6 +231,8 @@ export class ISwidgeProtocol {
|
|
|
204
231
|
*
|
|
205
232
|
* @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
|
|
206
233
|
* @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
|
|
234
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
235
|
+
* @throws {ProviderError} If the provider fails to fetch the available tokens.
|
|
207
236
|
*/
|
|
208
237
|
async getSupportedTokens (options) {
|
|
209
238
|
throw new NotImplementedError('getSupportedTokens(options)')
|
|
@@ -263,19 +292,35 @@ export default class SwidgeProtocol {
|
|
|
263
292
|
*
|
|
264
293
|
* @param {SwapOptions} options - The swap's options.
|
|
265
294
|
* @returns {Promise<SwapResult>} The swap's result.
|
|
266
|
-
* @throws {
|
|
295
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
|
|
296
|
+
* @throws {ValueError} If the swap options are not valid.
|
|
297
|
+
* @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
|
|
298
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
299
|
+
* @throws {ProviderError} If the provider fails to perform the swap.
|
|
300
|
+
* @throws {SwapError} If the swap fails with an error.
|
|
301
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the max. network or protocol fee options.
|
|
267
302
|
*/
|
|
268
303
|
async swap (options) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
304
|
+
try {
|
|
305
|
+
const result = await this.swidge({
|
|
306
|
+
fromToken: options.tokenIn,
|
|
307
|
+
toToken: options.tokenOut,
|
|
308
|
+
recipient: options.to,
|
|
309
|
+
fromTokenAmount: options.tokenInAmount,
|
|
310
|
+
toTokenAmount: options.tokenOutAmount,
|
|
311
|
+
minAmountOut: options.minAmountOut
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
const fee = result.fees.reduce((acc, f) => acc + f.amount, 0n)
|
|
315
|
+
|
|
316
|
+
return { hash: result.id, fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount }
|
|
317
|
+
} catch (error) {
|
|
318
|
+
if (error instanceof SwidgeError) {
|
|
319
|
+
throw new SwapError(error.message, { reason: error.reason, cause: error })
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
throw error
|
|
323
|
+
}
|
|
279
324
|
}
|
|
280
325
|
|
|
281
326
|
/**
|
|
@@ -283,19 +328,34 @@ export default class SwidgeProtocol {
|
|
|
283
328
|
*
|
|
284
329
|
* @param {SwapOptions} options - The swap's options.
|
|
285
330
|
* @returns {Promise<Omit<SwapResult, 'hash'>>} The swap's quotes.
|
|
286
|
-
* @throws {
|
|
331
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swap.
|
|
332
|
+
* @throws {ValueError} If the swap options are not valid.
|
|
333
|
+
* @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
|
|
334
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
335
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the swap.
|
|
336
|
+
* @throws {SwapError} If the swap fails with an error.
|
|
287
337
|
*/
|
|
288
338
|
async quoteSwap (options) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
339
|
+
try {
|
|
340
|
+
const result = await this.quoteSwidge({
|
|
341
|
+
fromToken: options.tokenIn,
|
|
342
|
+
toToken: options.tokenOut,
|
|
343
|
+
recipient: options.to,
|
|
344
|
+
fromTokenAmount: options.tokenInAmount,
|
|
345
|
+
toTokenAmount: options.tokenOutAmount,
|
|
346
|
+
minAmountOut: options.minAmountOut
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
const fee = result.fees.reduce((acc, f) => acc + f.amount, 0n)
|
|
350
|
+
|
|
351
|
+
return { fee, tokenInAmount: result.fromTokenAmount, tokenOutAmount: result.toTokenAmount }
|
|
352
|
+
} catch (error) {
|
|
353
|
+
if (error instanceof SwidgeError) {
|
|
354
|
+
throw new SwapError(error.message, { reason: error.reason, cause: error })
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
throw error
|
|
358
|
+
}
|
|
299
359
|
}
|
|
300
360
|
|
|
301
361
|
/**
|
|
@@ -303,21 +363,38 @@ export default class SwidgeProtocol {
|
|
|
303
363
|
*
|
|
304
364
|
* @param {BridgeOptions} options - The bridge's options.
|
|
305
365
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
306
|
-
* @throws {
|
|
366
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
367
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
368
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
369
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
370
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
371
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
372
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the max. network or protocol fee options.
|
|
307
373
|
*/
|
|
308
374
|
async bridge (options) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
375
|
+
try {
|
|
376
|
+
const { id: hash, fees } = await this.swidge({
|
|
377
|
+
fromToken: options.token,
|
|
378
|
+
toToken: options.token,
|
|
379
|
+
toChain: options.targetChain,
|
|
380
|
+
recipient: options.recipient,
|
|
381
|
+
fromTokenAmount: options.amount
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
const fee = fees.filter(f => f.type === 'network')
|
|
385
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
386
|
+
|
|
387
|
+
const bridgeFee = fees.filter(f => f.type === 'protocol')
|
|
388
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
389
|
+
|
|
390
|
+
return { hash, fee, bridgeFee }
|
|
391
|
+
} catch (error) {
|
|
392
|
+
if (error instanceof SwidgeError) {
|
|
393
|
+
throw new BridgeError(error.message, { reason: error.reason, cause: error })
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
throw error
|
|
397
|
+
}
|
|
321
398
|
}
|
|
322
399
|
|
|
323
400
|
/**
|
|
@@ -325,21 +402,37 @@ export default class SwidgeProtocol {
|
|
|
325
402
|
*
|
|
326
403
|
* @param {BridgeOptions} options - The bridge's options.
|
|
327
404
|
* @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
|
|
328
|
-
* @throws {
|
|
405
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swap.
|
|
406
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
407
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
408
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
409
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
410
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
329
411
|
*/
|
|
330
412
|
async quoteBridge (options) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
413
|
+
try {
|
|
414
|
+
const { fees } = await this.quoteSwidge({
|
|
415
|
+
fromToken: options.token,
|
|
416
|
+
toToken: options.token,
|
|
417
|
+
toChain: options.targetChain,
|
|
418
|
+
recipient: options.recipient,
|
|
419
|
+
fromTokenAmount: options.amount
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
const fee = fees.filter(f => f.type === 'network')
|
|
423
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
424
|
+
|
|
425
|
+
const bridgeFee = fees.filter(f => f.type === 'protocol')
|
|
426
|
+
.reduce((acc, { amount }) => acc + amount, 0n)
|
|
427
|
+
|
|
428
|
+
return { fee, bridgeFee }
|
|
429
|
+
} catch (error) {
|
|
430
|
+
if (error instanceof SwidgeError) {
|
|
431
|
+
throw new BridgeError(error.message, { reason: error.reason, cause: error })
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
throw error
|
|
435
|
+
}
|
|
343
436
|
}
|
|
344
437
|
|
|
345
438
|
/**
|
|
@@ -350,7 +443,12 @@ export default class SwidgeProtocol {
|
|
|
350
443
|
* @abstract
|
|
351
444
|
* @param {SwidgeOptions} options - The swidge options.
|
|
352
445
|
* @returns {Promise<SwidgeQuote>} The quoted swidge details.
|
|
353
|
-
* @throws {
|
|
446
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swidge.
|
|
447
|
+
* @throws {ValueError} If the swidge options are not valid.
|
|
448
|
+
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
449
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
450
|
+
* @throws {ProviderError} If the provider fails to perform the swidge.
|
|
451
|
+
* @throws {SwidgeError} If the swidge fails with an error.
|
|
354
452
|
*/
|
|
355
453
|
async quoteSwidge (options) {
|
|
356
454
|
throw new NotImplementedError('quoteSwidge(options)')
|
|
@@ -363,7 +461,13 @@ export default class SwidgeProtocol {
|
|
|
363
461
|
* @param {SwidgeOptions} options - The swidge options.
|
|
364
462
|
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
365
463
|
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
366
|
-
* @throws {
|
|
464
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
|
|
465
|
+
* @throws {ValueError} If the swidge options are not valid.
|
|
466
|
+
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
467
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
468
|
+
* @throws {ProviderError} If the provider fails to perform the swidge.
|
|
469
|
+
* @throws {SwidgeError} If the swidge fails with an error.
|
|
470
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the max. network or protocol fee options.
|
|
367
471
|
*/
|
|
368
472
|
async swidge (options, config) {
|
|
369
473
|
throw new NotImplementedError('swidge(options, config)')
|
|
@@ -376,7 +480,10 @@ export default class SwidgeProtocol {
|
|
|
376
480
|
* @param {string} id - The swidge execution identifier returned by swidge.
|
|
377
481
|
* @param {SwidgeStatusOptions} [options] - Optional hints to assist provider lookups.
|
|
378
482
|
* @returns {Promise<SwidgeStatusResult>} The current swidge status.
|
|
379
|
-
* @throws {
|
|
483
|
+
* @throws {ValueError} If the id is not valid.
|
|
484
|
+
* @throws {NoSuchElementError} If no swidge exists for the given id.
|
|
485
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
486
|
+
* @throws {ProviderError} If the provider fails to fetch the swidge's status.
|
|
380
487
|
*/
|
|
381
488
|
async getSwidgeStatus (id, options) {
|
|
382
489
|
throw new NotImplementedError('getSwidgeStatus(id, options)')
|
|
@@ -387,6 +494,8 @@ export default class SwidgeProtocol {
|
|
|
387
494
|
*
|
|
388
495
|
* @abstract
|
|
389
496
|
* @returns {Promise<SwidgeSupportedChain[]>} The supported chains.
|
|
497
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
498
|
+
* @throws {ProviderError} If the provider fails to fetch the available blockchains.
|
|
390
499
|
*/
|
|
391
500
|
async getSupportedChains () {
|
|
392
501
|
throw new NotImplementedError('getSupportedChains()')
|
|
@@ -398,6 +507,8 @@ export default class SwidgeProtocol {
|
|
|
398
507
|
* @abstract
|
|
399
508
|
* @param {SwidgeSupportedTokensOptions} [options] - Optional filters for chain- or route-scoped token discovery.
|
|
400
509
|
* @returns {Promise<SwidgeSupportedToken[]>} The supported tokens.
|
|
510
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
511
|
+
* @throws {ProviderError} If the provider fails to fetch the available tokens.
|
|
401
512
|
*/
|
|
402
513
|
async getSupportedTokens (options) {
|
|
403
514
|
throw new NotImplementedError('getSupportedTokens(options)')
|
package/src/signer.js
CHANGED
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
import { NotImplementedError } from './errors.js'
|
|
17
17
|
|
|
18
|
+
/** @typedef {import('./errors.js').UnsupportedOperationError} UnsupportedOperationError */
|
|
19
|
+
/** @typedef {import('./errors.js').ValueError} ValueError */
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* A minimal, cross-chain signer interface.
|
|
20
23
|
*
|
|
@@ -24,12 +27,13 @@ export class ISigner {
|
|
|
24
27
|
/**
|
|
25
28
|
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
26
29
|
*
|
|
27
|
-
* @param {string}
|
|
30
|
+
* @param {string} path - The relative derivation path.
|
|
28
31
|
* @returns {Promise<ISigner>} The derived signer.
|
|
29
|
-
* @throws {
|
|
32
|
+
* @throws {UnsupportedOperationError} If the signer does not support account derivation.
|
|
33
|
+
* @throws {ValueError} If the path is not valid.
|
|
30
34
|
*/
|
|
31
|
-
async derive (
|
|
32
|
-
throw new NotImplementedError('derive(
|
|
35
|
+
async derive (path) {
|
|
36
|
+
throw new NotImplementedError('derive(path)')
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
'use strict'
|
|
15
|
+
|
|
16
|
+
import { NotImplementedError } from './errors.js'
|
|
17
|
+
|
|
18
|
+
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
19
|
+
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
20
|
+
/** @typedef {import('./errors.js').ProviderError} ProviderError */
|
|
21
|
+
/** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
|
|
22
|
+
/** @typedef {import('./errors.js').TimeoutError} TimeoutError */
|
|
23
|
+
/** @typedef {import('./errors.js').ValueError} ValueError */
|
|
24
|
+
/** @typedef {import('./errors.js').UnsupportedOperationError} UnsupportedOperationError */
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A normalized, cross-chain transaction finality level.
|
|
28
|
+
*
|
|
29
|
+
* - `pending`: seen, not settled (mempool / processed / in-flight).
|
|
30
|
+
* - `confirmed`: settled, reversible only under extreme conditions.
|
|
31
|
+
* - `final`: irreversible per the chain's own guarantees.
|
|
32
|
+
* - `dropped`: evicted / replaced, never landed.
|
|
33
|
+
*
|
|
34
|
+
* @typedef {'pending' | 'confirmed' | 'final' | 'dropped'} Finality
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A normalized, cross-chain transaction receipt. Blockchain modules extend this
|
|
39
|
+
* type with their own native receipt fields (e.g. `confirmations`, the raw
|
|
40
|
+
* transaction and receipt objects, etc.).
|
|
41
|
+
*
|
|
42
|
+
* @typedef {Object} TransactionReceipt
|
|
43
|
+
* @property {string} hash - The transaction's identifier (hash / signature / lt:hash).
|
|
44
|
+
* @property {Finality} finality - The transaction's finality level.
|
|
45
|
+
* @property {boolean} [success] - The execution's result (not set if the transaction is still pending or it has been dropped).
|
|
46
|
+
* @property {number} [block] - A reference to the including block (block number / height / slot / masterchain seqno).
|
|
47
|
+
* @property {bigint} [fee] - The fee paid, when known.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The finality level to wait for.
|
|
52
|
+
*
|
|
53
|
+
* @typedef {'confirmed' | 'final'} WaitForTransactionTarget
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {Object} WaitForTransactionOptions
|
|
58
|
+
* @property {WaitForTransactionTarget} [target] - The finality target to wait for (default: 'confirmed').
|
|
59
|
+
* @property {number} [timeout] - The total time budget in milliseconds before giving up. If omitted, the account's `defaultWaitTimeout` is used.
|
|
60
|
+
* @property {number} [interval] - The poll cadence in milliseconds. If omitted, the account's `defaultWaitInterval` is used.
|
|
61
|
+
* @property {number} [maxPollErrors] - How many consecutive getTransaction() failures to tolerate before rethrowing (default: 3).
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The read-only members shared by every wallet account, single-signer or multisig.
|
|
66
|
+
*
|
|
67
|
+
* This is an internal base interface: it is not exported from the package entry point.
|
|
68
|
+
* Consumers use {@link IWalletAccountReadOnly} or {@link IWalletAccountReadOnlyMultisig},
|
|
69
|
+
* which both extend it.
|
|
70
|
+
*
|
|
71
|
+
* @interface
|
|
72
|
+
*/
|
|
73
|
+
export class IWalletAccountReadOnlySimple {
|
|
74
|
+
/**
|
|
75
|
+
* Returns the account's address.
|
|
76
|
+
*
|
|
77
|
+
* @returns {Promise<string>} The account's address.
|
|
78
|
+
*/
|
|
79
|
+
async getAddress () {
|
|
80
|
+
throw new NotImplementedError('getAddress()')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Verifies a message's signature.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} message - The original message.
|
|
87
|
+
* @param {string} signature - The signature to verify.
|
|
88
|
+
* @returns {Promise<boolean>} True if the signature is valid.
|
|
89
|
+
* @throws {UnsupportedOperationError} If the read-only wallet account class is not able to provide an implementation for the method.
|
|
90
|
+
*/
|
|
91
|
+
async verify (message, signature) {
|
|
92
|
+
throw new NotImplementedError('verify(message, signature)')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Returns the account's native token balance.
|
|
97
|
+
*
|
|
98
|
+
* @returns {Promise<bigint>} The native token balance.
|
|
99
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
100
|
+
* @throws {ProviderError} If the provider fails to fetch the account's balance.
|
|
101
|
+
*/
|
|
102
|
+
async getBalance () {
|
|
103
|
+
throw new NotImplementedError('getBalance()')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns the account balance for a specific token.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} tokenAddress - The smart contract address of the token.
|
|
110
|
+
* @returns {Promise<bigint>} The token balance.
|
|
111
|
+
* @throws {ValueError} If the token's address is not valid.
|
|
112
|
+
* @throws {InvalidTokenError} If the token's address doesn't match an existing ERC 20 token.
|
|
113
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
114
|
+
* @throws {ProviderError} If the provider fails to fetch the account's token balance.
|
|
115
|
+
*/
|
|
116
|
+
async getTokenBalance (tokenAddress) {
|
|
117
|
+
throw new NotImplementedError('getTokenBalance(tokenAddress)')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns a transaction's receipt.
|
|
122
|
+
*
|
|
123
|
+
* @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The native receipt fields remain available on each module's extended return type.
|
|
124
|
+
* @param {string} hash - The transaction's hash.
|
|
125
|
+
* @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
|
|
126
|
+
* @throws {ValueError} If the hash is not valid.
|
|
127
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
128
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction's receipt.
|
|
129
|
+
*/
|
|
130
|
+
async getTransactionReceipt (hash) {
|
|
131
|
+
throw new NotImplementedError('getTransactionReceipt(hash)')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns a normalized, finality-based receipt for a transaction.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} hash - The transaction's identifier (hash / signature / lt:hash).
|
|
138
|
+
* @returns {Promise<TransactionReceipt>} The normalized receipt.
|
|
139
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
140
|
+
* @throws {NoSuchElementError} If no transaction has been found for the given hash.
|
|
141
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
142
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
143
|
+
*/
|
|
144
|
+
async getTransaction (hash) {
|
|
145
|
+
throw new NotImplementedError('getTransaction(hash)')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} hash - The transaction's identifier.
|
|
152
|
+
* @param {WaitForTransactionOptions} [options] - The wait options.
|
|
153
|
+
* @returns {Promise<TransactionReceipt>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
|
|
154
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
155
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
156
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
157
|
+
* @throws {TimeoutError} If the operation times out.
|
|
158
|
+
*/
|
|
159
|
+
async waitForTransaction (hash, options) {
|
|
160
|
+
throw new NotImplementedError('waitForTransaction(hash, options)')
|
|
161
|
+
}
|
|
162
|
+
}
|