@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,15 @@
1
+ import { Balance, BalanceFormatter, LockedAmount } from "../../../types";
2
+ export type BalanceLockType = "reserved" | "democracy" | "crowdloan" | "staking" | "nompools-staking" | "nompools-unbonding" | "subtensor-staking" | "vesting" | "dapp-staking" | `other-${string}` | "other";
3
+ /**
4
+ * For converting the value of `lock?.id?.toUtf8?.()` which is retrieved from
5
+ * the Balances.Locks storage key into a useful classification for our UI
6
+ */
7
+ export declare const getLockedType: (input?: string) => BalanceLockType;
8
+ export declare const filterBaseLocks: (locks: Array<Omit<LockedAmount<string>, "amount"> & {
9
+ amount: BalanceFormatter;
10
+ }>) => (Omit<LockedAmount<string>, "amount"> & {
11
+ amount: BalanceFormatter;
12
+ })[];
13
+ export declare const getLockTitle: (lock: Pick<LockedAmount<string>, "label" | "meta">, { balance }?: {
14
+ balance?: Balance;
15
+ }) => string;
@@ -0,0 +1,13 @@
1
+ import { Chain, Token } from "@talismn/chaindata-provider";
2
+ import { AddressesByToken, MiniMetadata } from "../../../types";
3
+ import { RpcStateQuery, StorageCoders } from "../../util";
4
+ import { SubNativeBalance, SubNativeToken } from "../types";
5
+ export type QueryKey = string;
6
+ export declare function buildQueries(chains: Record<string, Chain>, tokens: Record<string, Token>, chainStorageCoders: StorageCoders<{
7
+ base: ["System", "Account"];
8
+ stakingLedger: ["Staking", "Ledger"];
9
+ reserves: ["Balances", "Reserves"];
10
+ holds: ["Balances", "Holds"];
11
+ locks: ["Balances", "Locks"];
12
+ freezes: ["Balances", "Freezes"];
13
+ }>, miniMetadatas: Map<string, MiniMetadata>, addressesByToken: AddressesByToken<SubNativeToken>): Promise<Record<QueryKey, Array<RpcStateQuery<SubNativeBalance>>>>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Crowdloan contributions are stored in the `childstate` key returned by this function.
3
+ */
4
+ export declare const crowdloanFundContributionsChildKey: (fundIndex: number) => `0x${string}`;
@@ -0,0 +1,2 @@
1
+ import { MiniMetadata } from "../../../types";
2
+ export declare const detectMiniMetadataChanges: () => import("rxjs").UnaryFunction<import("rxjs").Observable<Map<string, MiniMetadata>>, import("rxjs").Observable<Set<string>>>;
@@ -0,0 +1,13 @@
1
+ import { SubNativeBalance } from "../types";
2
+ export { filterBaseLocks, getLockTitle } from "./balanceLockTypes";
3
+ export type { BalanceLockType } from "./balanceLockTypes";
4
+ /**
5
+ * Function to merge two 'sub sources' of the same balance together, or
6
+ * two instances of the same balance with different values.
7
+ * @param balance1 SubNativeBalance
8
+ * @param balance2 SubNativeBalance
9
+ * @param source source that this merge is for (will discard previous values from that source)
10
+ * @param clear whether to clear the previous values from the source
11
+ * @returns SubNativeBalance
12
+ */
13
+ export declare const mergeBalances: (balance1: SubNativeBalance | undefined, balance2: SubNativeBalance, source: string, clear: boolean) => SubNativeBalance;
@@ -0,0 +1,5 @@
1
+ import { SS58String } from "polkadot-api";
2
+ /** The stash account for the nomination pool */
3
+ export declare const nompoolStashAccountId: (palletId: string, poolId: string | number) => SS58String;
4
+ /** The rewards account for the nomination pool */
5
+ export declare const nompoolRewardAccountId: (palletId: string, poolId: string | number) => SS58String;
@@ -0,0 +1 @@
1
+ export declare const sortChains: (a: string, b: string) => 0 | 1 | -1;
@@ -0,0 +1,55 @@
1
+ export declare const SUBTENSOR_ROOT_NETUID = 0;
2
+ export declare const SUBTENSOR_MIN_STAKE_AMOUNT_PLANK = 1000000n;
3
+ export declare const SCALE_FACTOR: bigint;
4
+ export declare const ONE_ALPHA_TOKEN: bigint;
5
+ export declare const EncodeParams_GetStakeInfoForColdkey: (address: string) => string;
6
+ export declare const DecodeResult_GetStakeInfoForColdkey: (result: string) => {
7
+ hotkey: import("polkadot-api").SS58String;
8
+ coldkey: import("polkadot-api").SS58String;
9
+ netuid: number | bigint;
10
+ stake: number | bigint;
11
+ locked: number | bigint;
12
+ emission: number | bigint;
13
+ tao_emission: number | bigint;
14
+ drain: number | bigint;
15
+ isRegistered: boolean;
16
+ }[];
17
+ /** Encoding/decoding for GetStakeDynamicInfo */
18
+ export declare const EncodeParams_GetDynamicInfo: (netuid: number) => string;
19
+ export type DynamicInfoType = ReturnType<typeof DecodeResult_GetDynamicInfo>;
20
+ export declare const DecodeResult_GetDynamicInfo: (result: string) => {
21
+ netuid: number;
22
+ tokenSymbol: string;
23
+ subnetIdentity: Record<string, string>;
24
+ taoIn: bigint;
25
+ alphaIn: bigint;
26
+ subnetName: string;
27
+ ownerHotkey: import("polkadot-api").SS58String;
28
+ ownerColdkey: import("polkadot-api").SS58String;
29
+ tempo: number | bigint;
30
+ lastStep: number | bigint;
31
+ blocksSinceLastStep: number | bigint;
32
+ emission: number | bigint;
33
+ alphaOut: number | bigint;
34
+ alphaOutEmission: number | bigint;
35
+ alphaInEmission: number | bigint;
36
+ taoInEmission: number | bigint;
37
+ pendingAlphaEmission: number | bigint;
38
+ pendingRootEmission: number | bigint;
39
+ subnetVolume: number | bigint;
40
+ networkRegisteredAt: number | bigint;
41
+ movingPrice: {
42
+ bits: number | bigint;
43
+ };
44
+ };
45
+ export declare const calculateAlphaPrice: ({ dynamicInfo, }: {
46
+ dynamicInfo: DynamicInfoType | void | null;
47
+ }) => bigint;
48
+ export declare const calculateTaoAmountFromAlpha: ({ alphaPrice, alphaStaked, }: {
49
+ alphaPrice: bigint;
50
+ alphaStaked: bigint;
51
+ }) => bigint;
52
+ export declare const calculateTaoFromDynamicInfo: ({ dynamicInfo, alphaStaked, }: {
53
+ dynamicInfo: DynamicInfoType | void | null;
54
+ alphaStaked: bigint;
55
+ }) => bigint;
@@ -0,0 +1,39 @@
1
+ import { TypeRegistry } from "@polkadot/types";
2
+ import { ExtDef } from "@polkadot/types/extrinsic/signedExtensions/types";
3
+ import { BalancesConfigTokenParams, ChainId, Token } from "@talismn/chaindata-provider";
4
+ import { NewBalanceModule, NewTransferParamsType } from "../BalanceModule";
5
+ import { NewBalanceType } from "../types";
6
+ type ModuleType = "substrate-psp22";
7
+ export type SubPsp22Token = Extract<Token, {
8
+ type: ModuleType;
9
+ }>;
10
+ export declare const subPsp22TokenId: (chainId: ChainId, tokenSymbol: string) => string;
11
+ export type SubPsp22ChainMeta = {
12
+ isTestnet: boolean;
13
+ };
14
+ export type SubPsp22ModuleConfig = {
15
+ tokens?: Array<{
16
+ symbol?: string;
17
+ decimals?: number;
18
+ ed?: string;
19
+ contractAddress?: string;
20
+ } & BalancesConfigTokenParams>;
21
+ };
22
+ export type SubPsp22Balance = NewBalanceType<ModuleType, "simple", "substrate">;
23
+ declare module "@talismn/balances/plugins" {
24
+ interface PluginBalanceTypes {
25
+ "substrate-psp22": SubPsp22Balance;
26
+ }
27
+ }
28
+ export type SubPsp22TransferParams = NewTransferParamsType<{
29
+ registry: TypeRegistry;
30
+ blockHash: string;
31
+ blockNumber: number;
32
+ nonce: number;
33
+ specVersion: number;
34
+ transactionVersion: number;
35
+ tip?: string;
36
+ userExtensions?: ExtDef;
37
+ }>;
38
+ export declare const SubPsp22Module: NewBalanceModule<ModuleType, SubPsp22Token, SubPsp22ChainMeta, SubPsp22ModuleConfig, SubPsp22TransferParams>;
39
+ export {};
@@ -0,0 +1,43 @@
1
+ import { TypeRegistry } from "@polkadot/types";
2
+ import { ExtDef } from "@polkadot/types/extrinsic/signedExtensions/types";
3
+ import { BalancesConfigTokenParams, ChainId, Token } from "@talismn/chaindata-provider";
4
+ import { NewBalanceModule, NewTransferParamsType } from "../BalanceModule";
5
+ import { NewBalanceType } from "../types";
6
+ type ModuleType = "substrate-tokens";
7
+ export type SubTokensToken = Extract<Token, {
8
+ type: ModuleType;
9
+ }>;
10
+ export declare const subTokensTokenId: (chainId: ChainId, tokenSymbol: string) => string;
11
+ export type SubTokensChainMeta = {
12
+ isTestnet: boolean;
13
+ palletId?: string;
14
+ miniMetadata?: string;
15
+ metadataVersion?: number;
16
+ };
17
+ export type SubTokensModuleConfig = {
18
+ palletId?: string;
19
+ tokens?: Array<{
20
+ symbol?: string;
21
+ decimals?: number;
22
+ ed?: string;
23
+ onChainId?: string | number;
24
+ } & BalancesConfigTokenParams>;
25
+ };
26
+ export type SubTokensBalance = NewBalanceType<ModuleType, "complex", "substrate">;
27
+ declare module "@talismn/balances/plugins" {
28
+ interface PluginBalanceTypes {
29
+ "substrate-tokens": SubTokensBalance;
30
+ }
31
+ }
32
+ export type SubTokensTransferParams = NewTransferParamsType<{
33
+ registry: TypeRegistry;
34
+ blockHash: string;
35
+ blockNumber: number;
36
+ nonce: number;
37
+ specVersion: number;
38
+ transactionVersion: number;
39
+ tip?: string;
40
+ userExtensions?: ExtDef;
41
+ }>;
42
+ export declare const SubTokensModule: NewBalanceModule<ModuleType, SubTokensToken, SubTokensChainMeta, SubTokensModuleConfig, SubTokensTransferParams>;
43
+ export {};
@@ -0,0 +1,227 @@
1
+ export declare const erc20Abi: readonly [{
2
+ readonly constant: true;
3
+ readonly inputs: readonly [];
4
+ readonly name: "name";
5
+ readonly outputs: readonly [{
6
+ readonly name: "";
7
+ readonly type: "string";
8
+ }];
9
+ readonly payable: false;
10
+ readonly stateMutability: "view";
11
+ readonly type: "function";
12
+ }, {
13
+ readonly constant: false;
14
+ readonly inputs: readonly [{
15
+ readonly name: "_spender";
16
+ readonly type: "address";
17
+ }, {
18
+ readonly name: "_value";
19
+ readonly type: "uint256";
20
+ }];
21
+ readonly name: "approve";
22
+ readonly outputs: readonly [{
23
+ readonly name: "";
24
+ readonly type: "bool";
25
+ }];
26
+ readonly payable: false;
27
+ readonly stateMutability: "nonpayable";
28
+ readonly type: "function";
29
+ }, {
30
+ readonly constant: true;
31
+ readonly inputs: readonly [];
32
+ readonly name: "totalSupply";
33
+ readonly outputs: readonly [{
34
+ readonly name: "";
35
+ readonly type: "uint256";
36
+ }];
37
+ readonly payable: false;
38
+ readonly stateMutability: "view";
39
+ readonly type: "function";
40
+ }, {
41
+ readonly constant: false;
42
+ readonly inputs: readonly [{
43
+ readonly name: "_from";
44
+ readonly type: "address";
45
+ }, {
46
+ readonly name: "_to";
47
+ readonly type: "address";
48
+ }, {
49
+ readonly name: "_value";
50
+ readonly type: "uint256";
51
+ }];
52
+ readonly name: "transferFrom";
53
+ readonly outputs: readonly [{
54
+ readonly name: "";
55
+ readonly type: "bool";
56
+ }];
57
+ readonly payable: false;
58
+ readonly stateMutability: "nonpayable";
59
+ readonly type: "function";
60
+ }, {
61
+ readonly constant: true;
62
+ readonly inputs: readonly [];
63
+ readonly name: "decimals";
64
+ readonly outputs: readonly [{
65
+ readonly name: "";
66
+ readonly type: "uint8";
67
+ }];
68
+ readonly payable: false;
69
+ readonly stateMutability: "view";
70
+ readonly type: "function";
71
+ }, {
72
+ readonly constant: false;
73
+ readonly inputs: readonly [{
74
+ readonly name: "_to";
75
+ readonly type: "address";
76
+ }, {
77
+ readonly name: "_value";
78
+ readonly type: "uint256";
79
+ }, {
80
+ readonly name: "_data";
81
+ readonly type: "bytes";
82
+ }];
83
+ readonly name: "transferAndCall";
84
+ readonly outputs: readonly [{
85
+ readonly name: "success";
86
+ readonly type: "bool";
87
+ }];
88
+ readonly payable: false;
89
+ readonly stateMutability: "nonpayable";
90
+ readonly type: "function";
91
+ }, {
92
+ readonly constant: false;
93
+ readonly inputs: readonly [{
94
+ readonly name: "_spender";
95
+ readonly type: "address";
96
+ }, {
97
+ readonly name: "_subtractedValue";
98
+ readonly type: "uint256";
99
+ }];
100
+ readonly name: "decreaseApproval";
101
+ readonly outputs: readonly [{
102
+ readonly name: "success";
103
+ readonly type: "bool";
104
+ }];
105
+ readonly payable: false;
106
+ readonly stateMutability: "nonpayable";
107
+ readonly type: "function";
108
+ }, {
109
+ readonly constant: true;
110
+ readonly inputs: readonly [{
111
+ readonly name: "_owner";
112
+ readonly type: "address";
113
+ }];
114
+ readonly name: "balanceOf";
115
+ readonly outputs: readonly [{
116
+ readonly name: "balance";
117
+ readonly type: "uint256";
118
+ }];
119
+ readonly payable: false;
120
+ readonly stateMutability: "view";
121
+ readonly type: "function";
122
+ }, {
123
+ readonly constant: true;
124
+ readonly inputs: readonly [];
125
+ readonly name: "symbol";
126
+ readonly outputs: readonly [{
127
+ readonly name: "";
128
+ readonly type: "string";
129
+ }];
130
+ readonly payable: false;
131
+ readonly stateMutability: "view";
132
+ readonly type: "function";
133
+ }, {
134
+ readonly constant: false;
135
+ readonly inputs: readonly [{
136
+ readonly name: "_to";
137
+ readonly type: "address";
138
+ }, {
139
+ readonly name: "_value";
140
+ readonly type: "uint256";
141
+ }];
142
+ readonly name: "transfer";
143
+ readonly outputs: readonly [{
144
+ readonly name: "success";
145
+ readonly type: "bool";
146
+ }];
147
+ readonly payable: false;
148
+ readonly stateMutability: "nonpayable";
149
+ readonly type: "function";
150
+ }, {
151
+ readonly constant: false;
152
+ readonly inputs: readonly [{
153
+ readonly name: "_spender";
154
+ readonly type: "address";
155
+ }, {
156
+ readonly name: "_addedValue";
157
+ readonly type: "uint256";
158
+ }];
159
+ readonly name: "increaseApproval";
160
+ readonly outputs: readonly [{
161
+ readonly name: "success";
162
+ readonly type: "bool";
163
+ }];
164
+ readonly payable: false;
165
+ readonly stateMutability: "nonpayable";
166
+ readonly type: "function";
167
+ }, {
168
+ readonly constant: true;
169
+ readonly inputs: readonly [{
170
+ readonly name: "_owner";
171
+ readonly type: "address";
172
+ }, {
173
+ readonly name: "_spender";
174
+ readonly type: "address";
175
+ }];
176
+ readonly name: "allowance";
177
+ readonly outputs: readonly [{
178
+ readonly name: "remaining";
179
+ readonly type: "uint256";
180
+ }];
181
+ readonly payable: false;
182
+ readonly stateMutability: "view";
183
+ readonly type: "function";
184
+ }, {
185
+ readonly inputs: readonly [];
186
+ readonly payable: false;
187
+ readonly stateMutability: "nonpayable";
188
+ readonly type: "constructor";
189
+ }, {
190
+ readonly anonymous: false;
191
+ readonly inputs: readonly [{
192
+ readonly indexed: true;
193
+ readonly name: "from";
194
+ readonly type: "address";
195
+ }, {
196
+ readonly indexed: true;
197
+ readonly name: "to";
198
+ readonly type: "address";
199
+ }, {
200
+ readonly indexed: false;
201
+ readonly name: "value";
202
+ readonly type: "uint256";
203
+ }, {
204
+ readonly indexed: false;
205
+ readonly name: "data";
206
+ readonly type: "bytes";
207
+ }];
208
+ readonly name: "Transfer";
209
+ readonly type: "event";
210
+ }, {
211
+ readonly anonymous: false;
212
+ readonly inputs: readonly [{
213
+ readonly indexed: true;
214
+ readonly name: "owner";
215
+ readonly type: "address";
216
+ }, {
217
+ readonly indexed: true;
218
+ readonly name: "spender";
219
+ readonly type: "address";
220
+ }, {
221
+ readonly indexed: false;
222
+ readonly name: "value";
223
+ readonly type: "uint256";
224
+ }];
225
+ readonly name: "Approval";
226
+ readonly type: "event";
227
+ }];
@@ -0,0 +1,19 @@
1
+ export declare const erc20BalancesAggregatorAbi: readonly [{
2
+ readonly name: "balances";
3
+ readonly type: "function";
4
+ readonly stateMutability: "view";
5
+ readonly inputs: readonly [{
6
+ readonly type: "tuple[]";
7
+ readonly components: readonly [{
8
+ readonly type: "address";
9
+ readonly name: "account";
10
+ }, {
11
+ readonly type: "address";
12
+ readonly name: "token";
13
+ }];
14
+ readonly name: "accountTokens";
15
+ }];
16
+ readonly outputs: readonly [{
17
+ readonly type: "uint256[]";
18
+ }];
19
+ }];