@tetherto/wdk-wallet 1.0.0-beta.16 → 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.
Files changed (45) hide show
  1. package/index.js +11 -12
  2. package/package.json +1 -1
  3. package/src/errors.js +280 -19
  4. package/src/multisig/errors.js +54 -0
  5. package/src/multisig/index.js +15 -3
  6. package/src/multisig/multisig-message-signing-read-only.js +63 -0
  7. package/src/multisig/multisig-message-signing.js +64 -0
  8. package/src/multisig/multisig-owner-management.js +22 -5
  9. package/src/multisig/wallet-account-multisig.js +28 -39
  10. package/src/multisig/wallet-account-read-only-multisig.js +20 -34
  11. package/src/protocols/bridge-protocol.js +35 -1
  12. package/src/protocols/errors.js +510 -0
  13. package/src/protocols/fiat-protocol.js +104 -4
  14. package/src/protocols/index.js +13 -0
  15. package/src/protocols/lending-protocol.js +114 -2
  16. package/src/protocols/sda-protocol.js +103 -16
  17. package/src/protocols/swap-protocol.js +35 -1
  18. package/src/protocols/swidge-protocol.js +166 -55
  19. package/src/signer.js +8 -4
  20. package/src/wallet-account-read-only-simple.js +86 -1
  21. package/src/wallet-account-read-only.js +175 -6
  22. package/src/wallet-account.js +25 -1
  23. package/src/wallet-manager.js +38 -22
  24. package/types/index.d.ts +9 -2
  25. package/types/src/errors.d.ts +198 -14
  26. package/types/src/multisig/errors.d.ts +33 -0
  27. package/types/src/multisig/index.d.ts +7 -3
  28. package/types/src/multisig/multisig-message-signing-read-only.d.ts +53 -0
  29. package/types/src/multisig/multisig-message-signing.d.ts +40 -0
  30. package/types/src/multisig/multisig-owner-management.d.ts +20 -4
  31. package/types/src/multisig/wallet-account-multisig.d.ts +29 -35
  32. package/types/src/multisig/wallet-account-read-only-multisig.d.ts +20 -40
  33. package/types/src/protocols/bridge-protocol.d.ts +39 -3
  34. package/types/src/protocols/errors.d.ts +366 -0
  35. package/types/src/protocols/fiat-protocol.d.ts +103 -9
  36. package/types/src/protocols/index.d.ts +11 -0
  37. package/types/src/protocols/lending-protocol.d.ts +118 -4
  38. package/types/src/protocols/sda-protocol.d.ts +120 -23
  39. package/types/src/protocols/swap-protocol.d.ts +40 -4
  40. package/types/src/protocols/swidge-protocol.d.ts +106 -38
  41. package/types/src/signer.d.ts +6 -4
  42. package/types/src/wallet-account-read-only-simple.d.ts +99 -1
  43. package/types/src/wallet-account-read-only.d.ts +95 -3
  44. package/types/src/wallet-account.d.ts +27 -3
  45. package/types/src/wallet-manager.d.ts +37 -35
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { IWalletAccountReadOnlyMultisig } from './wallet-account-read-only-multisig.js'
17
17
 
18
- import { NotImplementedError } from '../errors.js'
18
+ import { NotImplementedError } from './errors.js'
19
19
 
20
20
  /** @typedef {import('../wallet-account-read-only.js').Transaction} Transaction */
21
21
  /** @typedef {import('../wallet-account-read-only.js').TransactionResult} TransactionResult */
@@ -23,10 +23,15 @@ import { NotImplementedError } from '../errors.js'
23
23
  /** @typedef {import('../wallet-account.js').KeyPair} KeyPair */
24
24
 
25
25
  /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigProposal} MultisigProposal */
26
- /** @typedef {import('./wallet-account-read-only-multisig.js').MultisigMessageProposal} MultisigMessageProposal */
27
26
 
28
- /** @typedef {import('../errors.js').NoSuchElementError} NoSuchElementError */
29
- /** @typedef {import('../errors.js').ValueError} ValueError */
27
+ /** @typedef {import('./errors.js').AccountNotOwnerError} AccountNotOwnerError */
28
+ /** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
29
+ /** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
30
+ /** @typedef {import('./errors.js').ProviderError} ProviderError */
31
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
32
+ /** @typedef {import('./errors.js').TransactionError} TransactionError */
33
+ /** @typedef {import('./errors.js').ThresholdNotMetError} ThresholdNotMetError */
34
+ /** @typedef {import('./errors.js').ValueError} ValueError */
30
35
 
31
36
  /**
32
37
  * @typedef {Object} MultisigTransactionOptions
@@ -38,11 +43,6 @@ import { NotImplementedError } from '../errors.js'
38
43
  * @property {TransactionResult} [transaction] - If auto execute is set to true and the method call triggers the execution of the proposal, this field is set to the corresponding transaction's result (i.e., hash and fee).
39
44
  */
