@talismn/balances 0.6.0 → 0.7.0

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.
Files changed (62) hide show
  1. package/README.md +122 -0
  2. package/dist/declarations/src/BalanceModule.d.ts +25 -17
  3. package/dist/declarations/src/EvmTokenFetcher.d.ts +11 -0
  4. package/dist/declarations/src/MiniMetadataUpdater.d.ts +43 -0
  5. package/dist/declarations/src/TalismanBalancesDatabase.d.ts +6 -2
  6. package/dist/declarations/src/index.d.ts +4 -1
  7. package/dist/declarations/src/modules/EvmErc20Module.d.ts +33 -0
  8. package/dist/declarations/src/modules/EvmNativeModule.d.ts +26 -0
  9. package/dist/declarations/src/modules/EvmUniswapV2Module.d.ts +39 -0
  10. package/dist/declarations/src/modules/SubstrateAssetsModule.d.ts +38 -0
  11. package/dist/declarations/src/modules/SubstrateEquilibriumModule.d.ts +39 -0
  12. package/dist/declarations/src/modules/SubstrateForeignAssetsModule.d.ts +38 -0
  13. package/dist/declarations/src/modules/SubstrateNativeModule/index.d.ts +7 -0
  14. package/dist/declarations/src/modules/SubstrateNativeModule/subscribeBase.d.ts +5 -0
  15. package/dist/declarations/src/modules/SubstrateNativeModule/subscribeCrowdloans.d.ts +5 -0
  16. package/dist/declarations/src/modules/SubstrateNativeModule/subscribeNompoolStaking.d.ts +5 -0
  17. package/dist/declarations/src/modules/SubstrateNativeModule/subscribeSubtensorStaking.d.ts +5 -0
  18. package/dist/declarations/src/modules/SubstrateNativeModule/types.d.ts +49 -0
  19. package/dist/declarations/src/modules/SubstrateNativeModule/util/QueryCache.d.ts +13 -0
  20. package/dist/declarations/src/modules/SubstrateNativeModule/util/SubNativeBalanceError.d.ts +5 -0
  21. package/dist/declarations/src/modules/SubstrateNativeModule/util/asObservable.d.ts +10 -0
  22. package/dist/declarations/src/modules/SubstrateNativeModule/util/balanceLockTypes.d.ts +15 -0
  23. package/dist/declarations/src/modules/SubstrateNativeModule/util/buildQueries.d.ts +13 -0
  24. package/dist/declarations/src/modules/SubstrateNativeModule/util/crowdloanFundContributionsChildKey.d.ts +4 -0
  25. package/dist/declarations/src/modules/SubstrateNativeModule/util/detectMiniMetadataChanges.d.ts +2 -0
  26. package/dist/declarations/src/modules/SubstrateNativeModule/util/mergeBalances.d.ts +13 -0
  27. package/dist/declarations/src/modules/SubstrateNativeModule/util/nompoolAccountId.d.ts +5 -0
  28. package/dist/declarations/src/modules/SubstrateNativeModule/util/sortChains.d.ts +1 -0
  29. package/dist/declarations/src/modules/SubstrateNativeModule/util/subtensor.d.ts +55 -0
  30. package/dist/declarations/src/modules/SubstratePsp22Module.d.ts +39 -0
  31. package/dist/declarations/src/modules/SubstrateTokensModule.d.ts +43 -0
  32. package/dist/declarations/src/modules/abis/erc20.d.ts +227 -0
  33. package/dist/declarations/src/modules/abis/erc20BalancesAggregator.d.ts +19 -0
  34. package/dist/declarations/src/modules/abis/multicall.d.ts +276 -0
  35. package/dist/declarations/src/modules/abis/uniswapV2Pair.d.ts +560 -0
  36. package/dist/declarations/src/modules/index.d.ts +60 -0
  37. package/dist/declarations/src/modules/util/InferBalanceModuleTypes.d.ts +28 -0
  38. package/dist/declarations/src/modules/util/RpcStateQueryHelper.d.ts +19 -0
  39. package/dist/declarations/src/modules/util/balances.d.ts +8 -0
  40. package/dist/declarations/src/modules/util/buildStorageCoders.d.ts +26 -0
  41. package/dist/declarations/src/modules/util/decodeOutput.d.ts +13 -0
  42. package/dist/declarations/src/modules/util/detectTransferMethod.d.ts +11 -0
  43. package/dist/declarations/src/modules/util/findChainMeta.d.ts +8 -0
  44. package/dist/declarations/src/modules/util/getUniqueChainIds.d.ts +5 -0
  45. package/dist/declarations/src/modules/util/index.d.ts +10 -0
  46. package/dist/declarations/src/modules/util/makeContractCaller.d.ts +9 -0
  47. package/dist/declarations/src/modules/util/storageCompression.d.ts +9 -0
  48. package/dist/declarations/src/types/balances.d.ts +173 -22
  49. package/dist/declarations/src/types/balancetypes.d.ts +46 -35
  50. package/dist/declarations/src/types/index.d.ts +1 -0
  51. package/dist/declarations/src/types/minimetadatas.d.ts +33 -0
  52. package/dist/declarations/src/upgrades/2024-01-25-upgradeRemoveSymbolFromNativeTokenId.d.ts +2 -0
  53. package/dist/declarations/src/upgrades/2024-03-19-upgradeBalancesDataBlob.d.ts +2 -0
  54. package/dist/declarations/src/upgrades/index.d.ts +2 -0
  55. package/dist/declarations/src/util/hydrateChaindata.d.ts +8 -0
  56. package/dist/declarations/src/util/index.d.ts +1 -0
  57. package/dist/talismn-balances.cjs.dev.js +7256 -412
  58. package/dist/talismn-balances.cjs.prod.js +7256 -412
  59. package/dist/talismn-balances.esm.js +7202 -397
  60. package/package.json +41 -23
  61. package/CHANGELOG.md +0 -294
  62. package/dist/declarations/src/helpers.d.ts +0 -86
