@gearbox-protocol/sdk 4.0.3 → 4.1.1
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/cjs/dev/createTransport.js +63 -0
- package/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +20 -10
- package/dist/esm/dev/createTransport.js +36 -0
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/sdk/chain/chains.js +20 -10
- package/dist/types/dev/createTransport.d.ts +24 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/sdk/chain/chains.d.ts +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createTransport_exports = {};
|
|
20
|
+
__export(createTransport_exports, {
|
|
21
|
+
createTransport: () => createTransport,
|
|
22
|
+
getAlchemyHttpUrl: () => getAlchemyHttpUrl,
|
|
23
|
+
getAlchemyUrl: () => getAlchemyUrl,
|
|
24
|
+
getAlchemyWsUrl: () => getAlchemyWsUrl
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(createTransport_exports);
|
|
27
|
+
var import_viem = require("viem");
|
|
28
|
+
var import_sdk = require("../sdk/index.js");
|
|
29
|
+
function createTransport(config) {
|
|
30
|
+
const { alchemyKeys, protocol, network, ...rest } = config;
|
|
31
|
+
const rpcUrls = config.rpcUrls.filter((url) => {
|
|
32
|
+
return url.startsWith(protocol) && !alchemyKeys.some((key) => url.includes(key));
|
|
33
|
+
});
|
|
34
|
+
const { alchemyDomain } = (0, import_sdk.getChain)(network);
|
|
35
|
+
if (alchemyDomain) {
|
|
36
|
+
rpcUrls.unshift(
|
|
37
|
+
...alchemyKeys.map((key) => getAlchemyUrl(alchemyDomain, key, protocol))
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
const transports = rpcUrls.map(
|
|
41
|
+
(url) => protocol === "http" ? (0, import_viem.http)(url, rest) : (0, import_viem.webSocket)(url, rest)
|
|
42
|
+
);
|
|
43
|
+
if (transports.length === 0) {
|
|
44
|
+
throw new Error("no fitting rpc urls found");
|
|
45
|
+
}
|
|
46
|
+
return transports.length > 1 ? (0, import_viem.fallback)(transports) : transports[0];
|
|
47
|
+
}
|
|
48
|
+
function getAlchemyUrl(domain, apiKey, protocol) {
|
|
49
|
+
return protocol === "http" ? getAlchemyHttpUrl(domain, apiKey) : getAlchemyWsUrl(domain, apiKey);
|
|
50
|
+
}
|
|
51
|
+
function getAlchemyHttpUrl(domain, apiKey) {
|
|
52
|
+
return `https://${domain}.g.alchemy.com/v2/${apiKey}`;
|
|
53
|
+
}
|
|
54
|
+
function getAlchemyWsUrl(domain, apiKey) {
|
|
55
|
+
return `wss://${domain}.g.alchemy.com/v2/${apiKey}`;
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
createTransport,
|
|
60
|
+
getAlchemyHttpUrl,
|
|
61
|
+
getAlchemyUrl,
|
|
62
|
+
getAlchemyWsUrl
|
|
63
|
+
});
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __reExport(dev_exports, require("./AccountOpener.js"), module.exports);
|
|
|
19
19
|
__reExport(dev_exports, require("./calcLiquidatableLTs.js"), module.exports);
|
|
20
20
|
__reExport(dev_exports, require("./create2.js"), module.exports);
|
|
21
21
|
__reExport(dev_exports, require("./createAnvilClient.js"), module.exports);
|
|
22
|
+
__reExport(dev_exports, require("./createTransport.js"), module.exports);
|
|
22
23
|
__reExport(dev_exports, require("./detectChain.js"), module.exports);
|
|
23
24
|
__reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
|
|
24
25
|
__reExport(dev_exports, require("./PriceFeedStore.js"), module.exports);
|
|
@@ -30,6 +31,7 @@ __reExport(dev_exports, require("./setLTZero.js"), module.exports);
|
|
|
30
31
|
...require("./calcLiquidatableLTs.js"),
|
|
31
32
|
...require("./create2.js"),
|
|
32
33
|
...require("./createAnvilClient.js"),
|
|
34
|
+
...require("./createTransport.js"),
|
|
33
35
|
...require("./detectChain.js"),
|
|
34
36
|
...require("./migrateFaucet.js"),
|
|
35
37
|
...require("./PriceFeedStore.js"),
|
|
@@ -70,7 +70,8 @@ const chains = {
|
|
|
70
70
|
wellKnownToken: {
|
|
71
71
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
72
72
|
symbol: "USDC"
|
|
73
|
-
}
|
|
73
|
+
},
|
|
74
|
+
alchemyDomain: "eth-mainnet"
|
|
74
75
|
},
|
|
75
76
|
"ethereum-rpc"
|
|
76
77
|
),
|
|
@@ -85,7 +86,8 @@ const chains = {
|
|
|
85
86
|
wellKnownToken: {
|
|
86
87
|
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
87
88
|
symbol: "USDC"
|
|
88
|
-
}
|
|
89
|
+
},
|
|
90
|
+
alchemyDomain: "arb-mainnet"
|
|
89
91
|
},
|
|
90
92
|
"arbitrum-one-rpc"
|
|
91
93
|
),
|
|
@@ -100,7 +102,8 @@ const chains = {
|
|
|
100
102
|
wellKnownToken: {
|
|
101
103
|
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
102
104
|
symbol: "USDC"
|
|
103
|
-
}
|
|
105
|
+
},
|
|
106
|
+
alchemyDomain: "opt-mainnet"
|
|
104
107
|
},
|
|
105
108
|
"optimism-rpc"
|
|
106
109
|
),
|
|
@@ -113,7 +116,8 @@ const chains = {
|
|
|
113
116
|
wellKnownToken: {
|
|
114
117
|
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
115
118
|
symbol: "USDC"
|
|
116
|
-
}
|
|
119
|
+
},
|
|
120
|
+
alchemyDomain: "base-mainnet"
|
|
117
121
|
},
|
|
118
122
|
"base-rpc"
|
|
119
123
|
),
|
|
@@ -135,7 +139,8 @@ const chains = {
|
|
|
135
139
|
wellKnownToken: {
|
|
136
140
|
address: "0x29219dd400f2Bf60E5a23d13Be72B486D4038894",
|
|
137
141
|
symbol: "USDC.e"
|
|
138
|
-
}
|
|
142
|
+
},
|
|
143
|
+
alchemyDomain: "sonic-mainnet"
|
|
139
144
|
}),
|
|
140
145
|
"sonic-rpc"
|
|
141
146
|
),
|
|
@@ -160,8 +165,9 @@ const chains = {
|
|
|
160
165
|
wellKnownToken: {
|
|
161
166
|
address: "0xf817257fed379853cDe0fa4F97AB987181B1E5Ea",
|
|
162
167
|
symbol: "USDC"
|
|
163
|
-
}
|
|
168
|
+
},
|
|
164
169
|
// TODO: has no block explorer API
|
|
170
|
+
alchemyDomain: "monad-testnet"
|
|
165
171
|
}),
|
|
166
172
|
Berachain: withPublicNode(
|
|
167
173
|
{
|
|
@@ -179,7 +185,8 @@ const chains = {
|
|
|
179
185
|
wellKnownToken: {
|
|
180
186
|
address: "0x549943e04f40284185054145c6e4e9568c1d3241",
|
|
181
187
|
symbol: "USDC.e"
|
|
182
|
-
}
|
|
188
|
+
},
|
|
189
|
+
alchemyDomain: "berachain-mainnet"
|
|
183
190
|
},
|
|
184
191
|
"berachain-rpc"
|
|
185
192
|
),
|
|
@@ -192,7 +199,8 @@ const chains = {
|
|
|
192
199
|
wellKnownToken: {
|
|
193
200
|
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
194
201
|
symbol: "USDC"
|
|
195
|
-
}
|
|
202
|
+
},
|
|
203
|
+
alchemyDomain: "avax-mainnet"
|
|
196
204
|
},
|
|
197
205
|
"avalanche-c-chain-rpc"
|
|
198
206
|
),
|
|
@@ -210,7 +218,8 @@ const chains = {
|
|
|
210
218
|
wellKnownToken: {
|
|
211
219
|
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
212
220
|
symbol: "USDC"
|
|
213
|
-
}
|
|
221
|
+
},
|
|
222
|
+
alchemyDomain: "bnb-mainnet"
|
|
214
223
|
},
|
|
215
224
|
"bsc-rpc"
|
|
216
225
|
),
|
|
@@ -222,7 +231,8 @@ const chains = {
|
|
|
222
231
|
wellKnownToken: {
|
|
223
232
|
address: "0x79a02482a880bce3f13e09da970dc34db4cd24d1",
|
|
224
233
|
symbol: "USDC.e"
|
|
225
|
-
}
|
|
234
|
+
},
|
|
235
|
+
alchemyDomain: "worldchain-mainnet"
|
|
226
236
|
// TODO: has no block explorer API
|
|
227
237
|
})
|
|
228
238
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { fallback, http, webSocket } from "viem";
|
|
2
|
+
import { getChain } from "../sdk/index.js";
|
|
3
|
+
function createTransport(config) {
|
|
4
|
+
const { alchemyKeys, protocol, network, ...rest } = config;
|
|
5
|
+
const rpcUrls = config.rpcUrls.filter((url) => {
|
|
6
|
+
return url.startsWith(protocol) && !alchemyKeys.some((key) => url.includes(key));
|
|
7
|
+
});
|
|
8
|
+
const { alchemyDomain } = getChain(network);
|
|
9
|
+
if (alchemyDomain) {
|
|
10
|
+
rpcUrls.unshift(
|
|
11
|
+
...alchemyKeys.map((key) => getAlchemyUrl(alchemyDomain, key, protocol))
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const transports = rpcUrls.map(
|
|
15
|
+
(url) => protocol === "http" ? http(url, rest) : webSocket(url, rest)
|
|
16
|
+
);
|
|
17
|
+
if (transports.length === 0) {
|
|
18
|
+
throw new Error("no fitting rpc urls found");
|
|
19
|
+
}
|
|
20
|
+
return transports.length > 1 ? fallback(transports) : transports[0];
|
|
21
|
+
}
|
|
22
|
+
function getAlchemyUrl(domain, apiKey, protocol) {
|
|
23
|
+
return protocol === "http" ? getAlchemyHttpUrl(domain, apiKey) : getAlchemyWsUrl(domain, apiKey);
|
|
24
|
+
}
|
|
25
|
+
function getAlchemyHttpUrl(domain, apiKey) {
|
|
26
|
+
return `https://${domain}.g.alchemy.com/v2/${apiKey}`;
|
|
27
|
+
}
|
|
28
|
+
function getAlchemyWsUrl(domain, apiKey) {
|
|
29
|
+
return `wss://${domain}.g.alchemy.com/v2/${apiKey}`;
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
createTransport,
|
|
33
|
+
getAlchemyHttpUrl,
|
|
34
|
+
getAlchemyUrl,
|
|
35
|
+
getAlchemyWsUrl
|
|
36
|
+
};
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./AccountOpener.js";
|
|
|
2
2
|
export * from "./calcLiquidatableLTs.js";
|
|
3
3
|
export * from "./create2.js";
|
|
4
4
|
export * from "./createAnvilClient.js";
|
|
5
|
+
export * from "./createTransport.js";
|
|
5
6
|
export * from "./detectChain.js";
|
|
6
7
|
export * from "./migrateFaucet.js";
|
|
7
8
|
export * from "./PriceFeedStore.js";
|
|
@@ -53,7 +53,8 @@ const chains = {
|
|
|
53
53
|
wellKnownToken: {
|
|
54
54
|
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
55
55
|
symbol: "USDC"
|
|
56
|
-
}
|
|
56
|
+
},
|
|
57
|
+
alchemyDomain: "eth-mainnet"
|
|
57
58
|
},
|
|
58
59
|
"ethereum-rpc"
|
|
59
60
|
),
|
|
@@ -68,7 +69,8 @@ const chains = {
|
|
|
68
69
|
wellKnownToken: {
|
|
69
70
|
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
70
71
|
symbol: "USDC"
|
|
71
|
-
}
|
|
72
|
+
},
|
|
73
|
+
alchemyDomain: "arb-mainnet"
|
|
72
74
|
},
|
|
73
75
|
"arbitrum-one-rpc"
|
|
74
76
|
),
|
|
@@ -83,7 +85,8 @@ const chains = {
|
|
|
83
85
|
wellKnownToken: {
|
|
84
86
|
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
85
87
|
symbol: "USDC"
|
|
86
|
-
}
|
|
88
|
+
},
|
|
89
|
+
alchemyDomain: "opt-mainnet"
|
|
87
90
|
},
|
|
88
91
|
"optimism-rpc"
|
|
89
92
|
),
|
|
@@ -96,7 +99,8 @@ const chains = {
|
|
|
96
99
|
wellKnownToken: {
|
|
97
100
|
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
98
101
|
symbol: "USDC"
|
|
99
|
-
}
|
|
102
|
+
},
|
|
103
|
+
alchemyDomain: "base-mainnet"
|
|
100
104
|
},
|
|
101
105
|
"base-rpc"
|
|
102
106
|
),
|
|
@@ -118,7 +122,8 @@ const chains = {
|
|
|
118
122
|
wellKnownToken: {
|
|
119
123
|
address: "0x29219dd400f2Bf60E5a23d13Be72B486D4038894",
|
|
120
124
|
symbol: "USDC.e"
|
|
121
|
-
}
|
|
125
|
+
},
|
|
126
|
+
alchemyDomain: "sonic-mainnet"
|
|
122
127
|
}),
|
|
123
128
|
"sonic-rpc"
|
|
124
129
|
),
|
|
@@ -143,8 +148,9 @@ const chains = {
|
|
|
143
148
|
wellKnownToken: {
|
|
144
149
|
address: "0xf817257fed379853cDe0fa4F97AB987181B1E5Ea",
|
|
145
150
|
symbol: "USDC"
|
|
146
|
-
}
|
|
151
|
+
},
|
|
147
152
|
// TODO: has no block explorer API
|
|
153
|
+
alchemyDomain: "monad-testnet"
|
|
148
154
|
}),
|
|
149
155
|
Berachain: withPublicNode(
|
|
150
156
|
{
|
|
@@ -162,7 +168,8 @@ const chains = {
|
|
|
162
168
|
wellKnownToken: {
|
|
163
169
|
address: "0x549943e04f40284185054145c6e4e9568c1d3241",
|
|
164
170
|
symbol: "USDC.e"
|
|
165
|
-
}
|
|
171
|
+
},
|
|
172
|
+
alchemyDomain: "berachain-mainnet"
|
|
166
173
|
},
|
|
167
174
|
"berachain-rpc"
|
|
168
175
|
),
|
|
@@ -175,7 +182,8 @@ const chains = {
|
|
|
175
182
|
wellKnownToken: {
|
|
176
183
|
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
177
184
|
symbol: "USDC"
|
|
178
|
-
}
|
|
185
|
+
},
|
|
186
|
+
alchemyDomain: "avax-mainnet"
|
|
179
187
|
},
|
|
180
188
|
"avalanche-c-chain-rpc"
|
|
181
189
|
),
|
|
@@ -193,7 +201,8 @@ const chains = {
|
|
|
193
201
|
wellKnownToken: {
|
|
194
202
|
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
195
203
|
symbol: "USDC"
|
|
196
|
-
}
|
|
204
|
+
},
|
|
205
|
+
alchemyDomain: "bnb-mainnet"
|
|
197
206
|
},
|
|
198
207
|
"bsc-rpc"
|
|
199
208
|
),
|
|
@@ -205,7 +214,8 @@ const chains = {
|
|
|
205
214
|
wellKnownToken: {
|
|
206
215
|
address: "0x79a02482a880bce3f13e09da970dc34db4cd24d1",
|
|
207
216
|
symbol: "USDC.e"
|
|
208
|
-
}
|
|
217
|
+
},
|
|
218
|
+
alchemyDomain: "worldchain-mainnet"
|
|
209
219
|
// TODO: has no block explorer API
|
|
210
220
|
})
|
|
211
221
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpTransportConfig, Transport, WebSocketTransportConfig } from "viem";
|
|
2
|
+
import type { NetworkType } from "../sdk/index.js";
|
|
3
|
+
export interface CreateTransportURLOptions {
|
|
4
|
+
rpcUrls: string[];
|
|
5
|
+
alchemyKeys: string[];
|
|
6
|
+
network: NetworkType;
|
|
7
|
+
}
|
|
8
|
+
export type CreateHTTPTransportConfig = {
|
|
9
|
+
protocol: "http";
|
|
10
|
+
} & HttpTransportConfig & CreateTransportURLOptions;
|
|
11
|
+
export type CreateWSTransportConfig = {
|
|
12
|
+
protocol: "ws";
|
|
13
|
+
} & WebSocketTransportConfig & CreateTransportURLOptions;
|
|
14
|
+
export type CreateTransportConfig = CreateHTTPTransportConfig | CreateWSTransportConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Helper method to create viem Transport using API keys of well-known RPC providers and explicit fallback URLs
|
|
17
|
+
* Currently only supports Alchemy
|
|
18
|
+
* @param config
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
export declare function createTransport(config: CreateTransportConfig): Transport;
|
|
22
|
+
export declare function getAlchemyUrl(domain: string, apiKey: string, protocol: "http" | "ws"): string;
|
|
23
|
+
export declare function getAlchemyHttpUrl(domain: string, apiKey: string): string;
|
|
24
|
+
export declare function getAlchemyWsUrl(domain: string, apiKey: string): string;
|
|
@@ -2,6 +2,7 @@ export * from "./AccountOpener.js";
|
|
|
2
2
|
export * from "./calcLiquidatableLTs.js";
|
|
3
3
|
export * from "./create2.js";
|
|
4
4
|
export * from "./createAnvilClient.js";
|
|
5
|
+
export * from "./createTransport.js";
|
|
5
6
|
export * from "./detectChain.js";
|
|
6
7
|
export * from "./migrateFaucet.js";
|
|
7
8
|
export * from "./PriceFeedStore.js";
|
|
@@ -18,6 +18,10 @@ export interface GearboxChain extends Chain {
|
|
|
18
18
|
address: Address;
|
|
19
19
|
symbol: string;
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Alchemy subdomain to construct provider URL
|
|
23
|
+
*/
|
|
24
|
+
alchemyDomain?: string;
|
|
21
25
|
}
|
|
22
26
|
export declare const SUPPORTED_NETWORKS: readonly ["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"];
|
|
23
27
|
export declare const NetworkType: z.ZodEnum<["Mainnet", "Arbitrum", "Optimism", "Base", "Sonic", "MegaETH", "Monad", "Berachain", "Avalanche", "BNB", "WorldChain"]>;
|