@paxoslabs/amplify-sdk 0.0.1-alpha.1

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 (80) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +28 -0
  3. package/README.md +533 -0
  4. package/dist/amplify-sdk-api-B5hBTGrB.d.ts +258 -0
  5. package/dist/amplify-sdk-api-DPrRhynk.d.mts +258 -0
  6. package/dist/chunk-3I3PYX2F.js +45 -0
  7. package/dist/chunk-3I3PYX2F.js.map +1 -0
  8. package/dist/chunk-7RWWVUHP.mjs +39 -0
  9. package/dist/chunk-7RWWVUHP.mjs.map +1 -0
  10. package/dist/chunk-AFWUOS3M.js +15 -0
  11. package/dist/chunk-AFWUOS3M.js.map +1 -0
  12. package/dist/chunk-BDXS57YH.js +828 -0
  13. package/dist/chunk-BDXS57YH.js.map +1 -0
  14. package/dist/chunk-FYNPQXCR.mjs +46 -0
  15. package/dist/chunk-FYNPQXCR.mjs.map +1 -0
  16. package/dist/chunk-GE2VQUPP.mjs +228 -0
  17. package/dist/chunk-GE2VQUPP.mjs.map +1 -0
  18. package/dist/chunk-ICKDAKVS.js +16 -0
  19. package/dist/chunk-ICKDAKVS.js.map +1 -0
  20. package/dist/chunk-ISO6Z7LD.mjs +809 -0
  21. package/dist/chunk-ISO6Z7LD.mjs.map +1 -0
  22. package/dist/chunk-ITB7FXG4.js +14 -0
  23. package/dist/chunk-ITB7FXG4.js.map +1 -0
  24. package/dist/chunk-J3662HYT.mjs +29 -0
  25. package/dist/chunk-J3662HYT.mjs.map +1 -0
  26. package/dist/chunk-JLXNOGZB.js +2061 -0
  27. package/dist/chunk-JLXNOGZB.js.map +1 -0
  28. package/dist/chunk-O5P6SP2O.js +233 -0
  29. package/dist/chunk-O5P6SP2O.js.map +1 -0
  30. package/dist/chunk-R663BFAZ.mjs +14 -0
  31. package/dist/chunk-R663BFAZ.mjs.map +1 -0
  32. package/dist/chunk-RUIAH5HY.js +32 -0
  33. package/dist/chunk-RUIAH5HY.js.map +1 -0
  34. package/dist/chunk-SIR2TCAR.mjs +13 -0
  35. package/dist/chunk-SIR2TCAR.mjs.map +1 -0
  36. package/dist/chunk-XXHRCCZS.mjs +11 -0
  37. package/dist/chunk-XXHRCCZS.mjs.map +1 -0
  38. package/dist/chunk-ZSFIOWWT.js +49 -0
  39. package/dist/chunk-ZSFIOWWT.js.map +1 -0
  40. package/dist/chunk-ZZBZIDZP.mjs +2050 -0
  41. package/dist/chunk-ZZBZIDZP.mjs.map +1 -0
  42. package/dist/config-B-u3VqEX.d.mts +21 -0
  43. package/dist/config-B-u3VqEX.d.ts +21 -0
  44. package/dist/config-BQynVNDC.d.mts +101 -0
  45. package/dist/config-BQynVNDC.d.ts +101 -0
  46. package/dist/core.d.mts +152 -0
  47. package/dist/core.d.ts +152 -0
  48. package/dist/core.js +187 -0
  49. package/dist/core.js.map +1 -0
  50. package/dist/core.mjs +150 -0
  51. package/dist/core.mjs.map +1 -0
  52. package/dist/display.d.mts +25 -0
  53. package/dist/display.d.ts +25 -0
  54. package/dist/display.js +124 -0
  55. package/dist/display.js.map +1 -0
  56. package/dist/display.mjs +105 -0
  57. package/dist/display.mjs.map +1 -0
  58. package/dist/exchange-rate-CRA_CMaX.d.mts +65 -0
  59. package/dist/exchange-rate-D3_FVgqa.d.ts +65 -0
  60. package/dist/index.d.mts +3236 -0
  61. package/dist/index.d.ts +3236 -0
  62. package/dist/index.js +1115 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/index.mjs +1047 -0
  65. package/dist/index.mjs.map +1 -0
  66. package/dist/utils.d.mts +111 -0
  67. package/dist/utils.d.ts +111 -0
  68. package/dist/utils.js +51 -0
  69. package/dist/utils.js.map +1 -0
  70. package/dist/utils.mjs +17 -0
  71. package/dist/utils.mjs.map +1 -0
  72. package/dist/vault-config-BNzhv3QV.d.ts +15 -0
  73. package/dist/vault-config-BjSE7oL8.d.mts +15 -0
  74. package/dist/vaults.d.mts +6 -0
  75. package/dist/vaults.d.ts +6 -0
  76. package/dist/vaults.js +13 -0
  77. package/dist/vaults.js.map +1 -0
  78. package/dist/vaults.mjs +4 -0
  79. package/dist/vaults.mjs.map +1 -0
  80. package/package.json +142 -0
