@unicitylabs/sphere-sdk 0.8.0-dev.3 → 0.8.0-dev.4

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/dist/index.cjs CHANGED
@@ -7562,6 +7562,19 @@ var TokenRegistry = class _TokenRegistry {
7562
7562
  // ===========================================================================
7563
7563
  // Cache (StorageProvider)
7564
7564
  // ===========================================================================
7565
+ /**
7566
+ * Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
7567
+ * testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
7568
+ * global key let a stale testnet snapshot be served for a testnet2 request —
7569
+ * wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
7570
+ * by remoteUrl isolates the snapshots so a network can never read another's.
7571
+ */
7572
+ cacheKeys() {
7573
+ const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
7574
+ const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
7575
+ if (!this.remoteUrl) return { data: base, ts: baseTs };
7576
+ return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
7577
+ }
7565
7578
  /**
7566
7579
  * Load definitions from StorageProvider cache.
7567
7580
  * Only applies if cache exists and is fresh (within refreshIntervalMs).
@@ -7569,9 +7582,10 @@ var TokenRegistry = class _TokenRegistry {
7569
7582
  async loadFromCache() {
7570
7583
  if (!this.storage) return false;
7571
7584
  try {
7585
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7572
7586
  const [cached, cachedTs] = await Promise.all([
7573
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE),
7574
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS)
7587
+ this.storage.get(dataKey),
7588
+ this.storage.get(tsKey)
7575
7589
  ]);
7576
7590
  if (!cached || !cachedTs) return false;
7577
7591
  const ts = parseInt(cachedTs, 10);
@@ -7594,9 +7608,10 @@ var TokenRegistry = class _TokenRegistry {
7594
7608
  async saveToCache(definitions) {
7595
7609
  if (!this.storage) return;
7596
7610
  try {
7611
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7597
7612
  await Promise.all([
7598
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE, JSON.stringify(definitions)),
7599
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS, String(Date.now()))
7613
+ this.storage.set(dataKey, JSON.stringify(definitions)),
7614
+ this.storage.set(tsKey, String(Date.now()))
7600
7615
  ]);
7601
7616
  } catch {
7602
7617
  }
@@ -28420,6 +28435,8 @@ var Sphere = class _Sphere {
28420
28435
  const walletExists = await _Sphere.exists(options.storage);
28421
28436
  if (walletExists) {
28422
28437
  const sphere2 = await _Sphere.load({
28438
+ network: options.network,
28439
+ // forward network so load's configureTokenRegistry uses it (not the testnet default)
28423
28440
  storage: options.storage,
28424
28441
  transport: options.transport,
28425
28442
  oracle: options.oracle,
@@ -28454,6 +28471,8 @@ var Sphere = class _Sphere {
28454
28471
  }
28455
28472
  const sphere = await _Sphere.create({
28456
28473
  mnemonic,
28474
+ network: options.network,
28475
+ // forward network so create's configureTokenRegistry uses it (not the testnet default)
28457
28476
  storage: options.storage,
28458
28477
  transport: options.transport,
28459
28478
  oracle: options.oracle,
@@ -28541,6 +28560,12 @@ var Sphere = class _Sphere {
28541
28560
  * This method ensures the main bundle's TokenRegistry is properly configured.
28542
28561
  */
28543
28562
  static configureTokenRegistry(storage, network) {
28563
+ if (!network) {
28564
+ logger.warn(
28565
+ "Sphere",
28566
+ "configureTokenRegistry: no network provided \u2014 defaulting to testnet. Pass options.network to avoid loading the wrong-network registry."
28567
+ );
28568
+ }
28544
28569
  const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
28545
28570
  TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
28546
28571
  }
@@ -28692,7 +28717,8 @@ var Sphere = class _Sphere {
28692
28717
  await options.storage.connect();
28693
28718
  logger.debug("Sphere", "Storage reconnected");
28694
28719
  }
28695
- const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat);
28720
+ _Sphere.configureTokenRegistry(options.storage, options.network);
28721
+ const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
28696
28722
  const marketConfig = _Sphere.resolveMarketConfig(options.market);
28697
28723
  const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
28698
28724
  const swapConfig = _Sphere.resolveSwapConfig(options.swap);