@talismn/balances 0.0.0-pr707-20230418101721 → 0.0.0-pr708-20230419020004

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/CHANGELOG.md CHANGED
@@ -1,21 +1,16 @@
1
1
  # @talismn/balances
2
2
 
3
- ## 0.0.0-pr707-20230418101721
3
+ ## 0.0.0-pr708-20230419020004
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - fb8ee962: feat: proxy dapp websocket requests to talisman wallet backend when available
8
- - 71b68602: feat: crowdloan and nom pool balances
9
- - c3f58851: fix: packages publishing with incorrect interdependency versions
10
8
  - Updated dependencies [fb8ee962]
11
9
  - Updated dependencies [c898da98]
12
- - Updated dependencies [71b68602]
13
- - Updated dependencies [c3f58851]
14
- - @talismn/chain-connector@0.0.0-pr707-20230418101721
15
- - @talismn/chain-connector-evm@0.0.0-pr707-20230418101721
16
- - @talismn/util@0.0.0-pr707-20230418101721
17
- - @talismn/chaindata-provider@0.0.0-pr707-20230418101721
18
- - @talismn/token-rates@0.0.0-pr707-20230418101721
10
+ - @talismn/chain-connector@0.0.0-pr708-20230419020004
11
+ - @talismn/chain-connector-evm@0.0.0-pr708-20230419020004
12
+ - @talismn/chaindata-provider@0.0.0-pr708-20230419020004
13
+ - @talismn/token-rates@0.0.0-pr708-20230419020004
19
14
 
20
15
  ## 0.4.0
21
16
 
@@ -1,5 +1,4 @@
1
1
  import type { Registry } from "@polkadot/types-codec/types";
2
- import { ChainConnector } from "@talismn/chain-connector";
3
2
  import { ChainId } from "@talismn/chaindata-provider";
4
3
  import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams } from "./BalanceModule";
