@tetherto/wdk-wallet 1.0.0-beta.16 → 1.0.0-beta.18
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 +1 -1
- package/src/errors.js +280 -19
- package/src/multisig/errors.js +54 -0
- package/src/multisig/index.js +15 -3
- 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 +22 -5
- package/src/multisig/wallet-account-multisig.js +26 -37
- package/src/multisig/wallet-account-read-only-multisig.js +20 -34
- 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 +86 -1
- package/src/wallet-account-read-only.js +175 -6
- 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 +7 -3
- 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 +20 -4
- package/types/src/multisig/wallet-account-multisig.d.ts +27 -33
- package/types/src/multisig/wallet-account-read-only-multisig.d.ts +20 -40
- 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 +99 -1
- package/types/src/wallet-account-read-only.d.ts +95 -3
- package/types/src/wallet-account.d.ts +27 -3
- package/types/src/wallet-manager.d.ts +37 -35
|
@@ -5,6 +5,13 @@ export interface IBridgeProtocol {
|
|
|
5
5
|
*
|
|
6
6
|
* @param {BridgeOptions} options - The bridge's options.
|
|
7
7
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
8
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
9
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
10
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
11
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
12
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
13
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
14
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the bridge max. fee option.
|
|
8
15
|
*/
|
|
9
16
|
bridge(options: BridgeOptions): Promise<BridgeResult>;
|
|
10
17
|
/**
|
|
@@ -12,10 +19,19 @@ export interface IBridgeProtocol {
|
|
|
12
19
|
*
|
|
13
20
|
* @param {BridgeOptions} options - The bridge's options.
|
|
14
21
|
* @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
|
|
22
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a swap.
|
|
23
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
24
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
25
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
26
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
27
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
15
28
|
*/
|
|
16
29
|
quoteBridge(options: BridgeOptions): Promise<Omit<BridgeResult, "hash">>;
|
|
17
30
|
}
|
|
18
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* @abstract
|
|
33
|
+
* @implements {IBridgeProtocol}
|
|
34
|
+
*/
|
|
19
35
|
export default abstract class BridgeProtocol implements IBridgeProtocol {
|
|
20
36
|
/**
|
|
21
37
|
* Creates a new read-only bridge protocol.
|
|
@@ -37,9 +53,9 @@ export default abstract class BridgeProtocol implements IBridgeProtocol {
|
|
|
37
53
|
* The wallet account to use to interact with the protocol.
|
|
38
54
|
*
|
|
39
55
|
* @protected
|
|
40
|
-
* @type {IWalletAccount}
|
|
56
|
+
* @type {IWalletAccountReadOnly | IWalletAccount}
|
|
41
57
|
*/
|
|
42
|
-
protected _account: IWalletAccount;
|
|
58
|
+
protected _account: IWalletAccountReadOnly | IWalletAccount;
|
|
43
59
|
/**
|
|
44
60
|
* The bridge protocol configuration.
|
|
45
61
|
*
|
|
@@ -53,6 +69,13 @@ export default abstract class BridgeProtocol implements IBridgeProtocol {
|
|
|
53
69
|
* @abstract
|
|
54
70
|
* @param {BridgeOptions} options - The bridge's options.
|
|
55
71
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
72
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
73
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
74
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
75
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
76
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
77
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
78
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the bridge max. fee option.
|
|
56
79
|
*/
|
|
57
80
|
abstract bridge(options: BridgeOptions): Promise<BridgeResult>;
|
|
58
81
|
/**
|
|
@@ -61,11 +84,24 @@ export default abstract class BridgeProtocol implements IBridgeProtocol {
|
|
|
61
84
|
* @abstract
|
|
62
85
|
* @param {BridgeOptions} options - The bridge's options.
|
|
63
86
|
* @returns {Promise<Omit<BridgeResult, 'hash'>>} The bridge's quotes.
|
|
87
|
+
* @throws {ValueError} If the bridge options are not valid.
|
|
88
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
89
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
90
|
+
* @throws {ProviderError} If the provider fails to perform the bridge.
|
|
91
|
+
* @throws {BridgeError} If the bridge fails with an error.
|
|
64
92
|
*/
|
|
65
93
|
abstract quoteBridge(options: BridgeOptions): Promise<Omit<BridgeResult, "hash">>;
|
|
66
94
|
}
|
|
67
95
|
export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
|
|
68
96
|
export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
|
|
97
|
+
export type AccountRequiredError = import("./errors.js").AccountRequiredError;
|
|
98
|
+
export type BridgeError = import("./errors.js").BridgeError;
|
|
99
|
+
export type InvalidTokenError = import("./errors.js").InvalidTokenError;
|
|
100
|
+
export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
|
|
101
|
+
export type ReadOnlyAccountRequiredError = import("./errors.js").ReadOnlyAccountRequiredError;
|
|
102
|
+
export type ProviderError = import("./errors.js").ProviderError;
|
|
103
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
104
|
+
export type ValueError = import("./errors.js").ValueError;
|
|
69
105
|
export type BridgeProtocolConfig = {
|
|
70
106
|
/**
|
|
71
107
|
* - The maximum fee amount for bridge operations.
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for swap error reasons.
|
|
3
|
+
*/
|
|
4
|
+
export type SwapErrorReason = string;
|
|
5
|
+
export namespace SwapErrorReason {
|
|
6
|
+
let INSUFFICIENT_BALANCE: string;
|
|
7
|
+
let INSUFFICIENT_TOKEN_BALANCE: string;
|
|
8
|
+
let COULD_NOT_MET_THRESHOLD: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Enum for bridge error reasons.
|
|
12
|
+
*/
|
|
13
|
+
export type BridgeErrorReason = string;
|
|
14
|
+
export namespace BridgeErrorReason {
|
|
15
|
+
let INSUFFICIENT_BALANCE_1: string;
|
|
16
|
+
export { INSUFFICIENT_BALANCE_1 as INSUFFICIENT_BALANCE };
|
|
17
|
+
let INSUFFICIENT_TOKEN_BALANCE_1: string;
|
|
18
|
+
export { INSUFFICIENT_TOKEN_BALANCE_1 as INSUFFICIENT_TOKEN_BALANCE };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Enum for supply error reasons.
|
|
22
|
+
*/
|
|
23
|
+
export type SupplyErrorReason = string;
|
|
24
|
+
export namespace SupplyErrorReason {
|
|
25
|
+
let INSUFFICIENT_BALANCE_2: string;
|
|
26
|
+
export { INSUFFICIENT_BALANCE_2 as INSUFFICIENT_BALANCE };
|
|
27
|
+
let INSUFFICIENT_TOKEN_BALANCE_2: string;
|
|
28
|
+
export { INSUFFICIENT_TOKEN_BALANCE_2 as INSUFFICIENT_TOKEN_BALANCE };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Enum for withdraw error reasons.
|
|
32
|
+
*/
|
|
33
|
+
export type WithdrawErrorReason = string;
|
|
34
|
+
export namespace WithdrawErrorReason {
|
|
35
|
+
let INSUFFICIENT_BALANCE_3: string;
|
|
36
|
+
export { INSUFFICIENT_BALANCE_3 as INSUFFICIENT_BALANCE };
|
|
37
|
+
let INSUFFICIENT_TOKEN_BALANCE_3: string;
|
|
38
|
+
export { INSUFFICIENT_TOKEN_BALANCE_3 as INSUFFICIENT_TOKEN_BALANCE };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Enum for borrow error reasons.
|
|
42
|
+
*/
|
|
43
|
+
export type BorrowErrorReason = string;
|
|
44
|
+
export namespace BorrowErrorReason {
|
|
45
|
+
let INSUFFICIENT_BALANCE_4: string;
|
|
46
|
+
export { INSUFFICIENT_BALANCE_4 as INSUFFICIENT_BALANCE };
|
|
47
|
+
let INSUFFICIENT_TOKEN_BALANCE_4: string;
|
|
48
|
+
export { INSUFFICIENT_TOKEN_BALANCE_4 as INSUFFICIENT_TOKEN_BALANCE };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Enum for repay error reasons.
|
|
52
|
+
*/
|
|
53
|
+
export type RepayErrorReason = string;
|
|
54
|
+
export namespace RepayErrorReason {
|
|
55
|
+
let INSUFFICIENT_BALANCE_5: string;
|
|
56
|
+
export { INSUFFICIENT_BALANCE_5 as INSUFFICIENT_BALANCE };
|
|
57
|
+
let INSUFFICIENT_TOKEN_BALANCE_5: string;
|
|
58
|
+
export { INSUFFICIENT_TOKEN_BALANCE_5 as INSUFFICIENT_TOKEN_BALANCE };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Enum for buy error reasons.
|
|
62
|
+
*/
|
|
63
|
+
export type BuyErrorReason = string;
|
|
64
|
+
export namespace BuyErrorReason {
|
|
65
|
+
let INSUFFICIENT_FUNDS: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Enum for sell error reasons.
|
|
69
|
+
*/
|
|
70
|
+
export type SellErrorReason = string;
|
|
71
|
+
export namespace SellErrorReason {
|
|
72
|
+
let INSUFFICIENT_FUNDS_1: string;
|
|
73
|
+
export { INSUFFICIENT_FUNDS_1 as INSUFFICIENT_FUNDS };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Enum for swidge error reasons.
|
|
77
|
+
*/
|
|
78
|
+
export type SwidgeErrorReason = string;
|
|
79
|
+
export namespace SwidgeErrorReason {
|
|
80
|
+
let INSUFFICIENT_BALANCE_6: string;
|
|
81
|
+
export { INSUFFICIENT_BALANCE_6 as INSUFFICIENT_BALANCE };
|
|
82
|
+
let INSUFFICIENT_TOKEN_BALANCE_6: string;
|
|
83
|
+
export { INSUFFICIENT_TOKEN_BALANCE_6 as INSUFFICIENT_TOKEN_BALANCE };
|
|
84
|
+
let COULD_NOT_MET_THRESHOLD_1: string;
|
|
85
|
+
export { COULD_NOT_MET_THRESHOLD_1 as COULD_NOT_MET_THRESHOLD };
|
|
86
|
+
export let SLIPPAGE_TOO_HIGH: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Enum for SDA error reasons.
|
|
90
|
+
*/
|
|
91
|
+
export type SdaErrorReason = string;
|
|
92
|
+
export namespace SdaErrorReason {
|
|
93
|
+
let ROUTE_NOT_SUPPORTED: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Thrown when an operation requires an account to be set.
|
|
97
|
+
*/
|
|
98
|
+
export class AccountRequiredError extends WdkError {
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new account required error.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} message - The error's message.
|
|
103
|
+
*/
|
|
104
|
+
constructor(message: string);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Thrown when an operation requires a read-only account to be set.
|
|
108
|
+
*/
|
|
109
|
+
export class ReadOnlyAccountRequiredError extends AccountRequiredError {
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new read-only account required error.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} message - The error's message.
|
|
114
|
+
*/
|
|
115
|
+
constructor(message: string);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Thrown when a swap fails with an error.
|
|
119
|
+
*/
|
|
120
|
+
export class SwapError extends WdkError {
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new swap error.
|
|
123
|
+
*
|
|
124
|
+
* @param {string} message - The error's message.
|
|
125
|
+
* @param {SwapErrorOptions & ErrorOptions} options - The error's options.
|
|
126
|
+
*/
|
|
127
|
+
constructor(message: string, options: SwapErrorOptions & ErrorOptions);
|
|
128
|
+
/**
|
|
129
|
+
* The error's reason.
|
|
130
|
+
*
|
|
131
|
+
* @type {string}
|
|
132
|
+
*/
|
|
133
|
+
reason: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Thrown when a bridge fails with an error.
|
|
137
|
+
*/
|
|
138
|
+
export class BridgeError extends WdkError {
|
|
139
|
+
/**
|
|
140
|
+
* Creates a new bridge error.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} message - The error's message.
|
|
143
|
+
* @param {BridgeErrorOptions & ErrorOptions} options - The error's options.
|
|
144
|
+
*/
|
|
145
|
+
constructor(message: string, options: BridgeErrorOptions & ErrorOptions);
|
|
146
|
+
/**
|
|
147
|
+
* The error's reason.
|
|
148
|
+
*
|
|
149
|
+
* @type {string}
|
|
150
|
+
*/
|
|
151
|
+
reason: string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Thrown when a supply fails with an error.
|
|
155
|
+
*/
|
|
156
|
+
export class SupplyError extends WdkError {
|
|
157
|
+
/**
|
|
158
|
+
* Creates a new supply error.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} message - The error's message.
|
|
161
|
+
* @param {SupplyErrorOptions & ErrorOptions} options - The error's options.
|
|
162
|
+
*/
|
|
163
|
+
constructor(message: string, options: SupplyErrorOptions & ErrorOptions);
|
|
164
|
+
/**
|
|
165
|
+
* The error's reason.
|
|
166
|
+
*
|
|
167
|
+
* @type {string}
|
|
168
|
+
*/
|
|
169
|
+
reason: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Thrown when a withdraw fails with an error.
|
|
173
|
+
*/
|
|
174
|
+
export class WithdrawError extends WdkError {
|
|
175
|
+
/**
|
|
176
|
+
* Creates a new withdraw error.
|
|
177
|
+
*
|
|
178
|
+
* @param {string} message - The error's message.
|
|
179
|
+
* @param {WithdrawErrorOptions & ErrorOptions} options - The error's options.
|
|
180
|
+
*/
|
|
181
|
+
constructor(message: string, options: WithdrawErrorOptions & ErrorOptions);
|
|
182
|
+
/**
|
|
183
|
+
* The error's reason.
|
|
184
|
+
*
|
|
185
|
+
* @type {string}
|
|
186
|
+
*/
|
|
187
|
+
reason: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Thrown when a borrow fails with an error.
|
|
191
|
+
*/
|
|
192
|
+
export class BorrowError extends WdkError {
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new borrow error.
|
|
195
|
+
*
|
|
196
|
+
* @param {string} message - The error's message.
|
|
197
|
+
* @param {BorrowErrorOptions & ErrorOptions} options - The error's options.
|
|
198
|
+
*/
|
|
199
|
+
constructor(message: string, options: BorrowErrorOptions & ErrorOptions);
|
|
200
|
+
/**
|
|
201
|
+
* The error's reason.
|
|
202
|
+
*
|
|
203
|
+
* @type {string}
|
|
204
|
+
*/
|
|
205
|
+
reason: string;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Thrown when a repay fails with an error.
|
|
209
|
+
*/
|
|
210
|
+
export class RepayError extends WdkError {
|
|
211
|
+
/**
|
|
212
|
+
* Creates a new repay error.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} message - The error's message.
|
|
215
|
+
* @param {RepayErrorOptions & ErrorOptions} options - The error's options.
|
|
216
|
+
*/
|
|
217
|
+
constructor(message: string, options: RepayErrorOptions & ErrorOptions);
|
|
218
|
+
/**
|
|
219
|
+
* The error's reason.
|
|
220
|
+
*
|
|
221
|
+
* @type {string}
|
|
222
|
+
*/
|
|
223
|
+
reason: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Thrown when a purchase fails with an error.
|
|
227
|
+
*/
|
|
228
|
+
export class BuyError extends WdkError {
|
|
229
|
+
/**
|
|
230
|
+
* Creates a new buy error.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} message - The error's message.
|
|
233
|
+
* @param {BuyErrorOptions & ErrorOptions} options - The error's options.
|
|
234
|
+
*/
|
|
235
|
+
constructor(message: string, options: BuyErrorOptions & ErrorOptions);
|
|
236
|
+
/**
|
|
237
|
+
* The error's reason.
|
|
238
|
+
*
|
|
239
|
+
* @type {string}
|
|
240
|
+
*/
|
|
241
|
+
reason: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Thrown when a sale fails with an error.
|
|
245
|
+
*/
|
|
246
|
+
export class SellError extends WdkError {
|
|
247
|
+
/**
|
|
248
|
+
* Creates a new sell error.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} message - The error's message.
|
|
251
|
+
* @param {SellErrorOptions & ErrorOptions} options - The error's options.
|
|
252
|
+
*/
|
|
253
|
+
constructor(message: string, options: SellErrorOptions & ErrorOptions);
|
|
254
|
+
/**
|
|
255
|
+
* The error's reason.
|
|
256
|
+
*
|
|
257
|
+
* @type {string}
|
|
258
|
+
*/
|
|
259
|
+
reason: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Thrown when a swidge fails with an error.
|
|
263
|
+
*/
|
|
264
|
+
export class SwidgeError extends WdkError {
|
|
265
|
+
/**
|
|
266
|
+
* Creates a new swidge error.
|
|
267
|
+
*
|
|
268
|
+
* @param {string} message - The error's message.
|
|
269
|
+
* @param {SwidgeErrorOptions & ErrorOptions} options - The error's options.
|
|
270
|
+
*/
|
|
271
|
+
constructor(message: string, options: SwidgeErrorOptions & ErrorOptions);
|
|
272
|
+
/**
|
|
273
|
+
* The error's reason.
|
|
274
|
+
*
|
|
275
|
+
* @type {string}
|
|
276
|
+
*/
|
|
277
|
+
reason: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Thrown when a SDA fails with an error.
|
|
281
|
+
*/
|
|
282
|
+
export class SdaError extends WdkError {
|
|
283
|
+
/**
|
|
284
|
+
* Creates a new SDA error.
|
|
285
|
+
*
|
|
286
|
+
* @param {string} message - The error's message.
|
|
287
|
+
* @param {SdaErrorOptions & ErrorOptions} options - The error's options.
|
|
288
|
+
*/
|
|
289
|
+
constructor(message: string, options: SdaErrorOptions & ErrorOptions);
|
|
290
|
+
/**
|
|
291
|
+
* The error's reason.
|
|
292
|
+
*
|
|
293
|
+
* @type {string}
|
|
294
|
+
*/
|
|
295
|
+
reason: string;
|
|
296
|
+
}
|
|
297
|
+
export type SwapErrorOptions = {
|
|
298
|
+
/**
|
|
299
|
+
* - The error's reason.
|
|
300
|
+
*/
|
|
301
|
+
reason: SwapErrorReason;
|
|
302
|
+
};
|
|
303
|
+
export type BridgeErrorOptions = {
|
|
304
|
+
/**
|
|
305
|
+
* - The error's reason.
|
|
306
|
+
*/
|
|
307
|
+
reason: BridgeErrorReason;
|
|
308
|
+
};
|
|
309
|
+
export type SupplyErrorOptions = {
|
|
310
|
+
/**
|
|
311
|
+
* - The error's reason.
|
|
312
|
+
*/
|
|
313
|
+
reason: SupplyErrorReason;
|
|
314
|
+
};
|
|
315
|
+
export type WithdrawErrorOptions = {
|
|
316
|
+
/**
|
|
317
|
+
* - The error's reason.
|
|
318
|
+
*/
|
|
319
|
+
reason: WithdrawErrorReason;
|
|
320
|
+
};
|
|
321
|
+
export type BorrowErrorOptions = {
|
|
322
|
+
/**
|
|
323
|
+
* - The error's reason.
|
|
324
|
+
*/
|
|
325
|
+
reason: BorrowErrorReason;
|
|
326
|
+
};
|
|
327
|
+
export type RepayErrorOptions = {
|
|
328
|
+
/**
|
|
329
|
+
* - The error's reason.
|
|
330
|
+
*/
|
|
331
|
+
reason: RepayErrorReason;
|
|
332
|
+
};
|
|
333
|
+
export type BuyErrorOptions = {
|
|
334
|
+
/**
|
|
335
|
+
* - The error's reason.
|
|
336
|
+
*/
|
|
337
|
+
reason: BuyErrorReason;
|
|
338
|
+
};
|
|
339
|
+
export type SellErrorOptions = {
|
|
340
|
+
/**
|
|
341
|
+
* - The error's reason.
|
|
342
|
+
*/
|
|
343
|
+
reason: SellErrorReason;
|
|
344
|
+
};
|
|
345
|
+
export type SwidgeErrorOptions = {
|
|
346
|
+
/**
|
|
347
|
+
* - The error's reason.
|
|
348
|
+
*/
|
|
349
|
+
reason: SwidgeErrorReason;
|
|
350
|
+
};
|
|
351
|
+
export type SdaErrorOptions = {
|
|
352
|
+
/**
|
|
353
|
+
* - The error's reason.
|
|
354
|
+
*/
|
|
355
|
+
reason: SdaErrorReason;
|
|
356
|
+
};
|
|
357
|
+
import { InvalidTokenError } from '../errors.js';
|
|
358
|
+
import { MaximumFeeExceededError } from '../errors.js';
|
|
359
|
+
import { NoSuchElementError } from '../errors.js';
|
|
360
|
+
import { NotImplementedError } from '../errors.js';
|
|
361
|
+
import { ProviderError } from '../errors.js';
|
|
362
|
+
import { ProviderRequiredError } from '../errors.js';
|
|
363
|
+
import { UnsupportedOperationError } from '../errors.js';
|
|
364
|
+
import { ValueError } from '../errors.js';
|
|
365
|
+
import { WdkError } from '../errors.js';
|
|
366
|
+
export { InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError };
|
|
@@ -1,50 +1,88 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @interface
|
|
3
|
-
*/
|
|
1
|
+
/** @interface */
|
|
4
2
|
export interface IFiatProtocol {
|
|
5
3
|
/**
|
|
6
4
|
* Gets a quote for a crypto asset purchase.
|
|
5
|
+
*
|
|
7
6
|
* @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
|
|
8
7
|
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
8
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a purchase.
|
|
9
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
10
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
11
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the purchase.
|
|
12
|
+
* @throws {BuyError} If the purchase fails with an error.
|
|
9
13
|
*/
|
|
10
14
|
quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
|
|
11
15
|
/**
|
|
12
16
|
* Generates a widget URL for a user to purchase a crypto asset with fiat currency.
|
|
17
|
+
*
|
|
13
18
|
* @param {BuyOptions} options - The options for the buy operation.
|
|
14
19
|
* @returns {Promise<BuyResult>} The operation's result.
|
|
20
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
|
|
21
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
22
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
23
|
+
* @throws {ProviderError} If the provider fails to perform the purchase.
|
|
24
|
+
* @throws {BuyError} If the purchase fails with an error.
|
|
25
|
+
* @throws {MaximumFeeExceededError} If the the costs of the purchase exceeds the buy max. fee option.
|
|
15
26
|
*/
|
|
16
27
|
buy(options: BuyOptions): Promise<BuyResult>;
|
|
17
28
|
/**
|
|
18
29
|
* Gets a quote for a crypto asset sale.
|
|
30
|
+
*
|
|
19
31
|
* @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
|
|
20
32
|
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
33
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a sale.
|
|
34
|
+
* @throws {ValueError} If the sell options are not valid.
|
|
35
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
36
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the sale.
|
|
37
|
+
* @throws {SellError} If the sale fails with an error.
|
|
21
38
|
*/
|
|
22
39
|
quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
|
|
23
40
|
/**
|
|
24
41
|
* Generates a widget URL for a user to sell a crypto asset for fiat currency.
|
|
42
|
+
*
|
|
25
43
|
* @param {SellOptions} options - The options for the sell operation.
|
|
26
44
|
* @returns {Promise<SellResult>} The operation's result.
|
|
45
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
|
|
46
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
47
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
48
|
+
* @throws {ProviderError} If the provider fails to perform the sale.
|
|
49
|
+
* @throws {SellError} If the sale fails with an error.
|
|
50
|
+
* @throws {MaximumFeeExceededError} If the the costs of the sale exceeds the sell max. fee option.
|
|
27
51
|
*/
|
|
28
52
|
sell(options: SellOptions): Promise<SellResult>;
|
|
29
53
|
/**
|
|
30
54
|
* Retrieves the details of a specific transaction from the provider.
|
|
55
|
+
*
|
|
31
56
|
* @param {string} txId - The unique identifier of the transaction.
|
|
32
57
|
* @returns {Promise<FiatTransactionDetail>} The transaction details.
|
|
58
|
+
* @throws {ValueError} If the transaction's id is not valid.
|
|
59
|
+
* @throws {NoSuchElementError} If no transaction exists for the given id.
|
|
60
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
61
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction's details.
|
|
33
62
|
*/
|
|
34
63
|
getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
|
|
35
64
|
/**
|
|
36
65
|
* Retrieves a list of supported crypto assets from the provider.
|
|
66
|
+
*
|
|
37
67
|
* @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
|
|
68
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
69
|
+
* @throws {ProviderError} If the provider fails to fetch the available crypto assets.
|
|
38
70
|
*/
|
|
39
71
|
getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
|
|
40
72
|
/**
|
|
41
73
|
* Retrieves a list of supported fiat currencies from the provider.
|
|
74
|
+
*
|
|
42
75
|
* @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
|
|
76
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
77
|
+
* @throws {ProviderError} If the provider fails to fetch the available fiat currencies.
|
|
43
78
|
*/
|
|
44
79
|
getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
|
|
45
80
|
/**
|
|
46
81
|
* Retrieves a list of supported countries from the provider.
|
|
82
|
+
*
|
|
47
83
|
* @returns {Promise<SupportedCountry[]>} An array of supported countries.
|
|
84
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
85
|
+
* @throws {ProviderError} If the provider fails to fetch the available countries.
|
|
48
86
|
*/
|
|
49
87
|
getSupportedCountries(): Promise<SupportedCountry[]>;
|
|
50
88
|
}
|
|
@@ -54,19 +92,26 @@ export interface IFiatProtocol {
|
|
|
54
92
|
*/
|
|
55
93
|
export default abstract class FiatProtocol implements IFiatProtocol {
|
|
56
94
|
/**
|
|
57
|
-
* Creates a new
|
|
95
|
+
* Creates a new interface to the protocol without binding it to a wallet account.
|
|
96
|
+
*
|
|
97
|
+
* @overload
|
|
98
|
+
* @param {undefined} [account] - The wallet account to use to interact with the protocol.
|
|
99
|
+
*/
|
|
100
|
+
constructor(account?: undefined);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new read-only interface to the protocol.
|
|
58
103
|
*
|
|
59
104
|
* @overload
|
|
60
|
-
* @param {IWalletAccountReadOnly}
|
|
105
|
+
* @param {IWalletAccountReadOnly} account - The wallet account to use to interact with the protocol.
|
|
61
106
|
*/
|
|
62
|
-
constructor(account
|
|
107
|
+
constructor(account: IWalletAccountReadOnly);
|
|
63
108
|
/**
|
|
64
|
-
* Creates a new
|
|
109
|
+
* Creates a new interface to the protocol.
|
|
65
110
|
*
|
|
66
111
|
* @overload
|
|
67
|
-
* @param {IWalletAccount}
|
|
112
|
+
* @param {IWalletAccount} account - The wallet account to use to interact with the protocol.
|
|
68
113
|
*/
|
|
69
|
-
constructor(account
|
|
114
|
+
constructor(account: IWalletAccount);
|
|
70
115
|
/**
|
|
71
116
|
* The wallet account to use to interact with the protocol.
|
|
72
117
|
*
|
|
@@ -76,60 +121,109 @@ export default abstract class FiatProtocol implements IFiatProtocol {
|
|
|
76
121
|
protected _account: IWalletAccountReadOnly | IWalletAccount | undefined;
|
|
77
122
|
/**
|
|
78
123
|
* Gets a quote for a crypto asset purchase.
|
|
124
|
+
*
|
|
79
125
|
* @abstract
|
|
80
126
|
* @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
|
|
81
127
|
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
128
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a purchase.
|
|
129
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
130
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
131
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the purchase.
|
|
132
|
+
* @throws {BuyError} If the purchase fails with an error.
|
|
82
133
|
*/
|
|
83
134
|
abstract quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
|
|
84
135
|
/**
|
|
85
136
|
* Generates a URL for a user to purchase a crypto asset with fiat currency.
|
|
137
|
+
*
|
|
86
138
|
* @abstract
|
|
87
139
|
* @param {BuyOptions} options - The options for the buy operation.
|
|
88
140
|
* @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
|
|
141
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
|
|
142
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
143
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
144
|
+
* @throws {ProviderError} If the provider fails to perform the purchase.
|
|
145
|
+
* @throws {BuyError} If the purchase fails with an error.
|
|
146
|
+
* @throws {MaximumFeeExceededError} If the the costs of the purchase exceeds the buy max. fee option.
|
|
89
147
|
*/
|
|
90
148
|
abstract buy(options: BuyOptions): Promise<BuyResult>;
|
|
91
149
|
/**
|
|
92
150
|
* Gets a quote for a crypto asset sale.
|
|
151
|
+
*
|
|
93
152
|
* @abstract
|
|
94
153
|
* @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
|
|
95
154
|
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
155
|
+
* @throws {ReadOnlyAccountRequiredError} If the protocol requires a read-only or full account to quote the costs of a sale.
|
|
156
|
+
* @throws {ValueError} If the sell options are not valid.
|
|
157
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
158
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the sale.
|
|
159
|
+
* @throws {SellError} If the sale fails with an error.
|
|
96
160
|
*/
|
|
97
161
|
abstract quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
|
|
98
162
|
/**
|
|
99
163
|
* Generates a URL for a user to sell a crypto asset for fiat currency.
|
|
164
|
+
*
|
|
100
165
|
* @abstract
|
|
101
166
|
* @param {SellOptions} options - The options for the sell operation.
|
|
102
167
|
* @returns {Promise<SellResult>} The URL for the user to complete the sale.
|
|
168
|
+
* @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
|
|
169
|
+
* @throws {ValueError} If the buy options are not valid.
|
|
170
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
171
|
+
* @throws {ProviderError} If the provider fails to perform the sale.
|
|
172
|
+
* @throws {SellError} If the sale fails with an error.
|
|
173
|
+
* @throws {MaximumFeeExceededError} If the the costs of the sale exceeds the sell max. fee option.
|
|
103
174
|
*/
|
|
104
175
|
abstract sell(options: SellOptions): Promise<SellResult>;
|
|
105
176
|
/**
|
|
106
177
|
* Retrieves the details of a specific transaction from the provider.
|
|
178
|
+
*
|
|
107
179
|
* @abstract
|
|
108
180
|
* @param {string} txId - The unique identifier of the transaction.
|
|
109
181
|
* @returns {Promise<FiatTransactionDetail>} The transaction details.
|
|
182
|
+
* @throws {ValueError} If the transaction's id is not valid.
|
|
183
|
+
* @throws {NoSuchElementError} If no transaction exists for the given id.
|
|
184
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
185
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction's details.
|
|
110
186
|
*/
|
|
111
187
|
abstract getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
|
|
112
188
|
/**
|
|
113
189
|
* Retrieves a list of supported crypto assets from the provider.
|
|
190
|
+
*
|
|
114
191
|
* @abstract
|
|
115
192
|
* @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
|
|
193
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
194
|
+
* @throws {ProviderError} If the provider fails to fetch the available crypto assets.
|
|
116
195
|
*/
|
|
117
196
|
abstract getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
|
|
118
197
|
/**
|
|
119
198
|
* Retrieves a list of supported fiat currencies from the provider.
|
|
199
|
+
*
|
|
120
200
|
* @abstract
|
|
121
201
|
* @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
|
|
202
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
203
|
+
* @throws {ProviderError} If the provider fails to fetch the available fiat currencies.
|
|
122
204
|
*/
|
|
123
205
|
abstract getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
|
|
124
206
|
/**
|
|
125
207
|
* Retrieves a list of supported countries or regions from the provider.
|
|
208
|
+
*
|
|
126
209
|
* @abstract
|
|
127
210
|
* @returns {Promise<SupportedCountry[]>} An array of supported countries.
|
|
211
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
212
|
+
* @throws {ProviderError} If the provider fails to fetch the available countries.
|
|
128
213
|
*/
|
|
129
214
|
abstract getSupportedCountries(): Promise<SupportedCountry[]>;
|
|
130
215
|
}
|
|
131
216
|
export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
|
|
132
217
|
export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
|
|
218
|
+
export type AccountRequiredError = import("./errors.js").AccountRequiredError;
|
|
219
|
+
export type BuyError = import("./errors.js").BuyError;
|
|
220
|
+
export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
|
|
221
|
+
export type NoSuchElementError = import("./errors.js").NoSuchElementError;
|
|
222
|
+
export type ReadOnlyAccountRequiredError = import("./errors.js").ReadOnlyAccountRequiredError;
|
|
223
|
+
export type ProviderError = import("./errors.js").ProviderError;
|
|
224
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
225
|
+
export type SellError = import("./errors.js").SellError;
|
|
226
|
+
export type ValueError = import("./errors.js").ValueError;
|
|
133
227
|
/**
|
|
134
228
|
* Standardized status for an on/off-ramp transaction.
|
|
135
229
|
*/
|