@talismn/balances 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +132 -182
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +121 -171
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +226 -322
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -320
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let bignumber_js = require("bignumber.js");
|
|
25
24
|
bignumber_js = __toESM(bignumber_js);
|
|
26
25
|
let _talismn_chaindata_provider = require("@talismn/chaindata-provider");
|
|
@@ -49,11 +48,10 @@ let _talismn_sapi = require("@talismn/sapi");
|
|
|
49
48
|
let lodash_es_upperFirst = require("lodash-es/upperFirst");
|
|
50
49
|
lodash_es_upperFirst = __toESM(lodash_es_upperFirst);
|
|
51
50
|
let scale_ts = require("scale-ts");
|
|
52
|
-
|
|
51
|
+
// src/configureBigNumber.ts
|
|
53
52
|
bignumber_js.default.set({ STRICT: false });
|
|
54
53
|
var configureBigNumber_default = bignumber_js.default;
|
|
55
|
-
|
|
56
|
-
//#region src/classes/formatters.ts
|
|
54
|
+
// src/classes/formatters.ts
|
|
57
55
|
var BalanceValueGetter = class {
|
|
58
56
|
#storage;
|
|
59
57
|
constructor(storage) {
|
|
@@ -249,8 +247,7 @@ var Change24hCurrencyFormatter = class {
|
|
|
249
247
|
return this.#change24h("feePayable");
|
|
250
248
|
}
|
|
251
249
|
};
|
|
252
|
-
|
|
253
|
-
//#region src/classes/helpers.ts
|
|
250
|
+
// src/classes/helpers.ts
|
|
254
251
|
function excludeFromTransferableAmount(locks) {
|
|
255
252
|
if (typeof locks === "string") return BigInt(locks);
|
|
256
253
|
if (!Array.isArray(locks)) locks = [locks];
|
|
@@ -278,8 +275,7 @@ const filterMirrorTokens = (balance, _i, balances) => {
|
|
|
278
275
|
const mirrorOf = balance.token?.mirrorOf;
|
|
279
276
|
return !mirrorOf || !balances.find((b) => b.tokenId === mirrorOf);
|
|
280
277
|
};
|
|
281
|
-
|
|
282
|
-
//#region src/classes/Balance.ts
|
|
278
|
+
// src/classes/Balance.ts
|
|
283
279
|
var Balance = class {
|
|
284
280
|
/** The underlying data for this balance */
|
|
285
281
|
#storage;
|
|
@@ -526,11 +522,9 @@ var Balance = class {
|
|
|
526
522
|
return this.#format(_talismn_util.BigMath.max(this.free.planck - excludeAmount, 0n));
|
|
527
523
|
};
|
|
528
524
|
};
|
|
529
|
-
|
|
530
|
-
//#region src/log.ts
|
|
525
|
+
// src/log.ts
|
|
531
526
|
var log_default = (0, anylogger.default)("@talismn/balances");
|
|
532
|
-
|
|
533
|
-
//#region src/classes/Balances.ts
|
|
527
|
+
// src/classes/Balances.ts
|
|
534
528
|
/**
|
|
535
529
|
* A collection of balances.
|
|
536
530
|
*/
|
|
@@ -686,8 +680,7 @@ var Balances = class Balances {
|
|
|
686
680
|
return this.#cachedSumFormatter;
|
|
687
681
|
}
|
|
688
682
|
};
|
|
689
|
-
|
|
690
|
-
//#region src/classes/rawBalance.ts
|
|
683
|
+
// src/classes/rawBalance.ts
|
|
691
684
|
const getRawValues = (balance, valueType) => "values" in balance && balance.values ? balance.values.filter(({ type }) => type === valueType) : [];
|
|
692
685
|
/** raw "locked" values, straight from the IBalance JSON (see getRawTotalPlanck) */
|
|
693
686
|
const getRawLocks = (balance) => getRawValues(balance, "locked");
|
|
@@ -705,15 +698,12 @@ const getRawTotalPlanck = (balance) => {
|
|
|
705
698
|
const extra = getRawValues(balance, "extra").filter((extra) => extra.includeInTotal).reduce((sum, { amount }) => sum + BigInt(amount), 0n);
|
|
706
699
|
return free + reserved + nomPoolStakedPlancks + extra;
|
|
707
700
|
};
|
|
708
|
-
|
|
709
|
-
//#region src/modules/evm-erc20/config.ts
|
|
701
|
+
// src/modules/evm-erc20/config.ts
|
|
710
702
|
const MODULE_TYPE$12 = _talismn_chaindata_provider.EvmErc20TokenSchema.shape.type.value;
|
|
711
703
|
const PLATFORM$12 = _talismn_chaindata_provider.EvmErc20TokenSchema.shape.platform.value;
|
|
712
|
-
|
|
713
|
-
//#region src/modules/abis/erc20BalancesAggregator.ts
|
|
704
|
+
// src/modules/abis/erc20BalancesAggregator.ts
|
|
714
705
|
const erc20BalancesAggregatorAbi = (0, viem.parseAbi)(["struct AccountToken {address account; address token;}", "function balances(AccountToken[] memory accountTokens) public view returns (uint256[] memory)"]);
|
|
715
|
-
|
|
716
|
-
//#region src/modules/abis/multicall.ts
|
|
706
|
+
// src/modules/abis/multicall.ts
|
|
717
707
|
const abiMulticall = (0, viem.parseAbi)([
|
|
718
708
|
"struct Call { address target; bytes callData; }",
|
|
719
709
|
"struct Call3 { address target; bool allowFailure; bytes callData; }",
|
|
@@ -736,8 +726,7 @@ const abiMulticall = (0, viem.parseAbi)([
|
|
|
736
726
|
"function tryAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (Result[] memory returnData)",
|
|
737
727
|
"function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls) public payable returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData)"
|
|
738
728
|
]);
|
|
739
|
-
|
|
740
|
-
//#region src/modules/abis/uniswapV2Pair.ts
|
|
729
|
+
// src/modules/abis/uniswapV2Pair.ts
|
|
741
730
|
const uniswapV2PairAbi = [
|
|
742
731
|
{
|
|
743
732
|
anonymous: false,
|
|
@@ -1377,8 +1366,7 @@ const uniswapV2PairAbi = [
|
|
|
1377
1366
|
type: "function"
|
|
1378
1367
|
}
|
|
1379
1368
|
];
|
|
1380
|
-
|
|
1381
|
-
//#region src/modules/shared/errors.ts
|
|
1369
|
+
// src/modules/shared/errors.ts
|
|
1382
1370
|
var BalanceFetchError = class extends Error {
|
|
1383
1371
|
tokenId;
|
|
1384
1372
|
address;
|
|
@@ -1399,16 +1387,14 @@ var BalanceFetchNetworkError = class extends Error {
|
|
|
1399
1387
|
if (cause) this.cause = cause;
|
|
1400
1388
|
}
|
|
1401
1389
|
};
|
|
1402
|
-
|
|
1403
|
-
//#region src/modules/shared/types.ts
|
|
1390
|
+
// src/modules/shared/types.ts
|
|
1404
1391
|
const getBalanceDefs = (addressesByToken) => {
|
|
1405
1392
|
return addressesByToken.flatMap(([token, addresses]) => addresses.map((address) => ({
|
|
1406
1393
|
token,
|
|
1407
1394
|
address
|
|
1408
1395
|
})));
|
|
1409
1396
|
};
|
|
1410
|
-
|
|
1411
|
-
//#region src/modules/evm-erc20/fetchBalances.ts
|
|
1397
|
+
// src/modules/evm-erc20/fetchBalances.ts
|
|
1412
1398
|
const fetchBalances$12 = async ({ networkId, tokensWithAddresses, connector }) => {
|
|
1413
1399
|
if (!tokensWithAddresses.length) return {
|
|
1414
1400
|
success: [],
|
|
@@ -1504,8 +1490,7 @@ const fetchWithAggregator = async (client, balanceDefs, erc20BalancesAggregatorA
|
|
|
1504
1490
|
};
|
|
1505
1491
|
}
|
|
1506
1492
|
};
|
|
1507
|
-
|
|
1508
|
-
//#region src/modules/evm-erc20/utils.ts
|
|
1493
|
+
// src/modules/evm-erc20/utils.ts
|
|
1509
1494
|
const getErc20ContractData$1 = async (client, contractAddress) => {
|
|
1510
1495
|
try {
|
|
1511
1496
|
const contract = getTypedContract$1(client, viem.erc20Abi, contractAddress);
|
|
@@ -1537,8 +1522,7 @@ const getTypedContract$1 = (client, abi, contractAddress) => (0, viem.getContrac
|
|
|
1537
1522
|
abi,
|
|
1538
1523
|
client: { public: client }
|
|
1539
1524
|
});
|
|
1540
|
-
|
|
1541
|
-
//#region src/modules/evm-erc20/fetchTokens.ts
|
|
1525
|
+
// src/modules/evm-erc20/fetchTokens.ts
|
|
1542
1526
|
const TokenCacheSchema$3 = zod_v4.default.discriminatedUnion("isValid", [zod_v4.default.strictObject({
|
|
1543
1527
|
id: _talismn_chaindata_provider.EvmErc20TokenSchema.shape.id,
|
|
1544
1528
|
isValid: zod_v4.default.literal(true),
|
|
@@ -1598,13 +1582,11 @@ const fetchTokens$12 = async ({ networkId, tokens, connector, cache }) => {
|
|
|
1598
1582
|
}
|
|
1599
1583
|
return result;
|
|
1600
1584
|
};
|
|
1601
|
-
|
|
1602
|
-
//#region src/modules/evm-erc20/getMiniMetadata.ts
|
|
1585
|
+
// src/modules/evm-erc20/getMiniMetadata.ts
|
|
1603
1586
|
const getMiniMetadata$12 = () => {
|
|
1604
1587
|
throw new Error("MiniMetadata is not supported for ethereum tokens");
|
|
1605
1588
|
};
|
|
1606
|
-
|
|
1607
|
-
//#region src/modules/evm-erc20/getTransferCallData.ts
|
|
1589
|
+
// src/modules/evm-erc20/getTransferCallData.ts
|
|
1608
1590
|
const getTransferCallData$12 = ({ from, to, value, token }) => {
|
|
1609
1591
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$12)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$12}.`);
|
|
1610
1592
|
if (!(0, _talismn_crypto.isEthereumAddress)(from)) throw new Error("Invalid from address");
|
|
@@ -1620,8 +1602,7 @@ const getTransferCallData$12 = ({ from, to, value, token }) => {
|
|
|
1620
1602
|
data
|
|
1621
1603
|
};
|
|
1622
1604
|
};
|
|
1623
|
-
|
|
1624
|
-
//#region src/types/fingerprint.ts
|
|
1605
|
+
// src/types/fingerprint.ts
|
|
1625
1606
|
/**
|
|
1626
1607
|
* Cheap change-detection for the high-frequency balance pipelines, replacing lodash
|
|
1627
1608
|
* `isEqual` deep walks that previously ran on every block/poll emission at several
|
|
@@ -1684,8 +1665,7 @@ const isEqualMiniMetadatas = (a, b) => {
|
|
|
1684
1665
|
if (a === null || b === null) return false;
|
|
1685
1666
|
return a.length === b.length && a.every((m, i) => m.id === b[i].id && m.data === b[i].data);
|
|
1686
1667
|
};
|
|
1687
|
-
|
|
1688
|
-
//#region src/modules/shared/rpcQueryPack.ts
|
|
1668
|
+
// src/modules/shared/rpcQueryPack.ts
|
|
1689
1669
|
const fetchRpcQueryPack = async (connector, networkId, queries, at) => {
|
|
1690
1670
|
const allStateKeys = queries.flatMap(({ stateKeys }) => stateKeys).filter(_talismn_util.isNotNil);
|
|
1691
1671
|
if (!allStateKeys.length) return queries.map(({ stateKeys, decodeResult }) => decodeResult(stateKeys.map(() => null)));
|
|
@@ -1733,8 +1713,7 @@ const getRpcQueryPack$ = (connector, networkId, queries, timeout = false) => {
|
|
|
1733
1713
|
return getRawStorageUpdates$(connector, networkId, allStateKeys, timeout).pipe((0, _talismn_util.switchMapChunked)((changesByKey, { slicer }) => decodeRpcQueryPackChunked(queries, changesByKey, { slicer }), { label: `decode ${networkId}` }));
|
|
1734
1714
|
};
|
|
1735
1715
|
const decodeRpcQueryPackChunked = (queries, changesByKey, options) => (0, _talismn_util.mapWithYield)(queries, ({ stateKeys, decodeResult }) => decodeResult(stateKeys.map((stateKey) => (stateKey && changesByKey.get(stateKey)) ?? null)), options);
|
|
1736
|
-
|
|
1737
|
-
//#region src/modules/shared/subscribeBalances.ts
|
|
1716
|
+
// src/modules/shared/subscribeBalances.ts
|
|
1738
1717
|
const POLLING_INTERVAL = 6e3;
|
|
1739
1718
|
/** subscribes by calling fetchBalances every 6 seconds */
|
|
1740
1719
|
const createPollingSubscribeBalances = (moduleType, fetchBalances) => (args) => {
|
|
@@ -1785,8 +1764,7 @@ const createRpcQuerySubscribeBalances = (buildQueries) => (args) => {
|
|
|
1785
1764
|
errors: []
|
|
1786
1765
|
})));
|
|
1787
1766
|
};
|
|
1788
|
-
|
|
1789
|
-
//#region src/modules/evm-erc20/module.ts
|
|
1767
|
+
// src/modules/evm-erc20/module.ts
|
|
1790
1768
|
const EvmErc20BalanceModule = {
|
|
1791
1769
|
type: MODULE_TYPE$12,
|
|
1792
1770
|
platform: PLATFORM$12,
|
|
@@ -1796,21 +1774,17 @@ const EvmErc20BalanceModule = {
|
|
|
1796
1774
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$12, fetchBalances$12),
|
|
1797
1775
|
getTransferCallData: getTransferCallData$12
|
|
1798
1776
|
};
|
|
1799
|
-
|
|
1800
|
-
//#region src/types/tokens.ts
|
|
1777
|
+
// src/types/tokens.ts
|
|
1801
1778
|
const TokenConfigBaseSchema = _talismn_chaindata_provider.TokenBaseSchema.partial().omit({ id: true });
|
|
1802
|
-
|
|
1803
|
-
//#region src/modules/evm-erc20/types.ts
|
|
1779
|
+
// src/modules/evm-erc20/types.ts
|
|
1804
1780
|
const EvmErc20TokenConfigSchema = zod_v4.default.strictObject({
|
|
1805
1781
|
contractAddress: _talismn_chaindata_provider.EvmErc20TokenSchema.shape.contractAddress,
|
|
1806
1782
|
...TokenConfigBaseSchema.shape
|
|
1807
1783
|
});
|
|
1808
|
-
|
|
1809
|
-
//#region src/modules/evm-native/config.ts
|
|
1784
|
+
// src/modules/evm-native/config.ts
|
|
1810
1785
|
const MODULE_TYPE$11 = _talismn_chaindata_provider.EvmNativeTokenSchema.shape.type.value;
|
|
1811
1786
|
const PLATFORM$11 = _talismn_chaindata_provider.EvmNativeTokenSchema.shape.platform.value;
|
|
1812
|
-
|
|
1813
|
-
//#region src/modules/evm-native/fetchBalances.ts
|
|
1787
|
+
// src/modules/evm-native/fetchBalances.ts
|
|
1814
1788
|
const fetchBalances$11 = async ({ networkId, tokensWithAddresses, connector }) => {
|
|
1815
1789
|
if (!tokensWithAddresses.length) return {
|
|
1816
1790
|
success: [],
|
|
@@ -1891,8 +1865,7 @@ const fetchWithMulticall = async (client, balanceDefs, multicall3Address) => {
|
|
|
1891
1865
|
errors: []
|
|
1892
1866
|
};
|
|
1893
1867
|
};
|
|
1894
|
-
|
|
1895
|
-
//#region src/modules/evm-native/fetchTokens.ts
|
|
1868
|
+
// src/modules/evm-native/fetchTokens.ts
|
|
1896
1869
|
const fetchTokens$11 = async ({ networkId, tokens }) => {
|
|
1897
1870
|
if (tokens.length !== 1) throw new Error("EVM Native module expects the nativeCurrency to be passed as a single token in the array");
|
|
1898
1871
|
const token = (0, lodash_es.assign)({
|
|
@@ -1909,13 +1882,11 @@ const fetchTokens$11 = async ({ networkId, tokens }) => {
|
|
|
1909
1882
|
}
|
|
1910
1883
|
return [parsed.data];
|
|
1911
1884
|
};
|
|
1912
|
-
|
|
1913
|
-
//#region src/modules/evm-native/getMiniMetadata.ts
|
|
1885
|
+
// src/modules/evm-native/getMiniMetadata.ts
|
|
1914
1886
|
const getMiniMetadata$11 = () => {
|
|
1915
1887
|
throw new Error("MiniMetadata is not supported for ethereum tokens");
|
|
1916
1888
|
};
|
|
1917
|
-
|
|
1918
|
-
//#region src/modules/evm-native/getTransferCallData.ts
|
|
1889
|
+
// src/modules/evm-native/getTransferCallData.ts
|
|
1919
1890
|
const getTransferCallData$11 = ({ from, to, value, token }) => {
|
|
1920
1891
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$11)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$11}.`);
|
|
1921
1892
|
if (!(0, _talismn_crypto.isEthereumAddress)(from)) throw new Error("Invalid from address");
|
|
@@ -1927,8 +1898,7 @@ const getTransferCallData$11 = ({ from, to, value, token }) => {
|
|
|
1927
1898
|
data: "0x"
|
|
1928
1899
|
};
|
|
1929
1900
|
};
|
|
1930
|
-
|
|
1931
|
-
//#region src/modules/evm-native/module.ts
|
|
1901
|
+
// src/modules/evm-native/module.ts
|
|
1932
1902
|
const EvmNativeBalanceModule = {
|
|
1933
1903
|
type: MODULE_TYPE$11,
|
|
1934
1904
|
platform: PLATFORM$11,
|
|
@@ -1938,15 +1908,12 @@ const EvmNativeBalanceModule = {
|
|
|
1938
1908
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$11, fetchBalances$11),
|
|
1939
1909
|
getTransferCallData: getTransferCallData$11
|
|
1940
1910
|
};
|
|
1941
|
-
|
|
1942
|
-
//#region src/modules/evm-native/types.ts
|
|
1911
|
+
// src/modules/evm-native/types.ts
|
|
1943
1912
|
const EvmNativeTokenConfigSchema = zod_v4.default.strictObject({ ...TokenConfigBaseSchema.shape });
|
|
1944
|
-
|
|
1945
|
-
//#region src/modules/evm-uniswapv2/config.ts
|
|
1913
|
+
// src/modules/evm-uniswapv2/config.ts
|
|
1946
1914
|
const MODULE_TYPE$10 = _talismn_chaindata_provider.EvmUniswapV2TokenSchema.shape.type.value;
|
|
1947
1915
|
const PLATFORM$10 = _talismn_chaindata_provider.EvmUniswapV2TokenSchema.shape.platform.value;
|
|
1948
|
-
|
|
1949
|
-
//#region src/modules/evm-uniswapv2/fetchBalances.ts
|
|
1916
|
+
// src/modules/evm-uniswapv2/fetchBalances.ts
|
|
1950
1917
|
const fetchBalances$10 = async ({ networkId, tokensWithAddresses, connector }) => {
|
|
1951
1918
|
if (!tokensWithAddresses.length) return {
|
|
1952
1919
|
success: [],
|
|
@@ -2046,8 +2013,7 @@ const fetchPoolBalances = async (client, balanceDefs) => {
|
|
|
2046
2013
|
errors: []
|
|
2047
2014
|
});
|
|
2048
2015
|
};
|
|
2049
|
-
|
|
2050
|
-
//#region src/modules/evm-uniswapv2/utils.ts
|
|
2016
|
+
// src/modules/evm-uniswapv2/utils.ts
|
|
2051
2017
|
const getErc20ContractData = async (client, contractAddress) => {
|
|
2052
2018
|
try {
|
|
2053
2019
|
const contract = getTypedContract(client, viem.erc20Abi, contractAddress);
|
|
@@ -2094,8 +2060,7 @@ const getUniswapV2PairContractData = async (client, contractAddress) => {
|
|
|
2094
2060
|
name
|
|
2095
2061
|
};
|
|
2096
2062
|
};
|
|
2097
|
-
|
|
2098
|
-
//#region src/modules/evm-uniswapv2/fetchTokens.ts
|
|
2063
|
+
// src/modules/evm-uniswapv2/fetchTokens.ts
|
|
2099
2064
|
const TokenCacheSchema$2 = zod_v4.default.discriminatedUnion("isValid", [zod_v4.default.strictObject({
|
|
2100
2065
|
id: _talismn_chaindata_provider.EvmUniswapV2TokenSchema.shape.id,
|
|
2101
2066
|
isValid: zod_v4.default.literal(true),
|
|
@@ -2169,13 +2134,11 @@ const fetchTokens$10 = async ({ networkId, tokens, connector, cache }) => {
|
|
|
2169
2134
|
}
|
|
2170
2135
|
return result;
|
|
2171
2136
|
};
|
|
2172
|
-
|
|
2173
|
-
//#region src/modules/evm-uniswapv2/getMiniMetadata.ts
|
|
2137
|
+
// src/modules/evm-uniswapv2/getMiniMetadata.ts
|
|
2174
2138
|
const getMiniMetadata$10 = () => {
|
|
2175
2139
|
throw new Error("MiniMetadata is not supported for ethereum tokens");
|
|
2176
2140
|
};
|
|
2177
|
-
|
|
2178
|
-
//#region src/modules/evm-uniswapv2/getTransferCallData.ts
|
|
2141
|
+
// src/modules/evm-uniswapv2/getTransferCallData.ts
|
|
2179
2142
|
const getTransferCallData$10 = ({ from, to, value, token }) => {
|
|
2180
2143
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$10)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$10}.`);
|
|
2181
2144
|
if (!(0, _talismn_crypto.isEthereumAddress)(from)) throw new Error("Invalid from address");
|
|
@@ -2191,8 +2154,7 @@ const getTransferCallData$10 = ({ from, to, value, token }) => {
|
|
|
2191
2154
|
data
|
|
2192
2155
|
};
|
|
2193
2156
|
};
|
|
2194
|
-
|
|
2195
|
-
//#region src/modules/evm-uniswapv2/module.ts
|
|
2157
|
+
// src/modules/evm-uniswapv2/module.ts
|
|
2196
2158
|
const EvmUniswapV2BalanceModule = {
|
|
2197
2159
|
type: MODULE_TYPE$10,
|
|
2198
2160
|
platform: PLATFORM$10,
|
|
@@ -2202,18 +2164,15 @@ const EvmUniswapV2BalanceModule = {
|
|
|
2202
2164
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$10, fetchBalances$10),
|
|
2203
2165
|
getTransferCallData: getTransferCallData$10
|
|
2204
2166
|
};
|
|
2205
|
-
|
|
2206
|
-
//#region src/modules/evm-uniswapv2/types.ts
|
|
2167
|
+
// src/modules/evm-uniswapv2/types.ts
|
|
2207
2168
|
const EvmUniswapV2TokenConfigSchema = zod_v4.default.strictObject({
|
|
2208
2169
|
contractAddress: _talismn_chaindata_provider.EvmUniswapV2TokenSchema.shape.contractAddress,
|
|
2209
2170
|
...TokenConfigBaseSchema.shape
|
|
2210
2171
|
});
|
|
2211
|
-
|
|
2212
|
-
//#region src/modules/sol-native/config.ts
|
|
2172
|
+
// src/modules/sol-native/config.ts
|
|
2213
2173
|
const MODULE_TYPE$9 = _talismn_chaindata_provider.SolNativeTokenSchema.shape.type.value;
|
|
2214
2174
|
const PLATFORM$9 = _talismn_chaindata_provider.SolNativeTokenSchema.shape.platform.value;
|
|
2215
|
-
|
|
2216
|
-
//#region src/modules/sol-native/fetchBalances.ts
|
|
2175
|
+
// src/modules/sol-native/fetchBalances.ts
|
|
2217
2176
|
const fetchBalances$9 = async ({ networkId, tokensWithAddresses, connector }) => {
|
|
2218
2177
|
if (!tokensWithAddresses.length) return {
|
|
2219
2178
|
success: [],
|
|
@@ -2256,8 +2215,7 @@ const fetchBalances$9 = async ({ networkId, tokensWithAddresses, connector }) =>
|
|
|
2256
2215
|
errors: []
|
|
2257
2216
|
});
|
|
2258
2217
|
};
|
|
2259
|
-
|
|
2260
|
-
//#region src/modules/sol-native/fetchTokens.ts
|
|
2218
|
+
// src/modules/sol-native/fetchTokens.ts
|
|
2261
2219
|
const fetchTokens$9 = async ({ networkId, tokens }) => {
|
|
2262
2220
|
if (tokens.length !== 1) throw new Error("EVM Native module expects the nativeCurrency to be passed as a single token in the array");
|
|
2263
2221
|
const token = (0, lodash_es.assign)({
|
|
@@ -2274,13 +2232,11 @@ const fetchTokens$9 = async ({ networkId, tokens }) => {
|
|
|
2274
2232
|
}
|
|
2275
2233
|
return [parsed.data];
|
|
2276
2234
|
};
|
|
2277
|
-
|
|
2278
|
-
//#region src/modules/sol-native/getMiniMetadata.ts
|
|
2235
|
+
// src/modules/sol-native/getMiniMetadata.ts
|
|
2279
2236
|
const getMiniMetadata$9 = () => {
|
|
2280
2237
|
throw new Error("MiniMetadata is not supported for sol-native tokens");
|
|
2281
2238
|
};
|
|
2282
|
-
|
|
2283
|
-
//#region src/modules/sol-native/getTransferCallData.ts
|
|
2239
|
+
// src/modules/sol-native/getTransferCallData.ts
|
|
2284
2240
|
const getTransferCallData$9 = ({ from, to, value, token }) => {
|
|
2285
2241
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$9)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$9}.`);
|
|
2286
2242
|
return [(0, _solana_program_system.getTransferSolInstruction)({
|
|
@@ -2289,8 +2245,7 @@ const getTransferCallData$9 = ({ from, to, value, token }) => {
|
|
|
2289
2245
|
amount: BigInt(value)
|
|
2290
2246
|
})];
|
|
2291
2247
|
};
|
|
2292
|
-
|
|
2293
|
-
//#region src/modules/sol-native/module.ts
|
|
2248
|
+
// src/modules/sol-native/module.ts
|
|
2294
2249
|
const SolNativeBalanceModule = {
|
|
2295
2250
|
type: MODULE_TYPE$9,
|
|
2296
2251
|
platform: PLATFORM$9,
|
|
@@ -2300,15 +2255,12 @@ const SolNativeBalanceModule = {
|
|
|
2300
2255
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$9, fetchBalances$9),
|
|
2301
2256
|
getTransferCallData: getTransferCallData$9
|
|
2302
2257
|
};
|
|
2303
|
-
|
|
2304
|
-
//#region src/modules/sol-native/types.ts
|
|
2258
|
+
// src/modules/sol-native/types.ts
|
|
2305
2259
|
const SolNativeTokenConfigSchema = zod_v4.default.strictObject({ ...TokenConfigBaseSchema.shape });
|
|
2306
|
-
|
|
2307
|
-
//#region src/modules/sol-spl/config.ts
|
|
2260
|
+
// src/modules/sol-spl/config.ts
|
|
2308
2261
|
const MODULE_TYPE$8 = _talismn_chaindata_provider.SolSplTokenSchema.shape.type.value;
|
|
2309
2262
|
const PLATFORM$8 = _talismn_chaindata_provider.SolSplTokenSchema.shape.platform.value;
|
|
2310
|
-
|
|
2311
|
-
//#region src/modules/shared/scaleBuilderCache.ts
|
|
2263
|
+
// src/modules/shared/scaleBuilderCache.ts
|
|
2312
2264
|
/**
|
|
2313
2265
|
* Parsing chain metadata and building the dynamic scale builder
|
|
2314
2266
|
* (unifyMetadata(decAnyMetadata(data)) + getDynamicBuilder(getLookupFn(...))) costs tens to
|
|
@@ -2367,8 +2319,7 @@ const getCachedStorageCoder = (miniMetadata, pallet, entry) => {
|
|
|
2367
2319
|
while (storageCoderCache.size > STORAGE_CODER_CACHE_SIZE) storageCoderCache.delete(storageCoderCache.keys().next().value);
|
|
2368
2320
|
return coder;
|
|
2369
2321
|
};
|
|
2370
|
-
|
|
2371
|
-
//#region src/modules/shared/buildNetworkStorageCoders.ts
|
|
2322
|
+
// src/modules/shared/buildNetworkStorageCoders.ts
|
|
2372
2323
|
const buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
|
|
2373
2324
|
if (!miniMetadata.data) return null;
|
|
2374
2325
|
if (getCachedScaleBuilder(miniMetadata) === null) return null;
|
|
@@ -2377,8 +2328,7 @@ const buildNetworkStorageCoders = (chainId, miniMetadata, coders) => {
|
|
|
2377
2328
|
return [key, getCachedStorageCoder(miniMetadata, module, method)];
|
|
2378
2329
|
}));
|
|
2379
2330
|
};
|
|
2380
|
-
|
|
2381
|
-
//#region src/modules/shared/fetchBestBlockHash.ts
|
|
2331
|
+
// src/modules/shared/fetchBestBlockHash.ts
|
|
2382
2332
|
/**
|
|
2383
2333
|
* Hash of the current best block, to pin a poll's reads to.
|
|
2384
2334
|
*
|
|
@@ -2392,8 +2342,7 @@ const fetchBestBlockHash = async (connector, networkId) => {
|
|
|
2392
2342
|
if (!blockHash) throw new Error(`Failed to fetch best block hash on ${networkId}`);
|
|
2393
2343
|
return blockHash;
|
|
2394
2344
|
};
|
|
2395
|
-
|
|
2396
|
-
//#region src/modules/shared/parseMetadataRpcCached.ts
|
|
2345
|
+
// src/modules/shared/parseMetadataRpcCached.ts
|
|
2397
2346
|
/**
|
|
2398
2347
|
* parseMetadataRpc does a full metadata decode + dynamic-builder build (tens to hundreds
|
|
2399
2348
|
* of ms, indivisible). Modules that poll (e.g. substrate-dtao every 6s) call it with the
|
|
@@ -2421,8 +2370,7 @@ const parseMetadataRpcCached = (metadataRpc) => {
|
|
|
2421
2370
|
while (cache.size > CACHE_SIZE) cache.delete(cache.keys().next().value);
|
|
2422
2371
|
return result;
|
|
2423
2372
|
};
|
|
2424
|
-
|
|
2425
|
-
//#region src/modules/shared/fetchRuntimeCallResult.ts
|
|
2373
|
+
// src/modules/shared/fetchRuntimeCallResult.ts
|
|
2426
2374
|
const runtimeCallCache = /* @__PURE__ */ new WeakMap();
|
|
2427
2375
|
const getRuntimeCall = (builder, apiName, method) => {
|
|
2428
2376
|
let byName = runtimeCallCache.get(builder);
|
|
@@ -2457,8 +2405,7 @@ const fetchRuntimeCallResult = async (connector, networkId, metadataRpcOrBuilder
|
|
|
2457
2405
|
throw new Error(`Error fetching runtime call on ${networkId} for ${apiName}.${method}`, { cause });
|
|
2458
2406
|
}
|
|
2459
2407
|
};
|
|
2460
|
-
|
|
2461
|
-
//#region src/modules/shared/stabilizeBalances.ts
|
|
2408
|
+
// src/modules/shared/stabilizeBalances.ts
|
|
2462
2409
|
const DEFAULT_DRIFT_REFRESH_MS = 3e4;
|
|
2463
2410
|
const defaultNow = typeof performance !== "undefined" ? () => performance.now() : () => Date.now();
|
|
2464
2411
|
/**
|
|
@@ -2593,8 +2540,7 @@ const stabilizeModuleResults = (isEffectivelyEqual, options) => {
|
|
|
2593
2540
|
})));
|
|
2594
2541
|
});
|
|
2595
2542
|
};
|
|
2596
|
-
|
|
2597
|
-
//#region src/modules/shared/utils.ts
|
|
2543
|
+
// src/modules/shared/utils.ts
|
|
2598
2544
|
const hasStorageItem = (metadata, palletName, itemName) => {
|
|
2599
2545
|
const pallet = metadata.pallets.find((p) => p.name === palletName);
|
|
2600
2546
|
if (!pallet?.storage) return false;
|
|
@@ -2624,8 +2570,7 @@ const tryGetConstantValue = (metadata, pallet, constant) => {
|
|
|
2624
2570
|
if (!encodedValue) return null;
|
|
2625
2571
|
return builder.buildConstant(pallet, constant).dec(encodedValue);
|
|
2626
2572
|
};
|
|
2627
|
-
|
|
2628
|
-
//#region src/modules/shared/detectedTokens.ts
|
|
2573
|
+
// src/modules/shared/detectedTokens.ts
|
|
2629
2574
|
const tokenIdsByAddress = new rxjs.BehaviorSubject({});
|
|
2630
2575
|
const setDetectedTokenIds = (address, type, tokenIds) => {
|
|
2631
2576
|
const otherTokens = tokenIdsByAddress.value[address]?.filter((id) => (0, _talismn_chaindata_provider.parseTokenId)(id).type !== type) ?? [];
|
|
@@ -2635,8 +2580,7 @@ const setDetectedTokenIds = (address, type, tokenIds) => {
|
|
|
2635
2580
|
});
|
|
2636
2581
|
};
|
|
2637
2582
|
const getDetectedTokensIds$ = (address) => tokenIdsByAddress.pipe((0, rxjs.map)((ownedTokens) => ownedTokens[address] ?? []), (0, rxjs.distinctUntilChanged)(lodash_es.isEqual));
|
|
2638
|
-
|
|
2639
|
-
//#region src/modules/sol-shared/metaplexMetadata.ts
|
|
2583
|
+
// src/modules/sol-shared/metaplexMetadata.ts
|
|
2640
2584
|
const METAPLEX_PROGRAM_ID = (0, _solana_kit.address)("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
2641
2585
|
/** Derives the Metaplex metadata PDA for a mint. */
|
|
2642
2586
|
const deriveMetaplexMetadataPda = async (mintAddress) => {
|
|
@@ -2671,8 +2615,7 @@ const fetchMetaplexMetadata = async (rpc, mintAddress) => {
|
|
|
2671
2615
|
name: metadata.name.trim()
|
|
2672
2616
|
};
|
|
2673
2617
|
};
|
|
2674
|
-
|
|
2675
|
-
//#region src/modules/sol-shared/tokenAccountExists.ts
|
|
2618
|
+
// src/modules/sol-shared/tokenAccountExists.ts
|
|
2676
2619
|
/**
|
|
2677
2620
|
* Checks whether an associated token account already exists for the given token program.
|
|
2678
2621
|
*
|
|
@@ -2691,8 +2634,7 @@ const tokenAccountExists = async (rpc, address, tokenProgram) => {
|
|
|
2691
2634
|
}).send();
|
|
2692
2635
|
return value !== null && value.owner === tokenProgram;
|
|
2693
2636
|
};
|
|
2694
|
-
|
|
2695
|
-
//#region src/modules/sol-shared/tokenDataErrors.ts
|
|
2637
|
+
// src/modules/sol-shared/tokenDataErrors.ts
|
|
2696
2638
|
const ERROR_NO_MINT = "No mint info available";
|
|
2697
2639
|
const ERROR_NO_METADATA = "No metadata account found";
|
|
2698
2640
|
const ERROR_INVALID_DATA = "Invalid on-chain data";
|
|
@@ -2702,8 +2644,7 @@ const isTokenDataError = (msg) => [
|
|
|
2702
2644
|
ERROR_NO_METADATA,
|
|
2703
2645
|
ERROR_INVALID_DATA
|
|
2704
2646
|
].includes(msg);
|
|
2705
|
-
|
|
2706
|
-
//#region src/modules/sol-spl/onChainTokenMetadata.ts
|
|
2647
|
+
// src/modules/sol-spl/onChainTokenMetadata.ts
|
|
2707
2648
|
const TokenCacheSchema$1 = zod_v4.default.discriminatedUnion("isValid", [zod_v4.default.strictObject({
|
|
2708
2649
|
id: _talismn_chaindata_provider.SolSplTokenSchema.shape.id,
|
|
2709
2650
|
isValid: zod_v4.default.literal(true),
|
|
@@ -2749,8 +2690,7 @@ const fetchOnChainTokenData$1 = async (connector, tokenId) => {
|
|
|
2749
2690
|
}
|
|
2750
2691
|
return null;
|
|
2751
2692
|
};
|
|
2752
|
-
|
|
2753
|
-
//#region src/modules/sol-spl/fetchBalances.ts
|
|
2693
|
+
// src/modules/sol-spl/fetchBalances.ts
|
|
2754
2694
|
const SPL_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
2755
2695
|
const dynamicTokenMetadataCache$1 = new _talismn_util.LruMap(1024);
|
|
2756
2696
|
const associatedTokenAccountCache$1 = new _talismn_util.LruMap(1024);
|
|
@@ -2878,8 +2818,7 @@ const getAssociatedTokenAccount$1 = async (owner, mint) => {
|
|
|
2878
2818
|
associatedTokenAccountCache$1.set(key, associatedTokenAccount);
|
|
2879
2819
|
return associatedTokenAccount;
|
|
2880
2820
|
};
|
|
2881
|
-
|
|
2882
|
-
//#region src/modules/sol-spl/fetchTokens.ts
|
|
2821
|
+
// src/modules/sol-spl/fetchTokens.ts
|
|
2883
2822
|
const fetchTokens$8 = async ({ networkId, tokens, connector, cache }) => {
|
|
2884
2823
|
const result = [];
|
|
2885
2824
|
for (const tokenConfig of tokens) {
|
|
@@ -2906,13 +2845,11 @@ const fetchTokens$8 = async ({ networkId, tokens, connector, cache }) => {
|
|
|
2906
2845
|
}
|
|
2907
2846
|
return result;
|
|
2908
2847
|
};
|
|
2909
|
-
|
|
2910
|
-
//#region src/modules/sol-spl/getMiniMetadata.ts
|
|
2848
|
+
// src/modules/sol-spl/getMiniMetadata.ts
|
|
2911
2849
|
const getMiniMetadata$8 = () => {
|
|
2912
2850
|
throw new Error("MiniMetadata is not supported for solana tokens");
|
|
2913
2851
|
};
|
|
2914
|
-
|
|
2915
|
-
//#region src/modules/sol-spl/getTransferCallData.ts
|
|
2852
|
+
// src/modules/sol-spl/getTransferCallData.ts
|
|
2916
2853
|
const getTransferCallData$8 = async ({ from, to, value, token, connector }) => {
|
|
2917
2854
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$8)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$8}.`);
|
|
2918
2855
|
const rpc = await connector.getRpc(token.networkId);
|
|
@@ -2945,8 +2882,7 @@ const getTransferCallData$8 = async ({ from, to, value, token, connector }) => {
|
|
|
2945
2882
|
}));
|
|
2946
2883
|
return instructions;
|
|
2947
2884
|
};
|
|
2948
|
-
|
|
2949
|
-
//#region src/modules/sol-spl/module.ts
|
|
2885
|
+
// src/modules/sol-spl/module.ts
|
|
2950
2886
|
const SolSplBalanceModule = {
|
|
2951
2887
|
type: MODULE_TYPE$8,
|
|
2952
2888
|
platform: PLATFORM$8,
|
|
@@ -2956,26 +2892,22 @@ const SolSplBalanceModule = {
|
|
|
2956
2892
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$8, fetchBalances$8),
|
|
2957
2893
|
getTransferCallData: getTransferCallData$8
|
|
2958
2894
|
};
|
|
2959
|
-
|
|
2960
|
-
//#region src/modules/sol-spl/types.ts
|
|
2895
|
+
// src/modules/sol-spl/types.ts
|
|
2961
2896
|
const SolSplTokenConfigSchema = zod_v4.default.strictObject({
|
|
2962
2897
|
mintAddress: _talismn_chaindata_provider.SolSplTokenSchema.shape.mintAddress,
|
|
2963
2898
|
...TokenConfigBaseSchema.shape
|
|
2964
2899
|
});
|
|
2965
|
-
|
|
2966
|
-
//#region src/modules/sol-token2022/config.ts
|
|
2900
|
+
// src/modules/sol-token2022/config.ts
|
|
2967
2901
|
const MODULE_TYPE$7 = _talismn_chaindata_provider.SolToken2022TokenSchema.shape.type.value;
|
|
2968
2902
|
const PLATFORM$7 = _talismn_chaindata_provider.SolToken2022TokenSchema.shape.platform.value;
|
|
2969
|
-
|
|
2970
|
-
//#region src/modules/sol-token2022/mintExtensions.ts
|
|
2903
|
+
// src/modules/sol-token2022/mintExtensions.ts
|
|
2971
2904
|
const getMintExtensions = (mint) => (0, _solana_kit.unwrapOption)(mint.extensions) ?? [];
|
|
2972
2905
|
const getExtension = (mint, kind) => getMintExtensions(mint).find((ext) => ext.__kind === kind) ?? null;
|
|
2973
2906
|
const getTransferFeeConfig = (mint) => getExtension(mint, "TransferFeeConfig");
|
|
2974
2907
|
const getTransferHook = (mint) => getExtension(mint, "TransferHook");
|
|
2975
2908
|
const isNonTransferable = (mint) => getExtension(mint, "NonTransferable") !== null;
|
|
2976
2909
|
const getTokenMetadata = (mint) => getExtension(mint, "TokenMetadata");
|
|
2977
|
-
|
|
2978
|
-
//#region src/modules/sol-token2022/transferHook.ts
|
|
2910
|
+
// src/modules/sol-token2022/transferHook.ts
|
|
2979
2911
|
const EXECUTE_DISCRIMINATOR = Uint8Array.from([
|
|
2980
2912
|
105,
|
|
2981
2913
|
37,
|
|
@@ -3183,8 +3115,7 @@ const addExtraAccountMetasForTransferHook = async (args) => {
|
|
|
3183
3115
|
accounts: [...instruction.accounts ?? [], ...extraAccounts]
|
|
3184
3116
|
};
|
|
3185
3117
|
};
|
|
3186
|
-
|
|
3187
|
-
//#region src/modules/sol-token2022/getTransferCallData.ts
|
|
3118
|
+
// src/modules/sol-token2022/getTransferCallData.ts
|
|
3188
3119
|
const getTransferCallData$7 = async ({ from, to, value, token, connector }) => {
|
|
3189
3120
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$7)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$7}.`);
|
|
3190
3121
|
const rpc = await connector.getRpc(token.networkId);
|
|
@@ -3262,8 +3193,7 @@ const calculateCurrentEpochTransferFee = async (rpc, transferFeeConfig, amount)
|
|
|
3262
3193
|
const { epoch } = await rpc.getEpochInfo().send();
|
|
3263
3194
|
return calculateToken2022TransferFee(transferFeeConfig, epoch, amount);
|
|
3264
3195
|
};
|
|
3265
|
-
|
|
3266
|
-
//#region src/modules/sol-token2022/onChainTokenMetadata.ts
|
|
3196
|
+
// src/modules/sol-token2022/onChainTokenMetadata.ts
|
|
3267
3197
|
const TokenCacheSchema = zod_v4.default.discriminatedUnion("isValid", [zod_v4.default.strictObject({
|
|
3268
3198
|
id: _talismn_chaindata_provider.SolToken2022TokenSchema.shape.id,
|
|
3269
3199
|
isValid: zod_v4.default.literal(true),
|
|
@@ -3321,8 +3251,7 @@ const fetchOnChainTokenData = async (connector, tokenId) => {
|
|
|
3321
3251
|
}
|
|
3322
3252
|
return null;
|
|
3323
3253
|
};
|
|
3324
|
-
|
|
3325
|
-
//#region src/modules/sol-token2022/fetchBalances.ts
|
|
3254
|
+
// src/modules/sol-token2022/fetchBalances.ts
|
|
3326
3255
|
const TOKEN_2022_PROGRAM_ID = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
3327
3256
|
const dynamicTokenMetadataCache = /* @__PURE__ */ new Map();
|
|
3328
3257
|
const associatedTokenAccountCache = new _talismn_util.LruMap(1024);
|
|
@@ -3450,8 +3379,7 @@ const getAssociatedTokenAccount = async (owner, mint) => {
|
|
|
3450
3379
|
associatedTokenAccountCache.set(key, associatedTokenAccount);
|
|
3451
3380
|
return associatedTokenAccount;
|
|
3452
3381
|
};
|
|
3453
|
-
|
|
3454
|
-
//#region src/modules/sol-token2022/fetchTokens.ts
|
|
3382
|
+
// src/modules/sol-token2022/fetchTokens.ts
|
|
3455
3383
|
const fetchTokens$7 = async ({ networkId, tokens, connector, cache }) => {
|
|
3456
3384
|
const result = [];
|
|
3457
3385
|
for (const tokenConfig of tokens) {
|
|
@@ -3478,13 +3406,11 @@ const fetchTokens$7 = async ({ networkId, tokens, connector, cache }) => {
|
|
|
3478
3406
|
}
|
|
3479
3407
|
return result;
|
|
3480
3408
|
};
|
|
3481
|
-
|
|
3482
|
-
//#region src/modules/sol-token2022/getMiniMetadata.ts
|
|
3409
|
+
// src/modules/sol-token2022/getMiniMetadata.ts
|
|
3483
3410
|
const getMiniMetadata$7 = () => {
|
|
3484
3411
|
throw new Error("MiniMetadata is not supported for solana tokens");
|
|
3485
3412
|
};
|
|
3486
|
-
|
|
3487
|
-
//#region src/modules/sol-token2022/module.ts
|
|
3413
|
+
// src/modules/sol-token2022/module.ts
|
|
3488
3414
|
const SolToken2022BalanceModule = {
|
|
3489
3415
|
type: MODULE_TYPE$7,
|
|
3490
3416
|
platform: PLATFORM$7,
|
|
@@ -3494,18 +3420,15 @@ const SolToken2022BalanceModule = {
|
|
|
3494
3420
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$7, fetchBalances$7),
|
|
3495
3421
|
getTransferCallData: getTransferCallData$7
|
|
3496
3422
|
};
|
|
3497
|
-
|
|
3498
|
-
//#region src/modules/sol-token2022/types.ts
|
|
3423
|
+
// src/modules/sol-token2022/types.ts
|
|
3499
3424
|
const SolToken2022TokenConfigSchema = zod_v4.default.strictObject({
|
|
3500
3425
|
mintAddress: _talismn_chaindata_provider.SolToken2022TokenSchema.shape.mintAddress,
|
|
3501
3426
|
...TokenConfigBaseSchema.shape
|
|
3502
3427
|
});
|
|
3503
|
-
|
|
3504
|
-
//#region src/modules/substrate-assets/config.ts
|
|
3428
|
+
// src/modules/substrate-assets/config.ts
|
|
3505
3429
|
const MODULE_TYPE$6 = _talismn_chaindata_provider.SubAssetsTokenSchema.shape.type.value;
|
|
3506
3430
|
const PLATFORM$6 = _talismn_chaindata_provider.SubAssetsTokenSchema.shape.platform.value;
|
|
3507
|
-
|
|
3508
|
-
//#region src/modules/substrate-assets/buildQueries.ts
|
|
3431
|
+
// src/modules/substrate-assets/buildQueries.ts
|
|
3509
3432
|
const buildQueries$2 = (networkId, balanceDefs, miniMetadata) => {
|
|
3510
3433
|
const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, { storage: ["Assets", "Account"] });
|
|
3511
3434
|
return balanceDefs.map(({ token, address }) => {
|
|
@@ -3558,8 +3481,7 @@ const tryEncode = (scaleCoder, ...args) => {
|
|
|
3558
3481
|
return null;
|
|
3559
3482
|
}
|
|
3560
3483
|
};
|
|
3561
|
-
|
|
3562
|
-
//#region src/modules/substrate-assets/fetchBalances.ts
|
|
3484
|
+
// src/modules/substrate-assets/fetchBalances.ts
|
|
3563
3485
|
const fetchBalances$6 = async ({ networkId, tokensWithAddresses, connector, miniMetadata }) => {
|
|
3564
3486
|
if (!tokensWithAddresses.length) return {
|
|
3565
3487
|
success: [],
|
|
@@ -3626,8 +3548,7 @@ const fetchBalances$6 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
3626
3548
|
errors: []
|
|
3627
3549
|
});
|
|
3628
3550
|
};
|
|
3629
|
-
|
|
3630
|
-
//#region src/modules/substrate-assets/fetchTokens.ts
|
|
3551
|
+
// src/modules/substrate-assets/fetchTokens.ts
|
|
3631
3552
|
const fetchTokens$6 = async ({ networkId, tokens, connector, miniMetadata }) => {
|
|
3632
3553
|
const anyMiniMetadata = miniMetadata;
|
|
3633
3554
|
if (!anyMiniMetadata?.data) return [];
|
|
@@ -3682,8 +3603,7 @@ const fetchTokens$6 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
3682
3603
|
return _talismn_chaindata_provider.SubAssetsTokenSchema.safeParse(t).success;
|
|
3683
3604
|
});
|
|
3684
3605
|
};
|
|
3685
|
-
|
|
3686
|
-
//#region src/types/balancetypes.ts
|
|
3606
|
+
// src/types/balancetypes.ts
|
|
3687
3607
|
const getValueId = (amount) => {
|
|
3688
3608
|
const getMetaId = () => {
|
|
3689
3609
|
const meta = amount.meta;
|
|
@@ -3698,12 +3618,10 @@ const getValueId = (amount) => {
|
|
|
3698
3618
|
getMetaId()
|
|
3699
3619
|
].join("::");
|
|
3700
3620
|
};
|
|
3701
|
-
|
|
3702
|
-
//#region src/types/minimetadatas.ts
|
|
3621
|
+
// src/types/minimetadatas.ts
|
|
3703
3622
|
/** For fast db access, you can calculate the primary key for a miniMetadata using this method */
|
|
3704
3623
|
const deriveMiniMetadataId = ({ source, chainId, specVersion }) => (0, _talismn_scale.toHex)((0, _talismn_scale.Twox128)(new TextEncoder().encode(`${source}${chainId}${specVersion}${_talismn_chaindata_provider.MINIMETADATA_VERSION}`))).slice(-32);
|
|
3705
|
-
|
|
3706
|
-
//#region src/modules/substrate-assets/getMiniMetadata.ts
|
|
3624
|
+
// src/modules/substrate-assets/getMiniMetadata.ts
|
|
3707
3625
|
const getMiniMetadata$6 = ({ networkId, specVersion, metadataRpc }) => {
|
|
3708
3626
|
const source = MODULE_TYPE$6;
|
|
3709
3627
|
const chainId = networkId;
|
|
@@ -3743,8 +3661,7 @@ const getData$4 = ({ metadata, unifiedMetadata }) => {
|
|
|
3743
3661
|
}]);
|
|
3744
3662
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
3745
3663
|
};
|
|
3746
|
-
|
|
3747
|
-
//#region src/modules/substrate-assets/getTransferCallData.ts
|
|
3664
|
+
// src/modules/substrate-assets/getTransferCallData.ts
|
|
3748
3665
|
const getTransferCallData$6 = ({ from, to, value, token, type, metadataRpc }) => {
|
|
3749
3666
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
|
|
3750
3667
|
const { builder } = (0, _talismn_scale.parseMetadataRpc)(metadataRpc);
|
|
@@ -3819,8 +3736,7 @@ const getTransferAllEncodedArgs$2 = (assetId, to, codec) => {
|
|
|
3819
3736
|
})
|
|
3820
3737
|
]);
|
|
3821
3738
|
};
|
|
3822
|
-
|
|
3823
|
-
//#region src/modules/substrate-assets/module.ts
|
|
3739
|
+
// src/modules/substrate-assets/module.ts
|
|
3824
3740
|
const SubAssetsBalanceModule = {
|
|
3825
3741
|
type: MODULE_TYPE$6,
|
|
3826
3742
|
platform: PLATFORM$6,
|
|
@@ -3830,14 +3746,12 @@ const SubAssetsBalanceModule = {
|
|
|
3830
3746
|
subscribeBalances: createRpcQuerySubscribeBalances(buildQueries$2),
|
|
3831
3747
|
getTransferCallData: getTransferCallData$6
|
|
3832
3748
|
};
|
|
3833
|
-
|
|
3834
|
-
//#region src/modules/substrate-assets/types.ts
|
|
3749
|
+
// src/modules/substrate-assets/types.ts
|
|
3835
3750
|
const SubAssetsTokenConfigSchema = zod_v4.default.strictObject({
|
|
3836
3751
|
assetId: _talismn_chaindata_provider.SubAssetsTokenSchema.shape.assetId,
|
|
3837
3752
|
...TokenConfigBaseSchema.shape
|
|
3838
3753
|
});
|
|
3839
|
-
|
|
3840
|
-
//#region src/modules/substrate-dtao/alphaPrice.ts
|
|
3754
|
+
// src/modules/substrate-dtao/alphaPrice.ts
|
|
3841
3755
|
const TAO_DECIMALS = 9n;
|
|
3842
3756
|
const ALPHA_PRICE_SCALE = 10n ** TAO_DECIMALS;
|
|
3843
3757
|
const alphaToTao = (alpha, scaledAlphaPrice) => {
|
|
@@ -3859,8 +3773,7 @@ const taoToAlphaCeil = (tao, scaledAlphaPrice) => {
|
|
|
3859
3773
|
if (!tao || !scaledAlphaPrice) return 0n;
|
|
3860
3774
|
return (tao * ALPHA_PRICE_SCALE + scaledAlphaPrice - 1n) / scaledAlphaPrice;
|
|
3861
3775
|
};
|
|
3862
|
-
|
|
3863
|
-
//#region src/modules/substrate-dtao/basketClaims.ts
|
|
3776
|
+
// src/modules/substrate-dtao/basketClaims.ts
|
|
3864
3777
|
/** label of the claimable-rewards values emitted on root staking balances */
|
|
3865
3778
|
const CLAIMABLE_REWARDS_LABEL = "Claimable rewards";
|
|
3866
3779
|
/** Whether a lock is a claimable root rewards entitlement */
|
|
@@ -3904,8 +3817,7 @@ const fetchBasketClaims = async (connector, networkId, metadataRpc, addresses, a
|
|
|
3904
3817
|
throw cause;
|
|
3905
3818
|
}
|
|
3906
3819
|
};
|
|
3907
|
-
|
|
3908
|
-
//#region src/modules/substrate-dtao/convictionLocks.ts
|
|
3820
|
+
// src/modules/substrate-dtao/convictionLocks.ts
|
|
3909
3821
|
const convictionLockKey = (address, netuid) => `${address}:${netuid}`;
|
|
3910
3822
|
const getConvictionLockLabel = (lockType) => lockType === "perpetual" ? "Perpetual Conviction Lock" : "Decaying Conviction Lock";
|
|
3911
3823
|
/**
|
|
@@ -4058,12 +3970,10 @@ const fetchColdkeyLockStates = async (connector, networkId, builder, pairs, at)
|
|
|
4058
3970
|
}
|
|
4059
3971
|
}));
|
|
4060
3972
|
};
|
|
4061
|
-
|
|
4062
|
-
//#region src/modules/substrate-dtao/config.ts
|
|
3973
|
+
// src/modules/substrate-dtao/config.ts
|
|
4063
3974
|
const MODULE_TYPE$5 = _talismn_chaindata_provider.SubDTaoTokenSchema.shape.type.value;
|
|
4064
3975
|
const PLATFORM$5 = _talismn_chaindata_provider.SubDTaoTokenSchema.shape.platform.value;
|
|
4065
|
-
|
|
4066
|
-
//#region src/modules/substrate-dtao/rootStakeHold.ts
|
|
3976
|
+
// src/modules/substrate-dtao/rootStakeHold.ts
|
|
4067
3977
|
/**
|
|
4068
3978
|
* Extracts the root-stake hold from a balance's raw values (BalanceJson), if any.
|
|
4069
3979
|
* While present, the pair's root stake cannot leave root — unstake/move/swap/transfer
|
|
@@ -4077,6 +3987,43 @@ const findDTaoRootStakeHold = (balance) => {
|
|
|
4077
3987
|
}
|
|
4078
3988
|
return null;
|
|
4079
3989
|
};
|
|
3990
|
+
const hasRootStakeHoldStorage = (unifiedMetadata) => hasStorageItems(unifiedMetadata, "SubtensorModule", ["RootStakeUnlockInterval", "LastColdkeyHotkeyStakeBlock"]);
|
|
3991
|
+
/**
|
|
3992
|
+
* How long a `RootStakeUnlockInterval` read is reused. The chain has no extrinsic that sets
|
|
3993
|
+
* it: it changes with a runtime upgrade, which brings new metadata and so a new cache entry,
|
|
3994
|
+
* or through root's `set_storage`, which this bounds.
|
|
3995
|
+
*/
|
|
3996
|
+
const UNLOCK_INTERVAL_CACHE_MS = 6e5;
|
|
3997
|
+
/** cached reads by network, per parsed runtime metadata */
|
|
3998
|
+
const unlockIntervalCache = /* @__PURE__ */ new WeakMap();
|
|
3999
|
+
/**
|
|
4000
|
+
* The chain's `RootStakeUnlockInterval`: how many blocks root stake stays held after the
|
|
4001
|
+
* pair's last root stake operation. 0 (disabled) unless governance enables it, either by
|
|
4002
|
+
* setting the storage entry or with a runtime default that leaves it unset (metadata
|
|
4003
|
+
* fallback). Null on chains without root stake holds.
|
|
4004
|
+
*
|
|
4005
|
+
* Read at most once per `UNLOCK_INTERVAL_CACHE_MS` for each runtime, so that the 6s balance
|
|
4006
|
+
* polls don't spend a request on a value that hardly ever changes.
|
|
4007
|
+
*/
|
|
4008
|
+
const fetchRootStakeUnlockInterval = async (connector, networkId, metadataRpc, at) => {
|
|
4009
|
+
const { unifiedMetadata, builder } = parseMetadataRpcCached(metadataRpc);
|
|
4010
|
+
if (!hasRootStakeHoldStorage(unifiedMetadata)) return null;
|
|
4011
|
+
const byNetwork = unlockIntervalCache.get(builder) ?? /* @__PURE__ */ new Map();
|
|
4012
|
+
unlockIntervalCache.set(builder, byNetwork);
|
|
4013
|
+
const cached = byNetwork.get(networkId);
|
|
4014
|
+
if (cached && Date.now() - cached.readAt < UNLOCK_INTERVAL_CACHE_MS) return cached.interval;
|
|
4015
|
+
try {
|
|
4016
|
+
const interval = await fetchUnlockInterval(connector, networkId, unifiedMetadata, builder, at);
|
|
4017
|
+
byNetwork.set(networkId, {
|
|
4018
|
+
interval,
|
|
4019
|
+
readAt: Date.now()
|
|
4020
|
+
});
|
|
4021
|
+
return interval;
|
|
4022
|
+
} catch (cause) {
|
|
4023
|
+
log_default.warn(`Failed to fetch root stake unlock interval on ${networkId}`, { cause });
|
|
4024
|
+
throw cause;
|
|
4025
|
+
}
|
|
4026
|
+
};
|
|
4080
4027
|
/**
|
|
4081
4028
|
* Fetches active root-stake hold windows (spec 441): when `RootStakeUnlockInterval` is
|
|
4082
4029
|
* non-zero, root stake cannot leave root (remove/move/swap/transfer) until `interval`
|
|
@@ -4084,17 +4031,15 @@ const findDTaoRootStakeHold = (balance) => {
|
|
|
4084
4031
|
* Pairs already past their window are omitted — a returned hold means the pair's root
|
|
4085
4032
|
* stake is currently unremovable.
|
|
4086
4033
|
*
|
|
4087
|
-
* The
|
|
4088
|
-
*
|
|
4089
|
-
* per-pair queries only run when it is non-zero.
|
|
4034
|
+
* The per-pair queries only run when the interval (`fetchRootStakeUnlockInterval`, cached)
|
|
4035
|
+
* is non-zero.
|
|
4090
4036
|
*/
|
|
4091
4037
|
const fetchRootStakeHolds = async (connector, networkId, metadataRpc, rootPairs, at) => {
|
|
4092
4038
|
if (!rootPairs.length) return [];
|
|
4093
|
-
const
|
|
4094
|
-
if (!
|
|
4039
|
+
const interval = await fetchRootStakeUnlockInterval(connector, networkId, metadataRpc, at);
|
|
4040
|
+
if (!interval) return [];
|
|
4041
|
+
const { builder } = parseMetadataRpcCached(metadataRpc);
|
|
4095
4042
|
try {
|
|
4096
|
-
const interval = await fetchUnlockInterval(connector, networkId, unifiedMetadata, builder, at);
|
|
4097
|
-
if (interval === 0n) return [];
|
|
4098
4043
|
const { currentBlock, lastStakeBlocks } = await fetchLastStakeBlocks(connector, networkId, builder, rootPairs, at);
|
|
4099
4044
|
return lastStakeBlocks.flatMap(({ address, hotkey, lastStakeBlock }) => {
|
|
4100
4045
|
if (lastStakeBlock === 0n) return [];
|
|
@@ -4179,9 +4124,13 @@ const fetchLastStakeBlocks = async (connector, networkId, builder, rootPairs, at
|
|
|
4179
4124
|
lastStakeBlocks
|
|
4180
4125
|
};
|
|
4181
4126
|
};
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4127
|
+
// src/modules/substrate-dtao/fetchBalances.ts
|
|
4128
|
+
const fetchBalances$5 = (args) => fetchBalancesAt(args);
|
|
4129
|
+
/**
|
|
4130
|
+
* Fetches the balances as of block `at`, or as of the best block when `at` is not given.
|
|
4131
|
+
* Every read of the fetch is pinned to that one block.
|
|
4132
|
+
*/
|
|
4133
|
+
const fetchBalancesAt = async ({ networkId, tokensWithAddresses, connector, miniMetadata, signal }, at) => {
|
|
4185
4134
|
if (!tokensWithAddresses.length) return {
|
|
4186
4135
|
success: [],
|
|
4187
4136
|
errors: []
|
|
@@ -4221,10 +4170,16 @@ const fetchBalances$5 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4221
4170
|
};
|
|
4222
4171
|
}
|
|
4223
4172
|
const addresses = (0, lodash_es.uniq)(balanceDefs.map((def) => def.address));
|
|
4173
|
+
const metadataRpc = miniMetadata.data;
|
|
4224
4174
|
try {
|
|
4225
|
-
const { builder } = parseMetadataRpcCached(
|
|
4226
|
-
const
|
|
4227
|
-
const stakeInfos
|
|
4175
|
+
const { builder } = parseMetadataRpcCached(metadataRpc);
|
|
4176
|
+
const blockHash = await (at ?? fetchBestBlockHash(connector, networkId));
|
|
4177
|
+
const [stakeInfos, convictionLocks, basketClaims] = await Promise.all([
|
|
4178
|
+
fetchRuntimeCallResult(connector, networkId, builder, "StakeInfoRuntimeApi", "get_stake_info_for_coldkeys", [addresses], blockHash),
|
|
4179
|
+
fetchConvictionLocks(connector, networkId, metadataRpc, addresses, blockHash),
|
|
4180
|
+
fetchBasketClaims(connector, networkId, metadataRpc, addresses, blockHash),
|
|
4181
|
+
fetchRootStakeUnlockInterval(connector, networkId, metadataRpc, blockHash).catch(() => null)
|
|
4182
|
+
]);
|
|
4228
4183
|
const rootPairs = [];
|
|
4229
4184
|
const seenRootPairs = /* @__PURE__ */ new Set();
|
|
4230
4185
|
for (const [address, stakes] of stakeInfos) for (const stake of stakes) {
|
|
@@ -4237,15 +4192,7 @@ const fetchBalances$5 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4237
4192
|
hotkey: stake.hotkey
|
|
4238
4193
|
});
|
|
4239
4194
|
}
|
|
4240
|
-
const
|
|
4241
|
-
fetchConvictionLocks(connector, networkId, miniMetadata.data, addresses, at),
|
|
4242
|
-
fetchBasketClaims(connector, networkId, miniMetadata.data, addresses, at),
|
|
4243
|
-
fetchRootStakeHolds(connector, networkId, miniMetadata.data, rootPairs, at)
|
|
4244
|
-
]) : [
|
|
4245
|
-
[],
|
|
4246
|
-
[],
|
|
4247
|
-
[]
|
|
4248
|
-
];
|
|
4195
|
+
const rootStakeHolds = await fetchRootStakeHolds(connector, networkId, metadataRpc, rootPairs, blockHash);
|
|
4249
4196
|
const upsertBalance = (acc, address, tokenId, balance) => {
|
|
4250
4197
|
const key = `${address}:${tokenId}`;
|
|
4251
4198
|
const recordedBalance = acc[key];
|
|
@@ -4387,8 +4334,7 @@ const fetchBalances$5 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4387
4334
|
};
|
|
4388
4335
|
}
|
|
4389
4336
|
};
|
|
4390
|
-
|
|
4391
|
-
//#region src/modules/substrate-dtao/fetchTokens.ts
|
|
4337
|
+
// src/modules/substrate-dtao/fetchTokens.ts
|
|
4392
4338
|
const NATIVE_TOKEN_SYMBOLS = {
|
|
4393
4339
|
"bittensor": "TAO",
|
|
4394
4340
|
"bittensor-testnet": "testTAO"
|
|
@@ -4400,8 +4346,8 @@ const fetchTokens$5 = async ({ networkId, connector, tokens, miniMetadata }) =>
|
|
|
4400
4346
|
return dynamicInfos.filter(_talismn_util.isNotNil).map((info) => {
|
|
4401
4347
|
const config = tokens.find((t) => t.netuid === info.netuid);
|
|
4402
4348
|
let symbol = new TextDecoder().decode(Uint8Array.from(info.token_symbol));
|
|
4403
|
-
const subnetName = (info.subnet_identity?.subnet_name ? _polkadot_api_substrate_bindings.Binary.toText(info.subnet_identity.subnet_name) : void 0)
|
|
4404
|
-
const name = `SN${info.netuid}
|
|
4349
|
+
const subnetName = (info.subnet_identity?.subnet_name ? _polkadot_api_substrate_bindings.Binary.toText(info.subnet_identity.subnet_name) : void 0) || (info.netuid === 0 ? "Root" : `Subnet ${info.netuid}`);
|
|
4350
|
+
const name = `SN${info.netuid} ${subnetName}`;
|
|
4405
4351
|
if (info.netuid === 0 && NATIVE_TOKEN_SYMBOLS[networkId]) symbol = NATIVE_TOKEN_SYMBOLS[networkId];
|
|
4406
4352
|
const isTransferable = transferableTokensMap[info.netuid] ?? true;
|
|
4407
4353
|
const token = {
|
|
@@ -4433,8 +4379,7 @@ const fetchTransferableTokensMap = async (connector, metadata, networkId) => {
|
|
|
4433
4379
|
return [netuid, transferToggleCodec.value.dec(value)];
|
|
4434
4380
|
}));
|
|
4435
4381
|
};
|
|
4436
|
-
|
|
4437
|
-
//#region src/modules/substrate-dtao/getMiniMetadata.ts
|
|
4382
|
+
// src/modules/substrate-dtao/getMiniMetadata.ts
|
|
4438
4383
|
const getMiniMetadata$5 = ({ networkId, specVersion, metadataRpc }) => {
|
|
4439
4384
|
const source = MODULE_TYPE$5;
|
|
4440
4385
|
const chainId = networkId;
|
|
@@ -4488,8 +4433,7 @@ const getData$3 = (metadataRpc) => {
|
|
|
4488
4433
|
]);
|
|
4489
4434
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
4490
4435
|
};
|
|
4491
|
-
|
|
4492
|
-
//#region src/modules/substrate-dtao/getTransferCallData.ts
|
|
4436
|
+
// src/modules/substrate-dtao/getTransferCallData.ts
|
|
4493
4437
|
const getTransferCallData$5 = ({ from, to, value, token, metadataRpc }) => {
|
|
4494
4438
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$5)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$5}.`);
|
|
4495
4439
|
const { netuid: subnetId, hotkey } = (0, _talismn_chaindata_provider.parseSubDTaoTokenId)(token.id);
|
|
@@ -4509,8 +4453,7 @@ const getTransferCallData$5 = ({ from, to, value, token, metadataRpc }) => {
|
|
|
4509
4453
|
method: _polkadot_api_substrate_bindings.Binary.toHex(callData)
|
|
4510
4454
|
};
|
|
4511
4455
|
};
|
|
4512
|
-
|
|
4513
|
-
//#region src/modules/substrate-dtao/isEffectivelyEqualDTaoBalance.ts
|
|
4456
|
+
// src/modules/substrate-dtao/isEffectivelyEqualDTaoBalance.ts
|
|
4514
4457
|
/** basket claimable amounts are marked NAV quotes: they move with subnet pool prices and
|
|
4515
4458
|
* dividend accrual on (nearly) every block; the display is informational */
|
|
4516
4459
|
const CLAIM_DRIFT_TOLERANCE_BPS = 100n;
|
|
@@ -4609,8 +4552,11 @@ const isEffectivelyEqualDTaoBalance = (previous, next) => {
|
|
|
4609
4552
|
if (result.equivalence === "changed") log_default.debug(`[dtao-classify] changed ${next.tokenId}: ${result.reason}`);
|
|
4610
4553
|
return result.equivalence;
|
|
4611
4554
|
};
|
|
4612
|
-
|
|
4613
|
-
|
|
4555
|
+
// src/modules/substrate-dtao/subscribeBalances.ts
|
|
4556
|
+
/**
|
|
4557
|
+
* Half of Bittensor's 12s block time, so a new block is read within 6s of being produced.
|
|
4558
|
+
* A poll that finds the same best block as the last good poll ends after that one request.
|
|
4559
|
+
*/
|
|
4614
4560
|
const SUBSCRIPTION_INTERVAL = 6e3;
|
|
4615
4561
|
const subscribeBalances$5 = ({ networkId, tokensWithAddresses, connector, miniMetadata }) => {
|
|
4616
4562
|
if (!tokensWithAddresses.length) return (0, rxjs.of)({
|
|
@@ -4620,21 +4566,32 @@ const subscribeBalances$5 = ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
4620
4566
|
const balanceDefs = getBalanceDefs(tokensWithAddresses);
|
|
4621
4567
|
return new rxjs.Observable((subscriber) => {
|
|
4622
4568
|
const abortController = new AbortController();
|
|
4569
|
+
/** the block the last poll read without errors */
|
|
4570
|
+
let lastGoodBlockHash = null;
|
|
4623
4571
|
const poll = async () => {
|
|
4624
4572
|
try {
|
|
4625
4573
|
if (abortController.signal.aborted) return;
|
|
4626
|
-
const
|
|
4574
|
+
const bestBlock = fetchBestBlockHash(connector, networkId);
|
|
4575
|
+
const blockHash = await bestBlock.catch(() => void 0);
|
|
4576
|
+
if (abortController.signal.aborted) return;
|
|
4577
|
+
if (blockHash && blockHash === lastGoodBlockHash) {
|
|
4578
|
+
setTimeout(poll, SUBSCRIPTION_INTERVAL);
|
|
4579
|
+
return;
|
|
4580
|
+
}
|
|
4581
|
+
const balances = await fetchBalancesAt({
|
|
4627
4582
|
networkId,
|
|
4628
4583
|
tokensWithAddresses,
|
|
4629
4584
|
connector,
|
|
4630
4585
|
miniMetadata,
|
|
4631
4586
|
signal: abortController.signal
|
|
4632
|
-
});
|
|
4587
|
+
}, blockHash ?? bestBlock);
|
|
4633
4588
|
if (abortController.signal.aborted) return;
|
|
4589
|
+
lastGoodBlockHash = balances.errors.length ? null : blockHash ?? null;
|
|
4634
4590
|
(0, _talismn_util.reportJsActivity)(`poll ${MODULE_TYPE$5} ${networkId} (${balances.success.length})`);
|
|
4635
4591
|
subscriber.next(balances);
|
|
4636
4592
|
} catch (error) {
|
|
4637
4593
|
if (abortController.signal.aborted) return;
|
|
4594
|
+
lastGoodBlockHash = null;
|
|
4638
4595
|
log_default.error("Error", {
|
|
4639
4596
|
module: MODULE_TYPE$5,
|
|
4640
4597
|
networkId,
|
|
@@ -4660,8 +4617,7 @@ const subscribeBalances$5 = ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
4660
4617
|
};
|
|
4661
4618
|
}).pipe(stabilizeModuleResults(isEffectivelyEqualDTaoBalance), (0, rxjs.distinctUntilChanged)(isEqualModuleResults));
|
|
4662
4619
|
};
|
|
4663
|
-
|
|
4664
|
-
//#region src/modules/substrate-dtao/module.ts
|
|
4620
|
+
// src/modules/substrate-dtao/module.ts
|
|
4665
4621
|
const SubDTaoBalanceModule = {
|
|
4666
4622
|
type: MODULE_TYPE$5,
|
|
4667
4623
|
platform: PLATFORM$5,
|
|
@@ -4671,18 +4627,15 @@ const SubDTaoBalanceModule = {
|
|
|
4671
4627
|
subscribeBalances: subscribeBalances$5,
|
|
4672
4628
|
getTransferCallData: getTransferCallData$5
|
|
4673
4629
|
};
|
|
4674
|
-
|
|
4675
|
-
//#region src/modules/substrate-dtao/types.ts
|
|
4630
|
+
// src/modules/substrate-dtao/types.ts
|
|
4676
4631
|
const SubDTaoTokenConfigSchema = zod_v4.default.strictObject({
|
|
4677
4632
|
netuid: _talismn_chaindata_provider.SubDTaoTokenSchema.shape.netuid,
|
|
4678
4633
|
...TokenConfigBaseSchema.shape
|
|
4679
4634
|
});
|
|
4680
|
-
|
|
4681
|
-
//#region src/modules/substrate-foreignassets/config.ts
|
|
4635
|
+
// src/modules/substrate-foreignassets/config.ts
|
|
4682
4636
|
const MODULE_TYPE$4 = _talismn_chaindata_provider.SubForeignAssetsTokenSchema.shape.type.value;
|
|
4683
4637
|
const PLATFORM$4 = _talismn_chaindata_provider.SubForeignAssetsTokenSchema.shape.platform.value;
|
|
4684
|
-
|
|
4685
|
-
//#region src/modules/substrate-foreignassets/buildQueries.ts
|
|
4638
|
+
// src/modules/substrate-foreignassets/buildQueries.ts
|
|
4686
4639
|
const buildQueries$1 = (networkId, balanceDefs, miniMetadata) => {
|
|
4687
4640
|
const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, { storage: ["ForeignAssets", "Account"] });
|
|
4688
4641
|
return balanceDefs.map(({ token, address }) => {
|
|
@@ -4735,8 +4688,7 @@ const buildQueries$1 = (networkId, balanceDefs, miniMetadata) => {
|
|
|
4735
4688
|
};
|
|
4736
4689
|
}).filter(_talismn_util.isNotNil);
|
|
4737
4690
|
};
|
|
4738
|
-
|
|
4739
|
-
//#region src/modules/substrate-foreignassets/fetchBalances.ts
|
|
4691
|
+
// src/modules/substrate-foreignassets/fetchBalances.ts
|
|
4740
4692
|
const fetchBalances$4 = async ({ networkId, tokensWithAddresses, connector, miniMetadata }) => {
|
|
4741
4693
|
if (!tokensWithAddresses.length) return {
|
|
4742
4694
|
success: [],
|
|
@@ -4803,8 +4755,7 @@ const fetchBalances$4 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4803
4755
|
errors: []
|
|
4804
4756
|
});
|
|
4805
4757
|
};
|
|
4806
|
-
|
|
4807
|
-
//#region src/modules/substrate-foreignassets/fetchTokens.ts
|
|
4758
|
+
// src/modules/substrate-foreignassets/fetchTokens.ts
|
|
4808
4759
|
const fetchTokens$4 = async ({ networkId, tokens, connector, miniMetadata }) => {
|
|
4809
4760
|
const anyMiniMetadata = miniMetadata;
|
|
4810
4761
|
if (!anyMiniMetadata?.data) return [];
|
|
@@ -4861,8 +4812,7 @@ const fetchTokens$4 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
4861
4812
|
return _talismn_chaindata_provider.SubForeignAssetsTokenSchema.safeParse(t).success;
|
|
4862
4813
|
});
|
|
4863
4814
|
};
|
|
4864
|
-
|
|
4865
|
-
//#region src/modules/substrate-foreignassets/getMiniMetadata.ts
|
|
4815
|
+
// src/modules/substrate-foreignassets/getMiniMetadata.ts
|
|
4866
4816
|
const getMiniMetadata$4 = ({ networkId, specVersion, metadataRpc }) => {
|
|
4867
4817
|
const source = MODULE_TYPE$4;
|
|
4868
4818
|
const chainId = networkId;
|
|
@@ -4902,8 +4852,7 @@ const getData$2 = ({ metadata, unifiedMetadata }) => {
|
|
|
4902
4852
|
}]);
|
|
4903
4853
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
4904
4854
|
};
|
|
4905
|
-
|
|
4906
|
-
//#region src/modules/substrate-foreignassets/getTransferCallData.ts
|
|
4855
|
+
// src/modules/substrate-foreignassets/getTransferCallData.ts
|
|
4907
4856
|
const getTransferCallData$4 = ({ from, to, value, token, type, metadataRpc }) => {
|
|
4908
4857
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$4)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$4}.`);
|
|
4909
4858
|
const { builder } = (0, _talismn_scale.parseMetadataRpc)(metadataRpc);
|
|
@@ -4962,8 +4911,7 @@ const getTransferAllEncodedArgs$1 = (onChainId, to, codec) => {
|
|
|
4962
4911
|
keep_alive: false
|
|
4963
4912
|
})]);
|
|
4964
4913
|
};
|
|
4965
|
-
|
|
4966
|
-
//#region src/modules/substrate-foreignassets/module.ts
|
|
4914
|
+
// src/modules/substrate-foreignassets/module.ts
|
|
4967
4915
|
const SubForeignAssetsBalanceModule = {
|
|
4968
4916
|
type: MODULE_TYPE$4,
|
|
4969
4917
|
platform: PLATFORM$4,
|
|
@@ -4973,18 +4921,15 @@ const SubForeignAssetsBalanceModule = {
|
|
|
4973
4921
|
subscribeBalances: createRpcQuerySubscribeBalances(buildQueries$1),
|
|
4974
4922
|
getTransferCallData: getTransferCallData$4
|
|
4975
4923
|
};
|
|
4976
|
-
|
|
4977
|
-
//#region src/modules/substrate-foreignassets/types.ts
|
|
4924
|
+
// src/modules/substrate-foreignassets/types.ts
|
|
4978
4925
|
const SubForeignAssetsTokenConfigSchema = zod_v4.default.strictObject({
|
|
4979
4926
|
onChainId: _talismn_chaindata_provider.SubForeignAssetsTokenSchema.shape.onChainId,
|
|
4980
4927
|
...TokenConfigBaseSchema.shape
|
|
4981
4928
|
});
|
|
4982
|
-
|
|
4983
|
-
//#region src/modules/substrate-hydration/config.ts
|
|
4929
|
+
// src/modules/substrate-hydration/config.ts
|
|
4984
4930
|
const MODULE_TYPE$3 = _talismn_chaindata_provider.SubHydrationTokenSchema.shape.type.value;
|
|
4985
4931
|
const PLATFORM$3 = _talismn_chaindata_provider.SubHydrationTokenSchema.shape.platform.value;
|
|
4986
|
-
|
|
4987
|
-
//#region src/modules/substrate-hydration/fetchBalances.ts
|
|
4932
|
+
// src/modules/substrate-hydration/fetchBalances.ts
|
|
4988
4933
|
const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, miniMetadata }) => {
|
|
4989
4934
|
if (!tokensWithAddresses.length) return {
|
|
4990
4935
|
success: [],
|
|
@@ -5084,8 +5029,7 @@ const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5084
5029
|
};
|
|
5085
5030
|
}
|
|
5086
5031
|
};
|
|
5087
|
-
|
|
5088
|
-
//#region src/modules/substrate-hydration/fetchTokens.ts
|
|
5032
|
+
// src/modules/substrate-hydration/fetchTokens.ts
|
|
5089
5033
|
const fetchTokens$3 = async ({ networkId, tokens, connector, miniMetadata }) => {
|
|
5090
5034
|
const anyMiniMetadata = miniMetadata;
|
|
5091
5035
|
if (!anyMiniMetadata?.data) return [];
|
|
@@ -5129,8 +5073,7 @@ const fetchTokens$3 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
5129
5073
|
return _talismn_chaindata_provider.SubHydrationTokenSchema.safeParse(t).success;
|
|
5130
5074
|
});
|
|
5131
5075
|
};
|
|
5132
|
-
|
|
5133
|
-
//#region src/modules/substrate-hydration/getMiniMetadata.ts
|
|
5076
|
+
// src/modules/substrate-hydration/getMiniMetadata.ts
|
|
5134
5077
|
const getMiniMetadata$3 = ({ networkId, specVersion, metadataRpc }) => {
|
|
5135
5078
|
const source = MODULE_TYPE$3;
|
|
5136
5079
|
const chainId = networkId;
|
|
@@ -5168,8 +5111,7 @@ const getData$1 = (metadataRpc) => {
|
|
|
5168
5111
|
}]);
|
|
5169
5112
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
5170
5113
|
};
|
|
5171
|
-
|
|
5172
|
-
//#region src/modules/substrate-hydration/getTransferCallData.ts
|
|
5114
|
+
// src/modules/substrate-hydration/getTransferCallData.ts
|
|
5173
5115
|
const getTransferCallData$3 = ({ from, to, value, token, metadataRpc }) => {
|
|
5174
5116
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$3)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$3}.`);
|
|
5175
5117
|
const { builder } = (0, _talismn_scale.parseMetadataRpc)(metadataRpc);
|
|
@@ -5185,8 +5127,7 @@ const getTransferCallData$3 = ({ from, to, value, token, metadataRpc }) => {
|
|
|
5185
5127
|
method: _polkadot_api_substrate_bindings.Binary.toHex(callData)
|
|
5186
5128
|
};
|
|
5187
5129
|
};
|
|
5188
|
-
|
|
5189
|
-
//#region src/modules/substrate-hydration/module.ts
|
|
5130
|
+
// src/modules/substrate-hydration/module.ts
|
|
5190
5131
|
const SubHydrationBalanceModule = {
|
|
5191
5132
|
type: MODULE_TYPE$3,
|
|
5192
5133
|
platform: PLATFORM$3,
|
|
@@ -5196,14 +5137,12 @@ const SubHydrationBalanceModule = {
|
|
|
5196
5137
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$3, fetchBalances$3),
|
|
5197
5138
|
getTransferCallData: getTransferCallData$3
|
|
5198
5139
|
};
|
|
5199
|
-
|
|
5200
|
-
//#region src/modules/substrate-hydration/types.ts
|
|
5140
|
+
// src/modules/substrate-hydration/types.ts
|
|
5201
5141
|
const SubHydrationTokenConfigSchema = zod_v4.default.strictObject({
|
|
5202
5142
|
onChainId: _talismn_chaindata_provider.SubHydrationTokenSchema.shape.onChainId,
|
|
5203
5143
|
...TokenConfigBaseSchema.shape
|
|
5204
5144
|
});
|
|
5205
|
-
|
|
5206
|
-
//#region src/modules/substrate-native/evmMirror.ts
|
|
5145
|
+
// src/modules/substrate-native/evmMirror.ts
|
|
5207
5146
|
const EVM_MIRROR_LOCK_LABEL = "evm-mirror";
|
|
5208
5147
|
const isEvmMirrorWithdrawableLock = (lock) => lock.meta?.type === "evm-mirror-withdrawable";
|
|
5209
5148
|
const findEvmMirrorWithdrawable = (locks) => {
|
|
@@ -5213,12 +5152,10 @@ const findEvmMirrorWithdrawable = (locks) => {
|
|
|
5213
5152
|
amount: lock.amount.planck
|
|
5214
5153
|
} : null;
|
|
5215
5154
|
};
|
|
5216
|
-
|
|
5217
|
-
//#region src/modules/substrate-native/config.ts
|
|
5155
|
+
// src/modules/substrate-native/config.ts
|
|
5218
5156
|
const MODULE_TYPE$2 = _talismn_chaindata_provider.SubNativeTokenSchema.shape.type.value;
|
|
5219
5157
|
const PLATFORM$2 = _talismn_chaindata_provider.SubNativeTokenSchema.shape.platform.value;
|
|
5220
|
-
|
|
5221
|
-
//#region src/modules/substrate-native/util/lockTypes.ts
|
|
5158
|
+
// src/modules/substrate-native/util/lockTypes.ts
|
|
5222
5159
|
const getOtherType = (input) => `other-${input}`;
|
|
5223
5160
|
/**
|
|
5224
5161
|
* For converting the value of `lock?.id?.toUtf8?.()` which is retrieved from
|
|
@@ -5276,8 +5213,7 @@ const getLockTitle = (lock, { balance } = {}) => {
|
|
|
5276
5213
|
if (lock.label.startsWith("other")) return "Locked";
|
|
5277
5214
|
return (0, lodash_es_upperFirst.default)(lock.label);
|
|
5278
5215
|
};
|
|
5279
|
-
|
|
5280
|
-
//#region src/modules/substrate-native/queries/buildBaseQueries.ts
|
|
5216
|
+
// src/modules/substrate-native/queries/buildBaseQueries.ts
|
|
5281
5217
|
const buildBaseQueries = (networkId, balanceDefs, miniMetadata, hasFrontierMirrorWithdraw = false) => {
|
|
5282
5218
|
const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, {
|
|
5283
5219
|
account: ["System", "Account"],
|
|
@@ -5471,8 +5407,7 @@ const decodePoolMemberResult = (coder, value, networkId) => {
|
|
|
5471
5407
|
})
|
|
5472
5408
|
};
|
|
5473
5409
|
};
|
|
5474
|
-
|
|
5475
|
-
//#region src/modules/substrate-native/util/nompoolAccountId.ts
|
|
5410
|
+
// src/modules/substrate-native/util/nompoolAccountId.ts
|
|
5476
5411
|
/**
|
|
5477
5412
|
* Each nominationPool in the nominationPools pallet has access to some accountIds which have no
|
|
5478
5413
|
* associated private key. Instead, they are derived from this function.
|
|
@@ -5496,8 +5431,7 @@ const nompoolAccountId = (palletId, poolId, index) => {
|
|
|
5496
5431
|
};
|
|
5497
5432
|
/** The stash account for the nomination pool */
|
|
5498
5433
|
const nompoolStashAccountId = (palletId, poolId) => nompoolAccountId(palletId, poolId, 0);
|
|
5499
|
-
|
|
5500
|
-
//#region src/modules/substrate-native/queries/buildNomPoolQueries.ts
|
|
5434
|
+
// src/modules/substrate-native/queries/buildNomPoolQueries.ts
|
|
5501
5435
|
const buildNomPoolQueries = (networkId, partialBalances, miniMetadata) => {
|
|
5502
5436
|
const networkStorageCoders = getNomPoolCoders(networkId, miniMetadata);
|
|
5503
5437
|
if (!networkStorageCoders) throw new Error(`No network storage coders found for networkId: ${networkId}`);
|
|
@@ -5579,8 +5513,7 @@ const getNomPoolStateKeys = (coders, nomPoolMemberInfo, extra) => {
|
|
|
5579
5513
|
return [];
|
|
5580
5514
|
}
|
|
5581
5515
|
};
|
|
5582
|
-
|
|
5583
|
-
//#region src/modules/substrate-native/fetchBalances.ts
|
|
5516
|
+
// src/modules/substrate-native/fetchBalances.ts
|
|
5584
5517
|
const fetchBalances$2 = async ({ networkId, tokensWithAddresses, connector, miniMetadata, hasFrontierMirrorWithdraw }) => {
|
|
5585
5518
|
if (!tokensWithAddresses.length) return {
|
|
5586
5519
|
success: [],
|
|
@@ -5628,8 +5561,7 @@ const fetchBalances$2 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5628
5561
|
errors: []
|
|
5629
5562
|
};
|
|
5630
5563
|
};
|
|
5631
|
-
|
|
5632
|
-
//#region src/modules/substrate-native/fetchTokens.ts
|
|
5564
|
+
// src/modules/substrate-native/fetchTokens.ts
|
|
5633
5565
|
const fetchTokens$2 = async ({ networkId, tokens, connector, miniMetadata }) => {
|
|
5634
5566
|
if (miniMetadata.extra.disable) return [];
|
|
5635
5567
|
const { tokenSymbol: symbol, tokenDecimals: decimals } = await getChainProperties(connector, networkId);
|
|
@@ -5667,8 +5599,7 @@ const getChainProperties = async (connector, networkId) => {
|
|
|
5667
5599
|
const properties = await connector.send(networkId, "system_properties", [], true);
|
|
5668
5600
|
return DotNetworkPropertiesSchema.parse(properties);
|
|
5669
5601
|
};
|
|
5670
|
-
|
|
5671
|
-
//#region src/modules/substrate-native/getMiniMetadata.ts
|
|
5602
|
+
// src/modules/substrate-native/getMiniMetadata.ts
|
|
5672
5603
|
const getMiniMetadata$2 = ({ networkId, specVersion, metadataRpc, config }) => {
|
|
5673
5604
|
const source = MODULE_TYPE$2;
|
|
5674
5605
|
const chainId = networkId;
|
|
@@ -5737,8 +5668,7 @@ const getMiniMetadata$2 = ({ networkId, specVersion, metadataRpc, config }) => {
|
|
|
5737
5668
|
}
|
|
5738
5669
|
};
|
|
5739
5670
|
};
|
|
5740
|
-
|
|
5741
|
-
//#region src/modules/substrate-native/getTransferCallData.ts
|
|
5671
|
+
// src/modules/substrate-native/getTransferCallData.ts
|
|
5742
5672
|
const getTransferCallData$2 = ({ from, to, value, token, type, metadataRpc }) => {
|
|
5743
5673
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$2)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$2}.`);
|
|
5744
5674
|
const { unifiedMetadata, lookupFn, builder } = (0, _talismn_scale.parseMetadataRpc)(metadataRpc);
|
|
@@ -5801,8 +5731,7 @@ const getTransferAllEncodedArgs = (to, codec) => {
|
|
|
5801
5731
|
keep_alive: false
|
|
5802
5732
|
})]);
|
|
5803
5733
|
};
|
|
5804
|
-
|
|
5805
|
-
//#region src/modules/substrate-native/subscribeBalances.ts
|
|
5734
|
+
// src/modules/substrate-native/subscribeBalances.ts
|
|
5806
5735
|
const subscribeBalances$2 = ({ networkId, tokensWithAddresses, connector, miniMetadata, hasFrontierMirrorWithdraw }) => {
|
|
5807
5736
|
if (!tokensWithAddresses.length) return (0, rxjs.of)({
|
|
5808
5737
|
success: [],
|
|
@@ -5820,8 +5749,7 @@ const subscribeBalances$2 = ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
5820
5749
|
errors: []
|
|
5821
5750
|
})));
|
|
5822
5751
|
};
|
|
5823
|
-
|
|
5824
|
-
//#region src/modules/substrate-native/module.ts
|
|
5752
|
+
// src/modules/substrate-native/module.ts
|
|
5825
5753
|
const SubNativeBalanceModule = {
|
|
5826
5754
|
type: MODULE_TYPE$2,
|
|
5827
5755
|
platform: PLATFORM$2,
|
|
@@ -5831,8 +5759,7 @@ const SubNativeBalanceModule = {
|
|
|
5831
5759
|
subscribeBalances: subscribeBalances$2,
|
|
5832
5760
|
getTransferCallData: getTransferCallData$2
|
|
5833
5761
|
};
|
|
5834
|
-
|
|
5835
|
-
//#region src/modules/substrate-native/types.ts
|
|
5762
|
+
// src/modules/substrate-native/types.ts
|
|
5836
5763
|
const SubNativeTokenConfigSchema = zod_v4.default.strictObject({ ...TokenConfigBaseSchema.shape });
|
|
5837
5764
|
const SubNativeModuleConfigSchema = zod_v4.default.strictObject({ disable: zod_v4.default.boolean().optional() });
|
|
5838
5765
|
const SubNativeMiniMetadataExtraSchema = zod_v4.default.strictObject({
|
|
@@ -5841,12 +5768,10 @@ const SubNativeMiniMetadataExtraSchema = zod_v4.default.strictObject({
|
|
|
5841
5768
|
existentialDeposit: zod_v4.default.string().optional(),
|
|
5842
5769
|
nominationPoolsPalletId: zod_v4.default.string().optional()
|
|
5843
5770
|
});
|
|
5844
|
-
|
|
5845
|
-
//#region src/modules/substrate-psp22/config.ts
|
|
5771
|
+
// src/modules/substrate-psp22/config.ts
|
|
5846
5772
|
const MODULE_TYPE$1 = _talismn_chaindata_provider.SubPsp22TokenSchema.shape.type.value;
|
|
5847
5773
|
const PLATFORM$1 = _talismn_chaindata_provider.SubPsp22TokenSchema.shape.platform.value;
|
|
5848
|
-
|
|
5849
|
-
//#region src/modules/abis/psp22.json
|
|
5774
|
+
// src/modules/abis/psp22.json
|
|
5850
5775
|
var spec = {
|
|
5851
5776
|
"constructors": [{
|
|
5852
5777
|
"args": [
|
|
@@ -6212,8 +6137,7 @@ var spec = {
|
|
|
6212
6137
|
}
|
|
6213
6138
|
]
|
|
6214
6139
|
};
|
|
6215
|
-
|
|
6216
|
-
//#region src/modules/substrate-psp22/util.ts
|
|
6140
|
+
// src/modules/substrate-psp22/util.ts
|
|
6217
6141
|
/** decodes an ss58 address to its 32-byte account id */
|
|
6218
6142
|
const accountId32 = (address) => {
|
|
6219
6143
|
const info = (0, _polkadot_api_substrate_bindings.getSs58AddressInfo)(address);
|
|
@@ -6275,8 +6199,7 @@ const encodeContractsApiCallArgs = (callFrom, contractAddress, inputData) => (0,
|
|
|
6275
6199
|
(0, scale_ts.Bytes)().enc(inputData)
|
|
6276
6200
|
]);
|
|
6277
6201
|
const makeContractCaller = ({ chainConnector, chainId }) => async (callFrom, contractAddress, inputData) => ContractExecResultCodec.dec(await chainConnector.send(chainId, "state_call", ["ContractsApi_call", (0, _polkadot_api_utils.toHex)(encodeContractsApiCallArgs(callFrom, contractAddress, inputData))]));
|
|
6278
|
-
|
|
6279
|
-
//#region src/modules/substrate-psp22/fetchBalances.ts
|
|
6202
|
+
// src/modules/substrate-psp22/fetchBalances.ts
|
|
6280
6203
|
const REVERT_FLAG = 1;
|
|
6281
6204
|
const decodeU128 = (bytes) => bytes.reduceRight((value, byte) => value << 8n | BigInt(byte), 0n);
|
|
6282
6205
|
/** ink! 3 returns a bare u128, ink! 4+ a `MessageResult<u128, LangError>` with a leading Ok/Err tag */
|
|
@@ -6331,8 +6254,7 @@ const fetchBalances$1 = async ({ networkId, tokensWithAddresses, connector }) =>
|
|
|
6331
6254
|
errors: []
|
|
6332
6255
|
});
|
|
6333
6256
|
};
|
|
6334
|
-
|
|
6335
|
-
//#region src/modules/substrate-psp22/fetchTokens.ts
|
|
6257
|
+
// src/modules/substrate-psp22/fetchTokens.ts
|
|
6336
6258
|
const fetchTokens$1 = async ({ networkId, tokens, connector }) => {
|
|
6337
6259
|
if (!tokens.length) return [];
|
|
6338
6260
|
const contractCall = makeContractCaller({
|
|
@@ -6374,8 +6296,7 @@ const fetchTokens$1 = async ({ networkId, tokens, connector }) => {
|
|
|
6374
6296
|
return _talismn_chaindata_provider.SubPsp22TokenSchema.safeParse(t).success;
|
|
6375
6297
|
});
|
|
6376
6298
|
};
|
|
6377
|
-
|
|
6378
|
-
//#region src/modules/substrate-psp22/getMiniMetadata.ts
|
|
6299
|
+
// src/modules/substrate-psp22/getMiniMetadata.ts
|
|
6379
6300
|
const getMiniMetadata$1 = ({ networkId, specVersion, metadataRpc }) => {
|
|
6380
6301
|
const source = MODULE_TYPE$1;
|
|
6381
6302
|
const chainId = networkId;
|
|
@@ -6398,8 +6319,7 @@ const getMiniMetadata$1 = ({ networkId, specVersion, metadataRpc }) => {
|
|
|
6398
6319
|
extra: null
|
|
6399
6320
|
};
|
|
6400
6321
|
};
|
|
6401
|
-
|
|
6402
|
-
//#region src/modules/substrate-psp22/getTransferCallData.ts
|
|
6322
|
+
// src/modules/substrate-psp22/getTransferCallData.ts
|
|
6403
6323
|
const getTransferCallData$1 = async ({ from, to, value, token, metadataRpc, connector }) => {
|
|
6404
6324
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE$1)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$1}.`);
|
|
6405
6325
|
const networkId = (0, _talismn_chaindata_provider.parseTokenId)(token.id).networkId;
|
|
@@ -6427,8 +6347,7 @@ const getTransferCallData$1 = async ({ from, to, value, token, metadataRpc, conn
|
|
|
6427
6347
|
method: _polkadot_api_substrate_bindings.Binary.toHex(callData)
|
|
6428
6348
|
};
|
|
6429
6349
|
};
|
|
6430
|
-
|
|
6431
|
-
//#region src/modules/substrate-psp22/module.ts
|
|
6350
|
+
// src/modules/substrate-psp22/module.ts
|
|
6432
6351
|
const SubPsp22BalanceModule = {
|
|
6433
6352
|
type: MODULE_TYPE$1,
|
|
6434
6353
|
platform: PLATFORM$1,
|
|
@@ -6438,18 +6357,15 @@ const SubPsp22BalanceModule = {
|
|
|
6438
6357
|
subscribeBalances: createPollingSubscribeBalances(MODULE_TYPE$1, fetchBalances$1),
|
|
6439
6358
|
getTransferCallData: getTransferCallData$1
|
|
6440
6359
|
};
|
|
6441
|
-
|
|
6442
|
-
//#region src/modules/substrate-psp22/types.ts
|
|
6360
|
+
// src/modules/substrate-psp22/types.ts
|
|
6443
6361
|
const SubPsp22TokenConfigSchema = zod_v4.default.strictObject({
|
|
6444
6362
|
contractAddress: _talismn_chaindata_provider.SubPsp22TokenSchema.shape.contractAddress,
|
|
6445
6363
|
...TokenConfigBaseSchema.shape
|
|
6446
6364
|
});
|
|
6447
|
-
|
|
6448
|
-
//#region src/modules/substrate-tokens/config.ts
|
|
6365
|
+
// src/modules/substrate-tokens/config.ts
|
|
6449
6366
|
const MODULE_TYPE = _talismn_chaindata_provider.SubTokensTokenSchema.shape.type.value;
|
|
6450
6367
|
const PLATFORM = _talismn_chaindata_provider.SubTokensTokenSchema.shape.platform.value;
|
|
6451
|
-
|
|
6452
|
-
//#region src/modules/substrate-tokens/buildQueries.ts
|
|
6368
|
+
// src/modules/substrate-tokens/buildQueries.ts
|
|
6453
6369
|
const buildQueries = (networkId, balanceDefs, miniMetadata) => {
|
|
6454
6370
|
const networkStorageCoders = buildNetworkStorageCoders(networkId, miniMetadata, { storage: [miniMetadata.extra.palletId, "Accounts"] });
|
|
6455
6371
|
return balanceDefs.map(({ token, address }) => {
|
|
@@ -6507,8 +6423,7 @@ const buildQueries = (networkId, balanceDefs, miniMetadata) => {
|
|
|
6507
6423
|
};
|
|
6508
6424
|
}).filter(_talismn_util.isNotNil);
|
|
6509
6425
|
};
|
|
6510
|
-
|
|
6511
|
-
//#region src/modules/substrate-tokens/fetchBalances.ts
|
|
6426
|
+
// src/modules/substrate-tokens/fetchBalances.ts
|
|
6512
6427
|
const fetchBalances = async ({ networkId, tokensWithAddresses, connector, miniMetadata }) => {
|
|
6513
6428
|
if (!tokensWithAddresses.length) return {
|
|
6514
6429
|
success: [],
|
|
@@ -6575,8 +6490,7 @@ const fetchBalances = async ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
6575
6490
|
errors: []
|
|
6576
6491
|
});
|
|
6577
6492
|
};
|
|
6578
|
-
|
|
6579
|
-
//#region src/modules/substrate-tokens/fetchTokens.ts
|
|
6493
|
+
// src/modules/substrate-tokens/fetchTokens.ts
|
|
6580
6494
|
const fetchTokens = async ({ networkId, tokens, miniMetadata }) => {
|
|
6581
6495
|
if (!miniMetadata?.data) return [];
|
|
6582
6496
|
return tokens.map((tokenConfig) => (0, lodash_es.assign)({
|
|
@@ -6592,8 +6506,7 @@ const fetchTokens = async ({ networkId, tokens, miniMetadata }) => {
|
|
|
6592
6506
|
isDefault: true
|
|
6593
6507
|
}, tokenConfig));
|
|
6594
6508
|
};
|
|
6595
|
-
|
|
6596
|
-
//#region src/modules/substrate-tokens/getMiniMetadata.ts
|
|
6509
|
+
// src/modules/substrate-tokens/getMiniMetadata.ts
|
|
6597
6510
|
const getMiniMetadata = ({ networkId, specVersion, metadataRpc, config }) => {
|
|
6598
6511
|
const source = MODULE_TYPE;
|
|
6599
6512
|
const chainId = networkId;
|
|
@@ -6626,8 +6539,7 @@ const getData = (metadataRpc, pallet) => {
|
|
|
6626
6539
|
}]);
|
|
6627
6540
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
6628
6541
|
};
|
|
6629
|
-
|
|
6630
|
-
//#region src/modules/substrate-tokens/getTransferCallData.ts
|
|
6542
|
+
// src/modules/substrate-tokens/getTransferCallData.ts
|
|
6631
6543
|
const getTransferCallData = ({ from, to, value, token, type, metadataRpc, config }) => {
|
|
6632
6544
|
if (!(0, _talismn_chaindata_provider.isTokenOfType)(token, MODULE_TYPE)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE}.`);
|
|
6633
6545
|
const { builder } = (0, _talismn_scale.parseMetadataRpc)(metadataRpc);
|
|
@@ -6729,8 +6641,7 @@ const getCallDataOptions = (to, token, value, type, config) => {
|
|
|
6729
6641
|
}
|
|
6730
6642
|
}] : []);
|
|
6731
6643
|
};
|
|
6732
|
-
|
|
6733
|
-
//#region src/modules/substrate-tokens/module.ts
|
|
6644
|
+
// src/modules/substrate-tokens/module.ts
|
|
6734
6645
|
const SubTokensBalanceModule = {
|
|
6735
6646
|
type: MODULE_TYPE,
|
|
6736
6647
|
platform: PLATFORM,
|
|
@@ -6740,8 +6651,7 @@ const SubTokensBalanceModule = {
|
|
|
6740
6651
|
subscribeBalances: createRpcQuerySubscribeBalances(buildQueries),
|
|
6741
6652
|
getTransferCallData
|
|
6742
6653
|
};
|
|
6743
|
-
|
|
6744
|
-
//#region src/modules/substrate-tokens/types.ts
|
|
6654
|
+
// src/modules/substrate-tokens/types.ts
|
|
6745
6655
|
const SubTokensTokenConfigSchema = zod_v4.default.strictObject({
|
|
6746
6656
|
onChainId: _talismn_chaindata_provider.SubTokensTokenSchema.shape.onChainId,
|
|
6747
6657
|
...TokenConfigBaseSchema.shape,
|
|
@@ -6751,8 +6661,7 @@ const SubTokensTokenConfigSchema = zod_v4.default.strictObject({
|
|
|
6751
6661
|
});
|
|
6752
6662
|
const SubTokensModuleConfigSchema = zod_v4.default.strictObject({ palletId: zod_v4.default.string().optional() });
|
|
6753
6663
|
const SubTokensMiniMetadataExtraSchema = zod_v4.default.strictObject({ palletId: zod_v4.default.string() });
|
|
6754
|
-
|
|
6755
|
-
//#region src/modules/index.ts
|
|
6664
|
+
// src/modules/index.ts
|
|
6756
6665
|
const BALANCE_MODULES = [
|
|
6757
6666
|
SubNativeBalanceModule,
|
|
6758
6667
|
SubAssetsBalanceModule,
|
|
@@ -6768,8 +6677,7 @@ const BALANCE_MODULES = [
|
|
|
6768
6677
|
SolSplBalanceModule,
|
|
6769
6678
|
SolToken2022BalanceModule
|
|
6770
6679
|
];
|
|
6771
|
-
|
|
6772
|
-
//#region src/getMiniMetadatas/getMetadataRpc.ts
|
|
6680
|
+
// src/getMiniMetadatas/getMetadataRpc.ts
|
|
6773
6681
|
const CACHE$1 = /* @__PURE__ */ new Map();
|
|
6774
6682
|
const getMetadataRpc = async (chainConnector, networkId) => {
|
|
6775
6683
|
if (CACHE$1.has(networkId)) return CACHE$1.get(networkId);
|
|
@@ -6784,8 +6692,7 @@ const getMetadataRpc = async (chainConnector, networkId) => {
|
|
|
6784
6692
|
CACHE$1.delete(networkId);
|
|
6785
6693
|
}
|
|
6786
6694
|
};
|
|
6787
|
-
|
|
6788
|
-
//#region src/getMiniMetadatas/getSpecVersion.ts
|
|
6695
|
+
// src/getMiniMetadatas/getSpecVersion.ts
|
|
6789
6696
|
const CACHE_GET_SPEC_VERSION = /* @__PURE__ */ new Map();
|
|
6790
6697
|
const fetchSpecVersion = async (chainConnector, networkId) => {
|
|
6791
6698
|
const { specVersion } = await chainConnector.send(networkId, "state_getRuntimeVersion", [], true);
|
|
@@ -6806,8 +6713,7 @@ const getSpecVersion = async (chainConnector, networkId) => {
|
|
|
6806
6713
|
CACHE_GET_SPEC_VERSION.delete(networkId);
|
|
6807
6714
|
}
|
|
6808
6715
|
};
|
|
6809
|
-
|
|
6810
|
-
//#region src/getMiniMetadatas/index.ts
|
|
6716
|
+
// src/getMiniMetadatas/index.ts
|
|
6811
6717
|
const getCacheKey = (networkId, specVersion) => `${networkId}:${specVersion}`;
|
|
6812
6718
|
const CACHE = /* @__PURE__ */ new Map();
|
|
6813
6719
|
const POOL = new p_queue.default({ concurrency: 4 });
|
|
@@ -6849,8 +6755,7 @@ const fetchMiniMetadatas = async (chainConnector, chaindataProvider, chainId, sp
|
|
|
6849
6755
|
log_default.debug("[miniMetadata] updated miniMetadatas for %s in %sms", chainId, (performance.now() - start).toFixed(2));
|
|
6850
6756
|
}
|
|
6851
6757
|
};
|
|
6852
|
-
|
|
6853
|
-
//#region src/BalancesProvider.ts
|
|
6758
|
+
// src/BalancesProvider.ts
|
|
6854
6759
|
/** Delay before resubscribing a substrate module stream that errored: 2s, doubling, capped at 1min */
|
|
6855
6760
|
const substrateModuleRetryDelay = (retryCount) => (0, rxjs.timer)(Math.min(6e4, 2e3 * 2 ** (retryCount - 1)));
|
|
6856
6761
|
const DEFAULT_STORAGE = {
|
|
@@ -7339,7 +7244,6 @@ const mergeSortedBalanceArrays = async (arrays, slicer) => {
|
|
|
7339
7244
|
return round[0];
|
|
7340
7245
|
};
|
|
7341
7246
|
const sortByMiniMetadataId = (a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
7342
|
-
//#endregion
|
|
7343
7247
|
exports.ALPHA_PRICE_SCALE = ALPHA_PRICE_SCALE;
|
|
7344
7248
|
exports.BALANCE_MODULES = BALANCE_MODULES;
|
|
7345
7249
|
exports.Balance = Balance;
|