@gearbox-protocol/sdk 7.0.0 → 7.1.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.
|
@@ -19,23 +19,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var createTransport_exports = {};
|
|
20
20
|
__export(createTransport_exports, {
|
|
21
21
|
createTransport: () => createTransport,
|
|
22
|
-
getAlchemyHttpUrl: () => getAlchemyHttpUrl,
|
|
23
22
|
getAlchemyUrl: () => getAlchemyUrl,
|
|
24
|
-
|
|
23
|
+
getDrpcUrl: () => getDrpcUrl,
|
|
24
|
+
getProviderUrl: () => getProviderUrl
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(createTransport_exports);
|
|
27
27
|
var import_viem = require("viem");
|
|
28
28
|
var import_sdk = require("../sdk/index.js");
|
|
29
29
|
function createTransport(config) {
|
|
30
|
-
const {
|
|
30
|
+
const { rpcProviders = [], protocol, network, ...rest } = config;
|
|
31
|
+
const allKeys = rpcProviders.flatMap((provider) => provider.keys) ?? [];
|
|
31
32
|
const rpcUrls = config.rpcUrls.filter((url) => {
|
|
32
|
-
return url.startsWith(protocol) && !
|
|
33
|
+
return url.startsWith(protocol) && !allKeys.some((key) => url.includes(key));
|
|
33
34
|
});
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
for (const { provider, keys } of rpcProviders) {
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
const url = getProviderUrl(provider, network, key, protocol);
|
|
38
|
+
if (url) {
|
|
39
|
+
rpcUrls.push(url);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
const transports = rpcUrls.map(
|
|
41
44
|
(url) => protocol === "http" ? (0, import_viem.http)(url, rest) : (0, import_viem.webSocket)(url, rest)
|
|
@@ -45,19 +48,42 @@ function createTransport(config) {
|
|
|
45
48
|
}
|
|
46
49
|
return transports.length > 1 ? (0, import_viem.fallback)(transports) : transports[0];
|
|
47
50
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
51
|
+
function getProviderUrl(provider, network, apiKey, protocol) {
|
|
52
|
+
switch (provider) {
|
|
53
|
+
case "alchemy":
|
|
54
|
+
return getAlchemyUrl(network, apiKey, protocol);
|
|
55
|
+
case "drpc":
|
|
56
|
+
return getDrpcUrl(network, apiKey, protocol);
|
|
57
|
+
}
|
|
50
58
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
59
|
+
function getAlchemyUrl(network, apiKey, protocol) {
|
|
60
|
+
const { alchemyDomain } = (0, import_sdk.getChain)(network);
|
|
61
|
+
if (!alchemyDomain) {
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
return `${protocol}s://${alchemyDomain}.g.alchemy.com/v2/${apiKey}`;
|
|
53
65
|
}
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
const DRPC_NETS = {
|
|
67
|
+
Arbitrum: "arbitrum",
|
|
68
|
+
Base: "base",
|
|
69
|
+
BNB: "bsc",
|
|
70
|
+
Mainnet: "ethereum",
|
|
71
|
+
Optimism: "optimism",
|
|
72
|
+
Sonic: "sonic",
|
|
73
|
+
WorldChain: "worldchain",
|
|
74
|
+
Berachain: "berachain",
|
|
75
|
+
Avalanche: "avalanche",
|
|
76
|
+
Monad: "monad-testnet",
|
|
77
|
+
MegaETH: ""
|
|
78
|
+
};
|
|
79
|
+
function getDrpcUrl(network, apiKey, protocol) {
|
|
80
|
+
const net = DRPC_NETS[network];
|
|
81
|
+
return net ? `${protocol}s://lb.drpc.org/ogws?network=${net}&dkey=${apiKey}` : void 0;
|
|
56
82
|
}
|
|
57
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
84
|
0 && (module.exports = {
|
|
59
85
|
createTransport,
|
|
60
|
-
getAlchemyHttpUrl,
|
|
61
86
|
getAlchemyUrl,
|
|
62
|
-
|
|
87
|
+
getDrpcUrl,
|
|
88
|
+
getProviderUrl
|
|
63
89
|
});
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { fallback, http, webSocket } from "viem";
|
|
2
2
|
import { getChain } from "../sdk/index.js";
|
|
3
3
|
function createTransport(config) {
|
|
4
|
-
const {
|
|
4
|
+
const { rpcProviders = [], protocol, network, ...rest } = config;
|
|
5
|
+
const allKeys = rpcProviders.flatMap((provider) => provider.keys) ?? [];
|
|
5
6
|
const rpcUrls = config.rpcUrls.filter((url) => {
|
|
6
|
-
return url.startsWith(protocol) && !
|
|
7
|
+
return url.startsWith(protocol) && !allKeys.some((key) => url.includes(key));
|
|
7
8
|
});
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
for (const { provider, keys } of rpcProviders) {
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
const url = getProviderUrl(provider, network, key, protocol);
|
|
12
|
+
if (url) {
|
|
13
|
+
rpcUrls.push(url);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
13
16
|
}
|
|
14
17
|
const transports = rpcUrls.map(
|
|
15
18
|
(url) => protocol === "http" ? http(url, rest) : webSocket(url, rest)
|
|
@@ -19,18 +22,41 @@ function createTransport(config) {
|
|
|
19
22
|
}
|
|
20
23
|
return transports.length > 1 ? fallback(transports) : transports[0];
|
|
21
24
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
25
|
+
function getProviderUrl(provider, network, apiKey, protocol) {
|
|
26
|
+
switch (provider) {
|
|
27
|
+
case "alchemy":
|
|
28
|
+
return getAlchemyUrl(network, apiKey, protocol);
|
|
29
|
+
case "drpc":
|
|
30
|
+
return getDrpcUrl(network, apiKey, protocol);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
33
|
+
function getAlchemyUrl(network, apiKey, protocol) {
|
|
34
|
+
const { alchemyDomain } = getChain(network);
|
|
35
|
+
if (!alchemyDomain) {
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
return `${protocol}s://${alchemyDomain}.g.alchemy.com/v2/${apiKey}`;
|
|
27
39
|
}
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const DRPC_NETS = {
|
|
41
|
+
Arbitrum: "arbitrum",
|
|
42
|
+
Base: "base",
|
|
43
|
+
BNB: "bsc",
|
|
44
|
+
Mainnet: "ethereum",
|
|
45
|
+
Optimism: "optimism",
|
|
46
|
+
Sonic: "sonic",
|
|
47
|
+
WorldChain: "worldchain",
|
|
48
|
+
Berachain: "berachain",
|
|
49
|
+
Avalanche: "avalanche",
|
|
50
|
+
Monad: "monad-testnet",
|
|
51
|
+
MegaETH: ""
|
|
52
|
+
};
|
|
53
|
+
function getDrpcUrl(network, apiKey, protocol) {
|
|
54
|
+
const net = DRPC_NETS[network];
|
|
55
|
+
return net ? `${protocol}s://lb.drpc.org/ogws?network=${net}&dkey=${apiKey}` : void 0;
|
|
30
56
|
}
|
|
31
57
|
export {
|
|
32
58
|
createTransport,
|
|
33
|
-
getAlchemyHttpUrl,
|
|
34
59
|
getAlchemyUrl,
|
|
35
|
-
|
|
60
|
+
getDrpcUrl,
|
|
61
|
+
getProviderUrl
|
|
36
62
|
};
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { HttpTransportConfig, Transport, WebSocketTransportConfig } from "viem";
|
|
2
2
|
import type { NetworkType } from "../sdk/index.js";
|
|
3
|
+
export type RpcProvider = "alchemy" | "drpc";
|
|
4
|
+
export interface ProviderConfig {
|
|
5
|
+
provider: RpcProvider;
|
|
6
|
+
keys: string[];
|
|
7
|
+
}
|
|
3
8
|
export interface CreateTransportURLOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Explicitly provided RPC URLs, like anvil
|
|
11
|
+
* Have highest priority
|
|
12
|
+
*/
|
|
4
13
|
rpcUrls: string[];
|
|
5
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Known providers, first has highest priority
|
|
16
|
+
*/
|
|
17
|
+
rpcProviders?: ProviderConfig[];
|
|
6
18
|
network: NetworkType;
|
|
7
19
|
}
|
|
8
20
|
export type CreateHTTPTransportConfig = {
|
|
@@ -19,6 +31,6 @@ export type CreateTransportConfig = CreateHTTPTransportConfig | CreateWSTranspor
|
|
|
19
31
|
* @returns
|
|
20
32
|
*/
|
|
21
33
|
export declare function createTransport(config: CreateTransportConfig): Transport;
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
34
|
+
export declare function getProviderUrl(provider: RpcProvider, network: NetworkType, apiKey: string, protocol: "http" | "ws"): string | undefined;
|
|
35
|
+
export declare function getAlchemyUrl(network: NetworkType, apiKey: string, protocol: "http" | "ws"): string | undefined;
|
|
36
|
+
export declare function getDrpcUrl(network: NetworkType, apiKey: string, protocol: "http" | "ws"): string | undefined;
|