@talismn/balances 0.0.0-pr2075-20250711073805 → 0.0.0-pr2075-20250711181503

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.
@@ -4248,12 +4248,19 @@ const getTransferEncodedArgs = (to, value, codec) => {
4248
4248
  return getEncodedValue(codec, [() => ({
4249
4249
  dest: polkadotApi.Enum("Id", to),
4250
4250
  value: BigInt(value)
4251
+ }), () => ({
4252
+ dest: to,
4253
+ // ex: native MYTH on Mythos
4254
+ value: BigInt(value)
4251
4255
  })]);
4252
4256
  };
4253
4257
  const getTransferAllEncodedArgs = (to, codec) => {
4254
4258
  return getEncodedValue(codec, [() => ({
4255
4259
  dest: polkadotApi.Enum("Id", to),
4256
4260
  keep_alive: false
4261
+ }), () => ({
4262
+ dest: to,
4263
+ keep_alive: false
4257
4264
  })]);
4258
4265
  };
4259
4266
 
@@ -4277,19 +4284,15 @@ const subscribeBalances$2 = ({
4277
4284
  return getRpcQueryPack$(connector, networkId, nomPoolQueries);
4278
4285
  }));
4279
4286
  const subtensorBalancesByAddress$ = getSubtensorStakingBalances$(connector, networkId, balanceDefs, miniMetadata);
4280
- return rxjs.combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(rxjs.map(([baseBalances, subtensorBalancesByAddress]) => {
4281
- // add subtensor balances to base balances
4282
- for (const [address, subtensorBalances] of lodashEs.toPairs(subtensorBalancesByAddress)) {
4283
- const balance = baseBalances.find(b => b.address === address);
4284
- if (balance?.values) balance.values = [...balance.values.filter(({
4287
+ return rxjs.combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(rxjs.map(([baseBalances, subtensorBalancesByAddress]) => ({
4288
+ success: [...baseBalances.map(b => ({
4289
+ ...b,
4290
+ values: [...(b.values?.filter(({
4285
4291
  source
4286
- }) => source !== "subtensor-staking"), ...subtensorBalances];
4287
- }
4288
- return {
4289
- success: baseBalances,
4290
- errors: []
4291
- };
4292
- }));
4292
+ }) => source !== "subtensor-staking") ?? []), ...(subtensorBalancesByAddress[b.address] ?? [])]
4293
+ }))],
4294
+ errors: []
4295
+ })));
4293
4296
  };
4294
4297
 
