@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.
- package/AGENTS.md +49 -0
- package/bare.js +3 -3
- package/package.json +8 -3
- package/src/protocols/fiat-protocol.js +301 -0
- package/src/protocols/index.js +42 -0
- package/src/protocols/swidge-protocol.js +402 -0
- package/src/wallet-account-read-only.js +25 -0
- package/src/wallet-account.js +10 -0
- package/src/wallet-manager.js +5 -2
- package/types/src/protocols/fiat-protocol.d.ts +315 -0
- package/types/src/protocols/index.d.ts +34 -0
- package/types/src/protocols/swidge-protocol.d.ts +400 -0
- package/types/src/wallet-account-read-only.d.ts +19 -0
- package/types/src/wallet-account.d.ts +7 -0
- package/types/src/wallet-manager.d.ts +6 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @interface
|
|
3
|
+
*/
|
|
4
|
+
export interface IFiatProtocol {
|
|
5
|
+
/**
|
|
6
|
+
* Gets a quote for a crypto asset purchase.
|
|
7
|
+
* @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
|
|
8
|
+
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
9
|
+
*/
|
|
10
|
+
quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
|
|
11
|
+
/**
|
|
12
|
+
* Generates a widget URL for a user to purchase a crypto asset with fiat currency.
|
|
13
|
+
* @param {BuyOptions} options - The options for the buy operation.
|
|
14
|
+
* @returns {Promise<BuyResult>} The operation's result.
|
|
15
|
+
*/
|
|
16
|
+
buy(options: BuyOptions): Promise<BuyResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Gets a quote for a crypto asset sale.
|
|
19
|
+
* @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
|
|
20
|
+
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
21
|
+
*/
|
|
22
|
+
quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
|
|
23
|
+
/**
|
|
24
|
+
* Generates a widget URL for a user to sell a crypto asset for fiat currency.
|
|
25
|
+
* @param {SellOptions} options - The options for the sell operation.
|
|
26
|
+
* @returns {Promise<SellResult>} The operation's result.
|
|
27
|
+
*/
|
|
28
|
+
sell(options: SellOptions): Promise<SellResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the details of a specific transaction from the provider.
|
|
31
|
+
* @param {string} txId - The unique identifier of the transaction.
|
|
32
|
+
* @returns {Promise<FiatTransactionDetail>} The transaction details.
|
|
33
|
+
*/
|
|
34
|
+
getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves a list of supported crypto assets from the provider.
|
|
37
|
+
* @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
|
|
38
|
+
*/
|
|
39
|
+
getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves a list of supported fiat currencies from the provider.
|
|
42
|
+
* @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
|
|
43
|
+
*/
|
|
44
|
+
getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves a list of supported countries from the provider.
|
|
47
|
+
* @returns {Promise<SupportedCountry[]>} An array of supported countries.
|
|
48
|
+
*/
|
|
49
|
+
getSupportedCountries(): Promise<SupportedCountry[]>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @abstract
|
|
53
|
+
* @implements {IFiatProtocol}
|
|
54
|
+
*/
|
|
55
|
+
export default abstract class FiatProtocol implements IFiatProtocol {
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new fiat protocol with read-only account.
|
|
58
|
+
*
|
|
59
|
+
* @overload
|
|
60
|
+
* @param {IWalletAccountReadOnly} [account] - The wallet account to use to interact with the protocol.
|
|
61
|
+
*/
|
|
62
|
+
constructor(account?: IWalletAccountReadOnly);
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new fiat protocol with read-only account.
|
|
65
|
+
*
|
|
66
|
+
* @overload
|
|
67
|
+
* @param {IWalletAccount} [account] - The wallet account to use to interact with the protocol.
|
|
68
|
+
*/
|
|
69
|
+
constructor(account?: IWalletAccount);
|
|
70
|
+
/**
|
|
71
|
+
* The wallet account to use to interact with the protocol.
|
|
72
|
+
*
|
|
73
|
+
* @protected
|
|
74
|
+
* @type {IWalletAccountReadOnly | IWalletAccount | undefined}
|
|
75
|
+
*/
|
|
76
|
+
protected _account: IWalletAccountReadOnly | IWalletAccount | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Gets a quote for a crypto asset purchase.
|
|
79
|
+
* @abstract
|
|
80
|
+
* @param {Omit<BuyOptions, 'recipient'>} options - The options for the buy operation.
|
|
81
|
+
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
82
|
+
*/
|
|
83
|
+
abstract quoteBuy(options: Omit<BuyOptions, "recipient">): Promise<FiatQuote>;
|
|
84
|
+
/**
|
|
85
|
+
* Generates a URL for a user to purchase a crypto asset with fiat currency.
|
|
86
|
+
* @abstract
|
|
87
|
+
* @param {BuyOptions} options - The options for the buy operation.
|
|
88
|
+
* @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
|
|
89
|
+
*/
|
|
90
|
+
abstract buy(options: BuyOptions): Promise<BuyResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Gets a quote for a crypto asset sale.
|
|
93
|
+
* @abstract
|
|
94
|
+
* @param {Omit<SellOptions, 'refundAddress'>} options - The options for the sell operation.
|
|
95
|
+
* @returns {Promise<FiatQuote>} A quote for the transaction.
|
|
96
|
+
*/
|
|
97
|
+
abstract quoteSell(options: Omit<SellOptions, "refundAddress">): Promise<FiatQuote>;
|
|
98
|
+
/**
|
|
99
|
+
* Generates a URL for a user to sell a crypto asset for fiat currency.
|
|
100
|
+
* @abstract
|
|
101
|
+
* @param {SellOptions} options - The options for the sell operation.
|
|
102
|
+
* @returns {Promise<SellResult>} The URL for the user to complete the sale.
|
|
103
|
+
*/
|
|
104
|
+
abstract sell(options: SellOptions): Promise<SellResult>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves the details of a specific transaction from the provider.
|
|
107
|
+
* @abstract
|
|
108
|
+
* @param {string} txId - The unique identifier of the transaction.
|
|
109
|
+
* @returns {Promise<FiatTransactionDetail>} The transaction details.
|
|
110
|
+
*/
|
|
111
|
+
abstract getTransactionDetail(txId: string): Promise<FiatTransactionDetail>;
|
|
112
|
+
/**
|
|
113
|
+
* Retrieves a list of supported crypto assets from the provider.
|
|
114
|
+
* @abstract
|
|
115
|
+
* @returns {Promise<SupportedCryptoAsset[]>} An array of supported crypto assets.
|
|
116
|
+
*/
|
|
117
|
+
abstract getSupportedCryptoAssets(): Promise<SupportedCryptoAsset[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Retrieves a list of supported fiat currencies from the provider.
|
|
120
|
+
* @abstract
|
|
121
|
+
* @returns {Promise<SupportedFiatCurrency[]>} An array of supported fiat currencies.
|
|
122
|
+
*/
|
|
123
|
+
abstract getSupportedFiatCurrencies(): Promise<SupportedFiatCurrency[]>;
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves a list of supported countries or regions from the provider.
|
|
126
|
+
* @abstract
|
|
127
|
+
* @returns {Promise<SupportedCountry[]>} An array of supported countries.
|
|
128
|
+
*/
|
|
129
|
+
abstract getSupportedCountries(): Promise<SupportedCountry[]>;
|
|
130
|
+
}
|
|
131
|
+
export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
|
|
132
|
+
export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
|
|
133
|
+
/**
|
|
134
|
+
* Standardized status for an on/off-ramp transaction.
|
|
135
|
+
*/
|
|
136
|
+
export type FiatTransactionStatus = "in_progress" | "failed" | "completed";
|
|
137
|
+
/**
|
|
138
|
+
* A protocol-agnostic, standardized object representing the details of an on/off-ramp transaction.
|
|
139
|
+
*/
|
|
140
|
+
export type FiatTransactionDetail = {
|
|
141
|
+
/**
|
|
142
|
+
* - The current status of the transaction.
|
|
143
|
+
*/
|
|
144
|
+
status: FiatTransactionStatus;
|
|
145
|
+
/**
|
|
146
|
+
* - The provider-specific code of the crypto asset (e.g., 'btc').
|
|
147
|
+
*/
|
|
148
|
+
cryptoAsset: string;
|
|
149
|
+
/**
|
|
150
|
+
* - The currency's ISO 4217 code (e.g., 'USD').
|
|
151
|
+
*/
|
|
152
|
+
fiatCurrency: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* A protocol-agnostic, standardized object representing a supported crypto asset.
|
|
156
|
+
*/
|
|
157
|
+
export type SupportedCryptoAsset = {
|
|
158
|
+
/**
|
|
159
|
+
* - Provider-specific asset code for the crypto asset.
|
|
160
|
+
*/
|
|
161
|
+
code: string;
|
|
162
|
+
/**
|
|
163
|
+
* - The network code for the asset, if applicable (e.g., 'ethereum', 'tron').
|
|
164
|
+
*/
|
|
165
|
+
networkCode: string;
|
|
166
|
+
/**
|
|
167
|
+
* - The on-chain number of decimal places for the asset's base unit (e.g., 18 for ETH).
|
|
168
|
+
*/
|
|
169
|
+
decimals: number;
|
|
170
|
+
/**
|
|
171
|
+
* - The asset's full name (e.g., 'Bitcoin').
|
|
172
|
+
*/
|
|
173
|
+
name?: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* A protocol-agnostic, standardized object representing a supported fiat currency.
|
|
177
|
+
*/
|
|
178
|
+
export type SupportedFiatCurrency = {
|
|
179
|
+
/**
|
|
180
|
+
* - The currency's ISO 4217 code (e.g., 'USD').
|
|
181
|
+
*/
|
|
182
|
+
code: string;
|
|
183
|
+
/**
|
|
184
|
+
* - The number of decimal places for the currency's smallest unit (e.g., 2 for USD, 0 for JPY).
|
|
185
|
+
*/
|
|
186
|
+
decimals: number;
|
|
187
|
+
/**
|
|
188
|
+
* - The currency's full name (e.g., 'United States Dollar').
|
|
189
|
+
*/
|
|
190
|
+
name?: string;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* A protocol-agnostic, standardized object representing a supported country.
|
|
194
|
+
*/
|
|
195
|
+
export type SupportedCountry = {
|
|
196
|
+
/**
|
|
197
|
+
* - The country's ISO 3166-1 alpha-2 or alpha-3 code.
|
|
198
|
+
*/
|
|
199
|
+
code: string;
|
|
200
|
+
/**
|
|
201
|
+
* - Whether buying is supported in this country.
|
|
202
|
+
*/
|
|
203
|
+
isBuyAllowed: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* - Whether selling is supported in this country.
|
|
206
|
+
*/
|
|
207
|
+
isSellAllowed: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* - The country's common name.
|
|
210
|
+
*/
|
|
211
|
+
name?: string;
|
|
212
|
+
};
|
|
213
|
+
export type BuyOptions = BuyCommonOptions & (BuyExactCryptoAmountOptions | BuyWithFiatAmountOptions);
|
|
214
|
+
export type BuyCommonOptions = {
|
|
215
|
+
/**
|
|
216
|
+
* - The provider-specific code of the crypto asset to purchase.
|
|
217
|
+
*/
|
|
218
|
+
cryptoAsset: string;
|
|
219
|
+
/**
|
|
220
|
+
* - The currency's ISO 4217 code (e.g., 'USD').
|
|
221
|
+
*/
|
|
222
|
+
fiatCurrency: string;
|
|
223
|
+
/**
|
|
224
|
+
* - The wallet address to receive the purchased crypto asset. Defaults to the account's address.
|
|
225
|
+
*/
|
|
226
|
+
recipient?: string;
|
|
227
|
+
};
|
|
228
|
+
export type BuyExactCryptoAmountOptions = {
|
|
229
|
+
/**
|
|
230
|
+
* - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
|
|
231
|
+
*/
|
|
232
|
+
cryptoAmount: number | bigint;
|
|
233
|
+
/**
|
|
234
|
+
* - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
|
|
235
|
+
*/
|
|
236
|
+
fiatAmount?: never;
|
|
237
|
+
};
|
|
238
|
+
export type BuyWithFiatAmountOptions = {
|
|
239
|
+
/**
|
|
240
|
+
* - The amount of fiat currency to spend, in its smallest unit (e.g., cents for USD).
|
|
241
|
+
*/
|
|
242
|
+
fiatAmount: number | bigint;
|
|
243
|
+
/**
|
|
244
|
+
* - The amount of crypto asset to buy, in its base unit (e.g., wei for ETH).
|
|
245
|
+
*/
|
|
246
|
+
cryptoAmount?: never;
|
|
247
|
+
};
|
|
248
|
+
export type BuyResult = {
|
|
249
|
+
/**
|
|
250
|
+
* - The URL for the user to complete the purchase.
|
|
251
|
+
*/
|
|
252
|
+
buyUrl: string;
|
|
253
|
+
};
|
|
254
|
+
export type SellOptions = SellCommonOptions & (SellExactCryptoAmountOptions | SellForFiatAmountOptions);
|
|
255
|
+
export type SellCommonOptions = {
|
|
256
|
+
/**
|
|
257
|
+
* - The provider-specific code of the crypto asset to sell.
|
|
258
|
+
*/
|
|
259
|
+
cryptoAsset: string;
|
|
260
|
+
/**
|
|
261
|
+
* - The currency's ISO 4217 code (e.g., 'USD').
|
|
262
|
+
*/
|
|
263
|
+
fiatCurrency: string;
|
|
264
|
+
/**
|
|
265
|
+
* - The wallet address to receive refunds in case of failure. Defaults to the account's address.
|
|
266
|
+
*/
|
|
267
|
+
refundAddress?: string;
|
|
268
|
+
};
|
|
269
|
+
export type SellExactCryptoAmountOptions = {
|
|
270
|
+
/**
|
|
271
|
+
* - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
|
|
272
|
+
*/
|
|
273
|
+
cryptoAmount: number | bigint;
|
|
274
|
+
/**
|
|
275
|
+
* - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
|
|
276
|
+
*/
|
|
277
|
+
fiatAmount?: never;
|
|
278
|
+
};
|
|
279
|
+
export type SellForFiatAmountOptions = {
|
|
280
|
+
/**
|
|
281
|
+
* - The amount of fiat currency to receive, in its smallest unit (e.g., cents for USD).
|
|
282
|
+
*/
|
|
283
|
+
fiatAmount: number | bigint;
|
|
284
|
+
/**
|
|
285
|
+
* - The amount of crypto asset to sell, in its base unit (e.g., wei for ETH).
|
|
286
|
+
*/
|
|
287
|
+
cryptoAmount?: never;
|
|
288
|
+
};
|
|
289
|
+
export type SellResult = {
|
|
290
|
+
/**
|
|
291
|
+
* - The URL for the user to complete the sale.
|
|
292
|
+
*/
|
|
293
|
+
sellUrl: string;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* A protocol-agnostic, standardized object representing a quote for an on/off-ramp transaction.
|
|
297
|
+
*/
|
|
298
|
+
export type FiatQuote = {
|
|
299
|
+
/**
|
|
300
|
+
* - The amount of the crypto asset, in its base unit (e.g., wei).
|
|
301
|
+
*/
|
|
302
|
+
cryptoAmount: bigint;
|
|
303
|
+
/**
|
|
304
|
+
* - The amount of the fiat currency, in its smallest unit (e.g., cents).
|
|
305
|
+
*/
|
|
306
|
+
fiatAmount: bigint;
|
|
307
|
+
/**
|
|
308
|
+
* - The fee charged for the transaction, denominated in the smallest unit of the fiat currency.
|
|
309
|
+
*/
|
|
310
|
+
fee: bigint;
|
|
311
|
+
/**
|
|
312
|
+
* - The effective exchange rate, expressed as a string to avoid precision loss (e.g., a rate of "3000.50" for ETH/USD means 1 ETH = 3000.50 USD). Note: This rate applies to the standard units (e.g., ETH and USD).
|
|
313
|
+
*/
|
|
314
|
+
rate: string;
|
|
315
|
+
};
|
|
@@ -12,6 +12,40 @@ export type BorrowOptions = import("./lending-protocol.js").BorrowOptions;
|
|
|
12
12
|
export type BorrowResult = import("./lending-protocol.js").BorrowResult;
|
|
13
13
|
export type RepayOptions = import("./lending-protocol.js").RepayOptions;
|
|
14
14
|
export type RepayResult = import("./lending-protocol.js").RepayResult;
|
|
15
|
+
export type BuyOptions = import("./fiat-protocol.js").BuyOptions;
|
|
16
|
+
export type BuyCommonOptions = import("./fiat-protocol.js").BuyCommonOptions;
|
|
17
|
+
export type BuyExactCryptoAmountOptions = import("./fiat-protocol.js").BuyExactCryptoAmountOptions;
|
|
18
|
+
export type BuyWithFiatAmountOptions = import("./fiat-protocol.js").BuyWithFiatAmountOptions;
|
|
19
|
+
export type BuyResult = import("./fiat-protocol.js").BuyResult;
|
|
20
|
+
export type SellOptions = import("./fiat-protocol.js").SellOptions;
|
|
21
|
+
export type SellCommonOptions = import("./fiat-protocol.js").SellCommonOptions;
|
|
22
|
+
export type SellExactCryptoAmountOptions = import("./fiat-protocol.js").SellExactCryptoAmountOptions;
|
|
23
|
+
export type SellForFiatAmountOptions = import("./fiat-protocol.js").SellForFiatAmountOptions;
|
|
24
|
+
export type SellResult = import("./fiat-protocol.js").SellResult;
|
|
25
|
+
export type FiatQuote = import("./fiat-protocol.js").FiatQuote;
|
|
26
|
+
export type FiatTransactionStatus = import("./fiat-protocol.js").FiatTransactionStatus;
|
|
27
|
+
export type FiatTransactionDetail = import("./fiat-protocol.js").FiatTransactionDetail;
|
|
28
|
+
export type SupportedCryptoAsset = import("./fiat-protocol.js").SupportedCryptoAsset;
|
|
29
|
+
export type SupportedFiatCurrency = import("./fiat-protocol.js").SupportedFiatCurrency;
|
|
30
|
+
export type SupportedCountry = import("./fiat-protocol.js").SupportedCountry;
|
|
31
|
+
export type SwidgeStatus = import("./swidge-protocol.js").SwidgeStatus;
|
|
32
|
+
export type SwidgeFeeType = import("./swidge-protocol.js").SwidgeFeeType;
|
|
33
|
+
export type SwidgeProtocolConfig = import("./swidge-protocol.js").SwidgeProtocolConfig;
|
|
34
|
+
export type SwidgeOptions = import("./swidge-protocol.js").SwidgeOptions;
|
|
35
|
+
export type SwidgeCommonOptions = import("./swidge-protocol.js").SwidgeCommonOptions;
|
|
36
|
+
export type SwidgeExactInOptions = import("./swidge-protocol.js").SwidgeExactInOptions;
|
|
37
|
+
export type SwidgeExactOutOptions = import("./swidge-protocol.js").SwidgeExactOutOptions;
|
|
38
|
+
export type SwidgeFee = import("./swidge-protocol.js").SwidgeFee;
|
|
39
|
+
export type SwidgeTransaction = import("./swidge-protocol.js").SwidgeTransaction;
|
|
40
|
+
export type SwidgeQuote = import("./swidge-protocol.js").SwidgeQuote;
|
|
41
|
+
export type SwidgeResult = import("./swidge-protocol.js").SwidgeResult;
|
|
42
|
+
export type SwidgeStatusOptions = import("./swidge-protocol.js").SwidgeStatusOptions;
|
|
43
|
+
export type SwidgeStatusResult = import("./swidge-protocol.js").SwidgeStatusResult;
|
|
44
|
+
export type SwidgeSupportedChain = import("./swidge-protocol.js").SwidgeSupportedChain;
|
|
45
|
+
export type SwidgeSupportedToken = import("./swidge-protocol.js").SwidgeSupportedToken;
|
|
46
|
+
export type SwidgeSupportedTokensOptions = import("./swidge-protocol.js").SwidgeSupportedTokensOptions;
|
|
15
47
|
export { default as SwapProtocol, ISwapProtocol } from "./swap-protocol.js";
|
|
16
48
|
export { default as BridgeProtocol, IBridgeProtocol } from "./bridge-protocol.js";
|
|
17
49
|
export { default as LendingProtocol, ILendingProtocol } from "./lending-protocol.js";
|
|
50
|
+
export { default as FiatProtocol, IFiatProtocol } from "./fiat-protocol.js";
|
|
51
|
+
export { default as SwidgeProtocol, ISwidgeProtocol } from "./swidge-protocol.js";
|