@talismn/balances 0.9.9 → 0.9.11

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.
@@ -2,6 +2,7 @@ import { NewBalanceModule } from "../../BalanceModule";
2
2
  import { CustomSubNativeToken, ModuleType, SubNativeChainMeta, SubNativeModuleConfig, SubNativeToken, SubNativeTransferParams } from "./types";
3
3
  export { filterBaseLocks, getLockTitle } from "./util/balanceLockTypes";
4
4
  export type { BalanceLockType } from "./util/balanceLockTypes";
5
- export type { CustomSubNativeToken, ModuleType, SubNativeBalance, SubNativeChainMeta, SubNativeModuleConfig, SubNativeToken, SubNativeTransferParams, } from "./types";
6
5
  export { subNativeTokenId } from "./types";
6
+ export type { CustomSubNativeToken, ModuleType, SubNativeBalance, SubNativeChainMeta, SubNativeModuleConfig, SubNativeToken, SubNativeTransferParams, } from "./types";
7
+ export * from "./util/subtensor";
7
8
  export declare const SubNativeModule: NewBalanceModule<ModuleType, SubNativeToken | CustomSubNativeToken, SubNativeChainMeta, SubNativeModuleConfig, SubNativeTransferParams>;
@@ -0,0 +1 @@
1
+ export * from "./multicall";
@@ -58,3 +58,4 @@ export * from "./SubstrateNativeModule";
58
58
  export * from "./SubstratePsp22Module";
59
59
  export * from "./SubstrateTokensModule";
60
60
  export * from "./util";
61
+ export * from "./abis";
@@ -18,6 +18,12 @@ export declare const buildStorageCoders: <TBalanceModule extends AnyNewBalanceMo
18
18
  moduleType: InferModuleType<TBalanceModule>;
19
19
  coders: TCoders;
