@talismn/balances 0.0.0-pr752-20230512080211 → 0.0.0-pr756-20230516054136

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,23 +1,25 @@
1
1
  # @talismn/balances
2
2
 
3
- ## 0.0.0-pr752-20230512080211
3
+ ## 0.0.0-pr756-20230516054136
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - fb8ee962: feat: proxy dapp websocket requests to talisman wallet backend when available
8
8
  - f7aca48b: eslint rules
9
9
  - 01bf239b: feat: crowdloan and nom pool balances
10
+ - 48f0222e: fix: removed some explicit `any`s
10
11
  - 01bf239b: fix: packages publishing with incorrect interdependency versions
11
12
  - Updated dependencies [fb8ee962]
12
13
  - Updated dependencies [c898da98]
13
14
  - Updated dependencies [f7aca48b]
14
15
  - Updated dependencies [01bf239b]
16
+ - Updated dependencies [48f0222e]
15
17
  - Updated dependencies [01bf239b]
16
- - @talismn/chain-connector@0.0.0-pr752-20230512080211
17
- - @talismn/chain-connector-evm@0.0.0-pr752-20230512080211
18
- - @talismn/chaindata-provider@0.0.0-pr752-20230512080211
19
- - @talismn/token-rates@0.0.0-pr752-20230512080211
20
- - @talismn/util@0.0.0-pr752-20230512080211
18
+ - @talismn/chain-connector@0.0.0-pr756-20230516054136
19
+ - @talismn/chain-connector-evm@0.0.0-pr756-20230516054136
20
+ - @talismn/chaindata-provider@0.0.0-pr756-20230516054136
21
+ - @talismn/token-rates@0.0.0-pr756-20230516054136
22
+ - @talismn/util@0.0.0-pr756-20230516054136
21
23
 
22
24
  ## 0.4.0
23
25
 
@@ -1,7 +1,7 @@
1
1
  import type { Registry } from "@polkadot/types-codec/types";
2
2
  import { ChainConnector } from "@talismn/chain-connector";
