@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/dist/index.d.ts CHANGED
@@ -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,18 @@ export declare class Balance {
338
425
  coingeckoId?: string | undefined;
339
426
  noDiscovery?: boolean | undefined;
340
427
  mirrorOf?: string | undefined;
341
- type: "sol-spl";
342
- platform: "solana";
343
- mintAddress: string;
428
+ type: "evm-uniswapv2";
429
+ platform: "ethereum";
430
+ contractAddress: `0x${string}`;
431
+ isCustom?: boolean | undefined;
432
+ symbol0: string;
433
+ symbol1: string;
434
+ decimals0: number;
435
+ decimals1: number;
436
+ tokenAddress0: `0x${string}`;
437
+ tokenAddress1: `0x${string}`;
438
+ coingeckoId0?: string | undefined;
439
+ coingeckoId1?: string | undefined;
344
440
  } | {
345
441
  id: string;
346
442
  networkId: string;
@@ -352,9 +448,9 @@ export declare class Balance {
352
448
  coingeckoId?: string | undefined;
353
449
  noDiscovery?: boolean | undefined;
354
450
  mirrorOf?: string | undefined;
355
- type: "evm-erc20";
356
- platform: "ethereum";
357
- contractAddress: `0x${string}`;
451
+ type: "sol-spl";
452
+ platform: "solana";
453
+ mintAddress: string;
358
454
  } | {
359
455
  id: string;
360
456
  networkId: string;
@@ -366,8 +462,10 @@ export declare class Balance {
366
462
  coingeckoId?: string | undefined;
367
463
  noDiscovery?: boolean | undefined;
368
464
  mirrorOf?: string | undefined;
369
- type: "evm-native";
370
- platform: "ethereum";
465
+ type: "substrate-tokens";
466
+ platform: "polkadot";
467
+ onChainId: string | number;
468
+ existentialDeposit: string;
371
469
  } | {
372
470
  id: string;
373
471
  networkId: string;
@@ -379,11 +477,8 @@ export declare class Balance {
379
477
  coingeckoId?: string | undefined;
380
478
  noDiscovery?: boolean | undefined;
381
479
  mirrorOf?: string | undefined;
382
- type: "substrate-foreignassets";
480
+ type: "substrate-native";
383
481
  platform: "polkadot";
384
- onChainId: string;
385
- isFrozen?: boolean | undefined;
386
- isSufficient: boolean;
387
482
  existentialDeposit: string;
388
483
  } | {
389
484
  id: string;
@@ -396,10 +491,8 @@ export declare class Balance {
396
491
  coingeckoId?: string | undefined;
397
492
  noDiscovery?: boolean | undefined;
398
493
  mirrorOf?: string | undefined;
399
- type: "sol-token2022";
494
+ type: "sol-native";
400
495
  platform: "solana";
401
- mintAddress: string;
402
- isTransferable?: boolean | undefined;
403
496
  } | {
404
497
  id: string;
405
498
  networkId: string;
@@ -411,9 +504,9 @@ export declare class Balance {
411
504
  coingeckoId?: string | undefined;
412
505
  noDiscovery?: boolean | undefined;
413
506
  mirrorOf?: string | undefined;
414
- type: "substrate-psp22";
415
- platform: "polkadot";
416
- contractAddress: string;
507
+ type: "evm-erc20";
508
+ platform: "ethereum";
509
+ contractAddress: `0x${string}`;
417
510
  } | {
418
511
  id: string;
419
512
  networkId: string;
@@ -425,12 +518,8 @@ export declare class Balance {
425
518
  coingeckoId?: string | undefined;
426
519
  noDiscovery?: boolean | undefined;
427
520
  mirrorOf?: string | undefined;
428
- type: "substrate-assets";
429
- platform: "polkadot";
430
- assetId: string;
431
- isFrozen?: boolean | undefined;
432
- isSufficient: boolean;
433
- existentialDeposit: string;
521
+ type: "evm-native";
522
+ platform: "ethereum";
434
523
  } | {
435
524
  id: string;
436
525
  networkId: string;
@@ -442,9 +531,11 @@ export declare class Balance {
442
531
  coingeckoId?: string | undefined;
443
532
  noDiscovery?: boolean | undefined;
444
533
  mirrorOf?: string | undefined;
445
- type: "substrate-tokens";
534
+ type: "substrate-assets";
446
535
  platform: "polkadot";
447
- onChainId: string | number;
536
+ assetId: string;
537
+ isFrozen?: boolean | undefined;
538
+ isSufficient: boolean;
448
539
  existentialDeposit: string;
449
540
  } | {
450
541
  id: string;
@@ -457,12 +548,12 @@ export declare class Balance {
457
548
  coingeckoId?: string | undefined;
458
549
  noDiscovery?: boolean | undefined;
459
550
  mirrorOf?: string | undefined;
460
- type: "substrate-hydration";
551
+ type: "substrate-dtao";
461
552
  platform: "polkadot";
462
- onChainId: number;
463
- assetType: "Erc20" | "External" | "Token";
464
- isSufficient: boolean;
465
- existentialDeposit: string;
553
+ netuid: number;
554
+ subnetName?: string | undefined;
555
+ hotkey?: string | undefined;
556
+ isTransferable: boolean;
466
557
  } | {
467
558
  id: string;
468
559
  networkId: string;
@@ -474,18 +565,12 @@ export declare class Balance {
474
565
  coingeckoId?: string | undefined;
475
566
  noDiscovery?: boolean | undefined;
476
567
  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;
568
+ type: "substrate-foreignassets";
569
+ platform: "polkadot";
570
+ onChainId: string;
571
+ isFrozen?: boolean | undefined;
572
+ isSufficient: boolean;
573
+ existentialDeposit: string;
489
574
  } | {
490
575
  id: string;
491
576
  networkId: string;
@@ -497,12 +582,9 @@ export declare class Balance {
497
582
  coingeckoId?: string | undefined;
498
583
  noDiscovery?: boolean | undefined;
499
584
  mirrorOf?: string | undefined;
500
- type: "substrate-dtao";
585
+ type: "substrate-psp22";
501
586
  platform: "polkadot";
502
- netuid: number;
503
- subnetName?: string | undefined;
504
- hotkey?: string | undefined;
505
- isTransferable: boolean;
587
+ contractAddress: string;
506
588
  } | {
507
589
  id: string;
508
590
  networkId: string;
@@ -514,8 +596,11 @@ export declare class Balance {
514
596
  coingeckoId?: string | undefined;
515
597
  noDiscovery?: boolean | undefined;
516
598
  mirrorOf?: string | undefined;
517
- type: "substrate-native";
599
+ type: "substrate-hydration";
518
600
  platform: "polkadot";
601
+ onChainId: number;
602
+ assetType: "Erc20" | "External" | "Token";
603
+ isSufficient: boolean;
519
604
  existentialDeposit: string;
520
605
  } | {
521
606
  id: 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 };