@@ -0,0 +1,26 @@
1
+ import { ChainId, ChainList } from "@talismn/chaindata-provider";
2
+ import { getDynamicBuilder } from "@talismn/scale";
3
+ import { MiniMetadata } from "../../types";
4
+ import { AnyNewBalanceModule, InferModuleType } from "./InferBalanceModuleTypes";
5
+ export type StorageCoders<TCoders extends {
6
+ [key: string]: [string, string];
7
+ }> = Map<string, {
8
+ [Property in keyof TCoders]: ReturnType<ReturnType<typeof getDynamicBuilder>["buildStorage"]> | undefined;
9
+ }>;
10
+ export declare const buildStorageCoders: <TBalanceModule extends AnyNewBalanceModule, TCoders extends {
11
+ [key: string]: [string, string] | ((params: {
12
+ chainId: string;
13
+ }) => [string, string]);
14
+ }>({ chainIds, chains, miniMetadatas, moduleType, coders, }: {
15
+ chainIds: ChainId[];
16
+ chains: ChainList;
17
+ miniMetadatas: Map<string, MiniMetadata>;
18
+ moduleType: InferModuleType<TBalanceModule>;
19
+ coders: TCoders;
20
+ }) => Map<string, { [Property in keyof TCoders]: {
21
+ len: number;
22
+ fallback: unknown;
23
+ enc: (...args: any[]) => string;
24
+ dec: import("scale-ts").Decoder<unknown>;
25
+ keyDecoder: (value: string) => any[];
26
+ } | undefined; }>;
@@ -0,0 +1,13 @@
1
+ import { Abi } from "@polkadot/api-contract";
2
+ import { TypeRegistry } from "@polkadot/types";
3
+ import { ContractExecResult } from "@polkadot/types/interfaces";
4
+ /**
5
+ * Decodes & unwraps outputs and errors of a given result, contract, and method.
6
+ * Parsed error message can be found in `decodedOutput` if `isError` is true.
7
+ * SOURCE: https://github.com/paritytech/contracts-ui (GPL-3.0-only)
8
+ */
9
+ export declare function decodeOutput({ result }: Pick<ContractExecResult, "result" | "debugMessage">, registry: TypeRegistry, abi: Abi, method: string): {
10
+ output: any;
11
+ decodedOutput: string;
12
+ isError: boolean;
13
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * Detect Balances::transfer -> Balances::transfer_allow_death migration
4
+ * https://github.com/paritytech/substrate/pull/12951
5
+ *
6
+ * `transfer_allow_death` is the preferred method,
7
+ * so if something goes wrong during detection, we should assume the chain has migrated
8
+ * @param metadataRpc string containing the hashed RPC metadata for the chain
9
+ * @returns
10
+ */
11
+ export declare const detectTransferMethod: (metadataRpc: `0x${string}`) => "transfer_allow_death" | "transfer";
@@ -0,0 +1,8 @@
1
+ import { Chain } from "@talismn/chaindata-provider";
2
+ import { MiniMetadata } from "../../types";
3
+ import { AnyNewBalanceModule, InferChainMeta, InferModuleType } from "./InferBalanceModuleTypes";
4
+ /**
5
+ * Given a `moduleType` and a `chain` from a chaindataProvider, this function will find the chainMeta
6
+ * associated with the given balanceModule for the given chain.
7
+ */
8
+ export declare const findChainMeta: <TBalanceModule extends AnyNewBalanceModule>(miniMetadatas: Map<string, MiniMetadata>, moduleType: InferModuleType<TBalanceModule>, chain?: Chain) => [InferChainMeta<TBalanceModule> | undefined, MiniMetadata | undefined];
@@ -0,0 +1,5 @@
1
+ import { ChainId, TokenList } from "@talismn/chaindata-provider";
2
+ import { AddressesByToken } from "../../types";
3
+ export declare const getUniqueChainIds: (addressesByToken: AddressesByToken<{
4
+ id: string;
5
+ }>, tokens: TokenList) => ChainId[];
@@ -0,0 +1,10 @@
1
+ export * from "./balances";
2
+ export * from "./buildStorageCoders";
3
+ export * from "./decodeOutput";
4
+ export * from "./detectTransferMethod";
5
+ export * from "./findChainMeta";
6
+ export * from "./getUniqueChainIds";
7
+ export * from "./InferBalanceModuleTypes";
8
+ export * from "./makeContractCaller";
9
+ export * from "./RpcStateQueryHelper";
10
+ export * from "./storageCompression";
@@ -0,0 +1,9 @@
1
+ import { TypeRegistry } from "@polkadot/types";
2
+ import { ChainConnector } from "@talismn/chain-connector";
3
+ export declare const makeContractCaller: ({ chainConnector, chainId, registry, }: {
4
+ chainConnector: ChainConnector;
5
+ chainId: string;
6
+ registry: TypeRegistry;
7
+ }) => <T extends Uint8Array | {
8
+ toU8a: () => Uint8Array;
9
+ }>(callFrom: string, contractAddress: string, inputData: T) => Promise<import("@polkadot/types/interfaces").ContractExecResult>;
@@ -0,0 +1,9 @@
1
+ import { Table } from "dexie";
2
+ import { BalanceJson } from "../../types";
3
+ export type StoredBalanceJson = Omit<BalanceJson, "status">;
4
+ export declare const configureStore: (dbTable?: Table) => {
5
+ persistData: (balances: StoredBalanceJson[]) => Promise<void>;
6
+ retrieveData: () => Promise<StoredBalanceJson[]>;
7
+ };
8
+ export declare const compress: (balances: StoredBalanceJson[]) => Uint8Array;
9
+ export declare const decompress: (data: Uint8Array | ArrayBuffer) => StoredBalanceJson[];
@@ -1,7 +1,13 @@
1
1
  import { ChainList, EvmNetworkList, TokenList } from "@talismn/chaindata-provider";
2
2
  import { TokenRateCurrency, TokenRates, TokenRatesList } from "@talismn/token-rates";
3
3
  import { NonFunctionProperties } from "@talismn/util";
4
- import { BalanceJson, BalanceJsonList, IBalance } from "./balancetypes";
4
+ import { Amount, AmountWithLabel, BalanceJson, BalanceJsonList, BalanceStatusTypes, ExtraAmount, IBalance, LockedAmount } from "./balancetypes";
5
+ type FormattedAmount<GenericAmount extends AmountWithLabel<TLabel>, TLabel extends string> = Omit<GenericAmount, "amount"> & {
6
+ amount: BalanceFormatter;
7
+ };
8
+ export declare function excludeFromTransferableAmount(locks: Amount | FormattedAmount<LockedAmount<string>, string> | Array<FormattedAmount<LockedAmount<string>, string>>): bigint;
9
+ export declare function excludeFromFeePayableLocks(locks: Amount | LockedAmount<string> | Array<LockedAmount<string>>): Array<LockedAmount<string>>;
10
+ export declare function includeInTotalExtraAmount(extra?: FormattedAmount<ExtraAmount<string>, string> | Array<FormattedAmount<ExtraAmount<string>, string>>): bigint;
5
11
  /**
6
12
  * Have the importing library define its Token and BalanceJson enums (as a sum type of all plugins) and pass them into some
7
13
  * internal global typescript context, which is then picked up on by this module.
@@ -40,7 +46,7 @@ export declare class Balances {
40
46
  * // do something
41
47
  * }
42
48
  */
43
- [Symbol.iterator]: () => IterableIterator<Balance>;
49
+ [Symbol.iterator]: () => ArrayIterator<Balance>;
44
50
  /**
45
51
  * Hydrates all balances in this collection.
46
52
  *
@@ -66,14 +72,10 @@ export declare class Balances {
66
72
  * and another balance exists in this collection for the token specified by the `mirrorOf` field.
67
73
  */
68
74
  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
75
  /**
74
76
  * Filters this collection to only include balances which are not zero AND have a fiat conversion rate.
75
77
  */
76
- filterNonZeroFiat: (type: "total" | "free" | "reserved" | "locked" | "frozen" | "transferable" | "feePayable", currency: TokenRateCurrency) => Balances;
78
+ filterNonZeroFiat: (type: "total" | "free" | "reserved" | "locked" | "frozen" | "transferable" | "unavailable" | "feePayable", currency: TokenRateCurrency) => Balances;
77
79
  /**
78
80
  * Add some balances to this collection.
79
81
  * Added balances take priority over existing balances.
@@ -116,6 +118,7 @@ export declare class Balances {
116
118
  */
117
119
  get sum(): SumBalancesFormatter;
118
120
  }
