@talismn/balances 3.0.4 → 3.0.6

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/README.md CHANGED
@@ -6,111 +6,34 @@
6
6
  [![npm-version](https://img.shields.io/npm/v/@talismn/balances?style=flat-square)](https://www.npmjs.com/package/@talismn/balances)
7
7
  [![npm-downloads](https://img.shields.io/npm/dw/@talismn/balances?style=flat-square)](https://www.npmjs.com/package/@talismn/balances)
8
8
 
9
- **@talismn/balances** is the core of a set of packages used to subscribe to on-chain account token balances.
9
+ **@talismn/balances** fetches and subscribes to on-chain account token balances for Polkadot SDK, Ethereum (EVM) and Solana networks.
10
10
 
11
- A quick rundown on each package is given below.
11
+ It includes:
12
12
 
13
- ### This (the core) package:
13
+ - `BalancesProvider`: the API that wallets and dapps use to fetch and subscribe to balances (`getBalances$`)
14
+ - `Balances` and `Balance`: classes that aggregate balances and expose `total`, `free`, `locked`, `reserved` and fiat values
15
+ - The balance modules, one per token type, which all implement `IBalanceModule`
14
16
 
15
- **@talismn/balances** (this package) includes:
17
+ Networks and tokens come from `@talismn/chaindata-provider`. RPC connections come from `@talismn/chain-connectors`.
16
18
 
17
- - An API which wallets / dapps can use to access balances
18
- - An interface for balance modules to implement
19
- - A shared database (powered by dexie) for balance modules to store balances in
20
- - Helpers (utility functions) for balance modules to use
21
- - Provides a plugin architecture, which is used by the balance module packages to specify their balance types
19
+ ### Balance modules
22
20
 
23
- ### The balance modules:
21
+ Each module is a folder in `src/modules/`:
24
22
 
25
- **@talismn/balances-default-modules**
23
+ | Module | Tokens |
24
+ | --- | --- |
25
+ | `substrate-native` | Native tokens of Polkadot SDK chains, including locks, reserves and staking |
26
+ | `substrate-assets` | `assets` pallet tokens |
27
+ | `substrate-foreignassets` | `foreignAssets` pallet tokens |
28
+ | `substrate-tokens` | ORML `tokens` pallet tokens |
29
+ | `substrate-hydration` | Hydration multi-currency tokens (`CurrenciesApi` runtime API) |
30
+ | `substrate-psp22` | PSP22 (ink! contract) tokens |
31
+ | `substrate-dtao` | Bittensor subnet (dTAO) alpha stake |
32
+ | `evm-native` | Native tokens of EVM networks |
33
+ | `evm-erc20` | ERC20 tokens |
34
+ | `evm-uniswapv2` | Uniswap V2 LP tokens |
35
+ | `sol-native` | SOL |
36
+ | `sol-spl` | SPL tokens |
37
+ | `sol-token2022` | Token-2022 tokens |
26
38
 
27
- - Collates the default balance modules (which can be found below) into a single package
28
-
29
- **@talismn/substrate-native**
30
-
31
- - A balance module for substrate native tokens
32
- - Subscribes to the `system.account` state query balance for each token
33
- - Also subscribes to the crowdloans pallet balances
34
- - Also subscribes to the nompools pallet balances
35
-
36
- **@talismn/substrate-orml**
37
-
38
- - A proof-of-concept balance module for ORML token pallet tokens
39
- - Attempts to auto-detect tokens
40
- - **You should use @talismn/substrate-tokens instead**
41
-
42
- **@talismn/substrate-tokens**
43
-
44
- - A balance module for substrate ORML token pallet tokens
45
- - Supports any token which can be queried via the `tokens.accounts` state query
46
- - Requires configuration for each token (no auto-detection)
47
- - We recommend that you use this module for ORML tokens
48
-
49
- **@talismn/substrate-assets**
50
-
51
- - A balance module for substrate assets pallet tokens
52
- - Supports any token which can be queried via the `assets.account` state query
53
- - Requires configuration for each token (no auto-detection)
54
-
55
- **@talismn/substrate-equilibrium**
56
-
57
- - A balance module for substrate eqBalances pallet tokens
58
- - Used by [Equilibrium](https://equilibrium.io/) and [Genshiro](https://genshiro.io/)
59
- - Supports auto-detection
60
-
61
- **@talismn/evm-native**
62
-
63
- - A balance module for evm native tokens
64
-
65
- **@talismn/evm-erc20**
66
-
67
- - A balance module for evm erc20 tokens
68
-
69
- ### The chain connectors:
70
-
71
- **@talismn/chain-connector**
72
-
73
- - A package which manages the open RPC connections to substrate chains
74
- - Allows developers to say "Send this query to the chain with this id", without them needing to specify which RPCs to use
75
- - Ensures that connections are only opened to the chains which are in use by the wallet/dapp
76
- - Ensures that only one connection is open per chain
77
- - Handles exponential backoff in the case of network failures
78
- - Provides an interface which can be shared between a serviceworker and frontend, which enables the two to share the pool of open connections
79
- - Provides an interface which mimics a polkadot-js `WsProvider`, which can be plugged into polkadot-js to make it use the shared pool of open connections
80
-
81
- **@talismn/chain-connector-evm**
82
-
83
- - A package which manages the connections to evm chains
84
- - Allows developers to say "Send this query to the chain with this id", without them needing to specify which RPC to use
85
-
86
- ### The chaindata provider:
87
-
88
- **@talismn/chaindata-provider**
89
-
90
- - A database (powered by dexie) to store chains, evm chains and tokens in
91
- - An interface to interact with the database
92
- - Syncs with the list in the [chaindata repository](https://github.com/talismansociety/chaindata) via graphql
93
- - Supports custom (end-user-defined) chains and rpc overrides
94
- - Provides a plugin architecture, which is used by the balance module packages to specify their token types
95
-
96
- ### The remaining packages:
97
-
98
- **@talismn/connection-meta**
99
-
100
- - Contains a small db which is used to optimise network performance in the wallet.
101
- - Two metrics are kept:
102
- - chainPriorityRpc (the last known well-behaved RPC for a chain)
103
- - chainBackoffInterval (the amount of time the wallet should wait before attempting to connect to a unreachable chain again)
104
-
105
- **@talismn/mutate-metadata**
106
-
107
- - A package which can splice a chain's metadata into smaller pieces
108
- - Enables us to make state queries across many chains at once without using all of the browser's memory
109
-
110
- **@talismn/token-rates**
111
-
112
- - Fetches and stores coingecko rates for each token in the @talismn/chaindata-provider database
113
-
114
- **@talismn/util**
115
-
116
- - Utility functions shared by the other packages, as well as the wallet and the portal
39
+ See `BalancesModules.md` for what a module must do.
package/dist/index.d.mts CHANGED
@@ -2,9 +2,9 @@ import "bignumber.js";
2
2
  import { AnyMiniMetadata, ChaindataProvider, DotNetworkId, EthNetworkId, MINIMETADATA_VERSION, NetworkId, NetworkList, SolNetworkId, Token, TokenId, TokenList, TokenOfType, TokenType } from "@talismn/chaindata-provider";
3
3
  import { NonFunctionProperties } from "@talismn/util";
4
4
  import { Observable } from "rxjs";
5
+ import { TokenRateCurrency, TokenRates, TokenRatesList } from "@talismn/token-rates";
5
6
  import z from "zod/v4";
6
7
  import { Instruction } from "@solana/kit";
7
- import { TokenRateCurrency, TokenRates, TokenRatesList } from "@talismn/token-rates";
8
8
  import { Mint, TransferFee } from "@solana-program/token-2022";
9
9
  import { Enum, Enum as Enum$1, GetEnum, ResultPayload, SS58String, SizedHex } from "@polkadot-api/substrate-bindings";
10
10
  import "@polkadot-api/utils";
@@ -82,25 +82,7 @@ export type ExtraAmount<TLabel extends string> = BaseAmountWithLabel<TLabel> & {
82
82
  includeInTotal?: boolean;
83
83
  };
84
84
  //#endregion
85
- //#region src/types/balances.d.ts
86
- type FormattedAmount<GenericAmount extends AmountWithLabel<TLabel>, TLabel extends string> = Omit<GenericAmount, "amount"> & {
87
- amount: BalanceFormatter;
88
- };
89
- export declare function excludeFromTransferableAmount(locks: Amount | FormattedAmount<LockedAmount<string>, string> | Array<FormattedAmount<LockedAmount<string>, string>>): bigint;
90
- export declare function excludeFromFeePayableLocks(locks: Amount | LockedAmount<string> | Array<LockedAmount<string>>): Array<LockedAmount<string>>;
91
- export declare function includeInTotalExtraAmount(extra?: FormattedAmount<ExtraAmount<string>, string> | Array<FormattedAmount<ExtraAmount<string>, string>>): bigint;
92
- /** A utility type used to extract the underlying `BalanceType` of a specific source from a generalised `BalanceJson` */
93
- export type NarrowBalanceType<S extends IBalance, P> = S extends {
94
- source: P;
95
- } ? S : never;
96
- export type BalanceSource = BalanceJson["source"];
97
- /** TODO: Remove this in favour of a frontend-friendly `ChaindataProvider` */
98
- export type HydrateDb = Partial<{
99
- networks: NetworkList;
100
- tokens: TokenList;
101
- tokenRates: TokenRatesList;
102
- }>;
103
- export type BalanceSearchQuery = Partial<NonFunctionProperties<Balance>> | ((balance: Balance) => boolean);
85
+ //#region src/classes/Balances.d.ts
104
86
  /**
105
87
  * A collection of balances.
106
88
  */
@@ -182,7 +164,6 @@ export declare class Balances {
182
164
  get count(): number;
183
165
  /**
184
166
  * Get the summed value of balances in this collection.
185
- * TODO: Sum up token amounts AND fiat amounts
186
167
  *
187
168
  * @example
188
169
  * // Get the sum of all transferable balances in usd.
@@ -190,10 +171,116 @@ export declare class Balances {
190
171
  */
191
172
  get sum(): SumBalancesFormatter;
192
173
  }
193
- export declare const getBalanceId: (balance: Pick<IBalance, "address" | "tokenId">) => string;
194
- /**
195
- * An individual balance.
196
- */
174
+ //#endregion
175
+ //#region src/classes/formatters.d.ts
176
+ export declare class BalanceValueGetter {
177
+ #private;
178
+ constructor(storage: BalanceJson);
179
+ get(valueType: BalanceStatusTypes): AmountWithLabel<string>[];
180
+ add(valueType: BalanceStatusTypes, amount: Omit<AmountWithLabel<string>, "type">): void;
181
+ }
182
+ export declare class BalanceFormatter {
183
+ #private;
184
+ constructor(planck: string | bigint | undefined, decimals?: number | undefined, fiatRatios?: TokenRates | null);
185
+ toJSON: () => string;
186
+ get planck(): bigint;
187
+ get tokens(): string;
188
+ fiat(currency: TokenRateCurrency): number | null;
189
+ }
190
+ export declare class PlanckSumBalancesFormatter {
191
+ #private;
192
+ constructor(balances: Balances);
193
+ /**
194
+ * The total balance of these tokens. Includes the free and the reserved amount.
195
+ */
196
+ get total(): bigint;
197
+ /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
198
+ get free(): bigint;
199
+ /** The reserved balance of these tokens. Is included in the total. */
200
+ get reserved(): bigint;
201
+ /** The frozen balance of these tokens. Is included in the free amount. */
202
+ get locked(): bigint;
203
+ /** @deprecated Use balances.locked */
204
+ get frozen(): bigint;
205
+ /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
206
+ get transferable(): bigint;
207
+ /** The unavailable balance of these tokens. */
208
+ get unavailable(): bigint;
209
+ /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
210
+ get feePayable(): bigint;
211
+ }
212
+ export declare class FiatSumBalancesFormatter {
213
+ #private;
214
+ constructor(balances: Balances, currency: TokenRateCurrency);
215
+ /**
216
+ * The total balance of these tokens. Includes the free and the reserved amount.
217
+ */
218
+ get total(): number;
219
+ /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
220
+ get free(): number;
221
+ /** The reserved balance of these tokens. Is included in the total. */
222
+ get reserved(): number;
223
+ /** The frozen balance of these tokens. Is included in the free amount. */
224
+ get locked(): number;
225
+ /** @deprecated Use balances.locked */
226
+ get frozen(): number;
227
+ /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
228
+ get transferable(): number;
229
+ /** The unavailable balance of these tokens. */
230
+ get unavailable(): number;
231
+ /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
232
+ get feePayable(): number;
233
+ }
234
+ export declare class SumBalancesFormatter {
235
+ #private;
236
+ constructor(balances: Balances);
237
+ get planck(): PlanckSumBalancesFormatter;
238
+ fiat(currency: TokenRateCurrency): FiatSumBalancesFormatter;
239
+ change24h(currency: TokenRateCurrency): Change24hCurrencyFormatter;
240
+ }
241
+ export declare class Change24hCurrencyFormatter {
242
+ #private;
243
+ constructor(balances: Balances, currency: TokenRateCurrency);
244
+ get total(): {
245
+ diff: number;
246
+ ratio: number;
247
+ } | null;
248
+ get free(): {
249
+ diff: number;
250
+ ratio: number;
251
+ } | null;
252
+ get reserved(): {
253
+ diff: number;
254
+ ratio: number;
255
+ } | null;
256
+ get locked(): {
257
+ diff: number;
258
+ ratio: number;
259
+ } | null;
260
+ get frozen(): {
261
+ diff: number;
262
+ ratio: number;
263
+ } | null;
264
+ get transferable(): {
265
+ diff: number;
266
+ ratio: number;
267
+ } | null;
268
+ get unavailable(): {
269
+ diff: number;
270
+ ratio: number;
271
+ } | null;
272
+ get feePayable(): {
273
+ diff: number;
274
+ ratio: number;
275
+ } | null;
276
+ }
277
+ //#endregion
278
+ //#region src/classes/FormattedAmount.d.ts
279
+ type FormattedAmount<GenericAmount extends AmountWithLabel<TLabel>, TLabel extends string> = Omit<GenericAmount, "amount"> & {
280
+ amount: BalanceFormatter;
281
+ };
282
+ //#endregion
283
+ //#region src/classes/Balance.d.ts
197
284
  export declare class Balance {
198
285
  #private;
199
286
  constructor(storage: BalanceJson | IBalance, hydrate?: HydrateDb);
@@ -338,9 +425,11 @@ export declare class Balance {
338
425
  coingeckoId?: string | undefined;
339
426
  noDiscovery?: boolean | undefined;
340
427
  mirrorOf?: string | undefined;
341
- type: "substrate-tokens";
428
+ type: "substrate-hydration";
342
429
  platform: "polkadot";
343
- onChainId: string | number;
430
+ onChainId: number;
431
+ assetType: "Erc20" | "External" | "Token";
432
+ isSufficient: boolean;
344
433
  existentialDeposit: string;
345
434
  } | {
346
435
  id: string;
@@ -353,12 +442,9 @@ export declare class Balance {
353
442
  coingeckoId?: string | undefined;
354
443
  noDiscovery?: boolean | undefined;
355
444
  mirrorOf?: string | undefined;
356
- type: "substrate-assets";
445
+ type: "substrate-psp22";
357
446
  platform: "polkadot";
358
- assetId: string;
359
- isFrozen?: boolean | undefined;
360
- isSufficient: boolean;
361
- existentialDeposit: string;
447
+ contractAddress: string;
362
448
  } | {
363
449
  id: string;
364
450
  networkId: string;
@@ -370,12 +456,9 @@ export declare class Balance {
370
456
  coingeckoId?: string | undefined;
371
457
  noDiscovery?: boolean | undefined;
372
458
  mirrorOf?: string | undefined;
373
- type: "substrate-hydration";
374
- platform: "polkadot";
375
- onChainId: number;
376
- assetType: "Erc20" | "External" | "Token";
377
- isSufficient: boolean;
378
- existentialDeposit: string;
459
+ type: "evm-erc20";
460
+ platform: "ethereum";
461
+ contractAddress: `0x${string}`;
379
462
  } | {
380
463
  id: string;
381
464
  networkId: string;
@@ -387,9 +470,8 @@ export declare class Balance {
387
470
  coingeckoId?: string | undefined;
388
471
  noDiscovery?: boolean | undefined;
389
472
  mirrorOf?: string | undefined;
390
- type: "sol-spl";
391
- platform: "solana";
392
- mintAddress: string;
473
+ type: "evm-native";
474
+ platform: "ethereum";
393
475
  } | {
394
476
  id: string;
395
477
  networkId: string;
@@ -401,10 +483,18 @@ export declare class Balance {
401
483
  coingeckoId?: string | undefined;
402
484
  noDiscovery?: boolean | undefined;
403
485
  mirrorOf?: string | undefined;
404
- type: "sol-token2022";
405
- platform: "solana";
406
- mintAddress: string;
407
- isTransferable?: boolean | undefined;
486
+ type: "evm-uniswapv2";
487
+ platform: "ethereum";
488
+ contractAddress: `0x${string}`;
489
+ isCustom?: boolean | undefined;
490
+ symbol0: string;
491
+ symbol1: string;
492
+ decimals0: number;
493
+ decimals1: number;
494
+ tokenAddress0: `0x${string}`;
495
+ tokenAddress1: `0x${string}`;
496
+ coingeckoId0?: string | undefined;
497
+ coingeckoId1?: string | undefined;
408
498
  } | {
409
499
  id: string;
410
500
  networkId: string;
@@ -416,9 +506,9 @@ export declare class Balance {
416
506
  coingeckoId?: string | undefined;
417
507
  noDiscovery?: boolean | undefined;
418
508
  mirrorOf?: string | undefined;
419
- type: "substrate-foreignassets";
509
+ type: "substrate-assets";
420
510
  platform: "polkadot";
421
- onChainId: string;
511
+ assetId: string;
422
512
  isFrozen?: boolean | undefined;
423
513
  isSufficient: boolean;
424
514
  existentialDeposit: string;
@@ -433,9 +523,12 @@ export declare class Balance {
433
523
  coingeckoId?: string | undefined;
434
524
  noDiscovery?: boolean | undefined;
435
525
  mirrorOf?: string | undefined;
436
- type: "substrate-psp22";
526
+ type: "substrate-dtao";
437
527
  platform: "polkadot";
438
- contractAddress: string;
528
+ netuid: number;
529
+ subnetName?: string | undefined;
530
+ hotkey?: string | undefined;
531
+ isTransferable: boolean;
439
532
  } | {
440
533
  id: string;
441
534
  networkId: string;
@@ -447,9 +540,12 @@ export declare class Balance {
447
540
  coingeckoId?: string | undefined;
448
541
  noDiscovery?: boolean | undefined;
449
542
  mirrorOf?: string | undefined;
450
- type: "evm-erc20";
451
- platform: "ethereum";
452
- contractAddress: `0x${string}`;
543
+ type: "substrate-foreignassets";
544
+ platform: "polkadot";
545
+ onChainId: string;
546
+ isFrozen?: boolean | undefined;
547
+ isSufficient: boolean;
548
+ existentialDeposit: string;
453
549
  } | {
454
550
  id: string;
455
551
  networkId: string;
@@ -461,8 +557,9 @@ export declare class Balance {
461
557
  coingeckoId?: string | undefined;
462
558
  noDiscovery?: boolean | undefined;
463
559
  mirrorOf?: string | undefined;
464
- type: "evm-native";
465
- platform: "ethereum";
560
+ type: "substrate-native";
561
+ platform: "polkadot";
562
+ existentialDeposit: string;
466
563
  } | {
467
564
  id: string;
468
565
  networkId: string;
@@ -474,18 +571,10 @@ export declare class Balance {
474
571
  coingeckoId?: string | undefined;
475
572
  noDiscovery?: boolean | undefined;
476
573
  mirrorOf?: string | undefined;
477
- type: "evm-uniswapv2";
478
- platform: "ethereum";
479
- contractAddress: `0x${string}`;
480
- isCustom?: boolean | undefined;
481
- symbol0: string;
482
- symbol1: string;
483
- decimals0: number;
484
- decimals1: number;
485
- tokenAddress0: `0x${string}`;
486
- tokenAddress1: `0x${string}`;
487
- coingeckoId0?: string | undefined;
488
- coingeckoId1?: string | undefined;
574
+ type: "substrate-tokens";
575
+ platform: "polkadot";
576
+ onChainId: string | number;
577
+ existentialDeposit: string;
489
578
  } | {
490
579
  id: string;
491
580
  networkId: string;
@@ -497,12 +586,8 @@ export declare class Balance {
497
586
  coingeckoId?: string | undefined;
498
587
  noDiscovery?: boolean | undefined;
499
588
  mirrorOf?: string | undefined;
500
- type: "substrate-dtao";
501
- platform: "polkadot";
502
- netuid: number;
503
- subnetName?: string | undefined;
504
- hotkey?: string | undefined;
505
- isTransferable: boolean;
589
+ type: "sol-native";
590
+ platform: "solana";
506
591
  } | {
507
592
  id: string;
508
593
  networkId: string;
@@ -514,9 +599,9 @@ export declare class Balance {
514
599
  coingeckoId?: string | undefined;
515
600
  noDiscovery?: boolean | undefined;
516
601
  mirrorOf?: string | undefined;
517
- type: "substrate-native";
518
- platform: "polkadot";
519
- existentialDeposit: string;
602
+ type: "sol-spl";
603
+ platform: "solana";
604
+ mintAddress: string;
520
605
  } | {
521
606
  id: string;
522
607
  networkId: string;
@@ -528,8 +613,10 @@ export declare class Balance {
528
613
  coingeckoId?: string | undefined;
529
614
  noDiscovery?: boolean | undefined;
530
615
  mirrorOf?: string | undefined;
531
- type: "sol-native";
616
+ type: "sol-token2022";
532
617
  platform: "solana";
618
+ mintAddress: string;
619
+ isTransferable?: boolean | undefined;
533
620
  } | null;
534
621
  get decimals(): number | null;
535
622
  get rates(): TokenRates | null;
@@ -581,117 +668,20 @@ export declare class Balance {
581
668
  /** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
582
669
  get feePayable(): BalanceFormatter;
583
670
  }
584
- /** raw "locked" values, straight from the IBalance JSON (see getRawTotalPlanck) */
585
- export declare const getRawLocks: (balance: IBalance) => AmountWithLabel<string>[];
586
- /**
587
- * Computes `new Balance(b).total.planck` without constructing a Balance (which allocates
588
- * several BalanceFormatters per access) — used for high-frequency zero-balance filtering.
589
- * MUST mirror Balance.total exactly, including the DelegatedStaking-hold/nompool rule
590
- * (guarded by a parity test in balance-raw-helpers.test.ts).
591
- */
592
- export declare const getRawTotalPlanck: (balance: IBalance) => bigint;
593
- export declare class BalanceValueGetter {
594
- #private;
595
- constructor(storage: BalanceJson);
596
- get(valueType: BalanceStatusTypes): AmountWithLabel<string>[];
597
- add(valueType: BalanceStatusTypes, amount: Omit<AmountWithLabel<string>, "type">): void;
598
- }
599
- export declare class BalanceFormatter {
600
- #private;
601
- constructor(planck: string | bigint | undefined, decimals?: number | undefined, fiatRatios?: TokenRates | null);
602
- toJSON: () => string;
603
- get planck(): bigint;
604
- get tokens(): string;
605
- fiat(currency: TokenRateCurrency): number | null;
606
- }
607
- export declare class PlanckSumBalancesFormatter {
608
- #private;
609
- constructor(balances: Balances);
610
- /**
611
- * The total balance of these tokens. Includes the free and the reserved amount.
612
- */
613
- get total(): bigint;
614
- /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
615
- get free(): bigint;
616
- /** The reserved balance of these tokens. Is included in the total. */
617
- get reserved(): bigint;
618
- /** The frozen balance of these tokens. Is included in the free amount. */
619
- get locked(): bigint;
620
- /** @deprecated Use balances.locked */
621
- get frozen(): bigint;
622
- /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
623
- get transferable(): bigint;
624
- /** The unavailable balance of these tokens. */
625
- get unavailable(): bigint;
626
- /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
627
- get feePayable(): bigint;
628
- }
629
- export declare class FiatSumBalancesFormatter {
630
- #private;
631
- constructor(balances: Balances, currency: TokenRateCurrency);
632
- /**
633
- * The total balance of these tokens. Includes the free and the reserved amount.
634
- */
635
- get total(): number;
636
- /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
637
- get free(): number;
638
- /** The reserved balance of these tokens. Is included in the total. */
639
- get reserved(): number;
640
- /** The frozen balance of these tokens. Is included in the free amount. */
641
- get locked(): number;
642
- /** @deprecated Use balances.locked */
643
- get frozen(): number;
644
- /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
645
- get transferable(): number;
646
- /** The unavailable balance of these tokens. */
647
- get unavailable(): number;
648
- /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
649
- get feePayable(): number;
650
- }
651
- export declare class SumBalancesFormatter {
652
- #private;
653
- constructor(balances: Balances);
654
- get planck(): PlanckSumBalancesFormatter;
655
- fiat(currency: TokenRateCurrency): FiatSumBalancesFormatter;
656
- change24h(currency: TokenRateCurrency): Change24hCurrencyFormatter;
657
- }
658
- export declare class Change24hCurrencyFormatter {
659
- #private;
660
- constructor(balances: Balances, currency: TokenRateCurrency);
661
- get total(): {
662
- diff: number;
663
- ratio: number;
664
- } | null;
665
- get free(): {
666
- diff: number;
667
- ratio: number;
668
- } | null;
669
- get reserved(): {
670
- diff: number;
671
- ratio: number;
672
- } | null;
673
- get locked(): {
674
- diff: number;
675
- ratio: number;
676
- } | null;
677
- get frozen(): {
678
- diff: number;
679
- ratio: number;
680
- } | null;
681
- get transferable(): {
682
- diff: number;
683
- ratio: number;
684
- } | null;
685
- get unavailable(): {
686
- diff: number;
687
- ratio: number;
688
- } | null;
689
- get feePayable(): {
690
- diff: number;
691
- ratio: number;
692
- } | null;
693
- }
694
- export declare const filterMirrorTokens: (balance: Balance, _i: number, balances: Balance[]) => boolean;
671
+ /** raw values of a given type, straight from the IBalance JSON (no Balance/formatter allocation) */
672
+ //#endregion
673
+ //#region src/types/balances.d.ts
674
+ export type NarrowBalanceType<S extends IBalance, P> = S extends {
675
+ source: P;
676
+ } ? S : never;
677
+ export type BalanceSource = BalanceJson["source"];
678
+ /** TODO: Remove this in favour of a frontend-friendly `ChaindataProvider` */
679
+ export type HydrateDb = Partial<{
680
+ networks: NetworkList;
681
+ tokens: TokenList;
682
+ tokenRates: TokenRatesList;
683
+ }>;
684
+ export type BalanceSearchQuery = Partial<NonFunctionProperties<Balance>> | ((balance: Balance) => boolean);
695
685
  //#endregion
696
686
  //#region src/types/chainConnectors.d.ts
697
687
  export type ChainConnectors = {
@@ -877,6 +867,28 @@ export declare class BalancesProvider {
877
867
  }
878
868
  export declare const getSweepStaleVariant: (balance: IBalance) => IBalance;
879
869
  //#endregion
870
+ //#region src/classes/helpers.d.ts
871
+ export declare function excludeFromTransferableAmount(locks: Amount | FormattedAmount<LockedAmount<string>, string> | Array<FormattedAmount<LockedAmount<string>, string>>): bigint;
872
+ export declare function excludeFromFeePayableLocks(locks: Amount | LockedAmount<string> | Array<LockedAmount<string>>): Array<LockedAmount<string>>;
873
+ export declare function includeInTotalExtraAmount(extra?: FormattedAmount<ExtraAmount<string>, string> | Array<FormattedAmount<ExtraAmount<string>, string>>): bigint;
874
+ /** A utility type used to extract the underlying `BalanceType` of a specific source from a generalised `BalanceJson` */
875
+ export declare const getBalanceId: (balance: Pick<IBalance, "address" | "tokenId">) => string;
876
+ /**
877
+ * An individual balance.
878
+ */
879
+ export declare const filterMirrorTokens: (balance: Balance, _i: number, balances: Balance[]) => boolean;
880
+ //#endregion
881
+ //#region src/classes/rawBalance.d.ts
882
+ /** raw "locked" values, straight from the IBalance JSON (see getRawTotalPlanck) */
883
+ export declare const getRawLocks: (balance: IBalance) => AmountWithLabel<string>[];
884
+ /**
885
+ * Computes `new Balance(b).total.planck` without constructing a Balance (which allocates
886
+ * several BalanceFormatters per access) — used for high-frequency zero-balance filtering.
887
+ * MUST mirror Balance.total exactly, including the DelegatedStaking-hold/nompool rule
888
+ * (guarded by a parity test in balance-raw-helpers.test.ts).
889
+ */
890
+ export declare const getRawTotalPlanck: (balance: IBalance) => bigint;
891
+ //#endregion
880
892
  //#region src/modules/abis/erc20BalancesAggregator.d.ts
881
893
  export declare const erc20BalancesAggregatorAbi: readonly [{
882
894
  readonly name: "balances";
@@ -23605,6 +23617,7 @@ export declare const BALANCE_MODULES: (IBalanceModule<"evm-erc20", {
23605
23617
  }, {
23606
23618
  palletId: string;
23607
23619
  }>)[];
23620
+ /** @deprecated unused */
23608
23621
  export type AnyBalanceModule = (typeof BALANCE_MODULES)[number];
23609
23622
  //#endregion
23610
23623
  export { type DTaoClaimTarget, type DTaoConvictionLockInfo, MINIMETADATA_VERSION };