@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.
@@ -7280,6 +7280,19 @@ var TokenRegistry = class _TokenRegistry {
7280
7280
  // ===========================================================================
7281
7281
  // Cache (StorageProvider)
7282
7282
  // ===========================================================================
7283
+ /**
7284
+ * Per-network cache keys. The registry cache MUST be namespaced by remoteUrl:
7285
+ * testnet and testnet2 ship DIFFERENT coinIds for the same symbol, so a single
7286
+ * global key let a stale testnet snapshot be served for a testnet2 request —
7287
+ * wrong/missing icons AND self-mint resolving the wrong-network coinId. Keying
7288
+ * by remoteUrl isolates the snapshots so a network can never read another's.
7289
+ */
7290
+ cacheKeys() {
7291
+ const base = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE;
7292
+ const baseTs = STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS;
7293
+ if (!this.remoteUrl) return { data: base, ts: baseTs };
7294
+ return { data: `${base}:${this.remoteUrl}`, ts: `${baseTs}:${this.remoteUrl}` };
7295
+ }
7283
7296
  /**
7284
7297
  * Load definitions from StorageProvider cache.
7285
7298
  * Only applies if cache exists and is fresh (within refreshIntervalMs).
@@ -7287,9 +7300,10 @@ var TokenRegistry = class _TokenRegistry {
7287
7300
  async loadFromCache() {
7288
7301
  if (!this.storage) return false;
7289
7302
  try {
7303
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7290
7304
  const [cached, cachedTs] = await Promise.all([
7291
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE),
7292
- this.storage.get(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS)
7305
+ this.storage.get(dataKey),
7306
+ this.storage.get(tsKey)
7293
7307
  ]);
7294
7308
  if (!cached || !cachedTs) return false;
7295
7309
  const ts = parseInt(cachedTs, 10);
@@ -7312,9 +7326,10 @@ var TokenRegistry = class _TokenRegistry {
7312
7326
  async saveToCache(definitions) {
7313
7327
  if (!this.storage) return;
7314
7328
  try {
7329
+ const { data: dataKey, ts: tsKey } = this.cacheKeys();
7315
7330
  await Promise.all([
7316
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE, JSON.stringify(definitions)),
7317
- this.storage.set(STORAGE_KEYS_GLOBAL.TOKEN_REGISTRY_CACHE_TS, String(Date.now()))
7331
+ this.storage.set(dataKey, JSON.stringify(definitions)),
7332
+ this.storage.set(tsKey, String(Date.now()))
7318
7333
  ]);
7319
7334
  } catch {
7320
7335
  }
@@ -28061,6 +28076,8 @@ var Sphere = class _Sphere {
28061
28076
  const walletExists = await _Sphere.exists(options.storage);
28062
28077
  if (walletExists) {
28063
28078
  const sphere2 = await _Sphere.load({
28079
+ network: options.network,
28080
+ // forward network so load's configureTokenRegistry uses it (not the testnet default)
28064
28081
  storage: options.storage,
28065
28082
  transport: options.transport,
28066
28083
  oracle: options.oracle,
@@ -28095,6 +28112,8 @@ var Sphere = class _Sphere {
28095
28112
  }
28096
28113
  const sphere = await _Sphere.create({
28097
28114
  mnemonic,
28115
+ network: options.network,
28116
+ // forward network so create's configureTokenRegistry uses it (not the testnet default)
28098
28117
  storage: options.storage,
28099
28118
  transport: options.transport,
28100
28119
  oracle: options.oracle,
@@ -28182,6 +28201,12 @@ var Sphere = class _Sphere {
28182
28201
  * This method ensures the main bundle's TokenRegistry is properly configured.
28183
28202
  */
28184
28203
  static configureTokenRegistry(storage, network) {
28204
+ if (!network) {
28205
+ logger.warn(
28206
+ "Sphere",
28207
+ "configureTokenRegistry: no network provided \u2014 defaulting to testnet. Pass options.network to avoid loading the wrong-network registry."
28208
+ );
28209
+ }
28185
28210
  const netConfig = network ? NETWORKS[network] : NETWORKS.testnet;
28186
28211
  TokenRegistry.configure({ remoteUrl: netConfig.tokenRegistryUrl, storage });
28187
28212
  }
@@ -28333,7 +28358,8 @@ var Sphere = class _Sphere {
28333
28358
  await options.storage.connect();
28334
28359
  logger.debug("Sphere", "Storage reconnected");
28335
28360
  }
28336
- const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat);
28361
+ _Sphere.configureTokenRegistry(options.storage, options.network);
28362
+ const groupChatConfig = _Sphere.resolveGroupChatConfig(options.groupChat, options.network);
28337
28363
  const marketConfig = _Sphere.resolveMarketConfig(options.market);
28338
28364
  const accountingConfig = _Sphere.resolveAccountingConfig(options.accounting);
28339
28365
  const swapConfig = _Sphere.resolveSwapConfig(options.swap);