40
45
 
41
- /**
42
- * @typedef {Object} MultisigSignature
43
- * @property {string} signature - The caller's signature.
44
- */
45
-
46
46
  /** @interface */
47
47
  export class IWalletAccountMultisig extends IWalletAccountReadOnlyMultisig {
48
48
  /**
@@ -88,43 +88,24 @@ export class IWalletAccountMultisig extends IWalletAccountReadOnlyMultisig {
88
88
  *
89
89
  * @param {Transaction} tx - The transaction.
90
90
  * @param {MultisigTransactionOptions} [transactionOptions] - The multisig transaction's options.
91
- * @returns {Promise<MultisigProposal & MultisigAutoExecuteResult>} The created proposal; its `status` is `'executed'` when `autoExecute` ran to completion, otherwise `'pending'`.
92
- * @throws {Error} If the account is not an owner of the multisig wallet.
91
+ * @returns {Promise<MultisigProposal>} The created proposal; its `status` is `'executed'` when `autoExecute` ran to completion, otherwise `'pending'`.
92
+ * @throws {ValueError} If the transaction is not valid.
93
+ * @throws {ProviderRequiredError} If the method requires a provider.
94
+ * @throws {ProviderError} If the provider fails to propose the transaction.
95
+ * @throws {AccountNotOwnerError} If the account is not an owner of the multisig wallet.
93
96
  */
94
97
  async propose (tx, transactionOptions) {
95
98
  throw new NotImplementedError('propose(tx, transactionOptions)')
96
99
  }
97
100
 
98
- /**
99
- * Proposes signing a message.
100
- *
101
- * @param {string} message - The message to sign.
102
- * @returns {Promise<MultisigMessageProposal & MultisigSignature>} The multisig message proposal.
103
- * @throws {Error} If the account is not an owner of the multisig wallet.
104
- */
105
- async proposeMessage (message) {
106
- throw new NotImplementedError('proposeMessage(message)')
107
- }
108
-
109
- /**
110
- * Approves an existing message proposal.
111
- *
112
- * @param {string} messageId - The message's hash.
113
- * @returns {Promise<MultisigMessageProposal & MultisigSignature>} The multisig message proposal.
114
- * @throws {Error} If the account is not an owner of the multisig wallet.
115
- * @throws {NoSuchElementError} If no message exists for the given id.
116
- */
117
- async approveMessageProposal (messageId) {
118
- throw new NotImplementedError('approveMessageProposal(messageId)')
119
- }
120
-
121
101
  /**
122
102
  * Approves a pending proposal.
123
103
  *
124
104
  * @param {string} proposalId - The proposal's id.
125
- * @returns {Promise<MultisigProposal & MultisigAutoExecuteResult>} The multisig proposal.
126
- * @throws {Error} If the account is not an owner of the multisig wallet.
127
- * @throws {NoSuchElementError} If no proposal exists for the given id.
105
+ * @returns {Promise<MultisigProposal>} The multisig proposal.
106
+ * @throws {ValueError} If the proposal's identifier is not a valid id.
107
+ * @throws {NoSuchElementError} If no message exists for the given id.
108
+ * @throws {AccountNotOwnerError} If the account is not an owner of the multisig wallet.
128
109
  */
129
110
  async approveProposal (proposalId) {
130
111
  throw new NotImplementedError('approveProposal(proposalId)')
@@ -135,7 +116,9 @@ export class IWalletAccountMultisig extends IWalletAccountReadOnlyMultisig {
135
116
  *
136
117
  * @param {string} proposalId - The proposal's id.
137
118
  * @returns {Promise<MultisigProposal>} The multisig proposal.
138
- * @throws {NoSuchElementError} If no proposal exists for the given id.
119
+ * @throws {ValueError} If the proposal's identifier is not a valid id.
120
+ * @throws {NoSuchElementError} If no message exists for the given id.
121
+ * @throws {AccountNotOwnerError} If the account is not an owner of the multisig wallet.
139
122
  */
140
123
  async rejectProposal (proposalId) {
141
124
  throw new NotImplementedError('rejectProposal(proposalId)')
@@ -146,8 +129,14 @@ export class IWalletAccountMultisig extends IWalletAccountReadOnlyMultisig {
146
129
  *
147
130
  * @param {string} proposalId - The proposal's id.
148
131
  * @returns {Promise<TransactionResult>} The on-chain transaction's result.
132
+ * @throws {ValueError} If the proposal's identifier is not a valid id.
149
133
  * @throws {NoSuchElementError} If no proposal exists for the given id.
150
- * @throws {ValueError} If the proposal has not reached the approval threshold.
134
+ * @throws {ProviderRequiredError} If the method requires a provider.
135
+ * @throws {ProviderError} If the provider fails to execute the proposal.
136
+ * @throws {TransactionError} If the transaction fails with an error.
137
+ * @throws {AccountNotOwnerError} If the account is not an owner of the multisig wallet.
138
+ * @throws {ThresholdNotMetError} If the proposal's threshold has not been met yet.
139
+ * @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the transaction max. fee option.
151
140
  */
152
141
  async executeProposal (proposalId) {
153
142
  throw new NotImplementedError('executeProposal(proposalId)')
@@ -15,12 +15,16 @@
15
15
 
16
16
  import { IWalletAccountReadOnlySimple } from '../wallet-account-read-only-simple.js'
17
17
 
18
- import { NotImplementedError } from '../errors.js'
19
-
20
- /** @typedef {import('../errors.js').NoSuchElementError} NoSuchElementError */
18
+ import { NotImplementedError } from './errors.js'
21
19
 
22
20
  /** @typedef {import('../wallet-account-read-only.js').TransactionResult} TransactionResult */
23
21
 
22
+ /** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
23
+ /** @typedef {import('./errors.js').ProviderError} ProviderError */
24
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
25
+ /** @typedef {import('./errors.js').TransactionError} TransactionError */
26
+ /** @typedef {import('./errors.js').ValueError} ValueError */
27
+
24
28
  /**
25
29
  * @typedef {Object} MultisigInfo
26
30
  * @property {string} address - The multisig wallet account address.
@@ -37,21 +41,14 @@ import { NotImplementedError } from '../errors.js'
37
41
  * @property {'pending' | 'executed'} status - The proposal's lifecycle state: `'pending'` while it still awaits confirmations or on-chain execution, `'executed'` once it has been executed on-chain.
38
42
  */
39
43
 
40
- /**
41
- * @typedef {Object} MultisigMessageProposal
42
- * @property {string} messageId - The message's hash.
43
- * @property {string} message - The original message.
44
- * @property {number} confirmations - The current number of confirmations.
45
- * @property {number} threshold - The minimum amount of confirmations to sign the message.
46
- * @property {string | null} combinedSignature - The final combined signature when the threshold is met.
47
- */
48
-
49
44
  /** @interface */
50
45
  export class IWalletAccountReadOnlyMultisig extends IWalletAccountReadOnlySimple {
51
46
  /**
52
47
  * Returns the multisig wallet account info.
53
48
  *
54
49
  * @returns {Promise<MultisigInfo>} The info.
50
+ * @throws {ProviderRequiredError} If the method requires a provider.
51
+ * @throws {ProviderError} If the provider fails to fetch the multisig wallet's info.
55
52
  */
56
53
  async getMultisigInfo () {
57
54
  throw new NotImplementedError('getMultisigInfo()')
@@ -60,9 +57,12 @@ export class IWalletAccountReadOnlyMultisig extends IWalletAccountReadOnlySimple
60
57
  /**
61
58
  * Returns a list of proposals by their identifiers.
62
59
  *
63
- * @param {string[]} proposalIds - The list of proposal identifiers.
60
+ * @param {string[]} proposalIds - The list of proposal's identifiers.
64
61
  * @returns {Promise<Record<string, MultisigProposal | null>>} For each proposal id, the proposal details or
65
62
  * null if the proposal has not been found.
63
+ * @throws {ValueError} If the list of proposal's identifiers contains an invalid id.
64
+ * @throws {ProviderRequiredError} If the method requires a provider.
65
+ * @throws {ProviderError} If the provider fails to fetch the proposals.
66
66
  */
67
67
  async getProposals (proposalIds) {
68
68
  throw new NotImplementedError('getProposals(proposalIds)')
@@ -73,38 +73,24 @@ export class IWalletAccountReadOnlyMultisig extends IWalletAccountReadOnlySimple
73
73
  *
74
74
  * @param {string} proposalId - The proposal's identifier.
75
75
  * @returns {Promise<MultisigProposal | null>} The proposal details, or null if it has not been found.
76
+ * @throws {ValueError} If the proposal's identifier is not a valid id.
77
+ * @throws {ProviderRequiredError} If the method requires a provider.
78
+ * @throws {ProviderError} If the provider fails to fetch the proposal.
76
79
  */
77
80
  async getProposal (proposalId) {
78
81
  throw new NotImplementedError('getProposal(proposalId)')
79
82
  }
80
83
 
81
- /**
82
- * Returns a list of message proposals by their hashes.
83
- *
84
- * @param {string[]} messageIds - The list of message hashes
85
- * @returns {Promise<Record<string, MultisigMessageProposal | null>>} For each message hash, the message details or
86
- * null if the message has not been found.
87
- */
88
- async getMessageProposals (messageIds) {
89
- throw new NotImplementedError('getMessageProposals(messageIds)')
90
- }
91
-
92
- /**
93
- * Returns a message proposal by its identifier.
94
- *
95
- * @param {string} messageId - The message's hash.
96
- * @returns {Promise<MultisigMessageProposal | null>} The message details, or null if it has not been found.
97
- */
98
- async getMessageProposal (messageId) {
99
- throw new NotImplementedError('getMessageProposal(messageId)')
100
- }
101
-
102
84
  /**
103
85
  * Quotes the on-chain cost of executing a pending proposal.
104
86
  *
105
87
  * @param {string} proposalId - The proposal's id.
106
88
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The execution cost estimate.
89
+ * @throws {ValueError} If the proposal's identifier is not a valid id.
107
90
  * @throws {NoSuchElementError} If no proposal exists for the given id.
91
+ * @throws {ProviderRequiredError} If the method requires a provider.
92
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
93
+ * @throws {TransactionError} If the transaction fails with an error.
108
94
  */
109
95
  async quoteExecuteProposal (proposalId) {
110
96
  throw new NotImplementedError('quoteExecuteProposal(proposalId)')
@@ -13,12 +13,21 @@
13
13
  // limitations under the License.
14
14
  'use strict'
15
15
 
16
- import { NotImplementedError } from '../errors.js'
16
+ import { NotImplementedError } from './errors.js'
17
17
 
18
18
  /** @typedef {import('../wallet-account-read-only.js').IWalletAccountReadOnly} IWalletAccountReadOnly */
19
19
 
20
20
  /** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
21
21
 
22
+ /** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
23
+ /** @typedef {import('./errors.js').BridgeError} BridgeError */
24
+ /** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
25
+ /** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
26
+ /** @typedef {import('./errors.js').ReadOnlyAccountRequiredError} ReadOnlyAccountRequiredError */
27
+ /** @typedef {import('./errors.js').ProviderError} ProviderError */
28
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
29
+ /** @typedef {import('./errors.js').ValueError} ValueError */
30
+
22
31
  /**
23
32
  * @typedef {Object} BridgeProtocolConfig
24
33
  * @property {number | bigint} [bridgeMaxFee] - The maximum fee amount for bridge operations.
@@ -46,6 +55,13 @@ export class IBridgeProtocol {
46
55
  *
47
56
  * @param {BridgeOptions} options - The bridge's options.
48
57
  * @returns {Promise<BridgeResult>} The bridge's result.
58
+ * @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
59
+ * @throws {ValueError} If the bridge options are not valid.
60
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
61
+ * @throws {ProviderRequiredError} If the method requires a provider.
62
+ * @throws {ProviderError} If the provider fails to perform the bridge.
63
+ * @throws {BridgeError} If the bridge fails with an error.
64
+ * @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the bridge max. fee option.
49
65
  */
50
66
  async bridge (options) {
51
67
  throw new NotImplementedError('bridge(options)')
@@ -56,6 +72,12 @@ export class IBridgeProtocol {
56
72
  *
57
73
  * @param {BridgeOptions} options - The bridge's options.
58
74
  * @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
75
+ * @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swap.
76
+ * @throws {ValueError} If the bridge options are not valid.
77
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
78
+ * @throws {ProviderRequiredError} If the method requires a provider.
79
+ * @throws {ProviderError} If the provider fails to perform the bridge.
80
+ * @throws {BridgeError} If the bridge fails with an error.
59
81
  */
60
82
  async quoteBridge (options) {
61
83
  throw new NotImplementedError('quoteBridge(options)')
@@ -106,6 +128,13 @@ export default class BridgeProtocol {
106
128
  * @abstract
107
129
  * @param {BridgeOptions} options - The bridge's options.
108
130
  * @returns {Promise<BridgeResult>} The bridge's result.
131
+ * @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
132
+ * @throws {ValueError} If the bridge options are not valid.
133
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
134
+ * @throws {ProviderRequiredError} If the method requires a provider.
135
+ * @throws {ProviderError} If the provider fails to perform the bridge.
136
+ * @throws {BridgeError} If the bridge fails with an error.
137
+ * @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the bridge max. fee option.
109
138
  */
110
139
  async bridge (options) {
111
140
  throw new NotImplementedError('bridge(options)')
@@ -117,6 +146,11 @@ export default class BridgeProtocol {
117
146
  * @abstract
118
147
  * @param {BridgeOptions} options - The bridge's options.
119
148
  * @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
149
+ * @throws {ValueError} If the bridge options are not valid.
150
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
151
+ * @throws {ProviderRequiredError} If the method requires a provider.
152
+ * @throws {ProviderError} If the provider fails to perform the bridge.
153
+ * @throws {BridgeError} If the bridge fails with an error.
120
154
  */
121
155
  async quoteBridge (options) {
122
156
  throw new NotImplementedError('quoteBridge(options)')