@paxoslabs/amplify-sdk 0.4.1 → 0.4.2

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 (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +8 -0
  3. package/dist/{chunk-QKU5APOV.js → chunk-2YPKHXFJ.js} +120 -120
  4. package/dist/{chunk-QKU5APOV.js.map → chunk-2YPKHXFJ.js.map} +1 -1
  5. package/dist/{chunk-ZPIVBZLP.js → chunk-BQG3XKTU.js} +404 -371
  6. package/dist/chunk-BQG3XKTU.js.map +1 -0
  7. package/dist/{chunk-5FVJVJXC.mjs → chunk-GMMBJB4B.mjs} +7 -7
  8. package/dist/chunk-GMMBJB4B.mjs.map +1 -0
  9. package/dist/{chunk-VDNXXONH.js → chunk-OZJNKGW6.js} +59 -59
  10. package/dist/chunk-OZJNKGW6.js.map +1 -0
  11. package/dist/{chunk-SQ3YW6UK.mjs → chunk-RW7PZETN.mjs} +405 -371
  12. package/dist/chunk-RW7PZETN.mjs.map +1 -0
  13. package/dist/{chunk-PLWWBYSM.mjs → chunk-TPU2HZAX.mjs} +4 -4
  14. package/dist/{chunk-PLWWBYSM.mjs.map → chunk-TPU2HZAX.mjs.map} +1 -1
  15. package/dist/{chunk-Y55F4I3A.mjs → chunk-VZED4E3L.mjs} +5 -27
  16. package/dist/chunk-VZED4E3L.mjs.map +1 -0
  17. package/dist/{chunk-YTCO5BHT.js → chunk-WZXCJAKM.js} +12 -35
  18. package/dist/chunk-WZXCJAKM.js.map +1 -0
  19. package/dist/core.js +16 -16
  20. package/dist/core.mjs +4 -4
  21. package/dist/display.js +9 -9
  22. package/dist/display.mjs +3 -3
  23. package/dist/index.d.mts +28 -28
  24. package/dist/index.d.ts +28 -28
  25. package/dist/index.js +50 -58
  26. package/dist/index.mjs +4 -4
  27. package/dist/utils.js +7 -7
  28. package/dist/utils.mjs +2 -2
  29. package/dist/vaults.js +24 -24
  30. package/dist/vaults.mjs +3 -3
  31. package/package.json +1 -1
  32. package/dist/chunk-5FVJVJXC.mjs.map +0 -1
  33. package/dist/chunk-SQ3YW6UK.mjs.map +0 -1
  34. package/dist/chunk-VDNXXONH.js.map +0 -1
  35. package/dist/chunk-Y55F4I3A.mjs.map +0 -1
  36. package/dist/chunk-YTCO5BHT.js.map +0 -1
  37. package/dist/chunk-ZPIVBZLP.js.map +0 -1
@@ -1,26 +1,6 @@
1
- import { defineChain } from 'viem';
1
+ import { defineChain, createPublicClient, http } from 'viem';
2
2
  import { sepolia, mainnet } from 'viem/chains';
3
3
 
4
- // src/constants/environment.ts
5
- var Environment = {
6
- PRODUCTION: "production",
7
- STAGING: "staging"
8
- };
9
- var ENV_CONFIG = {
10
- production: {
11
- baseUrl: "https://api.paxoslabs.com"
12
- },
13
- staging: {
14
- baseUrl: "https://backend-v2-staging-qfnb.onrender.com"
15
- }
16
- };
17
- function getGraphQLEndpoint(env) {
18
- return `${ENV_CONFIG[env].baseUrl}/graphql`;
19
- }
20
- function getRestV2BaseURL(env) {
21
- return `${ENV_CONFIG[env].baseUrl}/v2`;
22
- }
23
-
24
4
  // src/types/telemetry.ts
25
5
  var LogLevel = {
26
6
  DEBUG: 0,
@@ -106,11 +86,14 @@ function createTimeoutSignal(timeoutMs) {
106
86
  return controller.signal;
107
87
  }
108
88
 
109
- // src/constants/index.ts
110
- var DEFAULT_DEADLINE = 3;
111
- var CHAINLINK_ADDRESS = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
112
- var DEFAULT_APPROVAL_AMOUNT = BigInt(2) ** BigInt(256) - BigInt(1);
113
- var API_BASE_URL = "https://api.paxoslabs.com";
89
+ // src/constants/environment.ts
90
+ var BASE_URL = "https://api.paxoslabs.com";
91
+ function getGraphQLEndpoint() {
92
+ return `${BASE_URL}/graphql`;
93
+ }
94
+ function getRestV2BaseURL() {
95
+ return `${BASE_URL}/v2`;
96
+ }
114
97
 
115
98
  // src/lib/vault-cache.ts
116
99
  var DEFAULT_TTL = 6e5;
@@ -291,6 +274,215 @@ var VaultCache = class {
291
274
  }
292
275
  };
293
276
 
277
+ // src/constants/index.ts
278
+ var DEFAULT_DEADLINE = 3;
279
+ var CHAINLINK_ADDRESS = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
280
+ var DEFAULT_APPROVAL_AMOUNT = BigInt(2) ** BigInt(256) - BigInt(1);
281
+ var API_BASE_URL = "https://api.paxoslabs.com";
282
+
283
+ // src/lib/telemetry.ts
284
+ var SDK_VERSION = "0.1.1-beta.1";
285
+ var MAX_ERROR_BUFFER_SIZE = 10;
286
+ var CONFIG_FETCH_TIMEOUT = 5e3;
287
+ var telemetryState = {
288
+ enabled: false,
289
+ isInitialized: false,
290
+ isInitializing: false,
291
+ initPromise: null,
292
+ config: null,
293
+ apiKey: null
294
+ };
295
+ var posthogClient = null;
296
+ var errorBuffer = [];
297
+ var bufferFullWarningLogged = false;
298
+ function hashApiKey(apiKey) {
299
+ const FNV_OFFSET = BigInt("0xcbf29ce484222325");
300
+ const FNV_PRIME = BigInt("0x100000001b3");
301
+ let hash = FNV_OFFSET;
302
+ for (let i = 0; i < apiKey.length; i++) {
303
+ hash ^= BigInt(apiKey.charCodeAt(i));
304
+ hash = hash * FNV_PRIME & BigInt("0xffffffffffffffff");
305
+ }
306
+ return `sdk_${hash.toString(16).slice(0, 12)}`;
307
+ }
308
+ async function fetchTelemetryConfig(apiKey) {
309
+ const endpoint = "/v1/earn-sdk/config";
310
+ const url = `${API_BASE_URL}${endpoint}`;
311
+ try {
312
+ const headers = getRequestHeaders();
313
+ if (!headers["x-api-key"]) {
314
+ headers["x-api-key"] = apiKey;
315
+ }
316
+ const response = await fetch(url, {
317
+ method: "GET",
318
+ headers,
319
+ signal: createTimeoutSignal(CONFIG_FETCH_TIMEOUT)
320
+ });
321
+ if (!response.ok) {
322
+ return null;
323
+ }
324
+ const data = await response.json();
325
+ if (!data || typeof data.posthogApiKey !== "string") {
326
+ return null;
327
+ }
328
+ return {
329
+ posthogApiKey: data.posthogApiKey,
330
+ posthogHost: data.posthogHost || "https://us.i.posthog.com"
331
+ };
332
+ } catch {
333
+ return null;
334
+ }
335
+ }
336
+ async function flushErrorBuffer() {
337
+ if (errorBuffer.length === 0 || !posthogClient) {
338
+ return;
339
+ }
340
+ for (const bufferedError of errorBuffer) {
341
+ const payload = {
342
+ error_type: bufferedError.name,
343
+ error_message: bufferedError.message,
344
+ error_code: bufferedError.code,
345
+ sdk_version: SDK_VERSION,
346
+ buffered: true,
347
+ ...bufferedError.context
348
+ };
349
+ posthogClient.capture("sdk_error", payload);
350
+ }
351
+ errorBuffer.length = 0;
352
+ }
353
+ async function initTelemetry(apiKey) {
354
+ if (telemetryState.isInitialized) {
355
+ return;
356
+ }
357
+ if (telemetryState.isInitializing && telemetryState.initPromise) {
358
+ await telemetryState.initPromise;
359
+ return;
360
+ }
361
+ telemetryState.isInitializing = true;
362
+ telemetryState.apiKey = apiKey;
363
+ telemetryState.initPromise = (async () => {
364
+ try {
365
+ const config = await fetchTelemetryConfig(apiKey);
366
+ if (!config) {
367
+ telemetryState.enabled = false;
368
+ telemetryState.isInitialized = true;
369
+ return;
370
+ }
371
+ telemetryState.config = config;
372
+ const posthogModule = await import('posthog-js');
373
+ const posthog = posthogModule.default;
374
+ posthog.init(config.posthogApiKey, {
375
+ api_host: config.posthogHost,
376
+ autocapture: false,
377
+ capture_pageview: false,
378
+ capture_pageleave: false,
379
+ disable_session_recording: true,
380
+ persistence: "memory",
381
+ // Don't persist to localStorage
382
+ loaded: (ph) => {
383
+ ph.identify(hashApiKey(apiKey));
384
+ }
385
+ });
386
+ posthogClient = posthog;
387
+ telemetryState.enabled = true;
388
+ telemetryState.isInitialized = true;
389
+ await flushErrorBuffer();
390
+ posthog.capture("sdk_initialized", {
391
+ sdk_version: SDK_VERSION
392
+ });
393
+ } catch (error) {
394
+ const logger = getLogger();
395
+ logger.warn("Telemetry initialization failed", {
396
+ error: error instanceof Error ? error.message : String(error)
397
+ });
398
+ telemetryState.enabled = false;
399
+ telemetryState.isInitialized = true;
400
+ } finally {
401
+ telemetryState.isInitializing = false;
402
+ telemetryState.initPromise = null;
403
+ }
404
+ })();
405
+ await telemetryState.initPromise;
406
+ }
407
+ function trackError(error, context) {
408
+ const logger = getLogger();
409
+ logger.error(error.message, {
410
+ name: error.name,
411
+ stack: error.stack,
412
+ ...context
413
+ });
414
+ const errorDetails = {
415
+ name: error.name,
416
+ message: error.message,
417
+ code: error.code,
418
+ context: context || {},
419
+ timestamp: Date.now()
420
+ };
421
+ if (!posthogClient || !telemetryState.enabled) {
422
+ if (errorBuffer.length < MAX_ERROR_BUFFER_SIZE) {
423
+ errorBuffer.push(errorDetails);
424
+ } else if (!bufferFullWarningLogged) {
425
+ logger.warn(
426
+ `Telemetry error buffer full (${MAX_ERROR_BUFFER_SIZE} errors). Additional errors will not be tracked until telemetry initializes.`
427
+ );
428
+ bufferFullWarningLogged = true;
429
+ }
430
+ return;
431
+ }
432
+ const payload = {
433
+ error_type: error.name,
434
+ error_message: error.message,
435
+ error_code: error.code,
436
+ endpoint: error.endpoint,
437
+ status_code: error.statusCode,
438
+ sdk_version: SDK_VERSION,
439
+ ...context
440
+ };
441
+ posthogClient.capture("sdk_error", payload);
442
+ }
443
+ function resetTelemetry() {
444
+ telemetryState.enabled = false;
445
+ telemetryState.isInitialized = false;
446
+ telemetryState.isInitializing = false;
447
+ telemetryState.initPromise = null;
448
+ telemetryState.config = null;
449
+ telemetryState.apiKey = null;
450
+ posthogClient = null;
451
+ errorBuffer.length = 0;
452
+ bufferFullWarningLogged = false;
453
+ }
454
+
455
+ // src/types/amplify-sdk-api.ts
456
+ var APIError = class _APIError extends Error {
457
+ constructor(message, options) {
458
+ super(message);
459
+ this.name = "APIError";
460
+ this.statusCode = options?.statusCode;
461
+ this.endpoint = options?.endpoint;
462
+ this.cause = options?.cause;
463
+ Object.setPrototypeOf(this, _APIError.prototype);
464
+ if (Error.captureStackTrace) {
465
+ Error.captureStackTrace(this, _APIError);
466
+ }
467
+ try {
468
+ trackError(this, {
469
+ endpoint: this.endpoint,
470
+ statusCode: this.statusCode
471
+ });
472
+ } catch {
473
+ }
474
+ }
475
+ };
476
+ function isValidYieldType(value) {
477
+ return typeof value === "string" && (value === "CORE" || value === "TREASURY" || value === "FRONTIER");
478
+ }
479
+ function isValidAddress(value) {
480
+ return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
481
+ }
482
+ function isValidChainId(value) {
483
+ return typeof value === "number" && value > 0 && Number.isInteger(value);
484
+ }
485
+
294
486
  // src/client/graphql-client.ts
295
487
  var VAULT_FIELDS = `
296
488
  id
@@ -515,8 +707,7 @@ var PAGE_SIZE = 100;
515
707
  var MAX_PAGES = 50;
516
708
  var ENDPOINT_PATH = "/amplify/vaultAssets";
517
709
  async function fetchVaultAssets() {
518
- const env = getEnvironment();
519
- const baseUrl = getRestV2BaseURL(env);
710
+ const baseUrl = getRestV2BaseURL();
520
711
  const allVaultAssets = [];
521
712
  let allTokenMetadata = {};
522
713
  let pageToken = null;
@@ -738,8 +929,7 @@ function validateAssetFilterOptions(options) {
738
929
  }
739
930
  }
740
931
  async function fetchVaultDataFromGraphQL() {
741
- const env = getEnvironment();
742
- const endpoint = getGraphQLEndpoint(env);
932
+ const endpoint = getGraphQLEndpoint();
743
933
  const logger = getLogger();
744
934
  const [graphqlResult, restResult] = await Promise.allSettled([
745
935
  fetchAmplifySdkConfigs(endpoint),
@@ -938,38 +1128,174 @@ async function getWithdrawSupportedAssets() {
938
1128
  }
939
1129
  return result;
940
1130
  }
941
-
942
- // src/lib/sdk-config.ts
943
- var MAX_CACHE_RETRIES = 3;
944
- var RETRY_DELAYS = [1e3, 2e3, 4e3];
945
- var sdkConfig = {
946
- apiKey: null,
947
- isInitialized: false,
948
- initializedAt: null,
949
- isInitializing: false,
950
- initPromise: null,
951
- telemetryEnabled: true,
952
- cachePopulationPromise: null,
953
- isCacheReady: false,
954
- environment: "production"
955
- };
956
- var ERROR_MESSAGES = {
957
- INVALID_API_KEY: "Invalid API key format. Expected format: pxl_<type>_<string>",
958
- EMPTY_API_KEY: "API key cannot be empty. Provide a valid API key from Paxos Labs.",
959
- UNKNOWN_ERROR: "Unexpected initialization error. Contact support if issue persists."};
960
- function validateAPIKey(apiKey) {
961
- if (!apiKey || apiKey.trim().length === 0) {
962
- throw new APIError(ERROR_MESSAGES.EMPTY_API_KEY, {
963
- endpoint: "initAmplifySDK",
964
- statusCode: void 0
965
- });
966
- }
967
- if (apiKey.length < 10) {
968
- throw new APIError(ERROR_MESSAGES.INVALID_API_KEY, {
969
- endpoint: "initAmplifySDK",
970
- statusCode: void 0
971
- });
972
- }
1131
+ var hyperEvm = defineChain({
1132
+ id: 999,
1133
+ name: "HyperEVM",
1134
+ nativeCurrency: {
1135
+ decimals: 18,
1136
+ name: "Hyperliquid",
1137
+ symbol: "HYPE"
1138
+ },
1139
+ rpcUrls: {
1140
+ default: {
1141
+ http: ["https://rpc.hyperliquid.xyz/evm"],
1142
+ webSocket: ["wss://hyperliquid.drpc.org"]
1143
+ }
1144
+ },
1145
+ blockExplorers: {
1146
+ default: { name: "Explorer", url: "https://purrsec.com/" }
1147
+ },
1148
+ contracts: {
1149
+ multicall3: {
1150
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
1151
+ blockCreated: 13051
1152
+ }
1153
+ }
1154
+ });
1155
+ var stableTestnet = defineChain({
1156
+ id: 2201,
1157
+ name: "Stable Testnet",
1158
+ nativeCurrency: {
1159
+ decimals: 18,
1160
+ name: "Ether",
1161
+ symbol: "ETH"
1162
+ },
1163
+ rpcUrls: {
1164
+ default: {
1165
+ http: ["https://rpc.testnet.stable.xyz"]
1166
+ }
1167
+ },
1168
+ blockExplorers: {
1169
+ default: { name: "Stablescan", url: "https://testnet.stablescan.xyz" }
1170
+ },
1171
+ contracts: {
1172
+ multicall3: {
1173
+ address: "0xcA11bde05977b3631167028862bE2a173976CA11",
1174
+ blockCreated: 0
1175
+ }
1176
+ },
1177
+ testnet: true
1178
+ });
1179
+ var CHAIN_ID_TO_CHAIN_MAP = {
1180
+ [mainnet.id]: mainnet,
1181
+ [sepolia.id]: sepolia,
1182
+ [hyperEvm.id]: hyperEvm,
1183
+ [stableTestnet.id]: stableTestnet
1184
+ };
1185
+
1186
+ // src/utils/chain-utils.ts
1187
+ function toChainId(value) {
1188
+ return typeof value === "number" ? value : Number(value);
1189
+ }
1190
+ var chainsCache = null;
1191
+ async function getChainFromConfig(chainId, config) {
1192
+ if (chainsCache && !config) {
1193
+ const chain2 = chainsCache.get(Number(chainId));
1194
+ if (chain2) {
1195
+ return chain2;
1196
+ }
1197
+ }
1198
+ const vaults = config ?? await fetchVaults();
1199
+ const vault = vaults.find((v) => v.chainId === chainId);
1200
+ if (!vault) {
1201
+ throw new Error(`Vault not found for ID: ${chainId}`);
1202
+ }
1203
+ if (config && !chainsCache) {
1204
+ const cache = /* @__PURE__ */ new Map();
1205
+ for (const v of vaults) {
1206
+ const chainConfig = CHAIN_ID_TO_CHAIN_MAP[v.chainId];
1207
+ if (!chainConfig) {
1208
+ throw new Error(`Chain config not found for ID: ${v.chainId}`);
1209
+ }
1210
+ cache.set(v.chainId, {
1211
+ id: v.chainId,
1212
+ name: chainConfig.name,
1213
+ nativeCurrency: chainConfig.nativeCurrency,
1214
+ rpcUrls: chainConfig.rpcUrls,
1215
+ contracts: chainConfig.contracts
1216
+ });
1217
+ }
1218
+ chainsCache = cache;
1219
+ }
1220
+ const chain = chainsCache ? chainsCache.get(chainId) : void 0;
1221
+ if (!chain) {
1222
+ throw new Error(`Chain not found for ID: ${chainId}`);
1223
+ }
1224
+ return chain;
1225
+ }
1226
+ function clearChainsCache() {
1227
+ chainsCache = null;
1228
+ }
1229
+
1230
+ // src/lib/viem/client.ts
1231
+ var clients = /* @__PURE__ */ new Map();
1232
+ var warnedChains = /* @__PURE__ */ new Set();
1233
+ var getClient = async (chainId) => {
1234
+ if (!chainId) {
1235
+ throw new Error("Chain ID is required");
1236
+ }
1237
+ const numericChainId = toChainId(chainId);
1238
+ if (!clients.has(numericChainId)) {
1239
+ const chain = await getChainFromConfig(
1240
+ numericChainId,
1241
+ await fetchVaults()
1242
+ );
1243
+ const customRpcUrl = getRpcUrls()[numericChainId];
1244
+ if (!customRpcUrl && !warnedChains.has(numericChainId)) {
1245
+ warnedChains.add(numericChainId);
1246
+ getLogger().warn(
1247
+ `No custom RPC URL provided for chain ${numericChainId} (${chain.name}). Using default public RPC. Public RPCs may be unreliable \u2014 pass rpcUrls in initAmplifySDK() options for better reliability.`
1248
+ );
1249
+ }
1250
+ const rpcUrl = customRpcUrl ?? chain.rpcUrls.default.http[0];
1251
+ const client2 = createPublicClient({
1252
+ chain,
1253
+ transport: http(rpcUrl)
1254
+ });
1255
+ clients.set(numericChainId, client2);
1256
+ }
1257
+ const client = clients.get(numericChainId);
1258
+ if (!client) {
1259
+ throw new Error(`Client not found for chain ID ${chainId}`);
1260
+ }
1261
+ return client;
1262
+ };
1263
+ function clearClients() {
1264
+ clients.clear();
1265
+ warnedChains.clear();
1266
+ }
1267
+
1268
+ // src/lib/sdk-config.ts
1269
+ var MAX_CACHE_RETRIES = 3;
1270
+ var RETRY_DELAYS = [1e3, 2e3, 4e3];
1271
+ var sdkConfig = {
1272
+ apiKey: null,
1273
+ isInitialized: false,
1274
+ initializedAt: null,
1275
+ isInitializing: false,
1276
+ initPromise: null,
1277
+ telemetryEnabled: true,
1278
+ cachePopulationPromise: null,
1279
+ isCacheReady: false,
1280
+ rpcUrls: {}
1281
+ };
1282
+ var ERROR_MESSAGES = {
1283
+ INVALID_API_KEY: "Invalid API key format. Expected format: pxl_<type>_<string>",
1284
+ EMPTY_API_KEY: "API key cannot be empty. Provide a valid API key from Paxos Labs.",
1285
+ UNKNOWN_ERROR: "Unexpected initialization error. Contact support if issue persists."};
1286
+ function validateAPIKey(apiKey) {
1287
+ if (!apiKey || apiKey.trim().length === 0) {
1288
+ throw new APIError(ERROR_MESSAGES.EMPTY_API_KEY, {
1289
+ endpoint: "initAmplifySDK",
1290
+ statusCode: void 0
1291
+ });
1292
+ }
1293
+ if (apiKey.length < 10) {
1294
+ throw new APIError(ERROR_MESSAGES.INVALID_API_KEY, {
1295
+ endpoint: "initAmplifySDK",
1296
+ statusCode: void 0
1297
+ });
1298
+ }
973
1299
  if (!apiKey.startsWith("pxl_")) ;
974
1300
  }
975
1301
  function setAPIKey(apiKey) {
@@ -978,6 +1304,9 @@ function setAPIKey(apiKey) {
978
1304
  function getAPIKey() {
979
1305
  return sdkConfig.apiKey;
980
1306
  }
1307
+ function getRpcUrls() {
1308
+ return { ...sdkConfig.rpcUrls };
1309
+ }
981
1310
  function clearConfig() {
982
1311
  sdkConfig.apiKey = null;
983
1312
  sdkConfig.isInitialized = false;
@@ -987,12 +1316,10 @@ function clearConfig() {
987
1316
  sdkConfig.telemetryEnabled = true;
988
1317
  sdkConfig.cachePopulationPromise = null;
989
1318
  sdkConfig.isCacheReady = false;
990
- sdkConfig.environment = "production";
1319
+ sdkConfig.rpcUrls = {};
1320
+ clearClients();
991
1321
  resetTelemetry();
992
1322
  }
993
- function getEnvironment() {
994
- return sdkConfig.environment;
995
- }
996
1323
  function getRequestHeaders() {
997
1324
  const apiKey = getAPIKey();
998
1325
  const headers = {
@@ -1058,6 +1385,14 @@ async function waitForCacheReady() {
1058
1385
  async function initAmplifySDK(apiKey, options) {
1059
1386
  validateAPIKey(apiKey);
1060
1387
  if (sdkConfig.isInitialized && sdkConfig.apiKey === apiKey) {
1388
+ const nextRpcUrls = options?.rpcUrls ?? {};
1389
+ const hasRpcUrlChange = Object.keys(nextRpcUrls).length !== Object.keys(sdkConfig.rpcUrls).length || Object.entries(nextRpcUrls).some(
1390
+ ([chainId, url]) => sdkConfig.rpcUrls[Number(chainId)] !== url
1391
+ );
1392
+ if (hasRpcUrlChange) {
1393
+ sdkConfig.rpcUrls = { ...nextRpcUrls };
1394
+ clearClients();
1395
+ }
1061
1396
  return;
1062
1397
  }
1063
1398
  if (sdkConfig.isInitializing && sdkConfig.initPromise) {
@@ -1074,8 +1409,8 @@ async function initAmplifySDK(apiKey, options) {
1074
1409
  if (options?.logLevel !== void 0) {
1075
1410
  setLogLevel(options.logLevel);
1076
1411
  }
1077
- sdkConfig.environment = options?.environment ?? "production";
1078
1412
  sdkConfig.telemetryEnabled = options?.telemetry !== false;
1413
+ sdkConfig.rpcUrls = options?.rpcUrls ?? {};
1079
1414
  sdkConfig.isInitializing = true;
1080
1415
  sdkConfig.initPromise = (async () => {
1081
1416
  try {
@@ -1110,307 +1445,6 @@ async function initAmplifySDK(apiKey, options) {
1110
1445
  await sdkConfig.initPromise;
1111
1446
  }
1112
1447
 
1113
- // src/lib/telemetry.ts
1114
- var SDK_VERSION = "0.1.1-beta.1";
1115
- var MAX_ERROR_BUFFER_SIZE = 10;
1116
- var CONFIG_FETCH_TIMEOUT = 5e3;
1117
- var telemetryState = {
1118
- enabled: false,
1119
- isInitialized: false,
1120
- isInitializing: false,
1121
- initPromise: null,
1122
- config: null,
1123
- apiKey: null
1124
- };
1125
- var posthogClient = null;
1126
- var errorBuffer = [];
1127
- var bufferFullWarningLogged = false;
1128
- function hashApiKey(apiKey) {
1129
- const FNV_OFFSET = BigInt("0xcbf29ce484222325");
1130
- const FNV_PRIME = BigInt("0x100000001b3");
1131
- let hash = FNV_OFFSET;
1132
- for (let i = 0; i < apiKey.length; i++) {
1133
- hash ^= BigInt(apiKey.charCodeAt(i));
1134
- hash = hash * FNV_PRIME & BigInt("0xffffffffffffffff");
1135
- }
1136
- return `sdk_${hash.toString(16).slice(0, 12)}`;
1137
- }
1138
- async function fetchTelemetryConfig(apiKey) {
1139
- const endpoint = "/v1/earn-sdk/config";
1140
- const url = `${API_BASE_URL}${endpoint}`;
1141
- try {
1142
- const headers = getRequestHeaders();
1143
- if (!headers["x-api-key"]) {
1144
- headers["x-api-key"] = apiKey;
1145
- }
1146
- const response = await fetch(url, {
1147
- method: "GET",
1148
- headers,
1149
- signal: createTimeoutSignal(CONFIG_FETCH_TIMEOUT)
1150
- });
1151
- if (!response.ok) {
1152
- return null;
1153
- }
1154
- const data = await response.json();
1155
- if (!data || typeof data.posthogApiKey !== "string") {
1156
- return null;
1157
- }
1158
- return {
1159
- posthogApiKey: data.posthogApiKey,
1160
- posthogHost: data.posthogHost || "https://us.i.posthog.com"
1161
- };
1162
- } catch {
1163
- return null;
1164
- }
1165
- }
1166
- async function flushErrorBuffer() {
1167
- if (errorBuffer.length === 0 || !posthogClient) {
1168
- return;
1169
- }
1170
- for (const bufferedError of errorBuffer) {
1171
- const payload = {
1172
- error_type: bufferedError.name,
1173
- error_message: bufferedError.message,
1174
- error_code: bufferedError.code,
1175
- sdk_version: SDK_VERSION,
1176
- buffered: true,
1177
- ...bufferedError.context
1178
- };
1179
- posthogClient.capture("sdk_error", payload);
1180
- }
1181
- errorBuffer.length = 0;
1182
- }
1183
- async function initTelemetry(apiKey) {
1184
- if (telemetryState.isInitialized) {
1185
- return;
1186
- }
1187
- if (telemetryState.isInitializing && telemetryState.initPromise) {
1188
- await telemetryState.initPromise;
1189
- return;
1190
- }
1191
- telemetryState.isInitializing = true;
1192
- telemetryState.apiKey = apiKey;
1193
- telemetryState.initPromise = (async () => {
1194
- try {
1195
- const config = await fetchTelemetryConfig(apiKey);
1196
- if (!config) {
1197
- telemetryState.enabled = false;
1198
- telemetryState.isInitialized = true;
1199
- return;
1200
- }
1201
- telemetryState.config = config;
1202
- const posthogModule = await import('posthog-js');
1203
- const posthog = posthogModule.default;
1204
- posthog.init(config.posthogApiKey, {
1205
- api_host: config.posthogHost,
1206
- autocapture: false,
1207
- capture_pageview: false,
1208
- capture_pageleave: false,
1209
- disable_session_recording: true,
1210
- persistence: "memory",
1211
- // Don't persist to localStorage
1212
- loaded: (ph) => {
1213
- ph.identify(hashApiKey(apiKey));
1214
- }
1215
- });
1216
- posthogClient = posthog;
1217
- telemetryState.enabled = true;
1218
- telemetryState.isInitialized = true;
1219
- await flushErrorBuffer();
1220
- posthog.capture("sdk_initialized", {
1221
- sdk_version: SDK_VERSION
1222
- });
1223
- } catch (error) {
1224
- const logger = getLogger();
1225
- logger.warn("Telemetry initialization failed", {
1226
- error: error instanceof Error ? error.message : String(error)
1227
- });
1228
- telemetryState.enabled = false;
1229
- telemetryState.isInitialized = true;
1230
- } finally {
1231
- telemetryState.isInitializing = false;
1232
- telemetryState.initPromise = null;
1233
- }
1234
- })();
1235
- await telemetryState.initPromise;
1236
- }
1237
- function trackError(error, context) {
1238
- const logger = getLogger();
1239
- logger.error(error.message, {
1240
- name: error.name,
1241
- stack: error.stack,
1242
- ...context
1243
- });
1244
- const errorDetails = {
1245
- name: error.name,
1246
- message: error.message,
1247
- code: error.code,
1248
- context: context || {},
1249
- timestamp: Date.now()
1250
- };
1251
- if (!posthogClient || !telemetryState.enabled) {
1252
- if (errorBuffer.length < MAX_ERROR_BUFFER_SIZE) {
1253
- errorBuffer.push(errorDetails);
1254
- } else if (!bufferFullWarningLogged) {
1255
- logger.warn(
1256
- `Telemetry error buffer full (${MAX_ERROR_BUFFER_SIZE} errors). Additional errors will not be tracked until telemetry initializes.`
1257
- );
1258
- bufferFullWarningLogged = true;
1259
- }
1260
- return;
1261
- }
1262
- const payload = {
1263
- error_type: error.name,
1264
- error_message: error.message,
1265
- error_code: error.code,
1266
- endpoint: error.endpoint,
1267
- status_code: error.statusCode,
1268
- sdk_version: SDK_VERSION,
1269
- ...context
1270
- };
1271
- posthogClient.capture("sdk_error", payload);
1272
- }
1273
- function resetTelemetry() {
1274
- telemetryState.enabled = false;
1275
- telemetryState.isInitialized = false;
1276
- telemetryState.isInitializing = false;
1277
- telemetryState.initPromise = null;
1278
- telemetryState.config = null;
1279
- telemetryState.apiKey = null;
1280
- posthogClient = null;
1281
- errorBuffer.length = 0;
1282
- bufferFullWarningLogged = false;
1283
- }
1284
-
1285
- // src/types/amplify-sdk-api.ts
1286
- var APIError = class _APIError extends Error {
1287
- constructor(message, options) {
1288
- super(message);
1289
- this.name = "APIError";
1290
- this.statusCode = options?.statusCode;
1291
- this.endpoint = options?.endpoint;
1292
- this.cause = options?.cause;
1293
- Object.setPrototypeOf(this, _APIError.prototype);
1294
- if (Error.captureStackTrace) {
1295
- Error.captureStackTrace(this, _APIError);
1296
- }
1297
- try {
1298
- trackError(this, {
1299
- endpoint: this.endpoint,
1300
- statusCode: this.statusCode
1301
- });
1302
- } catch {
1303
- }
1304
- }
1305
- };
1306
- function isValidYieldType(value) {
1307
- return typeof value === "string" && (value === "CORE" || value === "TREASURY" || value === "FRONTIER");
1308
- }
1309
- function isValidAddress(value) {
1310
- return typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
1311
- }
1312
- function isValidChainId(value) {
1313
- return typeof value === "number" && value > 0 && Number.isInteger(value);
1314
- }
1315
- var hyperEvm = defineChain({
1316
- id: 999,
1317
- name: "HyperEVM",
1318
- nativeCurrency: {
1319
- decimals: 18,
1320
- name: "Hyperliquid",
1321
- symbol: "HYPE"
1322
- },
1323
- rpcUrls: {
1324
- default: {
1325
- http: ["https://rpc.hyperliquid.xyz/evm"],
1326
- webSocket: ["wss://hyperliquid.drpc.org"]
1327
- }
1328
- },
1329
- blockExplorers: {
1330
- default: { name: "Explorer", url: "https://purrsec.com/" }
1331
- },
1332
- contracts: {
1333
- multicall3: {
1334
- address: "0xcA11bde05977b3631167028862bE2a173976CA11",
1335
- blockCreated: 13051
1336
- }
1337
- }
1338
- });
1339
- var stableTestnet = defineChain({
1340
- id: 2201,
1341
- name: "Stable Testnet",
1342
- nativeCurrency: {
1343
- decimals: 18,
1344
- name: "Ether",
1345
- symbol: "ETH"
1346
- },
1347
- rpcUrls: {
1348
- default: {
1349
- http: ["https://rpc.testnet.stable.xyz"]
1350
- }
1351
- },
1352
- blockExplorers: {
1353
- default: { name: "Stablescan", url: "https://testnet.stablescan.xyz" }
1354
- },
1355
- contracts: {
1356
- multicall3: {
1357
- address: "0xcA11bde05977b3631167028862bE2a173976CA11",
1358
- blockCreated: 0
1359
- }
1360
- },
1361
- testnet: true
1362
- });
1363
- var CHAIN_ID_TO_CHAIN_MAP = {
1364
- [mainnet.id]: mainnet,
1365
- [sepolia.id]: sepolia,
1366
- [hyperEvm.id]: hyperEvm,
1367
- [stableTestnet.id]: stableTestnet
1368
- };
1369
-
1370
- // src/utils/chain-utils.ts
1371
- function toChainId(value) {
1372
- return typeof value === "number" ? value : Number(value);
1373
- }
1374
- var chainsCache = null;
1375
- async function getChainFromConfig(chainId, config) {
1376
- if (chainsCache && !config) {
1377
- const chain2 = chainsCache.get(Number(chainId));
1378
- if (chain2) {
1379
- return chain2;
1380
- }
1381
- }
1382
- const vaults = config ?? await fetchVaults();
1383
- const vault = vaults.find((v) => v.chainId === chainId);
1384
- if (!vault) {
1385
- throw new Error(`Vault not found for ID: ${chainId}`);
1386
- }
1387
- if (config && !chainsCache) {
1388
- const cache = /* @__PURE__ */ new Map();
1389
- for (const v of vaults) {
1390
- const chainConfig = CHAIN_ID_TO_CHAIN_MAP[v.chainId];
1391
- if (!chainConfig) {
1392
- throw new Error(`Chain config not found for ID: ${v.chainId}`);
1393
- }
1394
- cache.set(v.chainId, {
1395
- id: v.chainId,
1396
- name: chainConfig.name,
1397
- nativeCurrency: chainConfig.nativeCurrency,
1398
- rpcUrls: chainConfig.rpcUrls,
1399
- contracts: chainConfig.contracts
1400
- });
1401
- }
1402
- chainsCache = cache;
1403
- }
1404
- const chain = chainsCache ? chainsCache.get(chainId) : void 0;
1405
- if (!chain) {
1406
- throw new Error(`Chain not found for ID: ${chainId}`);
1407
- }
1408
- return chain;
1409
- }
1410
- function clearChainsCache() {
1411
- chainsCache = null;
1412
- }
1413
-
1414
- export { APIError, API_BASE_URL, CHAINLINK_ADDRESS, DEFAULT_APPROVAL_AMOUNT, DEFAULT_DEADLINE, DEFAULT_SLIPPAGE_BPS, DEFAULT_TIMEOUT, Environment, LogLevel, YieldType, clearChainsCache, createTimeoutSignal, fetchSupportedAssets, fetchVaults, findVaultByConfig, getAssetsFromCache, getCache, getChainFromConfig, getEnvironment, getLogger, getRequestHeaders, getRestV2BaseURL, getWithdrawSupportedAssets, initAmplifySDK, initializeCache, isCacheReady, isValidAddress, refreshVaultCache, setLogLevel, setLogger, toChainId, waitForCacheReady };
1415
- //# sourceMappingURL=chunk-SQ3YW6UK.mjs.map
1416
- //# sourceMappingURL=chunk-SQ3YW6UK.mjs.map
1448
+ export { APIError, API_BASE_URL, CHAINLINK_ADDRESS, DEFAULT_APPROVAL_AMOUNT, DEFAULT_DEADLINE, DEFAULT_SLIPPAGE_BPS, DEFAULT_TIMEOUT, LogLevel, YieldType, clearChainsCache, createTimeoutSignal, fetchSupportedAssets, fetchVaults, findVaultByConfig, getAssetsFromCache, getCache, getChainFromConfig, getClient, getLogger, getRequestHeaders, getRestV2BaseURL, getWithdrawSupportedAssets, initAmplifySDK, initializeCache, isCacheReady, isValidAddress, refreshVaultCache, setLogLevel, setLogger, toChainId, waitForCacheReady };
1449
+ //# sourceMappingURL=chunk-RW7PZETN.mjs.map
1450
+ //# sourceMappingURL=chunk-RW7PZETN.mjs.map