@talismn/balances 0.0.0-pr557-20230216040942 → 0.0.0-pr563-20230221230003

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,16 +1,22 @@
1
1
  # @talismn/balances
2
2
 
3
- ## 0.0.0-pr557-20230216040942
3
+ ## 0.0.0-pr563-20230221230003
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - c651551: build: move `@polkadot` dependencies to `peerDependencies`
8
- - Updated dependencies [c651551]
9
- - @talismn/chain-connector@0.0.0-pr557-20230216040942
10
- - @talismn/util@0.0.0-pr557-20230216040942
11
- - @talismn/chain-connector-evm@0.0.0-pr557-20230216040942
12
- - @talismn/chaindata-provider@0.0.0-pr557-20230216040942
13
- - @talismn/token-rates@0.0.0-pr557-20230216040942
7
+ - 536eddb5: fix: ported useDbCache related perf fixes to @talismn/balances-react
8
+
9
+ ## 0.3.3
10
+
11
+ ### Patch Changes
12
+
13
+ - c651551c: build: move `@polkadot` dependencies to `peerDependencies`
14
+ - Updated dependencies [c651551c]
15
+ - @talismn/chain-connector@0.4.2
16
+ - @talismn/util@0.1.7
17
+ - @talismn/chain-connector-evm@0.4.2
18
+ - @talismn/chaindata-provider@0.4.2
19
+ - @talismn/token-rates@0.1.14
14
20
 
15
21
  ## 0.3.2
16
22
 
@@ -1,28 +1,46 @@
1
+ import { UnsignedTransaction } from "@substrate/txwrapper-core";
1
2
  import { ChainConnector } from "@talismn/chain-connector";
2
3
  import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
3
4
  import { ChainId, ChaindataProvider, IToken } from "@talismn/chaindata-provider";