121
+ export declare const getBalanceId: (balance: BalanceJson) => string;
119
122
  /**
120
123
  * An individual balance.
121
124
  */
@@ -126,7 +129,7 @@ export declare class Balance {
126
129
  isSource: (source: BalanceSource) => boolean;
127
130
  hydrate: (hydrate?: HydrateDb) => void;
128
131
  get id(): string;
129
- get source(): string;
132
+ get source(): "evm-erc20" | "evm-native" | "evm-uniswapv2" | "substrate-assets" | "substrate-equilibrium" | "substrate-foreignassets" | "substrate-native" | "substrate-psp22" | "substrate-tokens";
130
133
  get status(): import("./balancetypes").BalanceStatus;
131
134
  get address(): string;
132
135
  get chainId(): string | undefined;
@@ -134,9 +137,107 @@ export declare class Balance {
134
137
  get evmNetworkId(): string | undefined;
135
138
  get evmNetwork(): import("@talismn/chaindata-provider").EvmNetwork | null;
136
139
  get tokenId(): string;
137
- get token(): import("@talismn/chaindata-provider").IToken | null;
140
+ get token(): (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
141
+ type: "evm-erc20";
142
+ } & {
143
+ contractAddress: string;
144
+ evmNetwork: {
145
+ id: import("@talismn/chaindata-provider").EvmNetworkId;
146
+ } | null;
147
+ isCustom?: true;
148
+ image?: string;
149
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
150
+ type: "evm-native";
151
+ } & {
152
+ evmNetwork: {
153
+ id: import("@talismn/chaindata-provider").EvmNetworkId;
154
+ };
155
+ isCustom?: true;
156
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
157
+ type: "evm-uniswapv2";
158
+ } & {
159
+ contractAddress: string;
160
+ symbol0: string;
161
+ symbol1: string;
162
+ decimals0: number;
163
+ decimals1: number;
164
+ tokenAddress0: string;
165
+ tokenAddress1: string;
166
+ coingeckoId0?: string;
167
+ coingeckoId1?: string;
168
+ evmNetwork: {
169
+ id: import("@talismn/chaindata-provider").EvmNetworkId;
170
+ } | null;
171
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
172
+ type: "substrate-assets";
173
+ } & {
174
+ existentialDeposit: string;
175
+ assetId: string;
176
+ isFrozen: boolean;
177
+ chain: {
178
+ id: import("@talismn/chaindata-provider").ChainId;
179
+ };
180
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
181
+ type: "substrate-equilibrium";
182
+ } & {
183
+ existentialDeposit: string;
184
+ assetId: string;
185
+ chain: {
186
+ id: import("@talismn/chaindata-provider").ChainId;
187
+ };
188
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
189
+ type: "substrate-foreignassets";
190
+ } & {
191
+ existentialDeposit: string;
192
+ onChainId: string;
193
+ isFrozen: boolean;
194
+ chain: {
195
+ id: import("@talismn/chaindata-provider").ChainId;
196
+ };
197
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
198
+ type: "substrate-native";
199
+ } & {
200
+ existentialDeposit: string;
201
+ chain: {
202
+ id: import("@talismn/chaindata-provider").ChainId;
203
+ };
204
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
205
+ type: "substrate-psp22";
206
+ } & {
207
+ existentialDeposit: string;
208
+ contractAddress: string;
209
+ chain: {
210
+ id: import("@talismn/chaindata-provider").ChainId;
211
+ };
212
+ }) | (import("@talismn/chaindata-provider/dist/declarations/src/types/Token/types").TokenBase & {
213
+ type: "substrate-tokens";
214
+ } & {
215
+ existentialDeposit: string;
216
+ onChainId: string | number;
217
+ chain: {
218
+ id: import("@talismn/chaindata-provider").ChainId;
219
+ };
220
+ }) | null;
138
221
  get decimals(): number | null;
139
222
  get rates(): TokenRates | null;
223
+ /**
224
+ * A general method to get formatted values matching a certain type from this balance.
225
+ * @param valueType - The type of value to get.
226
+ * @returns An array of the values matching the type with formatted amounts.
227
+ */
228
+ private getValue;
229
+ /**
230
+ * A general method to get values matching a certain type from this balance.
231
+ * @param valueType - The type of value to get.
232
+ * @returns An array of the values matching the type.
233
+ */
234
+ private getRawValue;
235
+ /**
236
+ * A general method to add a value to the array of values for this balance.
237
+ * @param valueType - The type of value to add.
238
+ * @returns A function which can be used to add a value to the array of values for this balance.
239
+ */
240
+ private addValue;
140
241
  /**
141
242
  * The total balance of this token.
142
243
  * Includes the free and the reserved amount.
@@ -147,30 +248,37 @@ export declare class Balance {
147
248
  get free(): BalanceFormatter;
148
249
  /** The reserved balance of this token. Is included in the total. */
149
250
  get reserved(): BalanceFormatter;
150
- get reserves(): {
151
- amount: BalanceFormatter;
152
- label: string;
153
- meta?: unknown;
154
- }[];
251
+ get reserves(): FormattedAmount<AmountWithLabel<string>, string>[];
155
252
  /** The frozen balance of this token. Is included in the free amount. */
156
253
  get locked(): BalanceFormatter;
157
- get locks(): {
158
- amount: BalanceFormatter;
159
- label: string;
160
- meta?: unknown;
161
- includeInTransferable?: boolean | undefined;
162
- excludeFromFeePayable?: boolean | undefined;
163
- }[];
254
+ get locks(): FormattedAmount<AmountWithLabel<string>, string>[];
255
+ get crowdloans(): FormattedAmount<AmountWithLabel<string>, string>[];
256
+ get nompools(): FormattedAmount<AmountWithLabel<string>, string>[];
257
+ get subtensor(): FormattedAmount<AmountWithLabel<string>, string>[];
258
+ /** The extra balance of this token */
259
+ get extra(): ExtraAmount<string>[] | undefined;
164
260
  /** @deprecated Use balance.locked */
165
261
  get frozen(): BalanceFormatter;
166
262
  /** The transferable balance of this token. Is generally the free amount - the miscFrozen amount. */
167
263
  get transferable(): BalanceFormatter;
264
+ /**
265
+ * The unavailable balance of this token.
266
+ * Prior to the Fungible trait, this was the locked amount + the reserved amount, i.e. `locked + reserved`.
267
+ * Now, it is the bigger of the locked amount and the reserved amounts, i.e. `max(locked, reserved)`.
268
+ */
269
+ get unavailable(): BalanceFormatter;
168
270
  /** The feePayable balance of this token. Is generally the free amount - the feeFrozen amount. */
169
271
  get feePayable(): BalanceFormatter;
170
272
  }