3
- import { ChainId } from "@talismn/chaindata-provider";
4
- import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams } from "./BalanceModule";
3
+ import { Chain, ChainId } from "@talismn/chaindata-provider";
4
+ import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams, NewBalanceModule } from "./BalanceModule";
5
5
  import { AddressesByToken, Balance, BalanceJson, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
6
6
  /**
7
7
  * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
@@ -13,6 +13,37 @@ export type GetOrCreateTypeRegistry = (chainId: ChainId, metadataRpc?: `0x${stri
13
13
  export declare const createTypeRegistryCache: () => {
14
14
  getOrCreateTypeRegistry: GetOrCreateTypeRegistry;
15
15
  };
16
+ export type AnyBalanceModule = BalanceModule<any, any, any, any, any>;
17
+ export type AnyNewBalanceModule = NewBalanceModule<any, any, any, any, any>;
18
+ /**
19
+ * The following `Infer*` collection of generic types can be used when you want to
20
+ * extract one of the generic type arguments from an existing BalanceModule.
21
+ *
22
+ * For example, you might want to write a function which can accept any BalanceModule
23
+ * as an input, and then return the specific TokenType for that module:
24
+ * function getTokens<T extends AnyBalanceModule>(module: T): InferTokenType<T>
25
+ *
26
+ * Or for another example, you might want a function which can take any BalanceModule `type`
27
+ * string as input, and then return some data associated with that module with the correct type:
28
+ * function getChainMeta<T extends AnyBalanceModule>(type: InferModuleType<T>): InferChainMeta<T> | undefined
29
+ */
30
+ type InferBalanceModuleTypes<T extends AnyNewBalanceModule> = T extends NewBalanceModule<infer TModuleType, infer TTokenType, infer TChainMeta, infer TModuleConfig, infer TTransferParams> ? {
31
+ TModuleType: TModuleType;
32
+ TTokenType: TTokenType;
33
+ TChainMeta: TChainMeta;
34
+ TModuleConfig: TModuleConfig;
35
+ TTransferParams: TTransferParams;
36
+ } : never;
37
+ export type InferModuleType<T extends AnyNewBalanceModule> = InferBalanceModuleTypes<T>["TModuleType"];
38
+ export type InferTokenType<T extends AnyNewBalanceModule> = InferBalanceModuleTypes<T>["TTokenType"];
39
+ export type InferChainMeta<T extends AnyNewBalanceModule> = InferBalanceModuleTypes<T>["TChainMeta"];
40
+ export type InferModuleConfig<T extends AnyNewBalanceModule> = InferBalanceModuleTypes<T>["TModuleConfig"];
41
+ export type InferTransferParams<T extends AnyNewBalanceModule> = InferBalanceModuleTypes<T>["TTransferParams"];
42
+ /**
43
+ * Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
44
+ * associated with the given balanceModule for the given chain.
45
+ */
46
+ export declare const findChainMeta: <TBalanceModule extends AnyNewBalanceModule>(moduleType: InferModuleType<TBalanceModule>, chain: Chain) => InferChainMeta<TBalanceModule> | undefined;
16
47
  export declare const filterMirrorTokens: (balance: Balance, i: number, balances: Balance[]) => boolean;
17
48
  export declare const getValidSubscriptionIds: () => Set<string>;
18
49
  export declare const createSubscriptionId: () => string;
@@ -52,3 +83,4 @@ export declare class RpcStateQueryHelper<T> {
52
83
  subscribe(callback: SubscriptionCallback<T[]>, timeout?: number | false, subscribeMethod?: string, responseMethod?: string, unsubscribeMethod?: string): Promise<UnsubscribeFn>;
53
84
  fetch(method?: string): Promise<T[]>;
54
85
  }
86
+ export {};
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
69
69
 
70
70
  var packageJson = {
71
71
  name: "@talismn/balances",
72
- version: "0.0.0-pr752-20230512080211",
72
+ version: "0.0.0-pr756-20230516054136",
73
73
  author: "Talisman",
74
74
  homepage: "https://talisman.xyz",
75
75
  license: "UNLICENSED",
@@ -135,6 +135,11 @@ var packageJson = {
135
135
 
136
136
  var log = anylogger__default["default"](packageJson.name);
137
137
 
138
+ /**
139
+ * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
140
+ * This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
141
+ */
142
+
138
143
  async function balances(balanceModule, addressesByToken, callback) {
139
144
  // subscription request
140
145
  if (callback !== undefined) return await balanceModule.subscribeBalances(addressesByToken, callback);
@@ -166,6 +171,31 @@ const createTypeRegistryCache = () => {
166
171
  getOrCreateTypeRegistry
167
172
  };
168
173
  };
174
+
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+
177
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
178
+
179
+ /**
180
+ * The following `Infer*` collection of generic types can be used when you want to
181
+ * extract one of the generic type arguments from an existing BalanceModule.
182
+ *
183
+ * For example, you might want to write a function which can accept any BalanceModule
184
+ * as an input, and then return the specific TokenType for that module:
185
+ * function getTokens<T extends AnyBalanceModule>(module: T): InferTokenType<T>
186
+ *
187
+ * Or for another example, you might want a function which can take any BalanceModule `type`
188
+ * string as input, and then return some data associated with that module with the correct type:
189
+ * function getChainMeta<T extends AnyBalanceModule>(type: InferModuleType<T>): InferChainMeta<T> | undefined
190
+ */
191
+
192
+ /**
193
+ * Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
194
+ * associated with the given balanceModule for the given chain.
195
+ */
196
+ const findChainMeta = (moduleType, chain) => {
197
+ return (chain.balanceMetadata ?? []).find(meta => meta.moduleType === moduleType)?.metadata;
198
+ };
169
199
  const filterMirrorTokens = (balance, i, balances) => {
170
200
  // TODO: implement a mirrorOf property, which should be set from chaindata
171
201
  const mirrorOf = balance.token?.mirrorOf;
@@ -368,7 +398,36 @@ class RpcStateQueryHelper {
368
398
  }
369
399
  }
370
400
 
401
+ /**
402
+ * `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
403
+ *
404
+ * It is the same list, but with any invalid `BalanceType` definitions filtered out.
405
+ */
406
+
407
+ /**
408
+ * The `BalanceJson` sum type, which is a union of all of the possible `BalanceTypes`.
409
+ *
410
+ * Each variant comes from a plugin in use by the consuming app.
411
+ *
412
+ * For example, in an app with the `substrate-native`, `evm-native`, `substrate-orml` and `evm-erc20` plugins:
413
+ *
414
+ * type BalanceJson = SubNativeBalance | EvmNativeBalance | SubOrmlBalance | EvmErc20Balance
415
+ *
416
+ * If `BalanceTypes` is empty then `BalanceJson` will fall back to the common `IBalance` interface, which every balance must implement.
417
+ */
418
+
419
+ /** A collection of `BalanceJson` objects */
420
+
371
421
  const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
422
+
423
+ /** `IBalance` is a common interface which all balance types must implement. */
424
+
425
+ /** An unlabelled amount of a balance */
426
+
427
+ /** A labelled amount of a balance */
428
+
429
+ /** A labelled locked amount of a balance */
430
+
372
431
  function excludeFromTransferableAmount(locks) {
373
432
  if (typeof locks === "string") return BigInt(locks);
374
433
  if (!Array.isArray(locks)) locks = [locks];
@@ -396,7 +455,7 @@ function includeInTotalExtraAmount(extra) {
396
455
  */
397
456
 
398
457
  /** A utility type used to extract the underlying `BalanceType` of a specific source from a generalised `BalanceJson` */
399
-
458
+ /** TODO: Remove this in favour of a frontend-friendly `ChaindataProvider` */
400
459
  /**
401
460
  * A collection of balances.
402
461
  */
@@ -908,5 +967,6 @@ exports.deriveStatuses = deriveStatuses;
908
967
  exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
909
968
  exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
910
969
  exports.filterMirrorTokens = filterMirrorTokens;
970
+ exports.findChainMeta = findChainMeta;
911
971
  exports.getValidSubscriptionIds = getValidSubscriptionIds;
912
972
  exports.includeInTotalExtraAmount = includeInTotalExtraAmount;
@@ -69,7 +69,7 @@ const db = new TalismanBalancesDatabase();
69
69
 
70
70
  var packageJson = {
71
71
  name: "@talismn/balances",
72
- version: "0.0.0-pr752-20230512080211",
72
+ version: "0.0.0-pr756-20230516054136",
73
73
  author: "Talisman",
74
74
  homepage: "https://talisman.xyz",
75
75
  license: "UNLICENSED",
@@ -135,6 +135,11 @@ var packageJson = {
135
135
 
136
136
  var log = anylogger__default["default"](packageJson.name);
137
137
 
138
+ /**
139
+ * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
140
+ * This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
141
+ */
142
+
138
143
  async function balances(balanceModule, addressesByToken, callback) {
139
144
  // subscription request
140
145
  if (callback !== undefined) return await balanceModule.subscribeBalances(addressesByToken, callback);
@@ -166,6 +171,31 @@ const createTypeRegistryCache = () => {
166
171
  getOrCreateTypeRegistry
167
172
  };
168
173
  };
174
+
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+
177
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
178
+
179
+ /**
180
+ * The following `Infer*` collection of generic types can be used when you want to
181
+ * extract one of the generic type arguments from an existing BalanceModule.
182
+ *
183
+ * For example, you might want to write a function which can accept any BalanceModule
184
+ * as an input, and then return the specific TokenType for that module:
185
+ * function getTokens<T extends AnyBalanceModule>(module: T): InferTokenType<T>
186
+ *
187
+ * Or for another example, you might want a function which can take any BalanceModule `type`
188
+ * string as input, and then return some data associated with that module with the correct type:
189
+ * function getChainMeta<T extends AnyBalanceModule>(type: InferModuleType<T>): InferChainMeta<T> | undefined
190
+ */
191
+
192
+ /**
193
+ * Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
194
+ * associated with the given balanceModule for the given chain.
195
+ */
196
+ const findChainMeta = (moduleType, chain) => {
197
+ return (chain.balanceMetadata ?? []).find(meta => meta.moduleType === moduleType)?.metadata;
198
+ };
169
199
  const filterMirrorTokens = (balance, i, balances) => {
170
200
  // TODO: implement a mirrorOf property, which should be set from chaindata
171
201
  const mirrorOf = balance.token?.mirrorOf;
@@ -368,7 +398,36 @@ class RpcStateQueryHelper {
368
398
  }
369
399
  }
370
400
 
401
+ /**
402
+ * `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
403
+ *
404
+ * It is the same list, but with any invalid `BalanceType` definitions filtered out.
405
+ */
406
+
407
+ /**
408
+ * The `BalanceJson` sum type, which is a union of all of the possible `BalanceTypes`.
409
+ *
410
+ * Each variant comes from a plugin in use by the consuming app.
411
+ *
412
+ * For example, in an app with the `substrate-native`, `evm-native`, `substrate-orml` and `evm-erc20` plugins:
413
+ *
414
+ * type BalanceJson = SubNativeBalance | EvmNativeBalance | SubOrmlBalance | EvmErc20Balance
415
+ *
416
+ * If `BalanceTypes` is empty then `BalanceJson` will fall back to the common `IBalance` interface, which every balance must implement.
417
+ */
418
+
419
+ /** A collection of `BalanceJson` objects */
420
+
371
421
  const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
422
+
423
+ /** `IBalance` is a common interface which all balance types must implement. */
424
+
425
+ /** An unlabelled amount of a balance */
426
+
427
+ /** A labelled amount of a balance */
428
+
429
+ /** A labelled locked amount of a balance */
430
+
372
431
  function excludeFromTransferableAmount(locks) {
373
432
  if (typeof locks === "string") return BigInt(locks);
374
433
  if (!Array.isArray(locks)) locks = [locks];
@@ -396,7 +455,7 @@ function includeInTotalExtraAmount(extra) {
396
455
  */
397
456
 
398
457
  /** A utility type used to extract the underlying `BalanceType` of a specific source from a generalised `BalanceJson` */
399
-
458
+ /** TODO: Remove this in favour of a frontend-friendly `ChaindataProvider` */
400
459
  /**
401
460
  * A collection of balances.
402
461
  */
@@ -908,5 +967,6 @@ exports.deriveStatuses = deriveStatuses;
908
967
  exports.excludeFromFeePayableLocks = excludeFromFeePayableLocks;
909
968
  exports.excludeFromTransferableAmount = excludeFromTransferableAmount;
910
969
  exports.filterMirrorTokens = filterMirrorTokens;
970
+ exports.findChainMeta = findChainMeta;
911
971
  exports.getValidSubscriptionIds = getValidSubscriptionIds;
912
972
  exports.includeInTotalExtraAmount = includeInTotalExtraAmount;
@@ -60,7 +60,7 @@ const db = new TalismanBalancesDatabase();
60
60
 
61
61
  var packageJson = {
62
62
  name: "@talismn/balances",
63
- version: "0.0.0-pr752-20230512080211",
63
+ version: "0.0.0-pr756-20230516054136",
64
64
  author: "Talisman",
65
65
  homepage: "https://talisman.xyz",
66
66
  license: "UNLICENSED",
@@ -126,6 +126,11 @@ var packageJson = {
126
126
 
127
127
  var log = anylogger(packageJson.name);
128
128
 
129
+ /**
130
+ * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
131
+ * This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
132
+ */
133
+
129
134
  async function balances(balanceModule, addressesByToken, callback) {
130
135
  // subscription request
131
136
  if (callback !== undefined) return await balanceModule.subscribeBalances(addressesByToken, callback);
@@ -157,6 +162,31 @@ const createTypeRegistryCache = () => {
157
162
  getOrCreateTypeRegistry
158
163
  };
159
164
  };
165
+
166
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
167
+
168
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
169
+
170
+ /**
171
+ * The following `Infer*` collection of generic types can be used when you want to
172
+ * extract one of the generic type arguments from an existing BalanceModule.
173
+ *
174
+ * For example, you might want to write a function which can accept any BalanceModule
175
+ * as an input, and then return the specific TokenType for that module:
176
+ * function getTokens<T extends AnyBalanceModule>(module: T): InferTokenType<T>
177
+ *
178
+ * Or for another example, you might want a function which can take any BalanceModule `type`
179
+ * string as input, and then return some data associated with that module with the correct type:
180
+ * function getChainMeta<T extends AnyBalanceModule>(type: InferModuleType<T>): InferChainMeta<T> | undefined
181
+ */
182
+
183
+ /**
184
+ * Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
185
+ * associated with the given balanceModule for the given chain.
186
+ */
187
+ const findChainMeta = (moduleType, chain) => {
188
+ return (chain.balanceMetadata ?? []).find(meta => meta.moduleType === moduleType)?.metadata;
189
+ };
160
190
  const filterMirrorTokens = (balance, i, balances) => {
161
191
  // TODO: implement a mirrorOf property, which should be set from chaindata
162
192
  const mirrorOf = balance.token?.mirrorOf;
@@ -359,7 +389,36 @@ class RpcStateQueryHelper {
359
389
  }
360
390
  }
361
391
 
392
+ /**
393
+ * `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
394
+ *
395
+ * It is the same list, but with any invalid `BalanceType` definitions filtered out.
396
+ */
397
+
398
+ /**
399
+ * The `BalanceJson` sum type, which is a union of all of the possible `BalanceTypes`.
400
+ *
401
+ * Each variant comes from a plugin in use by the consuming app.
402
+ *
403
+ * For example, in an app with the `substrate-native`, `evm-native`, `substrate-orml` and `evm-erc20` plugins:
404
+ *
405
+ * type BalanceJson = SubNativeBalance | EvmNativeBalance | SubOrmlBalance | EvmErc20Balance
406
+ *
407
+ * If `BalanceTypes` is empty then `BalanceJson` will fall back to the common `IBalance` interface, which every balance must implement.
408
+ */
409
+
410
+ /** A collection of `BalanceJson` objects */
411
+
362
412
  const BalanceStatusLive = subscriptionId => `live-${subscriptionId}`;
413
+
414
+ /** `IBalance` is a common interface which all balance types must implement. */
415
+
416
+ /** An unlabelled amount of a balance */
417
+
418
+ /** A labelled amount of a balance */
419
+
420
+ /** A labelled locked amount of a balance */
421
+
363
422
  function excludeFromTransferableAmount(locks) {
364
423
  if (typeof locks === "string") return BigInt(locks);
365
424
  if (!Array.isArray(locks)) locks = [locks];
@@ -387,7 +446,7 @@ function includeInTotalExtraAmount(extra) {
387
446
  */
388
447
 
389
448
  /** A utility type used to extract the underlying `BalanceType` of a specific source from a generalised `BalanceJson` */
390
-
449
+ /** TODO: Remove this in favour of a frontend-friendly `ChaindataProvider` */
391
450
  /**
392
451
  * A collection of balances.
393
452
  */
@@ -879,4 +938,4 @@ class SumBalancesFormatter {
879
938
  }
880
939
  }
881
940
 
882
- export { Balance, BalanceFormatter, BalanceStatusLive, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, PlanckSumBalancesFormatter, RpcStateQueryHelper, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createSubscriptionId, createTypeRegistryCache, db, deleteSubscriptionId, deriveStatuses, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, getValidSubscriptionIds, includeInTotalExtraAmount };
941
+ export { Balance, BalanceFormatter, BalanceStatusLive, Balances, DefaultBalanceModule, FiatSumBalancesFormatter, PlanckSumBalancesFormatter, RpcStateQueryHelper, StorageHelper, SumBalancesFormatter, TalismanBalancesDatabase, balances, createSubscriptionId, createTypeRegistryCache, db, deleteSubscriptionId, deriveStatuses, excludeFromFeePayableLocks, excludeFromTransferableAmount, filterMirrorTokens, findChainMeta, getValidSubscriptionIds, includeInTotalExtraAmount };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.0.0-pr752-20230512080211",
3
+ "version": "0.0.0-pr756-20230516054136",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "UNLICENSED",
@@ -27,18 +27,18 @@
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-pr752-20230512080211",
31
- "@talismn/chain-connector-evm": "0.0.0-pr752-20230512080211",
32
- "@talismn/chaindata-provider": "0.0.0-pr752-20230512080211",
33
- "@talismn/token-rates": "0.0.0-pr752-20230512080211",
34
- "@talismn/util": "0.0.0-pr752-20230512080211",
30
+ "@talismn/chain-connector": "0.0.0-pr756-20230516054136",
31
+ "@talismn/chain-connector-evm": "0.0.0-pr756-20230516054136",
32
+ "@talismn/chaindata-provider": "0.0.0-pr756-20230516054136",
33
+ "@talismn/token-rates": "0.0.0-pr756-20230516054136",
34
+ "@talismn/util": "0.0.0-pr756-20230516054136",
35
35
  "anylogger": "^1.0.11",
36
36
  "dexie": "^3.2.3",
37
37
  "lodash": "4.17.21"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@polkadot/types": "^10.1.4",
41
- "@talismn/eslint-config": "0.0.0-pr752-20230512080211",
41
+ "@talismn/eslint-config": "0.0.0-pr756-20230516054136",
42
42
  "@talismn/tsconfig": "0.0.2",
43
43
  "@types/jest": "^27.5.1",
44
44
  "@types/lodash": "^4.14.180",