@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.
- package/README.md +122 -0
- package/dist/declarations/src/BalanceModule.d.ts +25 -17
- package/dist/declarations/src/EvmTokenFetcher.d.ts +11 -0
- package/dist/declarations/src/MiniMetadataUpdater.d.ts +43 -0
- package/dist/declarations/src/TalismanBalancesDatabase.d.ts +6 -2
- package/dist/declarations/src/index.d.ts +4 -1
- package/dist/declarations/src/modules/EvmErc20Module.d.ts +33 -0
- package/dist/declarations/src/modules/EvmNativeModule.d.ts +26 -0
- package/dist/declarations/src/modules/EvmUniswapV2Module.d.ts +39 -0
- package/dist/declarations/src/modules/SubstrateAssetsModule.d.ts +38 -0
- package/dist/declarations/src/modules/SubstrateEquilibriumModule.d.ts +39 -0
- package/dist/declarations/src/modules/SubstrateForeignAssetsModule.d.ts +38 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/index.d.ts +7 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeBase.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeCrowdloans.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeNompoolStaking.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/subscribeSubtensorStaking.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/types.d.ts +49 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/QueryCache.d.ts +13 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/SubNativeBalanceError.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/asObservable.d.ts +10 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/balanceLockTypes.d.ts +15 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/buildQueries.d.ts +13 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/crowdloanFundContributionsChildKey.d.ts +4 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/detectMiniMetadataChanges.d.ts +2 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/mergeBalances.d.ts +13 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/nompoolAccountId.d.ts +5 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/sortChains.d.ts +1 -0
- package/dist/declarations/src/modules/SubstrateNativeModule/util/subtensor.d.ts +55 -0
- package/dist/declarations/src/modules/SubstratePsp22Module.d.ts +39 -0
- package/dist/declarations/src/modules/SubstrateTokensModule.d.ts +43 -0
- package/dist/declarations/src/modules/abis/erc20.d.ts +227 -0
- package/dist/declarations/src/modules/abis/erc20BalancesAggregator.d.ts +19 -0
- package/dist/declarations/src/modules/abis/multicall.d.ts +276 -0
- package/dist/declarations/src/modules/abis/uniswapV2Pair.d.ts +560 -0
- package/dist/declarations/src/modules/index.d.ts +60 -0
- package/dist/declarations/src/modules/util/InferBalanceModuleTypes.d.ts +28 -0
- package/dist/declarations/src/modules/util/RpcStateQueryHelper.d.ts +19 -0
- package/dist/declarations/src/modules/util/balances.d.ts +8 -0
- package/dist/declarations/src/modules/util/buildStorageCoders.d.ts +26 -0
- package/dist/declarations/src/modules/util/decodeOutput.d.ts +13 -0
- package/dist/declarations/src/modules/util/detectTransferMethod.d.ts +11 -0
- package/dist/declarations/src/modules/util/findChainMeta.d.ts +8 -0
- package/dist/declarations/src/modules/util/getUniqueChainIds.d.ts +5 -0
- package/dist/declarations/src/modules/util/index.d.ts +10 -0
- package/dist/declarations/src/modules/util/makeContractCaller.d.ts +9 -0
- package/dist/declarations/src/modules/util/storageCompression.d.ts +9 -0
- package/dist/declarations/src/types/balances.d.ts +173 -22
- package/dist/declarations/src/types/balancetypes.d.ts +46 -35
- package/dist/declarations/src/types/index.d.ts +1 -0
- package/dist/declarations/src/types/minimetadatas.d.ts +33 -0
- package/dist/declarations/src/upgrades/2024-01-25-upgradeRemoveSymbolFromNativeTokenId.d.ts +2 -0
- package/dist/declarations/src/upgrades/2024-03-19-upgradeBalancesDataBlob.d.ts +2 -0
- package/dist/declarations/src/upgrades/index.d.ts +2 -0
- package/dist/declarations/src/util/hydrateChaindata.d.ts +8 -0
- package/dist/declarations/src/util/index.d.ts +1 -0
- package/dist/talismn-balances.cjs.dev.js +7256 -412
- package/dist/talismn-balances.cjs.prod.js +7256 -412
- package/dist/talismn-balances.esm.js +7202 -397
- package/package.json +41 -23
- package/CHANGELOG.md +0 -294
- package/dist/declarations/src/helpers.d.ts +0 -86
package/README.md
CHANGED
@@ -1 +1,123 @@
|
|
1
1
|
# @talismn/balances
|
2
|
+
|
3
|
+
<img src="talisman.svg" alt="Talisman" width="15%" align="right" />
|
4
|
+
|
5
|
+
[](https://github.com/TalismanSociety/talisman/blob/dev/LICENSE)
|
6
|
+
[](https://www.npmjs.com/package/@talismn/balances)
|
7
|
+
[](https://www.npmjs.com/package/@talismn/balances)
|
8
|
+
|
9
|
+
**@talismn/balances** is the core of a set of packages used to subscribe to on-chain account token balances.
|
10
|
+
|
11
|
+
A quick rundown on each package is given below.
|
12
|
+
|
13
|
+
### This (the core) package:
|
14
|
+
|
15
|
+
**@talismn/balances** (this package) includes:
|
16
|
+
|
17
|
+
- An API which wallets / dapps can use to access balances
|
18
|
+
- An interface for balance modules to implement
|
19
|
+
- A shared database (powered by dexie) for balance modules to store balances in
|
20
|
+
- Helpers (utility functions) for balance modules to use
|
21
|
+
- Provides a plugin architecture, which is used by the balance module packages to specify their balance types
|
22
|
+
|
23
|
+
### The react API for wallets & dapps:
|
24
|
+
|
25
|
+
**@talismn/balances-react** includes:
|
26
|
+
|
27
|
+
- React hooks for subscribing to on-chain account token balances
|
28
|
+
- (soon™): recoil atoms for on-chain account token balances
|
29
|
+
|
30
|
+
### The balance modules:
|
31
|
+
|
32
|
+
**@talismn/balances-default-modules**
|
33
|
+
|
34
|
+
- Collates the default balance modules (which can be found below) into a single package
|
35
|
+
|
36
|
+
**@talismn/substrate-native**
|
37
|
+
|
38
|
+
- A balance module for substrate native tokens
|
39
|
+
- Subscribes to the `system.account` state query balance for each token
|
40
|
+
- Also subscribes to the crowdloans pallet balances
|
41
|
+
- Also subscribes to the nompools pallet balances
|
42
|
+
|
43
|
+
**@talismn/substrate-orml**
|
44
|
+
|
45
|
+
- A proof-of-concept balance module for ORML token pallet tokens
|
46
|
+
- Attempts to auto-detect tokens
|
47
|
+
- **You should use @talismn/substrate-tokens instead**
|
48
|
+
|
49
|
+
**@talismn/substrate-tokens**
|
50
|
+
|
51
|
+
- A balance module for substrate ORML token pallet tokens
|
52
|
+
- Supports any token which can be queried via the `tokens.accounts` state query
|
53
|
+
- Requires configuration for each token (no auto-detection)
|
54
|
+
- We recommend that you use this module for ORML tokens
|
55
|
+
|
56
|
+
**@talismn/substrate-assets**
|
57
|
+
|
58
|
+
- A balance module for substrate assets pallet tokens
|
59
|
+
- Supports any token which can be queried via the `assets.account` state query
|
60
|
+
- Requires configuration for each token (no auto-detection)
|
61
|
+
|
62
|
+
**@talismn/substrate-equilibrium**
|
63
|
+
|
64
|
+
- A balance module for substrate eqBalances pallet tokens
|
65
|
+
- Used by [Equilibrium](https://equilibrium.io/) and [Genshiro](https://genshiro.io/)
|
66
|
+
- Supports auto-detection
|
67
|
+
|
68
|
+
**@talismn/evm-native**
|
69
|
+
|
70
|
+
- A balance module for evm native tokens
|
71
|
+
|
72
|
+
**@talismn/evm-erc20**
|
73
|
+
|
74
|
+
- A balance module for evm erc20 tokens
|
75
|
+
|
76
|
+
### The chain connectors:
|
77
|
+
|
78
|
+
**@talismn/chain-connector**
|
79
|
+
|
80
|
+
- A package which manages the open RPC connections to substrate chains
|
81
|
+
- Allows developers to say "Send this query to the chain with this id", without them needing to specify which RPCs to use
|
82
|
+
- Ensures that connections are only opened to the chains which are in use by the wallet/dapp
|
83
|
+
- Ensures that only one connection is open per chain
|
84
|
+
- Handles exponential backoff in the case of network failures
|
85
|
+
- Provides an interface which can be shared between a serviceworker and frontend, which enables the two to share the pool of open connections
|
86
|
+
- Provides an interface which mimics a polkadot-js `WsProvider`, which can be plugged into polkadot-js to make it use the shared pool of open connections
|
87
|
+
|
88
|
+
**@talismn/chain-connector-evm**
|
89
|
+
|
90
|
+
- A package which manages the connections to evm chains
|
91
|
+
- Allows developers to say "Send this query to the chain with this id", without them needing to specify which RPC to use
|
92
|
+
|
93
|
+
### The chaindata provider:
|
94
|
+
|
95
|
+
**@talismn/chaindata-provider**
|
96
|
+
|
97
|
+
- A database (powered by dexie) to store chains, evm chains and tokens in
|
98
|
+
- An interface to interact with the database
|
99
|
+
- Syncs with the list in the [chaindata repository](https://github.com/talismansociety/chaindata) via graphql
|
100
|
+
- Supports custom (end-user-defined) chains and rpc overrides
|
101
|
+
- Provides a plugin architecture, which is used by the balance module packages to specify their token types
|
102
|
+
|
103
|
+
### The remaining packages:
|
104
|
+
|
105
|
+
**@talismn/connection-meta**
|
106
|
+
|
107
|
+
- Contains a small db which is used to optimise network performance in the wallet.
|
108
|
+
- Two metrics are kept:
|
109
|
+
- chainPriorityRpc (the last known well-behaved RPC for a chain)
|
110
|
+
- chainBackoffInterval (the amount of time the wallet should wait before attempting to connect to a unreachable chain again)
|
111
|
+
|
112
|
+
**@talismn/mutate-metadata**
|
113
|
+
|
114
|
+
- A package which can splice a chain's metadata into smaller pieces
|
115
|
+
- Enables us to make state queries across many chains at once without using all of the browser's memory
|
116
|
+
|
117
|
+
**@talismn/token-rates**
|
118
|
+
|
119
|
+
- Fetches and stores coingecko rates for each token in the @talismn/chaindata-provider database
|
120
|
+
|
121
|
+
**@talismn/util**
|
122
|
+
|
123
|
+
- Utility functions shared by the other packages, as well as the wallet and the portal
|
@@ -1,10 +1,12 @@
|
|
1
|
-
import { UnsignedTransaction } from "@substrate/txwrapper-core";
|
2
1
|
import { ChainConnector } from "@talismn/chain-connector";
|
3
2
|
import { ChainConnectorEvm } from "@talismn/chain-connector-evm";
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
|
7
|
-
export type
|
3
|
+
import { ChaindataProvider, ChainId, Token } from "@talismn/chaindata-provider";
|
4
|
+
import { AddressesByToken, BalanceJson, Balances, SubscriptionCallback, UnsubscribeFn } from "./types";
|
5
|
+
export type BalancesCommonTransferMethods = "transfer_keep_alive" | "transfer_all";
|
6
|
+
export type BalancesTransferMethods = "transfer_allow_death" | BalancesCommonTransferMethods;
|
7
|
+
export type BalancesLegacyTransferMethods = "transfer" | BalancesCommonTransferMethods;
|
8
|
+
export type BalancesAllTransferMethods = BalancesLegacyTransferMethods | BalancesTransferMethods;
|
9
|
+
export type SelectableTokenType = Token;
|
8
10
|
export type ExtendableChainMeta = Record<string, unknown> | undefined;
|
9
11
|
export type DefaultChainMeta = undefined;
|
10
12
|
export type ExtendableModuleConfig = Record<string, unknown> | undefined;
|
@@ -14,16 +16,15 @@ export type BaseTransferParams = {
|
|
14
16
|
from: string;
|
15
17
|
to: string;
|
16
18
|
amount: string;
|
19
|
+
transferMethod: BalancesAllTransferMethods;
|
20
|
+
metadataRpc: `0x${string}`;
|
17
21
|
};
|
18
22
|
export type ExtendableTransferParams = BaseTransferParams | undefined;
|
19
23
|
export type DefaultTransferParams = undefined;
|
20
24
|
export type NewTransferParamsType<T extends Record<string, unknown>> = BaseTransferParams & T;
|
21
25
|
export type TransferTokenTx = {
|
22
26
|
type: "substrate";
|
23
|
-
|
24
|
-
} | {
|
25
|
-
type: "evm";
|
26
|
-
tx: ethers.providers.TransactionRequest;
|
27
|
+
callData: string;
|
27
28
|
};
|
28
29
|
export type ChainConnectors = {
|
29
30
|
substrate?: ChainConnector;
|
@@ -33,30 +34,37 @@ export type Hydrate = {
|
|
33
34
|
chainConnectors: ChainConnectors;
|
34
35
|
chaindataProvider: ChaindataProvider;
|
35
36
|
};
|
36
|
-
export type NewBalanceModule<TModuleType extends string, TTokenType extends
|
37
|
-
export interface BalanceModule<TModuleType extends string, TTokenType extends
|
37
|
+
export type NewBalanceModule<TModuleType extends string, TTokenType extends SelectableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> = (hydrate: Hydrate) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>;
|
38
|
+
export interface BalanceModule<TModuleType extends string, TTokenType extends SelectableTokenType, 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> {
|
38
39
|
}
|
39
|
-
export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends
|
40
|
-
interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends
|
40
|
+
export declare const DefaultBalanceModule: <TModuleType extends string, TTokenType extends SelectableTokenType, TChainMeta extends ExtendableChainMeta = undefined, TModuleConfig extends ExtendableModuleConfig = undefined, TTransferParams extends ExtendableTransferParams = undefined>(type: TModuleType) => BalanceModule<TModuleType, TTokenType, TChainMeta, TModuleConfig, TTransferParams>;
|
41
|
+
interface BalanceModuleSubstrate<TModuleType extends string, TTokenType extends SelectableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleCommon<TModuleType, TTokenType, TTransferParams> {
|
41
42
|
/** Pre-processes any substrate chain metadata required by this module ahead of time */
|
42
|
-
fetchSubstrateChainMeta(chainId: ChainId, moduleConfig?: TModuleConfig): Promise<TChainMeta | null>;
|
43
|
+
fetchSubstrateChainMeta(chainId: ChainId, moduleConfig?: TModuleConfig, metadataRpc?: `0x${string}`, systemProperties?: Record<string, any>): Promise<TChainMeta | null>;
|
43
44
|
/** Detects which tokens are available on a given substrate chain */
|
44
45
|
fetchSubstrateChainTokens(chainId: ChainId, chainMeta: TChainMeta, moduleConfig?: TModuleConfig): Promise<Record<TTokenType["id"], TTokenType>>;
|
45
46
|
}
|
46
|
-
interface BalanceModuleEvm<TModuleType extends string, TTokenType extends
|
47
|
+
interface BalanceModuleEvm<TModuleType extends string, TTokenType extends SelectableTokenType, TChainMeta extends ExtendableChainMeta = DefaultChainMeta, TModuleConfig extends ExtendableModuleConfig = DefaultModuleConfig, TTransferParams extends ExtendableTransferParams = DefaultTransferParams> extends BalanceModuleCommon<TModuleType, TTokenType, TTransferParams> {
|
47
48
|
/** Pre-processes any evm chain metadata required by this module ahead of time */
|
48
49
|
fetchEvmChainMeta(chainId: ChainId, moduleConfig?: TModuleConfig): Promise<TChainMeta | null>;
|
49
50
|
/** Detects which tokens are available on a given evm chain */
|
50
51
|
fetchEvmChainTokens(chainId: ChainId, chainMeta: TChainMeta, moduleConfig?: TModuleConfig): Promise<Record<TTokenType["id"], TTokenType>>;
|
51
52
|
}
|
52
|
-
|
53
|
+
export type SubscriptionResultWithStatus = {
|
54
|
+
status: "initialising" | "live";
|
55
|
+
data: BalanceJson[];
|
56
|
+
};
|
57
|
+
interface BalanceModuleCommon<TModuleType extends string, TTokenType extends SelectableTokenType, TTransferParams extends ExtendableTransferParams> {
|
53
58
|
get type(): TModuleType;
|
54
59
|
/**
|
55
60
|
* Subscribe to balances for this module with optional filtering.
|
56
61
|
*
|
57
62
|
* If subscriptions are not possible, this function should poll at some reasonable interval.
|
58
63
|
*/
|
59
|
-
subscribeBalances(addressesByToken
|
64
|
+
subscribeBalances({ addressesByToken, initialBalances, }: {
|
65
|
+
addressesByToken: AddressesByToken<TTokenType>;
|
66
|
+
initialBalances?: BalanceJson[];
|
67
|
+
}, callback: SubscriptionCallback<Balances | SubscriptionResultWithStatus>): Promise<UnsubscribeFn>;
|
60
68
|
/** Fetch balances for this module with optional filtering */
|
61
69
|
fetchBalances(addressesByToken: AddressesByToken<TTokenType>): Promise<Balances>;
|
62
70
|
/** Prepare a tx to transfer some tokens from this module */
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ChaindataProvider, EvmNetworkId } from "@talismn/chaindata-provider";
|
2
|
+
import { AnyBalanceModule } from "./modules/util";
|
3
|
+
/**
|
4
|
+
* Fetches tokens for EVM networks.
|
5
|
+
*/
|
6
|
+
export declare class EvmTokenFetcher {
|
7
|
+
#private;
|
8
|
+
constructor(chaindataProvider: ChaindataProvider, balanceModules: Array<AnyBalanceModule>);
|
9
|
+
update(evmNetworkIds: EvmNetworkId[]): Promise<void>;
|
10
|
+
private updateEvmNetworks;
|
11
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Chain, ChaindataProvider, ChainId } from "@talismn/chaindata-provider";
|
2
|
+
import { ChainConnectors } from "./BalanceModule";
|
3
|
+
import { AnyBalanceModule } from "./modules/util";
|
4
|
+
import { MiniMetadata, MiniMetadataStatus } from "./types";
|
5
|
+
/**
|
6
|
+
* A substrate dapp needs access to a set of types when it wants to communicate with a blockchain node.
|
7
|
+
*
|
8
|
+
* These types are used to encode requests & decode responses via the SCALE codec.
|
9
|
+
* Each chain generally has its own set of types.
|
10
|
+
*
|
11
|
+
* Substrate provides a construct to retrieve these types from a blockchain node.
|
12
|
+
* The chain metadata.
|
13
|
+
*
|
14
|
+
* The metadata includes the types required for any communication with the chain,
|
15
|
+
* including lots of methods which are not relevant to balance fetching.
|
16
|
+
*
|
17
|
+
* As such, the metadata can clock in at around 1-2MB per chain, which is a lot of storage
|
18
|
+
* for browser-based dapps which want to connect to lots of chains.
|
19
|
+
*
|
20
|
+
* By utilizing the wonderful [scale-ts](https://github.com/unstoppablejs/unstoppablejs/tree/main/packages/scale-ts#readme) library,
|
21
|
+
* we can trim the chain metadata down so that it only includes the types we need for balance fetching.
|
22
|
+
*
|
23
|
+
* Each balance module has a function to do just that, `BalanceModule::fetchSubstrateChainMeta`.
|
24
|
+
*
|
25
|
+
* But, we only want to run this operation when necessary.
|
26
|
+
*
|
27
|
+
* The purpose of this class, `MiniMetadataUpdater`, is to maintain a local cache of
|
28
|
+
* trimmed-down metadatas, which we'll refer to as `MiniMetadatas`.
|
29
|
+
*/
|
30
|
+
export declare class MiniMetadataUpdater {
|
31
|
+
#private;
|
32
|
+
constructor(chainConnectors: ChainConnectors, chaindataProvider: ChaindataProvider, balanceModules: Array<AnyBalanceModule>);
|
33
|
+
/** Subscribe to the metadata for a chain */
|
34
|
+
subscribe(chainId: ChainId): import("rxjs").Observable<MiniMetadata>;
|
35
|
+
update(chainIds: ChainId[]): Promise<void>;
|
36
|
+
statuses(chains: Array<Pick<Chain, "id" | "specName" | "specVersion" | "balancesConfig">>): Promise<{
|
37
|
+
wantedIdsByChain: Map<string, string[]>;
|
38
|
+
statusesByChain: Map<string, MiniMetadataStatus>;
|
39
|
+
}>;
|
40
|
+
hydrateFromChaindata(): Promise<boolean>;
|
41
|
+
hydrateCustomChains(): Promise<boolean>;
|
42
|
+
private updateSubstrateChains;
|
43
|
+
}
|
@@ -1,7 +1,11 @@
|
|
1
1
|
import { Dexie } from "dexie";
|
2
|
-
import {
|
2
|
+
import { MiniMetadata } from "./types";
|
3
3
|
export declare class TalismanBalancesDatabase extends Dexie {
|
4
|
-
|
4
|
+
balancesBlob: Dexie.Table<{
|
5
|
+
data: Uint8Array;
|
6
|
+
id: string;
|
7
|
+
}, string>;
|
8
|
+
miniMetadatas: Dexie.Table<MiniMetadata, string>;
|
5
9
|
constructor();
|
6
10
|
}
|
7
11
|
export declare const db: TalismanBalancesDatabase;
|
@@ -1,4 +1,7 @@
|
|
1
1
|
export * from "./BalanceModule";
|
2
|
+
export * from "./EvmTokenFetcher";
|
3
|
+
export * from "./MiniMetadataUpdater";
|
2
4
|
export * from "./TalismanBalancesDatabase";
|
3
|
-
export * from "./
|
5
|
+
export * from "./modules";
|
4
6
|
export * from "./types";
|
7
|
+
export * from "./util";
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { BalancesConfigTokenParams, EvmNetworkId, Token } from "@talismn/chaindata-provider";
|
2
|
+
import { NewBalanceModule } from "../BalanceModule";
|
3
|
+
import { NewBalanceType } from "../types";
|
4
|
+
import { erc20Abi } from "./abis/erc20";
|
5
|
+
import { erc20BalancesAggregatorAbi } from "./abis/erc20BalancesAggregator";
|
6
|
+
export { erc20Abi, erc20BalancesAggregatorAbi };
|
7
|
+
type ModuleType = "evm-erc20";
|
8
|
+
export type EvmErc20Token = Extract<Token, {
|
9
|
+
type: ModuleType;
|
10
|
+
isCustom?: true;
|
11
|
+
}>;
|
12
|
+
export type CustomEvmErc20Token = Extract<Token, {
|
13
|
+
type: ModuleType;
|
14
|
+
isCustom: true;
|
15
|
+
}>;
|
16
|
+
export declare const evmErc20TokenId: (chainId: EvmNetworkId, tokenContractAddress: EvmErc20Token["contractAddress"]) => string;
|
17
|
+
export type EvmErc20ChainMeta = {
|
18
|
+
isTestnet: boolean;
|
19
|
+
};
|
20
|
+
export type EvmErc20ModuleConfig = {
|
21
|
+
tokens?: Array<{
|
22
|
+
symbol?: string;
|
23
|
+
decimals?: number;
|
24
|
+
contractAddress?: string;
|
25
|
+
} & BalancesConfigTokenParams>;
|
26
|
+
};
|
27
|
+
export type EvmErc20Balance = NewBalanceType<ModuleType, "simple", "ethereum">;
|
28
|
+
declare module "@talismn/balances/plugins" {
|
29
|
+
interface PluginBalanceTypes {
|
30
|
+
"evm-erc20": EvmErc20Balance;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
export declare const EvmErc20Module: NewBalanceModule<ModuleType, EvmErc20Token | CustomEvmErc20Token, EvmErc20ChainMeta, EvmErc20ModuleConfig>;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { BalancesConfigTokenParams, EvmNetworkId, Token } from "@talismn/chaindata-provider";
|
2
|
+
import { NewBalanceModule } from "../BalanceModule";
|
3
|
+
import { NewBalanceType } from "../types";
|
4
|
+
type ModuleType = "evm-native";
|
5
|
+
export type EvmNativeToken = Extract<Token, {
|
6
|
+
type: ModuleType;
|
7
|
+
}>;
|
8
|
+
export type CustomEvmNativeToken = Extract<Token, {
|
9
|
+
type: ModuleType;
|
10
|
+
}>;
|
11
|
+
export declare const evmNativeTokenId: (chainId: EvmNetworkId) => string;
|
12
|
+
export type EvmNativeChainMeta = {
|
13
|
+
isTestnet: boolean;
|
14
|
+
};
|
15
|
+
export type EvmNativeModuleConfig = {
|
16
|
+
symbol?: string;
|
17
|
+
decimals?: number;
|
18
|
+
} & BalancesConfigTokenParams;
|
19
|
+
export type EvmNativeBalance = NewBalanceType<ModuleType, "simple", "ethereum">;
|
20
|
+
declare module "@talismn/balances/plugins" {
|
21
|
+
interface PluginBalanceTypes {
|
22
|
+
"evm-native": EvmNativeBalance;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
export declare const EvmNativeModule: NewBalanceModule<ModuleType, EvmNativeToken | CustomEvmNativeToken, EvmNativeChainMeta, EvmNativeModuleConfig>;
|
26
|
+
export {};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { BalancesConfigTokenParams, EvmNetworkId, Token } from "@talismn/chaindata-provider";
|
2
|
+
import { NewBalanceModule } from "../BalanceModule";
|
3
|
+
import { NewBalanceType } from "../types";
|
4
|
+
import { uniswapV2PairAbi } from "./abis/uniswapV2Pair";
|
5
|
+
export { uniswapV2PairAbi };
|
6
|
+
type ModuleType = "evm-uniswapv2";
|
7
|
+
export type EvmUniswapV2Token = Extract<Token, {
|
8
|
+
type: ModuleType;
|
9
|
+
isCustom?: true;
|
10
|
+
}>;
|
11
|
+
export type CustomEvmUniswapV2Token = Extract<Token, {
|
12
|
+
type: ModuleType;
|
13
|
+
isCustom: true;
|
14
|
+
}>;
|
15
|
+
export declare const evmUniswapV2TokenId: (chainId: EvmNetworkId, contractAddress: EvmUniswapV2Token["contractAddress"]) => string;
|
16
|
+
export type EvmUniswapV2ChainMeta = {
|
17
|
+
isTestnet: boolean;
|
18
|
+
};
|
19
|
+
export type EvmUniswapV2ModuleConfig = {
|
20
|
+
pools?: Array<{
|
21
|
+
contractAddress?: string;
|
22
|
+
decimals?: number;
|
23
|
+
symbol0?: string;
|
24
|
+
symbol1?: string;
|
25
|
+
decimals0?: number;
|
26
|
+
decimals1?: number;
|
27
|
+
tokenAddress0?: string;
|
28
|
+
tokenAddress1?: string;
|
29
|
+
coingeckoId0?: string;
|
30
|
+
coingeckoId1?: string;
|
31
|
+
} & BalancesConfigTokenParams>;
|
32
|
+
};
|
33
|
+
export type EvmUniswapV2Balance = NewBalanceType<"evm-uniswapv2", "complex", "ethereum">;
|
34
|
+
declare module "@talismn/balances/plugins" {
|
35
|
+
interface PluginBalanceTypes {
|
36
|
+
"evm-uniswapv2": EvmUniswapV2Balance;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
export declare const EvmUniswapV2Module: NewBalanceModule<ModuleType, EvmUniswapV2Token | CustomEvmUniswapV2Token, EvmUniswapV2ChainMeta, EvmUniswapV2ModuleConfig>;
|
@@ -0,0 +1,38 @@
|
|
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-assets";
|
7
|
+
export type SubAssetsToken = Extract<Token, {
|
8
|
+
type: ModuleType;
|
9
|
+
}>;
|
10
|
+
export declare const subAssetTokenId: (chainId: ChainId, assetId: string, tokenSymbol: string) => string;
|
11
|
+
export type SubAssetsChainMeta = {
|
12
|
+
isTestnet: boolean;
|
13
|
+
miniMetadata?: string;
|
14
|
+
metadataVersion?: number;
|
15
|
+
};
|
16
|
+
export type SubAssetsModuleConfig = {
|
17
|
+
tokens?: Array<{
|
18
|
+
assetId: string | number;
|
19
|
+
} & BalancesConfigTokenParams>;
|
20
|
+
};
|
21
|
+
export type SubAssetsBalance = NewBalanceType<ModuleType, "complex", "substrate">;
|
22
|
+
declare module "@talismn/balances/plugins" {
|
23
|
+
interface PluginBalanceTypes {
|
24
|
+
"substrate-assets": SubAssetsBalance;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
export type SubAssetsTransferParams = NewTransferParamsType<{
|
28
|
+
registry: TypeRegistry;
|
29
|
+
blockHash: string;
|
30
|
+
blockNumber: number;
|
31
|
+
nonce: number;
|
32
|
+
specVersion: number;
|
33
|
+
transactionVersion: number;
|
34
|
+
tip?: string;
|
35
|
+
userExtensions?: ExtDef;
|
36
|
+
}>;
|
37
|
+
export declare const SubAssetsModule: NewBalanceModule<ModuleType, SubAssetsToken, SubAssetsChainMeta, SubAssetsModuleConfig, SubAssetsTransferParams>;
|
38
|
+
export {};
|
@@ -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-equilibrium";
|
7
|
+
export type SubEquilibriumToken = Extract<Token, {
|
8
|
+
type: ModuleType;
|
9
|
+
}>;
|
10
|
+
export declare const subEquilibriumTokenId: (chainId: ChainId, tokenSymbol: string) => string;
|
11
|
+
export type SubEquilibriumChainMeta = {
|
12
|
+
isTestnet: boolean;
|
13
|
+
miniMetadata?: string;
|
14
|
+
metadataVersion?: number;
|
15
|
+
};
|
16
|
+
export type SubEquilibriumModuleConfig = {
|
17
|
+
disable?: boolean;
|
18
|
+
tokens?: Array<{
|
19
|
+
assetId?: string;
|
20
|
+
} & BalancesConfigTokenParams>;
|
21
|
+
};
|
22
|
+
export type SubEquilibriumBalance = NewBalanceType<ModuleType, "simple", "substrate">;
|
23
|
+
declare module "@talismn/balances/plugins" {
|
24
|
+
interface PluginBalanceTypes {
|
25
|
+
"substrate-equilibrium": SubEquilibriumBalance;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
export type SubEquilibriumTransferParams = 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 SubEquilibriumModule: NewBalanceModule<ModuleType, SubEquilibriumToken, SubEquilibriumChainMeta, SubEquilibriumModuleConfig, SubEquilibriumTransferParams>;
|
39
|
+
export {};
|
@@ -0,0 +1,38 @@
|
|
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-foreignassets";
|
7
|
+
export type SubForeignAssetsToken = Extract<Token, {
|
8
|
+
type: ModuleType;
|
9
|
+
}>;
|
10
|
+
export declare const subForeignAssetTokenId: (chainId: ChainId, tokenSymbol: string) => string;
|
11
|
+
export type SubForeignAssetsChainMeta = {
|
12
|
+
isTestnet: boolean;
|
13
|
+
miniMetadata?: string;
|
14
|
+
metadataVersion?: number;
|
15
|
+
};
|
16
|
+
export type SubForeignAssetsModuleConfig = {
|
17
|
+
tokens?: Array<{
|
18
|
+
onChainId: string;
|
19
|
+
} & BalancesConfigTokenParams>;
|
20
|
+
};
|
21
|
+
export type SubForeignAssetsBalance = NewBalanceType<ModuleType, "complex", "substrate">;
|
22
|
+
declare module "@talismn/balances/plugins" {
|
23
|
+
interface PluginBalanceTypes {
|
24
|
+
"substrate-foreignassets": SubForeignAssetsBalance;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
export type SubForeignAssetsTransferParams = NewTransferParamsType<{
|
28
|
+
registry: TypeRegistry;
|
29
|
+
blockHash: string;
|
30
|
+
blockNumber: number;
|
31
|
+
nonce: number;
|
32
|
+
specVersion: number;
|
33
|
+
transactionVersion: number;
|
34
|
+
tip?: string;
|
35
|
+
userExtensions?: ExtDef;
|
36
|
+
}>;
|
37
|
+
export declare const SubForeignAssetsModule: NewBalanceModule<ModuleType, SubForeignAssetsToken, SubForeignAssetsChainMeta, SubForeignAssetsModuleConfig, SubForeignAssetsTransferParams>;
|
38
|
+
export {};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { NewBalanceModule } from "../../BalanceModule";
|
2
|
+
import { CustomSubNativeToken, ModuleType, SubNativeChainMeta, SubNativeModuleConfig, SubNativeToken, SubNativeTransferParams } from "./types";
|
3
|
+
export { filterBaseLocks, getLockTitle } from "./util/balanceLockTypes";
|
4
|
+
export type { BalanceLockType } from "./util/balanceLockTypes";
|
5
|
+
export type { CustomSubNativeToken, ModuleType, SubNativeBalance, SubNativeChainMeta, SubNativeModuleConfig, SubNativeToken, SubNativeTransferParams, } from "./types";
|
6
|
+
export { subNativeTokenId } from "./types";
|
7
|
+
export declare const SubNativeModule: NewBalanceModule<ModuleType, SubNativeToken | CustomSubNativeToken, SubNativeChainMeta, SubNativeModuleConfig, SubNativeTransferParams>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ChainConnector } from "@talismn/chain-connector";
|
2
|
+
import { SubscriptionCallback } from "../../types";
|
3
|
+
import { RpcStateQuery } from "../util";
|
4
|
+
import { SubNativeBalance } from "./types";
|
5
|
+
export declare function subscribeBase(queries: RpcStateQuery<SubNativeBalance>[], chainConnector: ChainConnector, callback: SubscriptionCallback<SubNativeBalance[]>): Promise<import("../../types").UnsubscribeFn>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ChainConnector } from "@talismn/chain-connector";
|
2
|
+
import { ChaindataProvider } from "@talismn/chaindata-provider";
|
3
|
+
import { AddressesByToken, SubscriptionCallback } from "../../types";
|
4
|
+
import { CustomSubNativeToken, SubNativeBalance, SubNativeToken } from "./types";
|
5
|
+
export declare function subscribeCrowdloans(chaindataProvider: ChaindataProvider, chainConnector: ChainConnector, addressesByToken: AddressesByToken<SubNativeToken | CustomSubNativeToken>, callback: SubscriptionCallback<SubNativeBalance[]>): Promise<() => void>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ChainConnector } from "@talismn/chain-connector";
|
2
|
+
import { ChaindataProvider } from "@talismn/chaindata-provider";
|
3
|
+
import { AddressesByToken, SubscriptionCallback } from "../../types";
|
4
|
+
import { SubNativeBalance, SubNativeToken } from "./types";
|
5
|
+
export declare function subscribeNompoolStaking(chaindataProvider: ChaindataProvider, chainConnector: ChainConnector, addressesByToken: AddressesByToken<SubNativeToken>, callback: SubscriptionCallback<SubNativeBalance[]>): Promise<() => void>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { ChainConnector } from "@talismn/chain-connector";
|
2
|
+
import { ChaindataProvider } from "@talismn/chaindata-provider";
|
3
|
+
import { AddressesByToken, SubscriptionCallback } from "../../types";
|
4
|
+
import { SubNativeBalance, SubNativeToken } from "./types";
|
5
|
+
export declare function subscribeSubtensorStaking(chaindataProvider: ChaindataProvider, chainConnector: ChainConnector, addressesByToken: AddressesByToken<SubNativeToken>, callback: SubscriptionCallback<SubNativeBalance[]>): Promise<() => void>;
|
@@ -0,0 +1,49 @@
|
|
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 { NewTransferParamsType } from "../../BalanceModule";
|
5
|
+
import { NewBalanceType } from "../../types";
|
6
|
+
export { filterBaseLocks, getLockTitle } from "./util/balanceLockTypes";
|
7
|
+
export type { BalanceLockType } from "./util/balanceLockTypes";
|
8
|
+
export type ModuleType = "substrate-native";
|
9
|
+
export declare const moduleType: ModuleType;
|
10
|
+
export type SubNativeToken = Extract<Token, {
|
11
|
+
type: ModuleType;
|
12
|
+
isCustom?: true;
|
13
|
+
}>;
|
14
|
+
export type CustomSubNativeToken = Extract<Token, {
|
15
|
+
type: ModuleType;
|
16
|
+
isCustom: true;
|
17
|
+
}>;
|
18
|
+
export declare const subNativeTokenId: (chainId: ChainId) => string;
|
19
|
+
export type SubNativeChainMeta = {
|
20
|
+
isTestnet: boolean;
|
21
|
+
useLegacyTransferableCalculation?: boolean;
|
22
|
+
symbol?: string;
|
23
|
+
decimals?: number;
|
24
|
+
existentialDeposit?: string;
|
25
|
+
nominationPoolsPalletId?: string;
|
26
|
+
crowdloanPalletId?: string;
|
27
|
+
hasSubtensorPallet?: boolean;
|
28
|
+
miniMetadata?: string;
|
29
|
+
metadataVersion?: number;
|
30
|
+
};
|
31
|
+
export type SubNativeModuleConfig = {
|
32
|
+
disable?: boolean;
|
33
|
+
} & BalancesConfigTokenParams;
|
34
|
+
export type SubNativeBalance = NewBalanceType<ModuleType, "complex", "substrate">;
|
35
|
+
declare module "@talismn/balances/plugins" {
|
36
|
+
interface PluginBalanceTypes {
|
37
|
+
"substrate-native": SubNativeBalance;
|
38
|
+
}
|
39
|
+
}
|
40
|
+
export type SubNativeTransferParams = NewTransferParamsType<{
|
41
|
+
registry: TypeRegistry;
|
42
|
+
blockHash: string;
|
43
|
+
blockNumber: number;
|
44
|
+
nonce: number;
|
45
|
+
specVersion: number;
|
46
|
+
transactionVersion: number;
|
47
|
+
tip?: string;
|
48
|
+
userExtensions?: ExtDef;
|
49
|
+
}>;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ChaindataProvider } from "@talismn/chaindata-provider";
|
2
|
+
import { AddressesByToken } from "../../../types";
|
3
|
+
import { RpcStateQuery } from "../../util";
|
4
|
+
import { SubNativeBalance, SubNativeToken } from "../types";
|
5
|
+
export declare class QueryCache {
|
6
|
+
private chaindataProvider;
|
7
|
+
private balanceQueryCache;
|
8
|
+
private metadataSub;
|
9
|
+
constructor(chaindataProvider: ChaindataProvider);
|
10
|
+
ensureSetup(): void;
|
11
|
+
destroy(): void;
|
12
|
+
getQueries(addressesByToken: AddressesByToken<SubNativeToken>): Promise<RpcStateQuery<SubNativeBalance>[]>;
|
13
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Observable } from "rxjs";
|
2
|
+
import { SubscriptionCallback, UnsubscribeFn } from "../../../types";
|
3
|
+
/**
|
4
|
+
* Converts a subscription function into an Observable
|
5
|
+
*
|
6
|
+
* The type of a subscription function which can be converted into an observable:
|
7
|
+
*
|
8
|
+
* <TArgs, TResult>(...arguments: TArgs, callback: SubscriptionCallback<TResult>) => UnsubscribeFn
|
9
|
+
*/
|
10
|
+
export declare const asObservable: <T extends unknown[], R>(handler: (...args: [...T, SubscriptionCallback<R>]) => UnsubscribeFn) => (...args: T) => Observable<R>;
|