@talismn/balances 1.4.0 → 2.0.0

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.mjs CHANGED
@@ -1,3 +1,8 @@
1
+ // src/configureBigNumber.ts
2
+ import BigNumber from "bignumber.js";
3
+ BigNumber.set({ STRICT: false });
4
+ var configureBigNumber_default = BigNumber;
5
+
1
6
  // src/BalancesProvider.ts
2
7
  import {
3
8
  isNetworkDot,
@@ -38,7 +43,7 @@ import anylogger from "anylogger";
38
43
  // package.json
39
44
  var package_default = {
40
45
  name: "@talismn/balances",
41
- version: "1.4.0",
46
+ version: "2.0.0",
42
47
  author: "Talisman",
43
48
  homepage: "https://talisman.xyz",
44
49
  license: "GPL-3.0-or-later",
@@ -66,9 +71,9 @@ var package_default = {
66
71
  },
67
72
  dependencies: {
68
73
  "@metaplex-foundation/mpl-token-metadata": "^3.4.0",
69
- "@metaplex-foundation/umi": "^1.2.0",
70
- "@polkadot-api/utils": "0.2.0",
71
- "@solana/spl-token": "^0.4.13",
74
+ "@metaplex-foundation/umi": "^1.5.1",
75
+ "@polkadot-api/utils": "0.4.0",
76
+ "@solana/spl-token": "^0.4.14",
72
77
  "@solana/web3.js": "^1.98.2",
73
78
  "@talismn/chain-connectors": "workspace:*",
74
79
  "@talismn/chaindata-provider": "workspace:*",
@@ -78,21 +83,22 @@ var package_default = {
78
83
  "@talismn/token-rates": "workspace:*",
79
84
  "@talismn/util": "workspace:*",
80
85
  anylogger: "^1.0.11",
81
- "bignumber.js": "^9.1.2",
82
- "lodash-es": "4.17.21",
86
+ "bignumber.js": "^11.1.3",
87
+ "lodash-es": "4.18.1",
83
88
  "p-queue": "8.1.0",
84
- "polkadot-api": "1.23.3",
85
- rxjs: "^7.8.1",
89
+ "polkadot-api": "2.1.6",
90
+ rxjs: "^7.8.2",
86
91
  "scale-ts": "^1.6.1",
87
- viem: "^2.27.3",
88
- zod: "^3.25.76"
92
+ viem: "2.52.2",
93
+ zod: "^4.4.3"
89
94
  },
90
95
  devDependencies: {
91
96
  "@polkadot/api-contract": "16.1.2",
92
97
  "@polkadot/types": "16.1.2",
93
98
  "@talismn/tsconfig": "workspace:*",
94
99
  "@types/lodash-es": "4.17.12",
95
- typescript: "^5.6.3"
100
+ "@types/node": "^24.5.1",
101
+ typescript: "^6.0.3"
96
102
  },
97
103
  peerDependencies: {
98
104
  "@polkadot/api-contract": "*",
@@ -1019,13 +1025,8 @@ import { assign, omit } from "lodash-es";
1019
1025
  import z from "zod/v4";
1020
1026
 
1021
1027
  // src/modules/evm-erc20/utils.ts
1022
- import {
1023
- ContractFunctionExecutionError,
1024
- erc20Abi as erc20Abi2,
1025
- erc20Abi_bytes32,
1026
- getContract,
1027
- hexToString
1028
- } from "viem";
1028
+ import { isErrorOfName } from "@talismn/util";
1029
+ import { erc20Abi as erc20Abi2, erc20Abi_bytes32, getContract, hexToString } from "viem";
1029
1030
  var getErc20ContractData = async (client, contractAddress) => {
1030
1031
  try {
1031
1032
  const contract = getTypedContract(client, erc20Abi2, contractAddress);
@@ -1035,7 +1036,7 @@ var getErc20ContractData = async (client, contractAddress) => {
1035
1036
  contract.read.name()
1036
1037
  ]);
1037
1038
  } catch (e) {
1038
- if (e instanceof ContractFunctionExecutionError) {
1039
+ if (isErrorOfName(e, "ContractFunctionExecutionError")) {
1039
1040
  const contract = getTypedContract(client, erc20Abi_bytes32, contractAddress);
1040
1041
  var [bytesSymbol, decimals, nameSymbol] = await Promise.all([
1041
1042
  contract.read.symbol(),
@@ -1252,21 +1253,30 @@ var fetchBalances2 = async ({
1252
1253
  }
1253
1254
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
1254
1255
  if (client.chain?.contracts?.multicall3 && balanceDefs.length > 1) {
1255
- const multicall3 = client.chain.contracts.multicall3;
1256
- return fetchWithMulticall(client, balanceDefs, multicall3.address);
1256
+ try {
1257
+ return await fetchWithMulticall(
1258
+ client,
1259
+ balanceDefs,
1260
+ client.chain.contracts.multicall3.address
1261
+ );
1262
+ } catch {
1263
+ }
1257
1264
  }
1258
- return fetchWithoutMulticall(client, balanceDefs);
1265
+ return fetchWithGetBalance(client, balanceDefs);
1259
1266
  };
1260
- var fetchWithoutMulticall = async (client, balanceDefs) => {
1267
+ var fetchWithGetBalance = async (client, balanceDefs) => {
1261
1268
  if (balanceDefs.length === 0) return { success: [], errors: [] };
1262
1269
  const results = await Promise.allSettled(
1263
1270
  balanceDefs.map(async ({ token, address }) => {
1264
1271
  try {
1265
- const result = await client.getBalance({ address });
1272
+ const result = await client.request({
1273
+ method: "eth_getBalance",
1274
+ params: [address, "latest"]
1275
+ });
1266
1276
  const balance = {
1267
1277
  address,
1268
1278
  tokenId: token.id,
1269
- value: result.toString(),
1279
+ value: BigInt(result).toString(),
1270
1280
  source: MODULE_TYPE2,
1271
1281
  networkId: parseTokenId2(token.id).networkId,
1272
1282
  status: "live"
@@ -1300,55 +1310,28 @@ var fetchWithoutMulticall = async (client, balanceDefs) => {
1300
1310
  };
1301
1311
  var fetchWithMulticall = async (client, balanceDefs, multicall3Address) => {
1302
1312
  if (balanceDefs.length === 0) return { success: [], errors: [] };
1303
- try {
1304
- const callResults = await client.multicall({
1305
- contracts: balanceDefs.map(({ address }) => ({
1306
- address: multicall3Address,
1307
- abi: abiMulticall,
1308
- functionName: "getEthBalance",
1309
- args: [address]
1310
- }))
1311
- });
1312
- return callResults.reduce(
1313
- (acc, result, index) => {
1314
- if (result.status === "success") {
1315
- acc.success.push({
1316
- address: balanceDefs[index].address,
1317
- tokenId: balanceDefs[index].token.id,
1318
- value: result.result.toString(),
1319
- source: MODULE_TYPE2,
1320
- networkId: parseTokenId2(balanceDefs[index].token.id).networkId,
1321
- status: "live"
1322
- });
1323
- }
1324
- if (result.status === "failure") {
1325
- acc.errors.push({
1326
- tokenId: balanceDefs[index].token.id,
1327
- address: balanceDefs[index].address,
1328
- error: new BalanceFetchError(
1329
- `Failed to get balance for token ${balanceDefs[index].token.id} and address ${balanceDefs[index].address} on chain ${client.chain?.id}`,
1330
- balanceDefs[index].token.id,
1331
- balanceDefs[index].address,
1332
- result.error
1333
- )
1334
- });
1335
- }
1336
- return acc;
1337
- },
1338
- { success: [], errors: [] }
1339
- );
1340
- } catch (err) {
1341
- const errors = balanceDefs.map((balanceDef) => ({
1342
- tokenId: balanceDef.token.id,
1343
- address: balanceDef.address,
1344
- error: new BalanceFetchNetworkError(
1345
- `Failed to get balances for evm-erc20 tokens on chain ${client.chain?.id}`,
1346
- String(client.chain?.id),
1347
- err
1348
- )
1349
- }));
1350
- return { success: [], errors };
1351
- }
1313
+ const results = await client.multicall({
1314
+ allowFailure: false,
1315
+ contracts: balanceDefs.map(({ address }) => ({
1316
+ address: multicall3Address,
1317
+ abi: abiMulticall,
1318
+ functionName: "getEthBalance",
1319
+ args: [address]
1320
+ }))
1321
+ });
1322
+ return {
1323
+ success: results.map(
1324
+ (value, index) => ({
1325
+ address: balanceDefs[index].address,
1326
+ tokenId: balanceDefs[index].token.id,
1327
+ value: String(value),
1328
+ source: MODULE_TYPE2,
1329
+ networkId: parseTokenId2(balanceDefs[index].token.id).networkId,
1330
+ status: "live"
1331
+ })
1332
+ ),
1333
+ errors: []
1334
+ };
1352
1335
  };
1353
1336
 
1354
1337
  // src/modules/evm-native/fetchTokens.ts
@@ -1469,7 +1452,6 @@ var PLATFORM3 = EvmUniswapV2TokenSchema.shape.platform.value;
1469
1452
  // src/modules/evm-uniswapv2/fetchBalances.ts
1470
1453
  import { parseTokenId as parseTokenId3 } from "@talismn/chaindata-provider";
1471
1454
  import { isEthereumAddress as isEthereumAddress5 } from "@talismn/crypto";
1472
- import BigNumber from "bignumber.js";
1473
1455
  import { keyBy, uniq } from "lodash-es";
1474
1456
  import { getContract as getContract2 } from "viem";
1475
1457
  var fetchBalances3 = async ({
@@ -1561,7 +1543,7 @@ var fetchPoolBalances = async (client, balanceDefs) => {
1561
1543
  label,
1562
1544
  amount
1563
1545
  });
1564
- const ratio = BigNumber(String(balance)).div(totalSupply === 0n ? "1" : String(totalSupply));
1546
+ const ratio = configureBigNumber_default(String(balance)).div(totalSupply === 0n ? "1" : String(totalSupply));
1565
1547
  acc.success.push({
1566
1548
  address,
1567
1549
  tokenId: token.id,
@@ -1593,13 +1575,8 @@ import { assign as assign3, omit as omit2 } from "lodash-es";
1593
1575
  import z4 from "zod/v4";
1594
1576
 
1595
1577
  // src/modules/evm-uniswapv2/utils.ts
1596
- import {
1597
- ContractFunctionExecutionError as ContractFunctionExecutionError2,
1598
- erc20Abi as erc20Abi4,
1599
- erc20Abi_bytes32 as erc20Abi_bytes322,
1600
- getContract as getContract3,
1601
- hexToString as hexToString2
1602
- } from "viem";
1578
+ import { isErrorOfName as isErrorOfName2 } from "@talismn/util";
1579
+ import { erc20Abi as erc20Abi4, erc20Abi_bytes32 as erc20Abi_bytes322, getContract as getContract3, hexToString as hexToString2 } from "viem";
1603
1580
  var getErc20ContractData2 = async (client, contractAddress) => {
1604
1581
  try {
1605
1582
  const contract = getTypedContract2(client, erc20Abi4, contractAddress);
@@ -1609,7 +1586,7 @@ var getErc20ContractData2 = async (client, contractAddress) => {
1609
1586
  contract.read.name()
1610
1587
  ]);
1611
1588
  } catch (e) {
1612
- if (e instanceof ContractFunctionExecutionError2) {
1589
+ if (isErrorOfName2(e, "ContractFunctionExecutionError")) {
1613
1590
  const contract = getTypedContract2(client, erc20Abi_bytes322, contractAddress);
1614
1591
  var [bytesSymbol, decimals, nameSymbol] = await Promise.all([
1615
1592
  contract.read.symbol(),
@@ -2051,9 +2028,9 @@ var buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
2051
2028
 
2052
2029
  // src/modules/shared/fetchRuntimeCallResult.ts
2053
2030
  import { parseMetadataRpc, toHex } from "@talismn/scale";
2054
- var fetchRuntimeCallResult = async (connector, networkId, metadataRpc, apiName, method, args) => {
2031
+ var fetchRuntimeCallResult = async (connector, networkId, metadataRpcOrBuilder, apiName, method, args) => {
2055
2032
  try {
2056
- const { builder } = parseMetadataRpc(metadataRpc);
2033
+ const builder = typeof metadataRpcOrBuilder === "string" ? parseMetadataRpc(metadataRpcOrBuilder).builder : metadataRpcOrBuilder;
2057
2034
  const call = builder.buildRuntimeCall(apiName, method);
2058
2035
  const hex = await connector.send(networkId, "state_call", [
2059
2036
  `${apiName}_${method}`,
@@ -2124,17 +2101,17 @@ var decodeRpcQueryPack = (queries, result) => {
2124
2101
  import { parseMetadataRpc as parseMetadataRpc2 } from "@talismn/scale";
2125
2102
  var hasStorageItem = (metadata, palletName, itemName) => {
2126
2103
  const pallet = metadata.pallets.find((p) => p.name === palletName);
2127
- if (!pallet || !pallet.storage) return false;
2104
+ if (!pallet?.storage) return false;
2128
2105
  return pallet.storage.items.some((item) => item.name === itemName);
2129
2106
  };
2130
2107
  var hasStorageItems = (metadata, palletName, itemNames) => {
2131
2108
  const pallet = metadata.pallets.find((p) => p.name === palletName);
2132
- if (!pallet || !pallet.storage) return false;
2109
+ if (!pallet?.storage) return false;
2133
2110
  return itemNames.every((itemName) => pallet.storage?.items.some((item) => item.name === itemName));
2134
2111
  };
2135
2112
  var hasRuntimeApi = (metadata, apiName, method) => {
2136
2113
  const api = metadata.apis.find((api2) => api2.name === apiName);
2137
- if (!api || !api.methods) return false;
2114
+ if (!api?.methods) return false;
2138
2115
  return api.methods.some((m) => m.name === method);
2139
2116
  };
2140
2117
  var getConstantValue = (metadataRpc, pallet, constant) => {
@@ -2300,7 +2277,7 @@ var fetchBalances5 = async ({
2300
2277
  cached = fetched;
2301
2278
  }
2302
2279
  }
2303
- if (!cached || !cached.isValid) return;
2280
+ if (!cached?.isValid) return;
2304
2281
  const token = {
2305
2282
  id: tokenId,
2306
2283
  type: MODULE_TYPE5,
@@ -2691,7 +2668,7 @@ var fetchBalances6 = async ({
2691
2668
  cached = fetched;
2692
2669
  }
2693
2670
  }
2694
- if (!cached || !cached.isValid) return;
2671
+ if (!cached?.isValid) return;
2695
2672
  const token = {
2696
2673
  id: tokenId,
2697
2674
  type: MODULE_TYPE6,
@@ -3122,6 +3099,7 @@ import {
3122
3099
  } from "@talismn/chaindata-provider";
3123
3100
  import { getStorageKeyPrefix, parseMetadataRpc as parseMetadataRpc3 } from "@talismn/scale";
3124
3101
  import { assign as assign7, keyBy as keyBy4, keys } from "lodash-es";
3102
+ import { Binary } from "polkadot-api";
3125
3103
  var fetchTokens7 = async ({
3126
3104
  networkId,
3127
3105
  tokens,
@@ -3163,8 +3141,8 @@ var fetchTokens7 = async ({
3163
3141
  assetId,
3164
3142
  decimals: metadata.decimals,
3165
3143
  isFrozen: metadata.is_frozen,
3166
- name: metadata.name?.asText(),
3167
- symbol: metadata.symbol?.asText()
3144
+ name: metadata.name ? Binary.toText(metadata.name) : void 0,
3145
+ symbol: metadata.symbol ? Binary.toText(metadata.symbol) : void 0
3168
3146
  };
3169
3147
  }),
3170
3148
  (a) => a.assetId
@@ -3202,7 +3180,7 @@ var fetchTokens7 = async ({
3202
3180
 
3203
3181
  // src/modules/substrate-assets/getMiniMetadata.ts
3204
3182
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION3 } from "@talismn/chaindata-provider";
3205
- import { compactMetadata as compactMetadata2, encodeMetadata as encodeMetadata2, parseMetadataRpc as parseMetadataRpc8 } from "@talismn/scale";
3183
+ import { compactMetadata as compactMetadata2, encodeMetadata as encodeMetadata2, parseMetadataRpc as parseMetadataRpc9 } from "@talismn/scale";
3206
3184
 
3207
3185
  // src/types/balances.ts
3208
3186
  import { evmErc20TokenId as evmErc20TokenId2 } from "@talismn/chaindata-provider";
@@ -3215,7 +3193,6 @@ import {
3215
3193
  isBigInt,
3216
3194
  planckToTokens
3217
3195
  } from "@talismn/util";
3218
- import BigNumber2 from "bignumber.js";
3219
3196
 
3220
3197
  // src/modules/substrate-dtao/alphaPrice.ts
3221
3198
  var TAO_DECIMALS = 9n;
@@ -3232,6 +3209,179 @@ var taoToAlpha = (tao, scaledAlphaPrice) => {
3232
3209
  if (!tao || !scaledAlphaPrice) return 0n;
3233
3210
  return tao * ALPHA_PRICE_SCALE / scaledAlphaPrice;
3234
3211
  };
3212
+ var taoToAlphaCeil = (tao, scaledAlphaPrice) => {
3213
+ if (!tao || !scaledAlphaPrice) return 0n;
3214
+ return (tao * ALPHA_PRICE_SCALE + scaledAlphaPrice - 1n) / scaledAlphaPrice;
3215
+ };
3216
+
3217
+ // src/modules/substrate-dtao/convictionLocks.ts
3218
+ import {
3219
+ decodeScale as decodeScale2,
3220
+ parseMetadataRpc as parseMetadataRpc4
3221
+ } from "@talismn/scale";
3222
+ var convictionLockKey = (address, netuid) => `${address}:${netuid}`;
3223
+ var getConvictionLockLabel = (lockType) => lockType === "perpetual" ? "Perpetual Conviction Lock" : "Decaying Conviction Lock";
3224
+ var findDTaoConvictionLock = (locks) => {
3225
+ for (const lock of locks ?? []) {
3226
+ const meta = lock.meta;
3227
+ if (meta?.convictionLock?.type !== "conviction-lock") continue;
3228
+ const lockType = meta.convictionLock.lockType;
3229
+ return {
3230
+ amount: lock.amount.planck,
3231
+ hotkey: meta.convictionLock.hotkey,
3232
+ lockType,
3233
+ label: getConvictionLockLabel(lockType)
3234
+ };
3235
+ }
3236
+ return null;
3237
+ };
3238
+ var toBigIntValue = (value) => {
3239
+ if (typeof value === "bigint") return value;
3240
+ if (value && typeof value === "object" && "bits" in value) {
3241
+ const bits = value.bits;
3242
+ if (typeof bits === "bigint") return bits;
3243
+ }
3244
+ return 0n;
3245
+ };
3246
+ var fetchConvictionLocks = async (connector, networkId, metadataRpc, addresses) => {
3247
+ if (!addresses.length) return [];
3248
+ const { unifiedMetadata, builder } = parseMetadataRpc4(metadataRpc);
3249
+ if (!hasRuntimeApi(unifiedMetadata, "StakeInfoRuntimeApi", "get_coldkey_lock") || !hasStorageItems(unifiedMetadata, "SubtensorModule", ["Lock", "DecayingLock"])) {
3250
+ return [];
3251
+ }
3252
+ try {
3253
+ const lockStorageCoder = builder.buildStorage("SubtensorModule", "Lock");
3254
+ const decayingLockStorageCoder = builder.buildStorage("SubtensorModule", "DecayingLock");
3255
+ const lockStorageKeys = await fetchConvictionLockStorageKeys(
3256
+ connector,
3257
+ networkId,
3258
+ addresses,
3259
+ lockStorageCoder
3260
+ );
3261
+ if (!lockStorageKeys.length) return [];
3262
+ const hotkeyByPair = new Map(
3263
+ lockStorageKeys.map(({ address, netuid, hotkey }) => [
3264
+ convictionLockKey(address, netuid),
3265
+ hotkey
3266
+ ])
3267
+ );
3268
+ const [lockModesByPair, lockStates] = await Promise.all([
3269
+ fetchConvictionLockModes(connector, networkId, lockStorageKeys, decayingLockStorageCoder),
3270
+ fetchColdkeyLockStates(connector, networkId, builder, lockStorageKeys)
3271
+ ]);
3272
+ return lockStates.flatMap(({ address, netuid, lockState }) => {
3273
+ const amount = lockState?.locked_mass ?? 0n;
3274
+ const convictionRaw = toBigIntValue(lockState?.conviction);
3275
+ if (amount <= 0n && convictionRaw <= 0n) return [];
3276
+ const hotkey = hotkeyByPair.get(convictionLockKey(address, netuid));
3277
+ if (!hotkey) return [];
3278
+ return [
3279
+ {
3280
+ address,
3281
+ netuid,
3282
+ lock: {
3283
+ amount,
3284
+ hotkey,
3285
+ lockType: lockModesByPair.get(convictionLockKey(address, netuid)) ?? "decaying",
3286
+ convictionRaw: convictionRaw.toString()
3287
+ }
3288
+ }
3289
+ ];
3290
+ });
3291
+ } catch (cause) {
3292
+ log_default.warn(`Failed to fetch Bittensor conviction locks on ${networkId}`, { cause });
3293
+ return [];
3294
+ }
3295
+ };
3296
+ var fetchConvictionLockStorageKeys = async (connector, networkId, addresses, storageCoder) => {
3297
+ const keysPerAddress = await Promise.all(
3298
+ addresses.map(async (address) => {
3299
+ let keyPrefix;
3300
+ try {
3301
+ keyPrefix = storageCoder.keys.enc(address);
3302
+ } catch (cause) {
3303
+ log_default.warn(
3304
+ `Failed to encode conviction Lock key prefix (address=${address}) on ${networkId}`,
3305
+ { cause }
3306
+ );
3307
+ return [];
3308
+ }
3309
+ try {
3310
+ const stateKeys = await connector.send(networkId, "state_getKeys", [
3311
+ keyPrefix
3312
+ ]);
3313
+ return stateKeys.flatMap((stateKey) => {
3314
+ try {
3315
+ const [, netuid, hotkey] = storageCoder.keys.dec(stateKey);
3316
+ return [{ address, netuid, hotkey }];
3317
+ } catch (cause) {
3318
+ log_default.warn(`Failed to decode conviction Lock key ${stateKey} on ${networkId}`, { cause });
3319
+ return [];
3320
+ }
3321
+ });
3322
+ } catch (cause) {
3323
+ log_default.warn(`Failed to fetch conviction Lock keys (address=${address}) on ${networkId}`, {
3324
+ cause
3325
+ });
3326
+ return [];
3327
+ }
3328
+ })
3329
+ );
3330
+ return keysPerAddress.flat();
3331
+ };
3332
+ var fetchConvictionLockModes = async (connector, networkId, pairs, storageCoder) => {
3333
+ const queries = pairs.map(
3334
+ ({ address, netuid }) => {
3335
+ let stateKey = null;
3336
+ try {
3337
+ stateKey = storageCoder.keys.enc(address, netuid);
3338
+ } catch (cause) {
3339
+ log_default.warn(
3340
+ `Failed to encode conviction DecayingLock key (netuid=${netuid}, address=${address}) on ${networkId}`,
3341
+ { cause }
3342
+ );
3343
+ }
3344
+ const key = convictionLockKey(address, netuid);
3345
+ return {
3346
+ stateKeys: [stateKey],
3347
+ decodeResult: (changes) => {
3348
+ const hexValue = changes[0];
3349
+ if (!hexValue) return [key, "decaying"];
3350
+ const decoded = decodeScale2(
3351
+ storageCoder,
3352
+ hexValue,
3353
+ `Failed to decode DecayingLock for (netuid=${netuid}, address=${address}) on ${networkId}`
3354
+ );
3355
+ return [key, decoded === false ? "perpetual" : "decaying"];
3356
+ }
3357
+ };
3358
+ }
3359
+ );
3360
+ return new Map(await fetchRpcQueryPack(connector, networkId, queries));
3361
+ };
3362
+ var fetchColdkeyLockStates = async (connector, networkId, builder, pairs) => {
3363
+ return Promise.all(
3364
+ pairs.map(async ({ address, netuid }) => {
3365
+ try {
3366
+ const lockState = await fetchRuntimeCallResult(
3367
+ connector,
3368
+ networkId,
3369
+ builder,
3370
+ "StakeInfoRuntimeApi",
3371
+ "get_coldkey_lock",
3372
+ [address, netuid]
3373
+ );
3374
+ return { address, netuid, lockState };
3375
+ } catch (cause) {
3376
+ log_default.warn(
3377
+ `Failed to fetch get_coldkey_lock for (netuid=${netuid}, address=${address}) on ${networkId}`,
3378
+ { cause }
3379
+ );
3380
+ return { address, netuid, lockState: null };
3381
+ }
3382
+ })
3383
+ );
3384
+ };
3235
3385
 
3236
3386
  // src/modules/substrate-dtao/getDtaoTokenRates.ts
3237
3387
  import { subNativeTokenId } from "@talismn/chaindata-provider";
@@ -3239,7 +3389,14 @@ import {
3239
3389
  newTokenRates
3240
3390
  } from "@talismn/token-rates";
3241
3391
  var ONE_ALPHA = 10n ** TAO_DECIMALS;
3242
- var getDTaoTokenRates = (token, tokenRates, scaledAlphaPrice) => {
3392
+ var getAlphaChange24h = (currency, taoChange24h, alphaPriceChange24h) => {
3393
+ if (typeof alphaPriceChange24h !== "number" || !Number.isFinite(alphaPriceChange24h))
3394
+ return void 0;
3395
+ if (currency === "tao") return alphaPriceChange24h;
3396
+ if (typeof taoChange24h !== "number" || !Number.isFinite(taoChange24h)) return void 0;
3397
+ return ((1 + alphaPriceChange24h / 100) * (1 + taoChange24h / 100) - 1) * 100;
3398
+ };
3399
+ var getDTaoTokenRates = (token, tokenRates, scaledAlphaPrice, alphaPriceChange24h) => {
3243
3400
  try {
3244
3401
  const taoTokenId = subNativeTokenId(token.networkId);
3245
3402
  const taoTokenRates = tokenRates[taoTokenId];
@@ -3255,8 +3412,7 @@ var getDTaoTokenRates = (token, tokenRates, scaledAlphaPrice) => {
3255
3412
  alphaRates[currency] = {
3256
3413
  price: taoRate.price * priceRatio,
3257
3414
  marketCap: taoRate.marketCap ? taoRate.marketCap * priceRatio : void 0,
3258
- change24h: void 0
3259
- // cannot be determined from TAO rates alone
3415
+ change24h: getAlphaChange24h(currency, taoRate.change24h, alphaPriceChange24h)
3260
3416
  };
3261
3417
  }
3262
3418
  }
@@ -3278,7 +3434,7 @@ import {
3278
3434
  subDTaoTokenId as subDTaoTokenId2,
3279
3435
  TokenSchema
3280
3436
  } from "@talismn/chaindata-provider";
3281
- import { decodeScale as decodeScale2, parseMetadataRpc as parseMetadataRpc4 } from "@talismn/scale";
3437
+ import { decodeScale as decodeScale3, parseMetadataRpc as parseMetadataRpc5 } from "@talismn/scale";
3282
3438
  import { isNotNil as isNotNil5 } from "@talismn/util";
3283
3439
  import { keyBy as keyBy5, uniq as uniq4 } from "lodash-es";
3284
3440
 
@@ -3384,6 +3540,7 @@ var fetchBalances8 = async ({
3384
3540
  []
3385
3541
  )
3386
3542
  ]);
3543
+ const dynamicInfoByNetuid = keyBy5(dynamicInfos.filter(isNotNil5), (info) => info.netuid);
3387
3544
  const rootHotkeys = uniq4(
3388
3545
  stakeInfos.flatMap(
3389
3546
  ([, stakes]) => stakes.filter((stake) => stake.netuid === ROOT_NETUID).map((stake) => stake.hotkey)
@@ -3403,13 +3560,10 @@ var fetchBalances8 = async ({
3403
3560
  }
3404
3561
  }
3405
3562
  }
3406
- const rootClaimedAmounts = addressHotkeyNetuidPairs.length && miniMetadata.data ? await fetchRootClaimedAmounts(
3407
- connector,
3408
- networkId,
3409
- miniMetadata.data,
3410
- addressHotkeyNetuidPairs
3411
- ) : /* @__PURE__ */ new Map();
3412
- const dynamicInfoByNetuid = keyBy5(dynamicInfos.filter(isNotNil5), (info) => info.netuid);
3563
+ const [rootClaimedAmounts, convictionLocks] = await Promise.all([
3564
+ addressHotkeyNetuidPairs.length && miniMetadata.data ? fetchRootClaimedAmounts(connector, networkId, miniMetadata.data, addressHotkeyNetuidPairs) : Promise.resolve(/* @__PURE__ */ new Map()),
3565
+ miniMetadata.data ? fetchConvictionLocks(connector, networkId, miniMetadata.data, addresses) : Promise.resolve([])
3566
+ ]);
3413
3567
  const upsertBalance = (acc, address, tokenId, balance) => {
3414
3568
  const key = `${address}:${tokenId}`;
3415
3569
  const recordedBalance = acc[key];
@@ -3420,6 +3574,9 @@ var fetchBalances8 = async ({
3420
3574
  // If the new balance has pendingRootClaim, use it (it's calculated from current state)
3421
3575
  ...balance.pendingRootClaim !== void 0 && {
3422
3576
  pendingRootClaim: balance.pendingRootClaim
3577
+ },
3578
+ ...balance.convictionLock !== void 0 && {
3579
+ convictionLock: balance.convictionLock
3423
3580
  }
3424
3581
  };
3425
3582
  } else {
@@ -3462,6 +3619,21 @@ var fetchBalances8 = async ({
3462
3619
  },
3463
3620
  {}
3464
3621
  );
3622
+ for (const { address, netuid, lock } of convictionLocks) {
3623
+ const dynamicInfo = dynamicInfoByNetuid[netuid];
3624
+ const scaledAlphaPrice = dynamicInfo ? getScaledAlphaPrice(dynamicInfo.alpha_in, dynamicInfo.tao_in) : 0n;
3625
+ const balance = {
3626
+ address,
3627
+ tokenId: subDTaoTokenId2(networkId, netuid),
3628
+ baseTokenId: subDTaoTokenId2(networkId, netuid),
3629
+ stake: 0n,
3630
+ hotkey: lock.hotkey,
3631
+ netuid,
3632
+ scaledAlphaPrice,
3633
+ convictionLock: lock
3634
+ };
3635
+ upsertBalance(balancesRaw, address, balance.tokenId, balance);
3636
+ }
3465
3637
  const balances = Object.values(balancesRaw);
3466
3638
  const tokensById = keyBy5(
3467
3639
  tokensWithAddresses.map(([token]) => token),
@@ -3469,6 +3641,7 @@ var fetchBalances8 = async ({
3469
3641
  );
3470
3642
  const dynamicTokens = [];
3471
3643
  for (const bal of balances) {
3644
+ if (bal.tokenId === bal.baseTokenId) continue;
3472
3645
  if (!balanceDefs.some((def) => def.token.id === bal.tokenId)) {
3473
3646
  const baseToken = tokensById[bal.baseTokenId];
3474
3647
  if (baseToken) {
@@ -3489,6 +3662,8 @@ var fetchBalances8 = async ({
3489
3662
  };
3490
3663
  const stakeAmount = BigInt(stake?.stake?.toString() ?? "0");
3491
3664
  const pendingRootClaimAmount = BigInt(stake?.pendingRootClaim?.toString() ?? "0");
3665
+ const convictionLockAmount = BigInt(stake?.convictionLock?.amount?.toString() ?? "0");
3666
+ const convictionLockConviction = BigInt(stake?.convictionLock?.convictionRaw ?? "0");
3492
3667
  const hasZeroStake = stakeAmount === 0n;
3493
3668
  const hasPendingRootClaim = pendingRootClaimAmount > 0n;
3494
3669
  const balanceValue = {
@@ -3501,9 +3676,30 @@ var fetchBalances8 = async ({
3501
3676
  type: "locked",
3502
3677
  label: "Pending root claim",
3503
3678
  amount: pendingRootClaimAmount.toString(),
3679
+ // The pending claim is not part of the stake (free amount): on-chain it only becomes
3680
+ // stake once claimed (root_claim_on_subnet). Since it was never included in `free`,
3681
+ // it must not be subtracted from it either: flag it so it does not reduce the staked
3682
+ // position's transferable amount.
3683
+ includeInTransferable: true,
3504
3684
  meta
3505
3685
  };
3506
3686
  const values3 = [balanceValue, pendingRootClaimValue];
3687
+ if (stake?.convictionLock && (convictionLockAmount > 0n || convictionLockConviction > 0n)) {
3688
+ const convictionLockMeta = {
3689
+ ...meta,
3690
+ convictionLock: {
3691
+ type: "conviction-lock",
3692
+ hotkey: stake.convictionLock.hotkey,
3693
+ lockType: stake.convictionLock.lockType
3694
+ }
3695
+ };
3696
+ values3.push({
3697
+ type: "locked",
3698
+ label: getConvictionLockLabel(stake.convictionLock.lockType),
3699
+ amount: convictionLockAmount.toString(),
3700
+ meta: convictionLockMeta
3701
+ });
3702
+ }
3507
3703
  if (hasZeroStake && hasPendingRootClaim) {
3508
3704
  values3.push({
3509
3705
  type: "extra",
@@ -3541,7 +3737,7 @@ var fetchBalances8 = async ({
3541
3737
  }
3542
3738
  };
3543
3739
  var buildStorageCoder = (metadataRpc, pallet, entry) => {
3544
- const { builder } = parseMetadataRpc4(metadataRpc);
3740
+ const { builder } = parseMetadataRpc5(metadataRpc);
3545
3741
  return builder.buildStorage(pallet, entry);
3546
3742
  };
3547
3743
  var buildRootClaimableStorageCoder = async (_connector, networkId, metadataRpc) => {
@@ -3585,7 +3781,7 @@ var buildRootClaimableQueries = (networkId, hotkeys, storageCoder) => {
3585
3781
  if (!hexValue) {
3586
3782
  return [hotkey, /* @__PURE__ */ new Map()];
3587
3783
  }
3588
- const decoded = decodeScale2(
3784
+ const decoded = decodeScale3(
3589
3785
  storageCoder,
3590
3786
  hexValue,
3591
3787
  `Failed to decode RootClaimable for hotkey ${hotkey} on ${networkId}`
@@ -3629,7 +3825,7 @@ var buildRootClaimedQueries = (networkId, addressHotkeyNetuidPairs, storageCoder
3629
3825
  if (!hexValue) {
3630
3826
  return [address, hotkey, netuid, 0n];
3631
3827
  }
3632
- const decoded = decodeScale2(
3828
+ const decoded = decodeScale3(
3633
3829
  storageCoder,
3634
3830
  hexValue,
3635
3831
  `Failed to decode RootClaimed for (netuid=${netuid}, hotkey=${hotkey}, address=${address}) on ${networkId}`
@@ -3688,9 +3884,10 @@ import {
3688
3884
  SubDTaoTokenSchema as SubDTaoTokenSchema2,
3689
3885
  subDTaoTokenId as subDTaoTokenId3
3690
3886
  } from "@talismn/chaindata-provider";
3691
- import { getStorageKeyPrefix as getStorageKeyPrefix2, parseMetadataRpc as parseMetadataRpc5 } from "@talismn/scale";
3887
+ import { getStorageKeyPrefix as getStorageKeyPrefix2, parseMetadataRpc as parseMetadataRpc6 } from "@talismn/scale";
3692
3888
  import { isNotNil as isNotNil6 } from "@talismn/util";
3693
3889
  import { fromPairs } from "lodash-es";
3890
+ import { Binary as Binary2 } from "polkadot-api";
3694
3891
  var NATIVE_TOKEN_SYMBOLS = {
3695
3892
  "bittensor": "TAO",
3696
3893
  "bittensor-testnet": "testTAO"
@@ -3717,7 +3914,7 @@ var fetchTokens8 = async ({
3717
3914
  return dynamicInfos.filter(isNotNil6).map((info) => {
3718
3915
  const config = tokens.find((t) => t.netuid === info.netuid);
3719
3916
  let symbol = new TextDecoder().decode(Uint8Array.from(info.token_symbol));
3720
- const subnetName = info.subnet_identity?.subnet_name?.asText() ?? (info.netuid === 0 ? "Root" : `Subnet ${info.netuid}`);
3917
+ const subnetName = (info.subnet_identity?.subnet_name ? Binary2.toText(info.subnet_identity.subnet_name) : void 0) ?? (info.netuid === 0 ? "Root" : `Subnet ${info.netuid}`);
3721
3918
  const name = `SN${info.netuid} | ${subnetName} ${symbol}`;
3722
3919
  if (info.netuid === 0 && NATIVE_TOKEN_SYMBOLS[networkId])
3723
3920
  symbol = NATIVE_TOKEN_SYMBOLS[networkId];
@@ -3742,7 +3939,7 @@ var fetchTokens8 = async ({
3742
3939
  });
3743
3940
  };
3744
3941
  var fetchTransferableTokensMap = async (connector, metadata, networkId) => {
3745
- const { builder } = parseMetadataRpc5(metadata);
3942
+ const { builder } = parseMetadataRpc6(metadata);
3746
3943
  const transferToggleCodec = builder.buildStorage("SubtensorModule", "TransferToggle");
3747
3944
  const transferToggleKeys = await connector.send(networkId, "state_getKeys", [
3748
3945
  getStorageKeyPrefix2("SubtensorModule", "TransferToggle")
@@ -3764,7 +3961,7 @@ var fetchTransferableTokensMap = async (connector, metadata, networkId) => {
3764
3961
 
3765
3962
  // src/modules/substrate-dtao/getMiniMetadata.ts
3766
3963
  import { MINIMETADATA_VERSION } from "@talismn/chaindata-provider";
3767
- import { compactMetadata, encodeMetadata, parseMetadataRpc as parseMetadataRpc6 } from "@talismn/scale";
3964
+ import { compactMetadata, encodeMetadata, parseMetadataRpc as parseMetadataRpc7 } from "@talismn/scale";
3768
3965
  var getMiniMetadata7 = ({
3769
3966
  networkId,
3770
3967
  specVersion,
@@ -3778,7 +3975,7 @@ var getMiniMetadata7 = ({
3778
3975
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
3779
3976
  );
3780
3977
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
3781
- const { unifiedMetadata } = parseMetadataRpc6(metadataRpc);
3978
+ const { unifiedMetadata } = parseMetadataRpc7(metadataRpc);
3782
3979
  if (unifiedMetadata.version < 14)
3783
3980
  throw new Error(
3784
3981
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -3794,16 +3991,21 @@ var getMiniMetadata7 = ({
3794
3991
  };
3795
3992
  };
3796
3993
  var getData = (metadataRpc) => {
3797
- const { metadata, unifiedMetadata } = parseMetadataRpc6(metadataRpc);
3994
+ const { metadata, unifiedMetadata } = parseMetadataRpc7(metadataRpc);
3798
3995
  const isBittensor = unifiedMetadata.pallets.some(({ name }) => name === "SubtensorModule");
3799
3996
  if (!isBittensor) return null;
3800
3997
  compactMetadata(
3801
3998
  metadata,
3802
- [{ pallet: "SubtensorModule", items: ["TransferToggle", "RootClaimable", "RootClaimed"] }],
3999
+ [
4000
+ {
4001
+ pallet: "SubtensorModule",
4002
+ items: ["TransferToggle", "RootClaimable", "RootClaimed", "Lock", "DecayingLock"]
4003
+ }
4004
+ ],
3803
4005
  [
3804
4006
  {
3805
4007
  runtimeApi: "StakeInfoRuntimeApi",
3806
- methods: ["get_stake_info_for_coldkeys"]
4008
+ methods: ["get_stake_info_for_coldkeys", "get_coldkey_lock"]
3807
4009
  },
3808
4010
  {
3809
4011
  runtimeApi: "SubnetInfoRuntimeApi",
@@ -3817,8 +4019,8 @@ var getData = (metadataRpc) => {
3817
4019
  // src/modules/substrate-dtao/getTransferCallData.ts
3818
4020
  import { mergeUint8 } from "@polkadot-api/utils";
3819
4021
  import { isTokenOfType as isTokenOfType7, parseSubDTaoTokenId } from "@talismn/chaindata-provider";
3820
- import { parseMetadataRpc as parseMetadataRpc7 } from "@talismn/scale";
3821
- import { Binary } from "polkadot-api";
4022
+ import { parseMetadataRpc as parseMetadataRpc8 } from "@talismn/scale";
4023
+ import { Binary as Binary3 } from "polkadot-api";
3822
4024
  var getTransferCallData7 = ({
3823
4025
  from: from2,
3824
4026
  to,
@@ -3830,7 +4032,7 @@ var getTransferCallData7 = ({
3830
4032
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE8}.`);
3831
4033
  const { netuid: subnetId, hotkey } = parseSubDTaoTokenId(token.id);
3832
4034
  if (!hotkey) throw new Error(`Missing hotkey`);
3833
- const { builder } = parseMetadataRpc7(metadataRpc);
4035
+ const { builder } = parseMetadataRpc8(metadataRpc);
3834
4036
  const { codec, location } = builder.buildCall("SubtensorModule", "transfer_stake");
3835
4037
  const args = codec.enc({
3836
4038
  origin_netuid: subnetId,
@@ -3839,10 +4041,10 @@ var getTransferCallData7 = ({
3839
4041
  destination_netuid: subnetId,
3840
4042
  alpha_amount: value
3841
4043
  });
3842
- const callData = Binary.fromBytes(mergeUint8([new Uint8Array(location), args]));
4044
+ const callData = mergeUint8([new Uint8Array(location), args]);
3843
4045
  return {
3844
4046
  address: from2,
3845
- method: callData.asHex()
4047
+ method: Binary3.toHex(callData)
3846
4048
  };
3847
4049
  };
3848
4050
 
@@ -3857,6 +4059,7 @@ var subscribeBalances7 = ({
3857
4059
  miniMetadata
3858
4060
  }) => {
3859
4061
  if (!tokensWithAddresses.length) return of8({ success: [], errors: [] });
4062
+ const balanceDefs = getBalanceDefs(tokensWithAddresses);
3860
4063
  return new Observable8((subscriber) => {
3861
4064
  const abortController = new AbortController();
3862
4065
  const poll = async () => {
@@ -3870,8 +4073,8 @@ var subscribeBalances7 = ({
3870
4073
  });
3871
4074
  if (abortController.signal.aborted) return;
3872
4075
  subscriber.next(balances);
3873
- setTimeout(poll, SUBSCRIPTION_INTERVAL7);
3874
4076
  } catch (error) {
4077
+ if (abortController.signal.aborted) return;
3875
4078
  log_default.error("Error", {
3876
4079
  module: MODULE_TYPE8,
3877
4080
  networkId,
@@ -3879,8 +4082,17 @@ var subscribeBalances7 = ({
3879
4082
  addressesByToken: tokensWithAddresses,
3880
4083
  error
3881
4084
  });
3882
- subscriber.error(error);
4085
+ const fetchError = error instanceof Error ? error : new Error(String(error));
4086
+ subscriber.next({
4087
+ success: [],
4088
+ errors: balanceDefs.map((def) => ({
4089
+ tokenId: def.token.id,
4090
+ address: def.address,
4091
+ error: fetchError
4092
+ }))
4093
+ });
3883
4094
  }
4095
+ if (!abortController.signal.aborted) setTimeout(poll, SUBSCRIPTION_INTERVAL7);
3884
4096
  };
3885
4097
  poll();
3886
4098
  return () => {
@@ -4183,9 +4395,9 @@ var Balance = class {
4183
4395
  const totalSupply = extras.find((extra2) => extra2.label === "totalSupply")?.amount ?? "0";
4184
4396
  const reserve0 = extras.find((extra2) => extra2.label === "reserve0")?.amount ?? "0";
4185
4397
  const reserve1 = extras.find((extra2) => extra2.label === "reserve1")?.amount ?? "0";
4186
- const totalSupplyTokens = BigNumber2(totalSupply).times(10 ** (-1 * decimals));
4187
- const reserve0Tokens = BigNumber2(reserve0).times(10 ** (-1 * decimals0));
4188
- const reserve1Tokens = BigNumber2(reserve1).times(10 ** (-1 * decimals1));
4398
+ const totalSupplyTokens = configureBigNumber_default(totalSupply).times(10 ** (-1 * decimals));
4399
+ const reserve0Tokens = configureBigNumber_default(reserve0).times(10 ** (-1 * decimals0));
4400
+ const reserve1Tokens = configureBigNumber_default(reserve1).times(10 ** (-1 * decimals1));
4189
4401
  const rates0Currencies = new Set(Object.keys(rates0));
4190
4402
  const rates1Currencies = new Set(Object.keys(rates1));
4191
4403
  const currencies = [...rates0Currencies].filter((c) => rates1Currencies.has(c));
@@ -4193,7 +4405,7 @@ var Balance = class {
4193
4405
  (currency) => [
4194
4406
  currency,
4195
4407
  // tvl (in a given currency) == reserve0*currencyRate0 + reserve1*currencyRate1
4196
- BigNumber2.sum(
4408
+ configureBigNumber_default.sum(
4197
4409
  reserve0Tokens.times(rates0[currency]?.price ?? 0),
4198
4410
  reserve1Tokens.times(rates1[currency]?.price ?? 0)
4199
4411
  )
@@ -4584,7 +4796,7 @@ var getMiniMetadata8 = ({
4584
4796
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
4585
4797
  );
4586
4798
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
4587
- const { unifiedMetadata } = parseMetadataRpc8(metadataRpc);
4799
+ const { unifiedMetadata } = parseMetadataRpc9(metadataRpc);
4588
4800
  if (unifiedMetadata.version < 14)
4589
4801
  throw new Error(
4590
4802
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -4600,7 +4812,7 @@ var getMiniMetadata8 = ({
4600
4812
  };
4601
4813
  };
4602
4814
  var getData2 = (metadataRpc) => {
4603
- const { metadata, unifiedMetadata } = parseMetadataRpc8(metadataRpc);
4815
+ const { metadata, unifiedMetadata } = parseMetadataRpc9(metadataRpc);
4604
4816
  if (!hasStorageItems(unifiedMetadata, "Assets", ["Account", "Asset", "Metadata"])) return null;
4605
4817
  compactMetadata2(metadata, [{ pallet: "Assets", items: ["Account", "Asset", "Metadata"] }]);
4606
4818
  return encodeMetadata2(metadata);
@@ -4609,8 +4821,8 @@ var getData2 = (metadataRpc) => {
4609
4821
  // src/modules/substrate-assets/getTransferCallData.ts
4610
4822
  import { mergeUint8 as mergeUint82 } from "@polkadot-api/utils";
4611
4823
  import { isTokenOfType as isTokenOfType8 } from "@talismn/chaindata-provider";
4612
- import { parseMetadataRpc as parseMetadataRpc9 } from "@talismn/scale";
4613
- import { Binary as Binary2, Enum } from "polkadot-api";
4824
+ import { parseMetadataRpc as parseMetadataRpc10 } from "@talismn/scale";
4825
+ import { Binary as Binary4, Enum } from "polkadot-api";
4614
4826
  var getTransferCallData8 = ({
4615
4827
  from: from2,
4616
4828
  to,
@@ -4621,14 +4833,14 @@ var getTransferCallData8 = ({
4621
4833
  }) => {
4622
4834
  if (!isTokenOfType8(token, MODULE_TYPE7))
4623
4835
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE7}.`);
4624
- const { builder } = parseMetadataRpc9(metadataRpc);
4836
+ const { builder } = parseMetadataRpc10(metadataRpc);
4625
4837
  const method = getTransferMethod(type);
4626
4838
  const { codec, location } = builder.buildCall("Assets", method);
4627
4839
  const args = getEncodedArgs(method, token.assetId, to, value, codec);
4628
- const callData = Binary2.fromBytes(mergeUint82([new Uint8Array(location), args]));
4840
+ const callData = mergeUint82([new Uint8Array(location), args]);
4629
4841
  return {
4630
4842
  address: from2,
4631
- method: callData.asHex()
4843
+ method: Binary4.toHex(callData)
4632
4844
  };
4633
4845
  };
4634
4846
  var getTransferMethod = (type) => {
@@ -4752,7 +4964,7 @@ var MODULE_TYPE9 = SubForeignAssetsTokenSchema.shape.type.value;
4752
4964
  var PLATFORM9 = SubForeignAssetsTokenSchema.shape.platform.value;
4753
4965
 
4754
4966
  // src/modules/substrate-foreignassets/buildQueries.ts
4755
- import { decodeScale as decodeScale3, papiParse } from "@talismn/scale";
4967
+ import { decodeScale as decodeScale4, papiParse } from "@talismn/scale";
4756
4968
  import { isNotNil as isNotNil7 } from "@talismn/util";
4757
4969
  var buildQueries2 = (networkId, balanceDefs, miniMetadata) => {
4758
4970
  const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, {
@@ -4775,7 +4987,7 @@ var buildQueries2 = (networkId, balanceDefs, miniMetadata) => {
4775
4987
  return null;
4776
4988
  }
4777
4989
  const decodeResult = (changes) => {
4778
- const decoded = decodeScale3(
4990
+ const decoded = decodeScale4(
4779
4991
  scaleCoder,
4780
4992
  changes[0],
4781
4993
  `Failed to decode substrate-assets balance on chain ${networkId}`
@@ -4886,8 +5098,9 @@ import {
4886
5098
  SubForeignAssetsTokenSchema as SubForeignAssetsTokenSchema2,
4887
5099
  subForeignAssetTokenId
4888
5100
  } from "@talismn/chaindata-provider";
4889
- import { getStorageKeyPrefix as getStorageKeyPrefix3, papiStringify, parseMetadataRpc as parseMetadataRpc10 } from "@talismn/scale";
5101
+ import { getStorageKeyPrefix as getStorageKeyPrefix3, papiStringify, parseMetadataRpc as parseMetadataRpc11 } from "@talismn/scale";
4890
5102
  import { assign as assign8, keyBy as keyBy6, keys as keys2 } from "lodash-es";
5103
+ import { Binary as Binary5 } from "polkadot-api";
4891
5104
  var fetchTokens9 = async ({
4892
5105
  networkId,
4893
5106
  tokens,
@@ -4896,7 +5109,7 @@ var fetchTokens9 = async ({
4896
5109
  }) => {
4897
5110
  const anyMiniMetadata = miniMetadata;
4898
5111
  if (!anyMiniMetadata?.data) return [];
4899
- const { builder } = parseMetadataRpc10(anyMiniMetadata.data);
5112
+ const { builder } = parseMetadataRpc11(anyMiniMetadata.data);
4900
5113
  const assetCodec = builder.buildStorage("ForeignAssets", "Asset");
4901
5114
  const metadataCodec = builder.buildStorage("ForeignAssets", "Metadata");
4902
5115
  const [allAssetStorageKeys, allMetadataStorageKeys] = await Promise.all([
@@ -4931,8 +5144,8 @@ var fetchTokens9 = async ({
4931
5144
  onChainId,
4932
5145
  decimals: metadata.decimals,
4933
5146
  isFrozen: metadata.is_frozen,
4934
- name: metadata.name?.asText(),
4935
- symbol: metadata.symbol?.asText()
5147
+ name: metadata.name ? Binary5.toText(metadata.name) : void 0,
5148
+ symbol: metadata.symbol ? Binary5.toText(metadata.symbol) : void 0
4936
5149
  };
4937
5150
  }),
4938
5151
  (a) => a.onChainId
@@ -4970,7 +5183,7 @@ var fetchTokens9 = async ({
4970
5183
 
4971
5184
  // src/modules/substrate-foreignassets/getMiniMetadata.ts
4972
5185
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION4 } from "@talismn/chaindata-provider";
4973
- import { compactMetadata as compactMetadata3, encodeMetadata as encodeMetadata3, parseMetadataRpc as parseMetadataRpc11 } from "@talismn/scale";
5186
+ import { compactMetadata as compactMetadata3, encodeMetadata as encodeMetadata3, parseMetadataRpc as parseMetadataRpc12 } from "@talismn/scale";
4974
5187
  var getMiniMetadata9 = ({
4975
5188
  networkId,
4976
5189
  specVersion,
@@ -4984,7 +5197,7 @@ var getMiniMetadata9 = ({
4984
5197
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
4985
5198
  );
4986
5199
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
4987
- const { unifiedMetadata } = parseMetadataRpc11(metadataRpc);
5200
+ const { unifiedMetadata } = parseMetadataRpc12(metadataRpc);
4988
5201
  if (unifiedMetadata.version < 14)
4989
5202
  throw new Error(
4990
5203
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -5000,7 +5213,7 @@ var getMiniMetadata9 = ({
5000
5213
  };
5001
5214
  };
5002
5215
  var getData3 = (metadataRpc) => {
5003
- const { metadata, unifiedMetadata } = parseMetadataRpc11(metadataRpc);
5216
+ const { metadata, unifiedMetadata } = parseMetadataRpc12(metadataRpc);
5004
5217
  if (!hasStorageItems(unifiedMetadata, "ForeignAssets", ["Account", "Asset", "Metadata"]))
5005
5218
  return null;
5006
5219
  compactMetadata3(metadata, [{ pallet: "ForeignAssets", items: ["Account", "Asset", "Metadata"] }]);
@@ -5010,8 +5223,8 @@ var getData3 = (metadataRpc) => {
5010
5223
  // src/modules/substrate-foreignassets/getTransferCallData.ts
5011
5224
  import { mergeUint8 as mergeUint83 } from "@polkadot-api/utils";
5012
5225
  import { isTokenOfType as isTokenOfType9 } from "@talismn/chaindata-provider";
5013
- import { papiParse as papiParse2, parseMetadataRpc as parseMetadataRpc12 } from "@talismn/scale";
5014
- import { Binary as Binary3, Enum as Enum2 } from "polkadot-api";
5226
+ import { papiParse as papiParse2, parseMetadataRpc as parseMetadataRpc13 } from "@talismn/scale";
5227
+ import { Binary as Binary6, Enum as Enum2 } from "polkadot-api";
5015
5228
  var getTransferCallData9 = ({
5016
5229
  from: from2,
5017
5230
  to,
@@ -5022,14 +5235,14 @@ var getTransferCallData9 = ({
5022
5235
  }) => {
5023
5236
  if (!isTokenOfType9(token, MODULE_TYPE9))
5024
5237
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE9}.`);
5025
- const { builder } = parseMetadataRpc12(metadataRpc);
5238
+ const { builder } = parseMetadataRpc13(metadataRpc);
5026
5239
  const method = getTransferMethod2(type);
5027
5240
  const { codec, location } = builder.buildCall("ForeignAssets", method);
5028
5241
  const args = getEncodedArgs2(method, token.onChainId, to, value, codec);
5029
- const callData = Binary3.fromBytes(mergeUint83([new Uint8Array(location), args]));
5242
+ const callData = mergeUint83([new Uint8Array(location), args]);
5030
5243
  return {
5031
5244
  address: from2,
5032
- method: callData.asHex()
5245
+ method: Binary6.toHex(callData)
5033
5246
  };
5034
5247
  };
5035
5248
  var getTransferMethod2 = (type) => {
@@ -5261,8 +5474,9 @@ import {
5261
5474
  SubHydrationTokenSchema as SubHydrationTokenSchema2,
5262
5475
  subHydrationTokenId
5263
5476
  } from "@talismn/chaindata-provider";
5264
- import { getStorageKeyPrefix as getStorageKeyPrefix4, parseMetadataRpc as parseMetadataRpc13 } from "@talismn/scale";
5477
+ import { getStorageKeyPrefix as getStorageKeyPrefix4, parseMetadataRpc as parseMetadataRpc14 } from "@talismn/scale";
5265
5478
  import { assign as assign9, keyBy as keyBy8 } from "lodash-es";
5479
+ import { Binary as Binary7 } from "polkadot-api";
5266
5480
  var fetchTokens10 = async ({
5267
5481
  networkId,
5268
5482
  tokens,
@@ -5271,7 +5485,7 @@ var fetchTokens10 = async ({
5271
5485
  }) => {
5272
5486
  const anyMiniMetadata = miniMetadata;
5273
5487
  if (!anyMiniMetadata?.data) return [];
5274
- const { builder } = parseMetadataRpc13(anyMiniMetadata.data);
5488
+ const { builder } = parseMetadataRpc14(anyMiniMetadata.data);
5275
5489
  const assetsCodec = builder.buildStorage("AssetRegistry", "Assets");
5276
5490
  const allAssetStorageKeys = await connector.send(networkId, "state_getKeys", [
5277
5491
  getStorageKeyPrefix4("AssetRegistry", "Assets")
@@ -5290,8 +5504,8 @@ var fetchTokens10 = async ({
5290
5504
  onChainId,
5291
5505
  assetType: asset.asset_type.type,
5292
5506
  isSufficient: asset.is_sufficient,
5293
- name: asset.name?.asText(),
5294
- symbol: asset.symbol?.asText(),
5507
+ name: asset.name ? Binary7.toText(asset.name) : void 0,
5508
+ symbol: asset.symbol ? Binary7.toText(asset.symbol) : void 0,
5295
5509
  decimals: asset.decimals,
5296
5510
  existentialDeposit: asset.existential_deposit.toString()
5297
5511
  };
@@ -5325,7 +5539,7 @@ var fetchTokens10 = async ({
5325
5539
 
5326
5540
  // src/modules/substrate-hydration/getMiniMetadata.ts
5327
5541
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION5 } from "@talismn/chaindata-provider";
5328
- import { compactMetadata as compactMetadata4, encodeMetadata as encodeMetadata4, parseMetadataRpc as parseMetadataRpc14 } from "@talismn/scale";
5542
+ import { compactMetadata as compactMetadata4, encodeMetadata as encodeMetadata4, parseMetadataRpc as parseMetadataRpc15 } from "@talismn/scale";
5329
5543
  var getMiniMetadata10 = ({
5330
5544
  networkId,
5331
5545
  specVersion,
@@ -5339,7 +5553,7 @@ var getMiniMetadata10 = ({
5339
5553
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
5340
5554
  );
5341
5555
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
5342
- const { unifiedMetadata } = parseMetadataRpc14(metadataRpc);
5556
+ const { unifiedMetadata } = parseMetadataRpc15(metadataRpc);
5343
5557
  if (unifiedMetadata.version < 14)
5344
5558
  throw new Error(
5345
5559
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -5355,7 +5569,7 @@ var getMiniMetadata10 = ({
5355
5569
  };
5356
5570
  };
5357
5571
  var getData4 = (metadataRpc) => {
5358
- const { metadata, unifiedMetadata } = parseMetadataRpc14(metadataRpc);
5572
+ const { metadata, unifiedMetadata } = parseMetadataRpc15(metadataRpc);
5359
5573
  if (!hasStorageItem(unifiedMetadata, "AssetRegistry", "Assets") || !hasStorageItem(unifiedMetadata, "Tokens", "Accounts") || !hasRuntimeApi(unifiedMetadata, "CurrenciesApi", "accounts"))
5360
5574
  return null;
5361
5575
  compactMetadata4(
@@ -5379,8 +5593,8 @@ var getData4 = (metadataRpc) => {
5379
5593
  // src/modules/substrate-hydration/getTransferCallData.ts
5380
5594
  import { mergeUint8 as mergeUint84 } from "@polkadot-api/utils";
5381
5595
  import { isTokenOfType as isTokenOfType10 } from "@talismn/chaindata-provider";
5382
- import { parseMetadataRpc as parseMetadataRpc15 } from "@talismn/scale";
5383
- import { Binary as Binary4 } from "polkadot-api";
5596
+ import { parseMetadataRpc as parseMetadataRpc16 } from "@talismn/scale";
5597
+ import { Binary as Binary8 } from "polkadot-api";
5384
5598
  var getTransferCallData10 = ({
5385
5599
  from: from2,
5386
5600
  to,
@@ -5390,17 +5604,17 @@ var getTransferCallData10 = ({
5390
5604
  }) => {
5391
5605
  if (!isTokenOfType10(token, MODULE_TYPE10))
5392
5606
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE10}.`);
5393
- const { builder } = parseMetadataRpc15(metadataRpc);
5607
+ const { builder } = parseMetadataRpc16(metadataRpc);
5394
5608
  const { codec, location } = builder.buildCall("Currencies", "transfer");
5395
5609
  const args = {
5396
5610
  dest: to,
5397
5611
  currency_id: token.onChainId,
5398
5612
  amount: BigInt(value)
5399
5613
  };
5400
- const callData = Binary4.fromBytes(mergeUint84([new Uint8Array(location), codec.enc(args)]));
5614
+ const callData = mergeUint84([new Uint8Array(location), codec.enc(args)]);
5401
5615
  return {
5402
5616
  address: from2,
5403
- method: callData.asHex()
5617
+ method: Binary8.toHex(callData)
5404
5618
  };
5405
5619
  };
5406
5620
 
@@ -5472,8 +5686,9 @@ var MODULE_TYPE11 = SubNativeTokenSchema.shape.type.value;
5472
5686
  var PLATFORM11 = SubNativeTokenSchema.shape.platform.value;
5473
5687
 
5474
5688
  // src/modules/substrate-native/queries/buildBaseQueries.ts
5475
- import { decodeScale as decodeScale4 } from "@talismn/scale";
5689
+ import { decodeScale as decodeScale5 } from "@talismn/scale";
5476
5690
  import { isNotNil as isNotNil8 } from "@talismn/util";
5691
+ import { Binary as Binary9 } from "polkadot-api";
5477
5692
 
5478
5693
  // src/modules/substrate-native/util/lockTypes.ts
5479
5694
  import upperFirst from "lodash-es/upperFirst";
@@ -5637,7 +5852,7 @@ var buildBaseQueries = (networkId, balanceDefs, miniMetadata) => {
5637
5852
  }).filter(isNotNil8);
5638
5853
  };
5639
5854
  var decodeBaseResult = (coder, value, networkId) => {
5640
- const decoded = decodeScale4(
5855
+ const decoded = decodeScale5(
5641
5856
  coder,
5642
5857
  value,
5643
5858
  `Failed to decode base native balance on chain ${networkId}`
@@ -5657,22 +5872,25 @@ var decodeBaseResult = (coder, value, networkId) => {
5657
5872
  return newValues;
5658
5873
  };
5659
5874
  var decodeLocksResult = (coder, value, networkId) => {
5660
- const decoded = decodeScale4(
5875
+ const decoded = decodeScale5(
5661
5876
  coder,
5662
5877
  value,
5663
5878
  `Failed to decode lock on chain ${networkId}`
5664
5879
  );
5665
- const locksQueryLocks = decoded?.map?.((lock) => ({
5666
- type: "locked",
5667
- source: "substrate-native-locks",
5668
- label: getLockedType(lock?.id?.asText?.()),
5669
- meta: { id: lock?.id?.asText?.() },
5670
- amount: (lock?.amount ?? 0n).toString()
5671
- })) ?? [];
5880
+ const locksQueryLocks = decoded?.map?.((lock) => {
5881
+ const id = lock?.id ? Binary9.toText(Binary9.fromHex(lock.id)) : void 0;
5882
+ return {
5883
+ type: "locked",
5884
+ source: "substrate-native-locks",
5885
+ label: getLockedType(id),
5886
+ meta: { id },
5887
+ amount: (lock?.amount ?? 0n).toString()
5888
+ };
5889
+ }) ?? [];
5672
5890
  return locksQueryLocks;
5673
5891
  };
5674
5892
  var decodeFreezesResult = (coder, value, networkId) => {
5675
- const decoded = decodeScale4(
5893
+ const decoded = decodeScale5(
5676
5894
  coder,
5677
5895
  value,
5678
5896
  `Failed to decode freeze on chain ${networkId}`
@@ -5686,7 +5904,7 @@ var decodeFreezesResult = (coder, value, networkId) => {
5686
5904
  return freezesValues;
5687
5905
  };
5688
5906
  var decodeHoldsResult = (coder, value, networkId) => {
5689
- const decoded = decodeScale4(
5907
+ const decoded = decodeScale5(
5690
5908
  coder,
5691
5909
  value,
5692
5910
  `Failed to decode holds on chain ${networkId}`
@@ -5702,7 +5920,7 @@ var decodeHoldsResult = (coder, value, networkId) => {
5702
5920
  return holdsValues;
5703
5921
  };
5704
5922
  var decodeStakingLedgerResult = (coder, value, networkId) => {
5705
- const decoded = decodeScale4(
5923
+ const decoded = decodeScale5(
5706
5924
  coder,
5707
5925
  value,
5708
5926
  `Failed to decode unbonding query on chain ${networkId}`
@@ -5719,7 +5937,7 @@ var decodeStakingLedgerResult = (coder, value, networkId) => {
5719
5937
  return stakingLedgerResults;
5720
5938
  };
5721
5939
  var decodePoolMemberResult = (coder, value, networkId) => {
5722
- const decoded = decodeScale4(
5940
+ const decoded = decodeScale5(
5723
5941
  coder,
5724
5942
  value,
5725
5943
  `Failed to decode poolMembers on chain ${networkId}`
@@ -5741,7 +5959,8 @@ var decodePoolMemberResult = (coder, value, networkId) => {
5741
5959
  };
5742
5960
 
5743
5961
  // src/modules/substrate-native/queries/buildNomPoolQueries.ts
5744
- import { decodeScale as decodeScale5 } from "@talismn/scale";
5962
+ import { decodeScale as decodeScale6 } from "@talismn/scale";
5963
+ import { Binary as Binary10 } from "polkadot-api";
5745
5964
 
5746
5965
  // src/modules/substrate-native/util/nompoolAccountId.ts
5747
5966
  import { mergeUint8 as mergeUint85 } from "@polkadot-api/utils";
@@ -5834,7 +6053,7 @@ var getNomPoolCoders = (networkId, miniMetadata) => {
5834
6053
  });
5835
6054
  };
5836
6055
  var decodePoolPoints = (coder, value, networkId) => {
5837
- const decoded = decodeScale5(
6056
+ const decoded = decodeScale6(
5838
6057
  coder,
5839
6058
  value,
5840
6059
  `Failed to decode bondedPools on chain ${networkId}`
@@ -5842,7 +6061,7 @@ var decodePoolPoints = (coder, value, networkId) => {
5842
6061
  return { poolPoints: decoded?.points.toString() };
5843
6062
  };
5844
6063
  var decodePoolStake = (coder, value, networkId) => {
5845
- const decoded = decodeScale5(
6064
+ const decoded = decodeScale6(
5846
6065
  coder,
5847
6066
  value,
5848
6067
  `Failed to decode ledger on chain ${networkId}`
@@ -5850,12 +6069,12 @@ var decodePoolStake = (coder, value, networkId) => {
5850
6069
  return { poolTotalActiveStake: decoded?.active.toString() };
5851
6070
  };
5852
6071
  var decodePoolMeta = (coder, value, networkId) => {
5853
- const decoded = decodeScale5(
6072
+ const decoded = decodeScale6(
5854
6073
  coder,
5855
6074
  value,
5856
6075
  `Failed to decode metadata on chain ${networkId}`
5857
6076
  );
5858
- const metadata = decoded?.asText();
6077
+ const metadata = decoded ? Binary10.toText(decoded) : void 0;
5859
6078
  return { metadata };
5860
6079
  };
5861
6080
  var getNomPoolStateKeys = (coders, nomPoolMemberInfo, extra) => {
@@ -5972,7 +6191,8 @@ var getChainProperties = async (connector, networkId) => {
5972
6191
 
5973
6192
  // src/modules/substrate-native/getMiniMetadata.ts
5974
6193
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION6 } from "@talismn/chaindata-provider";
5975
- import { compactMetadata as compactMetadata5, encodeMetadata as encodeMetadata5, parseMetadataRpc as parseMetadataRpc16 } from "@talismn/scale";
6194
+ import { compactMetadata as compactMetadata5, encodeMetadata as encodeMetadata5, parseMetadataRpc as parseMetadataRpc17 } from "@talismn/scale";
6195
+ import { Binary as Binary11 } from "polkadot-api";
5976
6196
  var getMiniMetadata11 = ({ networkId, specVersion, metadataRpc, config }) => {
5977
6197
  const source = MODULE_TYPE11;
5978
6198
  const chainId = networkId;
@@ -5982,7 +6202,7 @@ var getMiniMetadata11 = ({ networkId, specVersion, metadataRpc, config }) => {
5982
6202
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
5983
6203
  );
5984
6204
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
5985
- const { metadata, unifiedMetadata } = parseMetadataRpc16(metadataRpc);
6205
+ const { metadata, unifiedMetadata } = parseMetadataRpc17(metadataRpc);
5986
6206
  if (unifiedMetadata.version < 14)
5987
6207
  throw new Error(
5988
6208
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -6002,11 +6222,12 @@ var getMiniMetadata11 = ({ networkId, specVersion, metadataRpc, config }) => {
6002
6222
  "Balances",
6003
6223
  "ExistentialDeposit"
6004
6224
  )?.toString();
6005
- const nominationPoolsPalletId = tryGetConstantValue(
6225
+ const nominationPoolsPalletIdHex = tryGetConstantValue(
6006
6226
  metadataRpc,
6007
6227
  "NominationPools",
6008
6228
  "PalletId"
6009
- )?.asText();
6229
+ );
6230
+ const nominationPoolsPalletId = nominationPoolsPalletIdHex ? Binary11.toText(Binary11.fromHex(nominationPoolsPalletIdHex)) : void 0;
6010
6231
  const hasFreezesItem = Boolean(
6011
6232
  unifiedMetadata.pallets.find(({ name }) => name === "Balances")?.storage?.items.find(({ name }) => name === "Freezes")
6012
6233
  );
@@ -6036,9 +6257,9 @@ var getMiniMetadata11 = ({ networkId, specVersion, metadataRpc, config }) => {
6036
6257
  import { mergeUint8 as mergeUint86 } from "@polkadot-api/utils";
6037
6258
  import { isTokenOfType as isTokenOfType11 } from "@talismn/chaindata-provider";
6038
6259
  import {
6039
- parseMetadataRpc as parseMetadataRpc17
6260
+ parseMetadataRpc as parseMetadataRpc18
6040
6261
  } from "@talismn/scale";
6041
- import { Binary as Binary5, Enum as Enum3 } from "polkadot-api";
6262
+ import { Binary as Binary12, Enum as Enum3 } from "polkadot-api";
6042
6263
  var getTransferCallData11 = ({
6043
6264
  from: from2,
6044
6265
  to,
@@ -6049,14 +6270,14 @@ var getTransferCallData11 = ({
6049
6270
  }) => {
6050
6271
  if (!isTokenOfType11(token, MODULE_TYPE11))
6051
6272
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE11}.`);
6052
- const { unifiedMetadata, lookupFn, builder } = parseMetadataRpc17(metadataRpc);
6273
+ const { unifiedMetadata, lookupFn, builder } = parseMetadataRpc18(metadataRpc);
6053
6274
  const method = getTransferMethod3(type, unifiedMetadata, lookupFn);
6054
6275
  const { codec, location } = builder.buildCall("Balances", method);
6055
6276
  const args = getEncodedArgs3(method, to, value, codec);
6056
- const callData = Binary5.fromBytes(mergeUint86([new Uint8Array(location), args]));
6277
+ const callData = mergeUint86([new Uint8Array(location), args]);
6057
6278
  return {
6058
6279
  address: from2,
6059
- method: callData.asHex()
6280
+ method: Binary12.toHex(callData)
6060
6281
  };
6061
6282
  };
6062
6283
  var getTransferMethod3 = (type, unifiedMetadata, lookupFn) => {
@@ -7352,7 +7573,7 @@ var fetchTokens12 = async ({
7352
7573
 
7353
7574
  // src/modules/substrate-psp22/getMiniMetadata.ts
7354
7575
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION7 } from "@talismn/chaindata-provider";
7355
- import { parseMetadataRpc as parseMetadataRpc18 } from "@talismn/scale";
7576
+ import { parseMetadataRpc as parseMetadataRpc19 } from "@talismn/scale";
7356
7577
  var getMiniMetadata12 = ({
7357
7578
  networkId,
7358
7579
  specVersion,
@@ -7366,7 +7587,7 @@ var getMiniMetadata12 = ({
7366
7587
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
7367
7588
  );
7368
7589
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
7369
- const { unifiedMetadata } = parseMetadataRpc18(metadataRpc);
7590
+ const { unifiedMetadata } = parseMetadataRpc19(metadataRpc);
7370
7591
  if (unifiedMetadata.version < 14)
7371
7592
  throw new Error(
7372
7593
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -7387,13 +7608,13 @@ import { Abi as Abi3 } from "@polkadot/api-contract";
7387
7608
  import { TypeRegistry as TypeRegistry3 } from "@polkadot/types";
7388
7609
  import { mergeUint8 as mergeUint87 } from "@polkadot-api/utils";
7389
7610
  import { isTokenOfType as isTokenOfType12, parseTokenId as parseTokenId5 } from "@talismn/chaindata-provider";
7390
- import { parseMetadataRpc as parseMetadataRpc19 } from "@talismn/scale";
7391
- import { Binary as Binary6, Enum as Enum4 } from "polkadot-api";
7611
+ import { parseMetadataRpc as parseMetadataRpc20 } from "@talismn/scale";
7612
+ import { Binary as Binary13, Enum as Enum4 } from "polkadot-api";
7392
7613
  var getTransferCallData12 = async ({ from: from2, to, value, token, metadataRpc, connector }) => {
7393
7614
  if (!isTokenOfType12(token, MODULE_TYPE12))
7394
7615
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE12}.`);
7395
7616
  const networkId = parseTokenId5(token.id).networkId;
7396
- const { builder } = parseMetadataRpc19(metadataRpc);
7617
+ const { builder } = parseMetadataRpc20(metadataRpc);
7397
7618
  const { codec, location } = builder.buildCall("Contracts", "call");
7398
7619
  const Psp22Abi = new Abi3(psp22_default);
7399
7620
  const registry = new TypeRegistry3();
@@ -7413,12 +7634,12 @@ var getTransferCallData12 = async ({ from: from2, to, value, token, metadataRpc,
7413
7634
  proof_size: dryRunResult.gasRequired.proofSize.toBigInt()
7414
7635
  },
7415
7636
  storage_deposit_limit: dryRunResult.storageDeposit.isCharge ? dryRunResult.storageDeposit.asCharge.toBigInt() : null,
7416
- data: Binary6.fromHex(hexData)
7637
+ data: Binary13.fromHex(hexData)
7417
7638
  });
7418
- const callData = Binary6.fromBytes(mergeUint87([new Uint8Array(location), args]));
7639
+ const callData = mergeUint87([new Uint8Array(location), args]);
7419
7640
  return {
7420
7641
  address: from2,
7421
- method: callData.asHex()
7642
+ method: Binary13.toHex(callData)
7422
7643
  };
7423
7644
  };
7424
7645
 
@@ -7490,7 +7711,7 @@ var MODULE_TYPE13 = SubTokensTokenSchema.shape.type.value;
7490
7711
  var PLATFORM13 = SubTokensTokenSchema.shape.platform.value;
7491
7712
 
7492
7713
  // src/modules/substrate-tokens/buildQueries.ts
7493
- import { decodeScale as decodeScale6, papiParse as papiParse3 } from "@talismn/scale";
7714
+ import { decodeScale as decodeScale7, papiParse as papiParse3 } from "@talismn/scale";
7494
7715
  import { isNotNil as isNotNil9 } from "@talismn/util";
7495
7716
  var buildQueries3 = (networkId, balanceDefs, miniMetadata) => {
7496
7717
  const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, {
@@ -7513,7 +7734,7 @@ var buildQueries3 = (networkId, balanceDefs, miniMetadata) => {
7513
7734
  return null;
7514
7735
  }
7515
7736
  const decodeResult = (changes) => {
7516
- const decoded = decodeScale6(
7737
+ const decoded = decodeScale7(
7517
7738
  scaleCoder,
7518
7739
  changes[0],
7519
7740
  `Failed to decode substrate-tokens balance on chain ${networkId}`
@@ -7637,7 +7858,7 @@ var fetchTokens13 = async ({
7637
7858
 
7638
7859
  // src/modules/substrate-tokens/getMiniMetadata.ts
7639
7860
  import { MINIMETADATA_VERSION as MINIMETADATA_VERSION8 } from "@talismn/chaindata-provider";
7640
- import { compactMetadata as compactMetadata6, encodeMetadata as encodeMetadata6, parseMetadataRpc as parseMetadataRpc20 } from "@talismn/scale";
7861
+ import { compactMetadata as compactMetadata6, encodeMetadata as encodeMetadata6, parseMetadataRpc as parseMetadataRpc21 } from "@talismn/scale";
7641
7862
  var getMiniMetadata13 = ({ networkId, specVersion, metadataRpc, config }) => {
7642
7863
  const source = MODULE_TYPE13;
7643
7864
  const chainId = networkId;
@@ -7647,7 +7868,7 @@ var getMiniMetadata13 = ({ networkId, specVersion, metadataRpc, config }) => {
7647
7868
  `specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`
7648
7869
  );
7649
7870
  const id = deriveMiniMetadataId({ source, chainId, specVersion });
7650
- const { unifiedMetadata } = parseMetadataRpc20(metadataRpc);
7871
+ const { unifiedMetadata } = parseMetadataRpc21(metadataRpc);
7651
7872
  if (unifiedMetadata.version < 14)
7652
7873
  throw new Error(
7653
7874
  `Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`
@@ -7664,7 +7885,7 @@ var getMiniMetadata13 = ({ networkId, specVersion, metadataRpc, config }) => {
7664
7885
  };
7665
7886
  };
7666
7887
  var getData5 = (metadataRpc, pallet) => {
7667
- const { metadata, unifiedMetadata } = parseMetadataRpc20(metadataRpc);
7888
+ const { metadata, unifiedMetadata } = parseMetadataRpc21(metadataRpc);
7668
7889
  if (!hasStorageItems(unifiedMetadata, pallet, ["Accounts"])) return null;
7669
7890
  compactMetadata6(metadata, [{ pallet, items: ["Accounts"] }]);
7670
7891
  return encodeMetadata6(metadata);
@@ -7673,17 +7894,17 @@ var getData5 = (metadataRpc, pallet) => {
7673
7894
  // src/modules/substrate-tokens/getTransferCallData.ts
7674
7895
  import { mergeUint8 as mergeUint88 } from "@polkadot-api/utils";
7675
7896
  import { isTokenOfType as isTokenOfType13 } from "@talismn/chaindata-provider";
7676
- import { papiParse as papiParse4, parseMetadataRpc as parseMetadataRpc21 } from "@talismn/scale";
7677
- import { Binary as Binary7, Enum as Enum5 } from "polkadot-api";
7897
+ import { papiParse as papiParse4, parseMetadataRpc as parseMetadataRpc22 } from "@talismn/scale";
7898
+ import { Binary as Binary14, Enum as Enum5 } from "polkadot-api";
7678
7899
  var getTransferCallData13 = ({ from: from2, to, value, token, type, metadataRpc, config }) => {
7679
7900
  if (!isTokenOfType13(token, MODULE_TYPE13))
7680
7901
  throw new Error(`Token type ${token.type} is not ${MODULE_TYPE13}.`);
7681
- const { builder } = parseMetadataRpc21(metadataRpc);
7902
+ const { builder } = parseMetadataRpc22(metadataRpc);
7682
7903
  const options = getCallDataOptions(to, token, value, type, config);
7683
7904
  const callData = getCallDataFromOptions(builder, options);
7684
7905
  return {
7685
7906
  address: from2,
7686
- method: callData.asHex()
7907
+ method: Binary14.toHex(callData)
7687
7908
  };
7688
7909
  };
7689
7910
  var getTransferMethod4 = (type) => {
@@ -7707,7 +7928,7 @@ var getCallDataFromOptions = (builder, options) => {
7707
7928
  };
7708
7929
  var buildCallData = (builder, pallet, method, args) => {
7709
7930
  const { location, codec } = builder.buildCall(pallet, method);
7710
- return Binary7.fromBytes(mergeUint88([new Uint8Array(location), codec.enc(args)]));
7931
+ return mergeUint88([new Uint8Array(location), codec.enc(args)]);
7711
7932
  };
7712
7933
  var getCallDataOptions = (to, token, value, type, config) => {
7713
7934
  const onChainId = papiParse4(token.onChainId);
@@ -8117,8 +8338,14 @@ var BalancesProvider = class {
8117
8338
  map6(
8118
8339
  (results) => ({
8119
8340
  status: "live",
8120
- // exclude zero balances
8121
- balances: results.success.filter((b) => new Balance(b).total.planck > 0n),
8341
+ // exclude zero balances, but keep balances that only hold a lock
8342
+ // (eg dtao conviction locks, reported on the subnet's base token — including
8343
+ // zero-mass "ghost" locks with residual conviction, which still pin the hotkey
8344
+ // of future lock_stake calls)
8345
+ balances: results.success.filter((b) => {
8346
+ const balance = new Balance(b);
8347
+ return balance.total.planck > 0n || balance.locks.some((lock) => lock.amount.planck > 0n) || !!findDTaoConvictionLock(balance.locks);
8348
+ }),
8122
8349
  failedBalanceIds: results.errors.map(
8123
8350
  ({ tokenId, address }) => getBalanceId({ tokenId, address })
8124
8351
  )
@@ -8505,7 +8732,9 @@ export {
8505
8732
  excludeFromTransferableAmount,
8506
8733
  filterBaseLocks,
8507
8734
  filterMirrorTokens,
8735
+ findDTaoConvictionLock,
8508
8736
  getBalanceId,
8737
+ getConvictionLockLabel,
8509
8738
  getDTaoTokenRates,
8510
8739
  getLockTitle,
8511
8740
  getLockedType,
@@ -8513,6 +8742,7 @@ export {
8513
8742
  getValueId,
8514
8743
  includeInTotalExtraAmount,
8515
8744
  taoToAlpha,
8745
+ taoToAlphaCeil,
8516
8746
  uniswapV2PairAbi
8517
8747
  };
8518
8748
  //# sourceMappingURL=index.mjs.map