5
4
  import { AddressesByToken, Balance, BalanceJson, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
@@ -9,9 +8,8 @@ import { AddressesByToken, Balance, BalanceJson, Balances, SubscriptionCallback,
9
8
  */
10
9
  export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>, addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
11
10
  export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>, addressesByToken: AddressesByToken<TTokenType>, callback: SubscriptionCallback<Balances>): Promise<UnsubscribeFn>;
12
- export type GetOrCreateTypeRegistry = (chainId: ChainId, metadataRpc?: `0x${string}`) => Registry;
13
11
  export declare const createTypeRegistryCache: () => {
14
- getOrCreateTypeRegistry: GetOrCreateTypeRegistry;
12
+ getOrCreateTypeRegistry: (chainId: ChainId, metadataRpc?: `0x${string}`) => Registry;
15
13
  };
16
14
  export declare const filterMirrorTokens: (balance: Balance, i: number, balances: Balance[]) => boolean;
17
15
  export declare const getValidSubscriptionIds: () => Set<string>;
@@ -35,20 +33,3 @@ export declare class StorageHelper {
35
33
  tag(tags: any): this;
36
34
  decode(input?: string | null): import("@polkadot/types-codec/types").Codec | undefined;
37
35
  }
38
- /**
39
- * Pass some these into an `RpcStateQueryHelper` in order to easily batch multiple state queries into the one rpc call.
40
- */
41
- export type RpcStateQuery<T> = {
42
- chainId: string;
43
- stateKey: string;
44
- decodeResult: (change: string | null) => T;
45
- };
46
- /**
47
- * Used by a variety of balance modules to help batch multiple state queries into the one rpc call.
48
- */
49
- export declare class RpcStateQueryHelper<T> {
50
- #private;
51
- constructor(chainConnector: ChainConnector, queries: Array<RpcStateQuery<T>>);
52
- subscribe(callback: SubscriptionCallback<T[]>, timeout?: number | false, subscribeMethod?: string, responseMethod?: string, unsubscribeMethod?: string): Promise<UnsubscribeFn>;
53
- fetch(method?: string): Promise<T[]>;
54
- }
@@ -61,19 +61,6 @@ export declare class Balances {
61
61
  * @returns All balances which match the query.
62
62
  */
63
63
  find: (query: BalanceSearchQuery | BalanceSearchQuery[]) => Balances;
64
- /**
65
- * Filters this collection to exclude token balances where the token has a `mirrorOf` field
66
- * and another balance exists in this collection for the token specified by the `mirrorOf` field.
67
- */
68
- filterMirrorTokens: () => Balances;
69
- /**
70
- * Filters this collection to only include balances which are not zero.
71
- */
72
- filterNonZero: (type: "total" | "free" | "reserved" | "locked" | "frozen" | "transferable" | "feePayable") => Balances;
73
- /**
74
- * Filters this collection to only include balances which are not zero AND have a fiat conversion rate.
75
- */
76
- filterNonZeroFiat: (type: "total" | "free" | "reserved" | "locked" | "frozen" | "transferable" | "feePayable", currency: TokenRateCurrency) => Balances;
77
64
  /**
78
65
  * Add some balances to this collection.
79
66
  * Added balances take priority over existing balances.
@@ -147,21 +134,9 @@ export declare class Balance {
147
134
  get free(): BalanceFormatter;
148
135
  /** The reserved balance of this token. Is included in the total. */
149
136
  get reserved(): BalanceFormatter;
150
- get reserves(): {
151
- amount: BalanceFormatter;
152
- label: string;
153
- meta?: unknown;
154
- }[];
155
137
  /** The frozen balance of this token. Is included in the free amount. */
156
138
  get locked(): BalanceFormatter;
157
- get locks(): {
158
- amount: BalanceFormatter;
159
- label: string;
160
- meta?: unknown;
161
- includeInTransferable?: boolean | undefined;
162
- excludeFromFeePayable?: boolean | undefined;
163
- }[];
164
- /** @deprecated Use balance.locked */
139
+ /** @depreacted - use balance.locked */
165
140
  get frozen(): BalanceFormatter;
166
141
  /** The transferable balance of this token. Is generally the free amount - the miscFrozen amount. */
167
142
  get transferable(): BalanceFormatter;
@@ -176,26 +151,6 @@ export declare class BalanceFormatter {
176
151
  get tokens(): string;
177
152
  fiat(currency: TokenRateCurrency): number | null;
178
153
  }
179
- export declare class PlanckSumBalancesFormatter {
180
- #private;
181
- constructor(balances: Balances);
182
- /**
183
- * The total balance of these tokens. Includes the free and the reserved amount.
184
- */
185
- get total(): bigint;
186
- /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
187
- get free(): bigint;
188
- /** The reserved balance of these tokens. Is included in the total. */
189
- get reserved(): bigint;
190
- /** The frozen balance of these tokens. Is included in the free amount. */
191
- get locked(): bigint;
192
- /** @deprecated Use balances.locked */
193
- get frozen(): bigint;
194
- /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
195
- get transferable(): bigint;
196
- /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
197
- get feePayable(): bigint;
198
- }
199
154
  export declare class FiatSumBalancesFormatter {
200
155
  #private;
201
156
  constructor(balances: Balances, currency: TokenRateCurrency);
@@ -209,7 +164,7 @@ export declare class FiatSumBalancesFormatter {
209
164
  get reserved(): number;
210
165
  /** The frozen balance of these tokens. Is included in the free amount. */
211
166
  get locked(): number;
212
- /** @deprecated Use balances.locked */
167
+ /** @deprecated - use balances.locked */
213
168
  get frozen(): number;
214
169
  /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
215
170
  get transferable(): number;
@@ -219,6 +174,5 @@ export declare class FiatSumBalancesFormatter {
219
174
  export declare class SumBalancesFormatter {
220
175
  #private;
221
176
  constructor(balances: Balances);
222
- get planck(): PlanckSumBalancesFormatter;
223
177
  fiat(currency: TokenRateCurrency): FiatSumBalancesFormatter;
224
178
  }
@@ -30,11 +30,6 @@ export type BalanceStatus = BalanceStatusLive | "live" | "cache" | "stale";
30
30
  export type IBalance = {
31
31
  /** The module that this balance was retrieved by */
32
32
  source: string;
33
- /**
34
- * For modules which fetch balances via module sources, this is the sub-source
35
- * e.g. `staking` or `crowdloans`
36
- **/
37
- subSource?: string;
38
33
  /** Has this balance never been fetched, or is it from a cache, or is it up to date? */
39
34
  status: BalanceStatus;
40
35
  /** The address of the account which owns this balance */
@@ -64,7 +59,6 @@ export type Amount = string;
64
59
  export type AmountWithLabel<TLabel extends string> = {
65
60
  label: TLabel;
66
61
  amount: Amount;
67
- meta?: unknown;
68
62
  };
69
63
  /** A labelled locked amount of a balance */
70
64
  export type LockedAmount<TLabel extends string> = AmountWithLabel<TLabel> & {
@@ -4,13 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var dexie = require('dexie');
6
6
  var types = require('@polkadot/types');
7
- var util = require('@talismn/util');
8
- var groupBy = require('lodash/groupBy');
9
7
  var anylogger = require('anylogger');
8
+ var util = require('@talismn/util');
10
9
 
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
12
11
 
13
- var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);
14
12
  var anylogger__default = /*#__PURE__*/_interopDefault(anylogger);
15
13
 
16
14
  // TODO: Document default balances module purpose/usage
@@ -69,7 +67,7 @@ const db = new TalismanBalancesDatabase();
69
67
 
70
68
  var packageJson = {
71
69
  name: "@talismn/balances",
72
- version: "0.0.0-pr707-20230418101721",
70
+ version: "0.0.0-pr708-20230419020004",
73
71
  author: "Talisman",
74
72
  homepage: "https://talisman.xyz",
75
73
  license: "UNLICENSED",
@@ -92,32 +90,30 @@ var packageJson = {
92
90
  },
93
91
  scripts: {
94
92
  test: "jest",
95
- lint: "eslint . --max-warnings 0",
93
+ lint: "eslint src --max-warnings 0",
96
94
  clean: "rm -rf dist && rm -rf .turbo rm -rf node_modules"
97
95
  },
98
96
  dependencies: {
99
- "@talismn/chain-connector": "workspace:*",
100
- "@talismn/chain-connector-evm": "workspace:*",
101
- "@talismn/chaindata-provider": "workspace:*",
102
- "@talismn/token-rates": "workspace:*",
103
- "@talismn/util": "workspace:*",
97
+ "@talismn/chain-connector": "workspace:^",
98
+ "@talismn/chain-connector-evm": "workspace:^",
99
+ "@talismn/chaindata-provider": "workspace:^",
100
+ "@talismn/token-rates": "workspace:^",
101
+ "@talismn/util": "workspace:^",
104
102
  anylogger: "^1.0.11",
105
- dexie: "^3.2.3",
106
- lodash: "4.17.21"
103
+ dexie: "^3.2.3"
107
104
  },
108
105
  devDependencies: {
109
- "@polkadot/types": "^10.1.4",
110
- "@talismn/eslint-config": "workspace:*",
111
- "@talismn/tsconfig": "workspace:*",
106
+ "@polkadot/types": "^9.10.5",
107
+ "@talismn/eslint-config": "workspace:^",
108
+ "@talismn/tsconfig": "workspace:^",
112
109
  "@types/jest": "^27.5.1",
113
- "@types/lodash": "^4.14.180",
114
110
  eslint: "^8.4.0",
115
111
  jest: "^28.1.0",
116
112
  "ts-jest": "^28.0.2",
117
113
  typescript: "^4.6.4"
118
114
  },
119
115
  peerDependencies: {
120
- "@polkadot/types": "10.x"
116
+ "@polkadot/types": "9.x"
121
117
  },
122
118
  preconstruct: {
123
119
  entrypoints: [
@@ -150,14 +146,8 @@ const createTypeRegistryCache = () => {
150
146
  if (cached) return cached;
151
147
  const typeRegistry = new types.TypeRegistry();
152
148
  if (typeof metadataRpc === "string") {
153
- try {
154
- const metadata = new types.Metadata(typeRegistry, metadataRpc);
155
- metadata.registry.setMetadata(metadata);
156
- } catch (cause) {
157
- log.warn(new Error(`Failed to set metadata for chain ${chainId}`, {
158
- cause
159
- }), cause);
160
- }
149
+ const metadata = new types.Metadata(typeRegistry, metadataRpc);
150
+ metadata.registry.setMetadata(metadata);
161
151
  }
162
152
  typeRegistryCache.set(chainId, typeRegistry);
163
153
  return typeRegistry;
@@ -224,7 +214,11 @@ class StorageHelper {
224
214
  #module;
225
215
  #method;
226
216
  #parameters;
217
+
218
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
227
219
  tags = null;
220
+
221
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
228
222
  constructor(registry, module, method, ...parameters) {
229
223
  this.#registry = registry;
230
224
  this.#module = module;
@@ -258,6 +252,8 @@ class StorageHelper {
258
252
  get parameters() {
259
253
  return this.#parameters;
260
254
  }
255
+
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
261
257
  tag(tags) {
262
258
  this.tags = tags;
263
259
  return this;
@@ -296,77 +292,11 @@ class StorageHelper {
296
292
  }
297
293
  }
298
294
 
299
- /**
300
- * Pass some these into an `RpcStateQueryHelper` in order to easily batch multiple state queries into the one rpc call.
301
- */
302
-
303
- /**
304
- * Used by a variety of balance modules to help batch multiple state queries into the one rpc call.
305
- */
306
- class RpcStateQueryHelper {
307
- #chainConnector;
308
- #queries;
309
- constructor(chainConnector, queries) {
310
- this.#chainConnector = chainConnector;
311
- this.#queries = queries;
312
- }
313
- async subscribe(callback, timeout = false, subscribeMethod = "state_subscribeStorage", responseMethod = "state_storage", unsubscribeMethod = "state_unsubscribeStorage") {
314
- const queriesByChain = groupBy__default["default"](this.#queries, "chainId");
315
- const subscriptions = Object.entries(queriesByChain).map(([chainId, queries]) => {
316
- const params = [queries.map(({
317
- stateKey
318
- }) => stateKey)];
319
- const unsub = this.#chainConnector.subscribe(chainId, subscribeMethod, responseMethod, params, (error, result) => {
320
- error ? callback(error) : callback(null, this.#distributeChangesToQueryDecoders.call(this, chainId, result));
321
- }, timeout);
322
- return () => unsub.then(unsubscribe => unsubscribe(unsubscribeMethod));
323
- });
324
- return () => subscriptions.forEach(unsubscribe => unsubscribe());
325
- }
326
- async fetch(method = "state_queryStorageAt") {
327
- const queriesByChain = groupBy__default["default"](this.#queries, "chainId");
328
- const resultsByChain = await Promise.all(Object.entries(queriesByChain).map(async ([chainId, queries]) => {
329
- const params = [queries.map(({
330
- stateKey
331
- }) => stateKey)];
332
- const result = (await this.#chainConnector.send(chainId, method, params))[0];
333
- return this.#distributeChangesToQueryDecoders.call(this, chainId, result);
334
- }));
335
- return resultsByChain.flatMap(result => result);
336
- }
337
- #distributeChangesToQueryDecoders(chainId, result) {
338
- if (typeof result !== "object" || result === null) return [];
339
- if (!util.hasOwnProperty(result, "changes") || typeof result.changes !== "object") return [];
340
- if (!Array.isArray(result.changes)) return [];
341
- return result.changes.flatMap(([reference, change]) => {
342
- if (typeof reference !== "string") {
343
- log.warn(`Received non-string reference in RPC result: ${reference}`);
344
- return [];
345
- }
346
- if (typeof change !== "string" && change !== null) {
347
- log.warn(`Received non-string and non-null change in RPC result: ${reference} | ${change}`);
348
- return [];
349
- }
350
- const query = this.#queries.find(({
351
- chainId: cId,
352
- stateKey
353
- }) => cId === chainId && stateKey === reference);
354
- if (!query) {
355
- log.warn(`Failed to find query:\n${reference} in\n${this.#queries.map(({
356
- stateKey
357
- }) => stateKey)}`);
358
- return [];
359
- }
360
- return [query.decodeResult(change)];
361
- });
362
- }
363
- }
364
-
365
295
  const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
366
296
  function excludeFromTransferableAmount(locks) {
367
297
  if (typeof locks === "string") return BigInt(locks);
368
298
  if (!Array.isArray(locks)) locks = [locks];
369
- return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
299
+ return locks.filter(lock => lock.includeInTransferable !== true).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), BigInt("0"));
370
300
  }
371
301
  function excludeFromFeePayableLocks(locks) {
372
302
  if (typeof locks === "string") return [];
@@ -377,9 +307,9 @@ function excludeFromFeePayableLocks(locks) {
377
307
  /** A labelled extra amount of a balance */
378
308
 
379
309
  function includeInTotalExtraAmount(extra) {
380
- if (!extra) return 0n;
310
+ if (!extra) return BigInt("0");
381
311
  if (!Array.isArray(extra)) extra = [extra];
382
- return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b, 0n);
312
+ return extra.filter(extra => extra.includeInTotal).map(extra => BigInt(extra.amount)).reduce((a, b) => a + b, BigInt("0"));
383
313
  }
384
314
 
385
315
  /** Used by plugins to help define their custom `BalanceType` */
@@ -490,27 +420,6 @@ class Balances {
490
420
  return new Balances([...this].filter(filter));
491
421
  };
492
422
 
493
- /**
494
- * Filters this collection to exclude token balances where the token has a `mirrorOf` field
495
- * and another balance exists in this collection for the token specified by the `mirrorOf` field.
496
- */
497
- filterMirrorTokens = () => new Balances([...this].filter(filterMirrorTokens));
498
-
499
- /**
500
- * Filters this collection to only include balances which are not zero.
501
- */
502
- filterNonZero = type => {
503
- const filter = balance => balance[type].planck > 0n;
504
- return this.find(filter);
505
- };
506
- /**
507
- * Filters this collection to only include balances which are not zero AND have a fiat conversion rate.
508
- */
509
- filterNonZeroFiat = (type, currency) => {
510
- const filter = balance => (balance[type].fiat(currency) ?? 0) > 0;
511
- return this.find(filter);
512
- };
513
-
514
423
  /**
515
424
  * Add some balances to this collection.
516
425
  * Added balances take priority over existing balances.
@@ -633,14 +542,13 @@ class Balance {
633
542
  get id() {
634
543
  const {
635
544
  source,
636
- subSource,
637
545
  address,
638
546
  chainId,
639
547
  evmNetworkId,
640
548
  tokenId
641
549
  } = this.#storage;
642
550
  const locationId = chainId !== undefined ? chainId : evmNetworkId;
643
- return [source, address, locationId, tokenId, subSource].filter(Boolean).join("-");
551
+ return `${source}-${address}-${locationId}-${tokenId}`;
644
552
  }
645
553
  get source() {
646
554
  return this.#storage.source;
@@ -689,43 +597,17 @@ class Balance {
689
597
  }
690
598
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
691
599
  get free() {
692
- return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.free?.amount || "0"));
600
+ return this.#format(typeof this.#storage.free === "string" ? BigInt(this.#storage.free) : Array.isArray(this.#storage.free) ? this.#storage.free.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, BigInt("0")) : BigInt(this.#storage.free?.amount || "0"));
693
601
  }
694
602
  /** The reserved balance of this token. Is included in the total. */
695
603
  get reserved() {
696
- return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, 0n) : BigInt(this.#storage.reserves?.amount || "0"));
697
- }
698
- get reserves() {
699
- return (Array.isArray(this.#storage.reserves) ? this.#storage.reserves : [this.#storage.reserves]).flatMap(reserve => {
700
- if (reserve === undefined) return [];
701
- if (typeof reserve === "string") return {
702
- label: "reserved",
703
- amount: this.#format(reserve)
704
- };
705
- return {
706
- ...reserve,
707
- amount: this.#format(reserve.amount)
708
- };
709
- });
604
+ return this.#format(typeof this.#storage.reserves === "string" ? BigInt(this.#storage.reserves) : Array.isArray(this.#storage.reserves) ? this.#storage.reserves.map(reserve => BigInt(reserve.amount)).reduce((a, b) => a + b, BigInt("0")) : BigInt(this.#storage.reserves?.amount || "0"));
710
605
  }
711
606
  /** The frozen balance of this token. Is included in the free amount. */
712
607
  get locked() {
713
- return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b), 0n) : BigInt(this.#storage.locks?.amount || "0"));
714
- }
715
- get locks() {
716
- return (Array.isArray(this.#storage.locks) ? this.#storage.locks : [this.#storage.locks]).flatMap(lock => {
717
- if (lock === undefined) return [];
718
- if (typeof lock === "string") return {
719
- label: "other",
720
- amount: this.#format(lock)
721
- };
722
- return {
723
- ...lock,
724
- amount: this.#format(lock.amount)
725
- };
726
- });
608
+ return this.#format(typeof this.#storage.locks === "string" ? BigInt(this.#storage.locks) : Array.isArray(this.#storage.locks) ? this.#storage.locks.map(lock => BigInt(lock.amount)).reduce((a, b) => util.BigMath.max(a, b), BigInt("0")) : BigInt(this.#storage.locks?.amount || "0"));
727
609
  }
728
- /** @deprecated Use balance.locked */
610
+ /** @depreacted - use balance.locked */
729
611
  get frozen() {
730
612
  return this.locked;
731
613
  }
@@ -738,7 +620,7 @@ class Balance {
738
620
  const excludeAmount = excludeFromTransferableAmount(this.#storage.locks);
739
621
 
740
622
  // subtract the lock from the free amount (but don't go below 0)
741
- return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
623
+ return this.#format(util.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
742
624
  }
743
625
  /** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
744
626
  get feePayable() {
@@ -746,10 +628,10 @@ class Balance {
746
628
  if (!this.#storage.locks) return this.free;
747
629
 
748
630
  // find the largest lock which can't be used to pay tx fees
749
- const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), 0n);
631
+ const excludeAmount = excludeFromFeePayableLocks(this.#storage.locks).map(lock => BigInt(lock.amount)).reduce((max, lock) => util.BigMath.max(max, lock), BigInt("0"));
750
632
 
751
633
  // subtract the lock from the free amount (but don't go below 0)
752
- return this.#format(util.BigMath.max(this.free.planck - excludeAmount, 0n));
634
+ return this.#format(util.BigMath.max(this.free.planck - excludeAmount, BigInt("0")));
753
635
  }
754
636
  }
755
637
  class BalanceFormatter {
@@ -775,52 +657,6 @@ class BalanceFormatter {
775
657
  return parseFloat(this.tokens) * ratio;
776
658
  }
777
659
  }
778
- class PlanckSumBalancesFormatter {
779
- #balances;
780
- constructor(balances) {
781
- this.#balances = balances;
782
- }
783
- #sum = balanceField => {
784
- // a function to get a planck amount from a balance
785
- const planck = balance => balance[balanceField].planck ?? 0n;
786
- return this.#balances.filterMirrorTokens().each.reduce(
787
- // add the total amount to the planck amount of each balance
788
- (total, balance) => total + planck(balance),
789
- // start with a total of 0
790
- 0n);
791
- };
792
-
793
- /**
794
- * The total balance of these tokens. Includes the free and the reserved amount.
795
- */
796
- get total() {
797
- return this.#sum("total");
798
- }
799
- /** The non-reserved balance of these tokens. Includes the frozen amount. Is included in the total. */
800
- get free() {
801
- return this.#sum("free");
802
- }
803
- /** The reserved balance of these tokens. Is included in the total. */
804
- get reserved() {
805
- return this.#sum("reserved");
806
- }
807
- /** The frozen balance of these tokens. Is included in the free amount. */
808
- get locked() {
809
- return this.#sum("locked");
810
- }
811
- /** @deprecated Use balances.locked */
812
- get frozen() {
813
- return this.locked;
814
- }
815
- /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
816
- get transferable() {
817
- return this.#sum("transferable");
818
- }
819
- /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
820
- get feePayable() {
821
- return this.#sum("feePayable");
822
- }
823
- }
824
660
  class FiatSumBalancesFormatter {
825
661
  #balances;
826
662
  #currency;
@@ -830,10 +666,15 @@ class FiatSumBalancesFormatter {
830
666
  }
831
667
  #sum = balanceField => {
832
668
  // a function to get a fiat amount from a balance
833
- const fiat = balance => balance[balanceField].fiat(this.#currency) ?? 0;
834
- return this.#balances.filterMirrorTokens().each.reduce(
835
- // add the total amount to the fiat amount of each balance
836
- (total, balance) => total + fiat(balance),
669
+ const fiat = balance => balance[balanceField].fiat(this.#currency) || 0;
670
+
671
+ // a function to add two amounts
672
+ const sum = (a, b) => a + b;
673
+ return [...this.#balances].filter(filterMirrorTokens).reduce((total, balance) => sum(
674
+ // add the total amount...
675
+ total,
676
+ // ...to the fiat amount of each balance
677
+ fiat(balance)),
837
678
  // start with a total of 0
838
679
  0);
839
680
  };
@@ -856,7 +697,7 @@ class FiatSumBalancesFormatter {
856
697
  get locked() {
857
698
  return this.#sum("locked");
858
699
  }
859
- /** @deprecated Use balances.locked */
700
+ /** @deprecated - use balances.locked */
860
701
  get frozen() {
861
702
  return this.locked;
862
703
  }
@@ -874,9 +715,6 @@ class SumBalancesFormatter {
874
715
  constructor(balances) {
875
716
  this.#balances = balances;
876
717
  }
877
- get planck() {
878
- return new PlanckSumBalancesFormatter(this.#balances);
879
- }
880
718
  fiat(currency) {
881
719
  return new FiatSumBalancesFormatter(this.#balances, currency);
882
720
  }
@@ -888,8 +726,6 @@ exports.BalanceStatusLive = BalanceStatusLive;
888
726
  exports.Balances = Balances;
889
727
  exports.DefaultBalanceModule = DefaultBalanceModule;
890
728
  exports.FiatSumBalancesFormatter = FiatSumBalancesFormatter;
891
- exports.PlanckSumBalancesFormatter = PlanckSumBalancesFormatter;
892
- exports.RpcStateQueryHelper = RpcStateQueryHelper;
893
729
  exports.StorageHelper = StorageHelper;
894
730
  exports.SumBalancesFormatter = SumBalancesFormatter;
895
731
  exports.TalismanBalancesDatabase = TalismanBalancesDatabase;