@gearbox-protocol/sdk 11.1.7 → 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.
@@ -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 = void 0;
171
+ let decoded;
172
172
  try {
173
173
  const treasurySplitter = new import_treasury_splitter.TreasurySplitterContract(
174
174
  target,
@@ -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
- ...import_chains.monadTestnet,
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: false,
204
+ isPublic: true,
179
205
  wellKnownToken: {
180
- address: "0xf817257fed379853cDe0fa4F97AB987181B1E5Ea",
181
- symbol: "USDC"
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: 9319691n,
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: 1e3,
67
- // on testnet
66
+ Monad: 400,
68
67
  Berachain: 1900,
69
68
  Avalanche: 1700,
70
69
  BNB: 3e3,
@@ -148,7 +148,7 @@ class InstanceManagerContract extends BaseContract {
148
148
  }
149
149
  case "configureTreasury": {
150
150
  const [target, data] = params.args;
151
- let decoded = void 0;
151
+ let decoded;
152
152
  try {
153
153
  const treasurySplitter = new TreasurySplitterContract(
154
154
  target,
@@ -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
+ };
@@ -1,5 +1,6 @@
1
1
  export * from "./bindings/index.js";
2
2
  export * from "./chains/archive-transport.js";
3
+ export * from "./chains/chunked-log-transport.js";
3
4
  export * from "./core/index.js";
4
5
  export * from "./deployment/addresses.js";
5
6
  export * from "./deployment/mainnet.js";
@@ -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
- ...monadTestnet,
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: false,
188
+ isPublic: true,
164
189
  wellKnownToken: {
165
- address: "0xf817257fed379853cDe0fa4F97AB987181B1E5Ea",
166
- symbol: "USDC"
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: 9319691n,
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: 1e3,
42
- // on testnet
41
+ Monad: 400,
43
42
  Berachain: 1900,
44
43
  Avalanche: 1700,
45
44
  BNB: 3e3,
@@ -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 {};
@@ -1,5 +1,6 @@
1
1
  export * from "./bindings/index.js";
2
2
  export * from "./chains/archive-transport.js";
3
+ export * from "./chains/chunked-log-transport.js";
3
4
  export * from "./core/index.js";
4
5
  export * from "./deployment/addresses.js";
5
6
  export * from "./deployment/mainnet.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "11.1.7",
3
+ "version": "11.2.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",