5
+ import { ethers } from "ethers";
4
6
  import { AddressesByToken, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
5
- export interface BalanceModule<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleSubstrate<TModuleType, TTokenType, TChainMeta, TModuleConfig>, BalanceModuleEvm<TModuleType, TTokenType, TChainMeta, TModuleConfig> {
6
- }
7
- export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends IToken, TChainMeta extends ExtendableChainMeta = undefined, TModuleConfig extends ExtendableModuleConfig = undefined>(type: TModuleType) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>;
8
7
  export type ExtendableTokenType = IToken;
9
8
  export type ExtendableChainMeta = Record<string, unknown> | undefined;
10
9
  export type DefaultChainMeta = undefined;
11
10
  export type ExtendableModuleConfig = Record<string, unknown> | undefined;
12
11
  export type DefaultModuleConfig = undefined;
13
- interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleCommon<TModuleType, TTokenType> {
12
+ export type BaseTransferParams = {
13
+ tokenId: string;
14
+ from: string;
15
+ to: string;
16
+ amount: string;
17
+ };
18
+ export type ExtendableTransferParams = BaseTransferParams | undefined;
19
+ export type DefaultTransferParams = undefined;
20
+ export type NewTransferParamsType<T extends Record<string, unknown>> = BaseTransferParams & T;
21
+ export type TransferTokenTx = {
22
+ type: "substrate";
23
+ tx: UnsignedTransaction;
24
+ } | {
25
+ type: "evm";
26
+ tx: ethers.providers.TransactionRequest;
27
+ };
28
+ export interface BalanceModule<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleSubstrate<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>, BalanceModuleEvm<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams> {
29
+ }
30
+ export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends IToken, TChainMeta extends ExtendableChainMeta = undefined, TModuleConfig extends ExtendableModuleConfig = undefined, TTransferParams extends ExtendableTransferParams = undefined>(type: TModuleType) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>;
31
+ interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleCommon<TModuleType, TTokenType, TTransferParams> {
14
32
  /** Pre-processes any substrate chain metadata required by this module ahead of time */
15
33
  fetchSubstrateChainMeta(chainConnector: ChainConnector, chaindataProvider: ChaindataProvider, chainId: ChainId, moduleConfig: TModuleConfig | undefined): Promise<TChainMeta | null>;
16
34
  /** Detects which tokens are available on a given substrate chain */
17
35
  fetchSubstrateChainTokens(chainConnector: ChainConnector, chaindataProvider: ChaindataProvider, chainId: ChainId, chainMeta: TChainMeta, moduleConfig: TModuleConfig | undefined): Promise<Record<TTokenType["id"], TTokenType>>;
18
36
  }
19
- interface BalanceModuleEvm<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig> extends BalanceModuleCommon<TModuleType, TTokenType> {
37
+ interface BalanceModuleEvm<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleCommon<TModuleType, TTokenType, TTransferParams> {
20
38
  /** Pre-processes any evm chain metadata required by this module ahead of time */
21
39
  fetchEvmChainMeta(chainConnector: ChainConnectorEvm, chaindataProvider: ChaindataProvider, chainId: ChainId, moduleConfig: TModuleConfig | undefined): Promise<TChainMeta | null>;
22
40
  /** Detects which tokens are available on a given evm chain */
23
41
  fetchEvmChainTokens(chainConnector: ChainConnectorEvm, chaindataProvider: ChaindataProvider, chainId: ChainId, chainMeta: TChainMeta, moduleConfig: TModuleConfig | undefined): Promise<Record<TTokenType["id"], TTokenType>>;
24
42
  }
25
- interface BalanceModuleCommon<TModuleType extends string, TTokenType extends ExtendableTokenType> {
43
+ interface BalanceModuleCommon<TModuleType extends string, TTokenType extends ExtendableTokenType, TTransferParams extends ExtendableTransferParams> {
26
44
  get type(): TModuleType;
27
45
  /**
28
46
  * Subscribe to balances for this module with optional filtering.
@@ -38,6 +56,10 @@ interface BalanceModuleCommon<TModuleType extends string, TTokenType extends Ext
38
56
  substrate?: ChainConnector;
39
57
  evm?: ChainConnectorEvm;
40
58
  }, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
59
+ transferToken(chainConnectors: {
60
+ substrate?: ChainConnector;
61
+ evm?: ChainConnectorEvm;
62
+ }, chaindataProvider: ChaindataProvider, transferParams: TTransferParams): Promise<TransferTokenTx | null>;
41
63
  [x: string | number | symbol]: unknown;
42
64
  }
43
65
  export {};
@@ -2,17 +2,17 @@ import { TypeRegistry } from "@polkadot/types";
2
2
  import { ChainConnector } from "@talismn/chain-connector";
3
3
  import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
4
4
  import { ChaindataProvider } from "@talismn/chaindata-provider";
5
- import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType } from "./BalanceModule";
5
+ import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams } from "./BalanceModule";
6
6
  import { AddressesByToken, Balance, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
7
7
  /**
8
8
  * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
9
9
  * This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
10
10
  */
11
- export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>, chainConnectors: {
11
+ 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>, chainConnectors: {
12
12
  substrate?: ChainConnector;
13
13
  evm?: ChainConnectorEvm;
14
14
  }, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
15
- export declare function balances<TModuleType extends string, TTokenType extends ExtendableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig>(balanceModule: BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig>, chainConnectors: {
15
+ 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>, chainConnectors: {
16
16
  substrate?: ChainConnector;
17
17
  evm?: ChainConnectorEvm;
18
18
  }, chaindataProvider: ChaindataProvider, addressesByToken: AddressesByToken<TTokenType>, callback: SubscriptionCallback<Balances>): Promise<UnsubscribeFn>;
@@ -41,6 +41,9 @@ const DefaultBalanceModule = type => ({
41
41
  },
42
42
  async fetchBalances() {
43
43
  throw new Error("Balance fetching is not implemented in this module.");
44
+ },
45
+ async transferToken() {
46
+ throw new Error("Token transfers are not implemented in this module.");
44
47
  }
45
48
  });
46
49
 
@@ -71,7 +74,7 @@ const db = new TalismanBalancesDatabase();
71
74
 
72
75
  var packageJson = {
73
76
  name: "@talismn/balances",
74
- version: "0.0.0-pr557-20230216040942",
77
+ version: "0.0.0-pr563-20230221230003",
75
78
  author: "Talisman",
76
79
  homepage: "https://talisman.xyz",
77
80
  license: "UNLICENSED",
@@ -145,9 +148,8 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
145
148
  return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
146
149
  }
147
150
  const filterMirrorTokens = (balance, i, balances) => {
148
- var _balance$token;
149
151
  // TODO implement a mirrorOf property, which should be set from chaindata
150
- const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
152
+ const mirrorOf = balance.token?.mirrorOf;
151
153
  return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
152
154
  };
153
155
 
@@ -183,8 +185,7 @@ class StorageHelper {
183
185
  }
184
186
  }
185
187
  get stateKey() {
186
- var _this$storageKey;
187
- return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
188
+ return this.#storageKey?.toHex();
188
189
  }
189
190
  get module() {
190
191
  return this.#module;
@@ -439,10 +440,7 @@ let Balances = (_dec = typescriptMemoize.Memoize(), _dec2 = typescriptMemoize.Me
439
440
  * @returns A sorted array of the balances in this collection.
440
441
  */
441
442
  get sorted() {
442
- return [...this].sort((a, b) => {
443
- var _ref, _ref2;
444
- return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
445
- });
443
+ return [...this].sort((a, b) => ((a.chain || a.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER) - ((b.chain || b.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER));
446
444
  }
447
445
 
448
446
  /**
@@ -507,10 +505,7 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
507
505
  hydrate = hydrate => {
508
506
  if (hydrate !== undefined) this.#db = hydrate;
509
507
  };
510
- #format = balance => {
511
- var _this$db;
512
- return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
513
- };
508
+ #format = balance => new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
514
509
 
515
510
  //
516
511
  // Accessors
@@ -540,32 +535,27 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
540
535
  return this.#storage.chainId;
541
536
  }
542
537
  get chain() {
543
- var _this$db2, _this$db3;
544
- return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
538
+ return this.#db?.chains && this.chainId && this.#db?.chains[this.chainId] || null;
545
539
  }
546
540
  get evmNetworkId() {
547
541
  return this.#storage.evmNetworkId;
548
542
  }
549
543
  get evmNetwork() {
550
- var _this$db4, _this$db5;
551
544
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
552
- return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
545
+ return this.#db?.evmNetworks && this.#db?.evmNetworks[this.evmNetworkId] || null;
553
546
  }
554
547
  get tokenId() {
555
548
  return this.#storage.tokenId;
556
549
  }
557
550
  get token() {
558
- var _this$db6, _this$db7;
559
551
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
560
- return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
552
+ return this.#db?.tokens && this.#db?.tokens[this.tokenId] || null;
561
553
  }
562
554
  get decimals() {
563
- var _this$token;
564
- return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
555
+ return this.token?.decimals || null;
565
556
  }
566
557
  get rates() {
567
- var _this$db8;
568
- return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
558
+ return this.#db?.tokenRates && this.#db.tokenRates[this.tokenId] || null;
569
559
  }
570
560
 
571
561
  /**
@@ -579,18 +569,15 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
579
569
  }
580
570
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
581
571
  get free() {
582
- var _this$storage$free;
583
- 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 = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
572
+ 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"));
584
573
  }
585
574
  /** The reserved balance of this token. Is included in the total. */
586
575
  get reserved() {
587
- var _this$storage$reserve;
588
- 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$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
576
+ 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"));
589
577
  }
590
578
  /** The frozen balance of this token. Is included in the free amount. */
591
579
  get locked() {
592
- var _this$storage$locks;
593
- 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 = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
580
+ 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"));
594
581
  }
595
582
  /** @depreacted - use balance.locked */
596
583
  get frozen() {
@@ -41,6 +41,9 @@ const DefaultBalanceModule = type => ({
41
41
  },
42
42
  async fetchBalances() {
43
43
  throw new Error("Balance fetching is not implemented in this module.");
44
+ },
45
+ async transferToken() {
46
+ throw new Error("Token transfers are not implemented in this module.");
44
47
  }
45
48
  });
46
49
 
@@ -71,7 +74,7 @@ const db = new TalismanBalancesDatabase();
71
74
 
72
75
  var packageJson = {
73
76
  name: "@talismn/balances",
74
- version: "0.0.0-pr557-20230216040942",
77
+ version: "0.0.0-pr563-20230221230003",
75
78
  author: "Talisman",
76
79
  homepage: "https://talisman.xyz",
77
80
  license: "UNLICENSED",
@@ -145,9 +148,8 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
145
148
  return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
146
149
  }
147
150
  const filterMirrorTokens = (balance, i, balances) => {
148
- var _balance$token;
149
151
  // TODO implement a mirrorOf property, which should be set from chaindata
150
- const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
152
+ const mirrorOf = balance.token?.mirrorOf;
151
153
  return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
152
154
  };
153
155
 
@@ -183,8 +185,7 @@ class StorageHelper {
183
185
  }
184
186
  }
185
187
  get stateKey() {
186
- var _this$storageKey;
187
- return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
188
+ return this.#storageKey?.toHex();
188
189
  }
189
190
  get module() {
190
191
  return this.#module;
@@ -439,10 +440,7 @@ let Balances = (_dec = typescriptMemoize.Memoize(), _dec2 = typescriptMemoize.Me
439
440
  * @returns A sorted array of the balances in this collection.
440
441
  */
441
442
  get sorted() {
442
- return [...this].sort((a, b) => {
443
- var _ref, _ref2;
444
- return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
445
- });
443
+ return [...this].sort((a, b) => ((a.chain || a.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER) - ((b.chain || b.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER));
446
444
  }
447
445
 
448
446
  /**
@@ -507,10 +505,7 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
507
505
  hydrate = hydrate => {
508
506
  if (hydrate !== undefined) this.#db = hydrate;
509
507
  };
510
- #format = balance => {
511
- var _this$db;
512
- return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
513
- };
508
+ #format = balance => new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
514
509
 
515
510
  //
516
511
  // Accessors
@@ -540,32 +535,27 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
540
535
  return this.#storage.chainId;
541
536
  }
542
537
  get chain() {
543
- var _this$db2, _this$db3;
544
- return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
538
+ return this.#db?.chains && this.chainId && this.#db?.chains[this.chainId] || null;
545
539
  }
546
540
  get evmNetworkId() {
547
541
  return this.#storage.evmNetworkId;
548
542
  }
549
543
  get evmNetwork() {
550
- var _this$db4, _this$db5;
551
544
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
552
- return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
545
+ return this.#db?.evmNetworks && this.#db?.evmNetworks[this.evmNetworkId] || null;
553
546
  }
554
547
  get tokenId() {
555
548
  return this.#storage.tokenId;
556
549
  }
557
550
  get token() {
558
- var _this$db6, _this$db7;
559
551
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
560
- return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
552
+ return this.#db?.tokens && this.#db?.tokens[this.tokenId] || null;
561
553
  }
562
554
  get decimals() {
563
- var _this$token;
564
- return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
555
+ return this.token?.decimals || null;
565
556
  }
566
557
  get rates() {
567
- var _this$db8;
568
- return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
558
+ return this.#db?.tokenRates && this.#db.tokenRates[this.tokenId] || null;
569
559
  }
570
560
 
571
561
  /**
@@ -579,18 +569,15 @@ let Balance = (_dec4 = typescriptMemoize.Memoize(), _dec5 = typescriptMemoize.Me
579
569
  }
580
570
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
581
571
  get free() {
582
- var _this$storage$free;
583
- 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 = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
572
+ 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"));
584
573
  }
585
574
  /** The reserved balance of this token. Is included in the total. */
586
575
  get reserved() {
587
- var _this$storage$reserve;
588
- 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$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
576
+ 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"));
589
577
  }
590
578
  /** The frozen balance of this token. Is included in the free amount. */
591
579
  get locked() {
592
- var _this$storage$locks;
593
- 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 = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
580
+ 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"));
594
581
  }
595
582
  /** @depreacted - use balance.locked */
596
583
  get frozen() {
@@ -32,6 +32,9 @@ const DefaultBalanceModule = type => ({
32
32
  },
33
33
  async fetchBalances() {
34
34
  throw new Error("Balance fetching is not implemented in this module.");
35
+ },
36
+ async transferToken() {
37
+ throw new Error("Token transfers are not implemented in this module.");
35
38
  }
36
39
  });
37
40
 
@@ -62,7 +65,7 @@ const db = new TalismanBalancesDatabase();
62
65
 
63
66
  var packageJson = {
64
67
  name: "@talismn/balances",
65
- version: "0.0.0-pr557-20230216040942",
68
+ version: "0.0.0-pr563-20230221230003",
66
69
  author: "Talisman",
67
70
  homepage: "https://talisman.xyz",
68
71
  license: "UNLICENSED",
@@ -136,9 +139,8 @@ async function balances(balanceModule, chainConnectors, chaindataProvider, addre
136
139
  return await balanceModule.fetchBalances(chainConnectors, chaindataProvider, addressesByToken);
137
140
  }
138
141
  const filterMirrorTokens = (balance, i, balances) => {
139
- var _balance$token;
140
142
  // TODO implement a mirrorOf property, which should be set from chaindata
141
- const mirrorOf = (_balance$token = balance.token) === null || _balance$token === void 0 ? void 0 : _balance$token.mirrorOf;
143
+ const mirrorOf = balance.token?.mirrorOf;
142
144
  return !mirrorOf || !balances.find(b => b.tokenId === mirrorOf);
143
145
  };
144
146
 
@@ -174,8 +176,7 @@ class StorageHelper {
174
176
  }
175
177
  }
176
178
  get stateKey() {
177
- var _this$storageKey;
178
- return (_this$storageKey = this.#storageKey) === null || _this$storageKey === void 0 ? void 0 : _this$storageKey.toHex();
179
+ return this.#storageKey?.toHex();
179
180
  }
180
181
  get module() {
181
182
  return this.#module;
@@ -430,10 +431,7 @@ let Balances = (_dec = Memoize(), _dec2 = Memoize(), _dec3 = Memoize(), (_class
430
431
  * @returns A sorted array of the balances in this collection.
431
432
  */
432
433
  get sorted() {
433
- return [...this].sort((a, b) => {
434
- var _ref, _ref2;
435
- return (((_ref = a.chain || a.evmNetwork) === null || _ref === void 0 ? void 0 : _ref.sortIndex) || Number.MAX_SAFE_INTEGER) - (((_ref2 = b.chain || b.evmNetwork) === null || _ref2 === void 0 ? void 0 : _ref2.sortIndex) || Number.MAX_SAFE_INTEGER);
436
- });
434
+ return [...this].sort((a, b) => ((a.chain || a.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER) - ((b.chain || b.evmNetwork)?.sortIndex || Number.MAX_SAFE_INTEGER));
437
435
  }
438
436
 
439
437
  /**
@@ -498,10 +496,7 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
498
496
  hydrate = hydrate => {
499
497
  if (hydrate !== undefined) this.#db = hydrate;
500
498
  };
501
- #format = balance => {
502
- var _this$db;
503
- return new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, ((_this$db = this.#db) === null || _this$db === void 0 ? void 0 : _this$db.tokenRates) && this.#db.tokenRates[this.tokenId]);
504
- };
499
+ #format = balance => new BalanceFormatter(typeof balance === "bigint" ? balance.toString() : balance, this.decimals || undefined, this.#db?.tokenRates && this.#db.tokenRates[this.tokenId]);
505
500
 
506
501
  //
507
502
  // Accessors
@@ -531,32 +526,27 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
531
526
  return this.#storage.chainId;
532
527
  }
533
528
  get chain() {
534
- var _this$db2, _this$db3;
535
- return ((_this$db2 = this.#db) === null || _this$db2 === void 0 ? void 0 : _this$db2.chains) && this.chainId && ((_this$db3 = this.#db) === null || _this$db3 === void 0 ? void 0 : _this$db3.chains[this.chainId]) || null;
529
+ return this.#db?.chains && this.chainId && this.#db?.chains[this.chainId] || null;
536
530
  }
537
531
  get evmNetworkId() {
538
532
  return this.#storage.evmNetworkId;
539
533
  }
540
534
  get evmNetwork() {
541
- var _this$db4, _this$db5;
542
535
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
543
- return ((_this$db4 = this.#db) === null || _this$db4 === void 0 ? void 0 : _this$db4.evmNetworks) && ((_this$db5 = this.#db) === null || _this$db5 === void 0 ? void 0 : _this$db5.evmNetworks[this.evmNetworkId]) || null;
536
+ return this.#db?.evmNetworks && this.#db?.evmNetworks[this.evmNetworkId] || null;
544
537
  }
545
538
  get tokenId() {
546
539
  return this.#storage.tokenId;
547
540
  }
548
541
  get token() {
549
- var _this$db6, _this$db7;
550
542
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
551
- return ((_this$db6 = this.#db) === null || _this$db6 === void 0 ? void 0 : _this$db6.tokens) && ((_this$db7 = this.#db) === null || _this$db7 === void 0 ? void 0 : _this$db7.tokens[this.tokenId]) || null;
543
+ return this.#db?.tokens && this.#db?.tokens[this.tokenId] || null;
552
544
  }
553
545
  get decimals() {
554
- var _this$token;
555
- return ((_this$token = this.token) === null || _this$token === void 0 ? void 0 : _this$token.decimals) || null;
546
+ return this.token?.decimals || null;
556
547
  }
557
548
  get rates() {
558
- var _this$db8;
559
- return ((_this$db8 = this.#db) === null || _this$db8 === void 0 ? void 0 : _this$db8.tokenRates) && this.#db.tokenRates[this.tokenId] || null;
549
+ return this.#db?.tokenRates && this.#db.tokenRates[this.tokenId] || null;
560
550
  }
561
551
 
562
552
  /**
@@ -570,18 +560,15 @@ let Balance = (_dec4 = Memoize(), _dec5 = Memoize(), _dec6 = Memoize(), _dec7 =
570
560
  }
571
561
  /** The non-reserved balance of this token. Includes the frozen amount. Is included in the total. */
572
562
  get free() {
573
- var _this$storage$free;
574
- 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 = this.#storage.free) === null || _this$storage$free === void 0 ? void 0 : _this$storage$free.amount) || "0"));
563
+ 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"));
575
564
  }
576
565
  /** The reserved balance of this token. Is included in the total. */
577
566
  get reserved() {
578
- var _this$storage$reserve;
579
- 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$reserve = this.#storage.reserves) === null || _this$storage$reserve === void 0 ? void 0 : _this$storage$reserve.amount) || "0"));
567
+ 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"));
580
568
  }
581
569
  /** The frozen balance of this token. Is included in the free amount. */
582
570
  get locked() {
583
- var _this$storage$locks;
584
- 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) => BigMath.max(a, b), BigInt("0")) : BigInt(((_this$storage$locks = this.#storage.locks) === null || _this$storage$locks === void 0 ? void 0 : _this$storage$locks.amount) || "0"));
571
+ 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) => BigMath.max(a, b), BigInt("0")) : BigInt(this.#storage.locks?.amount || "0"));
585
572
  }
586
573
  /** @depreacted - use balance.locked */
587
574
  get frozen() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.0.0-pr557-20230216040942",
3
+ "version": "0.0.0-pr563-20230221230003",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",
@@ -27,11 +27,11 @@
27
27
  "clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
28
28
  },
29
29
  "dependencies": {
30
- "@talismn/chain-connector": "^0.0.0-pr557-20230216040942",
31
- "@talismn/chain-connector-evm": "^0.0.0-pr557-20230216040942",
32
- "@talismn/chaindata-provider": "^0.0.0-pr557-20230216040942",
33
- "@talismn/token-rates": "^0.0.0-pr557-20230216040942",
34
- "@talismn/util": "^0.0.0-pr557-20230216040942",
30
+ "@talismn/chain-connector": "^0.4.2",
31
+ "@talismn/chain-connector-evm": "^0.4.2",
32
+ "@talismn/chaindata-provider": "^0.4.2",
33
+ "@talismn/token-rates": "^0.1.14",
34
+ "@talismn/util": "^0.1.7",
35
35
  "anylogger": "^1.0.11",
36
36
  "dexie": "^3.2.2",
37
37
  "lodash": "^4.17.21",