@talismn/balances 0.0.0-pr2041-20250612085325 → 0.0.0-pr2043-20250612121753
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/modules/EvmErc20Module.d.ts +3 -10
- package/dist/declarations/src/modules/EvmNativeModule.d.ts +2 -11
- package/dist/declarations/src/modules/EvmUniswapV2Module.d.ts +4 -12
- package/dist/declarations/src/modules/SubstrateAssetsModule.d.ts +1 -4
- package/dist/declarations/src/modules/SubstrateForeignAssetsModule.d.ts +1 -4
- package/dist/declarations/src/modules/SubstrateNativeModule/index.d.ts +3 -2
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeCrowdloans.d.ts +2 -2
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeNompoolStaking.d.ts +2 -2
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeSubtensorStaking.d.ts +2 -2
- package/dist/declarations/src/modules/SubstrateNativeModule/types.d.ts +1 -9
- package/dist/declarations/src/modules/SubstrateNativeModule/util/QueryCache.d.ts +2 -2
- package/dist/declarations/src/modules/SubstrateNativeModule/util/buildQueries.d.ts +2 -2
- package/dist/declarations/src/modules/SubstratePsp22Module.d.ts +1 -4
- package/dist/declarations/src/modules/SubstrateTokensModule.d.ts +1 -4
- package/dist/declarations/src/modules/index.d.ts +195 -39
- package/dist/declarations/src/types/balances.d.ts +118 -63
- package/dist/talismn-balances.cjs.dev.js +80 -347
- package/dist/talismn-balances.cjs.prod.js +80 -347
- package/dist/talismn-balances.esm.js +83 -348
- package/package.json +8 -8
- package/dist/declarations/src/modules/SubstrateEquilibriumModule.d.ts +0 -39
@@ -1,5 +1,5 @@
|
|
1
1
|
import PromisePool$1, { PromisePool } from '@supercharge/promise-pool';
|
2
|
-
import { fetchMiniMetadatas, fetchInitMiniMetadatas, availableTokenLogoFilenames, githubTokenLogoUrl } from '@talismn/chaindata-provider';
|
2
|
+
import { fetchMiniMetadatas, fetchInitMiniMetadatas, availableTokenLogoFilenames, githubTokenLogoUrl, EvmErc20TokenDef } from '@talismn/chaindata-provider';
|
3
3
|
import { fetchBestMetadata, getScaleApi } from '@talismn/sapi';
|
4
4
|
import { Dexie, liveQuery } from 'dexie';
|
5
5
|
import isEqual from 'lodash/isEqual';
|
@@ -13,7 +13,7 @@ import { xxhashAsU8a, blake2AsU8a } from '@polkadot/util-crypto';
|
|
13
13
|
import pako from 'pako';
|
14
14
|
import { parseAbi, isHex, hexToBigInt } from 'viem';
|
15
15
|
import { defineMethod } from '@substrate/txwrapper-core';
|
16
|
-
import { unifyMetadata, decAnyMetadata, getDynamicBuilder, getLookupFn, getMetadataVersion, compactMetadata, encodeMetadata, decodeScale,
|
16
|
+
import { unifyMetadata, decAnyMetadata, getDynamicBuilder, getLookupFn, getMetadataVersion, compactMetadata, encodeMetadata, decodeScale, papiParse, encodeStateKey } from '@talismn/scale';
|
17
17
|
import camelCase from 'lodash/camelCase';
|
18
18
|
import { Metadata, TypeRegistry } from '@polkadot/types';
|
19
19
|
import groupBy from 'lodash/groupBy';
|
@@ -1454,7 +1454,7 @@ const erc20Abi = [{
|
|
1454
1454
|
|
1455
1455
|
const erc20BalancesAggregatorAbi = parseAbi(["struct AccountToken {address account; address token;}", "function balances(AccountToken[] memory accountTokens) public view returns (uint256[] memory)"]);
|
1456
1456
|
|
1457
|
-
const moduleType$
|
1457
|
+
const moduleType$7 = "evm-erc20";
|
1458
1458
|
const evmErc20TokenId = (chainId, tokenContractAddress) => `${chainId}-evm-erc20-${tokenContractAddress}`.toLowerCase();
|
1459
1459
|
const EvmErc20Module = hydrate => {
|
1460
1460
|
const {
|
@@ -1479,14 +1479,14 @@ const EvmErc20Module = hydrate => {
|
|
1479
1479
|
}, {});
|
1480
1480
|
};
|
1481
1481
|
const getModuleTokens = async () => {
|
1482
|
-
return await chaindataProvider.tokensByIdForType(moduleType$
|
1482
|
+
return await chaindataProvider.tokensByIdForType(moduleType$7);
|
1483
1483
|
};
|
1484
1484
|
const getErc20Aggregators = async () => {
|
1485
1485
|
const evmNetworks = await chaindataProvider.evmNetworks();
|
1486
1486
|
return Object.fromEntries(evmNetworks.filter(n => n.erc20aggregator).map(n => [n.id, n.erc20aggregator]));
|
1487
1487
|
};
|
1488
1488
|
return {
|
1489
|
-
...DefaultBalanceModule(moduleType$
|
1489
|
+
...DefaultBalanceModule(moduleType$7),
|
1490
1490
|
/**
|
1491
1491
|
* This method is currently executed on [a squid](https://github.com/TalismanSociety/chaindata-squid/blob/0ee02818bf5caa7362e3f3664e55ef05ec8df078/src/steps/updateEvmNetworksFromGithub.ts#L280-L284).
|
1492
1492
|
* 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.
|
@@ -1510,13 +1510,16 @@ const EvmErc20Module = hydrate => {
|
|
1510
1510
|
const {
|
1511
1511
|
contractAddress,
|
1512
1512
|
symbol: contractSymbol,
|
1513
|
-
decimals: contractDecimals
|
1513
|
+
decimals: contractDecimals,
|
1514
|
+
name: contractName
|
1514
1515
|
} = tokenConfig;
|
1515
1516
|
// TODO : in chaindata's build, filter out all tokens that don't have any of these
|
1516
1517
|
if (!contractAddress || !contractSymbol || contractDecimals === undefined) {
|
1517
1518
|
log.warn("ignoring token on chain %s", chainId, tokenConfig);
|
1518
1519
|
continue;
|
1519
1520
|
}
|
1521
|
+
|
1522
|
+
// TODO zodify this
|
1520
1523
|
const symbol = tokenConfig?.symbol ?? contractSymbol ?? "ETH";
|
1521
1524
|
const decimals = typeof tokenConfig?.decimals === "number" ? tokenConfig.decimals : typeof contractDecimals === "number" ? contractDecimals : 18;
|
1522
1525
|
if (!symbol || typeof decimals !== "number") continue;
|
@@ -1524,21 +1527,26 @@ const EvmErc20Module = hydrate => {
|
|
1524
1527
|
const token = {
|
1525
1528
|
id,
|
1526
1529
|
type: "evm-erc20",
|
1530
|
+
platform: "ethereum",
|
1527
1531
|
isTestnet,
|
1528
1532
|
isDefault: tokenConfig.isDefault ?? true,
|
1529
1533
|
symbol,
|
1530
1534
|
decimals,
|
1535
|
+
name: contractName ?? symbol,
|
1531
1536
|
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
1532
1537
|
contractAddress,
|
1533
|
-
|
1534
|
-
id: chainId
|
1535
|
-
}
|
1538
|
+
networkId: chainId
|
1536
1539
|
};
|
1537
1540
|
if (tokenConfig?.symbol) token.symbol = tokenConfig?.symbol;
|
1538
1541
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
1539
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
1540
1542
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
1541
1543
|
if (tokenConfig?.noDiscovery) token.noDiscovery = tokenConfig?.noDiscovery;
|
1544
|
+
const validation = EvmErc20TokenDef.safeParse(token);
|
1545
|
+
if (validation.success) {
|
1546
|
+
chainTokens[token.id] = token;
|
1547
|
+
} else {
|
1548
|
+
log.warn("Ignoring invalid token", token.id, validation.error.message, validation.error.issues);
|
1549
|
+
}
|
1542
1550
|
chainTokens[token.id] = token;
|
1543
1551
|
}
|
1544
1552
|
return chainTokens;
|
@@ -1562,7 +1570,7 @@ const EvmErc20Module = hydrate => {
|
|
1562
1570
|
const ethAddresses = addresses.filter(isEthereumAddress);
|
1563
1571
|
if (ethAddresses.length === 0) return null;
|
1564
1572
|
const token = tokens[tokenId];
|
1565
|
-
const evmNetworkId = token.
|
1573
|
+
const evmNetworkId = token.networkId;
|
1566
1574
|
if (!evmNetworkId) return null;
|
1567
1575
|
return [tokenId, ethAddresses];
|
1568
1576
|
}).filter(x => Boolean(x)));
|
@@ -1772,7 +1780,7 @@ function groupAddressesByTokenByEvmNetwork$1(addressesByToken, tokens) {
|
|
1772
1780
|
log.error(`Token ${tokenId} not found`);
|
1773
1781
|
return byChain;
|
1774
1782
|
}
|
1775
|
-
const chainId = token.
|
1783
|
+
const chainId = token.networkId;
|
1776
1784
|
if (!chainId) {
|
1777
1785
|
log.error(`Token ${tokenId} has no evm network`);
|
1778
1786
|
return byChain;
|
@@ -1785,7 +1793,7 @@ function groupAddressesByTokenByEvmNetwork$1(addressesByToken, tokens) {
|
|
1785
1793
|
|
1786
1794
|
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)"]);
|
1787
1795
|
|
1788
|
-
const moduleType$
|
1796
|
+
const moduleType$6 = "evm-native";
|
1789
1797
|
const evmNativeTokenId = chainId => `${chainId}-evm-native`.toLowerCase().replace(/ /g, "-");
|
1790
1798
|
const getEvmNetworkIdFromTokenId = tokenId => {
|
1791
1799
|
const evmNetworkId = tokenId.split("-")[0];
|
@@ -1798,12 +1806,12 @@ const EvmNativeModule = hydrate => {
|
|
1798
1806
|
chaindataProvider
|
1799
1807
|
} = hydrate;
|
1800
1808
|
const getModuleTokens = async () => {
|
1801
|
-
return await chaindataProvider.tokensByIdForType(moduleType$
|
1809
|
+
return await chaindataProvider.tokensByIdForType(moduleType$6);
|
1802
1810
|
};
|
1803
1811
|
return {
|
1804
|
-
...DefaultBalanceModule(moduleType$
|
1812
|
+
...DefaultBalanceModule(moduleType$6),
|
1805
1813
|
get tokens() {
|
1806
|
-
return chaindataProvider.tokensByIdForType(moduleType$
|
1814
|
+
return chaindataProvider.tokensByIdForType(moduleType$6);
|
1807
1815
|
},
|
1808
1816
|
/**
|
1809
1817
|
* This method is currently executed on [a squid](https://github.com/TalismanSociety/chaindata-squid/blob/0ee02818bf5caa7362e3f3664e55ef05ec8df078/src/steps/updateEvmNetworksFromGithub.ts#L280-L284).
|
@@ -1825,22 +1833,22 @@ const EvmNativeModule = hydrate => {
|
|
1825
1833
|
} = chainMeta;
|
1826
1834
|
const symbol = moduleConfig?.symbol ?? "ETH";
|
1827
1835
|
const decimals = typeof moduleConfig?.decimals === "number" ? moduleConfig.decimals : 18;
|
1836
|
+
const name = moduleConfig?.name ?? symbol;
|
1828
1837
|
const id = evmNativeTokenId(chainId);
|
1829
1838
|
const nativeToken = {
|
1839
|
+
platform: "ethereum",
|
1830
1840
|
id,
|
1831
1841
|
type: "evm-native",
|
1832
1842
|
isTestnet,
|
1833
1843
|
isDefault: true,
|
1834
1844
|
symbol,
|
1835
1845
|
decimals,
|
1846
|
+
name,
|
1836
1847
|
logo: moduleConfig?.logo || githubTokenLogoUrl(id),
|
1837
|
-
|
1838
|
-
id: chainId
|
1839
|
-
}
|
1848
|
+
networkId: chainId
|
1840
1849
|
};
|
1841
1850
|
if (moduleConfig?.symbol) nativeToken.symbol = moduleConfig?.symbol;
|
1842
1851
|
if (moduleConfig?.coingeckoId) nativeToken.coingeckoId = moduleConfig?.coingeckoId;
|
1843
|
-
if (moduleConfig?.dcentName) nativeToken.dcentName = moduleConfig?.dcentName;
|
1844
1852
|
if (moduleConfig?.mirrorOf) nativeToken.mirrorOf = moduleConfig?.mirrorOf;
|
1845
1853
|
if (moduleConfig?.noDiscovery) nativeToken.noDiscovery = moduleConfig?.noDiscovery;
|
1846
1854
|
return {
|
@@ -1860,7 +1868,7 @@ const EvmNativeModule = hydrate => {
|
|
1860
1868
|
const ethAddresses = addresses.filter(isEthereumAddress);
|
1861
1869
|
if (ethAddresses.length === 0) return null;
|
1862
1870
|
const token = tokens[tokenId];
|
1863
|
-
const evmNetworkId = token.
|
1871
|
+
const evmNetworkId = token.networkId;
|
1864
1872
|
if (!evmNetworkId) return null;
|
1865
1873
|
return [tokenId, ethAddresses];
|
1866
1874
|
}).filter(x => Boolean(x)));
|
@@ -1952,7 +1960,7 @@ const fetchBalances$2 = async (evmChainConnector, addressesByToken, tokens) => {
|
|
1952
1960
|
if (!evmChainConnector) throw new Error(`This module requires an evm chain connector`);
|
1953
1961
|
return Promise.all(Object.entries(addressesByToken).map(async ([tokenId, addresses]) => {
|
1954
1962
|
const token = tokens[tokenId];
|
1955
|
-
const evmNetworkId = token.
|
1963
|
+
const evmNetworkId = token.networkId;
|
1956
1964
|
if (!evmNetworkId) throw new Error(`Token ${token.id} has no evm network`);
|
1957
1965
|
const publicClient = await evmChainConnector.getPublicClientForEvmNetwork(evmNetworkId);
|
1958
1966
|
if (!publicClient) throw new Error(`Could not get rpc provider for evm network ${evmNetworkId}`);
|
@@ -2021,7 +2029,7 @@ async function getFreeBalances(publicClient, addresses) {
|
|
2021
2029
|
});
|
2022
2030
|
} catch (err) {
|
2023
2031
|
const errorMessage = hasOwnProperty(err, "shortMessage") ? err.shortMessage : hasOwnProperty(err, "message") ? err.message : err;
|
2024
|
-
log.warn(`Failed to get balance from chain ${publicClient.chain
|
2032
|
+
log.warn(`Failed to get balance from chain ${publicClient.chain.id} for ${ethAddresses.length} addresses: ${errorMessage}`);
|
2025
2033
|
return ethAddresses.map(() => "error");
|
2026
2034
|
}
|
2027
2035
|
}
|
@@ -2589,7 +2597,7 @@ const uniswapV2PairAbi = [{
|
|
2589
2597
|
type: "function"
|
2590
2598
|
}];
|
2591
2599
|
|
2592
|
-
const moduleType$
|
2600
|
+
const moduleType$5 = "evm-uniswapv2";
|
2593
2601
|
const evmUniswapV2TokenId = (chainId, contractAddress) => `${chainId}-evm-uniswapv2-${contractAddress}`.toLowerCase();
|
2594
2602
|
const EvmUniswapV2Module = hydrate => {
|
2595
2603
|
const {
|
@@ -2599,7 +2607,7 @@ const EvmUniswapV2Module = hydrate => {
|
|
2599
2607
|
const chainConnector = chainConnectors.evm;
|
2600
2608
|
assert(chainConnector, "This module requires an evm chain connector");
|
2601
2609
|
return {
|
2602
|
-
...DefaultBalanceModule(moduleType$
|
2610
|
+
...DefaultBalanceModule(moduleType$5),
|
2603
2611
|
async fetchEvmChainMeta(chainId) {
|
2604
2612
|
const isTestnet = (await chaindataProvider.evmNetworkById(chainId))?.isTestnet || false;
|
2605
2613
|
return {
|
@@ -2622,7 +2630,8 @@ const EvmUniswapV2Module = hydrate => {
|
|
2622
2630
|
tokenAddress0,
|
2623
2631
|
tokenAddress1,
|
2624
2632
|
coingeckoId0,
|
2625
|
-
coingeckoId1
|
2633
|
+
coingeckoId1,
|
2634
|
+
name
|
2626
2635
|
} = tokenConfig;
|
2627
2636
|
if (!contractAddress || decimals === undefined || symbol0 === undefined || decimals0 === undefined || symbol1 === undefined || decimals1 === undefined || tokenAddress0 === undefined || tokenAddress1 === undefined) {
|
2628
2637
|
log.warn("ignoring token on chain %s", chainId, tokenConfig);
|
@@ -2632,9 +2641,11 @@ const EvmUniswapV2Module = hydrate => {
|
|
2632
2641
|
const token = {
|
2633
2642
|
id,
|
2634
2643
|
type: "evm-uniswapv2",
|
2644
|
+
platform: "ethereum",
|
2635
2645
|
isTestnet,
|
2636
2646
|
isDefault: tokenConfig.isDefault ?? false,
|
2637
2647
|
symbol: `${symbol0 ?? "UNKNOWN"}/${symbol1 ?? "UNKNOWN"}`,
|
2648
|
+
name: name ?? `${symbol0 ?? "UNKNOWN"}/${symbol1 ?? "UNKNOWN"}`,
|
2638
2649
|
decimals,
|
2639
2650
|
logo: tokenConfig?.logo || githubTokenLogoUrl("uniswap"),
|
2640
2651
|
symbol0,
|
@@ -2646,13 +2657,10 @@ const EvmUniswapV2Module = hydrate => {
|
|
2646
2657
|
tokenAddress1,
|
2647
2658
|
coingeckoId0,
|
2648
2659
|
coingeckoId1,
|
2649
|
-
|
2650
|
-
id: chainId
|
2651
|
-
}
|
2660
|
+
networkId: chainId
|
2652
2661
|
};
|
2653
2662
|
if (tokenConfig?.symbol) token.symbol = tokenConfig?.symbol;
|
2654
2663
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
2655
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
2656
2664
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
2657
2665
|
if (tokenConfig?.noDiscovery) token.noDiscovery = tokenConfig?.noDiscovery;
|
2658
2666
|
tokens[token.id] = token;
|
@@ -2796,7 +2804,7 @@ function groupAddressesByTokenByEvmNetwork(addressesByToken, tokens) {
|
|
2796
2804
|
log.error(`Token ${tokenId} not found`);
|
2797
2805
|
return byChain;
|
2798
2806
|
}
|
2799
|
-
const chainId = token.
|
2807
|
+
const chainId = token.networkId;
|
2800
2808
|
if (!chainId) {
|
2801
2809
|
log.error(`Token ${tokenId} has no evm network`);
|
2802
2810
|
return byChain;
|
@@ -3027,7 +3035,7 @@ const detectTransferMethod = metadataRpc => {
|
|
3027
3035
|
return hasDeprecatedTransferCall ? "transfer" : "transfer_allow_death";
|
3028
3036
|
};
|
3029
3037
|
|
3030
|
-
const getUniqueChainIds = (addressesByToken, tokens) => [...new Set(Object.keys(addressesByToken).map(tokenId => tokens[tokenId]?.
|
3038
|
+
const getUniqueChainIds = (addressesByToken, tokens) => [...new Set(Object.keys(addressesByToken).map(tokenId => tokens[tokenId]?.networkId).flatMap(chainId => chainId ? [chainId] : []))];
|
3031
3039
|
|
3032
3040
|
const makeContractCaller = ({
|
3033
3041
|
chainConnector,
|
@@ -3136,7 +3144,7 @@ const decompress = data => {
|
|
3136
3144
|
return JSON.parse(decompressed);
|
3137
3145
|
};
|
3138
3146
|
|
3139
|
-
const moduleType$
|
3147
|
+
const moduleType$4 = "substrate-assets";
|
3140
3148
|
const subAssetTokenId = (chainId, assetId, tokenSymbol) => `${chainId}-substrate-assets-${assetId}-${tokenSymbol}`.toLowerCase().replace(/ /g, "-");
|
3141
3149
|
const SubAssetsModule = hydrate => {
|
3142
3150
|
const {
|
@@ -3146,7 +3154,7 @@ const SubAssetsModule = hydrate => {
|
|
3146
3154
|
const chainConnector = chainConnectors.substrate;
|
3147
3155
|
assert(chainConnector, "This module requires a substrate chain connector");
|
3148
3156
|
return {
|
3149
|
-
...DefaultBalanceModule(moduleType$
|
3157
|
+
...DefaultBalanceModule(moduleType$4),
|
3150
3158
|
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
3151
3159
|
const isTestnet = (await chaindataProvider.chainById(chainId))?.isTestnet || false;
|
3152
3160
|
if (metadataRpc === undefined) return {
|
@@ -3197,24 +3205,23 @@ const SubAssetsModule = hydrate => {
|
|
3197
3205
|
const token = {
|
3198
3206
|
id,
|
3199
3207
|
type: "substrate-assets",
|
3208
|
+
platform: "polkadot",
|
3200
3209
|
isTestnet,
|
3201
3210
|
isDefault: tokenConfig?.isDefault ?? true,
|
3202
3211
|
symbol,
|
3212
|
+
name: tokenConfig?.name || symbol,
|
3203
3213
|
decimals,
|
3204
3214
|
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
3205
3215
|
existentialDeposit,
|
3206
3216
|
assetId,
|
3207
3217
|
isFrozen,
|
3208
|
-
|
3209
|
-
id: chainId
|
3210
|
-
}
|
3218
|
+
networkId: chainId
|
3211
3219
|
};
|
3212
3220
|
if (tokenConfig?.symbol) {
|
3213
3221
|
token.symbol = tokenConfig?.symbol;
|
3214
3222
|
token.id = subAssetTokenId(chainId, assetId, token.symbol);
|
3215
3223
|
}
|
3216
3224
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
3217
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
3218
3225
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
3219
3226
|
tokens[token.id] = token;
|
3220
3227
|
} catch (error) {
|
@@ -3228,7 +3235,7 @@ const SubAssetsModule = hydrate => {
|
|
3228
3235
|
async subscribeBalances({
|
3229
3236
|
addressesByToken
|
3230
3237
|
}, callback) {
|
3231
|
-
const queries = await buildQueries$
|
3238
|
+
const queries = await buildQueries$3(chaindataProvider, addressesByToken);
|
3232
3239
|
const unsubscribe = await new RpcStateQueryHelper(chainConnector, queries).subscribe((error, result) => {
|
3233
3240
|
if (error) return callback(error);
|
3234
3241
|
const balances = result?.filter(b => b !== null) ?? [];
|
@@ -3238,7 +3245,7 @@ const SubAssetsModule = hydrate => {
|
|
3238
3245
|
},
|
3239
3246
|
async fetchBalances(addressesByToken) {
|
3240
3247
|
assert(chainConnectors.substrate, "This module requires a substrate chain connector");
|
3241
|
-
const queries = await buildQueries$
|
3248
|
+
const queries = await buildQueries$3(chaindataProvider, addressesByToken);
|
3242
3249
|
const result = await new RpcStateQueryHelper(chainConnectors.substrate, queries).fetch();
|
3243
3250
|
const balances = result?.filter(b => b !== null) ?? [];
|
3244
3251
|
return new Balances(balances);
|
@@ -3262,7 +3269,7 @@ const SubAssetsModule = hydrate => {
|
|
3262
3269
|
const token = await chaindataProvider.tokenById(tokenId);
|
3263
3270
|
assert(token, `Token ${tokenId} not found in store`);
|
3264
3271
|
if (token.type !== "substrate-assets") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
3265
|
-
const chainId = token.
|
3272
|
+
const chainId = token.networkId;
|
3266
3273
|
const chain = await chaindataProvider.chainById(chainId);
|
3267
3274
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
3268
3275
|
const {
|
@@ -3308,7 +3315,7 @@ const SubAssetsModule = hydrate => {
|
|
3308
3315
|
}
|
3309
3316
|
};
|
3310
3317
|
};
|
3311
|
-
async function buildQueries$
|
3318
|
+
async function buildQueries$3(chaindataProvider, addressesByToken) {
|
3312
3319
|
const allChains = await chaindataProvider.chainsById();
|
3313
3320
|
const tokens = await chaindataProvider.tokensById();
|
3314
3321
|
const miniMetadatas = new Map((await db.miniMetadatas.toArray()).map(miniMetadata => [miniMetadata.id, miniMetadata]));
|
@@ -3333,7 +3340,7 @@ async function buildQueries$4(chaindataProvider, addressesByToken) {
|
|
3333
3340
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
3334
3341
|
return [];
|
3335
3342
|
}
|
3336
|
-
const chainId = token.
|
3343
|
+
const chainId = token.networkId;
|
3337
3344
|
if (!chainId) {
|
3338
3345
|
log.warn(`Token ${tokenId} has no chain`);
|
3339
3346
|
return [];
|
@@ -3415,274 +3422,6 @@ const tryEncode = (scaleCoder, ...args) => {
|
|
3415
3422
|
}
|
3416
3423
|
};
|
3417
3424
|
|
3418
|
-
const moduleType$4 = "substrate-equilibrium";
|
3419
|
-
const subEquilibriumTokenId = (chainId, tokenSymbol) => `${chainId}-substrate-equilibrium-${tokenSymbol}`.toLowerCase().replace(/ /g, "-");
|
3420
|
-
const SubEquilibriumModule = hydrate => {
|
3421
|
-
const {
|
3422
|
-
chainConnectors,
|
3423
|
-
chaindataProvider
|
3424
|
-
} = hydrate;
|
3425
|
-
const chainConnector = chainConnectors.substrate;
|
3426
|
-
assert(chainConnector, "This module requires a substrate chain connector");
|
3427
|
-
return {
|
3428
|
-
...DefaultBalanceModule(moduleType$4),
|
3429
|
-
async fetchSubstrateChainMeta(chainId, moduleConfig, metadataRpc) {
|
3430
|
-
const isTestnet = (await chaindataProvider.chainById(chainId))?.isTestnet || false;
|
3431
|
-
if (metadataRpc === undefined) return {
|
3432
|
-
isTestnet
|
3433
|
-
};
|
3434
|
-
if (moduleConfig?.disable !== false) return {
|
3435
|
-
isTestnet
|
3436
|
-
}; // default to disabled
|
3437
|
-
|
3438
|
-
const metadataVersion = getMetadataVersion(metadataRpc);
|
3439
|
-
const metadata = decAnyMetadata(metadataRpc);
|
3440
|
-
compactMetadata(metadata, [{
|
3441
|
-
pallet: "EqAssets",
|
3442
|
-
items: ["Assets"]
|
3443
|
-
}, {
|
3444
|
-
pallet: "System",
|
3445
|
-
items: ["Account"]
|
3446
|
-
}]);
|
3447
|
-
const miniMetadata = encodeMetadata(metadata);
|
3448
|
-
return {
|
3449
|
-
isTestnet,
|
3450
|
-
miniMetadata,
|
3451
|
-
metadataVersion
|
3452
|
-
};
|
3453
|
-
},
|
3454
|
-
async fetchSubstrateChainTokens(chainId, chainMeta, moduleConfig) {
|
3455
|
-
// default to disabled
|
3456
|
-
if (moduleConfig?.disable !== false) return {};
|
3457
|
-
const {
|
3458
|
-
isTestnet,
|
3459
|
-
miniMetadata,
|
3460
|
-
metadataVersion
|
3461
|
-
} = chainMeta;
|
3462
|
-
if (miniMetadata === undefined || metadataVersion === undefined) return {};
|
3463
|
-
if (metadataVersion < 14) return {};
|
3464
|
-
try {
|
3465
|
-
const metadata = unifyMetadata(decAnyMetadata(miniMetadata));
|
3466
|
-
const scaleBuilder = getDynamicBuilder(getLookupFn(metadata));
|
3467
|
-
const assetsCoder = scaleBuilder.buildStorage("EqAssets", "Assets");
|
3468
|
-
const stateKey = assetsCoder.keys.enc();
|
3469
|
-
|
3470
|
-
/** NOTE: Just a guideline, the RPC can return whatever it wants */
|
3471
|
-
|
3472
|
-
const assetsResult = await chainConnector.send(chainId, "state_getStorage", [stateKey]).then(result => assetsCoder.value.dec(result) ?? null);
|
3473
|
-
const tokens = (Array.isArray(assetsResult) ? assetsResult : []).flatMap(asset => {
|
3474
|
-
if (!asset) return [];
|
3475
|
-
if (!asset?.id) return [];
|
3476
|
-
const assetId = asset.id.toString(10);
|
3477
|
-
const symbol = tokenSymbolFromU64Id(asset.id);
|
3478
|
-
const id = subEquilibriumTokenId(chainId, symbol);
|
3479
|
-
const decimals = DEFAULT_DECIMALS$1;
|
3480
|
-
const tokenConfig = (moduleConfig?.tokens ?? []).find(token => token.assetId === assetId);
|
3481
|
-
const token = {
|
3482
|
-
id,
|
3483
|
-
type: "substrate-equilibrium",
|
3484
|
-
isTestnet,
|
3485
|
-
isDefault: tokenConfig?.isDefault ?? true,
|
3486
|
-
symbol,
|
3487
|
-
decimals,
|
3488
|
-
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
3489
|
-
// TODO: Fetch the ED
|
3490
|
-
existentialDeposit: "0",
|
3491
|
-
assetId,
|
3492
|
-
chain: {
|
3493
|
-
id: chainId
|
3494
|
-
}
|
3495
|
-
};
|
3496
|
-
if (tokenConfig?.symbol) {
|
3497
|
-
token.symbol = tokenConfig?.symbol;
|
3498
|
-
token.id = subEquilibriumTokenId(chainId, token.symbol);
|
3499
|
-
}
|
3500
|
-
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
3501
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
3502
|
-
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
3503
|
-
return [[token.id, token]];
|
3504
|
-
});
|
3505
|
-
return Object.fromEntries(tokens);
|
3506
|
-
} catch (error) {
|
3507
|
-
log.error(`Failed to build substrate-equilibrium tokens on ${chainId}`, error?.message ?? error);
|
3508
|
-
return {};
|
3509
|
-
}
|
3510
|
-
},
|
3511
|
-
// TODO: Don't create empty subscriptions
|
3512
|
-
async subscribeBalances({
|
3513
|
-
addressesByToken
|
3514
|
-
}, callback) {
|
3515
|
-
const queries = await buildQueries$3(chaindataProvider, addressesByToken);
|
3516
|
-
const unsubscribe = await new RpcStateQueryHelper(chainConnector, queries).subscribe((error, result) => {
|
3517
|
-
if (error) return callback(error);
|
3518
|
-
const balances = result?.flatMap(balances => balances) ?? [];
|
3519
|
-
if (balances.length > 0) callback(null, new Balances(balances));
|
3520
|
-
});
|
3521
|
-
return unsubscribe;
|
3522
|
-
},
|
3523
|
-
async fetchBalances(addressesByToken) {
|
3524
|
-
assert(chainConnectors.substrate, "This module requires a substrate chain connector");
|
3525
|
-
const queries = await buildQueries$3(chaindataProvider, addressesByToken);
|
3526
|
-
const result = await new RpcStateQueryHelper(chainConnectors.substrate, queries).fetch();
|
3527
|
-
const balances = result?.flatMap(balances => balances) ?? [];
|
3528
|
-
return new Balances(balances);
|
3529
|
-
},
|
3530
|
-
async transferToken({
|
3531
|
-
tokenId,
|
3532
|
-
from,
|
3533
|
-
to,
|
3534
|
-
amount,
|
3535
|
-
registry,
|
3536
|
-
metadataRpc,
|
3537
|
-
blockHash,
|
3538
|
-
blockNumber,
|
3539
|
-
nonce,
|
3540
|
-
specVersion,
|
3541
|
-
transactionVersion,
|
3542
|
-
tip,
|
3543
|
-
transferMethod,
|
3544
|
-
userExtensions
|
3545
|
-
}) {
|
3546
|
-
const token = await chaindataProvider.tokenById(tokenId);
|
3547
|
-
assert(token, `Token ${tokenId} not found in store`);
|
3548
|
-
if (token.type !== "substrate-equilibrium") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
3549
|
-
const chainId = token.chain.id;
|
3550
|
-
const chain = await chaindataProvider.chainById(chainId);
|
3551
|
-
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
3552
|
-
const {
|
3553
|
-
genesisHash
|
3554
|
-
} = chain;
|
3555
|
-
const {
|
3556
|
-
assetId
|
3557
|
-
} = token;
|
3558
|
-
const pallet = "EqBalances";
|
3559
|
-
const method = transferMethod === "transfer_all" ?
|
3560
|
-
// the eqBalances pallet has no transfer_all method
|
3561
|
-
"transfer" : transferMethod === "transfer_keep_alive" ?
|
3562
|
-
// the eqBalances pallet has no transfer_keep_alive method
|
3563
|
-
"transfer" : "transfer";
|
3564
|
-
const args = {
|
3565
|
-
asset: assetId,
|
3566
|
-
to,
|
3567
|
-
value: amount
|
3568
|
-
};
|
3569
|
-
const unsigned = defineMethod({
|
3570
|
-
method: {
|
3571
|
-
pallet: camelCase(pallet),
|
3572
|
-
name: camelCase(method),
|
3573
|
-
args
|
3574
|
-
},
|
3575
|
-
address: from,
|
3576
|
-
blockHash,
|
3577
|
-
blockNumber,
|
3578
|
-
eraPeriod: 64,
|
3579
|
-
genesisHash,
|
3580
|
-
metadataRpc,
|
3581
|
-
nonce,
|
3582
|
-
specVersion,
|
3583
|
-
tip: tip ? Number(tip) : 0,
|
3584
|
-
transactionVersion
|
3585
|
-
}, {
|
3586
|
-
metadataRpc,
|
3587
|
-
registry,
|
3588
|
-
userExtensions
|
3589
|
-
});
|
3590
|
-
return {
|
3591
|
-
type: "substrate",
|
3592
|
-
callData: unsigned.method
|
3593
|
-
};
|
3594
|
-
}
|
3595
|
-
};
|
3596
|
-
};
|
3597
|
-
async function buildQueries$3(chaindataProvider, addressesByToken) {
|
3598
|
-
const allChains = await chaindataProvider.chainsById();
|
3599
|
-
const tokens = await chaindataProvider.tokensById();
|
3600
|
-
const miniMetadatas = new Map((await db.miniMetadatas.toArray()).map(miniMetadata => [miniMetadata.id, miniMetadata]));
|
3601
|
-
const uniqueChainIds = getUniqueChainIds(addressesByToken, tokens);
|
3602
|
-
const chains = Object.fromEntries(uniqueChainIds.map(chainId => [chainId, allChains[chainId]]));
|
3603
|
-
const chainStorageCoders = buildStorageCoders({
|
3604
|
-
chainIds: uniqueChainIds,
|
3605
|
-
chains,
|
3606
|
-
miniMetadatas,
|
3607
|
-
moduleType: "substrate-equilibrium",
|
3608
|
-
coders: {
|
3609
|
-
storage: ["System", "Account"]
|
3610
|
-
}
|
3611
|
-
});
|
3612
|
-
|
3613
|
-
// equilibrium returns all chain tokens for each address in the one query
|
3614
|
-
// so, we only need to make one query per address, rather than one query per token per address
|
3615
|
-
const addressesByChain = new Map();
|
3616
|
-
const tokensByAddress = new Map();
|
3617
|
-
Object.entries(addressesByToken).map(([tokenId, addresses]) => {
|
3618
|
-
const token = tokens[tokenId];
|
3619
|
-
if (!token) return log.warn(`Token ${tokenId} not found`);
|
3620
|
-
if (token.type !== "substrate-equilibrium") return log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
3621
|
-
const chainId = token?.chain?.id;
|
3622
|
-
if (!chainId) return log.warn(`Token ${tokenId} has no chain`);
|
3623
|
-
const byChain = addressesByChain.get(chainId) ?? new Set();
|
3624
|
-
addresses.forEach(address => {
|
3625
|
-
byChain?.add(address);
|
3626
|
-
tokensByAddress.set(address, (tokensByAddress.get(address) ?? new Set()).add(token));
|
3627
|
-
});
|
3628
|
-
addressesByChain.set(chainId, byChain);
|
3629
|
-
});
|
3630
|
-
return Array.from(addressesByChain).flatMap(([chainId, addresses]) => {
|
3631
|
-
const chain = chains[chainId];
|
3632
|
-
if (!chain) {
|
3633
|
-
log.warn(`Chain ${chainId} not found`);
|
3634
|
-
return [];
|
3635
|
-
}
|
3636
|
-
return Array.from(addresses).flatMap(address => {
|
3637
|
-
const scaleCoder = chainStorageCoders.get(chainId)?.storage;
|
3638
|
-
const stateKey = encodeStateKey(scaleCoder, `Invalid address in ${chainId} storage query ${address}`, address);
|
3639
|
-
if (!stateKey) return [];
|
3640
|
-
const decodeResult = change => {
|
3641
|
-
/** NOTE: This type is only a hint for typescript, the chain can actually return whatever it wants to */
|
3642
|
-
|
3643
|
-
const decoded = decodeScale(scaleCoder, change, `Failed to decode eqBalances on chain ${chainId}`);
|
3644
|
-
const tokenBalances = Object.fromEntries((decoded?.data?.value?.balance ?? []).map(balance => ({
|
3645
|
-
id: (balance?.[0] ?? 0n)?.toString?.(),
|
3646
|
-
free: balance?.[1]?.type === "Positive" ? (balance?.[1]?.value ?? 0n).toString() : balance?.[1]?.type === "Negative" ? ((balance?.[1]?.value ?? 0n) * -1n).toString() : "0"
|
3647
|
-
})).map(({
|
3648
|
-
id,
|
3649
|
-
free
|
3650
|
-
}) => [id, free]).filter(([id, free]) => id !== undefined && free !== undefined));
|
3651
|
-
const result = Array.from(tokensByAddress.get(address) ?? []).filter(t => t.chain.id === chainId).map(token => {
|
3652
|
-
const value = tokenBalances[token.assetId];
|
3653
|
-
return {
|
3654
|
-
source: "substrate-equilibrium",
|
3655
|
-
status: "live",
|
3656
|
-
address,
|
3657
|
-
multiChainId: {
|
3658
|
-
subChainId: chainId
|
3659
|
-
},
|
3660
|
-
chainId,
|
3661
|
-
tokenId: token.id,
|
3662
|
-
value
|
3663
|
-
};
|
3664
|
-
}).filter(b => b !== undefined);
|
3665
|
-
return result;
|
3666
|
-
};
|
3667
|
-
return {
|
3668
|
-
chainId,
|
3669
|
-
stateKey,
|
3670
|
-
decodeResult
|
3671
|
-
};
|
3672
|
-
});
|
3673
|
-
});
|
3674
|
-
}
|
3675
|
-
const DEFAULT_DECIMALS$1 = 9;
|
3676
|
-
const tokenSymbolFromU64Id = u64 => {
|
3677
|
-
const bytes = [];
|
3678
|
-
let num = typeof u64 === "number" ? BigInt(u64) : isBigInt(u64) ? u64 : u64.toBigInt();
|
3679
|
-
do {
|
3680
|
-
bytes.unshift(Number(num % 256n));
|
3681
|
-
num = num / 256n;
|
3682
|
-
} while (num > 0);
|
3683
|
-
return new TextDecoder("utf-8").decode(new Uint8Array(bytes)).toUpperCase();
|
3684
|
-
};
|
3685
|
-
|
3686
3425
|
const moduleType$3 = "substrate-foreignassets";
|
3687
3426
|
const subForeignAssetTokenId = (chainId, tokenSymbol) => `${chainId}-substrate-foreignassets-${tokenSymbol}`.toLowerCase().replace(/ /g, "-");
|
3688
3427
|
const SubForeignAssetsModule = hydrate => {
|
@@ -3751,24 +3490,23 @@ const SubForeignAssetsModule = hydrate => {
|
|
3751
3490
|
const token = {
|
3752
3491
|
id,
|
3753
3492
|
type: "substrate-foreignassets",
|
3493
|
+
platform: "polkadot",
|
3754
3494
|
isTestnet,
|
3755
3495
|
isDefault: tokenConfig?.isDefault ?? true,
|
3756
3496
|
symbol,
|
3757
3497
|
decimals,
|
3498
|
+
name: tokenConfig?.name || symbol,
|
3758
3499
|
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
3759
3500
|
existentialDeposit,
|
3760
3501
|
onChainId: tokenConfig.onChainId,
|
3761
3502
|
isFrozen,
|
3762
|
-
|
3763
|
-
id: chainId
|
3764
|
-
}
|
3503
|
+
networkId: chainId
|
3765
3504
|
};
|
3766
3505
|
if (tokenConfig?.symbol) {
|
3767
3506
|
token.symbol = tokenConfig?.symbol;
|
3768
3507
|
token.id = subForeignAssetTokenId(chainId, token.symbol);
|
3769
3508
|
}
|
3770
3509
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
3771
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
3772
3510
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
3773
3511
|
tokens[token.id] = token;
|
3774
3512
|
} catch (error) {
|
@@ -3807,7 +3545,7 @@ const SubForeignAssetsModule = hydrate => {
|
|
3807
3545
|
const token = await chaindataProvider.tokenById(tokenId);
|
3808
3546
|
assert(token, `Token ${tokenId} not found in store`);
|
3809
3547
|
if (token.type !== "substrate-foreignassets") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
3810
|
-
const chainId = token.
|
3548
|
+
const chainId = token.networkId;
|
3811
3549
|
const chain = await chaindataProvider.chainById(chainId);
|
3812
3550
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
3813
3551
|
const onChainId = (() => {
|
@@ -3873,7 +3611,7 @@ async function buildQueries$2(chaindataProvider, addressesByToken) {
|
|
3873
3611
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
3874
3612
|
return [];
|
3875
3613
|
}
|
3876
|
-
const chainId = token.
|
3614
|
+
const chainId = token.networkId;
|
3877
3615
|
if (!chainId) {
|
3878
3616
|
log.warn(`Token ${tokenId} has no chain`);
|
3879
3617
|
return [];
|
@@ -3982,7 +3720,7 @@ async function subscribeCrowdloans(chaindataProvider, chainConnector, addressesB
|
|
3982
3720
|
// ignore non-native tokens
|
3983
3721
|
if (token.type !== "substrate-native") return;
|
3984
3722
|
// ignore tokens on chains with no crowdloans pallet
|
3985
|
-
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.
|
3723
|
+
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.networkId]);
|
3986
3724
|
return typeof chainMeta?.crowdloanPalletId === "string";
|
3987
3725
|
}).map(([tokenId]) => tokenId);
|
3988
3726
|
|
@@ -4015,7 +3753,7 @@ async function subscribeCrowdloans(chaindataProvider, chainConnector, addressesB
|
|
4015
3753
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
4016
3754
|
continue;
|
4017
3755
|
}
|
4018
|
-
const chainId = token.
|
3756
|
+
const chainId = token.networkId;
|
4019
3757
|
if (!chainId) {
|
4020
3758
|
log.warn(`Token ${tokenId} has no chain`);
|
4021
3759
|
continue;
|
@@ -4252,7 +3990,7 @@ async function subscribeNompoolStaking(chaindataProvider, chainConnector, addres
|
|
4252
3990
|
// ignore non-native tokens
|
4253
3991
|
if (token.type !== "substrate-native") return false;
|
4254
3992
|
// ignore tokens on chains with no nompools pallet
|
4255
|
-
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.
|
3993
|
+
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.networkId]);
|
4256
3994
|
return typeof chainMeta?.nominationPoolsPalletId === "string";
|
4257
3995
|
}).map(([tokenId]) => tokenId);
|
4258
3996
|
|
@@ -4287,7 +4025,7 @@ async function subscribeNompoolStaking(chaindataProvider, chainConnector, addres
|
|
4287
4025
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
4288
4026
|
continue;
|
4289
4027
|
}
|
4290
|
-
const chainId = token.
|
4028
|
+
const chainId = token.networkId;
|
4291
4029
|
if (!chainId) {
|
4292
4030
|
log.warn(`Token ${tokenId} has no chain`);
|
4293
4031
|
continue;
|
@@ -4567,7 +4305,7 @@ async function subscribeSubtensorStaking(chaindataProvider, chainConnector, addr
|
|
4567
4305
|
// ignore non-native tokens
|
4568
4306
|
if (token.type !== "substrate-native") return false;
|
4569
4307
|
// ignore tokens on chains with no subtensor pallet
|
4570
|
-
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.
|
4308
|
+
const [chainMeta] = findChainMeta(miniMetadatas, "substrate-native", allChains[token.networkId]);
|
4571
4309
|
return chainMeta?.hasSubtensorPallet === true;
|
4572
4310
|
}).map(([tokenId]) => tokenId);
|
4573
4311
|
|
@@ -4590,7 +4328,7 @@ async function subscribeSubtensorStaking(chaindataProvider, chainConnector, addr
|
|
4590
4328
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
4591
4329
|
continue;
|
4592
4330
|
}
|
4593
|
-
const chainId = token.
|
4331
|
+
const chainId = token.networkId;
|
4594
4332
|
if (!chainId) {
|
4595
4333
|
log.warn(`Token ${tokenId} has no chain`);
|
4596
4334
|
continue;
|
@@ -4934,7 +4672,7 @@ async function buildQueries$1(chains, tokens, chainStorageCoders, miniMetadatas,
|
|
4934
4672
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
4935
4673
|
return outerResult;
|
4936
4674
|
}
|
4937
|
-
const chainId = token.
|
4675
|
+
const chainId = token.networkId;
|
4938
4676
|
if (!chainId) {
|
4939
4677
|
log.warn(`Token ${tokenId} has no chain`);
|
4940
4678
|
return outerResult;
|
@@ -5275,8 +5013,8 @@ class QueryCache {
|
|
5275
5013
|
this.metadataSub = commonMetadataObservable.pipe(firstThenDebounce(500), detectMiniMetadataChanges(), combineLatestWith(this.chaindataProvider.tokensObservable), distinctUntilChanged()).subscribe(([miniMetadataChanges, tokens]) => {
|
5276
5014
|
// invalidate cache entries for any chains with new metadata
|
5277
5015
|
const tokensByChainId = tokens.filter(token => token.type === "substrate-native").reduce((result, token) => {
|
5278
|
-
if (!token.
|
5279
|
-
result[token.
|
5016
|
+
if (!token.networkId) return result;
|
5017
|
+
result[token.networkId] ? result[token.networkId].push(token) : result[token.networkId] = [token];
|
5280
5018
|
return result;
|
5281
5019
|
}, {});
|
5282
5020
|
miniMetadataChanges.forEach(chainId => {
|
@@ -5495,19 +5233,18 @@ const SubNativeModule = hydrate => {
|
|
5495
5233
|
const nativeToken = {
|
5496
5234
|
id,
|
5497
5235
|
type: "substrate-native",
|
5236
|
+
platform: "polkadot",
|
5498
5237
|
isTestnet,
|
5499
5238
|
isDefault: moduleConfig?.isDefault ?? true,
|
5500
5239
|
symbol: symbol ?? DEFAULT_SYMBOL,
|
5240
|
+
name: moduleConfig?.name ?? symbol ?? DEFAULT_SYMBOL,
|
5501
5241
|
decimals: decimals ?? DEFAULT_DECIMALS,
|
5502
5242
|
logo: moduleConfig?.logo || githubTokenLogoUrl(id),
|
5503
5243
|
existentialDeposit: existentialDeposit ?? "0",
|
5504
|
-
|
5505
|
-
id: chainId
|
5506
|
-
}
|
5244
|
+
networkId: chainId
|
5507
5245
|
};
|
5508
5246
|
if (moduleConfig?.symbol) nativeToken.symbol = moduleConfig?.symbol;
|
5509
5247
|
if (moduleConfig?.coingeckoId) nativeToken.coingeckoId = moduleConfig?.coingeckoId;
|
5510
|
-
if (moduleConfig?.dcentName) nativeToken.dcentName = moduleConfig?.dcentName;
|
5511
5248
|
if (moduleConfig?.mirrorOf) nativeToken.mirrorOf = moduleConfig?.mirrorOf;
|
5512
5249
|
return {
|
5513
5250
|
[nativeToken.id]: nativeToken
|
@@ -5635,7 +5372,7 @@ const SubNativeModule = hydrate => {
|
|
5635
5372
|
if (error instanceof ChainConnectionError) {
|
5636
5373
|
// coerce ChainConnection errors into SubNativeBalance errors
|
5637
5374
|
const errorChainId = error.chainId;
|
5638
|
-
Object.entries(await getModuleTokens()).filter(([, token]) => token.
|
5375
|
+
Object.entries(await getModuleTokens()).filter(([, token]) => token.networkId === errorChainId).forEach(([tokenId]) => {
|
5639
5376
|
const wrappedError = new SubNativeBalanceError(tokenId, error.message);
|
5640
5377
|
handleUpdate(wrappedError);
|
5641
5378
|
});
|
@@ -5700,7 +5437,7 @@ const SubNativeModule = hydrate => {
|
|
5700
5437
|
const token = await chaindataProvider.tokenById(tokenId);
|
5701
5438
|
assert(token, `Token ${tokenId} not found in store`);
|
5702
5439
|
if (token.type !== "substrate-native") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
5703
|
-
const chainId = token.
|
5440
|
+
const chainId = token.networkId;
|
5704
5441
|
const chain = await chaindataProvider.chainById(chainId);
|
5705
5442
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
5706
5443
|
const {
|
@@ -6949,23 +6686,22 @@ const SubPsp22Module = hydrate => {
|
|
6949
6686
|
const token = {
|
6950
6687
|
id,
|
6951
6688
|
type: "substrate-psp22",
|
6689
|
+
platform: "polkadot",
|
6952
6690
|
isTestnet,
|
6953
6691
|
isDefault: tokenConfig.isDefault ?? true,
|
6954
6692
|
symbol,
|
6955
6693
|
decimals,
|
6694
|
+
name: tokenConfig?.name || symbol,
|
6956
6695
|
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
6957
6696
|
existentialDeposit,
|
6958
6697
|
contractAddress,
|
6959
|
-
|
6960
|
-
id: chainId
|
6961
|
-
}
|
6698
|
+
networkId: chainId
|
6962
6699
|
};
|
6963
6700
|
if (tokenConfig?.symbol) {
|
6964
6701
|
token.symbol = tokenConfig?.symbol;
|
6965
6702
|
token.id = subPsp22TokenId(chainId, token.symbol);
|
6966
6703
|
}
|
6967
6704
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
6968
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
6969
6705
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
6970
6706
|
tokens[token.id] = token;
|
6971
6707
|
} catch (error) {
|
@@ -7031,7 +6767,7 @@ const SubPsp22Module = hydrate => {
|
|
7031
6767
|
const token = await chaindataProvider.tokenById(tokenId);
|
7032
6768
|
assert(token, `Token ${tokenId} not found in store`);
|
7033
6769
|
if (token.type !== "substrate-psp22") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
7034
|
-
const chainId = token.
|
6770
|
+
const chainId = token.networkId;
|
7035
6771
|
const chain = await chaindataProvider.chainById(chainId);
|
7036
6772
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
7037
6773
|
const {
|
@@ -7108,7 +6844,7 @@ const fetchBalances = async (chainConnector, tokens, addressesByToken) => {
|
|
7108
6844
|
// TODO: Use `decodeOutput` from `./util/decodeOutput`
|
7109
6845
|
const contractCall = makeContractCaller({
|
7110
6846
|
chainConnector,
|
7111
|
-
chainId: token.
|
6847
|
+
chainId: token.networkId,
|
7112
6848
|
registry
|
7113
6849
|
});
|
7114
6850
|
if (token.contractAddress === undefined) {
|
@@ -7126,9 +6862,9 @@ const fetchBalances = async (chainConnector, tokens, addressesByToken) => {
|
|
7126
6862
|
status: "live",
|
7127
6863
|
address,
|
7128
6864
|
multiChainId: {
|
7129
|
-
subChainId: token.
|
6865
|
+
subChainId: token.networkId
|
7130
6866
|
},
|
7131
|
-
chainId: token.
|
6867
|
+
chainId: token.networkId,
|
7132
6868
|
tokenId,
|
7133
6869
|
value: balance
|
7134
6870
|
};
|
@@ -7205,23 +6941,22 @@ const SubTokensModule = hydrate => {
|
|
7205
6941
|
const token = {
|
7206
6942
|
id,
|
7207
6943
|
type: "substrate-tokens",
|
6944
|
+
platform: "polkadot",
|
7208
6945
|
isTestnet,
|
7209
6946
|
isDefault: tokenConfig.isDefault ?? true,
|
7210
6947
|
symbol,
|
7211
6948
|
decimals,
|
6949
|
+
name: tokenConfig?.name ?? symbol,
|
7212
6950
|
logo: tokenConfig?.logo || githubTokenLogoUrl(id),
|
7213
6951
|
existentialDeposit,
|
7214
6952
|
onChainId,
|
7215
|
-
|
7216
|
-
id: chainId
|
7217
|
-
}
|
6953
|
+
networkId: chainId
|
7218
6954
|
};
|
7219
6955
|
if (tokenConfig?.symbol) {
|
7220
6956
|
token.symbol = tokenConfig?.symbol;
|
7221
6957
|
token.id = subTokensTokenId(chainId, token.onChainId);
|
7222
6958
|
}
|
7223
6959
|
if (tokenConfig?.coingeckoId) token.coingeckoId = tokenConfig?.coingeckoId;
|
7224
|
-
if (tokenConfig?.dcentName) token.dcentName = tokenConfig?.dcentName;
|
7225
6960
|
if (tokenConfig?.mirrorOf) token.mirrorOf = tokenConfig?.mirrorOf;
|
7226
6961
|
tokens[token.id] = token;
|
7227
6962
|
} catch (error) {
|
@@ -7260,7 +6995,7 @@ const SubTokensModule = hydrate => {
|
|
7260
6995
|
const token = await chaindataProvider.tokenById(tokenId);
|
7261
6996
|
assert(token, `Token ${tokenId} not found in store`);
|
7262
6997
|
if (token.type !== "substrate-tokens") throw new Error(`This module doesn't handle tokens of type ${token.type}`);
|
7263
|
-
const chainId = token.
|
6998
|
+
const chainId = token.networkId;
|
7264
6999
|
const chain = await chaindataProvider.chainById(chainId);
|
7265
7000
|
assert(chain?.genesisHash, `Chain ${chainId} not found in store`);
|
7266
7001
|
const miniMetadatas = new Map((await db.miniMetadatas.toArray()).map(miniMetadata => [miniMetadata.id, miniMetadata]));
|
@@ -7392,7 +7127,7 @@ async function buildQueries(chaindataProvider, addressesByToken) {
|
|
7392
7127
|
log.debug(`This module doesn't handle tokens of type ${token.type}`);
|
7393
7128
|
return [];
|
7394
7129
|
}
|
7395
|
-
const chainId = token.
|
7130
|
+
const chainId = token.networkId;
|
7396
7131
|
if (!chainId) {
|
7397
7132
|
log.warn(`Token ${tokenId} has no chain`);
|
7398
7133
|
return [];
|
@@ -7458,7 +7193,7 @@ async function buildQueries(chaindataProvider, addressesByToken) {
|
|
7458
7193
|
});
|
7459
7194
|
}
|
7460
7195
|
|
7461
|
-
const defaultBalanceModules = [EvmErc20Module, EvmNativeModule, EvmUniswapV2Module, SubAssetsModule,
|
7196
|
+
const defaultBalanceModules = [EvmErc20Module, EvmNativeModule, EvmUniswapV2Module, SubAssetsModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule];
|
7462
7197
|
|
7463
7198
|
/** Pulls the latest chaindata from https://github.com/TalismanSociety/chaindata */
|
7464
7199
|
const hydrateChaindataAndMiniMetadata = async (chaindataProvider, miniMetadataUpdater) => {
|
@@ -7486,4 +7221,4 @@ const updateEvmTokens = async (chaindataProvider, evmTokenFetcher) => {
|
|
7486
7221
|
await evmTokenFetcher.update(evmNetworkIds);
|
7487
7222
|
};
|
7488
7223
|
|
7489
|
-
export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, MiniMetadataUpdater, ONE_ALPHA_TOKEN, PlanckSumBalancesFormatter, RpcStateQueryHelper, SCALE_FACTOR, SUBTENSOR_MIN_STAKE_AMOUNT_PLANK, SUBTENSOR_ROOT_NETUID, SubAssetsModule,
|
7224
|
+
export { Balance, BalanceFormatter, BalanceValueGetter, Balances, Change24hCurrencyFormatter, DefaultBalanceModule, EvmErc20Module, EvmNativeModule, EvmTokenFetcher, EvmUniswapV2Module, FiatSumBalancesFormatter, MiniMetadataUpdater, ONE_ALPHA_TOKEN, PlanckSumBalancesFormatter, RpcStateQueryHelper, SCALE_FACTOR, SUBTENSOR_MIN_STAKE_AMOUNT_PLANK, SUBTENSOR_ROOT_NETUID, SubAssetsModule, SubForeignAssetsModule, SubNativeModule, SubPsp22Module, SubTokensModule, SumBalancesFormatter, TalismanBalancesDatabase, abiMulticall, balances, buildStorageCoders, calculateAlphaPrice, calculateTaoAmountFromAlpha, calculateTaoFromDynamicInfo, compress, configureStore, db, decodeOutput, decompress, defaultBalanceModules, deriveMiniMetadataId, detectTransferMethod, erc20Abi, erc20BalancesAggregatorAbi, evmErc20TokenId, evmNativeTokenId, evmUniswapV2TokenId, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterBaseLocks, filterMirrorTokens, findChainMeta, getBalanceId, getLockTitle, getUniqueChainIds, getValueId, hydrateChaindataAndMiniMetadata, includeInTotalExtraAmount, makeContractCaller, subAssetTokenId, subForeignAssetTokenId, subNativeTokenId, subPsp22TokenId, subTokensTokenId, uniswapV2PairAbi, updateCustomMiniMetadata, updateEvmTokens };
|