@gearbox-protocol/sdk 4.0.2 → 4.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.
- package/dist/cjs/dev/createTransport.js +63 -0
- package/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +23 -10
- package/dist/esm/dev/createTransport.js +36 -0
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/sdk/chain/chains.js +23 -10
- package/dist/types/dev/createTransport.d.ts +18 -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 } = 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) : (0, import_viem.webSocket)(url)
|
|
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
|
),
|
|
@@ -203,11 +211,15 @@ const chains = {
|
|
|
203
211
|
defaultMarketConfigurators: {
|
|
204
212
|
"0x5BCF14d8470e1a6110916371aacC8E1C947A7D9d": "Chaos Labs"
|
|
205
213
|
},
|
|
214
|
+
testMarketConfigurators: {
|
|
215
|
+
"0x537F5F2032e75Fa586E48ad635DF6f79c06205b9": "Chaos Labs"
|
|
216
|
+
},
|
|
206
217
|
isPublic: false,
|
|
207
218
|
wellKnownToken: {
|
|
208
219
|
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
209
220
|
symbol: "USDC"
|
|
210
|
-
}
|
|
221
|
+
},
|
|
222
|
+
alchemyDomain: "bnb-mainnet"
|
|
211
223
|
},
|
|
212
224
|
"bsc-rpc"
|
|
213
225
|
),
|
|
@@ -219,7 +231,8 @@ const chains = {
|
|
|
219
231
|
wellKnownToken: {
|
|
220
232
|
address: "0x79a02482a880bce3f13e09da970dc34db4cd24d1",
|
|
221
233
|
symbol: "USDC.e"
|
|
222
|
-
}
|
|
234
|
+
},
|
|
235
|
+
alchemyDomain: "worldchain-mainnet"
|
|
223
236
|
// TODO: has no block explorer API
|
|
224
237
|
})
|
|
225
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 } = 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) : webSocket(url)
|
|
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
|
),
|
|
@@ -186,11 +194,15 @@ const chains = {
|
|
|
186
194
|
defaultMarketConfigurators: {
|
|
187
195
|
"0x5BCF14d8470e1a6110916371aacC8E1C947A7D9d": "Chaos Labs"
|
|
188
196
|
},
|
|
197
|
+
testMarketConfigurators: {
|
|
198
|
+
"0x537F5F2032e75Fa586E48ad635DF6f79c06205b9": "Chaos Labs"
|
|
199
|
+
},
|
|
189
200
|
isPublic: false,
|
|
190
201
|
wellKnownToken: {
|
|
191
202
|
address: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
|
|
192
203
|
symbol: "USDC"
|
|
193
|
-
}
|
|
204
|
+
},
|
|
205
|
+
alchemyDomain: "bnb-mainnet"
|
|
194
206
|
},
|
|
195
207
|
"bsc-rpc"
|
|
196
208
|
),
|
|
@@ -202,7 +214,8 @@ const chains = {
|
|
|
202
214
|
wellKnownToken: {
|
|
203
215
|
address: "0x79a02482a880bce3f13e09da970dc34db4cd24d1",
|
|
204
216
|
symbol: "USDC.e"
|
|
205
|
-
}
|
|
217
|
+
},
|
|
218
|
+
alchemyDomain: "worldchain-mainnet"
|
|
206
219
|
// TODO: has no block explorer API
|
|
207
220
|
})
|
|
208
221
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Transport } from "viem";
|
|
2
|
+
import { type NetworkType } from "../sdk/index.js";
|
|
3
|
+
export interface CreateTransportConfig {
|
|
4
|
+
rpcUrls: string[];
|
|
5
|
+
alchemyKeys: string[];
|
|
6
|
+
protocol: "http" | "ws";
|
|
7
|
+
network: NetworkType;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Helper method to create viem Transport using API keys of well-known RPC providers and explicit fallback URLs
|
|
11
|
+
* Currently only supports Alchemy
|
|
12
|
+
* @param config
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function createTransport(config: CreateTransportConfig): Transport;
|
|
16
|
+
export declare function getAlchemyUrl(domain: string, apiKey: string, protocol: "http" | "ws"): string;
|
|
17
|
+
export declare function getAlchemyHttpUrl(domain: string, apiKey: string): string;
|
|
18
|
+
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"]>;
|