4295
4298
  const SubNativeBalanceModule = {
@@ -6255,12 +6258,19 @@ class BalancesProvider {
6255
6258
  if (!acc[networkId]) acc[networkId] = {};
6256
6259
  acc[networkId][tokenId] = addresses;
6257
6260
  return acc;
6258
- }, {})), rxjs.switchMap(addressesByTokenIdByNetworkId =>
6259
- // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6260
- rxjs.combineLatest({
6261
- isStale: rxjs.timer(30_000).pipe(rxjs.map(() => true), rxjs.startWith(false)),
6262
- results: rxjs.combineLatest(lodashEs.toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6263
- })), rxjs.map(
6261
+ }, {})), rxjs.switchMap(addressesByTokenIdByNetworkId => {
6262
+ // after cleanup we might end up without entries to fetch, which would break the combineLatest below
6263
+ if (!lodashEs.keys(addressesByTokenIdByNetworkId).length) return rxjs.of({
6264
+ isStale: false,
6265
+ results: []
6266
+ });
6267
+
6268
+ // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6269
+ return rxjs.combineLatest({
6270
+ isStale: rxjs.timer(30_000).pipe(rxjs.map(() => true), rxjs.startWith(false)),
6271
+ results: rxjs.combineLatest(lodashEs.toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6272
+ });
6273
+ }), rxjs.map(
6264
6274
  // combine
6265
6275
  ({
6266
6276
  isStale,
@@ -6385,15 +6395,14 @@ class BalancesProvider {
6385
6395
  return this.#chaindataProvider.getNetworkById$(networkId).pipe(rxjs.switchMap(network => chaindataProvider.isNetworkDot(network) ? this.getNetworkSpecVersion$(networkId).pipe(rxjs.switchMap(specVersion => specVersion === null ? rxjs.of([]) : this.getMiniMetadatas$(networkId, specVersion))) : rxjs.of([])));
6386
6396
  }
6387
6397
  getNetworkSpecVersion$(networkId) {
6388
- return rxjs.from(viem.withRetry(async () => {
6389
- if (!this.#chainConnectors.substrate) return null;
6390
- return await getSpecVersion(this.#chainConnectors.substrate, networkId);
6391
- }, {
6392
- delay: 2_000
6398
+ return rxjs.from(viem.withRetry(() => getSpecVersion(this.#chainConnectors.substrate, networkId), {
6399
+ delay: 2_000,
6400
+ shouldRetry: err => {
6401
+ log.warn("Failed to fetch spec version for network, retrying...", networkId, err);
6402
+ return true; // don't give up mate!
6403
+ }
6393
6404
  })).pipe(rxjs.catchError(() => {
6394
- log.warn("Failed to fetch spec version for network", {
6395
- networkId
6396
- });
6405
+ log.warn("Failed to fetch spec version for network", networkId);
6397
6406
  return rxjs.of(null);
6398
6407
  }));
6399
6408
  }
@@ -6413,7 +6422,18 @@ class BalancesProvider {
6413
6422
  if (defaultMiniMetadatas) return rxjs.of(defaultMiniMetadatas);
6414
6423
  if (storedMiniMetadatas) return rxjs.of(storedMiniMetadatas);
6415
6424
  if (!this.#chainConnectors.substrate) return rxjs.of([]);
6416
- return rxjs.from(getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion)).pipe(
6425
+ return rxjs.from(viem.withRetry(() =>
6426
+ // can fail if metadata cant be fetched
6427
+ getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion), {
6428
+ delay: 2_000,
6429
+ shouldRetry: err => {
6430
+ log.warn("Failed to fetch minimetadata for %s, retrying...", networkId, err);
6431
+ return true; // don't give up mate!
6432
+ }
6433
+ })).pipe(rxjs.catchError(() => {
6434
+ log.warn("Failed to fetch metadata for network", networkId);
6435
+ return rxjs.of([]);
6436
+ }),
6417
6437
  // and persist in storage for later reuse
6418
6438
  rxjs.tap(newMiniMetadatas => {
6419
6439
  if (!newMiniMetadatas.length) return;
@@ -4248,12 +4248,19 @@ const getTransferEncodedArgs = (to, value, codec) => {
4248
4248
  return getEncodedValue(codec, [() => ({
4249
4249
  dest: polkadotApi.Enum("Id", to),
4250
4250
  value: BigInt(value)
4251
+ }), () => ({
4252
+ dest: to,
4253
+ // ex: native MYTH on Mythos
4254
+ value: BigInt(value)
4251
4255
  })]);
4252
4256
  };
4253
4257
  const getTransferAllEncodedArgs = (to, codec) => {
4254
4258
  return getEncodedValue(codec, [() => ({
4255
4259
  dest: polkadotApi.Enum("Id", to),
4256
4260
  keep_alive: false
4261
+ }), () => ({
4262
+ dest: to,
4263
+ keep_alive: false
4257
4264
  })]);
4258
4265
  };
4259
4266
 
@@ -4277,19 +4284,15 @@ const subscribeBalances$2 = ({
4277
4284
  return getRpcQueryPack$(connector, networkId, nomPoolQueries);
4278
4285
  }));
4279
4286
  const subtensorBalancesByAddress$ = getSubtensorStakingBalances$(connector, networkId, balanceDefs, miniMetadata);
4280
- return rxjs.combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(rxjs.map(([baseBalances, subtensorBalancesByAddress]) => {
4281
- // add subtensor balances to base balances
4282
- for (const [address, subtensorBalances] of lodashEs.toPairs(subtensorBalancesByAddress)) {
4283
- const balance = baseBalances.find(b => b.address === address);
4284
- if (balance?.values) balance.values = [...balance.values.filter(({
4287
+ return rxjs.combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(rxjs.map(([baseBalances, subtensorBalancesByAddress]) => ({
4288
+ success: [...baseBalances.map(b => ({
4289
+ ...b,
4290
+ values: [...(b.values?.filter(({
4285
4291
  source
4286
- }) => source !== "subtensor-staking"), ...subtensorBalances];
4287
- }
4288
- return {
4289
- success: baseBalances,
4290
- errors: []
4291
- };
4292
- }));
4292
+ }) => source !== "subtensor-staking") ?? []), ...(subtensorBalancesByAddress[b.address] ?? [])]
4293
+ }))],
4294
+ errors: []
4295
+ })));
4293
4296
  };
4294
4297
 
4295
4298
  const SubNativeBalanceModule = {
@@ -6255,12 +6258,19 @@ class BalancesProvider {
6255
6258
  if (!acc[networkId]) acc[networkId] = {};
6256
6259
  acc[networkId][tokenId] = addresses;
6257
6260
  return acc;
6258
- }, {})), rxjs.switchMap(addressesByTokenIdByNetworkId =>
6259
- // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6260
- rxjs.combineLatest({
6261
- isStale: rxjs.timer(30_000).pipe(rxjs.map(() => true), rxjs.startWith(false)),
6262
- results: rxjs.combineLatest(lodashEs.toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6263
- })), rxjs.map(
6261
+ }, {})), rxjs.switchMap(addressesByTokenIdByNetworkId => {
6262
+ // after cleanup we might end up without entries to fetch, which would break the combineLatest below
6263
+ if (!lodashEs.keys(addressesByTokenIdByNetworkId).length) return rxjs.of({
6264
+ isStale: false,
6265
+ results: []
6266
+ });
6267
+
6268
+ // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6269
+ return rxjs.combineLatest({
6270
+ isStale: rxjs.timer(30_000).pipe(rxjs.map(() => true), rxjs.startWith(false)),
6271
+ results: rxjs.combineLatest(lodashEs.toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6272
+ });
6273
+ }), rxjs.map(
6264
6274
  // combine
6265
6275
  ({
6266
6276
  isStale,
@@ -6385,15 +6395,14 @@ class BalancesProvider {
6385
6395
  return this.#chaindataProvider.getNetworkById$(networkId).pipe(rxjs.switchMap(network => chaindataProvider.isNetworkDot(network) ? this.getNetworkSpecVersion$(networkId).pipe(rxjs.switchMap(specVersion => specVersion === null ? rxjs.of([]) : this.getMiniMetadatas$(networkId, specVersion))) : rxjs.of([])));
6386
6396
  }
6387
6397
  getNetworkSpecVersion$(networkId) {
6388
- return rxjs.from(viem.withRetry(async () => {
6389
- if (!this.#chainConnectors.substrate) return null;
6390
- return await getSpecVersion(this.#chainConnectors.substrate, networkId);
6391
- }, {
6392
- delay: 2_000
6398
+ return rxjs.from(viem.withRetry(() => getSpecVersion(this.#chainConnectors.substrate, networkId), {
6399
+ delay: 2_000,
6400
+ shouldRetry: err => {
6401
+ log.warn("Failed to fetch spec version for network, retrying...", networkId, err);
6402
+ return true; // don't give up mate!
6403
+ }
6393
6404
  })).pipe(rxjs.catchError(() => {
6394
- log.warn("Failed to fetch spec version for network", {
6395
- networkId
6396
- });
6405
+ log.warn("Failed to fetch spec version for network", networkId);
6397
6406
  return rxjs.of(null);
6398
6407
  }));
6399
6408
  }
@@ -6413,7 +6422,18 @@ class BalancesProvider {
6413
6422
  if (defaultMiniMetadatas) return rxjs.of(defaultMiniMetadatas);
6414
6423
  if (storedMiniMetadatas) return rxjs.of(storedMiniMetadatas);
6415
6424
  if (!this.#chainConnectors.substrate) return rxjs.of([]);
6416
- return rxjs.from(getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion)).pipe(
6425
+ return rxjs.from(viem.withRetry(() =>
6426
+ // can fail if metadata cant be fetched
6427
+ getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion), {
6428
+ delay: 2_000,
6429
+ shouldRetry: err => {
6430
+ log.warn("Failed to fetch minimetadata for %s, retrying...", networkId, err);
6431
+ return true; // don't give up mate!
6432
+ }
6433
+ })).pipe(rxjs.catchError(() => {
6434
+ log.warn("Failed to fetch metadata for network", networkId);
6435
+ return rxjs.of([]);
6436
+ }),
6417
6437
  // and persist in storage for later reuse
6418
6438
  rxjs.tap(newMiniMetadatas => {
6419
6439
  if (!newMiniMetadatas.length) return;
@@ -4239,12 +4239,19 @@ const getTransferEncodedArgs = (to, value, codec) => {
4239
4239
  return getEncodedValue(codec, [() => ({
4240
4240
  dest: Enum("Id", to),
4241
4241
  value: BigInt(value)
4242
+ }), () => ({
4243
+ dest: to,
4244
+ // ex: native MYTH on Mythos
4245
+ value: BigInt(value)
4242
4246
  })]);
4243
4247
  };
4244
4248
  const getTransferAllEncodedArgs = (to, codec) => {
4245
4249
  return getEncodedValue(codec, [() => ({
4246
4250
  dest: Enum("Id", to),
4247
4251
  keep_alive: false
4252
+ }), () => ({
4253
+ dest: to,
4254
+ keep_alive: false
4248
4255
  })]);
4249
4256
  };
4250
4257
 
@@ -4268,19 +4275,15 @@ const subscribeBalances$2 = ({
4268
4275
  return getRpcQueryPack$(connector, networkId, nomPoolQueries);
4269
4276
  }));
4270
4277
  const subtensorBalancesByAddress$ = getSubtensorStakingBalances$(connector, networkId, balanceDefs, miniMetadata);
4271
- return combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(map(([baseBalances, subtensorBalancesByAddress]) => {
4272
- // add subtensor balances to base balances
4273
- for (const [address, subtensorBalances] of toPairs(subtensorBalancesByAddress)) {
4274
- const balance = baseBalances.find(b => b.address === address);
4275
- if (balance?.values) balance.values = [...balance.values.filter(({
4278
+ return combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(map(([baseBalances, subtensorBalancesByAddress]) => ({
4279
+ success: [...baseBalances.map(b => ({
4280
+ ...b,
4281
+ values: [...(b.values?.filter(({
4276
4282
  source
4277
- }) => source !== "subtensor-staking"), ...subtensorBalances];
4278
- }
4279
- return {
4280
- success: baseBalances,
4281
- errors: []
4282
- };
4283
- }));
4283
+ }) => source !== "subtensor-staking") ?? []), ...(subtensorBalancesByAddress[b.address] ?? [])]
4284
+ }))],
4285
+ errors: []
4286
+ })));
4284
4287
  };
4285
4288
 
4286
4289
  const SubNativeBalanceModule = {
@@ -6246,12 +6249,19 @@ class BalancesProvider {
6246
6249
  if (!acc[networkId]) acc[networkId] = {};
6247
6250
  acc[networkId][tokenId] = addresses;
6248
6251
  return acc;
6249
- }, {})), switchMap(addressesByTokenIdByNetworkId =>
6250
- // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6251
- combineLatest({
6252
- isStale: timer(30_000).pipe(map(() => true), startWith(false)),
6253
- results: combineLatest(toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6254
- })), map(
6252
+ }, {})), switchMap(addressesByTokenIdByNetworkId => {
6253
+ // after cleanup we might end up without entries to fetch, which would break the combineLatest below
6254
+ if (!keys(addressesByTokenIdByNetworkId).length) return of({
6255
+ isStale: false,
6256
+ results: []
6257
+ });
6258
+
6259
+ // fetch balances and start a 30s timer to mark the whole subscription live after 30s
6260
+ return combineLatest({
6261
+ isStale: timer(30_000).pipe(map(() => true), startWith(false)),
6262
+ results: combineLatest(toPairs(addressesByTokenIdByNetworkId).map(([networkId]) => this.getNetworkBalances$(networkId, addressesByTokenIdByNetworkId[networkId])))
6263
+ });
6264
+ }), map(
6255
6265
  // combine
6256
6266
  ({
6257
6267
  isStale,
@@ -6376,15 +6386,14 @@ class BalancesProvider {
6376
6386
  return this.#chaindataProvider.getNetworkById$(networkId).pipe(switchMap(network => isNetworkDot(network) ? this.getNetworkSpecVersion$(networkId).pipe(switchMap(specVersion => specVersion === null ? of([]) : this.getMiniMetadatas$(networkId, specVersion))) : of([])));
6377
6387
  }
6378
6388
  getNetworkSpecVersion$(networkId) {
6379
- return from(withRetry(async () => {
6380
- if (!this.#chainConnectors.substrate) return null;
6381
- return await getSpecVersion(this.#chainConnectors.substrate, networkId);
6382
- }, {
6383
- delay: 2_000
6389
+ return from(withRetry(() => getSpecVersion(this.#chainConnectors.substrate, networkId), {
6390
+ delay: 2_000,
6391
+ shouldRetry: err => {
6392
+ log.warn("Failed to fetch spec version for network, retrying...", networkId, err);
6393
+ return true; // don't give up mate!
6394
+ }
6384
6395
  })).pipe(catchError(() => {
6385
- log.warn("Failed to fetch spec version for network", {
6386
- networkId
6387
- });
6396
+ log.warn("Failed to fetch spec version for network", networkId);
6388
6397
  return of(null);
6389
6398
  }));
6390
6399
  }
@@ -6404,7 +6413,18 @@ class BalancesProvider {
6404
6413
  if (defaultMiniMetadatas) return of(defaultMiniMetadatas);
6405
6414
  if (storedMiniMetadatas) return of(storedMiniMetadatas);
6406
6415
  if (!this.#chainConnectors.substrate) return of([]);
6407
- return from(getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion)).pipe(
6416
+ return from(withRetry(() =>
6417
+ // can fail if metadata cant be fetched
6418
+ getMiniMetadatas(this.#chainConnectors.substrate, this.#chaindataProvider, networkId, specVersion), {
6419
+ delay: 2_000,
6420
+ shouldRetry: err => {
6421
+ log.warn("Failed to fetch minimetadata for %s, retrying...", networkId, err);
6422
+ return true; // don't give up mate!
6423
+ }
6424
+ })).pipe(catchError(() => {
6425
+ log.warn("Failed to fetch metadata for network", networkId);
6426
+ return of([]);
6427
+ }),
6408
6428
  // and persist in storage for later reuse
6409
6429
  tap(newMiniMetadatas => {
6410
6430
  if (!newMiniMetadatas.length) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.0.0-pr2075-20250711073805",
3
+ "version": "0.0.0-pr2075-20250711181503",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -34,13 +34,13 @@
34
34
  "scale-ts": "^1.6.1",
35
35
  "viem": "^2.27.3",
36
36
  "zod": "^3.25.62",
37
- "@talismn/chain-connector": "0.0.0-pr2075-20250711073805",
38
- "@talismn/chain-connector-evm": "0.0.0-pr2075-20250711073805",
39
- "@talismn/scale": "0.0.0-pr2075-20250711073805",
40
- "@talismn/sapi": "0.0.0-pr2075-20250711073805",
41
- "@talismn/chaindata-provider": "0.0.0-pr2075-20250711073805",
42
- "@talismn/token-rates": "0.0.0-pr2075-20250711073805",
43
- "@talismn/util": "0.0.0-pr2075-20250711073805"
37
+ "@talismn/chain-connector-evm": "0.0.0-pr2075-20250711181503",
38
+ "@talismn/chaindata-provider": "0.0.0-pr2075-20250711181503",
39
+ "@talismn/scale": "0.0.0-pr2075-20250711181503",
40
+ "@talismn/token-rates": "0.0.0-pr2075-20250711181503",
41
+ "@talismn/sapi": "0.0.0-pr2075-20250711181503",
42
+ "@talismn/util": "0.0.0-pr2075-20250711181503",
43
+ "@talismn/chain-connector": "0.0.0-pr2075-20250711181503"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@polkadot/api-contract": "16.1.2",