@gearbox-protocol/sdk 11.1.6 → 11.2.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/permissionless/bindings/bytecode-repository.js +6 -1
- package/dist/cjs/permissionless/bindings/instance-manager.js +1 -1
- package/dist/cjs/permissionless/chains/archive-transport.js +8 -23
- package/dist/cjs/permissionless/chains/chunked-log-transport.js +116 -0
- package/dist/cjs/permissionless/index.js +2 -0
- package/dist/cjs/sdk/chain/chains.js +30 -5
- package/dist/cjs/sdk/constants/networks.js +2 -3
- package/dist/esm/permissionless/bindings/bytecode-repository.js +6 -1
- package/dist/esm/permissionless/bindings/instance-manager.js +1 -1
- package/dist/esm/permissionless/chains/archive-transport.js +8 -23
- package/dist/esm/permissionless/chains/chunked-log-transport.js +96 -0
- package/dist/esm/permissionless/index.js +1 -0
- package/dist/esm/sdk/chain/chains.js +30 -6
- package/dist/esm/sdk/constants/networks.js +2 -3
- package/dist/types/permissionless/chains/archive-transport.d.ts +5 -7
- package/dist/types/permissionless/chains/chunked-log-transport.d.ts +30 -0
- package/dist/types/permissionless/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -151,7 +151,12 @@ class BytecodeRepositoryContract extends import_base_contract.BaseContract {
|
|
|
151
151
|
if (code === void 0 || code === "0x") {
|
|
152
152
|
return [];
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
let publicDomains = [];
|
|
155
|
+
try {
|
|
156
|
+
publicDomains = await this.contract.read.getPublicDomains();
|
|
157
|
+
} catch {
|
|
158
|
+
publicDomains = [];
|
|
159
|
+
}
|
|
155
160
|
const publicDomainsString = publicDomains.map(
|
|
156
161
|
(domain) => (0, import_viem.hexToString)(domain, { size: 32 })
|
|
157
162
|
);
|
|
@@ -168,7 +168,7 @@ class InstanceManagerContract extends import_base_contract.BaseContract {
|
|
|
168
168
|
}
|
|
169
169
|
case "configureTreasury": {
|
|
170
170
|
const [target, data] = params.args;
|
|
171
|
-
let decoded
|
|
171
|
+
let decoded;
|
|
172
172
|
try {
|
|
173
173
|
const treasurySplitter = new import_treasury_splitter.TreasurySplitterContract(
|
|
174
174
|
target,
|
|
@@ -35,12 +35,18 @@ class ArchiveTransport {
|
|
|
35
35
|
enableLogging: false,
|
|
36
36
|
...config
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
if (!config.primaryRpcUrl && !config.primaryTransport) {
|
|
39
|
+
throw new Error("primaryRpcUrl or primaryTransport are required");
|
|
40
|
+
}
|
|
41
|
+
if (!config.archiveRpcUrl && !config.archiveTransport) {
|
|
42
|
+
throw new Error("archiveRpcUrl or archiveTransport are required");
|
|
43
|
+
}
|
|
44
|
+
this.primaryTransport = config.primaryTransport ?? (0, import_viem.http)(config.primaryRpcUrl, {
|
|
39
45
|
retryCount: this.config.retryCount,
|
|
40
46
|
retryDelay: this.config.retryDelay,
|
|
41
47
|
timeout: this.config.timeout
|
|
42
48
|
});
|
|
43
|
-
this.archiveTransport = (0, import_viem.http)(
|
|
49
|
+
this.archiveTransport = config.archiveTransport ?? (0, import_viem.http)(config.archiveRpcUrl, {
|
|
44
50
|
retryCount: this.config.retryCount,
|
|
45
51
|
retryDelay: this.config.retryDelay,
|
|
46
52
|
timeout: this.config.timeout
|
|
@@ -240,27 +246,6 @@ class ArchiveTransport {
|
|
|
240
246
|
getConfig() {
|
|
241
247
|
return { ...this.config };
|
|
242
248
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Update configuration (will invalidate cached transport)
|
|
245
|
-
*/
|
|
246
|
-
updateConfig(updates) {
|
|
247
|
-
this.config = { ...this.config, ...updates };
|
|
248
|
-
this.cachedTransport = void 0;
|
|
249
|
-
if (updates.primaryRpcUrl) {
|
|
250
|
-
this.primaryTransport = (0, import_viem.http)(this.config.primaryRpcUrl, {
|
|
251
|
-
retryCount: this.config.retryCount,
|
|
252
|
-
retryDelay: this.config.retryDelay,
|
|
253
|
-
timeout: this.config.timeout
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
if (updates.archiveRpcUrl) {
|
|
257
|
-
this.archiveTransport = (0, import_viem.http)(this.config.archiveRpcUrl, {
|
|
258
|
-
retryCount: this.config.retryCount,
|
|
259
|
-
retryDelay: this.config.retryDelay,
|
|
260
|
-
timeout: this.config.timeout
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
249
|
/**
|
|
265
250
|
* Enable or disable logging
|
|
266
251
|
*/
|
|
@@ -0,0 +1,116 @@
|
|
|
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 chunked_log_transport_exports = {};
|
|
20
|
+
__export(chunked_log_transport_exports, {
|
|
21
|
+
chunkedLogsTransport: () => chunkedLogsTransport
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chunked_log_transport_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
function chunkedLogsTransport({
|
|
26
|
+
transport,
|
|
27
|
+
chunkSize,
|
|
28
|
+
startBlock,
|
|
29
|
+
enableLogging = false
|
|
30
|
+
}) {
|
|
31
|
+
return (opts) => {
|
|
32
|
+
const baseTransport = transport(opts);
|
|
33
|
+
return (0, import_viem.custom)({
|
|
34
|
+
async request({ method, params }) {
|
|
35
|
+
if (method === "eth_getLogs") {
|
|
36
|
+
const [logsParams] = params;
|
|
37
|
+
if (logsParams.blockHash) {
|
|
38
|
+
return baseTransport.request({ method, params });
|
|
39
|
+
}
|
|
40
|
+
const fromBlock = logsParams.fromBlock !== void 0 ? typeof logsParams.fromBlock === "string" ? (0, import_viem.hexToNumber)(logsParams.fromBlock) : logsParams.fromBlock : void 0;
|
|
41
|
+
const toBlock = logsParams.toBlock !== void 0 ? typeof logsParams.toBlock === "string" ? (0, import_viem.hexToNumber)(logsParams.toBlock) : logsParams.toBlock : void 0;
|
|
42
|
+
if (startBlock !== void 0 && toBlock !== void 0 && toBlock < startBlock) {
|
|
43
|
+
if (enableLogging) {
|
|
44
|
+
console.log(
|
|
45
|
+
`[ChunkedLogsTransport] Request range (${fromBlock} -> ${toBlock}) is before startBlock (${startBlock}), returning empty array`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const adjustedFromBlock = startBlock !== void 0 && fromBlock !== void 0 && fromBlock < startBlock ? startBlock : fromBlock;
|
|
51
|
+
if (enableLogging && adjustedFromBlock !== fromBlock) {
|
|
52
|
+
console.log(
|
|
53
|
+
`[ChunkedLogsTransport] Adjusted fromBlock from ${fromBlock} to ${adjustedFromBlock} (startBlock: ${startBlock})`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (adjustedFromBlock === void 0 || toBlock === void 0 || toBlock - adjustedFromBlock <= chunkSize) {
|
|
57
|
+
const adjustedParams = [
|
|
58
|
+
{
|
|
59
|
+
...logsParams,
|
|
60
|
+
fromBlock: adjustedFromBlock !== void 0 ? (0, import_viem.numberToHex)(adjustedFromBlock) : logsParams.fromBlock
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
return baseTransport.request({ method, params: adjustedParams });
|
|
64
|
+
}
|
|
65
|
+
const chunks = [];
|
|
66
|
+
for (let start = adjustedFromBlock; start <= toBlock; start += chunkSize) {
|
|
67
|
+
chunks.push({
|
|
68
|
+
from: start,
|
|
69
|
+
to: Math.min(start + chunkSize - 1, toBlock)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (enableLogging) {
|
|
73
|
+
console.log(
|
|
74
|
+
`[ChunkedLogsTransport] Adjusted fromBlock: ${adjustedFromBlock}, toBlock: ${toBlock}`
|
|
75
|
+
);
|
|
76
|
+
console.log(
|
|
77
|
+
`[ChunkedLogsTransport] Splitting getLogs request into ${chunks.length} chunks (${adjustedFromBlock} -> ${toBlock}, chunk size: ${chunkSize})`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const batchRequests = chunks.map((chunk) => ({
|
|
81
|
+
method: "eth_getLogs",
|
|
82
|
+
params: [
|
|
83
|
+
{
|
|
84
|
+
...logsParams,
|
|
85
|
+
fromBlock: (0, import_viem.numberToHex)(chunk.from),
|
|
86
|
+
toBlock: (0, import_viem.numberToHex)(chunk.to)
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}));
|
|
90
|
+
const startTime = Date.now();
|
|
91
|
+
const results = await Promise.all(
|
|
92
|
+
batchRequests.map(
|
|
93
|
+
(req) => baseTransport.request({ method: req.method, params: req.params })
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
if (enableLogging) {
|
|
97
|
+
const duration = Date.now() - startTime;
|
|
98
|
+
const totalLogs = results.reduce(
|
|
99
|
+
(sum, logs) => sum + logs.length,
|
|
100
|
+
0
|
|
101
|
+
);
|
|
102
|
+
console.log(
|
|
103
|
+
`[ChunkedLogsTransport] Completed ${chunks.length} requests in ${duration}ms, retrieved ${totalLogs} logs`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
return results.flat();
|
|
107
|
+
}
|
|
108
|
+
return baseTransport.request({ method, params });
|
|
109
|
+
}
|
|
110
|
+
})(opts);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
chunkedLogsTransport
|
|
116
|
+
});
|
|
@@ -17,6 +17,7 @@ var permissionless_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(permissionless_exports);
|
|
18
18
|
__reExport(permissionless_exports, require("./bindings/index.js"), module.exports);
|
|
19
19
|
__reExport(permissionless_exports, require("./chains/archive-transport.js"), module.exports);
|
|
20
|
+
__reExport(permissionless_exports, require("./chains/chunked-log-transport.js"), module.exports);
|
|
20
21
|
__reExport(permissionless_exports, require("./core/index.js"), module.exports);
|
|
21
22
|
__reExport(permissionless_exports, require("./deployment/addresses.js"), module.exports);
|
|
22
23
|
__reExport(permissionless_exports, require("./deployment/mainnet.js"), module.exports);
|
|
@@ -25,6 +26,7 @@ __reExport(permissionless_exports, require("./utils/index.js"), module.exports);
|
|
|
25
26
|
0 && (module.exports = {
|
|
26
27
|
...require("./bindings/index.js"),
|
|
27
28
|
...require("./chains/archive-transport.js"),
|
|
29
|
+
...require("./chains/chunked-log-transport.js"),
|
|
28
30
|
...require("./core/index.js"),
|
|
29
31
|
...require("./deployment/addresses.js"),
|
|
30
32
|
...require("./deployment/mainnet.js"),
|
|
@@ -171,16 +171,41 @@ const chains = {
|
|
|
171
171
|
symbol: "WETH"
|
|
172
172
|
}
|
|
173
173
|
}),
|
|
174
|
+
// NOTE: Monad chain configs should be updated once the public mainnet is available
|
|
174
175
|
Monad: (0, import_viem.defineChain)({
|
|
175
|
-
|
|
176
|
+
id: 143,
|
|
177
|
+
name: "Monad",
|
|
178
|
+
nativeCurrency: {
|
|
179
|
+
name: "Monad",
|
|
180
|
+
symbol: "MON",
|
|
181
|
+
decimals: 18
|
|
182
|
+
},
|
|
183
|
+
rpcUrls: {
|
|
184
|
+
default: {
|
|
185
|
+
http: [
|
|
186
|
+
"https://permissionless-staging.gearbox.foundation/api/proxy/rpc/143"
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
blockExplorers: {
|
|
191
|
+
default: {
|
|
192
|
+
name: "Monvision",
|
|
193
|
+
url: "https://mainnet-beta.monvision.io"
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
contracts: {
|
|
197
|
+
multicall3: {
|
|
198
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
199
|
+
blockCreated: 9248132
|
|
200
|
+
}
|
|
201
|
+
},
|
|
176
202
|
network: "Monad",
|
|
177
203
|
defaultMarketConfigurators: {},
|
|
178
|
-
isPublic:
|
|
204
|
+
isPublic: true,
|
|
179
205
|
wellKnownToken: {
|
|
180
|
-
address: "
|
|
181
|
-
symbol: "
|
|
206
|
+
address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
|
|
207
|
+
symbol: "USDT0"
|
|
182
208
|
}
|
|
183
|
-
// TODO: has no block explorer API
|
|
184
209
|
}),
|
|
185
210
|
Berachain: withPublicNode(
|
|
186
211
|
{
|
|
@@ -35,7 +35,7 @@ const ADDRESS_PROVIDER_BLOCK = {
|
|
|
35
35
|
// New networks
|
|
36
36
|
MegaETH: 1677017n,
|
|
37
37
|
// arbitrary not deployed yet
|
|
38
|
-
Monad:
|
|
38
|
+
Monad: 34650265n,
|
|
39
39
|
// arbitrary not deployed yet
|
|
40
40
|
Berachain: 2788903n,
|
|
41
41
|
// arbitrary not deployed yet
|
|
@@ -63,8 +63,7 @@ const BLOCK_DURATION_LOCAL = {
|
|
|
63
63
|
// New networks
|
|
64
64
|
MegaETH: 10,
|
|
65
65
|
// <10ms/block, on testnet
|
|
66
|
-
Monad:
|
|
67
|
-
// on testnet
|
|
66
|
+
Monad: 400,
|
|
68
67
|
Berachain: 1900,
|
|
69
68
|
Avalanche: 1700,
|
|
70
69
|
BNB: 3e3,
|
|
@@ -134,7 +134,12 @@ class BytecodeRepositoryContract extends BaseContract {
|
|
|
134
134
|
if (code === void 0 || code === "0x") {
|
|
135
135
|
return [];
|
|
136
136
|
}
|
|
137
|
-
|
|
137
|
+
let publicDomains = [];
|
|
138
|
+
try {
|
|
139
|
+
publicDomains = await this.contract.read.getPublicDomains();
|
|
140
|
+
} catch {
|
|
141
|
+
publicDomains = [];
|
|
142
|
+
}
|
|
138
143
|
const publicDomainsString = publicDomains.map(
|
|
139
144
|
(domain) => hexToString(domain, { size: 32 })
|
|
140
145
|
);
|
|
@@ -148,7 +148,7 @@ class InstanceManagerContract extends BaseContract {
|
|
|
148
148
|
}
|
|
149
149
|
case "configureTreasury": {
|
|
150
150
|
const [target, data] = params.args;
|
|
151
|
-
let decoded
|
|
151
|
+
let decoded;
|
|
152
152
|
try {
|
|
153
153
|
const treasurySplitter = new TreasurySplitterContract(
|
|
154
154
|
target,
|
|
@@ -12,12 +12,18 @@ class ArchiveTransport {
|
|
|
12
12
|
enableLogging: false,
|
|
13
13
|
...config
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
if (!config.primaryRpcUrl && !config.primaryTransport) {
|
|
16
|
+
throw new Error("primaryRpcUrl or primaryTransport are required");
|
|
17
|
+
}
|
|
18
|
+
if (!config.archiveRpcUrl && !config.archiveTransport) {
|
|
19
|
+
throw new Error("archiveRpcUrl or archiveTransport are required");
|
|
20
|
+
}
|
|
21
|
+
this.primaryTransport = config.primaryTransport ?? http(config.primaryRpcUrl, {
|
|
16
22
|
retryCount: this.config.retryCount,
|
|
17
23
|
retryDelay: this.config.retryDelay,
|
|
18
24
|
timeout: this.config.timeout
|
|
19
25
|
});
|
|
20
|
-
this.archiveTransport = http(
|
|
26
|
+
this.archiveTransport = config.archiveTransport ?? http(config.archiveRpcUrl, {
|
|
21
27
|
retryCount: this.config.retryCount,
|
|
22
28
|
retryDelay: this.config.retryDelay,
|
|
23
29
|
timeout: this.config.timeout
|
|
@@ -217,27 +223,6 @@ class ArchiveTransport {
|
|
|
217
223
|
getConfig() {
|
|
218
224
|
return { ...this.config };
|
|
219
225
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Update configuration (will invalidate cached transport)
|
|
222
|
-
*/
|
|
223
|
-
updateConfig(updates) {
|
|
224
|
-
this.config = { ...this.config, ...updates };
|
|
225
|
-
this.cachedTransport = void 0;
|
|
226
|
-
if (updates.primaryRpcUrl) {
|
|
227
|
-
this.primaryTransport = http(this.config.primaryRpcUrl, {
|
|
228
|
-
retryCount: this.config.retryCount,
|
|
229
|
-
retryDelay: this.config.retryDelay,
|
|
230
|
-
timeout: this.config.timeout
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
if (updates.archiveRpcUrl) {
|
|
234
|
-
this.archiveTransport = http(this.config.archiveRpcUrl, {
|
|
235
|
-
retryCount: this.config.retryCount,
|
|
236
|
-
retryDelay: this.config.retryDelay,
|
|
237
|
-
timeout: this.config.timeout
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
226
|
/**
|
|
242
227
|
* Enable or disable logging
|
|
243
228
|
*/
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
custom,
|
|
3
|
+
hexToNumber,
|
|
4
|
+
numberToHex
|
|
5
|
+
} from "viem";
|
|
6
|
+
function chunkedLogsTransport({
|
|
7
|
+
transport,
|
|
8
|
+
chunkSize,
|
|
9
|
+
startBlock,
|
|
10
|
+
enableLogging = false
|
|
11
|
+
}) {
|
|
12
|
+
return (opts) => {
|
|
13
|
+
const baseTransport = transport(opts);
|
|
14
|
+
return custom({
|
|
15
|
+
async request({ method, params }) {
|
|
16
|
+
if (method === "eth_getLogs") {
|
|
17
|
+
const [logsParams] = params;
|
|
18
|
+
if (logsParams.blockHash) {
|
|
19
|
+
return baseTransport.request({ method, params });
|
|
20
|
+
}
|
|
21
|
+
const fromBlock = logsParams.fromBlock !== void 0 ? typeof logsParams.fromBlock === "string" ? hexToNumber(logsParams.fromBlock) : logsParams.fromBlock : void 0;
|
|
22
|
+
const toBlock = logsParams.toBlock !== void 0 ? typeof logsParams.toBlock === "string" ? hexToNumber(logsParams.toBlock) : logsParams.toBlock : void 0;
|
|
23
|
+
if (startBlock !== void 0 && toBlock !== void 0 && toBlock < startBlock) {
|
|
24
|
+
if (enableLogging) {
|
|
25
|
+
console.log(
|
|
26
|
+
`[ChunkedLogsTransport] Request range (${fromBlock} -> ${toBlock}) is before startBlock (${startBlock}), returning empty array`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const adjustedFromBlock = startBlock !== void 0 && fromBlock !== void 0 && fromBlock < startBlock ? startBlock : fromBlock;
|
|
32
|
+
if (enableLogging && adjustedFromBlock !== fromBlock) {
|
|
33
|
+
console.log(
|
|
34
|
+
`[ChunkedLogsTransport] Adjusted fromBlock from ${fromBlock} to ${adjustedFromBlock} (startBlock: ${startBlock})`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (adjustedFromBlock === void 0 || toBlock === void 0 || toBlock - adjustedFromBlock <= chunkSize) {
|
|
38
|
+
const adjustedParams = [
|
|
39
|
+
{
|
|
40
|
+
...logsParams,
|
|
41
|
+
fromBlock: adjustedFromBlock !== void 0 ? numberToHex(adjustedFromBlock) : logsParams.fromBlock
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
return baseTransport.request({ method, params: adjustedParams });
|
|
45
|
+
}
|
|
46
|
+
const chunks = [];
|
|
47
|
+
for (let start = adjustedFromBlock; start <= toBlock; start += chunkSize) {
|
|
48
|
+
chunks.push({
|
|
49
|
+
from: start,
|
|
50
|
+
to: Math.min(start + chunkSize - 1, toBlock)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (enableLogging) {
|
|
54
|
+
console.log(
|
|
55
|
+
`[ChunkedLogsTransport] Adjusted fromBlock: ${adjustedFromBlock}, toBlock: ${toBlock}`
|
|
56
|
+
);
|
|
57
|
+
console.log(
|
|
58
|
+
`[ChunkedLogsTransport] Splitting getLogs request into ${chunks.length} chunks (${adjustedFromBlock} -> ${toBlock}, chunk size: ${chunkSize})`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
const batchRequests = chunks.map((chunk) => ({
|
|
62
|
+
method: "eth_getLogs",
|
|
63
|
+
params: [
|
|
64
|
+
{
|
|
65
|
+
...logsParams,
|
|
66
|
+
fromBlock: numberToHex(chunk.from),
|
|
67
|
+
toBlock: numberToHex(chunk.to)
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}));
|
|
71
|
+
const startTime = Date.now();
|
|
72
|
+
const results = await Promise.all(
|
|
73
|
+
batchRequests.map(
|
|
74
|
+
(req) => baseTransport.request({ method: req.method, params: req.params })
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
if (enableLogging) {
|
|
78
|
+
const duration = Date.now() - startTime;
|
|
79
|
+
const totalLogs = results.reduce(
|
|
80
|
+
(sum, logs) => sum + logs.length,
|
|
81
|
+
0
|
|
82
|
+
);
|
|
83
|
+
console.log(
|
|
84
|
+
`[ChunkedLogsTransport] Completed ${chunks.length} requests in ${duration}ms, retrieved ${totalLogs} logs`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return results.flat();
|
|
88
|
+
}
|
|
89
|
+
return baseTransport.request({ method, params });
|
|
90
|
+
}
|
|
91
|
+
})(opts);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
chunkedLogsTransport
|
|
96
|
+
};
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
lisk,
|
|
11
11
|
mainnet,
|
|
12
12
|
megaethTestnet,
|
|
13
|
-
monadTestnet,
|
|
14
13
|
optimism,
|
|
15
14
|
plasma,
|
|
16
15
|
sonic,
|
|
@@ -156,16 +155,41 @@ const chains = {
|
|
|
156
155
|
symbol: "WETH"
|
|
157
156
|
}
|
|
158
157
|
}),
|
|
158
|
+
// NOTE: Monad chain configs should be updated once the public mainnet is available
|
|
159
159
|
Monad: defineChain({
|
|
160
|
-
|
|
160
|
+
id: 143,
|
|
161
|
+
name: "Monad",
|
|
162
|
+
nativeCurrency: {
|
|
163
|
+
name: "Monad",
|
|
164
|
+
symbol: "MON",
|
|
165
|
+
decimals: 18
|
|
166
|
+
},
|
|
167
|
+
rpcUrls: {
|
|
168
|
+
default: {
|
|
169
|
+
http: [
|
|
170
|
+
"https://permissionless-staging.gearbox.foundation/api/proxy/rpc/143"
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
blockExplorers: {
|
|
175
|
+
default: {
|
|
176
|
+
name: "Monvision",
|
|
177
|
+
url: "https://mainnet-beta.monvision.io"
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
contracts: {
|
|
181
|
+
multicall3: {
|
|
182
|
+
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
183
|
+
blockCreated: 9248132
|
|
184
|
+
}
|
|
185
|
+
},
|
|
161
186
|
network: "Monad",
|
|
162
187
|
defaultMarketConfigurators: {},
|
|
163
|
-
isPublic:
|
|
188
|
+
isPublic: true,
|
|
164
189
|
wellKnownToken: {
|
|
165
|
-
address: "
|
|
166
|
-
symbol: "
|
|
190
|
+
address: "0xe7cd86e13AC4309349F30B3435a9d337750fC82D",
|
|
191
|
+
symbol: "USDT0"
|
|
167
192
|
}
|
|
168
|
-
// TODO: has no block explorer API
|
|
169
193
|
}),
|
|
170
194
|
Berachain: withPublicNode(
|
|
171
195
|
{
|
|
@@ -10,7 +10,7 @@ const ADDRESS_PROVIDER_BLOCK = {
|
|
|
10
10
|
// New networks
|
|
11
11
|
MegaETH: 1677017n,
|
|
12
12
|
// arbitrary not deployed yet
|
|
13
|
-
Monad:
|
|
13
|
+
Monad: 34650265n,
|
|
14
14
|
// arbitrary not deployed yet
|
|
15
15
|
Berachain: 2788903n,
|
|
16
16
|
// arbitrary not deployed yet
|
|
@@ -38,8 +38,7 @@ const BLOCK_DURATION_LOCAL = {
|
|
|
38
38
|
// New networks
|
|
39
39
|
MegaETH: 10,
|
|
40
40
|
// <10ms/block, on testnet
|
|
41
|
-
Monad:
|
|
42
|
-
// on testnet
|
|
41
|
+
Monad: 400,
|
|
43
42
|
Berachain: 1900,
|
|
44
43
|
Avalanche: 1700,
|
|
45
44
|
BNB: 3e3,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type Transport } from "viem";
|
|
2
2
|
export interface ArchiveTransportConfig {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
primaryTransport?: Transport;
|
|
4
|
+
archiveTransport?: Transport;
|
|
5
|
+
primaryRpcUrl?: string;
|
|
6
|
+
archiveRpcUrl?: string;
|
|
5
7
|
blockThreshold: number;
|
|
6
8
|
retryCount?: number;
|
|
7
9
|
retryDelay?: number;
|
|
@@ -37,11 +39,7 @@ export declare class ArchiveTransport {
|
|
|
37
39
|
/**
|
|
38
40
|
* Get current configuration
|
|
39
41
|
*/
|
|
40
|
-
getConfig():
|
|
41
|
-
/**
|
|
42
|
-
* Update configuration (will invalidate cached transport)
|
|
43
|
-
*/
|
|
44
|
-
updateConfig(updates: Partial<ArchiveTransportConfig>): void;
|
|
42
|
+
getConfig(): ArchiveTransportConfig;
|
|
45
43
|
/**
|
|
46
44
|
* Enable or disable logging
|
|
47
45
|
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Transport } from "viem";
|
|
2
|
+
interface ChunkedLogsTransportConfig {
|
|
3
|
+
transport: Transport;
|
|
4
|
+
chunkSize: number;
|
|
5
|
+
startBlock?: number;
|
|
6
|
+
enableLogging?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a custom viem transport that chunks getLogs requests by block range
|
|
10
|
+
* and makes batch RPC requests for better performance with large block ranges.
|
|
11
|
+
*
|
|
12
|
+
* @param config Configuration object
|
|
13
|
+
* @param config.transport Base transport to wrap
|
|
14
|
+
* @param config.chunkSize Number of blocks per chunk
|
|
15
|
+
* @param config.startBlock Optional minimum block - logs before this block are filtered out
|
|
16
|
+
* @param config.enableLogging Enable debug logging
|
|
17
|
+
* @returns Viem Transport
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const transport = chunkedLogsTransport({
|
|
21
|
+
* transport: http('https://eth.llamarpc.com'),
|
|
22
|
+
* chunkSize: 2000,
|
|
23
|
+
* startBlock: 18000000,
|
|
24
|
+
* enableLogging: true,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const client = createPublicClient({ transport });
|
|
28
|
+
*/
|
|
29
|
+
export declare function chunkedLogsTransport({ transport, chunkSize, startBlock, enableLogging, }: ChunkedLogsTransportConfig): Transport;
|
|
30
|
+
export {};
|