@talismn/balances 0.0.0-pr2043-20250619072437 → 0.0.0-pr2043-20250619151012
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/declarations/src/BalanceModule.d.ts +7 -3
- package/dist/declarations/src/getMiniMetadata/index.d.ts +2 -1
- package/dist/declarations/src/modules/SubstrateAssetsModule.d.ts +2 -4
- package/dist/declarations/src/modules/SubstrateForeignAssetsModule.d.ts +2 -4
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeCrowdloans.d.ts +1 -1
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeNompoolStaking.d.ts +1 -1
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeSubtensorStaking.d.ts +1 -1
- package/dist/declarations/src/modules/SubstrateNativeModule/types.d.ts +3 -4
- package/dist/declarations/src/modules/SubstrateNativeModule/util/QueryCache.d.ts +4 -4
- package/dist/declarations/src/modules/SubstrateNativeModule/util/buildQueries.d.ts +3 -2
- package/dist/declarations/src/modules/SubstrateTokensModule.d.ts +3 -4
- package/dist/declarations/src/modules/index.d.ts +5 -17
- package/dist/declarations/src/modules/util/buildStorageCoders.d.ts +3 -4
- package/dist/declarations/src/modules/util/getAddresssesByTokenByNetwork.d.ts +3 -0
- package/dist/declarations/src/modules/util/index.d.ts +0 -1
- package/dist/declarations/src/types/balances.d.ts +0 -11
- package/dist/declarations/src/types/minimetadatas.d.ts +13 -8
- package/dist/talismn-balances.cjs.dev.js +178 -209
- package/dist/talismn-balances.cjs.prod.js +178 -209
- package/dist/talismn-balances.esm.js +175 -206
- package/package.json +6 -6
- package/dist/declarations/src/modules/SubstrateNativeModule/util/detectMiniMetadataChanges.d.ts +0 -2
- package/dist/declarations/src/modules/util/findChainMeta.d.ts +0 -8
@@ -1,17 +1,19 @@
|
|
1
|
-
import { Dexie
|
1
|
+
import { Dexie } from 'dexie';
|
2
2
|
import anylogger from 'anylogger';
|
3
|
-
import { evmErc20TokenId, EvmErc20TokenSchema, evmNativeTokenId, evmUniswapV2TokenId, githubTokenLogoUrl, parseSubAssetTokenId, subAssetTokenId, parseSubForeignAssetTokenId, subForeignAssetTokenId,
|
3
|
+
import { evmErc20TokenId, DotNetworkSchema, EvmErc20TokenSchema, networkIdFromTokenId, evmNativeTokenId, evmUniswapV2TokenId, githubTokenLogoUrl, parseSubAssetTokenId, subAssetTokenId, parseSubForeignAssetTokenId, subForeignAssetTokenId, parseTokenId, subNativeTokenId, subPsp22TokenId, parseSubTokensTokenId, subTokensTokenId } from '@talismn/chaindata-provider';
|
4
4
|
import { newTokenRates } from '@talismn/token-rates';
|
5
|
-
import { isBigInt, BigMath, planckToTokens, isArrayOf, isTruthy, isEthereumAddress, hasOwnProperty, decodeAnyAddress, isNotNil, blake2Concat,
|
5
|
+
import { isBigInt, BigMath, planckToTokens, isArrayOf, isTruthy, isEthereumAddress, hasOwnProperty, decodeAnyAddress, isNotNil, blake2Concat, Deferred } from '@talismn/util';
|
6
6
|
import BigNumber from 'bignumber.js';
|
7
7
|
import { u8aToHex, assert, stringCamelCase, u8aConcatStrict, u8aConcat, arrayChunk, u8aToString, hexToNumber, hexToU8a } from '@polkadot/util';
|
8
8
|
import { xxhashAsU8a, blake2AsU8a } from '@polkadot/util-crypto';
|
9
|
+
import { HexStringSchema } from '@talismn/chaindata-provider/src/chaindata/shared';
|
10
|
+
import z from 'zod/v4';
|
9
11
|
import pako from 'pako';
|
10
12
|
import { parseAbi, isHex, hexToBigInt } from 'viem';
|
13
|
+
import { fromPairs, toPairs, keys, groupBy as groupBy$1 } from 'lodash';
|
11
14
|
import isEqual from 'lodash/isEqual';
|
12
15
|
import { defineMethod } from '@substrate/txwrapper-core';
|
13
16
|
import { unifyMetadata, decAnyMetadata, getDynamicBuilder, getLookupFn, compactMetadata, encodeMetadata, decodeScale, papiParse, getMetadataVersion, encodeStateKey } from '@talismn/scale';
|
14
|
-
import { keys, toPairs, groupBy as groupBy$1 } from 'lodash';
|
15
17
|
import camelCase from 'lodash/camelCase';
|
16
18
|
import PQueue from 'p-queue';
|
17
19
|
import { fetchBestMetadata, getScaleApi } from '@talismn/sapi';
|
@@ -21,12 +23,13 @@ import { mergeUint8, toHex } from '@polkadot-api/utils';
|
|
21
23
|
import { Binary, AccountId } from 'polkadot-api';
|
22
24
|
import PromisePool from '@supercharge/promise-pool';
|
23
25
|
import { ChainConnectionError } from '@talismn/chain-connector';
|
24
|
-
import { Observable, scan, share, map, switchAll, combineLatest, from, mergeMap, toArray, interval, startWith, exhaustMap,
|
26
|
+
import { Observable, scan, share, map, switchAll, combineLatest, from, mergeMap, toArray, interval, startWith, exhaustMap, BehaviorSubject, debounceTime, takeUntil, distinctUntilChanged, switchMap, withLatestFrom, concatMap } from 'rxjs';
|
25
27
|
import { u32, u128, Struct } from 'scale-ts';
|
26
28
|
import upperFirst from 'lodash/upperFirst';
|
27
|
-
import z from 'zod/v4';
|
28
29
|
import { Abi } from '@polkadot/api-contract';
|
29
30
|
|
31
|
+
// Record<string, unknown> | undefined
|
32
|
+
|
30
33
|
// TODO: Document default balances module purpose/usage
|
31
34
|
const DefaultBalanceModule = type => ({
|
32
35
|
get type() {
|
@@ -111,7 +114,7 @@ class EvmTokenFetcher {
|
|
111
114
|
|
112
115
|
var pkg = {
|
113
116
|
name: "@talismn/balances",
|
114
|
-
version: "0.0.0-pr2043-
|
117
|
+
version: "0.0.0-pr2043-20250619151012"};
|
115
118
|
|
116
119
|
var log = anylogger(pkg.name);
|
117
120
|
|
@@ -395,13 +398,13 @@ class Balance {
|
|
395
398
|
return this.#storage.networkId;
|
396
399
|
}
|
397
400
|
get network() {
|
398
|
-
return this.#db?.networks
|
401
|
+
return this.#db?.networks?.[this.networkId] || null;
|
399
402
|
}
|
400
403
|
get tokenId() {
|
401
404
|
return this.#storage.tokenId;
|
402
405
|
}
|
403
406
|
get token() {
|
404
|
-
return this.#db?.tokens
|
407
|
+
return this.#db?.tokens?.[this.tokenId] || null;
|
405
408
|
}
|
406
409
|
get decimals() {
|
407
410
|
return this.token?.decimals || null;
|
@@ -921,6 +924,23 @@ const deriveMiniMetadataId = ({
|
|
921
924
|
specVersion,
|
922
925
|
libVersion
|
923
926
|
}) => u8aToHex(xxhashAsU8a(new TextEncoder().encode(`${source}${chainId}${specVersion}${libVersion}`), 64), undefined, false);
|
927
|
+
const MiniMetadataBaseSchema = z.strictObject({
|
928
|
+
/** The DB id for this metadata */
|
929
|
+
id: z.string().nonempty(),
|
930
|
+
/** The balance module which created this miniMetadata */
|
931
|
+
source: z.string().nonempty(),
|
932
|
+
// TODO make it an enum of balance module types
|
933
|
+
/** The chain this miniMetadata came from */
|
934
|
+
chainId: DotNetworkSchema.shape.id,
|
935
|
+
/** The chain specVersion which this miniMetadata is valid for */
|
936
|
+
specVersion: DotNetworkSchema.shape.specVersion,
|
937
|
+
/** the version of the balances library used to craft the mini metadata */
|
938
|
+
libVersion: z.string().nonempty(),
|
939
|
+
/** The miniMetadata encoded as a hex string */
|
940
|
+
data: HexStringSchema.nullable(),
|
941
|
+
// /** module specific information about the chain, such as pallet ids for specific features */
|
942
|
+
extra: z.any().nullable()
|
943
|
+
});
|
924
944
|
|
925
945
|
// for DB version 3, Wallet version 1.21.0
|
926
946
|
const upgradeRemoveSymbolFromNativeTokenId = async tx => {
|
@@ -1282,10 +1302,10 @@ const EvmErc20Module = hydrate => {
|
|
1282
1302
|
* In a future version of the balance libraries, we may build some kind of async scheduling system which will keep the chainmeta for each chain up to date without relying on a squid.
|
1283
1303
|
*/
|
1284
1304
|
async fetchEvmChainMeta(_chainId) {
|
1285
|
-
return
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1305
|
+
return {
|
1306
|
+
miniMetadata: null,
|
1307
|
+
extra: null
|
1308
|
+
};
|
1289
1309
|
},
|
1290
1310
|
/**
|
1291
1311
|
* This method is currently executed on [a squid](https://github.com/TalismanSociety/chaindata-squid/blob/0ee02818bf5caa7362e3f3664e55ef05ec8df078/src/steps/updateEvmNetworksFromGithub.ts#L338-L343).
|
@@ -1494,7 +1514,6 @@ const fetchBalances$3 = async (evmChainConnector, tokenAddressesByNetwork, erc20
|
|
1494
1514
|
source: "evm-erc20",
|
1495
1515
|
status: "live",
|
1496
1516
|
address: networkParams[i].address,
|
1497
|
-
// multiChainId: { evmChainId: evmNetworkId },
|
1498
1517
|
networkId,
|
1499
1518
|
tokenId: networkParams[i].token.id,
|
1500
1519
|
value: free
|
@@ -1580,15 +1599,6 @@ function groupAddressesByTokenByEvmNetwork$1(addressesByToken, tokens) {
|
|
1580
1599
|
const abiMulticall = 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)"]);
|
1581
1600
|
|
1582
1601
|
const moduleType$6 = "evm-native";
|
1583
|
-
|
1584
|
-
// export const evmNativeTokenId = (chainId: EvmNetworkId) =>
|
1585
|
-
// `${chainId}-evm-native`.toLowerCase().replace(/ /g, "-")
|
1586
|
-
|
1587
|
-
const getEvmNetworkIdFromTokenId = tokenId => {
|
1588
|
-
const evmNetworkId = tokenId.split(":")[0];
|
1589
|
-
if (!evmNetworkId) throw new Error(`Can't detect chainId for token ${tokenId}`);
|
1590
|
-
return evmNetworkId;
|
1591
|
-
};
|
1592
1602
|
const EvmNativeModule = hydrate => {
|
1593
1603
|
const {
|
1594
1604
|
chainConnectors,
|
@@ -1607,10 +1617,10 @@ const EvmNativeModule = hydrate => {
|
|
1607
1617
|
* In a future version of the balance libraries, we may build some kind of async scheduling system which will keep the chainmeta for each chain up to date without relying on a squid.
|
1608
1618
|
*/
|
1609
1619
|
async fetchEvmChainMeta(_chainId) {
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1620
|
+
return {
|
1621
|
+
miniMetadata: null,
|
1622
|
+
extra: null
|
1623
|
+
};
|
1614
1624
|
},
|
1615
1625
|
/**
|
1616
1626
|
* This method is currently executed on [a squid](https://github.com/TalismanSociety/chaindata-squid/blob/0ee02818bf5caa7362e3f3664e55ef05ec8df078/src/steps/updateEvmNetworksFromGithub.ts#L338-L343).
|
@@ -1649,7 +1659,7 @@ const EvmNativeModule = hydrate => {
|
|
1649
1659
|
const initDelay = 500; // 500ms == 0.5 seconds
|
1650
1660
|
|
1651
1661
|
const tokens = await getModuleTokens();
|
1652
|
-
const ethAddressesByToken =
|
1662
|
+
const ethAddressesByToken = fromPairs(toPairs(addressesByToken).map(([tokenId, addresses]) => {
|
1653
1663
|
const ethAddresses = addresses.filter(isEthereumAddress);
|
1654
1664
|
if (ethAddresses.length === 0) return null;
|
1655
1665
|
const token = tokens[tokenId];
|
@@ -1663,7 +1673,7 @@ const EvmNativeModule = hydrate => {
|
|
1663
1673
|
let zeroBalanceSubscriptionIntervalCounter = 0;
|
1664
1674
|
|
1665
1675
|
// setup initialising balances for all active evm networks
|
1666
|
-
const activeEvmNetworkIds =
|
1676
|
+
const activeEvmNetworkIds = keys(ethAddressesByToken).map(networkIdFromTokenId);
|
1667
1677
|
const initialisingBalances = new Set(activeEvmNetworkIds);
|
1668
1678
|
const positiveBalanceNetworks = new Set(initialBalances?.map(b => b.networkId));
|
1669
1679
|
const poll = async () => {
|
@@ -1672,7 +1682,7 @@ const EvmNativeModule = hydrate => {
|
|
1672
1682
|
try {
|
1673
1683
|
// fetch balance for each network sequentially to prevent creating a big queue of http requests (browser can only handle 2 at a time)
|
1674
1684
|
for (const [tokenId, addresses] of Object.entries(ethAddressesByToken)) {
|
1675
|
-
const evmNetworkId =
|
1685
|
+
const evmNetworkId = networkIdFromTokenId(tokenId);
|
1676
1686
|
|
1677
1687
|
// a zero balance network is one that has initialised and does not have a positive balance
|
1678
1688
|
const isZeroBalanceNetwork = !initialisingBalances.has(evmNetworkId) && !positiveBalanceNetworks.has(evmNetworkId);
|
@@ -2390,14 +2400,12 @@ const EvmUniswapV2Module = hydrate => {
|
|
2390
2400
|
return {
|
2391
2401
|
...DefaultBalanceModule(moduleType$5),
|
2392
2402
|
async fetchEvmChainMeta(_chainId) {
|
2393
|
-
|
2394
|
-
|
2395
|
-
|
2396
|
-
|
2403
|
+
return {
|
2404
|
+
miniMetadata: null,
|
2405
|
+
extra: null
|
2406
|
+
};
|
2397
2407
|
},
|
2398
2408
|
async fetchEvmChainTokens(chainId, _chainMeta, moduleConfig) {
|
2399
|
-
//const { isTestnet } = chainMeta
|
2400
|
-
|
2401
2409
|
const tokens = {};
|
2402
2410
|
for (const tokenConfig of moduleConfig?.pools ?? []) {
|
2403
2411
|
const {
|
@@ -2754,7 +2762,8 @@ const fetchMiniMetadatas = async (chainConnector, chaindataProvider, chainId, sp
|
|
2754
2762
|
chainId,
|
2755
2763
|
specVersion,
|
2756
2764
|
libVersion,
|
2757
|
-
data: chainMeta?.miniMetadata ?? null
|
2765
|
+
data: chainMeta?.miniMetadata ?? null,
|
2766
|
+
extra: chainMeta?.extra ?? null
|
2758
2767
|
};
|
2759
2768
|
}));
|
2760
2769
|
} finally {
|
@@ -2823,40 +2832,15 @@ async function balances(balanceModule, addressesByToken, callback) {
|
|
2823
2832
|
return await balanceModule.fetchBalances(addressesByToken);
|
2824
2833
|
}
|
2825
2834
|
|
2826
|
-
/**
|
2827
|
-
* Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
|
2828
|
-
* associated with the given balanceModule for the given chain.
|
2829
|
-
*/
|
2830
|
-
const findChainMeta = (miniMetadatas, moduleType, chain) => {
|
2831
|
-
if (!chain) return [undefined, undefined];
|
2832
|
-
if (!chain.specVersion) return [undefined, undefined];
|
2833
|
-
|
2834
|
-
// TODO: This is spaghetti to import this here, it should be injected into each balance module or something.
|
2835
|
-
const metadataId = deriveMiniMetadataId({
|
2836
|
-
source: moduleType,
|
2837
|
-
chainId: chain.id,
|
2838
|
-
specVersion: chain.specVersion,
|
2839
|
-
libVersion
|
2840
|
-
});
|
2841
|
-
|
2842
|
-
// TODO: Fix this (needs to fetch miniMetadata without being async)
|
2843
|
-
const miniMetadata = miniMetadatas.get(metadataId);
|
2844
|
-
const chainMeta = miniMetadata ? {
|
2845
|
-
miniMetadata: miniMetadata.data
|
2846
|
-
} : undefined;
|
2847
|
-
return [chainMeta, miniMetadata];
|
2848
|
-
};
|
2849
|
-
|
2850
2835
|
const buildStorageCoders = ({
|
2851
2836
|
chainIds,
|
2852
2837
|
chains,
|
2853
2838
|
miniMetadatas,
|
2854
|
-
moduleType,
|
2855
2839
|
coders
|
2856
2840
|
}) => new Map([...chainIds].flatMap(chainId => {
|
2857
2841
|
const chain = chains[chainId];
|
2858
2842
|
if (!chain) return [];
|
2859
|
-
const
|
2843
|
+
const miniMetadata = miniMetadatas.get(chainId); // findMiniMetadata<TBalanceModule>(miniMetadatas, moduleType, chain)
|
2860
2844
|
if (!miniMetadata) return [];
|
2861
2845
|
if (!miniMetadata.data) return [];
|
2862
2846
|
const metadata = unifyMetadata(decAnyMetadata(miniMetadata.data));
|
@@ -3092,6 +3076,10 @@ const decompress = data => {
|
|
3092
3076
|
};
|
3093
3077
|
|
3094
3078
|
const moduleType$4 = "substrate-assets";
|
3079
|
+
const UNSUPPORTED_CHAIN_META$3 = {
|
3080
|
+
miniMetadata: null,
|
3081
|
+
extra: null
|
3082
|
+
};
|
3095
3083
|
const SubAssetsModule = hydrate => {
|
3096
3084
|
const {
|
3097
3085
|
chainConnectors,
|
@@ -3103,7 +3091,7 @@ const SubAssetsModule = hydrate => {
|
|
3103
3091
|
...DefaultBalanceModule(moduleType$4),
|
3104
3092
|
// TODO make synchronous at the module definition level ?
|
3105
3093
|
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
3106
|
-
if (!metadataRpc) return
|
3094
|
+
if (!metadataRpc) return UNSUPPORTED_CHAIN_META$3;
|
3107
3095
|
const metadata = decAnyMetadata(metadataRpc);
|
3108
3096
|
compactMetadata(metadata, [{
|
3109
3097
|
pallet: "Assets",
|
@@ -3111,7 +3099,8 @@ const SubAssetsModule = hydrate => {
|
|
3111
3099
|
}]);
|
3112
3100
|
const miniMetadata = encodeMetadata(metadata);
|
3113
3101
|
return {
|
3114
|
-
miniMetadata
|
3102
|
+
miniMetadata,
|
3103
|
+
extra: null
|
3115
3104
|
};
|
3116
3105
|
},
|
3117
3106
|
async fetchSubstrateChainTokens(chainId, chainMeta, moduleConfig) {
|
@@ -3376,6 +3365,10 @@ const tryEncode = (scaleCoder, ...args) => {
|
|
3376
3365
|
};
|
3377
3366
|
|
3378
3367
|
const moduleType$3 = "substrate-foreignassets";
|
3368
|
+
const UNSUPPORTED_CHAIN_META$2 = {
|
3369
|
+
miniMetadata: null,
|
3370
|
+
extra: null
|
3371
|
+
};
|
3379
3372
|
const SubForeignAssetsModule = hydrate => {
|
3380
3373
|
const {
|
3381
3374
|
chainConnectors,
|
@@ -3386,9 +3379,9 @@ const SubForeignAssetsModule = hydrate => {
|
|
3386
3379
|
return {
|
3387
3380
|
...DefaultBalanceModule(moduleType$3),
|
3388
3381
|
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
3389
|
-
if (metadataRpc === undefined) return
|
3382
|
+
if (metadataRpc === undefined) return UNSUPPORTED_CHAIN_META$2;
|
3390
3383
|
const metadataVersion = getMetadataVersion(metadataRpc);
|
3391
|
-
if (metadataVersion < 14) return
|
3384
|
+
if (metadataVersion < 14) return UNSUPPORTED_CHAIN_META$2;
|
3392
3385
|
const metadata = decAnyMetadata(metadataRpc);
|
3393
3386
|
compactMetadata(metadata, [{
|
3394
3387
|
pallet: "ForeignAssets",
|
@@ -3396,7 +3389,8 @@ const SubForeignAssetsModule = hydrate => {
|
|
3396
3389
|
}]);
|
3397
3390
|
const miniMetadata = encodeMetadata(metadata);
|
3398
3391
|
return {
|
3399
|
-
miniMetadata
|
3392
|
+
miniMetadata,
|
3393
|
+
extra: null
|
3400
3394
|
};
|
3401
3395
|
},
|
3402
3396
|
async fetchSubstrateChainTokens(chainId, chainMeta, moduleConfig) {
|
@@ -3640,6 +3634,16 @@ async function buildQueries$2(chainConnector, chaindataProvider, addressesByToke
|
|
3640
3634
|
}))).flat();
|
3641
3635
|
}
|
3642
3636
|
|
3637
|
+
const getAddresssesByTokenByNetwork = addressesByToken => {
|
3638
|
+
const addressesByTokenByNetwork = toPairs(addressesByToken).reduce((acc, [tokenId, addresses]) => {
|
3639
|
+
const networkId = parseTokenId(tokenId).networkId;
|
3640
|
+
if (!acc[networkId]) acc[networkId] = {};
|
3641
|
+
acc[networkId][tokenId] = addresses;
|
3642
|
+
return acc;
|
3643
|
+
}, {});
|
3644
|
+
return addressesByTokenByNetwork;
|
3645
|
+
};
|
3646
|
+
|
3643
3647
|
async function subscribeBase(queries, chainConnector, callback) {
|
3644
3648
|
const unsubscribe = await new RpcStateQueryHelper(chainConnector, queries).subscribe((error, result) => {
|
3645
3649
|
if (error) callback(error);
|
@@ -3666,16 +3670,21 @@ const asObservable = handler => (...args) => new Observable(subscriber => {
|
|
3666
3670
|
*/
|
3667
3671
|
const crowdloanFundContributionsChildKey = fundIndex => u8aToHex(u8aConcat(":child_storage:default:", blake2AsU8a(u8aConcat("crowdloan", u32.enc(fundIndex)))));
|
3668
3672
|
|
3669
|
-
|
3673
|
+
// TODO make this method chain-specific
|
3674
|
+
async function subscribeCrowdloans(chaindataProvider, chainConnector, addressesByToken, callback, signal) {
|
3670
3675
|
const allChains = await chaindataProvider.chainsById();
|
3671
3676
|
const tokens = await chaindataProvider.tokensById();
|
3672
|
-
|
3677
|
+
|
3678
|
+
// there should be only one network here when subscribing to balances, we've split it up by network at the top level
|
3679
|
+
const networkIds = keys(addressesByToken).map(tokenId => parseTokenId(tokenId).networkId);
|
3680
|
+
const miniMetadatas = new Map();
|
3681
|
+
for (const networkId of networkIds) miniMetadatas.set(networkId, await getMiniMetadata(chaindataProvider, chainConnector, networkId, "substrate-native"));
|
3673
3682
|
const crowdloanTokenIds = Object.entries(tokens).filter(([, token]) => {
|
3674
3683
|
// ignore non-native tokens
|
3675
3684
|
if (token.type !== "substrate-native") return;
|
3676
3685
|
// ignore tokens on chains with no crowdloans pallet
|
3677
|
-
const
|
3678
|
-
return typeof
|
3686
|
+
const miniMetadata = miniMetadatas.get(token.networkId);
|
3687
|
+
return typeof miniMetadata?.extra?.crowdloanPalletId === "string";
|
3679
3688
|
}).map(([tokenId]) => tokenId);
|
3680
3689
|
|
3681
3690
|
// crowdloan contributions can only be done by the native token on chains with the crowdloan pallet
|
@@ -3690,7 +3699,6 @@ async function subscribeCrowdloans(chaindataProvider, chainConnector, addressesB
|
|
3690
3699
|
chainIds: uniqueChainIds,
|
3691
3700
|
chains,
|
3692
3701
|
miniMetadatas,
|
3693
|
-
moduleType: "substrate-native",
|
3694
3702
|
coders: {
|
3695
3703
|
parachains: ["Paras", "Parachains"],
|
3696
3704
|
funds: ["Crowdloan", "Funds"]
|
@@ -3933,16 +3941,25 @@ const nompoolAccountId = (palletId, poolId, index) => {
|
|
3933
3941
|
/** The stash account for the nomination pool */
|
3934
3942
|
const nompoolStashAccountId = (palletId, poolId) => nompoolAccountId(palletId, poolId, 0);
|
3935
3943
|
|
3936
|
-
|
3944
|
+
// TODO make this method chain-specific
|
3945
|
+
async function subscribeNompoolStaking(chaindataProvider, chainConnector, addressesByToken, callback, signal) {
|
3937
3946
|
const allChains = await chaindataProvider.chainsById();
|
3938
3947
|
const tokens = await chaindataProvider.tokensById();
|
3939
|
-
|
3948
|
+
|
3949
|
+
// there should be only one network here when subscribing to balances, we've split it up by network at the top level
|
3950
|
+
const networkIds = keys(addressesByToken).map(tokenId => parseTokenId(tokenId).networkId);
|
3951
|
+
const miniMetadatas = new Map();
|
3952
|
+
for (const networkId of networkIds) {
|
3953
|
+
const miniMetadata = await getMiniMetadata(chaindataProvider, chainConnector, networkId, "substrate-native");
|
3954
|
+
miniMetadatas.set(networkId, miniMetadata);
|
3955
|
+
}
|
3940
3956
|
const nomPoolTokenIds = Object.entries(tokens).filter(([, token]) => {
|
3941
3957
|
// ignore non-native tokens
|
3942
3958
|
if (token.type !== "substrate-native") return false;
|
3959
|
+
|
3943
3960
|
// ignore tokens on chains with no nompools pallet
|
3944
|
-
const
|
3945
|
-
return typeof
|
3961
|
+
const miniMetadata = miniMetadatas.get(token.networkId);
|
3962
|
+
return typeof miniMetadata?.extra?.nominationPoolsPalletId === "string";
|
3946
3963
|
}).map(([tokenId]) => tokenId);
|
3947
3964
|
|
3948
3965
|
// staking can only be done by the native token on chains with the staking pallet
|
@@ -3957,7 +3974,6 @@ async function subscribeNompoolStaking(chaindataProvider, chainConnector, addres
|
|
3957
3974
|
chainIds: uniqueChainIds,
|
3958
3975
|
chains,
|
3959
3976
|
miniMetadatas,
|
3960
|
-
moduleType: "substrate-native",
|
3961
3977
|
coders: {
|
3962
3978
|
poolMembers: ["NominationPools", "PoolMembers"],
|
3963
3979
|
bondedPools: ["NominationPools", "BondedPools"],
|
@@ -3986,10 +4002,10 @@ async function subscribeNompoolStaking(chaindataProvider, chainConnector, addres
|
|
3986
4002
|
log.warn(`Chain ${chainId} for token ${tokenId} not found`);
|
3987
4003
|
continue;
|
3988
4004
|
}
|
3989
|
-
const
|
4005
|
+
const miniMetadata = miniMetadatas.get(chainId);
|
3990
4006
|
const {
|
3991
4007
|
nominationPoolsPalletId
|
3992
|
-
} =
|
4008
|
+
} = miniMetadata?.extra ?? {};
|
3993
4009
|
const subscribePoolMembers = (addresses, callback) => {
|
3994
4010
|
const scaleCoder = chainStorageCoders.get(chainId)?.poolMembers;
|
3995
4011
|
const queries = addresses.flatMap(address => {
|
@@ -4245,16 +4261,24 @@ const calculateTaoFromDynamicInfo = ({
|
|
4245
4261
|
});
|
4246
4262
|
};
|
4247
4263
|
|
4248
|
-
|
4264
|
+
// TODO make this method chain-specific
|
4265
|
+
async function subscribeSubtensorStaking(chaindataProvider, chainConnector, addressesByToken, callback, signal) {
|
4249
4266
|
const allChains = await chaindataProvider.chainsById();
|
4250
4267
|
const tokens = await chaindataProvider.tokensById();
|
4251
|
-
|
4268
|
+
|
4269
|
+
// there should be only one network here when subscribing to balances, we've split it up by network at the top level
|
4270
|
+
const networkIds = keys(addressesByToken).map(tokenId => parseTokenId(tokenId).networkId);
|
4271
|
+
const miniMetadatas = new Map();
|
4272
|
+
for (const networkId of networkIds) {
|
4273
|
+
const miniMetadata = await getMiniMetadata(chaindataProvider, chainConnector, networkId, "substrate-native");
|
4274
|
+
miniMetadatas.set(networkId, miniMetadata);
|
4275
|
+
}
|
4252
4276
|
const subtensorTokenIds = Object.entries(tokens).filter(([, token]) => {
|
4253
4277
|
// ignore non-native tokens
|
4254
4278
|
if (token.type !== "substrate-native") return false;
|
4255
4279
|
// ignore tokens on chains with no subtensor pallet
|
4256
|
-
const
|
4257
|
-
return
|
4280
|
+
const miniMetadata = miniMetadatas.get(token.networkId);
|
4281
|
+
return miniMetadata?.extra?.hasSubtensorPallet === true;
|
4258
4282
|
}).map(([tokenId]) => tokenId);
|
4259
4283
|
|
4260
4284
|
// staking can only be done by the native token on chains with the subtensor pallet
|
@@ -4277,17 +4301,13 @@ async function subscribeSubtensorStaking(chaindataProvider, chainConnector, addr
|
|
4277
4301
|
continue;
|
4278
4302
|
}
|
4279
4303
|
const chainId = token.networkId;
|
4280
|
-
if (!chainId) {
|
4281
|
-
log.warn(`Token ${tokenId} has no chain`);
|
4282
|
-
continue;
|
4283
|
-
}
|
4284
4304
|
const chain = chains[chainId];
|
4285
4305
|
if (!chain) {
|
4286
4306
|
log.warn(`Chain ${chainId} for token ${tokenId} not found`);
|
4287
4307
|
continue;
|
4288
4308
|
}
|
4289
|
-
const
|
4290
|
-
if (!
|
4309
|
+
const miniMetadata = miniMetadatas.get(token.networkId);
|
4310
|
+
if (!miniMetadata?.data) {
|
4291
4311
|
log.warn(`MiniMetadata for chain ${chainId} not found`);
|
4292
4312
|
continue;
|
4293
4313
|
}
|
@@ -4297,7 +4317,7 @@ async function subscribeSubtensorStaking(chaindataProvider, chainConnector, addr
|
|
4297
4317
|
expectErrors: true
|
4298
4318
|
} // don't pollute the wallet logs when this request fails
|
4299
4319
|
)
|
4300
|
-
},
|
4320
|
+
}, miniMetadata.data, token, chain.hasCheckMetadataHash, chain.signedExtensions, chain.registryTypes);
|
4301
4321
|
|
4302
4322
|
// sets the number of addresses to query in parallel (per chain, since each chain runs in parallel to the others)
|
4303
4323
|
const concurrency = 4;
|
@@ -4544,9 +4564,6 @@ const getLockTitle = (lock, {
|
|
4544
4564
|
|
4545
4565
|
const moduleType$2 = "substrate-native";
|
4546
4566
|
|
4547
|
-
// export const subNativeTokenId = (chainId: ChainId) =>
|
4548
|
-
// `${chainId}-substrate-native`.toLowerCase().replace(/ /g, "-")
|
4549
|
-
|
4550
4567
|
/**
|
4551
4568
|
* Function to merge two 'sub sources' of the same balance together, or
|
4552
4569
|
* two instances of the same balance with different values.
|
@@ -4633,10 +4650,10 @@ async function buildQueries$1(chains, tokens, chainStorageCoders, miniMetadatas,
|
|
4633
4650
|
log.warn(`Chain ${chainId} for token ${tokenId} not found`);
|
4634
4651
|
return outerResult;
|
4635
4652
|
}
|
4636
|
-
const
|
4653
|
+
const miniMetadata = miniMetadatas.get(chainId);
|
4637
4654
|
const {
|
4638
4655
|
useLegacyTransferableCalculation
|
4639
|
-
} =
|
4656
|
+
} = miniMetadata?.extra ?? {};
|
4640
4657
|
addresses.flat().forEach(address => {
|
4641
4658
|
const queryKey = `${tokenId}-${address}`;
|
4642
4659
|
// We share this balanceJson between the base and the lock query for this address
|
@@ -4916,73 +4933,19 @@ const updateStakingLocksUsingUnbondingLocks = values => {
|
|
4916
4933
|
return [...otherValues, ...stakingLocks];
|
4917
4934
|
};
|
4918
4935
|
|
4919
|
-
const detectMiniMetadataChanges = () => {
|
4920
|
-
let previousMap = null;
|
4921
|
-
return pipe(map(currMap => {
|
4922
|
-
if (!currMap) return null;
|
4923
|
-
const changes = new Set();
|
4924
|
-
if (previousMap) {
|
4925
|
-
// Check for added or changed keys/values
|
4926
|
-
for (const [key, value] of currMap) {
|
4927
|
-
if (!previousMap.has(key) || !isEqual(previousMap.get(key), value)) {
|
4928
|
-
changes.add(value.chainId);
|
4929
|
-
}
|
4930
|
-
}
|
4931
|
-
|
4932
|
-
// Check for removed keys
|
4933
|
-
for (const [key, value] of previousMap) {
|
4934
|
-
if (!currMap.has(key)) {
|
4935
|
-
changes.add(value.chainId);
|
4936
|
-
}
|
4937
|
-
}
|
4938
|
-
}
|
4939
|
-
previousMap = currMap;
|
4940
|
-
return changes.size > 0 ? changes : null;
|
4941
|
-
}),
|
4942
|
-
// Filter out null emissions (no changes)
|
4943
|
-
filter(changes => changes !== null));
|
4944
|
-
};
|
4945
|
-
|
4946
|
-
// NOTE: `liveQuery` is not initialized until commonMetadataObservable is subscribed to.
|
4947
|
-
const commonMetadataObservable = from(liveQuery(() => db.miniMetadatas.where("source").equals("substrate-native").toArray())).pipe(map(items => new Map(items.map(item => [item.id, item]))),
|
4948
|
-
// `refCount: true` will unsubscribe from the DB when commonMetadataObservable has no more subscribers
|
4949
|
-
shareReplay({
|
4950
|
-
bufferSize: 1,
|
4951
|
-
refCount: true
|
4952
|
-
}));
|
4953
4936
|
class QueryCache {
|
4937
|
+
#chaindataProvider;
|
4938
|
+
#chainConnector;
|
4939
|
+
miniMetadatas = new Map();
|
4954
4940
|
balanceQueryCache = new Map();
|
4955
|
-
metadataSub = null
|
4956
|
-
|
4941
|
+
// private metadataSub: Subscription | null = null
|
4942
|
+
|
4943
|
+
constructor(chaindataProvider, chainConnector) {
|
4957
4944
|
this.chaindataProvider = chaindataProvider;
|
4958
|
-
|
4959
|
-
|
4960
|
-
if (this.metadataSub) return;
|
4961
|
-
this.metadataSub = commonMetadataObservable.pipe(firstThenDebounce(500), detectMiniMetadataChanges(), combineLatestWith(this.chaindataProvider.tokensObservable), distinctUntilChanged()).subscribe(([miniMetadataChanges, tokens]) => {
|
4962
|
-
// invalidate cache entries for any chains with new metadata
|
4963
|
-
const tokensByChainId = tokens.filter(token => token.type === "substrate-native").reduce((result, token) => {
|
4964
|
-
if (!token.networkId) return result;
|
4965
|
-
result[token.networkId] ? result[token.networkId].push(token) : result[token.networkId] = [token];
|
4966
|
-
return result;
|
4967
|
-
}, {});
|
4968
|
-
miniMetadataChanges.forEach(chainId => {
|
4969
|
-
const chainTokens = tokensByChainId[chainId];
|
4970
|
-
if (!chainTokens) return;
|
4971
|
-
chainTokens.forEach(token => {
|
4972
|
-
const tokenId = token.id;
|
4973
|
-
const cacheKeys = this.balanceQueryCache.keys();
|
4974
|
-
for (const key of cacheKeys) {
|
4975
|
-
if (key.startsWith(`${tokenId}-`)) this.balanceQueryCache.delete(key);
|
4976
|
-
}
|
4977
|
-
});
|
4978
|
-
});
|
4979
|
-
});
|
4980
|
-
}
|
4981
|
-
destroy() {
|
4982
|
-
this.metadataSub?.unsubscribe();
|
4945
|
+
this.#chaindataProvider = chaindataProvider;
|
4946
|
+
this.#chainConnector = chainConnector;
|
4983
4947
|
}
|
4984
4948
|
async getQueries(addressesByToken) {
|
4985
|
-
this.ensureSetup();
|
4986
4949
|
const chains = await this.chaindataProvider.chainsById();
|
4987
4950
|
const tokens = await this.chaindataProvider.tokensById();
|
4988
4951
|
const queryResults = Object.entries(addressesByToken).reduce((result, [tokenId, addresses]) => {
|
@@ -5000,15 +4963,20 @@ class QueryCache {
|
|
5000
4963
|
existing: [],
|
5001
4964
|
newAddressesByToken: {}
|
5002
4965
|
});
|
4966
|
+
const byNetwork = getAddresssesByTokenByNetwork(addressesByToken);
|
4967
|
+
for (const networkId of keys(byNetwork)) {
|
4968
|
+
if (this.miniMetadatas.has(networkId)) continue;
|
4969
|
+
const miniMetadata = await getMiniMetadata(this.#chaindataProvider, this.#chainConnector, networkId, "substrate-native");
|
4970
|
+
this.miniMetadatas.set(networkId, miniMetadata);
|
4971
|
+
}
|
5003
4972
|
|
5004
4973
|
// build queries for token/address pairs which have not been queried before
|
5005
|
-
const miniMetadatas = await firstValueFrom(commonMetadataObservable)
|
5006
|
-
const uniqueChainIds = getUniqueChainIds(queryResults.newAddressesByToken, tokens)
|
4974
|
+
// const miniMetadatas = await firstValueFrom(commonMetadataObservable)
|
4975
|
+
const uniqueChainIds = keys(byNetwork); // getUniqueChainIds(queryResults.newAddressesByToken, tokens)
|
5007
4976
|
const chainStorageCoders = buildStorageCoders({
|
5008
4977
|
chainIds: uniqueChainIds,
|
5009
4978
|
chains,
|
5010
|
-
miniMetadatas,
|
5011
|
-
moduleType: "substrate-native",
|
4979
|
+
miniMetadatas: this.miniMetadatas,
|
5012
4980
|
coders: {
|
5013
4981
|
base: ["System", "Account"],
|
5014
4982
|
stakingLedger: ["Staking", "Ledger"],
|
@@ -5018,7 +4986,7 @@ class QueryCache {
|
|
5018
4986
|
freezes: ["Balances", "Freezes"]
|
5019
4987
|
}
|
5020
4988
|
});
|
5021
|
-
const queries = await buildQueries$1(chains, tokens, chainStorageCoders, miniMetadatas, queryResults.newAddressesByToken);
|
4989
|
+
const queries = await buildQueries$1(chains, tokens, chainStorageCoders, this.miniMetadatas, queryResults.newAddressesByToken);
|
5022
4990
|
// now update the cache
|
5023
4991
|
Object.entries(queries).forEach(([key, query]) => {
|
5024
4992
|
this.balanceQueryCache.set(key, query);
|
@@ -5069,6 +5037,10 @@ const getChainProperties = async (chainConnector, networkId) => {
|
|
5069
5037
|
|
5070
5038
|
const POLLING_WINDOW_SIZE = 20;
|
5071
5039
|
const MAX_SUBSCRIPTION_SIZE = 40;
|
5040
|
+
const UNSUPPORTED_CHAIN_META$1 = {
|
5041
|
+
miniMetadata: null,
|
5042
|
+
extra: null
|
5043
|
+
};
|
5072
5044
|
const SubNativeModule = hydrate => {
|
5073
5045
|
const {
|
5074
5046
|
chainConnectors,
|
@@ -5076,7 +5048,7 @@ const SubNativeModule = hydrate => {
|
|
5076
5048
|
} = hydrate;
|
5077
5049
|
const chainConnector = chainConnectors.substrate;
|
5078
5050
|
assert(chainConnector, "This module requires a substrate chain connector");
|
5079
|
-
const queryCache = new QueryCache(chaindataProvider);
|
5051
|
+
const queryCache = new QueryCache(chaindataProvider, chainConnector);
|
5080
5052
|
const getModuleTokens = async () => {
|
5081
5053
|
return await chaindataProvider.tokensByIdForType(moduleType$2);
|
5082
5054
|
};
|
@@ -5254,13 +5226,13 @@ const SubNativeModule = hydrate => {
|
|
5254
5226
|
return {
|
5255
5227
|
...DefaultBalanceModule(moduleType$2),
|
5256
5228
|
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
5257
|
-
if (!metadataRpc) return
|
5229
|
+
if (!metadataRpc) return UNSUPPORTED_CHAIN_META$1;
|
5258
5230
|
|
5259
5231
|
//
|
5260
5232
|
// process metadata into SCALE encoders/decoders
|
5261
5233
|
//
|
5262
5234
|
const metadataVersion = getMetadataVersion(metadataRpc);
|
5263
|
-
if (metadataVersion < 14) return
|
5235
|
+
if (metadataVersion < 14) return UNSUPPORTED_CHAIN_META$1;
|
5264
5236
|
const metadata = decAnyMetadata(metadataRpc);
|
5265
5237
|
const unifiedMetadata = unifyMetadata(metadata);
|
5266
5238
|
|
@@ -5327,18 +5299,17 @@ const SubNativeModule = hydrate => {
|
|
5327
5299
|
}) => name === "Freezes"));
|
5328
5300
|
const useLegacyTransferableCalculation = !hasFreezesItem;
|
5329
5301
|
const chainMeta = {
|
5330
|
-
|
5331
|
-
|
5332
|
-
|
5333
|
-
|
5334
|
-
|
5335
|
-
|
5336
|
-
|
5337
|
-
|
5338
|
-
miniMetadata
|
5302
|
+
miniMetadata,
|
5303
|
+
extra: {
|
5304
|
+
useLegacyTransferableCalculation,
|
5305
|
+
existentialDeposit,
|
5306
|
+
nominationPoolsPalletId,
|
5307
|
+
crowdloanPalletId,
|
5308
|
+
hasSubtensorPallet
|
5309
|
+
}
|
5339
5310
|
};
|
5340
|
-
if (!useLegacyTransferableCalculation) delete chainMeta.useLegacyTransferableCalculation;
|
5341
|
-
if (!hasSubtensorPallet) delete chainMeta.hasSubtensorPallet;
|
5311
|
+
if (!useLegacyTransferableCalculation) delete chainMeta.extra?.useLegacyTransferableCalculation;
|
5312
|
+
if (!hasSubtensorPallet) delete chainMeta.extra?.hasSubtensorPallet;
|
5342
5313
|
return chainMeta;
|
5343
5314
|
},
|
5344
5315
|
async fetchSubstrateChainTokens(chainId, chainMeta, moduleConfig) {
|
@@ -5349,7 +5320,7 @@ const SubNativeModule = hydrate => {
|
|
5349
5320
|
} = await getChainProperties(chainConnector, chainId);
|
5350
5321
|
const {
|
5351
5322
|
existentialDeposit
|
5352
|
-
} = chainMeta;
|
5323
|
+
} = chainMeta.extra ?? {};
|
5353
5324
|
const id = subNativeTokenId(chainId);
|
5354
5325
|
const nativeToken = {
|
5355
5326
|
id,
|
@@ -5375,19 +5346,11 @@ const SubNativeModule = hydrate => {
|
|
5375
5346
|
initialBalances
|
5376
5347
|
}, callback) {
|
5377
5348
|
assert(chainConnectors.substrate, "This module requires a substrate chain connector");
|
5378
|
-
const addressesByTokenByNetwork =
|
5379
|
-
const networkId = parseSubNativeTokenId(tokenId).networkId;
|
5380
|
-
if (!acc[networkId]) acc[networkId] = {};
|
5381
|
-
acc[networkId][tokenId] = addressesByToken[tokenId];
|
5382
|
-
return acc;
|
5383
|
-
}, {});
|
5349
|
+
const addressesByTokenByNetwork = getAddresssesByTokenByNetwork(addressesByToken);
|
5384
5350
|
const initialBalancesByNetwork = groupBy$1(initialBalances ?? [], "networkId");
|
5385
|
-
const
|
5386
|
-
abort,
|
5387
|
-
signal
|
5388
|
-
} = new AbortController();
|
5351
|
+
const controller = new AbortController();
|
5389
5352
|
const safeCallback = (error, result) => {
|
5390
|
-
if (signal.aborted) return;
|
5353
|
+
if (controller.signal.aborted) return;
|
5391
5354
|
// typescript isnt happy with fowarding parameters as is
|
5392
5355
|
return error ? callback(error, undefined) : callback(error, result);
|
5393
5356
|
};
|
@@ -5395,19 +5358,19 @@ const SubNativeModule = hydrate => {
|
|
5395
5358
|
try {
|
5396
5359
|
// this is what we want to be done separately for each network
|
5397
5360
|
// this will update the DB so minimetadata will be available when it's used, veeeeery far down the tree of subscribeChainBalances
|
5398
|
-
await getMiniMetadata(chaindataProvider, chainConnector, networkId, moduleType$2, signal);
|
5361
|
+
await getMiniMetadata(chaindataProvider, chainConnector, networkId, moduleType$2, controller.signal);
|
5399
5362
|
} catch (err) {
|
5400
|
-
if (!signal.aborted) log.warn("Failed to get native token miniMetadata for network", networkId, err);
|
5363
|
+
if (!controller.signal.aborted) log.warn("Failed to get native token miniMetadata for network", networkId, err);
|
5401
5364
|
return () => {};
|
5402
5365
|
}
|
5403
|
-
if (signal.aborted) return () => {};
|
5366
|
+
if (controller.signal.aborted) return () => {};
|
5404
5367
|
return subscribeChainBalances(networkId, {
|
5405
5368
|
addressesByToken: addressesByTokenByNetwork[networkId] ?? {},
|
5406
5369
|
initialBalances: initialBalancesByNetwork[networkId] ?? []
|
5407
5370
|
}, safeCallback);
|
5408
5371
|
}));
|
5409
5372
|
return () => {
|
5410
|
-
abort();
|
5373
|
+
controller.abort();
|
5411
5374
|
unsubsribeFns.then(fns => fns.forEach(unsubscribe => unsubscribe()));
|
5412
5375
|
};
|
5413
5376
|
},
|
@@ -6636,7 +6599,11 @@ const SubPsp22Module = hydrate => {
|
|
6636
6599
|
return {
|
6637
6600
|
...DefaultBalanceModule(moduleType$1),
|
6638
6601
|
async fetchSubstrateChainMeta(_chainId) {
|
6639
|
-
|
6602
|
+
// we dont need anything
|
6603
|
+
return {
|
6604
|
+
miniMetadata: null,
|
6605
|
+
extra: null
|
6606
|
+
};
|
6640
6607
|
},
|
6641
6608
|
async fetchSubstrateChainTokens(chainId, _chainMeta, moduleConfig) {
|
6642
6609
|
// const { isTestnet } = chainMeta
|
@@ -6870,6 +6837,10 @@ const fetchBalances = async (chainConnector, tokens, addressesByToken) => {
|
|
6870
6837
|
|
6871
6838
|
const moduleType = "substrate-tokens";
|
6872
6839
|
const defaultPalletId = "Tokens";
|
6840
|
+
const UNSUPPORTED_CHAIN_META = {
|
6841
|
+
miniMetadata: null,
|
6842
|
+
extra: {}
|
6843
|
+
};
|
6873
6844
|
const SubTokensModule = hydrate => {
|
6874
6845
|
const {
|
6875
6846
|
chainConnectors,
|
@@ -6880,7 +6851,7 @@ const SubTokensModule = hydrate => {
|
|
6880
6851
|
return {
|
6881
6852
|
...DefaultBalanceModule(moduleType),
|
6882
6853
|
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
6883
|
-
if (metadataRpc === undefined) return
|
6854
|
+
if (metadataRpc === undefined) return UNSUPPORTED_CHAIN_META;
|
6884
6855
|
const metadata = decAnyMetadata(metadataRpc);
|
6885
6856
|
const palletId = moduleConfig?.palletId ?? defaultPalletId;
|
6886
6857
|
compactMetadata(metadata, [{
|
@@ -6888,11 +6859,11 @@ const SubTokensModule = hydrate => {
|
|
6888
6859
|
items: ["Accounts"]
|
6889
6860
|
}]);
|
6890
6861
|
const miniMetadata = encodeMetadata(metadata);
|
6891
|
-
return
|
6892
|
-
miniMetadata
|
6893
|
-
|
6894
|
-
|
6895
|
-
|
6862
|
+
return {
|
6863
|
+
miniMetadata,
|
6864
|
+
extra: {
|
6865
|
+
palletId
|
6866
|
+
}
|
6896
6867
|
};
|
6897
6868
|
},
|
6898
6869
|
async fetchSubstrateChainTokens(chainId, chainMeta, moduleConfig) {
|
@@ -6982,9 +6953,8 @@ const SubTokensModule = hydrate => {
|
|
6982
6953
|
const chainId = token.networkId;
|
6983
6954
|
const chain = await chaindataProvider.chainById(chainId);
|
6984
6955
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
6985
|
-
const
|
6986
|
-
const
|
6987
|
-
const tokensPallet = chainMeta?.palletId ?? defaultPalletId;
|
6956
|
+
const miniMetadata = await getMiniMetadata(chaindataProvider, chainConnector, chainId, moduleType);
|
6957
|
+
const tokensPallet = miniMetadata?.extra?.palletId ?? defaultPalletId;
|
6988
6958
|
const onChainId = (() => {
|
6989
6959
|
try {
|
6990
6960
|
return papiParse(token.onChainId);
|
@@ -7089,8 +7059,7 @@ async function buildNetworkQueries(networkId, chainConnector, chaindataProvider,
|
|
7089
7059
|
const tokens = await chaindataProvider.tokensById();
|
7090
7060
|
if (!chain) return [];
|
7091
7061
|
signal?.throwIfAborted();
|
7092
|
-
const
|
7093
|
-
const palletId = tokensMetadata.palletId ?? defaultPalletId;
|
7062
|
+
const palletId = miniMetadata.extra.palletId ?? defaultPalletId;
|
7094
7063
|
const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, {
|
7095
7064
|
storage: [palletId, "Accounts"]
|
7096
7065
|
});
|
@@ -7170,4 +7139,4 @@ async function buildQueries(chainConnector, chaindataProvider, addressesByToken,
|
|
7170
7139
|
|
7171
7140
|
const defaultBalanceModules = [EvmErc20Module, EvmNativeModule, EvmUniswapV2Module, SubAssetsModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule];
|
7172
7141
|
|
7173
|
-
export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, ONE_ALPHA_TOKEN, PlanckSumBalancesFormatter, RpcStateQueryHelper, SCALE_FACTOR, SUBTENSOR_MIN_STAKE_AMOUNT_PLANK, SUBTENSOR_ROOT_NETUID, SubAssetsModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule, SumBalancesFormatter, TalismanBalancesDatabase, abiMulticall, balances, buildNetworkStorageCoders, buildStorageCoders, calculateAlphaPrice, calculateTaoAmountFromAlpha, calculateTaoFromDynamicInfo, compress, configureStore, db, decodeOutput, decompress, defaultBalanceModules, deriveMiniMetadataId, detectTransferMethod, erc20Abi, erc20BalancesAggregatorAbi, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterBaseLocks, filterMirrorTokens,
|
7142
|
+
export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, MiniMetadataBaseSchema, ONE_ALPHA_TOKEN, PlanckSumBalancesFormatter, RpcStateQueryHelper, SCALE_FACTOR, SUBTENSOR_MIN_STAKE_AMOUNT_PLANK, SUBTENSOR_ROOT_NETUID, SubAssetsModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule, SumBalancesFormatter, TalismanBalancesDatabase, abiMulticall, balances, buildNetworkStorageCoders, buildStorageCoders, calculateAlphaPrice, calculateTaoAmountFromAlpha, calculateTaoFromDynamicInfo, compress, configureStore, db, decodeOutput, decompress, defaultBalanceModules, deriveMiniMetadataId, detectTransferMethod, erc20Abi, erc20BalancesAggregatorAbi, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterBaseLocks, filterMirrorTokens, getBalanceId, getLockTitle, getUniqueChainIds, getValueId, includeInTotalExtraAmount, makeContractCaller, uniswapV2PairAbi };
|