@talismn/balances 1.0.8 → 1.1.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.
Files changed (23) hide show
  1. package/dist/declarations/src/modules/index.d.ts +12 -1
  2. package/dist/declarations/src/modules/substrate-dtao/alphaPrice.d.ts +5 -0
  3. package/dist/declarations/src/modules/substrate-dtao/config.d.ts +5 -0
  4. package/dist/declarations/src/modules/substrate-dtao/fetchBalances.d.ts +3 -0
  5. package/dist/declarations/src/modules/substrate-dtao/fetchTokens.d.ts +3 -0
  6. package/dist/declarations/src/modules/substrate-dtao/getDtaoTokenRates.d.ts +11 -0
  7. package/dist/declarations/src/modules/substrate-dtao/getMiniMetadata.d.ts +3 -0
  8. package/dist/declarations/src/modules/substrate-dtao/getTransferCallData.d.ts +3 -0
  9. package/dist/declarations/src/modules/substrate-dtao/index.d.ts +4 -0
  10. package/dist/declarations/src/modules/substrate-dtao/module.d.ts +3 -0
  11. package/dist/declarations/src/modules/substrate-dtao/subscribeBalances.d.ts +3 -0
  12. package/dist/declarations/src/modules/substrate-dtao/types.d.ts +17 -0
  13. package/dist/declarations/src/modules/substrate-native/index.d.ts +0 -1
  14. package/dist/declarations/src/modules/substrate-native/types.d.ts +0 -1
  15. package/dist/declarations/src/types/IBalanceModule.d.ts +4 -0
  16. package/dist/declarations/src/types/balances.d.ts +26 -10
  17. package/dist/declarations/src/types/balancetypes.d.ts +1 -1
  18. package/dist/talismn-balances.cjs.dev.js +568 -348
  19. package/dist/talismn-balances.cjs.prod.js +568 -348
  20. package/dist/talismn-balances.esm.js +565 -346
  21. package/package.json +6 -6
  22. package/dist/declarations/src/modules/substrate-native/bittensor/getSubtensorStakingBalances.d.ts +0 -9
  23. package/dist/declarations/src/modules/substrate-native/bittensor/subtensor.d.ts +0 -20
@@ -33,8 +33,8 @@ var BigNumber__default = /*#__PURE__*/_interopDefault(BigNumber);
33
33
  var upperFirst__default = /*#__PURE__*/_interopDefault(upperFirst);
34
34
  var PQueue__default = /*#__PURE__*/_interopDefault(PQueue);
35
35
 
36
- const MODULE_TYPE$a = chaindataProvider.EvmErc20TokenSchema.shape.type.value;
37
- const PLATFORM$a = chaindataProvider.EvmErc20TokenSchema.shape.platform.value;
36
+ const MODULE_TYPE$b = chaindataProvider.EvmErc20TokenSchema.shape.type.value;
37
+ const PLATFORM$b = chaindataProvider.EvmErc20TokenSchema.shape.platform.value;
38
38
 
39
39
  const abiMulticall = viem.parseAbi(["struct Call { address target; bytes callData; }", "struct Call3 { address target; bool allowFailure; bytes callData; }", "struct Call3Value { address target; bool allowFailure; uint256 value; bytes callData; }", "struct Result { bool success; bytes returnData; }", "function aggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes[] memory returnData)", "function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData)", "function aggregate3Value(Call3Value[] calldata calls) public payable returns (Result[] memory returnData)", "function blockAndAggregate(Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData)", "function getBasefee() view returns (uint256 basefee)", "function getBlockHash(uint256 blockNumber) view returns (bytes32 blockHash)", "function getBlockNumber() view returns (uint256 blockNumber)", "function getChainId() view returns (uint256 chainid)", "function getCurrentBlockCoinbase() view returns (address coinbase)", "function getCurrentBlockDifficulty() view returns (uint256 difficulty)", "function getCurrentBlockGasLimit() view returns (uint256 gaslimit)", "function getCurrentBlockTimestamp() view returns (uint256 timestamp)", "function getEthBalance(address addr) view returns (uint256 balance)", "function getLastBlockHash() view returns (bytes32 blockHash)", "function tryAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (Result[] memory returnData)", "function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData)"]);
40
40
 
