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