@talismn/balances 3.0.2 → 3.0.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 +1914 -636
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +1909 -631
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -17
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
@@ -45,8 +45,8 @@ let _metaplex_foundation_umi = require("@metaplex-foundation/umi");
|
|
|
45
45
|
let _solana_program_token_2022 = require("@solana-program/token-2022");
|
|
46
46
|
let _polkadot_api_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
47
47
|
let _polkadot_api_utils = require("@polkadot-api/utils");
|
|
48
|
-
let
|
|
49
|
-
|
|
48
|
+
let lodash_es_upperFirst = require("lodash-es/upperFirst");
|
|
49
|
+
lodash_es_upperFirst = __toESM(lodash_es_upperFirst);
|
|
50
50
|
let scale_ts = require("scale-ts");
|
|
51
51
|
let _talismn_sapi = require("@talismn/sapi");
|
|
52
52
|
//#region src/configureBigNumber.ts
|
|
@@ -1736,7 +1736,8 @@ const getCachedScaleBuilder = (miniMetadata) => {
|
|
|
1736
1736
|
}
|
|
1737
1737
|
let builder = null;
|
|
1738
1738
|
try {
|
|
1739
|
-
|
|
1739
|
+
const metadata = (0, _talismn_scale.unifyMetadata)((0, _talismn_scale.decAnyMetadata)(miniMetadata.data));
|
|
1740
|
+
builder = (0, _talismn_scale.getDynamicBuilder)((0, _talismn_scale.getLookupFn)(metadata));
|
|
1740
1741
|
} catch (cause) {
|
|
1741
1742
|
log_default.error(`Failed to build scale builder for chain ${miniMetadata.chainId}`, cause);
|
|
1742
1743
|
}
|
|
@@ -3690,7 +3691,8 @@ const fetchBalances$6 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
3690
3691
|
}))
|
|
3691
3692
|
};
|
|
3692
3693
|
}
|
|
3693
|
-
const
|
|
3694
|
+
const queries = buildQueries$2(networkId, balanceDefs, miniMetadata);
|
|
3695
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
3694
3696
|
return balanceDefs.reduce((acc, def) => {
|
|
3695
3697
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
3696
3698
|
if (balance) acc.success.push(balance);
|
|
@@ -3964,28 +3966,26 @@ const findDTaoClaimablePlancks = (balances, { networkId, address, hotkey }) => {
|
|
|
3964
3966
|
return claimablePlancks > 0n ? claimablePlancks : null;
|
|
3965
3967
|
};
|
|
3966
3968
|
/**
|
|
3967
|
-
* Fetches the TAO each coldkey would
|
|
3969
|
+
* Fetches the TAO each coldkey would receive by claiming its validator beta baskets
|
|
3968
3970
|
* (Bittensor spec 441 "Root Reborn": root dividends accrue in per-validator escrow funds
|
|
3969
3971
|
* and must be claimed manually; the payout is TAO staked back onto the root position).
|
|
3970
3972
|
*
|
|
3971
|
-
* Amounts are
|
|
3972
|
-
*
|
|
3973
|
-
* `
|
|
3973
|
+
* Amounts are the chain's own claim preview (`redeemable_tao`, spec 468): the entitlement
|
|
3974
|
+
* minus the dust rows the claim would skip, which is the figure the chain compares to
|
|
3975
|
+
* `RootClaimableThreshold` and pays out. They are marked NAV quotes, so they move with
|
|
3976
|
+
* subnet pool prices as well as accrual. Attribution is per validator hotkey:
|
|
3977
|
+
* `get_root_basket_claim_previews` walks the chain's own coldkey→hotkeys index and so
|
|
3974
3978
|
* includes validators the coldkey fully unstaked from (entitlement survives unstaking).
|
|
3975
|
-
*
|
|
3976
|
-
* It is the only entitlement read: the coldkey-wide `get_root_basket_owed` total sums the
|
|
3977
|
-
* same positions, and claiming is per validator hotkey, so entitlement outside a position
|
|
3978
|
-
* would be unclaimable anyway.
|
|
3979
3979
|
*/
|
|
3980
3980
|
const fetchBasketClaims = async (connector, networkId, metadataRpc, addresses, at) => {
|
|
3981
3981
|
if (!addresses.length) return [];
|
|
3982
3982
|
const { unifiedMetadata, builder } = parseMetadataRpcCached(metadataRpc);
|
|
3983
|
-
if (!hasRuntimeApi(unifiedMetadata, "BetaBasketRuntimeApi", "
|
|
3983
|
+
if (!hasRuntimeApi(unifiedMetadata, "BetaBasketRuntimeApi", "get_root_basket_claim_previews")) return [];
|
|
3984
3984
|
try {
|
|
3985
|
-
return (await Promise.all(addresses.map(async (address) => [address, await fetchRuntimeCallResult(connector, networkId, builder, "BetaBasketRuntimeApi", "
|
|
3985
|
+
return (await Promise.all(addresses.map(async (address) => [address, await fetchRuntimeCallResult(connector, networkId, builder, "BetaBasketRuntimeApi", "get_root_basket_claim_previews", [address], at)]))).flatMap(([address, previews]) => previews.filter((preview) => preview.redeemable_tao > 0n).map((preview) => ({
|
|
3986
3986
|
address,
|
|
3987
|
-
hotkey,
|
|
3988
|
-
amount:
|
|
3987
|
+
hotkey: preview.hotkey,
|
|
3988
|
+
amount: preview.redeemable_tao
|
|
3989
3989
|
})));
|
|
3990
3990
|
} catch (cause) {
|
|
3991
3991
|
log_default.warn(`Failed to fetch beta basket claims on ${networkId}`, { cause });
|
|
@@ -4222,7 +4222,7 @@ const fetchRootStakeHolds = async (connector, networkId, metadataRpc, rootPairs,
|
|
|
4222
4222
|
};
|
|
4223
4223
|
const fetchUnlockInterval = async (connector, networkId, unifiedMetadata, builder, at) => {
|
|
4224
4224
|
const storageCoder = builder.buildStorage("SubtensorModule", "RootStakeUnlockInterval");
|
|
4225
|
-
const
|
|
4225
|
+
const query = {
|
|
4226
4226
|
stateKeys: [storageCoder.keys.enc()],
|
|
4227
4227
|
decodeResult: (changes) => {
|
|
4228
4228
|
const encoded = changes[0] ?? getUnlockIntervalFallback(unifiedMetadata, networkId);
|
|
@@ -4230,7 +4230,8 @@ const fetchUnlockInterval = async (connector, networkId, unifiedMetadata, builde
|
|
|
4230
4230
|
if (decoded === null) throw new Error(`Failed to decode RootStakeUnlockInterval on ${networkId}`);
|
|
4231
4231
|
return decoded;
|
|
4232
4232
|
}
|
|
4233
|
-
}
|
|
4233
|
+
};
|
|
4234
|
+
const [interval] = await fetchRpcQueryPack(connector, networkId, [query], at);
|
|
4234
4235
|
return interval ?? 0n;
|
|
4235
4236
|
};
|
|
4236
4237
|
const getUnlockIntervalFallback = (unifiedMetadata, networkId) => {
|
|
@@ -4254,7 +4255,7 @@ const fetchLastStakeBlocks = async (connector, networkId, builder, rootPairs, at
|
|
|
4254
4255
|
}
|
|
4255
4256
|
};
|
|
4256
4257
|
const storageCoder = builder.buildStorage("SubtensorModule", "LastColdkeyHotkeyStakeBlock");
|
|
4257
|
-
const
|
|
4258
|
+
const queries = rootPairs.map(({ address, hotkey }) => {
|
|
4258
4259
|
let stateKey;
|
|
4259
4260
|
try {
|
|
4260
4261
|
stateKey = storageCoder.keys.enc(address, hotkey);
|
|
@@ -4280,7 +4281,8 @@ const fetchLastStakeBlocks = async (connector, networkId, builder, rootPairs, at
|
|
|
4280
4281
|
};
|
|
4281
4282
|
}
|
|
4282
4283
|
};
|
|
4283
|
-
})
|
|
4284
|
+
});
|
|
4285
|
+
const [currentBlock, ...lastStakeBlocks] = await fetchRpcQueryPack(connector, networkId, [currentBlockQuery, ...queries], at);
|
|
4284
4286
|
return {
|
|
4285
4287
|
currentBlock,
|
|
4286
4288
|
lastStakeBlocks
|
|
@@ -4534,7 +4536,8 @@ const fetchTransferableTokensMap = async (connector, metadata, networkId) => {
|
|
|
4534
4536
|
const transferToggleCodec = builder.buildStorage("SubtensorModule", "TransferToggle");
|
|
4535
4537
|
const transferToggleKeys = await fetchStorageKeysPaged(connector, networkId, (0, _talismn_scale.getStorageKeyPrefix)("SubtensorModule", "TransferToggle"));
|
|
4536
4538
|
const transferToggleResults = await connector.send(networkId, "state_queryStorageAt", [transferToggleKeys]);
|
|
4537
|
-
|
|
4539
|
+
const transferToggleEntries = transferToggleResults.length ? transferToggleResults[0].changes : [];
|
|
4540
|
+
return (0, lodash_es.fromPairs)(transferToggleEntries.map(([key, value]) => {
|
|
4538
4541
|
const [netuid] = transferToggleCodec.keys.dec(key);
|
|
4539
4542
|
return [netuid, transferToggleCodec.value.dec(value)];
|
|
4540
4543
|
}));
|
|
@@ -4589,7 +4592,7 @@ const getData$3 = (metadataRpc) => {
|
|
|
4589
4592
|
},
|
|
4590
4593
|
{
|
|
4591
4594
|
runtimeApi: "BetaBasketRuntimeApi",
|
|
4592
|
-
methods: ["
|
|
4595
|
+
methods: ["get_root_basket_claim_previews"]
|
|
4593
4596
|
}
|
|
4594
4597
|
]);
|
|
4595
4598
|
return (0, _talismn_scale.encodeMetadata)(metadata);
|
|
@@ -4677,11 +4680,13 @@ const classifyValue = (previous, next) => {
|
|
|
4677
4680
|
if (previousLock?.type !== nextLock?.type || previousLock?.hotkey !== nextLock?.hotkey || previousLock?.lockType !== nextLock?.lockType) return changed("conviction lock meta");
|
|
4678
4681
|
if (previousMeta?.rootStakeHold?.unlockAtBlock !== nextMeta?.rootStakeHold?.unlockAtBlock) return changed("root stake hold meta");
|
|
4679
4682
|
let drift = false;
|
|
4680
|
-
if (previous.amount !== next.amount)
|
|
4681
|
-
if (
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4683
|
+
if (previous.amount !== next.amount) {
|
|
4684
|
+
if (previous.label === "Claimable rewards") {
|
|
4685
|
+
if (!isWithinDriftTolerance(previous.amount, next.amount, CLAIM_DRIFT_TOLERANCE_BPS)) drift = true;
|
|
4686
|
+
} else if (previousLock) drift = true;
|
|
4687
|
+
else if (isWithinDriftTolerance(previous.amount, next.amount, STAKE_DRIFT_TOLERANCE_BPS)) drift = true;
|
|
4688
|
+
else return changed(`amount ${previous.amount}→${next.amount}`);
|
|
4689
|
+
}
|
|
4685
4690
|
return { equivalence: drift ? "drift" : "equal" };
|
|
4686
4691
|
};
|
|
4687
4692
|
const keyOf = (value) => `${value.type}|${value.label}`;
|
|
@@ -4887,7 +4892,8 @@ const fetchBalances$4 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4887
4892
|
}))
|
|
4888
4893
|
};
|
|
4889
4894
|
}
|
|
4890
|
-
const
|
|
4895
|
+
const queries = buildQueries$1(networkId, balanceDefs, miniMetadata);
|
|
4896
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
4891
4897
|
return balanceDefs.reduce((acc, def) => {
|
|
4892
4898
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
4893
4899
|
if (balance) acc.success.push(balance);
|
|
@@ -5153,7 +5159,7 @@ const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5153
5159
|
const addresses = (0, lodash_es.uniq)(balanceDefs.map((def) => def.address));
|
|
5154
5160
|
try {
|
|
5155
5161
|
const res = await Promise.all(addresses.map((address) => fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "CurrenciesApi", "accounts", [address])));
|
|
5156
|
-
const
|
|
5162
|
+
const fetchedBalances = addresses.flatMap((address, index) => {
|
|
5157
5163
|
return res[index].map(([onChainId, balance]) => ({
|
|
5158
5164
|
address,
|
|
5159
5165
|
onChainId,
|
|
@@ -5161,7 +5167,8 @@ const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5161
5167
|
reserved: balance.reserved.toString(),
|
|
5162
5168
|
frozen: balance.frozen.toString()
|
|
5163
5169
|
})).filter((b) => b.onChainId !== void 0);
|
|
5164
|
-
})
|
|
5170
|
+
});
|
|
5171
|
+
const balancesByKey = (0, lodash_es.keyBy)(fetchedBalances, (b) => `${b.address}:${b.onChainId}`);
|
|
5165
5172
|
return {
|
|
5166
5173
|
success: tokensWithAddresses.reduce((acc, [token, addresses]) => {
|
|
5167
5174
|
if (token.type === MODULE_TYPE$3) for (const address of addresses) {
|
|
@@ -5427,7 +5434,7 @@ const getLockTitle = (lock, { balance } = {}) => {
|
|
|
5427
5434
|
if (lock.label === "fees") return "Locked (Fees)";
|
|
5428
5435
|
if (lock.label === "misc") return "Locked";
|
|
5429
5436
|
if (lock.label.startsWith("other")) return "Locked";
|
|
5430
|
-
return (0,
|
|
5437
|
+
return (0, lodash_es_upperFirst.default)(lock.label);
|
|
5431
5438
|
};
|
|
5432
5439
|
//#endregion
|
|
5433
5440
|
//#region src/modules/substrate-native/queries/buildBaseQueries.ts
|
|
@@ -5602,12 +5609,13 @@ const nompoolAccountId = (palletId, poolId, index) => {
|
|
|
5602
5609
|
const encIndex = new Uint8Array([index]);
|
|
5603
5610
|
const encPoolId = scale_ts.u32.enc(typeof poolId === "string" ? parseInt(poolId, 10) : poolId);
|
|
5604
5611
|
const remainingBytes = 32 - (encModPrefix.length + encPalletId.length + encIndex.length + encPoolId.length);
|
|
5612
|
+
const encEmptyH256 = new Uint8Array(remainingBytes);
|
|
5605
5613
|
const bytes = (0, _polkadot_api_utils.mergeUint8)([
|
|
5606
5614
|
encModPrefix,
|
|
5607
5615
|
encPalletId,
|
|
5608
5616
|
encIndex,
|
|
5609
5617
|
encPoolId,
|
|
5610
|
-
|
|
5618
|
+
encEmptyH256
|
|
5611
5619
|
]);
|
|
5612
5620
|
return (0, _polkadot_api_substrate_bindings.AccountId)().dec(bytes);
|
|
5613
5621
|
};
|
|
@@ -5735,8 +5743,11 @@ const fetchBalances$2 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5735
5743
|
}))
|
|
5736
5744
|
};
|
|
5737
5745
|
}
|
|
5746
|
+
const baseQueries = buildBaseQueries(networkId, balanceDefs, miniMetadata);
|
|
5747
|
+
const partialBalances = await fetchRpcQueryPack(connector, networkId, baseQueries);
|
|
5748
|
+
const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
|
|
5738
5749
|
return {
|
|
5739
|
-
success: await fetchRpcQueryPack(connector, networkId,
|
|
5750
|
+
success: await fetchRpcQueryPack(connector, networkId, nomPoolQueries),
|
|
5740
5751
|
errors: []
|
|
5741
5752
|
};
|
|
5742
5753
|
};
|
|
@@ -5747,7 +5758,7 @@ const fetchTokens$2 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
5747
5758
|
const { tokenSymbol: symbol, tokenDecimals: decimals } = await getChainProperties(connector, networkId);
|
|
5748
5759
|
if (!miniMetadata.extra.existentialDeposit) log_default.warn(`Substrate native module: existentialDeposit is undefined for ${networkId}, using 0`);
|
|
5749
5760
|
const tokenConfig = tokens[0];
|
|
5750
|
-
const
|
|
5761
|
+
const nativeToken = {
|
|
5751
5762
|
id: (0, _talismn_chaindata_provider.subNativeTokenId)(networkId),
|
|
5752
5763
|
type: "substrate-native",
|
|
5753
5764
|
platform: "polkadot",
|
|
@@ -5757,7 +5768,8 @@ const fetchTokens$2 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
5757
5768
|
name: symbol,
|
|
5758
5769
|
decimals,
|
|
5759
5770
|
existentialDeposit: miniMetadata.extra.existentialDeposit ?? "0"
|
|
5760
|
-
}
|
|
5771
|
+
};
|
|
5772
|
+
const token = (0, lodash_es.assign)(nativeToken, tokenConfig);
|
|
5761
5773
|
const parsed = _talismn_chaindata_provider.SubNativeTokenSchema.safeParse(token);
|
|
5762
5774
|
if (!parsed.success) return [];
|
|
5763
5775
|
return [parsed.data];
|
|
@@ -5923,7 +5935,8 @@ const subscribeBalances$2 = ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
5923
5935
|
await (0, _talismn_util.yieldToEventLoop)();
|
|
5924
5936
|
return buildBaseQueries(networkId, balanceDefs, miniMetadata);
|
|
5925
5937
|
}).pipe((0, rxjs.switchMap)((baseQueries) => getRpcQueryPack$(connector, networkId, baseQueries)), (0, rxjs.switchMap)((partialBalances) => {
|
|
5926
|
-
|
|
5938
|
+
const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
|
|
5939
|
+
return getRpcQueryPack$(connector, networkId, nomPoolQueries);
|
|
5927
5940
|
}), (0, rxjs.map)((balances) => ({
|
|
5928
5941
|
success: balances,
|
|
5929
5942
|
errors: []
|
|
@@ -6697,7 +6710,8 @@ const fetchBalances = async ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
6697
6710
|
}))
|
|
6698
6711
|
};
|
|
6699
6712
|
}
|
|
6700
|
-
const
|
|
6713
|
+
const queries = buildQueries(networkId, balanceDefs, miniMetadata);
|
|
6714
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
6701
6715
|
return balanceDefs.reduce((acc, def) => {
|
|
6702
6716
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
6703
6717
|
if (balance) acc.success.push(balance);
|
|
@@ -7090,7 +7104,9 @@ var BalancesProvider = class {
|
|
|
7090
7104
|
return getDetectedTokensIds$(address);
|
|
7091
7105
|
}
|
|
7092
7106
|
getNetworkBalances$(networkId, addressesByTokenId) {
|
|
7093
|
-
|
|
7107
|
+
const network$ = this.#chaindataProvider.getNetworkById$(networkId);
|
|
7108
|
+
const tokensMapById$ = this.#chaindataProvider.getTokensMapById$();
|
|
7109
|
+
return (0, rxjs.combineLatest)([network$, tokensMapById$]).pipe((0, rxjs.map)(([network, tokensMapById]) => ({
|
|
7094
7110
|
network,
|
|
7095
7111
|
tokens: (0, lodash_es.keys)(addressesByTokenId).map((tokenId) => tokensMapById[tokenId])
|
|
7096
7112
|
})), (0, rxjs.distinctUntilChanged)((a, b) => a.network === b.network && a.tokens.every((token, i) => token === b.tokens[i])), (0, rxjs.switchMap)(({ network, tokens }) => {
|
|
@@ -7465,7 +7481,7 @@ const getStaleVariant = (balance) => {
|
|
|
7465
7481
|
}
|
|
7466
7482
|
return variant;
|
|
7467
7483
|
};
|
|
7468
|
-
const LIVE_SEED_MAX_AGE_MS =
|
|
7484
|
+
const LIVE_SEED_MAX_AGE_MS = 3e5;
|
|
7469
7485
|
const liveVariants = /* @__PURE__ */ new WeakMap();
|
|
7470
7486
|
const seededLiveVariants = /* @__PURE__ */ new WeakSet();
|
|
7471
7487
|
const getLiveVariant = (balance) => {
|