@talismn/chain-connectors 0.0.13 → 0.0.15
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/dist/index.d.mts +139 -0
- package/dist/index.d.ts +139 -0
- package/dist/{talismn-chain-connectors.cjs.dev.js → index.js} +496 -510
- package/dist/index.js.map +1 -0
- package/dist/{talismn-chain-connectors.esm.js → index.mjs} +443 -468
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -22
- package/dist/declarations/src/dot/ChainConnectorDot.d.ts +0 -79
- package/dist/declarations/src/dot/ChainConnectorDotStub.d.ts +0 -11
- package/dist/declarations/src/dot/IChainConnectorDot.d.ts +0 -10
- package/dist/declarations/src/dot/Websocket.d.ts +0 -111
- package/dist/declarations/src/dot/helpers.d.ts +0 -15
- package/dist/declarations/src/dot/index.d.ts +0 -3
- package/dist/declarations/src/eth/ChainConnectorEth.d.ts +0 -10
- package/dist/declarations/src/eth/ChainConnectorEthStub.d.ts +0 -10
- package/dist/declarations/src/eth/IChainConnectorEth.d.ts +0 -7
- package/dist/declarations/src/eth/getChainFromEvmNetwork.d.ts +0 -4
- package/dist/declarations/src/eth/getEvmNetworkPublicClient.d.ts +0 -4
- package/dist/declarations/src/eth/getEvmNetworkWalletClient.d.ts +0 -7
- package/dist/declarations/src/eth/getTransportForEvmNetwork.d.ts +0 -8
- package/dist/declarations/src/eth/index.d.ts +0 -3
- package/dist/declarations/src/index.d.ts +0 -3
- package/dist/declarations/src/log.d.ts +0 -2
- package/dist/declarations/src/sol/ChainConnectorSol.d.ts +0 -8
- package/dist/declarations/src/sol/ChainConnectorSolStub.d.ts +0 -8
- package/dist/declarations/src/sol/IChainConnectorSol.d.ts +0 -5
- package/dist/declarations/src/sol/getSolConnection.d.ts +0 -3
- package/dist/declarations/src/sol/index.d.ts +0 -3
- package/dist/talismn-chain-connectors.cjs.d.ts +0 -1
- package/dist/talismn-chain-connectors.cjs.js +0 -7
- package/dist/talismn-chain-connectors.cjs.prod.js +0 -1243
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
|
|
2
|
+
import { DotNetworkId, IChaindataNetworkProvider, DotNetwork, EthNetworkId, IChaindataTokenProvider, EthNetwork, SolNetworkId, SolNetwork } from '@talismn/chaindata-provider';
|
|
3
|
+
import { TalismanConnectionMetaDatabase } from '@talismn/connection-meta';
|
|
4
|
+
import { PublicClient, Account, WalletClient } from 'viem';
|
|
5
|
+
import { Connection } from '@solana/web3.js';
|
|
6
|
+
|
|
7
|
+
interface IChainConnectorDot {
|
|
8
|
+
asProvider(chainId: DotNetworkId): ProviderInterface;
|
|
9
|
+
send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
|
|
10
|
+
expectErrors?: boolean;
|
|
11
|
+
}): Promise<T>;
|
|
12
|
+
subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
13
|
+
reset(chainId: DotNetworkId): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class ChainConnectionError extends Error {
|
|
17
|
+
type: "CHAIN_CONNECTION_ERROR";
|
|
18
|
+
chainId: string;
|
|
19
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
declare class StaleRpcError extends Error {
|
|
22
|
+
type: "STALE_RPC_ERROR";
|
|
23
|
+
chainId: string;
|
|
24
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
declare class WebsocketAllocationExhaustedError extends Error {
|
|
27
|
+
type: "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR";
|
|
28
|
+
chainId: string;
|
|
29
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ChainConnector provides an interface similar to WsProvider, but with three points of difference:
|
|
33
|
+
*
|
|
34
|
+
* 1. ChainConnector methods all accept a `chainId` instead of an array of RPCs. RPCs are then fetched internally from chaindata.
|
|
35
|
+
* 2. ChainConnector creates only one `WsProvider` per chain and ensures that all downstream requests to a chain share the one socket connection.
|
|
36
|
+
* 3. Subscriptions return a callable `unsubscribe` method instead of an id.
|
|
37
|
+
*
|
|
38
|
+
* Additionally, when run on the clientside of a dapp where `window.talismanSub` is available, instead of spinning up new websocket
|
|
39
|
+
* connections this class will forward all requests through to the wallet backend - where another instance of this class will
|
|
40
|
+
* handle the websocket connections.
|
|
41
|
+
*/
|
|
42
|
+
declare class ChainConnectorDot implements IChainConnectorDot {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(chaindataChainProvider: IChaindataNetworkProvider, connectionMetaDb?: TalismanConnectionMetaDatabase);
|
|
45
|
+
/**
|
|
46
|
+
* Creates a facade over this ChainConnector which conforms to the PJS ProviderInterface
|
|
47
|
+
* @example // Using a chainConnector as a Provider for an ApiPromise
|
|
48
|
+
* const provider = chainConnector.asProvider('polkadot')
|
|
49
|
+
* const api = new ApiPromise({ provider })
|
|
50
|
+
*/
|
|
51
|
+
asProvider(chainId: DotNetworkId): ProviderInterface;
|
|
52
|
+
send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean | undefined, extraOptions?: {
|
|
53
|
+
/**
|
|
54
|
+
* Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
|
|
55
|
+
*
|
|
56
|
+
* 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
|
|
57
|
+
*
|
|
58
|
+
* By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
|
|
59
|
+
* An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
|
|
60
|
+
* to another query or perhaps an empty result.
|
|
61
|
+
*/
|
|
62
|
+
expectErrors?: boolean;
|
|
63
|
+
}): Promise<T>;
|
|
64
|
+
subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
65
|
+
/**
|
|
66
|
+
* Kills current websocket if any
|
|
67
|
+
* Useful after changing rpc order to make sure it's applied for futher requests
|
|
68
|
+
*/
|
|
69
|
+
reset(chainId: DotNetworkId): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Wait for websocket to be ready, but don't wait forever
|
|
72
|
+
*/
|
|
73
|
+
private waitForWs;
|
|
74
|
+
/**
|
|
75
|
+
* Connect to an RPC via chainId
|
|
76
|
+
*
|
|
77
|
+
* The caller must call disconnectChainSocket with the returned SocketUserId once they are finished with it
|
|
78
|
+
*/
|
|
79
|
+
private connectChainSocket;
|
|
80
|
+
private disconnectChainSocket;
|
|
81
|
+
private addSocketUser;
|
|
82
|
+
private removeSocketUser;
|
|
83
|
+
/** continues to generate a random number until it finds one which is not present in the exclude list */
|
|
84
|
+
private getExclusiveRandomId;
|
|
85
|
+
/** generates a random number */
|
|
86
|
+
private getRandomId;
|
|
87
|
+
private getTalismanSub;
|
|
88
|
+
private updateRpcPriority;
|
|
89
|
+
private getEndpoints;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class ChainConnectorDotStub implements IChainConnectorDot {
|
|
93
|
+
#private;
|
|
94
|
+
constructor(network: DotNetwork);
|
|
95
|
+
asProvider(): ProviderInterface;
|
|
96
|
+
send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
|
|
97
|
+
subscribe(_chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
98
|
+
reset(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface IChainConnectorEth {
|
|
102
|
+
getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
|
|
103
|
+
getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
|
|
104
|
+
clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class ChainConnectorEth implements IChainConnectorEth {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
|
|
110
|
+
getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
|
|
111
|
+
getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
|
|
112
|
+
clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare class ChainConnectorEthStub implements IChainConnectorEth {
|
|
116
|
+
#private;
|
|
117
|
+
constructor(network: EthNetwork);
|
|
118
|
+
getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
|
|
119
|
+
getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
|
|
120
|
+
clearRpcProvidersCache(): void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface IChainConnectorSol {
|
|
124
|
+
getConnection: (networkId: SolNetworkId) => Promise<Connection>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare class ChainConnectorSol implements IChainConnectorSol {
|
|
128
|
+
#private;
|
|
129
|
+
constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
|
|
130
|
+
getConnection(networkId: SolNetworkId): Promise<Connection>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class ChainConnectorSolStub implements IChainConnectorSol {
|
|
134
|
+
#private;
|
|
135
|
+
constructor(networkOrConnection: Pick<SolNetwork, "id" | "rpcs"> | Connection);
|
|
136
|
+
getConnection(): Promise<Connection>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, type IChainConnectorDot, type IChainConnectorEth, type IChainConnectorSol, StaleRpcError, WebsocketAllocationExhaustedError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
|
|
2
|
+
import { DotNetworkId, IChaindataNetworkProvider, DotNetwork, EthNetworkId, IChaindataTokenProvider, EthNetwork, SolNetworkId, SolNetwork } from '@talismn/chaindata-provider';
|
|
3
|
+
import { TalismanConnectionMetaDatabase } from '@talismn/connection-meta';
|
|
4
|
+
import { PublicClient, Account, WalletClient } from 'viem';
|
|
5
|
+
import { Connection } from '@solana/web3.js';
|
|
6
|
+
|
|
7
|
+
interface IChainConnectorDot {
|
|
8
|
+
asProvider(chainId: DotNetworkId): ProviderInterface;
|
|
9
|
+
send<T = unknown>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean, extraOptions?: {
|
|
10
|
+
expectErrors?: boolean;
|
|
11
|
+
}): Promise<T>;
|
|
12
|
+
subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
13
|
+
reset(chainId: DotNetworkId): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class ChainConnectionError extends Error {
|
|
17
|
+
type: "CHAIN_CONNECTION_ERROR";
|
|
18
|
+
chainId: string;
|
|
19
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
20
|
+
}
|
|
21
|
+
declare class StaleRpcError extends Error {
|
|
22
|
+
type: "STALE_RPC_ERROR";
|
|
23
|
+
chainId: string;
|
|
24
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
25
|
+
}
|
|
26
|
+
declare class WebsocketAllocationExhaustedError extends Error {
|
|
27
|
+
type: "WEBSOCKET_ALLOCATION_EXHAUSTED_ERROR";
|
|
28
|
+
chainId: string;
|
|
29
|
+
constructor(chainId: string, options?: ErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* ChainConnector provides an interface similar to WsProvider, but with three points of difference:
|
|
33
|
+
*
|
|
34
|
+
* 1. ChainConnector methods all accept a `chainId` instead of an array of RPCs. RPCs are then fetched internally from chaindata.
|
|
35
|
+
* 2. ChainConnector creates only one `WsProvider` per chain and ensures that all downstream requests to a chain share the one socket connection.
|
|
36
|
+
* 3. Subscriptions return a callable `unsubscribe` method instead of an id.
|
|
37
|
+
*
|
|
38
|
+
* Additionally, when run on the clientside of a dapp where `window.talismanSub` is available, instead of spinning up new websocket
|
|
39
|
+
* connections this class will forward all requests through to the wallet backend - where another instance of this class will
|
|
40
|
+
* handle the websocket connections.
|
|
41
|
+
*/
|
|
42
|
+
declare class ChainConnectorDot implements IChainConnectorDot {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(chaindataChainProvider: IChaindataNetworkProvider, connectionMetaDb?: TalismanConnectionMetaDatabase);
|
|
45
|
+
/**
|
|
46
|
+
* Creates a facade over this ChainConnector which conforms to the PJS ProviderInterface
|
|
47
|
+
* @example // Using a chainConnector as a Provider for an ApiPromise
|
|
48
|
+
* const provider = chainConnector.asProvider('polkadot')
|
|
49
|
+
* const api = new ApiPromise({ provider })
|
|
50
|
+
*/
|
|
51
|
+
asProvider(chainId: DotNetworkId): ProviderInterface;
|
|
52
|
+
send<T = any>(chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean | undefined, extraOptions?: {
|
|
53
|
+
/**
|
|
54
|
+
* Set to `true` if this query is speculative, i.e. if on some chains it's expected that it will raise a wasm unreachable error of the form:
|
|
55
|
+
*
|
|
56
|
+
* 4003: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
|
|
57
|
+
*
|
|
58
|
+
* By setting expectErrors to true, this method won't pollute the logs with errors we intend to have happen.
|
|
59
|
+
* An example use case of this is when you plan to catch the wasm unreachable error on chains that don't support the query, and then fall back
|
|
60
|
+
* to another query or perhaps an empty result.
|
|
61
|
+
*/
|
|
62
|
+
expectErrors?: boolean;
|
|
63
|
+
}): Promise<T>;
|
|
64
|
+
subscribe(chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
65
|
+
/**
|
|
66
|
+
* Kills current websocket if any
|
|
67
|
+
* Useful after changing rpc order to make sure it's applied for futher requests
|
|
68
|
+
*/
|
|
69
|
+
reset(chainId: DotNetworkId): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Wait for websocket to be ready, but don't wait forever
|
|
72
|
+
*/
|
|
73
|
+
private waitForWs;
|
|
74
|
+
/**
|
|
75
|
+
* Connect to an RPC via chainId
|
|
76
|
+
*
|
|
77
|
+
* The caller must call disconnectChainSocket with the returned SocketUserId once they are finished with it
|
|
78
|
+
*/
|
|
79
|
+
private connectChainSocket;
|
|
80
|
+
private disconnectChainSocket;
|
|
81
|
+
private addSocketUser;
|
|
82
|
+
private removeSocketUser;
|
|
83
|
+
/** continues to generate a random number until it finds one which is not present in the exclude list */
|
|
84
|
+
private getExclusiveRandomId;
|
|
85
|
+
/** generates a random number */
|
|
86
|
+
private getRandomId;
|
|
87
|
+
private getTalismanSub;
|
|
88
|
+
private updateRpcPriority;
|
|
89
|
+
private getEndpoints;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
declare class ChainConnectorDotStub implements IChainConnectorDot {
|
|
93
|
+
#private;
|
|
94
|
+
constructor(network: DotNetwork);
|
|
95
|
+
asProvider(): ProviderInterface;
|
|
96
|
+
send<T = unknown>(_chainId: DotNetworkId, method: string, params: unknown[], isCacheable?: boolean): Promise<T>;
|
|
97
|
+
subscribe(_chainId: DotNetworkId, subscribeMethod: string, responseMethod: string, params: unknown[], callback: ProviderInterfaceCallback, timeout?: number | false): Promise<(unsubscribeMethod: string) => void>;
|
|
98
|
+
reset(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
interface IChainConnectorEth {
|
|
102
|
+
getPublicClientForEvmNetwork: (evmNetworkId: EthNetworkId) => Promise<PublicClient | null>;
|
|
103
|
+
getWalletClientForEvmNetwork: (evmNetworkId: EthNetworkId, account?: `0x${string}` | Account) => Promise<WalletClient | null>;
|
|
104
|
+
clearRpcProvidersCache: (evmNetworkId?: EthNetworkId) => void;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare class ChainConnectorEth implements IChainConnectorEth {
|
|
108
|
+
#private;
|
|
109
|
+
constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
|
|
110
|
+
getPublicClientForEvmNetwork(evmNetworkId: EthNetworkId): Promise<PublicClient | null>;
|
|
111
|
+
getWalletClientForEvmNetwork(evmNetworkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
|
|
112
|
+
clearRpcProvidersCache(evmNetworkId?: EthNetworkId): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare class ChainConnectorEthStub implements IChainConnectorEth {
|
|
116
|
+
#private;
|
|
117
|
+
constructor(network: EthNetwork);
|
|
118
|
+
getPublicClientForEvmNetwork(): Promise<PublicClient | null>;
|
|
119
|
+
getWalletClientForEvmNetwork(_networkId: EthNetworkId, account?: `0x${string}` | Account): Promise<WalletClient | null>;
|
|
120
|
+
clearRpcProvidersCache(): void;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface IChainConnectorSol {
|
|
124
|
+
getConnection: (networkId: SolNetworkId) => Promise<Connection>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
declare class ChainConnectorSol implements IChainConnectorSol {
|
|
128
|
+
#private;
|
|
129
|
+
constructor(chaindataProvider: IChaindataNetworkProvider & IChaindataTokenProvider);
|
|
130
|
+
getConnection(networkId: SolNetworkId): Promise<Connection>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
declare class ChainConnectorSolStub implements IChainConnectorSol {
|
|
134
|
+
#private;
|
|
135
|
+
constructor(networkOrConnection: Pick<SolNetwork, "id" | "rpcs"> | Connection);
|
|
136
|
+
getConnection(): Promise<Connection>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { ChainConnectionError, ChainConnectorDot, ChainConnectorDotStub, ChainConnectorEth, ChainConnectorEthStub, ChainConnectorSol, ChainConnectorSolStub, type IChainConnectorDot, type IChainConnectorEth, type IChainConnectorSol, StaleRpcError, WebsocketAllocationExhaustedError };
|