@talismn/balances 0.4.0 → 0.4.1

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,5 +1,26 @@
1
1
  # @talismn/balances
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fb8ee962: feat: proxy dapp websocket requests to talisman wallet backend when available
8
+ - f7aca48b: eslint rules
9
+ - 01bf239b: feat: crowdloan and nom pool balances
10
+ - 48f0222e: fix: removed some explicit `any`s
11
+ - 01bf239b: fix: packages publishing with incorrect interdependency versions
12
+ - Updated dependencies [fb8ee962]
13
+ - Updated dependencies [c898da98]
14
+ - Updated dependencies [f7aca48b]
15
+ - Updated dependencies [01bf239b]
16
+ - Updated dependencies [48f0222e]
17
+ - Updated dependencies [01bf239b]
18
+ - @talismn/chain-connector@0.4.4
19
+ - @talismn/chain-connector-evm@0.4.4
20
+ - @talismn/chaindata-provider@0.4.4
21
+ - @talismn/token-rates@0.1.16
22
+ - @talismn/util@0.1.9
23
+
3
24
  ## 0.4.0
4
25
 
5
26
  ### Patch Changes
@@ -1,17 +1,57 @@
1
1
  import type { Registry } from "@polkadot/types-codec/types";
2
- import { ChainId } from "@talismn/chaindata-provider";
3
- import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams } from "./BalanceModule";
4
- import { AddressesByToken, Balance, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
2
+ import { ChainConnector } from "@talismn/chain-connector";
3
+ import { Chain, ChainId } from "@talismn/chaindata-provider";
4
+ import { BalanceModule, DefaultChainMeta, DefaultModuleConfig, DefaultTransferParams, ExtendableChainMeta, ExtendableModuleConfig, ExtendableTokenType, ExtendableTransferParams, NewBalanceModule } from "./BalanceModule";
5
+ import { AddressesByToken, Balance, BalanceJson, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
5
6
  /**
6
7
  * Wraps a BalanceModule's fetch/subscribe methods with a single `balances` method.
7
8
  * This `balances` method will subscribe if a callback parameter is provided, or otherwise fetch.
8
9
  */
9
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>): Promise<Balances>;
10
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>, addressesByToken: AddressesByToken<TTokenType>, callback: SubscriptionCallback<Balances>): Promise<UnsubscribeFn>;
12
+ export type GetOrCreateTypeRegistry = (chainId: ChainId, metadataRpc?: `0x${string}`) => Registry;
11
13
  export declare const createTypeRegistryCache: () => {
12
- getOrCreateTypeRegistry: (chainId: ChainId, metadataRpc?: `0x${string}`) => Registry;
14
+ getOrCreateTypeRegistry: GetOrCreateTypeRegistry;
13
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;
14
47
  export declare const filterMirrorTokens: (balance: Balance, i: number, balances: Balance[]) => boolean;
48
+ export declare const getValidSubscriptionIds: () => Set<string>;
49
+ export declare const createSubscriptionId: () => string;
50
+ export declare const deleteSubscriptionId: () => void;
51
+ /**
52
+ * Sets all balance statuses from `live-${string}` to either `live` or `cached`
53
+ */
54
+ export declare const deriveStatuses: (validSubscriptionIds: string[], balances: BalanceJson[]) => BalanceJson[];
15
55
  /**
16
56
  * Used by a variety of balance modules to help encode and decode substrate state calls.
17
57
  */
@@ -26,3 +66,21 @@ export declare class StorageHelper {
26
66
  tag(tags: any): this;
27
67
  decode(input?: string | null): import("@polkadot/types-codec/types").Codec | undefined;
28
68
  }
69
+ /**
70
+ * Pass some these into an `RpcStateQueryHelper` in order to easily batch multiple state queries into the one rpc call.
71
+ */
72
+ export type RpcStateQuery<T> = {
73
+ chainId: string;
74
+ stateKey: string;
75
+ decodeResult: (change: string | null) => T;
76
+ };
77
+ /**
78
+ * Used by a variety of balance modules to help batch multiple state queries into the one rpc call.
79
+ */
80
+ export declare class RpcStateQueryHelper<T> {
81
+ #private;
82
+ constructor(chainConnector: ChainConnector, queries: Array<RpcStateQuery<T>>);
83
+ subscribe(callback: SubscriptionCallback<T[]>, timeout?: number | false, subscribeMethod?: string, responseMethod?: string, unsubscribeMethod?: string): Promise<UnsubscribeFn>;
84
+ fetch(method?: string): Promise<T[]>;
85
+ }
86
+ export {};
@@ -61,6 +61,19 @@ 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;
64
77
  /**
65
78
  * Add some balances to this collection.
66
79
  * Added balances take priority over existing balances.
@@ -134,9 +147,21 @@ export declare class Balance {
134
147
  get free(): BalanceFormatter;
135
148
  /** The reserved balance of this token. Is included in the total. */
136
149
  get reserved(): BalanceFormatter;
150
+ get reserves(): {
151
+ amount: BalanceFormatter;
152
+ label: string;
153
+ meta?: unknown;
154
+ }[];
137
155
  /** The frozen balance of this token. Is included in the free amount. */
138
156
  get locked(): BalanceFormatter;
139
- /** @depreacted - use balance.locked */
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 */
140
165
  get frozen(): BalanceFormatter;
141
166
  /** The transferable balance of this token. Is generally the free amount - the miscFrozen amount. */
142
167
  get transferable(): BalanceFormatter;
@@ -151,6 +176,26 @@ export declare class BalanceFormatter {
151
176
  get tokens(): string;
152
177
  fiat(currency: TokenRateCurrency): number | null;
153
178
  }
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
+ }
154
199
  export declare class FiatSumBalancesFormatter {
155
200
  #private;
156
201
  constructor(balances: Balances, currency: TokenRateCurrency);
@@ -164,7 +209,7 @@ export declare class FiatSumBalancesFormatter {
164
209
  get reserved(): number;
165
210
  /** The frozen balance of these tokens. Is included in the free amount. */
166
211
  get locked(): number;
167
- /** @deprecated - use balances.locked */
212
+ /** @deprecated Use balances.locked */
168
213
  get frozen(): number;
169
214
  /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
170
215
  get transferable(): number;
@@ -174,5 +219,6 @@ export declare class FiatSumBalancesFormatter {
174
219
  export declare class SumBalancesFormatter {
175
220
  #private;
176
221
  constructor(balances: Balances);
222
+ get planck(): PlanckSumBalancesFormatter;
177
223
  fiat(currency: TokenRateCurrency): FiatSumBalancesFormatter;
178
224
  }
@@ -23,11 +23,18 @@ export type BalanceTypes = {
23
23
  export type BalanceJson = BalanceTypes[keyof BalanceTypes] extends never ? IBalance : BalanceTypes[keyof BalanceTypes];
24
24
  /** A collection of `BalanceJson` objects */
25
25
  export type BalanceJsonList = Record<string, BalanceJson>;
26
- export type BalanceStatus = "live" | "cache" | "stale";
26
+ export type BalanceStatusLive = `live-${string}`;
27
+ export declare const BalanceStatusLive: (subscriptionId: string) => BalanceStatusLive;
28
+ export type BalanceStatus = BalanceStatusLive | "live" | "cache" | "stale";
27
29
  /** `IBalance` is a common interface which all balance types must implement. */
28
30
  export type IBalance = {
29
31
  /** The module that this balance was retrieved by */
30
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;
31
38
  /** Has this balance never been fetched, or is it from a cache, or is it up to date? */
32
39
  status: BalanceStatus;
33
40
  /** The address of the account which owns this balance */
@@ -57,6 +64,7 @@ export type Amount = string;
57
64
  export type AmountWithLabel<TLabel extends string> = {
58
65
  label: TLabel;
59
66
  amount: Amount;
67
+ meta?: unknown;
60
68
  };
61
69
  /** A labelled locked amount of a balance */
62
70
  export type LockedAmount<TLabel extends string> = AmountWithLabel<TLabel> & {