@talismn/balances 3.0.1 → 3.0.3
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 +184 -184
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +179 -179
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -19
package/dist/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ import { publicKey, sol } from "@metaplex-foundation/umi";
|
|
|
18
18
|
import { TOKEN_2022_PROGRAM_ADDRESS, fetchMint, getMintDecoder as getMintDecoder$1, getTransferCheckedInstruction, getTransferCheckedWithFeeInstruction } from "@solana-program/token-2022";
|
|
19
19
|
import { AccountId, Binary, Enum, getSs58AddressInfo } from "@polkadot-api/substrate-bindings";
|
|
20
20
|
import { fromHex, mergeUint8, toHex as toHex$1 } from "@polkadot-api/utils";
|
|
21
|
-
import upperFirst from "lodash-es/upperFirst
|
|
21
|
+
import upperFirst from "lodash-es/upperFirst";
|
|
22
22
|
import { Bytes, Enum as Enum$1, Result, Struct, compact, enhanceCodec, u128, u32 } from "scale-ts";
|
|
23
23
|
import { fetchBestMetadata } from "@talismn/sapi";
|
|
24
24
|
//#region src/configureBigNumber.ts
|
|
@@ -1708,7 +1708,8 @@ const getCachedScaleBuilder = (miniMetadata) => {
|
|
|
1708
1708
|
}
|
|
1709
1709
|
let builder = null;
|
|
1710
1710
|
try {
|
|
1711
|
-
|
|
1711
|
+
const metadata = unifyMetadata(decAnyMetadata(miniMetadata.data));
|
|
1712
|
+
builder = getDynamicBuilder(getLookupFn(metadata));
|
|
1712
1713
|
} catch (cause) {
|
|
1713
1714
|
log_default.error(`Failed to build scale builder for chain ${miniMetadata.chainId}`, cause);
|
|
1714
1715
|
}
|
|
@@ -3662,7 +3663,8 @@ const fetchBalances$6 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
3662
3663
|
}))
|
|
3663
3664
|
};
|
|
3664
3665
|
}
|
|
3665
|
-
const
|
|
3666
|
+
const queries = buildQueries$2(networkId, balanceDefs, miniMetadata);
|
|
3667
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
3666
3668
|
return balanceDefs.reduce((acc, def) => {
|
|
3667
3669
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
3668
3670
|
if (balance) acc.success.push(balance);
|
|
@@ -4194,7 +4196,7 @@ const fetchRootStakeHolds = async (connector, networkId, metadataRpc, rootPairs,
|
|
|
4194
4196
|
};
|
|
4195
4197
|
const fetchUnlockInterval = async (connector, networkId, unifiedMetadata, builder, at) => {
|
|
4196
4198
|
const storageCoder = builder.buildStorage("SubtensorModule", "RootStakeUnlockInterval");
|
|
4197
|
-
const
|
|
4199
|
+
const query = {
|
|
4198
4200
|
stateKeys: [storageCoder.keys.enc()],
|
|
4199
4201
|
decodeResult: (changes) => {
|
|
4200
4202
|
const encoded = changes[0] ?? getUnlockIntervalFallback(unifiedMetadata, networkId);
|
|
@@ -4202,7 +4204,8 @@ const fetchUnlockInterval = async (connector, networkId, unifiedMetadata, builde
|
|
|
4202
4204
|
if (decoded === null) throw new Error(`Failed to decode RootStakeUnlockInterval on ${networkId}`);
|
|
4203
4205
|
return decoded;
|
|
4204
4206
|
}
|
|
4205
|
-
}
|
|
4207
|
+
};
|
|
4208
|
+
const [interval] = await fetchRpcQueryPack(connector, networkId, [query], at);
|
|
4206
4209
|
return interval ?? 0n;
|
|
4207
4210
|
};
|
|
4208
4211
|
const getUnlockIntervalFallback = (unifiedMetadata, networkId) => {
|
|
@@ -4226,7 +4229,7 @@ const fetchLastStakeBlocks = async (connector, networkId, builder, rootPairs, at
|
|
|
4226
4229
|
}
|
|
4227
4230
|
};
|
|
4228
4231
|
const storageCoder = builder.buildStorage("SubtensorModule", "LastColdkeyHotkeyStakeBlock");
|
|
4229
|
-
const
|
|
4232
|
+
const queries = rootPairs.map(({ address, hotkey }) => {
|
|
4230
4233
|
let stateKey;
|
|
4231
4234
|
try {
|
|
4232
4235
|
stateKey = storageCoder.keys.enc(address, hotkey);
|
|
@@ -4252,7 +4255,8 @@ const fetchLastStakeBlocks = async (connector, networkId, builder, rootPairs, at
|
|
|
4252
4255
|
};
|
|
4253
4256
|
}
|
|
4254
4257
|
};
|
|
4255
|
-
})
|
|
4258
|
+
});
|
|
4259
|
+
const [currentBlock, ...lastStakeBlocks] = await fetchRpcQueryPack(connector, networkId, [currentBlockQuery, ...queries], at);
|
|
4256
4260
|
return {
|
|
4257
4261
|
currentBlock,
|
|
4258
4262
|
lastStakeBlocks
|
|
@@ -4506,7 +4510,8 @@ const fetchTransferableTokensMap = async (connector, metadata, networkId) => {
|
|
|
4506
4510
|
const transferToggleCodec = builder.buildStorage("SubtensorModule", "TransferToggle");
|
|
4507
4511
|
const transferToggleKeys = await fetchStorageKeysPaged(connector, networkId, getStorageKeyPrefix("SubtensorModule", "TransferToggle"));
|
|
4508
4512
|
const transferToggleResults = await connector.send(networkId, "state_queryStorageAt", [transferToggleKeys]);
|
|
4509
|
-
|
|
4513
|
+
const transferToggleEntries = transferToggleResults.length ? transferToggleResults[0].changes : [];
|
|
4514
|
+
return fromPairs(transferToggleEntries.map(([key, value]) => {
|
|
4510
4515
|
const [netuid] = transferToggleCodec.keys.dec(key);
|
|
4511
4516
|
return [netuid, transferToggleCodec.value.dec(value)];
|
|
4512
4517
|
}));
|
|
@@ -4649,11 +4654,13 @@ const classifyValue = (previous, next) => {
|
|
|
4649
4654
|
if (previousLock?.type !== nextLock?.type || previousLock?.hotkey !== nextLock?.hotkey || previousLock?.lockType !== nextLock?.lockType) return changed("conviction lock meta");
|
|
4650
4655
|
if (previousMeta?.rootStakeHold?.unlockAtBlock !== nextMeta?.rootStakeHold?.unlockAtBlock) return changed("root stake hold meta");
|
|
4651
4656
|
let drift = false;
|
|
4652
|
-
if (previous.amount !== next.amount)
|
|
4653
|
-
if (
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
+
if (previous.amount !== next.amount) {
|
|
4658
|
+
if (previous.label === "Claimable rewards") {
|
|
4659
|
+
if (!isWithinDriftTolerance(previous.amount, next.amount, CLAIM_DRIFT_TOLERANCE_BPS)) drift = true;
|
|
4660
|
+
} else if (previousLock) drift = true;
|
|
4661
|
+
else if (isWithinDriftTolerance(previous.amount, next.amount, STAKE_DRIFT_TOLERANCE_BPS)) drift = true;
|
|
4662
|
+
else return changed(`amount ${previous.amount}→${next.amount}`);
|
|
4663
|
+
}
|
|
4657
4664
|
return { equivalence: drift ? "drift" : "equal" };
|
|
4658
4665
|
};
|
|
4659
4666
|
const keyOf = (value) => `${value.type}|${value.label}`;
|
|
@@ -4859,7 +4866,8 @@ const fetchBalances$4 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
4859
4866
|
}))
|
|
4860
4867
|
};
|
|
4861
4868
|
}
|
|
4862
|
-
const
|
|
4869
|
+
const queries = buildQueries$1(networkId, balanceDefs, miniMetadata);
|
|
4870
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
4863
4871
|
return balanceDefs.reduce((acc, def) => {
|
|
4864
4872
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
4865
4873
|
if (balance) acc.success.push(balance);
|
|
@@ -5125,7 +5133,7 @@ const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5125
5133
|
const addresses = uniq(balanceDefs.map((def) => def.address));
|
|
5126
5134
|
try {
|
|
5127
5135
|
const res = await Promise.all(addresses.map((address) => fetchRuntimeCallResult(connector, networkId, miniMetadata.data, "CurrenciesApi", "accounts", [address])));
|
|
5128
|
-
const
|
|
5136
|
+
const fetchedBalances = addresses.flatMap((address, index) => {
|
|
5129
5137
|
return res[index].map(([onChainId, balance]) => ({
|
|
5130
5138
|
address,
|
|
5131
5139
|
onChainId,
|
|
@@ -5133,7 +5141,8 @@ const fetchBalances$3 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5133
5141
|
reserved: balance.reserved.toString(),
|
|
5134
5142
|
frozen: balance.frozen.toString()
|
|
5135
5143
|
})).filter((b) => b.onChainId !== void 0);
|
|
5136
|
-
})
|
|
5144
|
+
});
|
|
5145
|
+
const balancesByKey = keyBy(fetchedBalances, (b) => `${b.address}:${b.onChainId}`);
|
|
5137
5146
|
return {
|
|
5138
5147
|
success: tokensWithAddresses.reduce((acc, [token, addresses]) => {
|
|
5139
5148
|
if (token.type === MODULE_TYPE$3) for (const address of addresses) {
|
|
@@ -5574,12 +5583,13 @@ const nompoolAccountId = (palletId, poolId, index) => {
|
|
|
5574
5583
|
const encIndex = new Uint8Array([index]);
|
|
5575
5584
|
const encPoolId = u32.enc(typeof poolId === "string" ? parseInt(poolId, 10) : poolId);
|
|
5576
5585
|
const remainingBytes = 32 - (encModPrefix.length + encPalletId.length + encIndex.length + encPoolId.length);
|
|
5586
|
+
const encEmptyH256 = new Uint8Array(remainingBytes);
|
|
5577
5587
|
const bytes = mergeUint8([
|
|
5578
5588
|
encModPrefix,
|
|
5579
5589
|
encPalletId,
|
|
5580
5590
|
encIndex,
|
|
5581
5591
|
encPoolId,
|
|
5582
|
-
|
|
5592
|
+
encEmptyH256
|
|
5583
5593
|
]);
|
|
5584
5594
|
return AccountId().dec(bytes);
|
|
5585
5595
|
};
|
|
@@ -5707,8 +5717,11 @@ const fetchBalances$2 = async ({ networkId, tokensWithAddresses, connector, mini
|
|
|
5707
5717
|
}))
|
|
5708
5718
|
};
|
|
5709
5719
|
}
|
|
5720
|
+
const baseQueries = buildBaseQueries(networkId, balanceDefs, miniMetadata);
|
|
5721
|
+
const partialBalances = await fetchRpcQueryPack(connector, networkId, baseQueries);
|
|
5722
|
+
const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
|
|
5710
5723
|
return {
|
|
5711
|
-
success: await fetchRpcQueryPack(connector, networkId,
|
|
5724
|
+
success: await fetchRpcQueryPack(connector, networkId, nomPoolQueries),
|
|
5712
5725
|
errors: []
|
|
5713
5726
|
};
|
|
5714
5727
|
};
|
|
@@ -5719,7 +5732,7 @@ const fetchTokens$2 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
5719
5732
|
const { tokenSymbol: symbol, tokenDecimals: decimals } = await getChainProperties(connector, networkId);
|
|
5720
5733
|
if (!miniMetadata.extra.existentialDeposit) log_default.warn(`Substrate native module: existentialDeposit is undefined for ${networkId}, using 0`);
|
|
5721
5734
|
const tokenConfig = tokens[0];
|
|
5722
|
-
const
|
|
5735
|
+
const nativeToken = {
|
|
5723
5736
|
id: subNativeTokenId(networkId),
|
|
5724
5737
|
type: "substrate-native",
|
|
5725
5738
|
platform: "polkadot",
|
|
@@ -5729,7 +5742,8 @@ const fetchTokens$2 = async ({ networkId, tokens, connector, miniMetadata }) =>
|
|
|
5729
5742
|
name: symbol,
|
|
5730
5743
|
decimals,
|
|
5731
5744
|
existentialDeposit: miniMetadata.extra.existentialDeposit ?? "0"
|
|
5732
|
-
}
|
|
5745
|
+
};
|
|
5746
|
+
const token = assign(nativeToken, tokenConfig);
|
|
5733
5747
|
const parsed = SubNativeTokenSchema.safeParse(token);
|
|
5734
5748
|
if (!parsed.success) return [];
|
|
5735
5749
|
return [parsed.data];
|
|
@@ -5895,7 +5909,8 @@ const subscribeBalances$2 = ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
5895
5909
|
await yieldToEventLoop();
|
|
5896
5910
|
return buildBaseQueries(networkId, balanceDefs, miniMetadata);
|
|
5897
5911
|
}).pipe(switchMap((baseQueries) => getRpcQueryPack$(connector, networkId, baseQueries)), switchMap((partialBalances) => {
|
|
5898
|
-
|
|
5912
|
+
const nomPoolQueries = buildNomPoolQueries(networkId, partialBalances, miniMetadata);
|
|
5913
|
+
return getRpcQueryPack$(connector, networkId, nomPoolQueries);
|
|
5899
5914
|
}), map((balances) => ({
|
|
5900
5915
|
success: balances,
|
|
5901
5916
|
errors: []
|
|
@@ -6669,7 +6684,8 @@ const fetchBalances = async ({ networkId, tokensWithAddresses, connector, miniMe
|
|
|
6669
6684
|
}))
|
|
6670
6685
|
};
|
|
6671
6686
|
}
|
|
6672
|
-
const
|
|
6687
|
+
const queries = buildQueries(networkId, balanceDefs, miniMetadata);
|
|
6688
|
+
const balances = await fetchRpcQueryPack(connector, networkId, queries);
|
|
6673
6689
|
return balanceDefs.reduce((acc, def) => {
|
|
6674
6690
|
const balance = balances.find((b) => b?.address === def.address && b?.tokenId === def.token.id);
|
|
6675
6691
|
if (balance) acc.success.push(balance);
|
|
@@ -7062,7 +7078,9 @@ var BalancesProvider = class {
|
|
|
7062
7078
|
return getDetectedTokensIds$(address);
|
|
7063
7079
|
}
|
|
7064
7080
|
getNetworkBalances$(networkId, addressesByTokenId) {
|
|
7065
|
-
|
|
7081
|
+
const network$ = this.#chaindataProvider.getNetworkById$(networkId);
|
|
7082
|
+
const tokensMapById$ = this.#chaindataProvider.getTokensMapById$();
|
|
7083
|
+
return combineLatest([network$, tokensMapById$]).pipe(map(([network, tokensMapById]) => ({
|
|
7066
7084
|
network,
|
|
7067
7085
|
tokens: keys(addressesByTokenId).map((tokenId) => tokensMapById[tokenId])
|
|
7068
7086
|
})), distinctUntilChanged((a, b) => a.network === b.network && a.tokens.every((token, i) => token === b.tokens[i])), switchMap(({ network, tokens }) => {
|
|
@@ -7437,7 +7455,7 @@ const getStaleVariant = (balance) => {
|
|
|
7437
7455
|
}
|
|
7438
7456
|
return variant;
|
|
7439
7457
|
};
|
|
7440
|
-
const LIVE_SEED_MAX_AGE_MS =
|
|
7458
|
+
const LIVE_SEED_MAX_AGE_MS = 3e5;
|
|
7441
7459
|
const liveVariants = /* @__PURE__ */ new WeakMap();
|
|
7442
7460
|
const seededLiveVariants = /* @__PURE__ */ new WeakSet();
|
|
7443
7461
|
const getLiveVariant = (balance) => {
|