@@ -630,7 +630,7 @@ const getBalanceDefs = addressesByToken => {
630
630
  // if there is at least one storage entry, the results will be an array with a single object
631
631
  // if the storage has no entries in it (ex: Assets on ewx or moonbeam), the response will be an empty array
632
632
 
633
- const fetchBalances$a = async ({
633
+ const fetchBalances$b = async ({
634
634
  networkId,
635
635
  tokensWithAddresses,
636
636
  connector
@@ -642,7 +642,7 @@ const fetchBalances$a = async ({
642
642
  const client = await connector.getPublicClientForEvmNetwork(networkId);
643
643
  if (!client) throw new Error(`Could not get rpc provider for evm network ${networkId}`);
644
644
  for (const [token, addresses] of tokensWithAddresses) {
645
- if (token.type !== MODULE_TYPE$a || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
645
+ if (token.type !== MODULE_TYPE$b || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
646
646
  for (const address of addresses) if (!crypto.isEthereumAddress(address)) throw new Error(`Invalid ethereum address for EVM ERC20 balance module: ${address} for token ${token.id}`);
647
647
  }
648
648
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
@@ -672,7 +672,7 @@ const fetchWithoutAggregator = async (client, balanceDefs) => {
672
672
  address,
673
673
  tokenId: token.id,
674
674
  value: result.toString(),
675
- source: MODULE_TYPE$a,
675
+ source: MODULE_TYPE$b,
676
676
  networkId: chaindataProvider.parseEvmErc20TokenId(token.id).networkId,
677
677
  status: "live"
678
678
  };
@@ -715,7 +715,7 @@ const fetchWithAggregator = async (client, balanceDefs, erc20BalancesAggregatorA
715
715
  address: balanceDef.address,
716
716
  tokenId: balanceDef.token.id,
717
717
  value: erc20Balances[index].toString(),
718
- source: MODULE_TYPE$a,
718
+ source: MODULE_TYPE$b,
719
719
  networkId: chaindataProvider.parseTokenId(balanceDef.token.id).networkId,
720
720
  status: "live"
721
721
  }));
@@ -784,7 +784,7 @@ const TokenCacheSchema$2 = z__default.default.discriminatedUnion("isValid", [z__
784
784
  id: chaindataProvider.EvmErc20TokenSchema.shape.id,
785
785
  isValid: z__default.default.literal(false)
786
786
  })]);
787
- const fetchTokens$a = async ({
787
+ const fetchTokens$b = async ({
788
788
  networkId,
789
789
  tokens,
790
790
  connector,
@@ -824,8 +824,8 @@ const fetchTokens$a = async ({
824
824
  }
825
825
  const base = {
826
826
  id: tokenId,
827
- type: MODULE_TYPE$a,
828
- platform: PLATFORM$a,
827
+ type: MODULE_TYPE$b,
828
+ platform: PLATFORM$b,
829
829
  networkId
830
830
  };
831
831
  const cached2 = cache[tokenId] && TokenCacheSchema$2.safeParse(cache[tokenId]).data;
@@ -843,17 +843,17 @@ const fetchTokens$a = async ({
843
843
  return result;
844
844
  };
845
845
 
846
- const getMiniMetadata$a = () => {
846
+ const getMiniMetadata$b = () => {
847
847
  throw new Error("MiniMetadata is not supported for ethereum tokens");
848
848
  };
849
849
 
850
- const getTransferCallData$a = ({
850
+ const getTransferCallData$b = ({
851
851
  from,
852
852
  to,
853
853
  value,
854
854
  token
855
855
  }) => {
856
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$a)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$a}.`);
856
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$b)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$b}.`);
857
857
  if (!crypto.isEthereumAddress(from)) throw new Error("Invalid from address");
858
858
  if (!crypto.isEthereumAddress(to)) throw new Error("Invalid to address");
859
859
  const data = viem.encodeFunctionData({
@@ -868,8 +868,8 @@ const getTransferCallData$a = ({
868
868
  };
869
869
  };
870
870
 
871
- const SUBSCRIPTION_INTERVAL$6 = 6_000;
872
- const subscribeBalances$a = ({
871
+ const SUBSCRIPTION_INTERVAL$7 = 6_000;
872
+ const subscribeBalances$b = ({
873
873
  networkId,
874
874
  tokensWithAddresses,
875
875
  connector
@@ -883,17 +883,17 @@ const subscribeBalances$a = ({
883
883
  const poll = async () => {
884
884
  try {
885
885
  if (abortController.signal.aborted) return;
886
- const balances = await fetchBalances$a({
886
+ const balances = await fetchBalances$b({
887
887
  networkId,
888
888
  tokensWithAddresses: tokensWithAddresses,
889
889
  connector
890
890
  });
891
891
  if (abortController.signal.aborted) return;
892
892
  subscriber.next(balances);
893
- setTimeout(poll, SUBSCRIPTION_INTERVAL$6);
893
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$7);
894
894
  } catch (error) {
895
895
  log.error("Error", {
896
- module: MODULE_TYPE$a,
896
+ module: MODULE_TYPE$b,
897
897
  networkId,
898
898
  addressesByToken: tokensWithAddresses,
899
899
  error
@@ -909,13 +909,13 @@ const subscribeBalances$a = ({
909
909
  };
910
910
 
911
911
  const EvmErc20BalanceModule = {
912
- type: MODULE_TYPE$a,
913
- platform: PLATFORM$a,
914
- getMiniMetadata: getMiniMetadata$a,
915
- fetchTokens: fetchTokens$a,
916
- fetchBalances: fetchBalances$a,
917
- subscribeBalances: subscribeBalances$a,
918
- getTransferCallData: getTransferCallData$a
912
+ type: MODULE_TYPE$b,
913
+ platform: PLATFORM$b,
914
+ getMiniMetadata: getMiniMetadata$b,
915
+ fetchTokens: fetchTokens$b,
916
+ fetchBalances: fetchBalances$b,
917
+ subscribeBalances: subscribeBalances$b,
918
+ getTransferCallData: getTransferCallData$b
919
919
  };
920
920
 
921
921
  const TokenConfigBaseSchema = chaindataProvider.TokenBaseSchema.partial().omit({
@@ -928,10 +928,10 @@ const EvmErc20TokenConfigSchema = z__default.default.strictObject({
928
928
  ...TokenConfigBaseSchema.shape
929
929
  });
930
930
 
931
- const MODULE_TYPE$9 = chaindataProvider.EvmNativeTokenSchema.shape.type.value;
932
- const PLATFORM$9 = chaindataProvider.EvmNativeTokenSchema.shape.platform.value;
931
+ const MODULE_TYPE$a = chaindataProvider.EvmNativeTokenSchema.shape.type.value;
932
+ const PLATFORM$a = chaindataProvider.EvmNativeTokenSchema.shape.platform.value;
933
933
 
934
- const fetchBalances$9 = async ({
934
+ const fetchBalances$a = async ({
935
935
  networkId,
936
936
  tokensWithAddresses,
937
937
  connector
@@ -943,7 +943,7 @@ const fetchBalances$9 = async ({
943
943
  const client = await connector.getPublicClientForEvmNetwork(networkId);
944
944
  if (!client) throw new Error(`Could not get rpc provider for evm network ${networkId}`);
945
945
  for (const [token, addresses] of tokensWithAddresses) {
946
- if (token.type !== MODULE_TYPE$9 || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
946
+ if (token.type !== MODULE_TYPE$a || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
947
947
  for (const address of addresses) if (!crypto.isEthereumAddress(address)) throw new Error(`Invalid ethereum address for EVM ERC20 balance module: ${address} for token ${token.id}`);
948
948
  }
949
949
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
@@ -970,7 +970,7 @@ const fetchWithoutMulticall = async (client, balanceDefs) => {
970
970
  address,
971
971
  tokenId: token.id,
972
972
  value: result.toString(),
973
- source: MODULE_TYPE$9,
973
+ source: MODULE_TYPE$a,
974
974
  networkId: chaindataProvider.parseTokenId(token.id).networkId,
975
975
  status: "live"
976
976
  };
@@ -1016,7 +1016,7 @@ const fetchWithMulticall = async (client, balanceDefs, multicall3Address) => {
1016
1016
  address: balanceDefs[index].address,
1017
1017
  tokenId: balanceDefs[index].token.id,
1018
1018
  value: result.result.toString(),
1019
- source: MODULE_TYPE$9,
1019
+ source: MODULE_TYPE$a,
1020
1020
  networkId: chaindataProvider.parseTokenId(balanceDefs[index].token.id).networkId,
1021
1021
  status: "live"
1022
1022
  });
@@ -1046,7 +1046,7 @@ const fetchWithMulticall = async (client, balanceDefs, multicall3Address) => {
1046
1046
  }
1047
1047
  };
1048
1048
 
1049
- const fetchTokens$9 = async ({
1049
+ const fetchTokens$a = async ({
1050
1050
  networkId,
1051
1051
  tokens
1052
1052
  }) => {
@@ -1054,8 +1054,8 @@ const fetchTokens$9 = async ({
1054
1054
  if (tokens.length !== 1) throw new Error("EVM Native module expects the nativeCurrency to be passed as a single token in the array");
1055
1055
  const token = lodashEs.assign({
1056
1056
  id: chaindataProvider.evmNativeTokenId(networkId),
1057
- type: MODULE_TYPE$9,
1058
- platform: PLATFORM$9,
1057
+ type: MODULE_TYPE$a,
1058
+ platform: PLATFORM$a,
1059
1059
  networkId,
1060
1060
  isDefault: true
1061
1061
  }, tokens[0]);
@@ -1067,17 +1067,17 @@ const fetchTokens$9 = async ({
1067
1067
  return [parsed.data];
1068
1068
  };
1069
1069
 
1070
- const getMiniMetadata$9 = () => {
1070
+ const getMiniMetadata$a = () => {
1071
1071
  throw new Error("MiniMetadata is not supported for ethereum tokens");
1072
1072
  };
1073
1073
 
1074
- const getTransferCallData$9 = ({
1074
+ const getTransferCallData$a = ({
1075
1075
  from,
1076
1076
  to,
1077
1077
  value,
1078
1078
  token
1079
1079
  }) => {
1080
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$9)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$9}.`);
1080
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$a)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$a}.`);
1081
1081
  if (!crypto.isEthereumAddress(from)) throw new Error("Invalid from address");
1082
1082
  if (!crypto.isEthereumAddress(to)) throw new Error("Invalid to address");
1083
1083
  return {
@@ -1088,8 +1088,8 @@ const getTransferCallData$9 = ({
1088
1088
  };
1089
1089
  };
1090
1090
 
1091
- const SUBSCRIPTION_INTERVAL$5 = 6_000;
1092
- const subscribeBalances$9 = ({
1091
+ const SUBSCRIPTION_INTERVAL$6 = 6_000;
1092
+ const subscribeBalances$a = ({
1093
1093
  networkId,
1094
1094
  tokensWithAddresses,
1095
1095
  connector
@@ -1103,17 +1103,17 @@ const subscribeBalances$9 = ({
1103
1103
  const poll = async () => {
1104
1104
  try {
1105
1105
  if (abortController.signal.aborted) return;
1106
- const balances = await fetchBalances$9({
1106
+ const balances = await fetchBalances$a({
1107
1107
  networkId,
1108
1108
  tokensWithAddresses: tokensWithAddresses,
1109
1109
  connector
1110
1110
  });
1111
1111
  if (abortController.signal.aborted) return;
1112
1112
  subscriber.next(balances);
1113
- setTimeout(poll, SUBSCRIPTION_INTERVAL$5);
1113
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$6);
1114
1114
  } catch (error) {
1115
1115
  log.error("Error", {
1116
- module: MODULE_TYPE$9,
1116
+ module: MODULE_TYPE$a,
1117
1117
  networkId,
1118
1118
  addressesByToken: tokensWithAddresses,
1119
1119
  error
@@ -1129,13 +1129,13 @@ const subscribeBalances$9 = ({
1129
1129
  };
1130
1130
 
1131
1131
  const EvmNativeBalanceModule = {
1132
- type: MODULE_TYPE$9,
1133
- platform: PLATFORM$9,
1134
- getMiniMetadata: getMiniMetadata$9,
1135
- fetchTokens: fetchTokens$9,
1136
- fetchBalances: fetchBalances$9,
1137
- subscribeBalances: subscribeBalances$9,
1138
- getTransferCallData: getTransferCallData$9
1132
+ type: MODULE_TYPE$a,
1133
+ platform: PLATFORM$a,
1134
+ getMiniMetadata: getMiniMetadata$a,
1135
+ fetchTokens: fetchTokens$a,
1136
+ fetchBalances: fetchBalances$a,
1137
+ subscribeBalances: subscribeBalances$a,
1138
+ getTransferCallData: getTransferCallData$a
1139
1139
  };
1140
1140
 
1141
1141
  // to be used by chaindata too
@@ -1143,10 +1143,10 @@ const EvmNativeTokenConfigSchema = z__default.default.strictObject({
1143
1143
  ...TokenConfigBaseSchema.shape
1144
1144
  });
1145
1145
 
1146
- const MODULE_TYPE$8 = chaindataProvider.EvmUniswapV2TokenSchema.shape.type.value;
1147
- const PLATFORM$8 = chaindataProvider.EvmUniswapV2TokenSchema.shape.platform.value;
1146
+ const MODULE_TYPE$9 = chaindataProvider.EvmUniswapV2TokenSchema.shape.type.value;
1147
+ const PLATFORM$9 = chaindataProvider.EvmUniswapV2TokenSchema.shape.platform.value;
1148
1148
 
1149
- const fetchBalances$8 = async ({
1149
+ const fetchBalances$9 = async ({
1150
1150
  networkId,
1151
1151
  tokensWithAddresses,
1152
1152
  connector
@@ -1158,7 +1158,7 @@ const fetchBalances$8 = async ({
1158
1158
  const client = await connector.getPublicClientForEvmNetwork(networkId);
1159
1159
  if (!client) throw new Error(`Could not get rpc provider for evm network ${networkId}`);
1160
1160
  for (const [token, addresses] of tokensWithAddresses) {
1161
- if (token.type !== MODULE_TYPE$8 || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
1161
+ if (token.type !== MODULE_TYPE$9 || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for EVM ERC20 balance module: ${token.type} on ${token.networkId}`);
1162
1162
  for (const address of addresses) if (!crypto.isEthereumAddress(address)) throw new Error(`Invalid ethereum address for EVM ERC20 balance module: ${address} for token ${token.id}`);
1163
1163
  }
1164
1164
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
@@ -1245,7 +1245,7 @@ const fetchPoolBalances = async (client, balanceDefs) => {
1245
1245
  acc.success.push({
1246
1246
  address,
1247
1247
  tokenId: token.id,
1248
- source: MODULE_TYPE$8,
1248
+ source: MODULE_TYPE$9,
1249
1249
  networkId: chaindataProvider.parseTokenId(token.id).networkId,
1250
1250
  status: "live",
1251
1251
  values: [{
@@ -1323,7 +1323,7 @@ const TokenCacheSchema$1 = z__default.default.discriminatedUnion("isValid", [z__
1323
1323
  id: chaindataProvider.EvmUniswapV2TokenSchema.shape.id,
1324
1324
  isValid: z__default.default.literal(false)
1325
1325
  })]);
1326
- const fetchTokens$8 = async ({
1326
+ const fetchTokens$9 = async ({
1327
1327
  networkId,
1328
1328
  tokens,
1329
1329
  connector,
@@ -1382,8 +1382,8 @@ const fetchTokens$8 = async ({
1382
1382
  }
1383
1383
  const base = {
1384
1384
  id: tokenId,
1385
- type: MODULE_TYPE$8,
1386
- platform: PLATFORM$8,
1385
+ type: MODULE_TYPE$9,
1386
+ platform: PLATFORM$9,
1387
1387
  networkId
1388
1388
  };
1389
1389
  const cached2 = cache[tokenId] && TokenCacheSchema$1.safeParse(cache[tokenId]).data;
@@ -1399,17 +1399,17 @@ const fetchTokens$8 = async ({
1399
1399
  return result;
1400
1400
  };
1401
1401
 
1402
- const getMiniMetadata$8 = () => {
1402
+ const getMiniMetadata$9 = () => {
1403
1403
  throw new Error("MiniMetadata is not supported for ethereum tokens");
1404
1404
  };
1405
1405
 
1406
- const getTransferCallData$8 = ({
1406
+ const getTransferCallData$9 = ({
1407
1407
  from,
1408
1408
  to,
1409
1409
  value,
1410
1410
  token
1411
1411
  }) => {
1412
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$8)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$8}.`);
1412
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$9)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$9}.`);
1413
1413
  if (!crypto.isEthereumAddress(from)) throw new Error("Invalid from address");
1414
1414
  if (!crypto.isEthereumAddress(to)) throw new Error("Invalid to address");
1415
1415
  const data = viem.encodeFunctionData({
@@ -1424,8 +1424,8 @@ const getTransferCallData$8 = ({
1424
1424
  };
1425
1425
  };
1426
1426
 
1427
- const SUBSCRIPTION_INTERVAL$4 = 6_000;
1428
- const subscribeBalances$8 = ({
1427
+ const SUBSCRIPTION_INTERVAL$5 = 6_000;
1428
+ const subscribeBalances$9 = ({
1429
1429
  networkId,
1430
1430
  tokensWithAddresses,
1431
1431
  connector
@@ -1439,17 +1439,17 @@ const subscribeBalances$8 = ({
1439
1439
  const poll = async () => {
1440
1440
  try {
1441
1441
  if (abortController.signal.aborted) return;
1442
- const balances = await fetchBalances$8({
1442
+ const balances = await fetchBalances$9({
1443
1443
  networkId,
1444
1444
  tokensWithAddresses: tokensWithAddresses,
1445
1445
  connector
1446
1446
  });
1447
1447
  if (abortController.signal.aborted) return;
1448
1448
  subscriber.next(balances);
1449
- setTimeout(poll, SUBSCRIPTION_INTERVAL$4);
1449
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$5);
1450
1450
  } catch (error) {
1451
1451
  log.error("Error", {
1452
- module: MODULE_TYPE$8,
1452
+ module: MODULE_TYPE$9,
1453
1453
  networkId,
1454
1454
  addressesByToken: tokensWithAddresses,
1455
1455
  error
@@ -1465,13 +1465,13 @@ const subscribeBalances$8 = ({
1465
1465
  };
1466
1466
 
1467
1467
  const EvmUniswapV2BalanceModule = {
1468
- type: MODULE_TYPE$8,
1469
- platform: PLATFORM$8,
1470
- getMiniMetadata: getMiniMetadata$8,
1471
- fetchTokens: fetchTokens$8,
1472
- fetchBalances: fetchBalances$8,
1473
- subscribeBalances: subscribeBalances$8,
1474
- getTransferCallData: getTransferCallData$8
1468
+ type: MODULE_TYPE$9,
1469
+ platform: PLATFORM$9,
1470
+ getMiniMetadata: getMiniMetadata$9,
1471
+ fetchTokens: fetchTokens$9,
1472
+ fetchBalances: fetchBalances$9,
1473
+ subscribeBalances: subscribeBalances$9,
1474
+ getTransferCallData: getTransferCallData$9
1475
1475
  };
1476
1476
 
1477
1477
  // to be used by chaindata too
@@ -1480,10 +1480,10 @@ const EvmUniswapV2TokenConfigSchema = z__default.default.strictObject({
1480
1480
  ...TokenConfigBaseSchema.shape
1481
1481
  });
1482
1482
 
1483
- const MODULE_TYPE$7 = chaindataProvider.SolNativeTokenSchema.shape.type.value;
1484
- const PLATFORM$7 = chaindataProvider.SolNativeTokenSchema.shape.platform.value;
1483
+ const MODULE_TYPE$8 = chaindataProvider.SolNativeTokenSchema.shape.type.value;
1484
+ const PLATFORM$8 = chaindataProvider.SolNativeTokenSchema.shape.platform.value;
1485
1485
 
1486
- const fetchBalances$7 = async ({
1486
+ const fetchBalances$8 = async ({
1487
1487
  networkId,
1488
1488
  tokensWithAddresses,
1489
1489
  connector
@@ -1495,7 +1495,7 @@ const fetchBalances$7 = async ({
1495
1495
  const connection = await connector.getConnection(networkId);
1496
1496
  if (!connection) throw new Error(`Could not get rpc provider for sol network ${networkId}`);
1497
1497
  for (const [token, addresses] of tokensWithAddresses) {
1498
- if (token.type !== MODULE_TYPE$7 || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for balance module: ${token.type} on ${token.networkId}`);
1498
+ if (token.type !== MODULE_TYPE$8 || token.networkId !== networkId) throw new Error(`Invalid token type or networkId for balance module: ${token.type} on ${token.networkId}`);
1499
1499
  for (const address of addresses) if (!crypto.isSolanaAddress(address)) throw new Error(`Invalid solana address for balance module: ${address} for token ${token.id}`);
1500
1500
  }
1501
1501
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
@@ -1510,7 +1510,7 @@ const fetchBalances$7 = async ({
1510
1510
  address: address,
1511
1511
  tokenId: token.id,
1512
1512
  value: lamports.toString(),
1513
- source: MODULE_TYPE$7,
1513
+ source: MODULE_TYPE$8,
1514
1514
  networkId: token.networkId,
1515
1515
  status: "live"
1516
1516
  };
@@ -1534,7 +1534,7 @@ const fetchBalances$7 = async ({
1534
1534
  });
1535
1535
  };
1536
1536
 
1537
- const fetchTokens$7 = async ({
1537
+ const fetchTokens$8 = async ({
1538
1538
  networkId,
1539
1539
  tokens
1540
1540
  }) => {
@@ -1542,8 +1542,8 @@ const fetchTokens$7 = async ({
1542
1542
  if (tokens.length !== 1) throw new Error("EVM Native module expects the nativeCurrency to be passed as a single token in the array");
1543
1543
  const token = lodashEs.assign({
1544
1544
  id: chaindataProvider.solNativeTokenId(networkId),
1545
- type: MODULE_TYPE$7,
1546
- platform: PLATFORM$7,
1545
+ type: MODULE_TYPE$8,
1546
+ platform: PLATFORM$8,
1547
1547
  networkId,
1548
1548
  isDefault: true
1549
1549
  }, tokens[0]);
@@ -1555,17 +1555,17 @@ const fetchTokens$7 = async ({
1555
1555
  return [parsed.data];
1556
1556
  };
1557
1557
 
1558
- const getMiniMetadata$7 = () => {
1558
+ const getMiniMetadata$8 = () => {
1559
1559
  throw new Error("MiniMetadata is not supported for sol-native tokens");
1560
1560
  };
1561
1561
 
1562
- const getTransferCallData$7 = ({
1562
+ const getTransferCallData$8 = ({
1563
1563
  from,
1564
1564
  to,
1565
1565
  value,
1566
1566
  token
1567
1567
  }) => {
1568
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$7)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$7}.`);
1568
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$8)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$8}.`);
1569
1569
  const fromPubkey = new web3_js.PublicKey(from);
1570
1570
  const transferIx = web3_js.SystemProgram.transfer({
1571
1571
  fromPubkey,
@@ -1575,8 +1575,8 @@ const getTransferCallData$7 = ({
1575
1575
  return [transferIx];
1576
1576
  };
1577
1577
 
1578
- const SUBSCRIPTION_INTERVAL$3 = 6_000;
1579
- const subscribeBalances$7 = ({
1578
+ const SUBSCRIPTION_INTERVAL$4 = 6_000;
1579
+ const subscribeBalances$8 = ({
1580
1580
  networkId,
1581
1581
  tokensWithAddresses,
1582
1582
  connector
@@ -1590,17 +1590,17 @@ const subscribeBalances$7 = ({
1590
1590
  const poll = async () => {
1591
1591
  try {
1592
1592
  if (abortController.signal.aborted) return;
1593
- const balances = await fetchBalances$7({
1593
+ const balances = await fetchBalances$8({
1594
1594
  networkId,
1595
1595
  tokensWithAddresses,
1596
1596
  connector
1597
1597
  });
1598
1598
  if (abortController.signal.aborted) return;
1599
1599
  subscriber.next(balances);
1600
- setTimeout(poll, SUBSCRIPTION_INTERVAL$3);
1600
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$4);
1601
1601
  } catch (error) {
1602
1602
  log.error("Error", {
1603
- module: MODULE_TYPE$7,
1603
+ module: MODULE_TYPE$8,
1604
1604
  networkId,
1605
1605
  tokensWithAddresses,
1606
1606
  error
@@ -1616,13 +1616,13 @@ const subscribeBalances$7 = ({
1616
1616
  };
1617
1617
 
1618
1618
  const SolNativeBalanceModule = {
1619
- type: MODULE_TYPE$7,
1620
- platform: PLATFORM$7,
1621
- getMiniMetadata: getMiniMetadata$7,
1622
- fetchTokens: fetchTokens$7,
1623
- fetchBalances: fetchBalances$7,
1624
- subscribeBalances: subscribeBalances$7,
1625
- getTransferCallData: getTransferCallData$7
1619
+ type: MODULE_TYPE$8,
1620
+ platform: PLATFORM$8,
1621
+ getMiniMetadata: getMiniMetadata$8,
1622
+ fetchTokens: fetchTokens$8,
1623
+ fetchBalances: fetchBalances$8,
1624
+ subscribeBalances: subscribeBalances$8,
1625
+ getTransferCallData: getTransferCallData$8
1626
1626
  };
1627
1627
 
1628
1628
  // to be used by chaindata too
@@ -1630,16 +1630,22 @@ const SolNativeTokenConfigSchema = z__default.default.strictObject({
1630
1630
  ...TokenConfigBaseSchema.shape
1631
1631
  });
1632
1632
 
1633
- const MODULE_TYPE$6 = chaindataProvider.SolSplTokenSchema.shape.type.value;
1634
- const PLATFORM$6 = chaindataProvider.SolSplTokenSchema.shape.platform.value;
1633
+ const MODULE_TYPE$7 = chaindataProvider.SolSplTokenSchema.shape.type.value;
1634
+ const PLATFORM$7 = chaindataProvider.SolSplTokenSchema.shape.platform.value;
1635
1635
 
1636
1636
  const fetchRuntimeCallResult = async (connector, networkId, metadataRpc, apiName, method, args) => {
1637
- const {
1638
- builder
1639
- } = scale.parseMetadataRpc(metadataRpc);
1640
- const call = builder.buildRuntimeCall(apiName, method);
1641
- const hex = await connector.send(networkId, "state_call", [`${apiName}_${method}`, scale.toHex(call.args.enc(args))]);
1642
- return call.value.dec(hex);
1637
+ try {
1638
+ const {
1639
+ builder
1640
+ } = scale.parseMetadataRpc(metadataRpc);
1641
+ const call = builder.buildRuntimeCall(apiName, method);
1642
+ const hex = await connector.send(networkId, "state_call", [`${apiName}_${method}`, scale.toHex(call.args.enc(args))]);
1643
+ return call.value.dec(hex);
1644
+ } catch (cause) {
1645
+ throw new Error(`Error fetching runtime call on ${networkId} for ${apiName}.${method}`, {
1646
+ cause
1647
+ });
1648
+ }
1643
1649
  };
1644
1650
 
1645
1651
  const hasStorageItem = (metadata, palletName, itemName) => {
@@ -1784,7 +1790,7 @@ const setDetectedTokenIds = (address, type, tokenIds) => {
1784
1790
  const getDetectedTokensIds$ = address => tokenIdsByAddress.pipe(rxjs.map(ownedTokens => ownedTokens[address] ?? []), rxjs.distinctUntilChanged(lodashEs.isEqual));
1785
1791
 
1786
1792
  const SPL_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
1787
- const fetchBalances$6 = async ({
1793
+ const fetchBalances$7 = async ({
1788
1794
  networkId,
1789
1795
  tokensWithAddresses,
1790
1796
  connector
@@ -1808,7 +1814,7 @@ const fetchBalances$6 = async ({
1808
1814
  tokenId: chaindataProvider.solSplTokenId(networkId, mintAddress),
1809
1815
  networkId,
1810
1816
  address,
1811
- source: MODULE_TYPE$6,
1817
+ source: MODULE_TYPE$7,
1812
1818
  status: "live",
1813
1819
  value
1814
1820
  };
@@ -1822,7 +1828,7 @@ const fetchBalances$6 = async ({
1822
1828
  }).filter(util.isNotNil);
1823
1829
 
1824
1830
  // allows the wallet to detect new tokens, and enable them automatically
1825
- setDetectedTokenIds(address, MODULE_TYPE$6, balances.map(b => b.tokenId));
1831
+ setDetectedTokenIds(address, MODULE_TYPE$7, balances.map(b => b.tokenId));
1826
1832
  return [address, balances];
1827
1833
  }));
1828
1834
  const allBalancesByKey = lodashEs.keyBy(balancesPerAddress.flatMap(([, addressBalances]) => addressBalances), b => getBalanceKey(b.tokenId, b.address));
@@ -1835,7 +1841,7 @@ const fetchBalances$6 = async ({
1835
1841
  tokenId: bd.token.id,
1836
1842
  networkId: bd.token.networkId,
1837
1843
  address: bd.address,
1838
- source: MODULE_TYPE$6,
1844
+ source: MODULE_TYPE$7,
1839
1845
  status: "live",
1840
1846
  value: "0"
1841
1847
  };
@@ -1863,7 +1869,7 @@ const TokenCacheSchema = z__default.default.discriminatedUnion("isValid", [z__de
1863
1869
  isValid: z__default.default.literal(false)
1864
1870
  })]);
1865
1871
  const METAPLEX_PROGRAM_ID = new web3_js.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
1866
- const fetchTokens$6 = async ({
1872
+ const fetchTokens$7 = async ({
1867
1873
  networkId,
1868
1874
  tokens,
1869
1875
  connector,
@@ -1881,8 +1887,8 @@ const fetchTokens$6 = async ({
1881
1887
  if (cached?.isValid === false) continue;
1882
1888
  const base = {
1883
1889
  id: tokenId,
1884
- type: MODULE_TYPE$6,
1885
- platform: PLATFORM$6,
1890
+ type: MODULE_TYPE$7,
1891
+ platform: PLATFORM$7,
1886
1892
  networkId
1887
1893
  };
1888
1894
  const token = lodashEs.assign(base, cached?.isValid ? lodashEs.omit(cached, ["isValid"]) : {}, tokenConfig);
@@ -1949,18 +1955,18 @@ const fetchOnChainTokenData = async (connector, tokenId) => {
1949
1955
  return null;
1950
1956
  };
1951
1957
 
1952
- const getMiniMetadata$6 = () => {
1958
+ const getMiniMetadata$7 = () => {
1953
1959
  throw new Error("MiniMetadata is not supported for solana tokens");
1954
1960
  };
1955
1961
 
1956
- const getTransferCallData$6 = async ({
1962
+ const getTransferCallData$7 = async ({
1957
1963
  from,
1958
1964
  to,
1959
1965
  value,
1960
1966
  token,
1961
1967
  connector
1962
1968
  }) => {
1963
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
1969
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$7)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$7}.`);
1964
1970
  const connection = await connector.getConnection(token.networkId);
1965
1971
  const instructions = [];
1966
1972
  const mint = new web3_js.PublicKey(token.mintAddress);
@@ -1991,8 +1997,8 @@ const tokenAccountExists = async (connection, address) => {
1991
1997
  }
1992
1998
  };
1993
1999
 
1994
- const SUBSCRIPTION_INTERVAL$2 = 6_000;
1995
- const subscribeBalances$6 = ({
2000
+ const SUBSCRIPTION_INTERVAL$3 = 6_000;
2001
+ const subscribeBalances$7 = ({
1996
2002
  networkId,
1997
2003
  tokensWithAddresses,
1998
2004
  connector
@@ -2006,17 +2012,17 @@ const subscribeBalances$6 = ({
2006
2012
  const poll = async () => {
2007
2013
  try {
2008
2014
  if (abortController.signal.aborted) return;
2009
- const balances = await fetchBalances$6({
2015
+ const balances = await fetchBalances$7({
2010
2016
  networkId,
2011
2017
  tokensWithAddresses: tokensWithAddresses,
2012
2018
  connector
2013
2019
  });
2014
2020
  if (abortController.signal.aborted) return;
2015
2021
  subscriber.next(balances);
2016
- setTimeout(poll, SUBSCRIPTION_INTERVAL$2);
2022
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$3);
2017
2023
  } catch (error) {
2018
2024
  log.error("Error", {
2019
- module: MODULE_TYPE$6,
2025
+ module: MODULE_TYPE$7,
2020
2026
  networkId,
2021
2027
  addressesByToken: tokensWithAddresses,
2022
2028
  error
@@ -2032,13 +2038,13 @@ const subscribeBalances$6 = ({
2032
2038
  };
2033
2039
 
2034
2040
  const SolSplBalanceModule = {
2035
- type: MODULE_TYPE$6,
2036
- platform: PLATFORM$6,
2037
- getMiniMetadata: getMiniMetadata$6,
2038
- fetchTokens: fetchTokens$6,
2039
- fetchBalances: fetchBalances$6,
2040
- subscribeBalances: subscribeBalances$6,
2041
- getTransferCallData: getTransferCallData$6
2041
+ type: MODULE_TYPE$7,
2042
+ platform: PLATFORM$7,
2043
+ getMiniMetadata: getMiniMetadata$7,
2044
+ fetchTokens: fetchTokens$7,
2045
+ fetchBalances: fetchBalances$7,
2046
+ subscribeBalances: subscribeBalances$7,
2047
+ getTransferCallData: getTransferCallData$7
2042
2048
  };
2043
2049
 
2044
2050
  // to be used by chaindata too
@@ -2047,8 +2053,8 @@ const SolSplTokenConfigSchema = z__default.default.strictObject({
2047
2053
  ...TokenConfigBaseSchema.shape
2048
2054
  });
2049
2055
 
2050
- const MODULE_TYPE$5 = chaindataProvider.SubAssetsTokenSchema.shape.type.value;
2051
- const PLATFORM$5 = chaindataProvider.SubAssetsTokenSchema.shape.platform.value;
2056
+ const MODULE_TYPE$6 = chaindataProvider.SubAssetsTokenSchema.shape.type.value;
2057
+ const PLATFORM$6 = chaindataProvider.SubAssetsTokenSchema.shape.platform.value;
2052
2058
 
2053
2059
  const buildQueries$2 = (networkId, balanceDefs, miniMetadata) => {
2054
2060
  const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, {
@@ -2124,7 +2130,7 @@ const tryEncode = (scaleCoder, ...args) => {
2124
2130
  }
2125
2131
  };
2126
2132
 
2127
- const fetchBalances$5 = async ({
2133
+ const fetchBalances$6 = async ({
2128
2134
  networkId,
2129
2135
  tokensWithAddresses,
2130
2136
  connector,
@@ -2136,7 +2142,7 @@ const fetchBalances$5 = async ({
2136
2142
  };
2137
2143
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
2138
2144
  if (!miniMetadata?.data) {
2139
- log.warn(`MiniMetadata is required for fetching ${MODULE_TYPE$5} balances on ${networkId}.`);
2145
+ log.warn(`MiniMetadata is required for fetching ${MODULE_TYPE$6} balances on ${networkId}.`);
2140
2146
  return {
2141
2147
  success: [],
2142
2148
  errors: balanceDefs.map(def => ({
@@ -2146,19 +2152,19 @@ const fetchBalances$5 = async ({
2146
2152
  }))
2147
2153
  };
2148
2154
  }
2149
- if (miniMetadata.source !== MODULE_TYPE$5) {
2150
- log.warn(`Ignoring miniMetadata with source ${miniMetadata.source} in ${MODULE_TYPE$5}.`);
2155
+ if (miniMetadata.source !== MODULE_TYPE$6) {
2156
+ log.warn(`Ignoring miniMetadata with source ${miniMetadata.source} in ${MODULE_TYPE$6}.`);
2151
2157
  return {
2152
2158
  success: [],
2153
2159
  errors: balanceDefs.map(def => ({
2154
2160
  tokenId: def.token.id,
2155
2161
  address: def.address,
2156
- error: new Error(`Invalid request: miniMetadata source is not ${MODULE_TYPE$5}`)
2162
+ error: new Error(`Invalid request: miniMetadata source is not ${MODULE_TYPE$6}`)
2157
2163
  }))
2158
2164
  };
2159
2165
  }
2160
2166
  if (miniMetadata.chainId !== networkId) {
2161
- log.warn(`Ignoring miniMetadata with chainId ${miniMetadata.chainId} in ${MODULE_TYPE$5}. Expected chainId is ${networkId}`);
2167
+ log.warn(`Ignoring miniMetadata with chainId ${miniMetadata.chainId} in ${MODULE_TYPE$6}. Expected chainId is ${networkId}`);
2162
2168
  return {
2163
2169
  success: [],
2164
2170
  errors: balanceDefs.map(def => ({
@@ -2178,7 +2184,7 @@ const fetchBalances$5 = async ({
2178
2184
  address: def.address,
2179
2185
  networkId,
2180
2186
  tokenId: def.token.id,
2181
- source: MODULE_TYPE$5,
2187
+ source: MODULE_TYPE$6,
2182
2188
  status: "live",
2183
2189
  values: [{
2184
2190
  type: "free",
@@ -2197,7 +2203,7 @@ const fetchBalances$5 = async ({
2197
2203
  });
2198
2204
  };
2199
2205
 
2200
- const fetchTokens$5 = async ({
2206
+ const fetchTokens$6 = async ({
2201
2207
  networkId,
2202
2208
  tokens,
2203
2209
  connector,
@@ -2238,7 +2244,7 @@ const fetchTokens$5 = async ({
2238
2244
  const configTokenByAssetId = lodashEs.keyBy(tokens, t => t.assetId);
2239
2245
  return allTokens.map(asset => ({
2240
2246
  id: chaindataProvider.subAssetTokenId(networkId, String(asset.assetId)),
2241
- type: MODULE_TYPE$5,
2247
+ type: MODULE_TYPE$6,
2242
2248
  platform: "polkadot",
2243
2249
  networkId,
2244
2250
  assetId: String(asset.assetId),
@@ -2269,6 +2275,374 @@ const fetchTokens$5 = async ({
2269
2275
  });
2270
2276
  };
2271
2277
 
2278
+ const MODULE_TYPE$5 = chaindataProvider.SubDTaoTokenSchema.shape.type.value;
2279
+ const PLATFORM$5 = chaindataProvider.SubDTaoTokenSchema.shape.platform.value;
2280
+
2281
+ const TAO_DECIMALS = 9n;
2282
+
2283
+ // manipulating price as bigint requires using at least as many decimals as TAO itself
2284
+ const ALPHA_PRICE_SCALE = 10n ** TAO_DECIMALS;
2285
+ const getScaledAlphaPrice = (alphaIn, taoIn) => {
2286
+ if (!alphaIn || !taoIn) return 0n;
2287
+ return taoIn * ALPHA_PRICE_SCALE / alphaIn;
2288
+ };
2289
+ const alphaToTao = (alpha, scaledAlphaPrice) => {
2290
+ if (!alpha || !scaledAlphaPrice) return 0n;
2291
+ return alpha * scaledAlphaPrice / ALPHA_PRICE_SCALE;
2292
+ };
2293
+ const taoToAlpha = (tao, scaledAlphaPrice) => {
2294
+ if (!tao || !scaledAlphaPrice) return 0n;
2295
+ return tao * ALPHA_PRICE_SCALE / scaledAlphaPrice;
2296
+ };
2297
+
2298
+ const fetchBalances$5 = async ({
2299
+ networkId,
2300
+ tokensWithAddresses,
2301
+ connector,
2302
+ miniMetadata
2303
+ }) => {
2304
+ if (!tokensWithAddresses.length) return {
2305
+ success: [],
2306
+ errors: []
2307
+ };
2308
+ const balanceDefs = getBalanceDefs(tokensWithAddresses);
2309
+ if (!miniMetadata?.data) {
2310
+ log.warn(`MiniMetadata is required for fetching ${MODULE_TYPE$5} balances on ${networkId}.`, {
2311
+ tokensWithAddresses
2312
+ });
2313
+ return {
2314
+ success: [],
2315
+ errors: balanceDefs.map(def => ({
2316
+ tokenId: def.token.id,
2317
+ address: def.address,
2318
+ error: new Error("Minimetadata is required for fetching balances")
2319
+ }))
2320
+ };
2321
+ }
2322
+ if (miniMetadata.source !== MODULE_TYPE$5) {
2323
+ log.warn(`Ignoring miniMetadata with source ${miniMetadata.source} in ${MODULE_TYPE$5}.`);
2324
+ return {
2325
+ success: [],
2326
+ errors: balanceDefs.map(def => ({
2327
+ tokenId: def.token.id,
2328
+ address: def.address,
2329
+ error: new Error(`Invalid request: miniMetadata source is not ${MODULE_TYPE$5}`)
2330
+ }))
2331
+ };
2332
+ }
2333
+ if (miniMetadata.chainId !== networkId) {
2334
+ log.warn(`Ignoring miniMetadata with chainId ${miniMetadata.chainId} in ${MODULE_TYPE$5}. Expected chainId is ${networkId}`);
2335
+ return {
2336
+ success: [],
2337
+ errors: balanceDefs.map(def => ({
2338
+ tokenId: def.token.id,
2339
+ address: def.address,
2340
+ error: new Error(`Invalid request: Expected chainId is ${networkId}`)
2341
+ }))
2342
+ };
2343
+ }
2344
+ const addresses = lodashEs.uniq(balanceDefs.map(def => def.address));
2345
+ try {
2346
+ const [stakeInfos, dynamicInfos] = await Promise.all([fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "StakeInfoRuntimeApi", "get_stake_info_for_coldkeys", [addresses]), fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "SubnetInfoRuntimeApi", "get_all_dynamic_info", [])]);
2347
+ const dynamicInfoByNetuid = lodashEs.keyBy(dynamicInfos.filter(util.isNotNil), info => info.netuid);
2348
+ const balances = stakeInfos.flatMap(([address, stakes]) => stakes.map(stake => {
2349
+ const dynamicInfo = dynamicInfoByNetuid[stake.netuid];
2350
+ const scaledAlphaPrice = dynamicInfo ? getScaledAlphaPrice(dynamicInfo.alpha_in, dynamicInfo.tao_in) : 0n;
2351
+ return {
2352
+ address,
2353
+ tokenId: chaindataProvider.subDTaoTokenId(networkId, stake.netuid, stake.hotkey),
2354
+ baseTokenId: chaindataProvider.subDTaoTokenId(networkId, stake.netuid),
2355
+ stake: stake.stake,
2356
+ hotkey: stake.hotkey,
2357
+ netuid: stake.netuid,
2358
+ scaledAlphaPrice
2359
+ };
2360
+ }));
2361
+ const tokensById = lodashEs.keyBy(tokensWithAddresses.map(([token]) => token), t => t.id);
2362
+ const dynamicTokens = [];
2363
+
2364
+ // identify tokens that were not requested but have balances
2365
+ // BalanceProvider will be register them in ChaindataProvider at runtime, so they will be requested on next call
2366
+ for (const bal of balances) {
2367
+ if (!balanceDefs.some(def => def.token.id === bal.tokenId)) {
2368
+ const baseToken = tokensById[bal.baseTokenId];
2369
+ // define a token specific to this staking hotkey
2370
+ if (baseToken) {
2371
+ const cleanToken = chaindataProvider.getCleanToken(baseToken);
2372
+ const newToken = chaindataProvider.TokenSchema.parse({
2373
+ ...cleanToken,
2374
+ id: bal.tokenId,
2375
+ hotkey: bal.hotkey
2376
+ });
2377
+ dynamicTokens.push(newToken);
2378
+ }
2379
+ }
2380
+ }
2381
+ const success = balanceDefs.map(def => {
2382
+ const stake = balances.find(b => b.address === def.address && b.tokenId === def.token.id);
2383
+ const meta = {
2384
+ scaledAlphaPrice: stake?.scaledAlphaPrice.toString() ?? "0"
2385
+ };
2386
+ const balanceValue = {
2387
+ type: "free",
2388
+ label: stake?.netuid === 0 ? "Root Staking" : `Subnet Staking`,
2389
+ amount: stake?.stake.toString() ?? "0",
2390
+ meta
2391
+ };
2392
+ return {
2393
+ address: def.address,
2394
+ networkId,
2395
+ tokenId: def.token.id,
2396
+ source: MODULE_TYPE$5,
2397
+ status: "live",
2398
+ values: [balanceValue]
2399
+ };
2400
+ });
2401
+ return {
2402
+ success,
2403
+ errors: [],
2404
+ dynamicTokens
2405
+ };
2406
+ } catch (err) {
2407
+ log.warn("Failed to fetch balances for substrate-dtao", {
2408
+ err
2409
+ });
2410
+ const errors = balanceDefs.map(def => ({
2411
+ tokenId: def.token.id,
2412
+ address: def.address,
2413
+ error: new Error(`Failed to fetch balance for ${def.address} on ${networkId}`)
2414
+ }));
2415
+ return {
2416
+ success: [],
2417
+ errors
2418
+ };
2419
+ }
2420
+ };
2421
+
2422
+ // hardcoded because we dont have access to native tokens from the balance module
2423
+ const NATIVE_TOKEN_SYMBOLS = {
2424
+ "bittensor": "TAO",
2425
+ "bittensor-testnet": "testTAO"
2426
+ };
2427
+ const fetchTokens$5 = async ({
2428
+ networkId,
2429
+ connector,
2430
+ tokens,
2431
+ miniMetadata
2432
+ }) => {
2433
+ const anyMiniMetadata = miniMetadata;
2434
+ if (!anyMiniMetadata?.data) return [];
2435
+ const dynamicInfos = await fetchRuntimeCallResult(connector, networkId, anyMiniMetadata.data, "SubnetInfoRuntimeApi", "get_all_dynamic_info", []);
2436
+ return dynamicInfos.filter(util.isNotNil).map(info => {
2437
+ const config = tokens.find(t => t.netuid === info.netuid);
2438
+ let symbol = new TextDecoder().decode(Uint8Array.from(info.token_symbol));
2439
+ const subnetName = info.subnet_identity?.subnet_name?.asText() ?? (info.netuid === 0 ? "Root" : `Subnet ${info.netuid}`);
2440
+ const name = `SN${info.netuid} | ${subnetName} ${symbol}`;
2441
+
2442
+ // for root we want same symbol as native so they can be grouped together in portfolio
2443
+ if (info.netuid === 0 && NATIVE_TOKEN_SYMBOLS[networkId]) symbol = NATIVE_TOKEN_SYMBOLS[networkId];
2444
+ return Object.assign({}, {
2445
+ id: chaindataProvider.subDTaoTokenId(networkId, info.netuid),
2446
+ type: MODULE_TYPE$5,
2447
+ platform: PLATFORM$5,
2448
+ networkId,
2449
+ netuid: info.netuid,
2450
+ isDefault: true,
2451
+ symbol,
2452
+ decimals: 9,
2453
+ name,
2454
+ subnetName
2455
+ }, config);
2456
+ }).filter(t => {
2457
+ const parsed = chaindataProvider.SubDTaoTokenSchema.safeParse(t);
2458
+ return parsed.success;
2459
+ });
2460
+ };
2461
+
2462
+ const getMiniMetadata$6 = ({
2463
+ networkId,
2464
+ specVersion,
2465
+ metadataRpc
2466
+ }) => {
2467
+ const source = MODULE_TYPE$5;
2468
+ const chainId = networkId;
2469
+ const systemVersion = getConstantValue(metadataRpc, "System", "Version");
2470
+ if (specVersion !== systemVersion.spec_version) throw new Error(`specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`);
2471
+ const id = deriveMiniMetadataId({
2472
+ source,
2473
+ chainId,
2474
+ specVersion
2475
+ });
2476
+ const {
2477
+ unifiedMetadata
2478
+ } = scale.parseMetadataRpc(metadataRpc);
2479
+ if (unifiedMetadata.version < 14) throw new Error(`Unsupported metadata version: ${unifiedMetadata.version}. Minimum required is 14.`);
2480
+ return {
2481
+ id,
2482
+ source,
2483
+ chainId,
2484
+ specVersion,
2485
+ version: chaindataProvider.MINIMETADATA_VERSION,
2486
+ data: getData$4(metadataRpc),
2487
+ extra: null
2488
+ };
2489
+ };
2490
+ const getData$4 = metadataRpc => {
2491
+ const {
2492
+ metadata,
2493
+ unifiedMetadata
2494
+ } = scale.parseMetadataRpc(metadataRpc);
2495
+ const isBittensor = unifiedMetadata.pallets.some(({
2496
+ name
2497
+ }) => name === "SubtensorModule");
2498
+ if (!isBittensor) return null;
2499
+ scale.compactMetadata(metadata, [
2500
+ // { pallet: "SubtensorModule", items: ["StakingHotkeys", "Stake"] }
2501
+ ], [{
2502
+ runtimeApi: "StakeInfoRuntimeApi",
2503
+ methods: ["get_stake_info_for_coldkeys"]
2504
+ }, {
2505
+ runtimeApi: "SubnetInfoRuntimeApi",
2506
+ methods: ["get_all_dynamic_info"]
2507
+ }]);
2508
+ return scale.encodeMetadata(metadata);
2509
+ };
2510
+
2511
+ const getTransferCallData$6 = ({
2512
+ from,
2513
+ to,
2514
+ value,
2515
+ token,
2516
+ metadataRpc
2517
+ }) => {
2518
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$5)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$5}.`);
2519
+ const {
2520
+ netuid: subnetId,
2521
+ hotkey
2522
+ } = chaindataProvider.parseSubDTaoTokenId(token.id);
2523
+ if (!hotkey) throw new Error(`Missing hotkey`);
2524
+ const {
2525
+ builder
2526
+ } = scale.parseMetadataRpc(metadataRpc);
2527
+ const {
2528
+ codec,
2529
+ location
2530
+ } = builder.buildCall("SubtensorModule", "transfer_stake");
2531
+ const args = codec.enc({
2532
+ origin_netuid: subnetId,
2533
+ hotkey,
2534
+ destination_coldkey: to,
2535
+ destination_netuid: subnetId,
2536
+ alpha_amount: value
2537
+ });
2538
+ const callData = polkadotApi.Binary.fromBytes(utils.mergeUint8([new Uint8Array(location), args]));
2539
+ return {
2540
+ address: from,
2541
+ method: callData.asHex()
2542
+ };
2543
+ };
2544
+
2545
+ const SUBSCRIPTION_INTERVAL$2 = 6_000;
2546
+ const subscribeBalances$6 = ({
2547
+ networkId,
2548
+ tokensWithAddresses,
2549
+ connector,
2550
+ miniMetadata
2551
+ }) => {
2552
+ if (!tokensWithAddresses.length) return rxjs.of({
2553
+ success: [],
2554
+ errors: []
2555
+ });
2556
+ return new rxjs.Observable(subscriber => {
2557
+ const abortController = new AbortController();
2558
+
2559
+ // on hydration balances are fetched using a runtimeApi, which can't be subscribed to.
2560
+ // => poll values for each block
2561
+ const poll = async () => {
2562
+ try {
2563
+ if (abortController.signal.aborted) return;
2564
+ const balances = await fetchBalances$5({
2565
+ networkId,
2566
+ tokensWithAddresses: tokensWithAddresses,
2567
+ connector,
2568
+ miniMetadata
2569
+ });
2570
+ if (abortController.signal.aborted) return;
2571
+ subscriber.next(balances);
2572
+ setTimeout(poll, SUBSCRIPTION_INTERVAL$2);
2573
+ } catch (error) {
2574
+ log.error("Error", {
2575
+ module: MODULE_TYPE$5,
2576
+ networkId,
2577
+ miniMetadata,
2578
+ addressesByToken: tokensWithAddresses,
2579
+ error
2580
+ });
2581
+ subscriber.error(error);
2582
+ }
2583
+ };
2584
+ poll();
2585
+ return () => {
2586
+ abortController.abort();
2587
+ };
2588
+ }).pipe(rxjs.distinctUntilChanged(lodashEs.isEqual));
2589
+ };
2590
+
2591
+ const SubDTaoBalanceModule = {
2592
+ type: MODULE_TYPE$5,
2593
+ platform: PLATFORM$5,
2594
+ getMiniMetadata: getMiniMetadata$6,
2595
+ fetchTokens: fetchTokens$5,
2596
+ fetchBalances: fetchBalances$5,
2597
+ subscribeBalances: subscribeBalances$6,
2598
+ getTransferCallData: getTransferCallData$6
2599
+ };
2600
+
2601
+ // to be used by chaindata too
2602
+ const SubDTaoTokenConfigSchema = z__default.default.strictObject({
2603
+ netuid: chaindataProvider.SubDTaoTokenSchema.shape.netuid,
2604
+ ...TokenConfigBaseSchema.shape
2605
+ });
2606
+
2607
+ const ONE_ALPHA = 10n ** TAO_DECIMALS;
2608
+
2609
+ /**
2610
+ * To be used for tokens that don't have a coingecko id
2611
+ *
2612
+ * @param token
2613
+ * @param tokenRates
2614
+ * @param scaledAlphaPrice
2615
+ * @returns
2616
+ */
2617
+ const getDTaoTokenRates = (token, tokenRates$1, scaledAlphaPrice) => {
2618
+ try {
2619
+ const taoTokenId = chaindataProvider.subNativeTokenId(token.networkId);
2620
+ const taoTokenRates = tokenRates$1[taoTokenId];
2621
+ if (!taoTokenRates) return null;
2622
+
2623
+ // for root subnet, same rates as TAO
2624
+ if (token.netuid === 0) return structuredClone(taoTokenRates);
2625
+ const alphaRates = tokenRates.newTokenRates();
2626
+ for (const [currency, taoRate] of Object.entries(taoTokenRates)) {
2627
+ if (!taoRate) {
2628
+ alphaRates[currency] = null;
2629
+ } else {
2630
+ const taoPrice = alphaToTao(ONE_ALPHA, BigInt(scaledAlphaPrice));
2631
+ const priceRatio = Number(taoPrice) / Number(ALPHA_PRICE_SCALE);
2632
+ alphaRates[currency] = {
2633
+ price: taoRate.price * priceRatio,
2634
+ marketCap: taoRate.marketCap ? taoRate.marketCap * priceRatio : undefined,
2635
+ change24h: undefined // cannot be determined from TAO rates alone
2636
+ };
2637
+ }
2638
+ }
2639
+ return alphaRates;
2640
+ } catch (err) {
2641
+ log.error(err);
2642
+ return null;
2643
+ }
2644
+ };
2645
+
2272
2646
  function excludeFromTransferableAmount(locks) {
2273
2647
  if (typeof locks === "string") return BigInt(locks);
2274
2648
  if (!Array.isArray(locks)) locks = [locks];
@@ -2597,6 +2971,16 @@ class Balance {
2597
2971
  return lpTokenRates;
2598
2972
  }
2599
2973
 
2974
+ // dTAO balances need to be converted to the native token to compute their rate, unless we have a coingeckoId
2975
+ if (this.token?.type === "substrate-dtao" && !this.token.coingeckoId) {
2976
+ if (!this.#db?.tokenRates) return null;
2977
+ const balances = this.#valueGetter.get("free");
2978
+ if (!balances.length) return null;
2979
+ const balanceMeta = balances[0].meta;
2980
+ if (!balanceMeta?.scaledAlphaPrice) return null;
2981
+ return getDTaoTokenRates(this.token, this.#db.tokenRates, balanceMeta.scaledAlphaPrice);
2982
+ }
2983
+
2600
2984
  // other tokens can just pick from the tokenRates db using the tokenId
2601
2985
  return this.#db?.tokenRates && this.#db.tokenRates[this.tokenId] || null;
2602
2986
  }
@@ -2643,9 +3027,7 @@ class Balance {
2643
3027
  const nomPoolStakedPlancks = this.locks.some(lock => lock.source === "substrate-native-holds" && lock.label === "DelegatedStaking") ? 0n : this.nompools.map(({
2644
3028
  amount
2645
3029
  }) => amount.planck).reduce((a, b) => a + b, 0n);
2646
- return this.#format(this.free.planck + this.reserved.planck + nomPoolStakedPlancks + this.subtensor.map(({
2647
- amount
2648
- }) => amount.planck).reduce((a, b) => a + b, 0n) + includeInTotalExtraAmount(extra));
3030
+ return this.#format(this.free.planck + this.reserved.planck + nomPoolStakedPlancks + includeInTotalExtraAmount(extra));
2649
3031
  }
2650
3032
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
2651
3033
  get free() {
@@ -2682,9 +3064,6 @@ class Balance {
2682
3064
  get nompools() {
2683
3065
  return this.getValue("nompool");
2684
3066
  }
2685
- get subtensor() {
2686
- return this.getValue("subtensor");
2687
- }
2688
3067
 
2689
3068
  /** The extra balance of this token */
2690
3069
  get extra() {
@@ -2757,8 +3136,7 @@ class Balance {
2757
3136
  const nomPoolStakedPlancks = this.locks.some(lock => lock.source === "substrate-native-holds" && lock.label === "DelegatedStaking") ? 0n : this.nompools.map(({
2758
3137
  amount
2759
3138
  }) => amount.planck).reduce((a, b) => a + b, 0n);
2760
- const otherUnavailable = nomPoolStakedPlancks + this.subtensor.reduce((total, each) => total + each.amount.planck, 0n);
2761
- return this.#format(baseUnavailable + otherUnavailable);
3139
+ return this.#format(baseUnavailable + nomPoolStakedPlancks);
2762
3140
  }
2763
3141
 
2764
3142
  /** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
@@ -3005,13 +3383,6 @@ const getValueId = amount => {
3005
3383
  const meta = amount.meta;
3006
3384
  if (!meta) return "";
3007
3385
  if (amount.type === "nompool") return meta.poolId?.toString() ?? "";
3008
- if (amount.type === "subtensor") {
3009
- const {
3010
- hotkey,
3011
- netuid
3012
- } = meta;
3013
- if (hotkey && netuid !== undefined) return `${hotkey.toString()}${netuid.toString()}`;
3014
- }
3015
3386
  return "";
3016
3387
  };
3017
3388
  return [amount.label, amount.type, amount.source, getMetaId()].join("::");
@@ -3033,7 +3404,7 @@ const getMiniMetadata$5 = ({
3033
3404
  specVersion,
3034
3405
  metadataRpc
3035
3406
  }) => {
3036
- const source = MODULE_TYPE$5;
3407
+ const source = MODULE_TYPE$6;
3037
3408
  const chainId = networkId;
3038
3409
  const systemVersion = getConstantValue(metadataRpc, "System", "Version");
3039
3410
  if (specVersion !== systemVersion.spec_version) throw new Error(`specVersion mismatch: expected ${specVersion}, metadata got ${systemVersion.spec_version}`);
@@ -3079,7 +3450,7 @@ const getTransferCallData$5 = ({
3079
3450
  type,
3080
3451
  metadataRpc
3081
3452
  }) => {
3082
- if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$5)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$5}.`);
3453
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
3083
3454
  const {
3084
3455
  builder
3085
3456
  } = scale.parseMetadataRpc(metadataRpc);
@@ -3096,6 +3467,7 @@ const getTransferCallData$5 = ({
3096
3467
  };
3097
3468
  };
3098
3469
  const getTransferMethod$3 = type => {
3470
+ // TODO handle the case where transfer_all does not exist
3099
3471
  switch (type) {
3100
3472
  case "keep-alive":
3101
3473
  return "transfer_keep_alive";
@@ -3141,6 +3513,11 @@ const getTransferEncodedArgs$2 = (assetId, to, value, codec) => {
3141
3513
  // for Astar
3142
3514
  target: polkadotApi.Enum("Id", to),
3143
3515
  amount: BigInt(value)
3516
+ }), () => ({
3517
+ id: BigInt(assetId),
3518
+ // for Neuroweb
3519
+ target: to,
3520
+ amount: BigInt(value)
3144
3521
  })]);
3145
3522
  };
3146
3523
  const getTransferAllEncodedArgs$2 = (assetId, to, codec) => {
@@ -3154,6 +3531,11 @@ const getTransferAllEncodedArgs$2 = (assetId, to, codec) => {
3154
3531
  // for Astar
3155
3532
  dest: polkadotApi.Enum("Id", to),
3156
3533
  keep_alive: false
3534
+ }), () => ({
3535
+ id: BigInt(assetId),
3536
+ // for Neuroweb (although transfer_all does not exist)
3537
+ dest: to,
3538
+ keep_alive: false
3157
3539
  })]);
3158
3540
  };
3159
3541
 
@@ -3176,11 +3558,11 @@ const subscribeBalances$5 = ({
3176
3558
  };
3177
3559
 
3178
3560
  const SubAssetsBalanceModule = {
3179
- type: MODULE_TYPE$5,
3180
- platform: PLATFORM$5,
3561
+ type: MODULE_TYPE$6,
3562
+ platform: PLATFORM$6,
3181
3563
  getMiniMetadata: getMiniMetadata$5,
3182
- fetchTokens: fetchTokens$5,
3183
- fetchBalances: fetchBalances$5,
3564
+ fetchTokens: fetchTokens$6,
3565
+ fetchBalances: fetchBalances$6,
3184
3566
  subscribeBalances: subscribeBalances$5,
3185
3567
  getTransferCallData: getTransferCallData$5
3186
3568
  };
@@ -3524,6 +3906,11 @@ const getTransferEncodedArgs$1 = (onChainId, to, value, codec) => {
3524
3906
  // for most networks
3525
3907
  target: polkadotApi.Enum("Id", to),
3526
3908
  amount: BigInt(value)
3909
+ }), () => ({
3910
+ id: scale.papiParse(onChainId),
3911
+ // for Neuroweb
3912
+ target: to,
3913
+ amount: BigInt(value)
3527
3914
  })]);
3528
3915
  };
3529
3916
  const getTransferAllEncodedArgs$1 = (onChainId, to, codec) => {
@@ -3532,6 +3919,11 @@ const getTransferAllEncodedArgs$1 = (onChainId, to, codec) => {
3532
3919
  // for most networks
3533
3920
  dest: polkadotApi.Enum("Id", to),
3534
3921
  keep_alive: false
3922
+ }), () => ({
3923
+ id: scale.papiParse(onChainId),
3924
+ // for Neuroweb
3925
+ dest: to,
3926
+ keep_alive: false
3535
3927
  })]);
3536
3928
  };
3537
3929
 
@@ -3891,154 +4283,6 @@ const SubHydrationBalanceModule = {
3891
4283
  const MODULE_TYPE$2 = chaindataProvider.SubNativeTokenSchema.shape.type.value;
3892
4284
  const PLATFORM$2 = chaindataProvider.SubNativeTokenSchema.shape.platform.value;
3893
4285
 
3894
- const SUBTENSOR_ROOT_NETUID = 0;
3895
- const SUBTENSOR_MIN_STAKE_AMOUNT_PLANK = 1000000n;
3896
- const TAO_DECIMALS = 9n;
3897
- const SCALE_FACTOR = 10n ** TAO_DECIMALS; // Equivalent to 10e9 for precision
3898
- const ONE_ALPHA_TOKEN = SCALE_FACTOR;
3899
- const calculateAlphaPrice = ({
3900
- dynamicInfo
3901
- }) => {
3902
- if (!dynamicInfo) return 0n;
3903
- const {
3904
- alpha_in,
3905
- tao_in
3906
- } = dynamicInfo;
3907
-
3908
- // Scale taoIn before division to preserve precision
3909
- const result = tao_in * SCALE_FACTOR / alpha_in;
3910
- return result; // Scaled price as bigint
3911
- };
3912
- const calculateTaoAmountFromAlpha = ({
3913
- alphaPrice,
3914
- alphaStaked
3915
- }) => {
3916
- if (!alphaStaked || !alphaPrice) return 0n;
3917
- const expectedAlpha = alphaStaked * alphaPrice;
3918
- return expectedAlpha / SCALE_FACTOR;
3919
- };
3920
- const calculateTaoFromDynamicInfo = ({
3921
- dynamicInfo,
3922
- alphaStaked
3923
- }) => {
3924
- const alphaPrice = calculateAlphaPrice({
3925
- dynamicInfo
3926
- });
3927
- return calculateTaoAmountFromAlpha({
3928
- alphaPrice,
3929
- alphaStaked
3930
- });
3931
- };
3932
-
3933
- // per address, lists of values to add to the native balance
3934
-
3935
- const getSubtensorStakingBalances$ = (connector, networkId, balanceDefs, miniMetadata) => {
3936
- const addresses = balanceDefs.map(def => def.address);
3937
- const token = balanceDefs[0].token;
3938
- if (!addresses.length || !token || !miniMetadata.extra.hasSubtensorPallet || !miniMetadata.data) return rxjs.of({});
3939
-
3940
- // we are only doing runtime calls, there is no way to subscribe to changes, except polling
3941
- // => start immediately, then repeat every 30 seconds
3942
- return rxjs.timer(0, 30000).pipe(rxjs.switchMap(() => rxjs.from(fetchStakeInfoByAddress(connector, networkId, miniMetadata, addresses)).pipe(rxjs.switchMap(stakeInfoByAddress => fetchStakingBalanceValuesByAddress(connector, networkId, miniMetadata, stakeInfoByAddress)))));
3943
- };
3944
- const fetchStakingBalanceValuesByAddress = async (connector, networkId, miniMetadata, stakeInfoByAddress) => {
3945
- const uniqueNetuids = lodashEs.uniq(lodashEs.values(stakeInfoByAddress).flatMap(infos => infos.map(info => info.netuid))).filter(netuid => netuid !== SUBTENSOR_ROOT_NETUID);
3946
- const dynamicInfoByNetuid = await fetchDynamicInfoByNetuid(connector, networkId, miniMetadata, uniqueNetuids);
3947
- return lodashEs.fromPairs(lodashEs.toPairs(stakeInfoByAddress).map(([address, stakeInfos]) => {
3948
- const stakesBalances = stakeInfos.filter(({
3949
- stake
3950
- }) => stake >= SUBTENSOR_MIN_STAKE_AMOUNT_PLANK).map(({
3951
- hotkey,
3952
- netuid,
3953
- stake
3954
- }) => ({
3955
- hotkey,
3956
- netuid: Number(netuid),
3957
- stake: BigInt(stake),
3958
- dynamicInfo: dynamicInfoByNetuid[Number(netuid)]
3959
- })).map(({
3960
- hotkey,
3961
- stake,
3962
- netuid,
3963
- dynamicInfo
3964
- }) => {
3965
- const {
3966
- token_symbol,
3967
- subnet_name,
3968
- subnet_identity
3969
- } = dynamicInfo ?? {};
3970
- const tokenSymbol = new TextDecoder().decode(Uint8Array.from(token_symbol ?? []));
3971
- const subnetName = new TextDecoder().decode(Uint8Array.from(subnet_name ?? []));
3972
- const subnetIdentity = subnet_identity ? lodashEs.fromPairs(lodashEs.toPairs(subnet_identity).map(([key, binary]) => [key, binary.asText()])) : undefined;
3973
-
3974
- // Add 1n balance if failed to fetch dynamic info, so the position is not ignored by Balance lib and is displayed in the UI.
3975
- const alphaStakedInTao = dynamicInfo ? calculateTaoFromDynamicInfo({
3976
- dynamicInfo,
3977
- alphaStaked: stake
3978
- }) : 1n;
3979
- const alphaToTaoRate = calculateTaoFromDynamicInfo({
3980
- dynamicInfo: dynamicInfo ?? null,
3981
- alphaStaked: ONE_ALPHA_TOKEN
3982
- }).toString();
3983
- const stakeByNetuid = Number(netuid) === SUBTENSOR_ROOT_NETUID ? stake : alphaStakedInTao;
3984
- const balanceValue = {
3985
- source: "subtensor-staking",
3986
- type: "subtensor",
3987
- label: "subtensor-staking",
3988
- amount: stakeByNetuid.toString(),
3989
- meta: {
3990
- type: "subtensor-staking",
3991
- hotkey,
3992
- netuid,
3993
- amountStaked: stake.toString(),
3994
- alphaToTaoRate,
3995
- dynamicInfo: {
3996
- tokenSymbol,
3997
- subnetName,
3998
- subnetIdentity: {
3999
- ...subnetIdentity,
4000
- subnetName: subnetIdentity?.subnet_name || subnetName
4001
- }
4002
- }
4003
- }
4004
- };
4005
- return balanceValue;
4006
- });
4007
- return [address, stakesBalances];
4008
- }));
4009
- };
4010
- const fetchStakeInfoByAddress = async (connector, networkId, miniMetadata, addresses) => {
4011
- const pairs = await Promise.all(addresses.map(async address => [address, await viem.withRetry(() => fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "StakeInfoRuntimeApi", "get_stake_info_for_coldkey", [address]), {
4012
- delay: 500,
4013
- retryCount: 3
4014
- })]));
4015
- return lodashEs.fromPairs(pairs);
4016
- };
4017
-
4018
- // assume dynamic info doesnt change over the course of a browser session
4019
- const dynamicInfoCache = new Map();
4020
- const getCacheKey$1 = (networkId, netuid) => `${networkId}:${netuid}`;
4021
- const fetchDynamicInfoByNetuid = async (connector, networkId, miniMetadata, uniqueNetuids) => {
4022
- const fetchInfo = async netuid => {
4023
- if (netuid === SUBTENSOR_ROOT_NETUID) return null;
4024
- const cacheKey = getCacheKey$1(networkId, netuid);
4025
- if (!dynamicInfoCache.has(cacheKey)) {
4026
- await viem.withRetry(async () => {
4027
- const result = await fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "SubnetInfoRuntimeApi", "get_dynamic_info", [netuid]);
4028
- dynamicInfoCache.set(cacheKey, result); // Cache successful response
4029
-
4030
- return result;
4031
- }, {
4032
- delay: 500,
4033
- retryCount: 3
4034
- });
4035
- }
4036
- return dynamicInfoCache.get(cacheKey) ?? null;
4037
- };
4038
- const results = await Promise.all(uniqueNetuids.map(async netuid => [netuid, await fetchInfo(netuid)]));
4039
- return lodashEs.fromPairs(results);
4040
- };
4041
-
4042
4286
  const getOtherType = input => `other-${input}`;
4043
4287
 
4044
4288
  /**
@@ -4479,17 +4723,6 @@ const fetchBalances$2 = async ({
4479
4723
  // now for each balance that includes nomPoolStaking, we need to fetch the metadata for the pool
4480
4724
  const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
4481
4725
  const balances = await fetchRpcQueryPack(connector, networkId, nomPoolQueries);
4482
-
4483
- // TODO ⚠️ dedupe locks
4484
-
4485
- const subtensorBalances$ = getSubtensorStakingBalances$(connector, networkId, balanceDefs, miniMetadata);
4486
- const subtensorBalancesByAddress = await rxjs.firstValueFrom(subtensorBalances$);
4487
- for (const [address, subtensorBalances] of Object.entries(subtensorBalancesByAddress)) {
4488
- const balance = balances.find(b => b.address === address);
4489
- if (balance?.values) balance.values = [...balance.values.filter(({
4490
- source
4491
- }) => source !== "subtensor-staking"), ...subtensorBalances];
4492
- }
4493
4726
  return {
4494
4727
  success: balances,
4495
4728
  errors: []
@@ -4578,7 +4811,6 @@ const getMiniMetadata$2 = ({
4578
4811
  };
4579
4812
  const existentialDeposit = tryGetConstantValue(metadataRpc, "Balances", "ExistentialDeposit")?.toString();
4580
4813
  const nominationPoolsPalletId = tryGetConstantValue(metadataRpc, "NominationPools", "PalletId")?.asText();
4581
- const hasSubtensorPallet = !!tryGetConstantValue(metadataRpc, "SubtensorModule", "KeySwapCost");
4582
4814
  const hasFreezesItem = Boolean(unifiedMetadata.pallets.find(({
4583
4815
  name
4584
4816
  }) => name === "Balances")?.storage?.items.find(({
@@ -4598,15 +4830,6 @@ const getMiniMetadata$2 = ({
4598
4830
  }, {
4599
4831
  pallet: "Staking",
4600
4832
  items: ["Ledger"]
4601
- }, {
4602
- pallet: "SubtensorModule",
4603
- items: ["StakingHotkeys", "Stake"]
4604
- }], [{
4605
- runtimeApi: "StakeInfoRuntimeApi",
4606
- methods: ["get_stake_info_for_coldkey"]
4607
- }, {
4608
- runtimeApi: "SubnetInfoRuntimeApi",
4609
- methods: ["get_dynamic_info"]
4610
4833
  }]);
4611
4834
  return {
4612
4835
  id,
@@ -4618,8 +4841,7 @@ const getMiniMetadata$2 = ({
4618
4841
  extra: {
4619
4842
  useLegacyTransferableCalculation,
4620
4843
  existentialDeposit,
4621
- nominationPoolsPalletId,
4622
- hasSubtensorPallet
4844
+ nominationPoolsPalletId
4623
4845
  }
4624
4846
  };
4625
4847
  };
@@ -4729,19 +4951,12 @@ const subscribeBalances$2 = ({
4729
4951
  // could be use as shared observable key if we decide to cache the sub
4730
4952
  const balanceDefs = getBalanceDefs(tokensWithAddresses);
4731
4953
  const baseQueries = buildBaseQueries(networkId, balanceDefs, miniMetadata);
4732
- const baseBalances$ = getRpcQueryPack$(connector, networkId, baseQueries).pipe(rxjs.switchMap(partialBalances => {
4954
+ return getRpcQueryPack$(connector, networkId, baseQueries).pipe(rxjs.switchMap(partialBalances => {
4733
4955
  // now for each balance that includes nomPoolStaking, we need to fetch the metadata for the pool
4734
4956
  const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
4735
4957
  return getRpcQueryPack$(connector, networkId, nomPoolQueries);
4736
- }));
4737
- const subtensorBalancesByAddress$ = getSubtensorStakingBalances$(connector, networkId, balanceDefs, miniMetadata);
4738
- return rxjs.combineLatest([baseBalances$, subtensorBalancesByAddress$]).pipe(rxjs.map(([baseBalances, subtensorBalancesByAddress]) => ({
4739
- success: [...baseBalances.map(b => ({
4740
- ...b,
4741
- values: [...(b.values?.filter(({
4742
- source
4743
- }) => source !== "subtensor-staking") ?? []), ...(subtensorBalancesByAddress[b.address] ?? [])]
4744
- }))],
4958
+ }), rxjs.map(balances => ({
4959
+ success: balances,
4745
4960
  errors: []
4746
4961
  })));
4747
4962
  };
@@ -4773,8 +4988,7 @@ const SubNativeMiniMetadataExtraSchema = z__default.default.strictObject({
4773
4988
  disable: z__default.default.boolean().optional(),
4774
4989
  useLegacyTransferableCalculation: z__default.default.boolean().optional(),
4775
4990
  existentialDeposit: z__default.default.string().optional(),
4776
- nominationPoolsPalletId: z__default.default.string().optional(),
4777
- hasSubtensorPallet: z__default.default.boolean().optional()
4991
+ nominationPoolsPalletId: z__default.default.string().optional()
4778
4992
  });
4779
4993
 
4780
4994
  // Do not use this type outside of this module
@@ -6577,7 +6791,7 @@ const SubTokensMiniMetadataExtraSchema = z__default.default.strictObject({
6577
6791
  palletId: z__default.default.string()
6578
6792
  });
6579
6793
 
6580
- const BALANCE_MODULES = [SubNativeBalanceModule, SubAssetsBalanceModule, SubHydrationBalanceModule, SubForeignAssetsBalanceModule, SubPsp22BalanceModule, SubTokensBalanceModule, EvmErc20BalanceModule, EvmUniswapV2BalanceModule, EvmNativeBalanceModule, SolNativeBalanceModule, SolSplBalanceModule];
6794
+ const BALANCE_MODULES = [SubNativeBalanceModule, SubAssetsBalanceModule, SubDTaoBalanceModule, SubHydrationBalanceModule, SubForeignAssetsBalanceModule, SubPsp22BalanceModule, SubTokensBalanceModule, EvmErc20BalanceModule, EvmUniswapV2BalanceModule, EvmNativeBalanceModule, SolNativeBalanceModule, SolSplBalanceModule];
6581
6795
 
6582
6796
  // share requests as all modules will call this at once
6583
6797
  const CACHE$1 = new Map();
@@ -6819,7 +7033,12 @@ class BalancesProvider {
6819
7033
  miniMetadata: miniMetadata
6820
7034
  })), rxjs.catchError(() => rxjs.EMPTY),
6821
7035
  // don't emit, let provider mark balances stale
6822
- rxjs.map(results => ({
7036
+ rxjs.tap(results => {
7037
+ if (results.dynamicTokens?.length) {
7038
+ // register missing tokens in the chaindata provider
7039
+ this.#chaindataProvider.registerDynamicTokens(results.dynamicTokens);
7040
+ }
7041
+ }), rxjs.map(results => ({
6823
7042
  status: "live",
6824
7043
  // exclude zero balances
6825
7044
  balances: results.success.filter(b => new Balance(b).total.planck > 0n)
@@ -7091,6 +7310,7 @@ Object.defineProperty(exports, "MINIMETADATA_VERSION", {
7091
7310
  enumerable: true,
7092
7311
  get: function () { return chaindataProvider.MINIMETADATA_VERSION; }
7093
7312
  });
7313
+ exports.ALPHA_PRICE_SCALE = ALPHA_PRICE_SCALE;
7094
7314
  exports.BALANCE_MODULES = BALANCE_MODULES;
7095
7315
  exports.Balance = Balance;
7096
7316
  exports.BalanceFormatter = BalanceFormatter;
@@ -7105,17 +7325,15 @@ exports.EvmNativeTokenConfigSchema = EvmNativeTokenConfigSchema;
7105
7325
  exports.EvmUniswapV2BalanceModule = EvmUniswapV2BalanceModule;
7106
7326
  exports.EvmUniswapV2TokenConfigSchema = EvmUniswapV2TokenConfigSchema;
7107
7327
  exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
7108
- exports.ONE_ALPHA_TOKEN = ONE_ALPHA_TOKEN;
7109
7328
  exports.PlanckSumBalancesFormatter = PlanckSumBalancesFormatter;
7110
- exports.SCALE_FACTOR = SCALE_FACTOR;
7111
- exports.SUBTENSOR_MIN_STAKE_AMOUNT_PLANK = SUBTENSOR_MIN_STAKE_AMOUNT_PLANK;
7112
- exports.SUBTENSOR_ROOT_NETUID = SUBTENSOR_ROOT_NETUID;
7113
7329
  exports.SolNativeBalanceModule = SolNativeBalanceModule;
7114
7330
  exports.SolNativeTokenConfigSchema = SolNativeTokenConfigSchema;
7115
7331
  exports.SolSplBalanceModule = SolSplBalanceModule;
7116
7332
  exports.SolSplTokenConfigSchema = SolSplTokenConfigSchema;
7117
7333
  exports.SubAssetsBalanceModule = SubAssetsBalanceModule;
7118
7334
  exports.SubAssetsTokenConfigSchema = SubAssetsTokenConfigSchema;
7335
+ exports.SubDTaoBalanceModule = SubDTaoBalanceModule;
7336
+ exports.SubDTaoTokenConfigSchema = SubDTaoTokenConfigSchema;
7119
7337
  exports.SubForeignAssetsBalanceModule = SubForeignAssetsBalanceModule;
7120
7338
  exports.SubForeignAssetsTokenConfigSchema = SubForeignAssetsTokenConfigSchema;
7121
7339
  exports.SubHydrationBalanceModule = SubHydrationBalanceModule;
@@ -7131,10 +7349,9 @@ exports.SubTokensMiniMetadataExtraSchema = SubTokensMiniMetadataExtraSchema;
7131
7349
  exports.SubTokensModuleConfigSchema = SubTokensModuleConfigSchema;
7132
7350
  exports.SubTokensTokenConfigSchema = SubTokensTokenConfigSchema;
7133
7351
  exports.SumBalancesFormatter = SumBalancesFormatter;
7352
+ exports.TAO_DECIMALS = TAO_DECIMALS;
7134
7353
  exports.abiMulticall = abiMulticall;
7135
- exports.calculateAlphaPrice = calculateAlphaPrice;
7136
- exports.calculateTaoAmountFromAlpha = calculateTaoAmountFromAlpha;
7137
- exports.calculateTaoFromDynamicInfo = calculateTaoFromDynamicInfo;
7354
+ exports.alphaToTao = alphaToTao;
7138
7355
  exports.deriveMiniMetadataId = deriveMiniMetadataId;
7139
7356
  exports.erc20BalancesAggregatorAbi = erc20BalancesAggregatorAbi;
7140
7357
  exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
@@ -7142,8 +7359,11 @@ exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
7142
7359
  exports.filterBaseLocks = filterBaseLocks;
7143
7360
  exports.filterMirrorTokens = filterMirrorTokens;
7144
7361
  exports.getBalanceId = getBalanceId;
7362
+ exports.getDTaoTokenRates = getDTaoTokenRates;
7145
7363
  exports.getLockTitle = getLockTitle;
7146
7364
  exports.getLockedType = getLockedType;
7365
+ exports.getScaledAlphaPrice = getScaledAlphaPrice;
7147
7366
  exports.getValueId = getValueId;
7148
7367
  exports.includeInTotalExtraAmount = includeInTotalExtraAmount;
7368
+ exports.taoToAlpha = taoToAlpha;
7149
7369
  exports.uniswapV2PairAbi = uniswapV2PairAbi;