20
20
  }) => Map<string, { [Property in keyof TCoders]: {
21
+ args: [import("scale-ts").Encoder<any[]>, import("scale-ts").Decoder<any[]>] & {
22
+ enc: import("scale-ts").Encoder<any[]>;
23
+ dec: import("scale-ts").Decoder<any[]>;
24
+ } & {
25
+ inner: import("@talismn/scale").Codec<any>[];
26
+ };
21
27
  keys: {
22
28
  enc: (...args: any[]) => string;
23
29
  dec: (value: string) => any[];
@@ -2,11 +2,10 @@
2
2
 
3
3
  var PromisePool = require('@supercharge/promise-pool');
4
4
  var chaindataProvider = require('@talismn/chaindata-provider');
5
- var scale = require('@talismn/scale');
5
+ var sapi = require('@talismn/sapi');
6
6
  var dexie = require('dexie');
7
7
  var isEqual = require('lodash/isEqual');
8
8
  var rxjs = require('rxjs');
9
- var scaleTs = require('scale-ts');
10
9
  var anylogger = require('anylogger');
11
10
  var tokenRates = require('@talismn/token-rates');
12
11
  var util = require('@talismn/util');
@@ -16,13 +15,14 @@ var utilCrypto = require('@polkadot/util-crypto');
16
15
  var pako = require('pako');
17
16
  var viem = require('viem');
18
17
  var txwrapperCore = require('@substrate/txwrapper-core');
18
+ var scale = require('@talismn/scale');
19
19
  var camelCase = require('lodash/camelCase');
20
20
  var types = require('@polkadot/types');
21
21
  var groupBy = require('lodash/groupBy');
22
22
  var utils = require('@polkadot-api/utils');
23
23
  var polkadotApi = require('polkadot-api');
24
24
  var chainConnector = require('@talismn/chain-connector');
25
- var sapi = require('@talismn/sapi');
25
+ var scaleTs = require('scale-ts');
26
26
  var upperFirst = require('lodash/upperFirst');
27
27
  var apiContract = require('@polkadot/api-contract');
28
28
  var lzString = require('lz-string');
@@ -1185,25 +1185,16 @@ class MiniMetadataUpdater {
1185
1185
  if (specName === null) return;
1186
1186
  if (specVersion === null) return;
1187
1187
  const fetchMetadata = async () => {
1188
- const errors = {
1189
- v15: null,
1190
- v14: null
1191
- };
1192
- try {
1193
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_call", ["Metadata_metadata_at_version", scale.toHex(scaleTs.u32.enc(15))]);
1194
- const result = response ? scaleTs.Option(scaleTs.Bytes()).dec(response) : null;
1195
- if (result) return result;
1196
- } catch (v15Cause) {
1197
- errors.v15 = v15Cause;
1198
- }
1199
1188
  try {
1200
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_getMetadata", []);
1201
- if (response) return response;
1202
- } catch (v14Cause) {
1203
- errors.v14 = v14Cause;
1189
+ return await sapi.fetchBestMetadata((method, params, isCacheable) => {
1190
+ if (!this.#chainConnectors.substrate) throw new Error("Substrate connector is not available");
1191
+ return this.#chainConnectors.substrate.send(chainId, method, params, isCacheable);
1192
+ }, true // allow v14 fallback
1193
+ );
1194
+ } catch (err) {
1195
+ log.warn(`Failed to fetch metadata for chain ${chainId}`);
1196
+ return undefined;
1204
1197
  }
1205
- log.warn(`Failed to fetch both metadata v15 and v14 for chain ${chainId}`, errors.v15, errors.v14);
1206
- return null;
1207
1198
  };
1208
1199
  const [metadataRpc, systemProperties] = await Promise.all([fetchMetadata(), this.#chainConnectors.substrate?.send(chainId, "system_properties", [])]);
1209
1200
  for (const mod of this.#balanceModules.filter(m => m.type.startsWith("substrate-"))) {
@@ -2948,11 +2939,7 @@ const buildStorageCoders = ({
2948
2939
  const [, miniMetadata] = findChainMeta(miniMetadatas, moduleType, chain);
2949
2940
  if (!miniMetadata) return [];
2950
2941
  if (!miniMetadata.data) return [];
2951
- const {
2952
- metadata,
2953
- tag
2954
- } = scale.decodeMetadata(miniMetadata.data);
2955
- if (!metadata || !tag) return [];
2942
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata.data));
2956
2943
  try {
2957
2944
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
2958
2945
  const builtCoders = Object.fromEntries(Object.entries(coders).flatMap(([key, moduleMethodOrFn]) => {
@@ -3181,25 +3168,13 @@ const SubAssetsModule = hydrate => {
3181
3168
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3182
3169
  isTestnet
3183
3170
  };
3184
- const {
3185
- metadataVersion,
3186
- metadata,
3187
- tag
3188
- } = scale.decodeMetadata(metadataRpc);
3189
- if (!metadata) return {
3190
- isTestnet
3191
- };
3171
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3172
+ const metadata = scale.decAnyMetadata(metadataRpc);
3192
3173
  scale.compactMetadata(metadata, [{
3193
3174
  pallet: "Assets",
3194
3175
  items: ["Account", "Asset", "Metadata"]
3195
3176
  }]);
3196
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3197
- tag,
3198
- metadata
3199
- } : {
3200
- tag,
3201
- metadata
3202
- });
3177
+ const miniMetadata = scale.encodeMetadata(metadata);
3203
3178
  return {
3204
3179
  isTestnet,
3205
3180
  miniMetadata,
@@ -3215,10 +3190,7 @@ const SubAssetsModule = hydrate => {
3215
3190
  } = chainMeta;
3216
3191
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3217
3192
  if (metadataVersion < 14) return {};
3218
- const {
3219
- metadata
3220
- } = scale.decodeMetadata(miniMetadata);
3221
- if (metadata === undefined) return {};
3193
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata));
3222
3194
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3223
3195
  const assetCoder = scaleBuilder.buildStorage("Assets", "Asset");
3224
3196
  const metadataCoder = scaleBuilder.buildStorage("Assets", "Metadata");
@@ -3476,14 +3448,8 @@ const SubEquilibriumModule = hydrate => {
3476
3448
  isTestnet
3477
3449
  }; // default to disabled
3478
3450
 
3479
- const {
3480
- metadataVersion,
3481
- metadata,
3482
- tag
3483
- } = scale.decodeMetadata(metadataRpc);
3484
- if (!metadata) return {
3485
- isTestnet
3486
- };
3451
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3452
+ const metadata = scale.decAnyMetadata(metadataRpc);
3487
3453
  scale.compactMetadata(metadata, [{
3488
3454
  pallet: "EqAssets",
3489
3455
  items: ["Assets"]
@@ -3491,13 +3457,7 @@ const SubEquilibriumModule = hydrate => {
3491
3457
  pallet: "System",
3492
3458
  items: ["Account"]
3493
3459
  }]);
3494
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3495
- tag,
3496
- metadata
3497
- } : {
3498
- tag,
3499
- metadata
3500
- });
3460
+ const miniMetadata = scale.encodeMetadata(metadata);
3501
3461
  return {
3502
3462
  isTestnet,
3503
3463
  miniMetadata,
@@ -3514,11 +3474,8 @@ const SubEquilibriumModule = hydrate => {
3514
3474
  } = chainMeta;
3515
3475
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3516
3476
  if (metadataVersion < 14) return {};
3517
- const {
3518
- metadata
3519
- } = scale.decodeMetadata(miniMetadata);
3520
- if (metadata === undefined) return {};
3521
3477
  try {
3478
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata));
3522
3479
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3523
3480
  const assetsCoder = scaleBuilder.buildStorage("EqAssets", "Assets");
3524
3481
  const stateKey = assetsCoder.keys.enc();
@@ -3758,25 +3715,13 @@ const SubForeignAssetsModule = hydrate => {
3758
3715
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3759
3716
  isTestnet
3760
3717
  };
3761
- const {
3762
- metadataVersion,
3763
- metadata,
3764
- tag
3765
- } = scale.decodeMetadata(metadataRpc);
3766
- if (!metadata) return {
3767
- isTestnet
3768
- };
3718
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3719
+ const metadata = scale.decAnyMetadata(metadataRpc);
3769
3720
  scale.compactMetadata(metadata, [{
3770
3721
  pallet: "ForeignAssets",
3771
3722
  items: ["Account", "Asset", "Metadata"]
3772
3723
  }]);
3773
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3774
- tag,
3775
- metadata
3776
- } : {
3777
- tag,
3778
- metadata
3779
- });
3724
+ const miniMetadata = scale.encodeMetadata(metadata);
3780
3725
  return {
3781
3726
  isTestnet,
3782
3727
  miniMetadata,
@@ -3792,11 +3737,9 @@ const SubForeignAssetsModule = hydrate => {
3792
3737
  } = chainMeta;
3793
3738
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3794
3739
  if (metadataVersion < 14) return {};
3795
- const {
3796
- metadata
3797
- } = scale.decodeMetadata(miniMetadata);
3798
- if (metadata === undefined) return {};
3799
- const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3740
+ const metadata = scale.decAnyMetadata(miniMetadata);
3741
+ const unifiedMetadata = scale.unifyMetadata(metadata);
3742
+ const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(unifiedMetadata));
3800
3743
  const assetCoder = scaleBuilder.buildStorage("ForeignAssets", "Asset");
3801
3744
  const metadataCoder = scaleBuilder.buildStorage("ForeignAssets", "Metadata");
3802
3745
  const tokens = {};
@@ -3898,17 +3841,14 @@ const SubForeignAssetsModule = hydrate => {
3898
3841
  },
3899
3842
  amount: BigInt(amount)
3900
3843
  };
3901
- const {
3902
- metadata
3903
- } = scale.decodeMetadata(metadataRpc);
3904
- if (metadata === undefined) throw new Error("Unable to decode metadata");
3844
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(metadataRpc));
3905
3845
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3906
3846
  try {
3907
3847
  const {
3908
3848
  location,
3909
3849
  codec
3910
3850
  } = scaleBuilder.buildCall(pallet, method);
3911
- const callData = polkadotApi.Binary.fromBytes(utils.mergeUint8(new Uint8Array(location), codec.enc(args)));
3851
+ const callData = polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)]));
3912
3852
  return {
3913
3853
  type: "substrate",
3914
3854
  callData: utils.toHex(callData.asBytes())
@@ -4311,7 +4251,7 @@ const nompoolAccountId = (palletId, poolId, index) => {
4311
4251
  const length = encModPrefix.length + encPalletId.length + encIndex.length + encPoolId.length;
4312
4252
  const remainingBytes = 32 - length;
4313
4253
  const encEmptyH256 = new Uint8Array(remainingBytes);
4314
- const bytes = utils.mergeUint8(encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256);
4254
+ const bytes = utils.mergeUint8([encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256]);
4315
4255
  return polkadotApi.AccountId().dec(bytes);
4316
4256
  };
4317
4257
  /** The stash account for the nomination pool */
@@ -5474,25 +5414,17 @@ const SubNativeModule = hydrate => {
5474
5414
  //
5475
5415
  // process metadata into SCALE encoders/decoders
5476
5416
  //
5477
-
5478
- const {
5479
- metadataVersion,
5480
- metadata,
5481
- tag
5482
- } = scale.decodeMetadata(metadataRpc);
5483
- if (!metadata) return {
5484
- isTestnet,
5485
- symbol,
5486
- decimals
5487
- };
5417
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
5418
+ const metadata = scale.decAnyMetadata(metadataRpc);
5419
+ const unifiedMetadata = scale.unifyMetadata(metadata);
5488
5420
 
5489
5421
  //
5490
5422
  // get runtime constants
5491
5423
  //
5492
5424
 
5493
- const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
5425
+ const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(unifiedMetadata));
5494
5426
  const getConstantValue = (palletName, constantName) => {
5495
- const encodedValue = metadata.pallets.find(({
5427
+ const encodedValue = unifiedMetadata.pallets.find(({
5496
5428
  name
5497
5429
  }) => name === palletName)?.constants.find(({
5498
5430
  name
@@ -5541,14 +5473,8 @@ const SubNativeModule = hydrate => {
5541
5473
  runtimeApi: "SubnetInfoRuntimeApi",
5542
5474
  methods: ["get_dynamic_info"]
5543
5475
  }]);
5544
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
5545
- tag,
5546
- metadata
5547
- } : {
5548
- tag,
5549
- metadata
5550
- });
5551
- const hasFreezesItem = Boolean(metadata.pallets.find(({
5476
+ const miniMetadata = scale.encodeMetadata(metadata);
5477
+ const hasFreezesItem = Boolean(unifiedMetadata.pallets.find(({
5552
5478
  name
5553
5479
  }) => name === "Balances")?.storage?.items.find(({
5554
5480
  name
@@ -7257,26 +7183,14 @@ const SubTokensModule = hydrate => {
7257
7183
  if ((moduleConfig?.tokens ?? []).length < 1) return {
7258
7184
  isTestnet
7259
7185
  };
7260
- const {
7261
- metadataVersion,
7262
- metadata,
7263
- tag
7264
- } = scale.decodeMetadata(metadataRpc);
7265
- if (!metadata) return {
7266
- isTestnet
7267
- };
7186
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
7187
+ const metadata = scale.decAnyMetadata(metadataRpc);
7268
7188
  const palletId = moduleConfig?.palletId ?? defaultPalletId;
7269
7189
  scale.compactMetadata(metadata, [{
7270
7190
  pallet: palletId,
7271
7191
  items: ["Accounts"]
7272
7192
  }]);
7273
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
7274
- tag,
7275
- metadata
7276
- } : {
7277
- tag,
7278
- metadata
7279
- });
7193
+ const miniMetadata = scale.encodeMetadata(metadata);
7280
7194
  return palletId === defaultPalletId ? {
7281
7195
  isTestnet,
7282
7196
  miniMetadata,
@@ -7372,10 +7286,7 @@ const SubTokensModule = hydrate => {
7372
7286
  return token.onChainId;
7373
7287
  }
7374
7288
  })();
7375
- const {
7376
- metadata
7377
- } = scale.decodeMetadata(metadataRpc);
7378
- if (metadata === undefined) throw new Error("Unable to decode metadata");
7289
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(metadataRpc));
7379
7290
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
7380
7291
  const tryBuildCallData = (pallet, method, args) => {
7381
7292
  try {
@@ -7383,7 +7294,7 @@ const SubTokensModule = hydrate => {
7383
7294
  location,
7384
7295
  codec
7385
7296
  } = scaleBuilder.buildCall(pallet, method);
7386
- return [polkadotApi.Binary.fromBytes(utils.mergeUint8(new Uint8Array(location), codec.enc(args))), undefined];
7297
+ return [polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)])), undefined];
7387
7298
  } catch (cause) {
7388
7299
  return [undefined, new Error("Failed to build call", {
7389
7300
  cause
@@ -7600,8 +7511,12 @@ exports.EvmTokenFetcher = EvmTokenFetcher;
7600
7511
  exports.EvmUniswapV2Module = EvmUniswapV2Module;
7601
7512
  exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
7602
7513
  exports.MiniMetadataUpdater = MiniMetadataUpdater;
7514
+ exports.ONE_ALPHA_TOKEN = ONE_ALPHA_TOKEN;
7603
7515
  exports.PlanckSumBalancesFormatter = PlanckSumBalancesFormatter;
7604
7516
  exports.RpcStateQueryHelper = RpcStateQueryHelper;
7517
+ exports.SCALE_FACTOR = SCALE_FACTOR;
7518
+ exports.SUBTENSOR_MIN_STAKE_AMOUNT_PLANK = SUBTENSOR_MIN_STAKE_AMOUNT_PLANK;
7519
+ exports.SUBTENSOR_ROOT_NETUID = SUBTENSOR_ROOT_NETUID;
7605
7520
  exports.SubAssetsModule = SubAssetsModule;
7606
7521
  exports.SubEquilibriumModule = SubEquilibriumModule;
7607
7522
  exports.SubForeignAssetsModule = SubForeignAssetsModule;
@@ -7610,8 +7525,12 @@ exports.SubPsp22Module = SubPsp22Module;
7610
7525
  exports.SubTokensModule = SubTokensModule;
7611
7526
  exports.SumBalancesFormatter = SumBalancesFormatter;
7612
7527
  exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
7528
+ exports.abiMulticall = abiMulticall;
7613
7529
  exports.balances = balances;
7614
7530
  exports.buildStorageCoders = buildStorageCoders;
7531
+ exports.calculateAlphaPrice = calculateAlphaPrice;
7532
+ exports.calculateTaoAmountFromAlpha = calculateTaoAmountFromAlpha;
7533
+ exports.calculateTaoFromDynamicInfo = calculateTaoFromDynamicInfo;
7615
7534
  exports.compress = compress;
7616
7535
  exports.configureStore = configureStore;
7617
7536
  exports.db = db;
@@ -2,11 +2,10 @@
2
2
 
3
3
  var PromisePool = require('@supercharge/promise-pool');
4
4
  var chaindataProvider = require('@talismn/chaindata-provider');
5
- var scale = require('@talismn/scale');
5
+ var sapi = require('@talismn/sapi');
6
6
  var dexie = require('dexie');
7
7
  var isEqual = require('lodash/isEqual');
8
8
  var rxjs = require('rxjs');
9
- var scaleTs = require('scale-ts');
10
9
  var anylogger = require('anylogger');
11
10
  var tokenRates = require('@talismn/token-rates');
12
11
  var util = require('@talismn/util');
@@ -16,13 +15,14 @@ var utilCrypto = require('@polkadot/util-crypto');
16
15
  var pako = require('pako');
17
16
  var viem = require('viem');
18
17
  var txwrapperCore = require('@substrate/txwrapper-core');
18
+ var scale = require('@talismn/scale');
19
19
  var camelCase = require('lodash/camelCase');
20
20
  var types = require('@polkadot/types');
21
21
  var groupBy = require('lodash/groupBy');
22
22
  var utils = require('@polkadot-api/utils');
23
23
  var polkadotApi = require('polkadot-api');
24
24
  var chainConnector = require('@talismn/chain-connector');
25
- var sapi = require('@talismn/sapi');
25
+ var scaleTs = require('scale-ts');
26
26
  var upperFirst = require('lodash/upperFirst');
27
27
  var apiContract = require('@polkadot/api-contract');
28
28
  var lzString = require('lz-string');
@@ -1185,25 +1185,16 @@ class MiniMetadataUpdater {
1185
1185
  if (specName === null) return;
1186
1186
  if (specVersion === null) return;
1187
1187
  const fetchMetadata = async () => {
1188
- const errors = {
1189
- v15: null,
1190
- v14: null
1191
- };
1192
- try {
1193
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_call", ["Metadata_metadata_at_version", scale.toHex(scaleTs.u32.enc(15))]);
1194
- const result = response ? scaleTs.Option(scaleTs.Bytes()).dec(response) : null;
1195
- if (result) return result;
1196
- } catch (v15Cause) {
1197
- errors.v15 = v15Cause;
1198
- }
1199
1188
  try {
1200
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_getMetadata", []);
1201
- if (response) return response;
1202
- } catch (v14Cause) {
1203
- errors.v14 = v14Cause;
1189
+ return await sapi.fetchBestMetadata((method, params, isCacheable) => {
1190
+ if (!this.#chainConnectors.substrate) throw new Error("Substrate connector is not available");
1191
+ return this.#chainConnectors.substrate.send(chainId, method, params, isCacheable);
1192
+ }, true // allow v14 fallback
1193
+ );
1194
+ } catch (err) {
1195
+ log.warn(`Failed to fetch metadata for chain ${chainId}`);
1196
+ return undefined;
1204
1197
  }
1205
- log.warn(`Failed to fetch both metadata v15 and v14 for chain ${chainId}`, errors.v15, errors.v14);
1206
- return null;
1207
1198
  };
1208
1199
  const [metadataRpc, systemProperties] = await Promise.all([fetchMetadata(), this.#chainConnectors.substrate?.send(chainId, "system_properties", [])]);
1209
1200
  for (const mod of this.#balanceModules.filter(m => m.type.startsWith("substrate-"))) {
@@ -2948,11 +2939,7 @@ const buildStorageCoders = ({
2948
2939
  const [, miniMetadata] = findChainMeta(miniMetadatas, moduleType, chain);
2949
2940
  if (!miniMetadata) return [];
2950
2941
  if (!miniMetadata.data) return [];
2951
- const {
2952
- metadata,
2953
- tag
2954
- } = scale.decodeMetadata(miniMetadata.data);
2955
- if (!metadata || !tag) return [];
2942
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata.data));
2956
2943
  try {
2957
2944
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
2958
2945
  const builtCoders = Object.fromEntries(Object.entries(coders).flatMap(([key, moduleMethodOrFn]) => {
@@ -3181,25 +3168,13 @@ const SubAssetsModule = hydrate => {
3181
3168
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3182
3169
  isTestnet
3183
3170
  };
3184
- const {
3185
- metadataVersion,
3186
- metadata,
3187
- tag
3188
- } = scale.decodeMetadata(metadataRpc);
3189
- if (!metadata) return {
3190
- isTestnet
3191
- };
3171
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3172
+ const metadata = scale.decAnyMetadata(metadataRpc);
3192
3173
  scale.compactMetadata(metadata, [{
3193
3174
  pallet: "Assets",
3194
3175
  items: ["Account", "Asset", "Metadata"]
3195
3176
  }]);
3196
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3197
- tag,
3198
- metadata
3199
- } : {
3200
- tag,
3201
- metadata
3202
- });
3177
+ const miniMetadata = scale.encodeMetadata(metadata);
3203
3178
  return {
3204
3179
  isTestnet,
3205
3180
  miniMetadata,
@@ -3215,10 +3190,7 @@ const SubAssetsModule = hydrate => {
3215
3190
  } = chainMeta;
3216
3191
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3217
3192
  if (metadataVersion < 14) return {};
3218
- const {
3219
- metadata
3220
- } = scale.decodeMetadata(miniMetadata);
3221
- if (metadata === undefined) return {};
3193
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata));
3222
3194
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3223
3195
  const assetCoder = scaleBuilder.buildStorage("Assets", "Asset");
3224
3196
  const metadataCoder = scaleBuilder.buildStorage("Assets", "Metadata");
@@ -3476,14 +3448,8 @@ const SubEquilibriumModule = hydrate => {
3476
3448
  isTestnet
3477
3449
  }; // default to disabled
3478
3450
 
3479
- const {
3480
- metadataVersion,
3481
- metadata,
3482
- tag
3483
- } = scale.decodeMetadata(metadataRpc);
3484
- if (!metadata) return {
3485
- isTestnet
3486
- };
3451
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3452
+ const metadata = scale.decAnyMetadata(metadataRpc);
3487
3453
  scale.compactMetadata(metadata, [{
3488
3454
  pallet: "EqAssets",
3489
3455
  items: ["Assets"]
@@ -3491,13 +3457,7 @@ const SubEquilibriumModule = hydrate => {
3491
3457
  pallet: "System",
3492
3458
  items: ["Account"]
3493
3459
  }]);
3494
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3495
- tag,
3496
- metadata
3497
- } : {
3498
- tag,
3499
- metadata
3500
- });
3460
+ const miniMetadata = scale.encodeMetadata(metadata);
3501
3461
  return {
3502
3462
  isTestnet,
3503
3463
  miniMetadata,
@@ -3514,11 +3474,8 @@ const SubEquilibriumModule = hydrate => {
3514
3474
  } = chainMeta;
3515
3475
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3516
3476
  if (metadataVersion < 14) return {};
3517
- const {
3518
- metadata
3519
- } = scale.decodeMetadata(miniMetadata);
3520
- if (metadata === undefined) return {};
3521
3477
  try {
3478
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(miniMetadata));
3522
3479
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3523
3480
  const assetsCoder = scaleBuilder.buildStorage("EqAssets", "Assets");
3524
3481
  const stateKey = assetsCoder.keys.enc();
@@ -3758,25 +3715,13 @@ const SubForeignAssetsModule = hydrate => {
3758
3715
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3759
3716
  isTestnet
3760
3717
  };
3761
- const {
3762
- metadataVersion,
3763
- metadata,
3764
- tag
3765
- } = scale.decodeMetadata(metadataRpc);
3766
- if (!metadata) return {
3767
- isTestnet
3768
- };
3718
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
3719
+ const metadata = scale.decAnyMetadata(metadataRpc);
3769
3720
  scale.compactMetadata(metadata, [{
3770
3721
  pallet: "ForeignAssets",
3771
3722
  items: ["Account", "Asset", "Metadata"]
3772
3723
  }]);
3773
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
3774
- tag,
3775
- metadata
3776
- } : {
3777
- tag,
3778
- metadata
3779
- });
3724
+ const miniMetadata = scale.encodeMetadata(metadata);
3780
3725
  return {
3781
3726
  isTestnet,
3782
3727
  miniMetadata,
@@ -3792,11 +3737,9 @@ const SubForeignAssetsModule = hydrate => {
3792
3737
  } = chainMeta;
3793
3738
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3794
3739
  if (metadataVersion < 14) return {};
3795
- const {
3796
- metadata
3797
- } = scale.decodeMetadata(miniMetadata);
3798
- if (metadata === undefined) return {};
3799
- const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3740
+ const metadata = scale.decAnyMetadata(miniMetadata);
3741
+ const unifiedMetadata = scale.unifyMetadata(metadata);
3742
+ const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(unifiedMetadata));
3800
3743
  const assetCoder = scaleBuilder.buildStorage("ForeignAssets", "Asset");
3801
3744
  const metadataCoder = scaleBuilder.buildStorage("ForeignAssets", "Metadata");
3802
3745
  const tokens = {};
@@ -3898,17 +3841,14 @@ const SubForeignAssetsModule = hydrate => {
3898
3841
  },
3899
3842
  amount: BigInt(amount)
3900
3843
  };
3901
- const {
3902
- metadata
3903
- } = scale.decodeMetadata(metadataRpc);
3904
- if (metadata === undefined) throw new Error("Unable to decode metadata");
3844
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(metadataRpc));
3905
3845
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
3906
3846
  try {
3907
3847
  const {
3908
3848
  location,
3909
3849
  codec
3910
3850
  } = scaleBuilder.buildCall(pallet, method);
3911
- const callData = polkadotApi.Binary.fromBytes(utils.mergeUint8(new Uint8Array(location), codec.enc(args)));
3851
+ const callData = polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)]));
3912
3852
  return {
3913
3853
  type: "substrate",
3914
3854
  callData: utils.toHex(callData.asBytes())
@@ -4311,7 +4251,7 @@ const nompoolAccountId = (palletId, poolId, index) => {
4311
4251
  const length = encModPrefix.length + encPalletId.length + encIndex.length + encPoolId.length;
4312
4252
  const remainingBytes = 32 - length;
4313
4253
  const encEmptyH256 = new Uint8Array(remainingBytes);
4314
- const bytes = utils.mergeUint8(encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256);
4254
+ const bytes = utils.mergeUint8([encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256]);
4315
4255
  return polkadotApi.AccountId().dec(bytes);
4316
4256
  };
4317
4257
  /** The stash account for the nomination pool */
@@ -5474,25 +5414,17 @@ const SubNativeModule = hydrate => {
5474
5414
  //
5475
5415
  // process metadata into SCALE encoders/decoders
5476
5416
  //
5477
-
5478
- const {
5479
- metadataVersion,
5480
- metadata,
5481
- tag
5482
- } = scale.decodeMetadata(metadataRpc);
5483
- if (!metadata) return {
5484
- isTestnet,
5485
- symbol,
5486
- decimals
5487
- };
5417
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
5418
+ const metadata = scale.decAnyMetadata(metadataRpc);
5419
+ const unifiedMetadata = scale.unifyMetadata(metadata);
5488
5420
 
5489
5421
  //
5490
5422
  // get runtime constants
5491
5423
  //
5492
5424
 
5493
- const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
5425
+ const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(unifiedMetadata));
5494
5426
  const getConstantValue = (palletName, constantName) => {
5495
- const encodedValue = metadata.pallets.find(({
5427
+ const encodedValue = unifiedMetadata.pallets.find(({
5496
5428
  name
5497
5429
  }) => name === palletName)?.constants.find(({
5498
5430
  name
@@ -5541,14 +5473,8 @@ const SubNativeModule = hydrate => {
5541
5473
  runtimeApi: "SubnetInfoRuntimeApi",
5542
5474
  methods: ["get_dynamic_info"]
5543
5475
  }]);
5544
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
5545
- tag,
5546
- metadata
5547
- } : {
5548
- tag,
5549
- metadata
5550
- });
5551
- const hasFreezesItem = Boolean(metadata.pallets.find(({
5476
+ const miniMetadata = scale.encodeMetadata(metadata);
5477
+ const hasFreezesItem = Boolean(unifiedMetadata.pallets.find(({
5552
5478
  name
5553
5479
  }) => name === "Balances")?.storage?.items.find(({
5554
5480
  name
@@ -7257,26 +7183,14 @@ const SubTokensModule = hydrate => {
7257
7183
  if ((moduleConfig?.tokens ?? []).length < 1) return {
7258
7184
  isTestnet
7259
7185
  };
7260
- const {
7261
- metadataVersion,
7262
- metadata,
7263
- tag
7264
- } = scale.decodeMetadata(metadataRpc);
7265
- if (!metadata) return {
7266
- isTestnet
7267
- };
7186
+ const metadataVersion = scale.getMetadataVersion(metadataRpc);
7187
+ const metadata = scale.decAnyMetadata(metadataRpc);
7268
7188
  const palletId = moduleConfig?.palletId ?? defaultPalletId;
7269
7189
  scale.compactMetadata(metadata, [{
7270
7190
  pallet: palletId,
7271
7191
  items: ["Accounts"]
7272
7192
  }]);
7273
- const miniMetadata = scale.encodeMetadata(tag === "v15" ? {
7274
- tag,
7275
- metadata
7276
- } : {
7277
- tag,
7278
- metadata
7279
- });
7193
+ const miniMetadata = scale.encodeMetadata(metadata);
7280
7194
  return palletId === defaultPalletId ? {
7281
7195
  isTestnet,
7282
7196
  miniMetadata,
@@ -7372,10 +7286,7 @@ const SubTokensModule = hydrate => {
7372
7286
  return token.onChainId;
7373
7287
  }
7374
7288
  })();
7375
- const {
7376
- metadata
7377
- } = scale.decodeMetadata(metadataRpc);
7378
- if (metadata === undefined) throw new Error("Unable to decode metadata");
7289
+ const metadata = scale.unifyMetadata(scale.decAnyMetadata(metadataRpc));
7379
7290
  const scaleBuilder = scale.getDynamicBuilder(scale.getLookupFn(metadata));
7380
7291
  const tryBuildCallData = (pallet, method, args) => {
7381
7292
  try {
@@ -7383,7 +7294,7 @@ const SubTokensModule = hydrate => {
7383
7294
  location,
7384
7295
  codec
7385
7296
  } = scaleBuilder.buildCall(pallet, method);
7386
- return [polkadotApi.Binary.fromBytes(utils.mergeUint8(new Uint8Array(location), codec.enc(args))), undefined];
7297
+ return [polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), codec.enc(args)])), undefined];
7387
7298
  } catch (cause) {
7388
7299
  return [undefined, new Error("Failed to build call", {
7389
7300
  cause
@@ -7600,8 +7511,12 @@ exports.EvmTokenFetcher = EvmTokenFetcher;
7600
7511
  exports.EvmUniswapV2Module = EvmUniswapV2Module;
7601
7512
  exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
7602
7513
  exports.MiniMetadataUpdater = MiniMetadataUpdater;
7514
+ exports.ONE_ALPHA_TOKEN = ONE_ALPHA_TOKEN;
7603
7515
  exports.PlanckSumBalancesFormatter = PlanckSumBalancesFormatter;
7604
7516
  exports.RpcStateQueryHelper = RpcStateQueryHelper;
7517
+ exports.SCALE_FACTOR = SCALE_FACTOR;
7518
+ exports.SUBTENSOR_MIN_STAKE_AMOUNT_PLANK = SUBTENSOR_MIN_STAKE_AMOUNT_PLANK;
7519
+ exports.SUBTENSOR_ROOT_NETUID = SUBTENSOR_ROOT_NETUID;
7605
7520
  exports.SubAssetsModule = SubAssetsModule;
7606
7521
  exports.SubEquilibriumModule = SubEquilibriumModule;
7607
7522
  exports.SubForeignAssetsModule = SubForeignAssetsModule;
@@ -7610,8 +7525,12 @@ exports.SubPsp22Module = SubPsp22Module;
7610
7525
  exports.SubTokensModule = SubTokensModule;
7611
7526
  exports.SumBalancesFormatter = SumBalancesFormatter;
7612
7527
  exports.TalismanBalancesDatabase = TalismanBalancesDatabase;
7528
+ exports.abiMulticall = abiMulticall;
7613
7529
  exports.balances = balances;
7614
7530
  exports.buildStorageCoders = buildStorageCoders;
7531
+ exports.calculateAlphaPrice = calculateAlphaPrice;
7532
+ exports.calculateTaoAmountFromAlpha = calculateTaoAmountFromAlpha;
7533
+ exports.calculateTaoFromDynamicInfo = calculateTaoFromDynamicInfo;
7615
7534
  exports.compress = compress;
7616
7535
  exports.configureStore = configureStore;
7617
7536
  exports.db = db;
@@ -1,10 +1,9 @@
1
1
  import PromisePool$1, { PromisePool } from '@supercharge/promise-pool';
2
2
  import { fetchMiniMetadatas, fetchInitMiniMetadatas, availableTokenLogoFilenames, githubTokenLogoUrl } from '@talismn/chaindata-provider';
3
- import { toHex, decodeMetadata, getDynamicBuilder, getLookupFn, compactMetadata, encodeMetadata, decodeScale, encodeStateKey, papiParse } from '@talismn/scale';
3
+ import { fetchBestMetadata, getScaleApi } from '@talismn/sapi';
4
4
  import { Dexie, liveQuery } from 'dexie';
5
5
  import isEqual from 'lodash/isEqual';
6
6
  import { from, Observable, scan, share, map, switchAll, combineLatest, mergeMap, toArray, interval, startWith, exhaustMap, pipe, filter, shareReplay, combineLatestWith, distinctUntilChanged, firstValueFrom, BehaviorSubject, debounceTime, takeUntil, switchMap, withLatestFrom, concatMap } from 'rxjs';
7
- import { u32, Option, Bytes, u128, Struct } from 'scale-ts';
8
7
  import anylogger from 'anylogger';
9
8
  import { newTokenRates } from '@talismn/token-rates';
10
9
  import { isBigInt, BigMath, planckToTokens, isTruthy, isArrayOf, isEthereumAddress, hasOwnProperty, decodeAnyAddress, isNotNil, blake2Concat, firstThenDebounce, Deferred } from '@talismn/util';
@@ -14,13 +13,14 @@ import { xxhashAsU8a, blake2AsU8a } from '@polkadot/util-crypto';
14
13
  import pako from 'pako';
15
14
  import { parseAbi, isHex, hexToBigInt } from 'viem';
16
15
  import { defineMethod } from '@substrate/txwrapper-core';
16
+ import { unifyMetadata, decAnyMetadata, getDynamicBuilder, getLookupFn, getMetadataVersion, compactMetadata, encodeMetadata, decodeScale, encodeStateKey, papiParse } from '@talismn/scale';
17
17
  import camelCase from 'lodash/camelCase';
18
18
  import { Metadata, TypeRegistry } from '@polkadot/types';
19
19
  import groupBy from 'lodash/groupBy';
20
- import { mergeUint8, toHex as toHex$1 } from '@polkadot-api/utils';
20
+ import { mergeUint8, toHex } from '@polkadot-api/utils';
21
21
  import { Binary, AccountId } from 'polkadot-api';
22
22
  import { ChainConnectionError } from '@talismn/chain-connector';
23
- import { getScaleApi } from '@talismn/sapi';
23
+ import { u32, u128, Struct } from 'scale-ts';
24
24
  import upperFirst from 'lodash/upperFirst';
25
25
  import { Abi } from '@polkadot/api-contract';
26
26
  import { compressToEncodedURIComponent } from 'lz-string';
@@ -1172,25 +1172,16 @@ class MiniMetadataUpdater {
1172
1172
  if (specName === null) return;
1173
1173
  if (specVersion === null) return;
1174
1174
  const fetchMetadata = async () => {
1175
- const errors = {
1176
- v15: null,
1177
- v14: null
1178
- };
1179
- try {
1180
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_call", ["Metadata_metadata_at_version", toHex(u32.enc(15))]);
1181
- const result = response ? Option(Bytes()).dec(response) : null;
1182
- if (result) return result;
1183
- } catch (v15Cause) {
1184
- errors.v15 = v15Cause;
1185
- }
1186
1175
  try {
1187
- const response = await this.#chainConnectors.substrate?.send(chainId, "state_getMetadata", []);
1188
- if (response) return response;
1189
- } catch (v14Cause) {
1190
- errors.v14 = v14Cause;
1176
+ return await fetchBestMetadata((method, params, isCacheable) => {
1177
+ if (!this.#chainConnectors.substrate) throw new Error("Substrate connector is not available");
1178
+ return this.#chainConnectors.substrate.send(chainId, method, params, isCacheable);
1179
+ }, true // allow v14 fallback
1180
+ );
1181
+ } catch (err) {
1182
+ log.warn(`Failed to fetch metadata for chain ${chainId}`);
1183
+ return undefined;
1191
1184
  }
1192
- log.warn(`Failed to fetch both metadata v15 and v14 for chain ${chainId}`, errors.v15, errors.v14);
1193
- return null;
1194
1185
  };
1195
1186
  const [metadataRpc, systemProperties] = await Promise.all([fetchMetadata(), this.#chainConnectors.substrate?.send(chainId, "system_properties", [])]);
1196
1187
  for (const mod of this.#balanceModules.filter(m => m.type.startsWith("substrate-"))) {
@@ -2935,11 +2926,7 @@ const buildStorageCoders = ({
2935
2926
  const [, miniMetadata] = findChainMeta(miniMetadatas, moduleType, chain);
2936
2927
  if (!miniMetadata) return [];
2937
2928
  if (!miniMetadata.data) return [];
2938
- const {
2939
- metadata,
2940
- tag
2941
- } = decodeMetadata(miniMetadata.data);
2942
- if (!metadata || !tag) return [];
2929
+ const metadata = unifyMetadata(decAnyMetadata(miniMetadata.data));
2943
2930
  try {
2944
2931
  const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
2945
2932
  const builtCoders = Object.fromEntries(Object.entries(coders).flatMap(([key, moduleMethodOrFn]) => {
@@ -3168,25 +3155,13 @@ const SubAssetsModule = hydrate => {
3168
3155
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3169
3156
  isTestnet
3170
3157
  };
3171
- const {
3172
- metadataVersion,
3173
- metadata,
3174
- tag
3175
- } = decodeMetadata(metadataRpc);
3176
- if (!metadata) return {
3177
- isTestnet
3178
- };
3158
+ const metadataVersion = getMetadataVersion(metadataRpc);
3159
+ const metadata = decAnyMetadata(metadataRpc);
3179
3160
  compactMetadata(metadata, [{
3180
3161
  pallet: "Assets",
3181
3162
  items: ["Account", "Asset", "Metadata"]
3182
3163
  }]);
3183
- const miniMetadata = encodeMetadata(tag === "v15" ? {
3184
- tag,
3185
- metadata
3186
- } : {
3187
- tag,
3188
- metadata
3189
- });
3164
+ const miniMetadata = encodeMetadata(metadata);
3190
3165
  return {
3191
3166
  isTestnet,
3192
3167
  miniMetadata,
@@ -3202,10 +3177,7 @@ const SubAssetsModule = hydrate => {
3202
3177
  } = chainMeta;
3203
3178
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3204
3179
  if (metadataVersion < 14) return {};
3205
- const {
3206
- metadata
3207
- } = decodeMetadata(miniMetadata);
3208
- if (metadata === undefined) return {};
3180
+ const metadata = unifyMetadata(decAnyMetadata(miniMetadata));
3209
3181
  const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
3210
3182
  const assetCoder = scaleBuilder.buildStorage("Assets", "Asset");
3211
3183
  const metadataCoder = scaleBuilder.buildStorage("Assets", "Metadata");
@@ -3463,14 +3435,8 @@ const SubEquilibriumModule = hydrate => {
3463
3435
  isTestnet
3464
3436
  }; // default to disabled
3465
3437
 
3466
- const {
3467
- metadataVersion,
3468
- metadata,
3469
- tag
3470
- } = decodeMetadata(metadataRpc);
3471
- if (!metadata) return {
3472
- isTestnet
3473
- };
3438
+ const metadataVersion = getMetadataVersion(metadataRpc);
3439
+ const metadata = decAnyMetadata(metadataRpc);
3474
3440
  compactMetadata(metadata, [{
3475
3441
  pallet: "EqAssets",
3476
3442
  items: ["Assets"]
@@ -3478,13 +3444,7 @@ const SubEquilibriumModule = hydrate => {
3478
3444
  pallet: "System",
3479
3445
  items: ["Account"]
3480
3446
  }]);
3481
- const miniMetadata = encodeMetadata(tag === "v15" ? {
3482
- tag,
3483
- metadata
3484
- } : {
3485
- tag,
3486
- metadata
3487
- });
3447
+ const miniMetadata = encodeMetadata(metadata);
3488
3448
  return {
3489
3449
  isTestnet,
3490
3450
  miniMetadata,
@@ -3501,11 +3461,8 @@ const SubEquilibriumModule = hydrate => {
3501
3461
  } = chainMeta;
3502
3462
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3503
3463
  if (metadataVersion < 14) return {};
3504
- const {
3505
- metadata
3506
- } = decodeMetadata(miniMetadata);
3507
- if (metadata === undefined) return {};
3508
3464
  try {
3465
+ const metadata = unifyMetadata(decAnyMetadata(miniMetadata));
3509
3466
  const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
3510
3467
  const assetsCoder = scaleBuilder.buildStorage("EqAssets", "Assets");
3511
3468
  const stateKey = assetsCoder.keys.enc();
@@ -3745,25 +3702,13 @@ const SubForeignAssetsModule = hydrate => {
3745
3702
  if ((moduleConfig?.tokens ?? []).length < 1) return {
3746
3703
  isTestnet
3747
3704
  };
3748
- const {
3749
- metadataVersion,
3750
- metadata,
3751
- tag
3752
- } = decodeMetadata(metadataRpc);
3753
- if (!metadata) return {
3754
- isTestnet
3755
- };
3705
+ const metadataVersion = getMetadataVersion(metadataRpc);
3706
+ const metadata = decAnyMetadata(metadataRpc);
3756
3707
  compactMetadata(metadata, [{
3757
3708
  pallet: "ForeignAssets",
3758
3709
  items: ["Account", "Asset", "Metadata"]
3759
3710
  }]);
3760
- const miniMetadata = encodeMetadata(tag === "v15" ? {
3761
- tag,
3762
- metadata
3763
- } : {
3764
- tag,
3765
- metadata
3766
- });
3711
+ const miniMetadata = encodeMetadata(metadata);
3767
3712
  return {
3768
3713
  isTestnet,
3769
3714
  miniMetadata,
@@ -3779,11 +3724,9 @@ const SubForeignAssetsModule = hydrate => {
3779
3724
  } = chainMeta;
3780
3725
  if (miniMetadata === undefined || metadataVersion === undefined) return {};
3781
3726
  if (metadataVersion < 14) return {};
3782
- const {
3783
- metadata
3784
- } = decodeMetadata(miniMetadata);
3785
- if (metadata === undefined) return {};
3786
- const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
3727
+ const metadata = decAnyMetadata(miniMetadata);
3728
+ const unifiedMetadata = unifyMetadata(metadata);
3729
+ const scaleBuilder = getDynamicBuilder(getLookupFn(unifiedMetadata));
3787
3730
  const assetCoder = scaleBuilder.buildStorage("ForeignAssets", "Asset");
3788
3731
  const metadataCoder = scaleBuilder.buildStorage("ForeignAssets", "Metadata");
3789
3732
  const tokens = {};
@@ -3885,20 +3828,17 @@ const SubForeignAssetsModule = hydrate => {
3885
3828
  },
3886
3829
  amount: BigInt(amount)
3887
3830
  };
3888
- const {
3889
- metadata
3890
- } = decodeMetadata(metadataRpc);
3891
- if (metadata === undefined) throw new Error("Unable to decode metadata");
3831
+ const metadata = unifyMetadata(decAnyMetadata(metadataRpc));
3892
3832
  const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
3893
3833
  try {
3894
3834
  const {
3895
3835
  location,
3896
3836
  codec
3897
3837
  } = scaleBuilder.buildCall(pallet, method);
3898
- const callData = Binary.fromBytes(mergeUint8(new Uint8Array(location), codec.enc(args)));
3838
+ const callData = Binary.fromBytes(mergeUint8([new Uint8Array(location), codec.enc(args)]));
3899
3839
  return {
3900
3840
  type: "substrate",
3901
- callData: toHex$1(callData.asBytes())
3841
+ callData: toHex(callData.asBytes())
3902
3842
  };
3903
3843
  } catch (cause) {
3904
3844
  throw new Error(`Failed to build ${moduleType$3} transfer tx`, {
@@ -4298,7 +4238,7 @@ const nompoolAccountId = (palletId, poolId, index) => {
4298
4238
  const length = encModPrefix.length + encPalletId.length + encIndex.length + encPoolId.length;
4299
4239
  const remainingBytes = 32 - length;
4300
4240
  const encEmptyH256 = new Uint8Array(remainingBytes);
4301
- const bytes = mergeUint8(encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256);
4241
+ const bytes = mergeUint8([encModPrefix, encPalletId, encIndex, encPoolId, encEmptyH256]);
4302
4242
  return AccountId().dec(bytes);
4303
4243
  };
4304
4244
  /** The stash account for the nomination pool */
@@ -5461,25 +5401,17 @@ const SubNativeModule = hydrate => {
5461
5401
  //
5462
5402
  // process metadata into SCALE encoders/decoders
5463
5403
  //
5464
-
5465
- const {
5466
- metadataVersion,
5467
- metadata,
5468
- tag
5469
- } = decodeMetadata(metadataRpc);
5470
- if (!metadata) return {
5471
- isTestnet,
5472
- symbol,
5473
- decimals
5474
- };
5404
+ const metadataVersion = getMetadataVersion(metadataRpc);
5405
+ const metadata = decAnyMetadata(metadataRpc);
5406
+ const unifiedMetadata = unifyMetadata(metadata);
5475
5407
 
5476
5408
  //
5477
5409
  // get runtime constants
5478
5410
  //
5479
5411
 
5480
- const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
5412
+ const scaleBuilder = getDynamicBuilder(getLookupFn(unifiedMetadata));
5481
5413
  const getConstantValue = (palletName, constantName) => {
5482
- const encodedValue = metadata.pallets.find(({
5414
+ const encodedValue = unifiedMetadata.pallets.find(({
5483
5415
  name
5484
5416
  }) => name === palletName)?.constants.find(({
5485
5417
  name
@@ -5528,14 +5460,8 @@ const SubNativeModule = hydrate => {
5528
5460
  runtimeApi: "SubnetInfoRuntimeApi",
5529
5461
  methods: ["get_dynamic_info"]
5530
5462
  }]);
5531
- const miniMetadata = encodeMetadata(tag === "v15" ? {
5532
- tag,
5533
- metadata
5534
- } : {
5535
- tag,
5536
- metadata
5537
- });
5538
- const hasFreezesItem = Boolean(metadata.pallets.find(({
5463
+ const miniMetadata = encodeMetadata(metadata);
5464
+ const hasFreezesItem = Boolean(unifiedMetadata.pallets.find(({
5539
5465
  name
5540
5466
  }) => name === "Balances")?.storage?.items.find(({
5541
5467
  name
@@ -7244,26 +7170,14 @@ const SubTokensModule = hydrate => {
7244
7170
  if ((moduleConfig?.tokens ?? []).length < 1) return {
7245
7171
  isTestnet
7246
7172
  };
7247
- const {
7248
- metadataVersion,
7249
- metadata,
7250
- tag
7251
- } = decodeMetadata(metadataRpc);
7252
- if (!metadata) return {
7253
- isTestnet
7254
- };
7173
+ const metadataVersion = getMetadataVersion(metadataRpc);
7174
+ const metadata = decAnyMetadata(metadataRpc);
7255
7175
  const palletId = moduleConfig?.palletId ?? defaultPalletId;
7256
7176
  compactMetadata(metadata, [{
7257
7177
  pallet: palletId,
7258
7178
  items: ["Accounts"]
7259
7179
  }]);
7260
- const miniMetadata = encodeMetadata(tag === "v15" ? {
7261
- tag,
7262
- metadata
7263
- } : {
7264
- tag,
7265
- metadata
7266
- });
7180
+ const miniMetadata = encodeMetadata(metadata);
7267
7181
  return palletId === defaultPalletId ? {
7268
7182
  isTestnet,
7269
7183
  miniMetadata,
@@ -7359,10 +7273,7 @@ const SubTokensModule = hydrate => {
7359
7273
  return token.onChainId;
7360
7274
  }
7361
7275
  })();
7362
- const {
7363
- metadata
7364
- } = decodeMetadata(metadataRpc);
7365
- if (metadata === undefined) throw new Error("Unable to decode metadata");
7276
+ const metadata = unifyMetadata(decAnyMetadata(metadataRpc));
7366
7277
  const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
7367
7278
  const tryBuildCallData = (pallet, method, args) => {
7368
7279
  try {
@@ -7370,7 +7281,7 @@ const SubTokensModule = hydrate => {
7370
7281
  location,
7371
7282
  codec
7372
7283
  } = scaleBuilder.buildCall(pallet, method);
7373
- return [Binary.fromBytes(mergeUint8(new Uint8Array(location), codec.enc(args))), undefined];
7284
+ return [Binary.fromBytes(mergeUint8([new Uint8Array(location), codec.enc(args)])), undefined];
7374
7285
  } catch (cause) {
7375
7286
  return [undefined, new Error("Failed to build call", {
7376
7287
  cause
@@ -7448,7 +7359,7 @@ const SubTokensModule = hydrate => {
7448
7359
  }
7449
7360
  return {
7450
7361
  type: "substrate",
7451
- callData: toHex$1(callData.asBytes())
7362
+ callData: toHex(callData.asBytes())
7452
7363
  };
7453
7364
  }
7454
7365
  };
@@ -7575,4 +7486,4 @@ const updateEvmTokens = async (chaindataProvider, evmTokenFetcher) => {
7575
7486
  await evmTokenFetcher.update(evmNetworkIds);
7576
7487
  };
7577
7488
 
7578
- export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, MiniMetadataUpdater, PlanckSumBalancesFormatter, RpcStateQueryHelper, SubAssetsModule, SubEquilibriumModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule, SumBalancesFormatter, TalismanBalancesDatabase, balances, buildStorageCoders, compress, configureStore, db, decodeOutput, decompress, defaultBalanceModules, deriveMiniMetadataId, detectTransferMethod, erc20Abi, erc20BalancesAggregatorAbi, evmErc20TokenId, evmNativeTokenId, evmUniswapV2TokenId, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterBaseLocks, filterMirrorTokens, findChainMeta, getBalanceId, getLockTitle, getUniqueChainIds, getValueId, hydrateChaindataAndMiniMetadata, includeInTotalExtraAmount, makeContractCaller, subAssetTokenId, subEquilibriumTokenId, subForeignAssetTokenId, subNativeTokenId, subPsp22TokenId, subTokensTokenId, uniswapV2PairAbi, updateCustomMiniMetadata, updateEvmTokens };
7489
+ export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, MiniMetadataUpdater, ONE_ALPHA_TOKEN, PlanckSumBalancesFormatter, RpcStateQueryHelper, SCALE_FACTOR, SUBTENSOR_MIN_STAKE_AMOUNT_PLANK, SUBTENSOR_ROOT_NETUID, SubAssetsModule, SubEquilibriumModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule, SumBalancesFormatter, TalismanBalancesDatabase, abiMulticall, balances, buildStorageCoders, calculateAlphaPrice, calculateTaoAmountFromAlpha, calculateTaoFromDynamicInfo, compress, configureStore, db, decodeOutput, decompress, defaultBalanceModules, deriveMiniMetadataId, detectTransferMethod, erc20Abi, erc20BalancesAggregatorAbi, evmErc20TokenId, evmNativeTokenId, evmUniswapV2TokenId, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterBaseLocks, filterMirrorTokens, findChainMeta, getBalanceId, getLockTitle, getUniqueChainIds, getValueId, hydrateChaindataAndMiniMetadata, includeInTotalExtraAmount, makeContractCaller, subAssetTokenId, subEquilibriumTokenId, subForeignAssetTokenId, subNativeTokenId, subPsp22TokenId, subTokensTokenId, uniswapV2PairAbi, updateCustomMiniMetadata, updateEvmTokens };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -22,7 +22,7 @@
22
22
  "node": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@polkadot-api/utils": "0.1.2",
25
+ "@polkadot-api/utils": "0.2.0",
26
26
  "@supercharge/promise-pool": "^3.2.0",
27
27
  "anylogger": "^1.0.11",
28
28
  "bignumber.js": "^9.1.2",
@@ -30,23 +30,23 @@
30
30
  "lodash": "4.17.21",
31
31
  "lz-string": "1.5.0",
32
32
  "pako": "^2.1.0",
33
- "polkadot-api": "1.7.6",
33
+ "polkadot-api": "1.13.1",
34
34
  "rxjs": "^7.8.1",
35
35
  "scale-ts": "^1.6.1",
36
36
  "viem": "^2.27.3",
37
- "@talismn/chain-connector-evm": "0.10.8",
38
- "@talismn/chaindata-provider": "0.10.8",
39
- "@talismn/scale": "0.1.1",
40
- "@talismn/sapi": "0.0.3",
41
- "@talismn/util": "0.4.1",
42
- "@talismn/token-rates": "2.0.9",
43
- "@talismn/chain-connector": "0.10.8"
37
+ "@talismn/chain-connector": "0.11.0",
38
+ "@talismn/chain-connector-evm": "0.11.0",
39
+ "@talismn/sapi": "0.0.5",
40
+ "@talismn/chaindata-provider": "0.11.0",
41
+ "@talismn/scale": "0.1.2",
42
+ "@talismn/token-rates": "2.0.11",
43
+ "@talismn/util": "0.4.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@polkadot/api-contract": "15.8.1",
47
- "@polkadot/types": "15.8.1",
48
- "@polkadot/util": "13.4.3",
49
- "@polkadot/util-crypto": "13.4.3",
46
+ "@polkadot/api-contract": "16.1.2",
47
+ "@polkadot/types": "16.1.2",
48
+ "@polkadot/util": "13.5.1",
49
+ "@polkadot/util-crypto": "13.5.1",
50
50
  "@substrate/txwrapper-core": "7.5.3",
51
51
  "@types/jest": "^29.5.14",
52
52
  "@types/lodash": "^4.17.12",