@@ -0,0 +1,809 @@
1
+ import { defineChain } from 'viem';
2
+ import { swellchain, sei, plumeMainnet, form, boba, mainnet } from 'viem/chains';
3
+
4
+ // src/types/amplify-sdk-api.ts
5
+ var APIError = class _APIError extends Error {
6
+ constructor(message, options) {
7
+ super(message);
8
+ this.name = "APIError";
9
+ this.statusCode = options?.statusCode;
10
+ this.endpoint = options?.endpoint;
11
+ this.cause = options?.cause;
12
+ if (Error.captureStackTrace) {
13
+ Error.captureStackTrace(this, _APIError);
14
+ }
15
+ }
16
+ };
17
+ function isValidYieldType(value) {
18
+ return typeof value === "string" && (value === "PRIME" || value === "TBILL" || value === "LENDING");
19
+ }
20
+ function isValidAddress(value) {
21
+ return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
22
+ }
23
+ function isValidChainId(value) {
24
+ return typeof value === "number" && value > 0 && Number.isInteger(value);
25
+ }
26
+
27
+ // src/lib/vault-cache.ts
28
+ var DEFAULT_TTL = 6e5;
29
+ var VaultCache = class {
30
+ /**
31
+ * Creates a new VaultCache instance
32
+ *
33
+ * @param ttl - Time-to-live in milliseconds (default: 600000 = 10 minutes)
34
+ */
35
+ constructor(ttl = DEFAULT_TTL) {
36
+ this.vaults = /* @__PURE__ */ new Map();
37
+ this.assets = /* @__PURE__ */ new Map();
38
+ this.lastFetch = 0;
39
+ this.ttl = ttl;
40
+ this.refreshing = false;
41
+ }
42
+ /**
43
+ * Gets vaults by deposit token address
44
+ *
45
+ * Returns undefined if no vaults found for the given token address.
46
+ * Does NOT automatically refresh if cache is expired; use refresh() for that.
47
+ *
48
+ * @param tokenAddress - Deposit token address (baseTokenAddress)
49
+ * @returns Array of AmplifyVault objects, or undefined if not found
50
+ */
51
+ getVault(tokenAddress) {
52
+ return this.vaults.get(tokenAddress);
53
+ }
54
+ /**
55
+ * Gets asset by token address
56
+ *
57
+ * Returns undefined if asset not found.
58
+ * Does NOT automatically refresh if cache is expired; use refresh() for that.
59
+ *
60
+ * @param tokenAddress - Token address
61
+ * @returns SupportedAsset object, or undefined if not found
62
+ */
63
+ getAsset(tokenAddress) {
64
+ return this.assets.get(tokenAddress);
65
+ }
66
+ /**
67
+ * Gets all cached vaults
68
+ *
69
+ * Returns an array of all vaults across all deposit tokens.
70
+ * Does NOT automatically refresh if cache is expired; use refresh() for that.
71
+ *
72
+ * @returns Array of all AmplifyVault objects
73
+ */
74
+ getAllVaults() {
75
+ const allVaults = [];
76
+ for (const vaultArray of this.vaults.values()) {
77
+ allVaults.push(...vaultArray);
78
+ }
79
+ return allVaults;
80
+ }
81
+ /**
82
+ * Gets all cached assets
83
+ *
84
+ * Returns an array of all assets.
85
+ * Does NOT automatically refresh if cache is expired; use refresh() for that.
86
+ *
87
+ * @returns Array of all SupportedAsset objects
88
+ */
89
+ getAllAssets() {
90
+ return Array.from(this.assets.values());
91
+ }
92
+ /**
93
+ * Checks if cache is expired
94
+ *
95
+ * Cache is considered expired if current time exceeds lastFetch + ttl.
96
+ *
97
+ * @returns true if cache is expired, false otherwise
98
+ */
99
+ isExpired() {
100
+ return Date.now() > this.lastFetch + this.ttl;
101
+ }
102
+ /**
103
+ * Gets the time until cache expires
104
+ *
105
+ * @returns Milliseconds until expiry, or 0 if already expired
106
+ */
107
+ getTimeUntilExpiry() {
108
+ const expiryTime = this.lastFetch + this.ttl;
109
+ const now = Date.now();
110
+ return Math.max(0, expiryTime - now);
111
+ }
112
+ /**
113
+ * Checks if cache is empty (never populated)
114
+ *
115
+ * @returns true if cache has never been populated, false otherwise
116
+ */
117
+ isEmpty() {
118
+ return this.lastFetch === 0;
119
+ }
120
+ /**
121
+ * Manually refreshes the cache
122
+ *
123
+ * Fetches fresh data from the API and updates both vaults and assets maps.
124
+ * Updates lastFetch timestamp on success.
125
+ *
126
+ * If a refresh is already in progress, this method waits for it to complete
127
+ * instead of starting a concurrent refresh.
128
+ *
129
+ * @throws {APIError} If the API request fails
130
+ */
131
+ async refresh() {
132
+ if (this.refreshing) {
133
+ while (this.refreshing) {
134
+ await new Promise((resolve) => setTimeout(resolve, 100));
135
+ }
136
+ return;
137
+ }
138
+ this.refreshing = true;
139
+ try {
140
+ const [vaultsData, assetsData] = await Promise.all([
141
+ fetchVaults(),
142
+ fetchSupportedAssets()
143
+ ]);
144
+ this.vaults.clear();
145
+ this.assets.clear();
146
+ for (const vault of vaultsData) {
147
+ const tokenAddress = vault.vault.baseTokenAddress;
148
+ const existing = this.vaults.get(tokenAddress);
149
+ if (existing) {
150
+ existing.push(vault);
151
+ } else {
152
+ this.vaults.set(tokenAddress, [vault]);
153
+ }
154
+ }
155
+ for (const asset of assetsData) {
156
+ this.assets.set(asset.address, asset);
157
+ }
158
+ this.lastFetch = Date.now();
159
+ } finally {
160
+ this.refreshing = false;
161
+ }
162
+ }
163
+ /**
164
+ * Clears the cache
165
+ *
166
+ * Removes all cached data and resets lastFetch timestamp.
167
+ * Does not affect TTL setting.
168
+ */
169
+ clear() {
170
+ this.vaults.clear();
171
+ this.assets.clear();
172
+ this.lastFetch = 0;
173
+ }
174
+ /**
175
+ * Gets cache statistics
176
+ *
177
+ * @returns Object with cache statistics
178
+ */
179
+ getStats() {
180
+ return {
181
+ vaultCount: this.getAllVaults().length,
182
+ assetCount: this.assets.size,
183
+ tokenCount: this.vaults.size,
184
+ lastFetch: this.lastFetch,
185
+ ttl: this.ttl,
186
+ isExpired: this.isExpired(),
187
+ isEmpty: this.isEmpty(),
188
+ timeUntilExpiry: this.getTimeUntilExpiry()
189
+ };
190
+ }
191
+ };
192
+
193
+ // src/api/amplify-sdk-client.ts
194
+ var API_BASE_URL = "https://api.paxoslabs.com";
195
+ var DEFAULT_TIMEOUT = 1e4;
196
+ function createTimeoutSignal(timeoutMs) {
197
+ const controller = new AbortController();
198
+ setTimeout(() => controller.abort(), timeoutMs);
199
+ return controller.signal;
200
+ }
201
+ function validateVaultFilterOptions(options) {
202
+ if (!options) return;
203
+ if (options.chainId !== void 0 && !isValidChainId(options.chainId)) {
204
+ throw new APIError(
205
+ `Invalid chainId: ${options.chainId}. Must be a positive integer.`,
206
+ { endpoint: "/v1/earn-sdk/vaults" }
207
+ );
208
+ }
209
+ if (options.yieldType !== void 0 && !isValidYieldType(options.yieldType)) {
210
+ throw new APIError(
211
+ `Invalid yieldType: ${options.yieldType}. Must be one of: PRIME, TBILL, LENDING.`,
212
+ { endpoint: "/v1/earn-sdk/vaults" }
213
+ );
214
+ }
215
+ if (options.depositTokenAddress !== void 0 && !isValidAddress(options.depositTokenAddress)) {
216
+ throw new APIError(
217
+ `Invalid depositTokenAddress: ${options.depositTokenAddress}. Must be a valid Ethereum address.`,
218
+ { endpoint: "/v1/earn-sdk/vaults" }
219
+ );
220
+ }
221
+ }
222
+ function validateAssetFilterOptions(options) {
223
+ if (!options) return;
224
+ if (options.chains !== void 0) {
225
+ if (!Array.isArray(options.chains) || options.chains.length === 0) {
226
+ throw new APIError(
227
+ "Invalid chains: Must be a non-empty array of chain IDs.",
228
+ { endpoint: "/v1/earn-sdk/supported-assets-by-chains" }
229
+ );
230
+ }
231
+ for (const chainId of options.chains) {
232
+ if (!isValidChainId(chainId)) {
233
+ throw new APIError(
234
+ `Invalid chainId in chains array: ${chainId}. Must be a positive integer.`,
235
+ { endpoint: "/v1/earn-sdk/supported-assets-by-chains" }
236
+ );
237
+ }
238
+ }
239
+ }
240
+ if (options.yieldType !== void 0 && !isValidYieldType(options.yieldType)) {
241
+ throw new APIError(
242
+ `Invalid yieldType: ${options.yieldType}. Must be one of: PRIME, TBILL, LENDING.`,
243
+ { endpoint: "/v1/earn-sdk/supported-assets-by-chains" }
244
+ );
245
+ }
246
+ if (options.address !== void 0 && !isValidAddress(options.address)) {
247
+ throw new APIError(
248
+ `Invalid address: ${options.address}. Must be a valid Ethereum address.`,
249
+ { endpoint: "/v1/earn-sdk/supported-assets-by-chains" }
250
+ );
251
+ }
252
+ if (options.symbol !== void 0 && typeof options.symbol !== "string") {
253
+ throw new APIError(`Invalid symbol: ${options.symbol}. Must be a string.`, {
254
+ endpoint: "/v1/earn-sdk/supported-assets-by-chains"
255
+ });
256
+ }
257
+ }
258
+ function validateAmplifyVault(data) {
259
+ if (!data || typeof data !== "object") return false;
260
+ const vaultData = data;
261
+ if (typeof vaultData.id !== "string" || vaultData.id.length === 0)
262
+ return false;
263
+ if (!isValidChainId(vaultData.chainId)) return false;
264
+ if (!isValidYieldType(vaultData.yieldType)) return false;
265
+ if (!vaultData.vault || typeof vaultData.vault !== "object") return false;
266
+ const vault = vaultData.vault;
267
+ if (!isValidAddress(vault.boringVaultAddress)) return false;
268
+ if (!isValidAddress(vault.tellerAddress)) return false;
269
+ if (!isValidAddress(vault.accountantAddress)) return false;
270
+ if (!isValidAddress(vault.managerAddress)) return false;
271
+ if (!isValidAddress(vault.rolesAuthorityAddress)) return false;
272
+ if (!isValidAddress(vault.baseTokenAddress)) return false;
273
+ if (vault.baseTokenStandIn !== void 0 && vault.baseTokenStandIn !== null && !isValidAddress(vault.baseTokenStandIn)) {
274
+ return false;
275
+ }
276
+ if (vault.communityCodeDepositorAddress !== void 0 && vault.communityCodeDepositorAddress !== null && !isValidAddress(vault.communityCodeDepositorAddress)) {
277
+ return false;
278
+ }
279
+ if (!vaultData.supportedAssets || typeof vaultData.supportedAssets !== "object") {
280
+ return false;
281
+ }
282
+ const supportedAssets = vaultData.supportedAssets;
283
+ if (!isValidAddress(supportedAssets.address)) return false;
284
+ if (typeof supportedAssets.symbol !== "string" || supportedAssets.symbol.length === 0) {
285
+ return false;
286
+ }
287
+ if (typeof supportedAssets.name !== "string" || supportedAssets.name.length === 0) {
288
+ return false;
289
+ }
290
+ if (typeof supportedAssets.decimals !== "number" || supportedAssets.decimals < 0 || !Number.isInteger(supportedAssets.decimals)) {
291
+ return false;
292
+ }
293
+ if (supportedAssets.coinGeckoTokenId !== void 0 && typeof supportedAssets.coinGeckoTokenId !== "string") {
294
+ return false;
295
+ }
296
+ return true;
297
+ }
298
+ function validateSupportedAsset(data) {
299
+ if (!data || typeof data !== "object") return false;
300
+ const asset = data;
301
+ if (!isValidAddress(asset.address)) return false;
302
+ if (typeof asset.symbol !== "string" || asset.symbol.length === 0)
303
+ return false;
304
+ if (typeof asset.name !== "string" || asset.name.length === 0) return false;
305
+ if (typeof asset.decimals !== "number" || asset.decimals < 0 || !Number.isInteger(asset.decimals)) {
306
+ return false;
307
+ }
308
+ if (asset.coinGeckoTokenId !== void 0 && typeof asset.coinGeckoTokenId !== "string") {
309
+ return false;
310
+ }
311
+ if (!Array.isArray(asset.chains) || asset.chains.length === 0) {
312
+ return false;
313
+ }
314
+ for (const chainId of asset.chains) {
315
+ if (!isValidChainId(chainId)) return false;
316
+ }
317
+ return true;
318
+ }
319
+ async function fetchVaults(options) {
320
+ const endpoint = "/v1/earn-sdk/vaults";
321
+ validateVaultFilterOptions(options);
322
+ const params = new URLSearchParams();
323
+ if (options?.chainId !== void 0) {
324
+ params.append("chain_id", options.chainId.toString());
325
+ }
326
+ if (options?.yieldType) {
327
+ params.append("yield_type", options.yieldType);
328
+ }
329
+ if (options?.depositTokenAddress) {
330
+ params.append("deposit_token_address", options.depositTokenAddress);
331
+ }
332
+ const url = `${API_BASE_URL}${endpoint}${params.toString() ? `?${params.toString()}` : ""}`;
333
+ try {
334
+ const response = await fetch(url, {
335
+ method: "GET",
336
+ headers: getRequestHeaders(),
337
+ signal: createTimeoutSignal(DEFAULT_TIMEOUT)
338
+ });
339
+ if (!response.ok) {
340
+ const errorText = await response.text().catch(() => "Unknown error");
341
+ throw new APIError(
342
+ `Failed to fetch vaults: ${response.status} ${response.statusText}`,
343
+ {
344
+ statusCode: response.status,
345
+ endpoint,
346
+ cause: errorText
347
+ }
348
+ );
349
+ }
350
+ let data;
351
+ try {
352
+ data = await response.json();
353
+ } catch (error) {
354
+ throw new APIError("Failed to parse vaults response: Invalid JSON", {
355
+ statusCode: response.status,
356
+ endpoint,
357
+ cause: error
358
+ });
359
+ }
360
+ if (!Array.isArray(data)) {
361
+ throw new APIError("Invalid vaults response: Expected array", {
362
+ statusCode: response.status,
363
+ endpoint,
364
+ cause: data
365
+ });
366
+ }
367
+ const vaults = [];
368
+ for (let i = 0; i < data.length; i++) {
369
+ const vault = data[i];
370
+ if (!validateAmplifyVault(vault)) {
371
+ throw new APIError(
372
+ `Invalid vault data at index ${i}: Failed validation`,
373
+ {
374
+ statusCode: response.status,
375
+ endpoint,
376
+ cause: vault
377
+ }
378
+ );
379
+ }
380
+ vaults.push(vault);
381
+ }
382
+ return vaults;
383
+ } catch (error) {
384
+ if (error instanceof Error && error.name === "AbortError") {
385
+ throw new APIError(`Failed to fetch vaults: Network timeout`, {
386
+ endpoint,
387
+ cause: error
388
+ });
389
+ }
390
+ if (error instanceof APIError) {
391
+ throw error;
392
+ }
393
+ if (error instanceof TypeError) {
394
+ throw new APIError(`Failed to fetch vaults: Network error`, {
395
+ endpoint,
396
+ cause: error
397
+ });
398
+ }
399
+ throw new APIError(`Failed to fetch vaults: Unknown error`, {
400
+ endpoint,
401
+ cause: error
402
+ });
403
+ }
404
+ }
405
+ async function fetchSupportedAssets(options) {
406
+ const endpoint = "/v1/earn-sdk/supported-assets-by-chains";
407
+ validateAssetFilterOptions(options);
408
+ const params = new URLSearchParams();
409
+ if (options?.chains !== void 0 && options.chains.length > 0) {
410
+ params.append("chains", options.chains.join(","));
411
+ }
412
+ if (options?.yieldType) {
413
+ params.append("yield_type", options.yieldType);
414
+ }
415
+ const url = `${API_BASE_URL}${endpoint}${params.toString() ? `?${params.toString()}` : ""}`;
416
+ try {
417
+ const response = await fetch(url, {
418
+ method: "GET",
419
+ headers: getRequestHeaders(),
420
+ signal: createTimeoutSignal(DEFAULT_TIMEOUT)
421
+ });
422
+ if (!response.ok) {
423
+ const errorText = await response.text().catch(() => "Unknown error");
424
+ throw new APIError(
425
+ `Failed to fetch supported assets: ${response.status} ${response.statusText}`,
426
+ {
427
+ statusCode: response.status,
428
+ endpoint,
429
+ cause: errorText
430
+ }
431
+ );
432
+ }
433
+ let data;
434
+ try {
435
+ data = await response.json();
436
+ } catch (error) {
437
+ throw new APIError(
438
+ "Failed to parse supported assets response: Invalid JSON",
439
+ {
440
+ statusCode: response.status,
441
+ endpoint,
442
+ cause: error
443
+ }
444
+ );
445
+ }
446
+ if (!Array.isArray(data)) {
447
+ throw new APIError("Invalid supported assets response: Expected array", {
448
+ statusCode: response.status,
449
+ endpoint,
450
+ cause: data
451
+ });
452
+ }
453
+ const assets = [];
454
+ for (let i = 0; i < data.length; i++) {
455
+ const asset = data[i];
456
+ if (!validateSupportedAsset(asset)) {
457
+ throw new APIError(
458
+ `Invalid asset data at index ${i}: Failed validation`,
459
+ {
460
+ statusCode: response.status,
461
+ endpoint,
462
+ cause: asset
463
+ }
464
+ );
465
+ }
466
+ assets.push(asset);
467
+ }
468
+ return assets;
469
+ } catch (error) {
470
+ if (error instanceof Error && error.name === "AbortError") {
471
+ throw new APIError(`Failed to fetch supported assets: Network timeout`, {
472
+ endpoint,
473
+ cause: error
474
+ });
475
+ }
476
+ if (error instanceof APIError) {
477
+ throw error;
478
+ }
479
+ if (error instanceof TypeError) {
480
+ throw new APIError(`Failed to fetch supported assets: Network error`, {
481
+ endpoint,
482
+ cause: error
483
+ });
484
+ }
485
+ throw new APIError(`Failed to fetch supported assets: Unknown error`, {
486
+ endpoint,
487
+ cause: error
488
+ });
489
+ }
490
+ }
491
+ var globalCache = null;
492
+ function initializeCache(ttl) {
493
+ globalCache = new VaultCache(ttl);
494
+ return globalCache;
495
+ }
496
+ function getCache() {
497
+ if (!globalCache) {
498
+ globalCache = new VaultCache();
499
+ }
500
+ return globalCache;
501
+ }
502
+ async function refreshVaultCache() {
503
+ const cache = getCache();
504
+ await cache.refresh();
505
+ }
506
+ function clearCache() {
507
+ const cache = getCache();
508
+ cache.clear();
509
+ }
510
+ async function getAssetsFromCache(options) {
511
+ const cache = getCache();
512
+ if (cache.isEmpty() || cache.isExpired()) {
513
+ await cache.refresh();
514
+ }
515
+ let assets = cache.getAllAssets();
516
+ if (options?.chains !== void 0 && options.chains.length > 0) {
517
+ assets = assets.filter(
518
+ (asset) => options.chains?.some((chainId) => asset.chains.includes(chainId))
519
+ );
520
+ }
521
+ if (options?.address) {
522
+ const normalizedAddress = options.address.toLowerCase();
523
+ assets = assets.filter(
524
+ (asset) => asset.address.toLowerCase() === normalizedAddress
525
+ );
526
+ }
527
+ if (options?.symbol) {
528
+ assets = assets.filter((asset) => asset.symbol === options.symbol);
529
+ }
530
+ return assets;
531
+ }
532
+ async function findVaultByConfig(params) {
533
+ if (!isValidAddress(params.assetAddress)) {
534
+ throw new APIError(
535
+ `Invalid assetAddress: ${params.assetAddress}. Must be a valid Ethereum address.`,
536
+ { endpoint: "findVaultByConfig" }
537
+ );
538
+ }
539
+ if (!isValidYieldType(params.yieldType)) {
540
+ throw new APIError(
541
+ `Invalid yieldType: ${params.yieldType}. Must be one of: PRIME, TBILL, LENDING.`,
542
+ { endpoint: "findVaultByConfig" }
543
+ );
544
+ }
545
+ if (!isValidChainId(params.chainId)) {
546
+ throw new APIError(
547
+ `Invalid chainId: ${params.chainId}. Must be a positive integer.`,
548
+ { endpoint: "findVaultByConfig" }
549
+ );
550
+ }
551
+ const cache = getCache();
552
+ if (cache.isExpired()) {
553
+ await cache.refresh();
554
+ }
555
+ const normalizedAddress = params.assetAddress.toLowerCase();
556
+ let vaultsByToken = cache.getVault(params.assetAddress);
557
+ if (!vaultsByToken) {
558
+ vaultsByToken = cache.getVault(normalizedAddress);
559
+ }
560
+ if (!vaultsByToken) {
561
+ const allVaults = cache.getAllVaults();
562
+ const matchingVaults = allVaults.filter(
563
+ (vault) => vault.vault.baseTokenAddress.toLowerCase() === normalizedAddress
564
+ );
565
+ vaultsByToken = matchingVaults.length > 0 ? matchingVaults : void 0;
566
+ }
567
+ if (!vaultsByToken || vaultsByToken.length === 0) {
568
+ return null;
569
+ }
570
+ const matchingVault = vaultsByToken.find(
571
+ (vault) => vault.yieldType === params.yieldType && vault.chainId === params.chainId
572
+ );
573
+ return matchingVault || null;
574
+ }
575
+ async function getWithdrawSupportedAssets() {
576
+ const cache = getCache();
577
+ if (cache.isEmpty() || cache.isExpired()) {
578
+ await cache.refresh();
579
+ }
580
+ const vaults = cache.getAllVaults();
581
+ const assets = cache.getAllAssets();
582
+ const result = [];
583
+ const assetMap = /* @__PURE__ */ new Map();
584
+ for (const asset of assets) {
585
+ assetMap.set(asset.address.toLowerCase(), asset);
586
+ }
587
+ const assetVaultMap = /* @__PURE__ */ new Map();
588
+ for (const vault of vaults) {
589
+ const assetAddress = vault.vault.baseTokenAddress.toLowerCase();
590
+ if (!assetVaultMap.has(assetAddress)) {
591
+ assetVaultMap.set(assetAddress, []);
592
+ }
593
+ assetVaultMap.get(assetAddress)?.push({
594
+ id: vault.id,
595
+ yieldType: vault.yieldType,
596
+ chainId: vault.chainId,
597
+ vaultId: vault.id
598
+ });
599
+ }
600
+ for (const [assetAddress, vaultsData] of assetVaultMap.entries()) {
601
+ const asset = assetMap.get(assetAddress);
602
+ if (asset) {
603
+ result.push({
604
+ address: asset.address,
605
+ symbol: asset.symbol,
606
+ decimals: asset.decimals,
607
+ vaults: vaultsData
608
+ });
609
+ }
610
+ }
611
+ return result;
612
+ }
613
+
614
+ // src/lib/sdk-config.ts
615
+ var sdkConfig = {
616
+ apiKey: null,
617
+ isInitialized: false,
618
+ initializedAt: null,
619
+ isInitializing: false,
620
+ initPromise: null
621
+ };
622
+ var ERROR_MESSAGES = {
623
+ INVALID_API_KEY: "Invalid API key format. Expected format: pxl_<type>_<string>",
624
+ EMPTY_API_KEY: "API key cannot be empty. Provide a valid API key from Paxos Labs.",
625
+ CACHE_INIT_FAILED: "Failed to initialize cache. Retry or check API status."};
626
+ function validateAPIKey(apiKey) {
627
+ if (!apiKey || apiKey.trim().length === 0) {
628
+ throw new APIError(ERROR_MESSAGES.EMPTY_API_KEY, {
629
+ endpoint: "initAmplifySDK",
630
+ statusCode: void 0
631
+ });
632
+ }
633
+ if (apiKey.length < 10) {
634
+ throw new APIError(ERROR_MESSAGES.INVALID_API_KEY, {
635
+ endpoint: "initAmplifySDK",
636
+ statusCode: void 0
637
+ });
638
+ }
639
+ if (!apiKey.startsWith("pxl_")) ;
640
+ }
641
+ function setAPIKey(apiKey) {
642
+ sdkConfig.apiKey = apiKey;
643
+ }
644
+ function getAPIKey() {
645
+ return sdkConfig.apiKey;
646
+ }
647
+ function clearConfig() {
648
+ sdkConfig.apiKey = null;
649
+ sdkConfig.isInitialized = false;
650
+ sdkConfig.initializedAt = null;
651
+ sdkConfig.isInitializing = false;
652
+ sdkConfig.initPromise = null;
653
+ }
654
+ function getRequestHeaders() {
655
+ const apiKey = getAPIKey();
656
+ const headers = {
657
+ "Content-Type": "application/json"
658
+ };
659
+ if (apiKey) {
660
+ headers["x-api-key"] = apiKey;
661
+ }
662
+ return headers;
663
+ }
664
+ async function initAmplifySDK(apiKey) {
665
+ validateAPIKey(apiKey);
666
+ if (sdkConfig.isInitialized && sdkConfig.apiKey === apiKey) {
667
+ return;
668
+ }
669
+ if (sdkConfig.isInitializing && sdkConfig.initPromise) {
670
+ await sdkConfig.initPromise;
671
+ return;
672
+ }
673
+ if (sdkConfig.isInitialized && sdkConfig.apiKey !== apiKey) {
674
+ clearConfig();
675
+ clearCache();
676
+ }
677
+ sdkConfig.isInitializing = true;
678
+ sdkConfig.initPromise = (async () => {
679
+ try {
680
+ setAPIKey(apiKey);
681
+ const cache = initializeCache();
682
+ await cache.refresh();
683
+ sdkConfig.isInitialized = true;
684
+ sdkConfig.initializedAt = /* @__PURE__ */ new Date();
685
+ } catch (error) {
686
+ clearConfig();
687
+ clearCache();
688
+ if (error instanceof APIError) {
689
+ throw error;
690
+ }
691
+ throw new APIError(ERROR_MESSAGES.CACHE_INIT_FAILED, {
692
+ endpoint: "initAmplifySDK",
693
+ cause: error
694
+ });
695
+ } finally {
696
+ sdkConfig.isInitializing = false;
697
+ sdkConfig.initPromise = null;
698
+ }
699
+ })();
700
+ await sdkConfig.initPromise;
701
+ }
702
+ var rari = defineChain({
703
+ id: 1380012617,
704
+ name: "Rari Chain",
705
+ nativeCurrency: {
706
+ name: "Ether",
707
+ symbol: "ETH",
708
+ decimals: 18
709
+ },
710
+ rpcUrls: {
711
+ default: {
712
+ http: ["https://mainnet.rpc.rarichain.org/http"],
713
+ webSocket: ["wss://mainnet.rpc.rarichain.org/ws"]
714
+ }
715
+ },
716
+ blockExplorers: {
717
+ default: {
718
+ name: "Rari Explorer",
719
+ url: "https://mainnet.explorer.rarichain.org"
720
+ }
721
+ },
722
+ contracts: {
723
+ multicall3: {
724
+ address: "0x3F5Fc48153f8aDd3E429F0c84fA6FEd5c58657Dc"
725
+ }
726
+ }
727
+ });
728
+ var hyperEvm = defineChain({
729
+ id: 999,
730
+ name: "HyperEVM",
731
+ nativeCurrency: {
732
+ decimals: 18,
733
+ name: "Hyperliquid",
734
+ symbol: "HYPE"
735
+ },
736
+ rpcUrls: {
737
+ default: {
738
+ http: ["https://rpc.hyperliquid.xyz/evm"],
739
+ webSocket: ["wss://hyperliquid.drpc.org"]
740
+ }
741
+ },
742
+ blockExplorers: {
743
+ default: { name: "Explorer", url: "https://purrsec.com/" }
744
+ },
745
+ contracts: {
746
+ multicall3: {
747
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
748
+ blockCreated: 13051
749
+ }
750
+ }
751
+ });
752
+ var CHAIN_ID_TO_CHAIN_MAP = {
753
+ [mainnet.id]: mainnet,
754
+ [boba.id]: boba,
755
+ [form.id]: form,
756
+ [hyperEvm.id]: hyperEvm,
757
+ [plumeMainnet.id]: plumeMainnet,
758
+ [rari.id]: rari,
759
+ [sei.id]: sei,
760
+ [swellchain.id]: swellchain
761
+ };
762
+
763
+ // src/utils/chain-utils.ts
764
+ var chainsCache = null;
765
+ async function getChainFromConfig(chainId, config) {
766
+ if (chainsCache && !config) {
767
+ const chain2 = chainsCache.get(Number(chainId));
768
+ if (chain2) return chain2;
769
+ }
770
+ const vaults = config ?? await fetchVaults();
771
+ const vault = vaults.find((v) => v.chainId === chainId);
772
+ if (!vault) {
773
+ throw new Error(`Vault not found for ID: ${chainId}`);
774
+ }
775
+ if (config && !chainsCache) {
776
+ const cache = /* @__PURE__ */ new Map();
777
+ for (const v of vaults) {
778
+ if (v.chainId === chainId) {
779
+ cache.set(v.chainId, {
780
+ id: v.chainId,
781
+ name: CHAIN_ID_TO_CHAIN_MAP[v.chainId]?.name,
782
+ nativeCurrency: CHAIN_ID_TO_CHAIN_MAP[v.chainId]?.nativeCurrency,
783
+ rpcUrls: CHAIN_ID_TO_CHAIN_MAP[v.chainId]?.rpcUrls
784
+ });
785
+ }
786
+ }
787
+ chainsCache = cache;
788
+ }
789
+ const chain = chainsCache ? chainsCache.get(chainId) : void 0;
790
+ if (!chain) {
791
+ throw new Error(`Chain not found for ID: ${chainId}`);
792
+ }
793
+ return chain;
794
+ }
795
+ function clearChainsCache() {
796
+ chainsCache = null;
797
+ }
798
+
799
+ // src/constants/index.ts
800
+ var ATOMIC_QUEUE_CONTRACT_ADDRESS = "0x228c44bb4885c6633f4b6c83f14622f37d5112e5";
801
+ var DEFAULT_DEADLINE = 3;
802
+ var NATIVE_TOKEN_FOR_BRIDGE_FEE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
803
+ var CHAINLINK_ADDRESS = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
804
+ var DEFAULT_APPROVAL_AMOUNT = BigInt(2) ** BigInt(256) - BigInt(1);
805
+ var NUCLEUS_BASE_URL = "https://backend.nucleusearn.io/v1/protocol";
806
+
807
+ export { APIError, ATOMIC_QUEUE_CONTRACT_ADDRESS, CHAINLINK_ADDRESS, DEFAULT_APPROVAL_AMOUNT, DEFAULT_DEADLINE, NATIVE_TOKEN_FOR_BRIDGE_FEE, NUCLEUS_BASE_URL, clearChainsCache, fetchSupportedAssets, fetchVaults, findVaultByConfig, getAssetsFromCache, getCache, getChainFromConfig, getWithdrawSupportedAssets, initAmplifySDK, initializeCache, refreshVaultCache };
808
+ //# sourceMappingURL=chunk-ISO6Z7LD.mjs.map
809
+ //# sourceMappingURL=chunk-ISO6Z7LD.mjs.map