273
+ export declare class BalanceValueGetter {
274
+ #private;
275
+ constructor(storage: BalanceJson);
276
+ get(valueType: BalanceStatusTypes): AmountWithLabel<string>[];
277
+ add(valueType: BalanceStatusTypes, amount: Omit<AmountWithLabel<string>, "type">): void;
278
+ }
171
279
  export declare class BalanceFormatter {
172
280
  #private;
173
- constructor(planck: string | bigint | undefined, decimals?: number | undefined, fiatRatios?: TokenRates);
281
+ constructor(planck: string | bigint | undefined, decimals?: number | undefined, fiatRatios?: TokenRates | null);
174
282
  toJSON: () => string;
175
283
  get planck(): bigint;
176
284
  get tokens(): string;
@@ -193,6 +301,8 @@ export declare class PlanckSumBalancesFormatter {
193
301
  get frozen(): bigint;
194
302
  /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
195
303
  get transferable(): bigint;
304
+ /** The unavailable balance of these tokens. */
305
+ get unavailable(): bigint;
196
306
  /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
197
307
  get feePayable(): bigint;
198
308
  }
@@ -213,6 +323,8 @@ export declare class FiatSumBalancesFormatter {
213
323
  get frozen(): number;
214
324
  /** The transferable balance of these tokens. Is generally the free amount - the miscFrozen amount. */
215
325
  get transferable(): number;
326
+ /** The unavailable balance of these tokens. */
327
+ get unavailable(): number;
216
328
  /** The feePayable balance of these tokens. Is generally the free amount - the feeFrozen amount. */
217
329
  get feePayable(): number;
218
330
  }
@@ -221,4 +333,43 @@ export declare class SumBalancesFormatter {
221
333
  constructor(balances: Balances);
222
334
  get planck(): PlanckSumBalancesFormatter;
223
335
  fiat(currency: TokenRateCurrency): FiatSumBalancesFormatter;
336
+ change24h(currency: TokenRateCurrency): Change24hCurrencyFormatter;
337
+ }
338
+ export declare class Change24hCurrencyFormatter {
339
+ #private;
340
+ constructor(balances: Balances, currency: TokenRateCurrency);
341
+ get total(): {
342
+ diff: number;
343
+ ratio: number;
344
+ } | null;
345
+ get free(): {
346
+ diff: number;
347
+ ratio: number;
348
+ } | null;
349
+ get reserved(): {
350
+ diff: number;
351
+ ratio: number;
352
+ } | null;
353
+ get locked(): {
354
+ diff: number;
355
+ ratio: number;
356
+ } | null;
357
+ get frozen(): {
358
+ diff: number;
359
+ ratio: number;
360
+ } | null;
361
+ get transferable(): {
362
+ diff: number;
363
+ ratio: number;
364
+ } | null;
365
+ get unavailable(): {
366
+ diff: number;
367
+ ratio: number;
368
+ } | null;
369
+ get feePayable(): {
370
+ diff: number;
371
+ ratio: number;
372
+ } | null;
224
373
  }
374
+ export declare const filterMirrorTokens: (balance: Balance, i: number, balances: Balance[]) => boolean;
375
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { PluginBalanceTypes } from "@talismn/balances/plugins";
2
- import { ChainId, EvmNetworkId, MultiChainId, TokenId } from "@talismn/chaindata-provider";
2
+ import { ChainId, EvmChainId, EvmNetworkId, SubChainId, TokenId } from "@talismn/chaindata-provider";
3
3
  import { Address } from "./addresses";
4
4
  /**
5
5
  * `BalanceTypes` is an automatically determined sub-selection of `PluginBalanceTypes`.
@@ -14,60 +14,71 @@ export type BalanceTypes = {
14
14
  *
15
15
  * Each variant comes from a plugin in use by the consuming app.
16
16
  *
17
- * For example, in an app with the `substrate-native`, `evm-native`, `substrate-orml` and `evm-erc20` plugins:
17
+ * For example, in an app with the `substrate-native`, `evm-native`, `substrate-tokens` and `evm-erc20` plugins:
18
18
  *
19
- * type BalanceJson = SubNativeBalance | EvmNativeBalance | SubOrmlBalance | EvmErc20Balance
19
+ * type BalanceJson = SubNativeBalance | EvmNativeBalance | SubTokensBalance | EvmErc20Balance
20
20
  *
21
21
  * If `BalanceTypes` is empty then `BalanceJson` will fall back to the common `IBalance` interface, which every balance must implement.
22
22
  */
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 BalanceStatusLive = `live-${string}`;
27
- export declare const BalanceStatusLive: (subscriptionId: string) => BalanceStatusLive;
28
- export type BalanceStatus = BalanceStatusLive | "live" | "cache" | "stale";
29
- /** `IBalance` is a common interface which all balance types must implement. */
30
- export type IBalance = {
26
+ export type BalanceStatus = "live" | "cache" | "stale";
27
+ type IBalanceBase = {
31
28
  /** The module that this balance was retrieved by */
32
29
  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;
30
+ useLegacyTransferableCalculation?: boolean;
38
31
  /** Has this balance never been fetched, or is it from a cache, or is it up to date? */
39
32
  status: BalanceStatus;
40
33
  /** The address of the account which owns this balance */
41
34
  address: Address;
42
35
  /** The token this balance is for */
43
36
  tokenId: TokenId;
37
+ };
38
+ type IBalanceBaseEvm = {
44
39
  /** WIP, use `chainId` or `evmNetworkId` for now */
45
- multiChainId: MultiChainId;
46
- /** The substrate chain this balance is on */
47
- chainId?: ChainId;
40
+ multiChainId: EvmChainId;
48
41
  /** The evm chain this balance is on */
49
- evmNetworkId?: EvmNetworkId;
50
- } & IBalanceAmounts;
51
- export type IBalanceAmounts = {
52
- /** The portion of a balance that is not reserved. The free balance is the only balance that matters for most operations. */
53
- free?: Amount | AmountWithLabel<string> | Array<AmountWithLabel<string>>;
54
- /** The portion of a balance that is owned by the account but is reserved/suspended/unavailable. Reserved balance can still be slashed, but only after all the free balance has been slashed. */
55
- reserves?: Amount | AmountWithLabel<string> | Array<AmountWithLabel<string>>;
56
- /** A freeze on a specified amount of an account's free balance until a specified block number. Multiple locks always operate over the same funds, so they overlay rather than stack. */
57
- locks?: Amount | LockedAmount<string> | Array<LockedAmount<string>>;
58
- /** Additional balances held by an account. By default these will not be included in the account total. Dapps may choose to add support for showing extra amounts on a case by case basis. */
59
- extra?: ExtraAmount<string> | Array<ExtraAmount<string>>;
42
+ evmNetworkId: EvmNetworkId;
43
+ };
44
+ type IBalanceBaseSubstrate = {
45
+ multiChainId: SubChainId;
46
+ /** The substrate chain this balance is on */
47
+ chainId: ChainId;
60
48
  };
49
+ type IBalanceSimpleValues = {
50
+ /** For balance types with a simple value, this is the value of the balance (eg, evm native token balance) */
51
+ value: Amount;
52
+ values?: Array<AmountWithLabel<string>>;
53
+ };
54
+ type IBalanceComplexValues = {
55
+ /** For balance types with multple possible states, these are the values of the balance (eg, substrate native token balance) */
56
+ values: Array<AmountWithLabel<string>>;
57
+ value?: undefined;
58
+ };
59
+ /** `IBalance` is a common interface which all balance types must implement. */
60
+ export type IBalance = IBalanceBase & (IBalanceSimpleValues | IBalanceComplexValues) & (IBalanceBaseEvm | IBalanceBaseSubstrate);
61
+ export type EvmBalance = IBalanceBase & IBalanceBaseEvm & (IBalanceSimpleValues | IBalanceComplexValues);
62
+ export type SubstrateBalance = IBalanceBase & IBalanceBaseSubstrate & (IBalanceSimpleValues | IBalanceComplexValues);
61
63
  /** An unlabelled amount of a balance */
62
64
  export type Amount = string;
65
+ export type BalanceStatusTypes = "free" | "reserved" | "locked" | "extra" | "crowdloan" | "nompool" | "subtensor";
63
66
  /** A labelled amount of a balance */
64
- export type AmountWithLabel<TLabel extends string> = {
67
+ type BaseAmountWithLabel<TLabel extends string> = {
68
+ type: BalanceStatusTypes;
69
+ /**
70
+ * For modules which fetch balances via module sources, the source is equivalent to previous 'subSource' field
71
+ * on the parent balance object
72
+ * e.g. `staking` or `crowdloans`
73
+ **/
74
+ source?: string;
65
75
  label: TLabel;
66
76
  amount: Amount;
67
77
  meta?: unknown;
68
78
  };
79
+ export declare const getValueId: (amount: AmountWithLabel<string>) => string;
69
80
  /** A labelled locked amount of a balance */
70
- export type LockedAmount<TLabel extends string> = AmountWithLabel<TLabel> & {
81
+ export type LockedAmount<TLabel extends string> = BaseAmountWithLabel<TLabel> & {
71
82
  /**
72
83
  * By default, the largest locked amount is subtrated from the transferable amount of this balance.
73
84
  * If this property is set to true, this particular lock will be skipped when making this calculation.
@@ -82,15 +93,15 @@ export type LockedAmount<TLabel extends string> = AmountWithLabel<TLabel> & {
82
93
  */
83
94
  excludeFromFeePayable?: boolean;
84
95
  };
85
- export declare function excludeFromTransferableAmount(locks: Amount | LockedAmount<string> | Array<LockedAmount<string>>): bigint;
86
- export declare function excludeFromFeePayableLocks(locks: Amount | LockedAmount<string> | Array<LockedAmount<string>>): Array<LockedAmount<string>>;
96
+ export type AmountWithLabel<TLabel extends string> = BaseAmountWithLabel<TLabel> | LockedAmount<TLabel> | ExtraAmount<TLabel>;
87
97
  /** A labelled extra amount of a balance */
88
- export type ExtraAmount<TLabel extends string> = AmountWithLabel<TLabel> & {
98
+ export type ExtraAmount<TLabel extends string> = BaseAmountWithLabel<TLabel> & {
99
+ type: "extra";
89
100
  /** If set to true, this extra amount will be included in the calculation of the total amount of this balance. */
90
101
  includeInTotal?: boolean;
91
102
  };
92
- export declare function includeInTotalExtraAmount(extra?: ExtraAmount<string> | Array<ExtraAmount<string>>): bigint;
93
103
  /** Used by plugins to help define their custom `BalanceType` */
94
- export type NewBalanceType<TModuleType extends string, T extends IBalanceAmounts> = IBalance & {
104
+ export type NewBalanceType<TModuleType extends string, TBalanceValueType extends "simple" | "complex", TNetworkType extends "ethereum" | "substrate"> = IBalanceBase & (TBalanceValueType extends "simple" ? IBalanceSimpleValues : IBalanceComplexValues) & (TNetworkType extends "ethereum" ? IBalanceBaseEvm : IBalanceBaseSubstrate) & {
95
105
  source: TModuleType;
96
- } & T;
106
+ };
107
+ export {};
@@ -1,4 +1,5 @@
1
1
  export * from "./addresses";
2
2
  export * from "./balances";
3
3
  export * from "./balancetypes";
4
+ export * from "./minimetadatas";
4
5
  export * from "./subscriptions";
@@ -0,0 +1,33 @@
1
+ import { ChainId } from "@talismn/chaindata-provider";
2
+ /** For fast db access, you can calculate the primary key for a miniMetadata using this method */
3
+ export declare const deriveMiniMetadataId: ({ source, chainId, specName, specVersion, balancesConfig, }: Pick<MiniMetadata, "source" | "chainId" | "specName" | "specVersion" | "balancesConfig">) => string;
4
+ export type MiniMetadataStatus =
5
+ /** Metadata is up to date */
6
+ "good"
7
+ /** Metadata exists, but needs to be updated */
8
+ | "outdated"
9
+ /** Metadata doesn't exist */
10
+ | "none";
11
+ export type MiniMetadata = {
12
+ /** The DB id for this metadata */
13
+ id: string;
14
+ /** The balance module which created this miniMetadata */
15
+ source: string;
16
+ /** The chain this miniMetadata came from */
17
+ chainId: ChainId;
18
+ /** The chain specName which this miniMetadata is valid for */
19
+ specName: string;
20
+ /** The chain specVersion which this miniMetadata is valid for */
21
+ specVersion: string;
22
+ /** The JSON-encoded chain balancesConfig which this miniMetadata is valid for */
23
+ balancesConfig: string;
24
+ /** The version of the metadata format e.g. 13, 14, 15, etc */
25
+ version: number;
26
+ /** The miniMetadata encoded as a hex string */
27
+ data: `0x${string}` | null;
28
+ /**
29
+ * Some balance modules need a little bit of extra data in addition to the miniMetadata.
30
+ * They can store that data as a JSON-encoded string here.
31
+ */
32
+ extra: string;
33
+ };
@@ -0,0 +1,2 @@
1
+ import { Transaction } from "dexie";
2
+ export declare const upgradeRemoveSymbolFromNativeTokenId: (tx: Transaction) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ import { Transaction } from "dexie";
2
+ export declare const upgradeBalancesDataBlob: (tx: Transaction) => Promise<void>;
@@ -0,0 +1,2 @@
1
+ export * from "./2024-01-25-upgradeRemoveSymbolFromNativeTokenId";
2
+ export * from "./2024-03-19-upgradeBalancesDataBlob";
@@ -0,0 +1,8 @@
1
+ import { EvmTokenFetcher, MiniMetadataUpdater } from "@talismn/balances";
2
+ import { ChaindataProvider } from "@talismn/chaindata-provider";
3
+ /** Pulls the latest chaindata from https://github.com/TalismanSociety/chaindata */
4
+ export declare const hydrateChaindataAndMiniMetadata: (chaindataProvider: ChaindataProvider, miniMetadataUpdater: MiniMetadataUpdater) => Promise<void>;
5
+ /** Builds any missing miniMetadatas (e.g. for the user's custom substrate chains) */
6
+ export declare const updateCustomMiniMetadata: (chaindataProvider: ChaindataProvider, miniMetadataUpdater: MiniMetadataUpdater) => Promise<void>;
7
+ /** Fetches any missing Evm Tokens */
8
+ export declare const updateEvmTokens: (chaindataProvider: ChaindataProvider, evmTokenFetcher: EvmTokenFetcher) => Promise<void>;
@@ -0,0 +1 @@
1
+ export * from "./hydrateChaindata";