@gearbox-protocol/sdk 14.0.0-next.8 → 14.0.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/RevolverTransport.js +10 -4
- package/dist/cjs/rewards/rewards/extra-apy.js +1 -1
- package/dist/cjs/sdk/MultichainSDK.js +5 -0
- package/dist/cjs/sdk/OnchainSDK.js +1 -2
- package/dist/cjs/sdk/utils/viem/index.js +0 -4
- package/dist/esm/dev/RevolverTransport.js +10 -4
- package/dist/esm/rewards/rewards/extra-apy.js +1 -1
- package/dist/esm/sdk/MultichainSDK.js +5 -0
- package/dist/esm/sdk/OnchainSDK.js +1 -2
- package/dist/esm/sdk/utils/viem/index.js +0 -2
- package/dist/types/dev/RevolverTransport.d.ts +2 -1
- package/dist/types/sdk/utils/viem/index.d.ts +0 -2
- package/package.json +4 -4
- package/dist/cjs/sdk/utils/viem/getLogsPaginated.js +0 -62
- package/dist/cjs/sdk/utils/viem/getLogsSafe.js +0 -87
- package/dist/esm/sdk/utils/viem/getLogsPaginated.js +0 -38
- package/dist/esm/sdk/utils/viem/getLogsSafe.js +0 -65
- package/dist/types/sdk/utils/viem/getLogsPaginated.d.ts +0 -12
- package/dist/types/sdk/utils/viem/getLogsSafe.d.ts +0 -3
|
@@ -87,8 +87,14 @@ const revolverTransportConfigSchema = import_v4.z.union([
|
|
|
87
87
|
})
|
|
88
88
|
]);
|
|
89
89
|
class NoAvailableTransportsError extends import_viem.BaseError {
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
statuses;
|
|
91
|
+
constructor(statuses, cause) {
|
|
92
|
+
super("No available transports", {
|
|
93
|
+
cause,
|
|
94
|
+
metaMessages: statuses.length > 0 ? statuses.map((s) => `- ${s.id}: ${s.status}`) : ["No transports configured"],
|
|
95
|
+
name: "NoAvailableTransportsError"
|
|
96
|
+
});
|
|
97
|
+
this.statuses = statuses;
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
class RevolverTransport {
|
|
@@ -146,7 +152,7 @@ class RevolverTransport {
|
|
|
146
152
|
);
|
|
147
153
|
}
|
|
148
154
|
if (transports.length === 0) {
|
|
149
|
-
throw new NoAvailableTransportsError();
|
|
155
|
+
throw new NoAvailableTransportsError([]);
|
|
150
156
|
}
|
|
151
157
|
this.#isSingle = transports.length === 1;
|
|
152
158
|
const selectionStrategy = config.selectionStrategy ?? "simple";
|
|
@@ -197,7 +203,7 @@ class RevolverTransport {
|
|
|
197
203
|
}
|
|
198
204
|
} while (this.#selector.canRotate());
|
|
199
205
|
this.#requests.delete(r);
|
|
200
|
-
throw new NoAvailableTransportsError(error);
|
|
206
|
+
throw new NoAvailableTransportsError(this.#selector.statuses(), error);
|
|
201
207
|
};
|
|
202
208
|
get config() {
|
|
203
209
|
return {
|
|
@@ -66,7 +66,7 @@ class PoolPointsAPI {
|
|
|
66
66
|
}
|
|
67
67
|
static async getTokenTotal(token, network, tokensList) {
|
|
68
68
|
const chainId = import_sdk.chains[network]?.id;
|
|
69
|
-
const url = `https://
|
|
69
|
+
const url = `https://api.gearbox.foundation/v1/getBalanceAt?asset=${token}&chainId=${chainId}`;
|
|
70
70
|
const result = await import_axios.default.get(url);
|
|
71
71
|
const balance = result.data.result.reduce(
|
|
72
72
|
(sum, r) => r.effective_balance + sum,
|
|
@@ -29,8 +29,10 @@ class MultichainSDK {
|
|
|
29
29
|
#chains;
|
|
30
30
|
#redstoneCache;
|
|
31
31
|
#pythCache;
|
|
32
|
+
#logger;
|
|
32
33
|
constructor(options) {
|
|
33
34
|
this.#chains = /* @__PURE__ */ new Map();
|
|
35
|
+
this.#logger = options.logger;
|
|
34
36
|
for (const [network, chainConfig] of Object.entries(options.chains)) {
|
|
35
37
|
const { gasLimit, ...clientOptions } = chainConfig;
|
|
36
38
|
let plugins;
|
|
@@ -92,6 +94,7 @@ class MultichainSDK {
|
|
|
92
94
|
});
|
|
93
95
|
})
|
|
94
96
|
);
|
|
97
|
+
this.#logger?.info("Attached all chains");
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
100
|
* Hydrate all configured chains from serialised state.
|
|
@@ -142,6 +145,7 @@ class MultichainSDK {
|
|
|
142
145
|
}
|
|
143
146
|
});
|
|
144
147
|
}
|
|
148
|
+
this.#logger?.info("Hydrated all chains");
|
|
145
149
|
}
|
|
146
150
|
/**
|
|
147
151
|
* Returns the {@link OnchainSDK} for a given network or chain ID.
|
|
@@ -200,6 +204,7 @@ class MultichainSDK {
|
|
|
200
204
|
if (Object.keys(errors).length > 0) {
|
|
201
205
|
throw new import_core.SdkSyncFailedError(errors);
|
|
202
206
|
}
|
|
207
|
+
this.#logger?.info("Synced state for all chains");
|
|
203
208
|
}
|
|
204
209
|
/**
|
|
205
210
|
* Serialisable snapshot of all chains' state.
|
|
@@ -32,7 +32,6 @@ var import_pricefeeds = require("./market/pricefeeds/index.js");
|
|
|
32
32
|
var import_plugins = require("./plugins/index.js");
|
|
33
33
|
var import_router = require("./router/index.js");
|
|
34
34
|
var import_utils = require("./utils/index.js");
|
|
35
|
-
var import_viem2 = require("./utils/viem/index.js");
|
|
36
35
|
const STATE_VERSION = 1;
|
|
37
36
|
function createViemClient(opts, chain) {
|
|
38
37
|
if ("client" in opts) {
|
|
@@ -326,7 +325,7 @@ class OnchainSDK extends import_base.ChainContractsRegister {
|
|
|
326
325
|
this.logger?.debug(
|
|
327
326
|
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
328
327
|
);
|
|
329
|
-
const logs = await
|
|
328
|
+
const logs = await this.client.getLogs({
|
|
330
329
|
fromBlock,
|
|
331
330
|
toBlock: blockNumber,
|
|
332
331
|
address: watchAddresses
|
|
@@ -16,8 +16,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var viem_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(viem_exports);
|
|
18
18
|
__reExport(viem_exports, require("./cast.js"), module.exports);
|
|
19
|
-
__reExport(viem_exports, require("./getLogsPaginated.js"), module.exports);
|
|
20
|
-
__reExport(viem_exports, require("./getLogsSafe.js"), module.exports);
|
|
21
19
|
__reExport(viem_exports, require("./sendRawTx.js"), module.exports);
|
|
22
20
|
__reExport(viem_exports, require("./simulateMulticall.js"), module.exports);
|
|
23
21
|
__reExport(viem_exports, require("./simulateWithPriceUpdates.js"), module.exports);
|
|
@@ -25,8 +23,6 @@ __reExport(viem_exports, require("./watchBlocksAsync.js"), module.exports);
|
|
|
25
23
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
24
|
0 && (module.exports = {
|
|
27
25
|
...require("./cast.js"),
|
|
28
|
-
...require("./getLogsPaginated.js"),
|
|
29
|
-
...require("./getLogsSafe.js"),
|
|
30
26
|
...require("./sendRawTx.js"),
|
|
31
27
|
...require("./simulateMulticall.js"),
|
|
32
28
|
...require("./simulateWithPriceUpdates.js"),
|
|
@@ -70,8 +70,14 @@ const revolverTransportConfigSchema = z.union([
|
|
|
70
70
|
})
|
|
71
71
|
]);
|
|
72
72
|
class NoAvailableTransportsError extends BaseError {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
statuses;
|
|
74
|
+
constructor(statuses, cause) {
|
|
75
|
+
super("No available transports", {
|
|
76
|
+
cause,
|
|
77
|
+
metaMessages: statuses.length > 0 ? statuses.map((s) => `- ${s.id}: ${s.status}`) : ["No transports configured"],
|
|
78
|
+
name: "NoAvailableTransportsError"
|
|
79
|
+
});
|
|
80
|
+
this.statuses = statuses;
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
class RevolverTransport {
|
|
@@ -129,7 +135,7 @@ class RevolverTransport {
|
|
|
129
135
|
);
|
|
130
136
|
}
|
|
131
137
|
if (transports.length === 0) {
|
|
132
|
-
throw new NoAvailableTransportsError();
|
|
138
|
+
throw new NoAvailableTransportsError([]);
|
|
133
139
|
}
|
|
134
140
|
this.#isSingle = transports.length === 1;
|
|
135
141
|
const selectionStrategy = config.selectionStrategy ?? "simple";
|
|
@@ -180,7 +186,7 @@ class RevolverTransport {
|
|
|
180
186
|
}
|
|
181
187
|
} while (this.#selector.canRotate());
|
|
182
188
|
this.#requests.delete(r);
|
|
183
|
-
throw new NoAvailableTransportsError(error);
|
|
189
|
+
throw new NoAvailableTransportsError(this.#selector.statuses(), error);
|
|
184
190
|
};
|
|
185
191
|
get config() {
|
|
186
192
|
return {
|
|
@@ -36,7 +36,7 @@ class PoolPointsAPI {
|
|
|
36
36
|
}
|
|
37
37
|
static async getTokenTotal(token, network, tokensList) {
|
|
38
38
|
const chainId = chains[network]?.id;
|
|
39
|
-
const url = `https://
|
|
39
|
+
const url = `https://api.gearbox.foundation/v1/getBalanceAt?asset=${token}&chainId=${chainId}`;
|
|
40
40
|
const result = await axios.get(url);
|
|
41
41
|
const balance = result.data.result.reduce(
|
|
42
42
|
(sum, r) => r.effective_balance + sum,
|
|
@@ -15,8 +15,10 @@ class MultichainSDK {
|
|
|
15
15
|
#chains;
|
|
16
16
|
#redstoneCache;
|
|
17
17
|
#pythCache;
|
|
18
|
+
#logger;
|
|
18
19
|
constructor(options) {
|
|
19
20
|
this.#chains = /* @__PURE__ */ new Map();
|
|
21
|
+
this.#logger = options.logger;
|
|
20
22
|
for (const [network, chainConfig] of Object.entries(options.chains)) {
|
|
21
23
|
const { gasLimit, ...clientOptions } = chainConfig;
|
|
22
24
|
let plugins;
|
|
@@ -78,6 +80,7 @@ class MultichainSDK {
|
|
|
78
80
|
});
|
|
79
81
|
})
|
|
80
82
|
);
|
|
83
|
+
this.#logger?.info("Attached all chains");
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
86
|
* Hydrate all configured chains from serialised state.
|
|
@@ -128,6 +131,7 @@ class MultichainSDK {
|
|
|
128
131
|
}
|
|
129
132
|
});
|
|
130
133
|
}
|
|
134
|
+
this.#logger?.info("Hydrated all chains");
|
|
131
135
|
}
|
|
132
136
|
/**
|
|
133
137
|
* Returns the {@link OnchainSDK} for a given network or chain ID.
|
|
@@ -186,6 +190,7 @@ class MultichainSDK {
|
|
|
186
190
|
if (Object.keys(errors).length > 0) {
|
|
187
191
|
throw new SdkSyncFailedError(errors);
|
|
188
192
|
}
|
|
193
|
+
this.#logger?.info("Synced state for all chains");
|
|
189
194
|
}
|
|
190
195
|
/**
|
|
191
196
|
* Serialisable snapshot of all chains' state.
|
|
@@ -27,7 +27,6 @@ import { PriceFeedRegister } from "./market/pricefeeds/index.js";
|
|
|
27
27
|
import { PluginStateVersionError } from "./plugins/index.js";
|
|
28
28
|
import { createRouter } from "./router/index.js";
|
|
29
29
|
import { formatTimestamp, TypedObjectUtils, toAddress } from "./utils/index.js";
|
|
30
|
-
import { getLogsSafe } from "./utils/viem/index.js";
|
|
31
30
|
const STATE_VERSION = 1;
|
|
32
31
|
function createViemClient(opts, chain) {
|
|
33
32
|
if ("client" in opts) {
|
|
@@ -321,7 +320,7 @@ class OnchainSDK extends ChainContractsRegister {
|
|
|
321
320
|
this.logger?.debug(
|
|
322
321
|
`getting logs from ${watchAddresses.length} addresses in [${fromBlock}:${blockNumber}]`
|
|
323
322
|
);
|
|
324
|
-
const logs = await
|
|
323
|
+
const logs = await this.client.getLogs({
|
|
325
324
|
fromBlock,
|
|
326
325
|
toBlock: blockNumber,
|
|
327
326
|
address: watchAddresses
|
|
@@ -167,7 +167,8 @@ export type RevolverTransportConfig = {
|
|
|
167
167
|
onRotateFailed?: (oldTransportName: string, reason?: BaseError) => void | Promise<void>;
|
|
168
168
|
} & z.infer<typeof revolverTransportConfigSchema>;
|
|
169
169
|
export declare class NoAvailableTransportsError extends BaseError {
|
|
170
|
-
|
|
170
|
+
statuses: ProviderStatus[];
|
|
171
|
+
constructor(statuses: ProviderStatus[], cause?: Error);
|
|
171
172
|
}
|
|
172
173
|
export interface RevolverTransportValue {
|
|
173
174
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "14.0.0
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@commitlint/config-conventional": "^20.5.0",
|
|
92
92
|
"@gearbox-protocol/biome-config": "^1.0.27",
|
|
93
93
|
"@types/cross-spawn": "^6.0.6",
|
|
94
|
-
"axios": "^1.15.
|
|
94
|
+
"axios": "^1.15.1",
|
|
95
95
|
"cross-spawn": "^7.0.6",
|
|
96
96
|
"husky": "^9.1.7",
|
|
97
97
|
"lint-staged": "^16.4.0",
|
|
@@ -99,9 +99,9 @@
|
|
|
99
99
|
"pino-pretty": "^13.1.3",
|
|
100
100
|
"tsup": "^8.5.1",
|
|
101
101
|
"tsx": "^4.21.0",
|
|
102
|
-
"typescript": "^6.0.
|
|
102
|
+
"typescript": "^6.0.3",
|
|
103
103
|
"viem-deal": "^2.0.4",
|
|
104
|
-
"vite": "^8.0.
|
|
104
|
+
"vite": "^8.0.9",
|
|
105
105
|
"vitest": "^4.1.4",
|
|
106
106
|
"yaml": "^2.8.3"
|
|
107
107
|
},
|
|
@@ -1,62 +0,0 @@
|
|
|
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 getLogsPaginated_exports = {};
|
|
20
|
-
__export(getLogsPaginated_exports, {
|
|
21
|
-
getLogsPaginated: () => getLogsPaginated
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(getLogsPaginated_exports);
|
|
24
|
-
var import_actions = require("viem/actions");
|
|
25
|
-
async function getLogsPaginated(client, params) {
|
|
26
|
-
const from_ = params.fromBlock;
|
|
27
|
-
const to_ = params.toBlock;
|
|
28
|
-
const pageSize = params.pageSize;
|
|
29
|
-
const requests = [];
|
|
30
|
-
for (let fromBlock = from_; fromBlock < to_; fromBlock += pageSize) {
|
|
31
|
-
let toBlock = fromBlock + pageSize - 1n;
|
|
32
|
-
if (toBlock > to_) {
|
|
33
|
-
toBlock = to_;
|
|
34
|
-
}
|
|
35
|
-
requests.push({
|
|
36
|
-
...params,
|
|
37
|
-
fromBlock,
|
|
38
|
-
toBlock
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const responses = await Promise.all(
|
|
42
|
-
requests.map(
|
|
43
|
-
(r) => (0, import_actions.getLogs)(
|
|
44
|
-
client,
|
|
45
|
-
r
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
);
|
|
49
|
-
return responses.flat().sort((a, b) => {
|
|
50
|
-
if (a.blockNumber === b.blockNumber) {
|
|
51
|
-
return a.logIndex - b.logIndex;
|
|
52
|
-
} else if (a.blockNumber < b.blockNumber) {
|
|
53
|
-
return -1;
|
|
54
|
-
} else {
|
|
55
|
-
return 1;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
-
0 && (module.exports = {
|
|
61
|
-
getLogsPaginated
|
|
62
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
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 getLogsSafe_exports = {};
|
|
20
|
-
__export(getLogsSafe_exports, {
|
|
21
|
-
getLogsSafe: () => getLogsSafe
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(getLogsSafe_exports);
|
|
24
|
-
var import_viem = require("viem");
|
|
25
|
-
var import_actions = require("viem/actions");
|
|
26
|
-
async function getLogsSafe(client, params = {}) {
|
|
27
|
-
try {
|
|
28
|
-
const events = await (0, import_actions.getLogs)(client, params);
|
|
29
|
-
return events;
|
|
30
|
-
} catch (e) {
|
|
31
|
-
const fromBlock = params.fromBlock;
|
|
32
|
-
const toBlock = params.toBlock;
|
|
33
|
-
const bisected = tryBisectBlockRange({ fromBlock, toBlock }, e);
|
|
34
|
-
if (!bisected) {
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
const [left, right] = await Promise.all([
|
|
38
|
-
getLogsSafe(client, { ...params, ...bisected[0] }),
|
|
39
|
-
getLogsSafe(client, { ...params, ...bisected[1] })
|
|
40
|
-
]);
|
|
41
|
-
return [...left, ...right];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function tryBisectBlockRange({ fromBlock, toBlock }, e) {
|
|
45
|
-
const alchemyMid = checkForAlchemyBlockRange(e);
|
|
46
|
-
if (alchemyMid && alchemyMid > fromBlock && alchemyMid < toBlock) {
|
|
47
|
-
return [
|
|
48
|
-
{ fromBlock, toBlock: alchemyMid },
|
|
49
|
-
{ fromBlock: alchemyMid + 1n, toBlock }
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
const blockRangeErrors = [
|
|
53
|
-
"query exceeds max block",
|
|
54
|
-
"range is too large",
|
|
55
|
-
"eth_getLogs is limited to",
|
|
56
|
-
"eth_getLogs requests with up to",
|
|
57
|
-
"exceeded max allowed range"
|
|
58
|
-
];
|
|
59
|
-
if (e instanceof Error && blockRangeErrors.some((errorText) => e.message.includes(errorText))) {
|
|
60
|
-
const middle = (fromBlock + toBlock) / 2n;
|
|
61
|
-
return [
|
|
62
|
-
{ fromBlock, toBlock: middle },
|
|
63
|
-
{ fromBlock: middle + 1n, toBlock }
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
return void 0;
|
|
67
|
-
}
|
|
68
|
-
const ALCHEMY_BLOCK_RANGE_REGEX = /this block range should work: \[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/;
|
|
69
|
-
function checkForAlchemyBlockRange(e) {
|
|
70
|
-
if (e instanceof import_viem.HttpRequestError) {
|
|
71
|
-
try {
|
|
72
|
-
const err = JSON.parse(e.details);
|
|
73
|
-
if (typeof err.message === "string") {
|
|
74
|
-
const match = err.message.match(ALCHEMY_BLOCK_RANGE_REGEX);
|
|
75
|
-
if (match) {
|
|
76
|
-
return BigInt(match[2]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return void 0;
|
|
83
|
-
}
|
|
84
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
-
0 && (module.exports = {
|
|
86
|
-
getLogsSafe
|
|
87
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { getLogs } from "viem/actions";
|
|
2
|
-
async function getLogsPaginated(client, params) {
|
|
3
|
-
const from_ = params.fromBlock;
|
|
4
|
-
const to_ = params.toBlock;
|
|
5
|
-
const pageSize = params.pageSize;
|
|
6
|
-
const requests = [];
|
|
7
|
-
for (let fromBlock = from_; fromBlock < to_; fromBlock += pageSize) {
|
|
8
|
-
let toBlock = fromBlock + pageSize - 1n;
|
|
9
|
-
if (toBlock > to_) {
|
|
10
|
-
toBlock = to_;
|
|
11
|
-
}
|
|
12
|
-
requests.push({
|
|
13
|
-
...params,
|
|
14
|
-
fromBlock,
|
|
15
|
-
toBlock
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const responses = await Promise.all(
|
|
19
|
-
requests.map(
|
|
20
|
-
(r) => getLogs(
|
|
21
|
-
client,
|
|
22
|
-
r
|
|
23
|
-
)
|
|
24
|
-
)
|
|
25
|
-
);
|
|
26
|
-
return responses.flat().sort((a, b) => {
|
|
27
|
-
if (a.blockNumber === b.blockNumber) {
|
|
28
|
-
return a.logIndex - b.logIndex;
|
|
29
|
-
} else if (a.blockNumber < b.blockNumber) {
|
|
30
|
-
return -1;
|
|
31
|
-
} else {
|
|
32
|
-
return 1;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
getLogsPaginated
|
|
38
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpRequestError
|
|
3
|
-
} from "viem";
|
|
4
|
-
import { getLogs } from "viem/actions";
|
|
5
|
-
async function getLogsSafe(client, params = {}) {
|
|
6
|
-
try {
|
|
7
|
-
const events = await getLogs(client, params);
|
|
8
|
-
return events;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
const fromBlock = params.fromBlock;
|
|
11
|
-
const toBlock = params.toBlock;
|
|
12
|
-
const bisected = tryBisectBlockRange({ fromBlock, toBlock }, e);
|
|
13
|
-
if (!bisected) {
|
|
14
|
-
throw e;
|
|
15
|
-
}
|
|
16
|
-
const [left, right] = await Promise.all([
|
|
17
|
-
getLogsSafe(client, { ...params, ...bisected[0] }),
|
|
18
|
-
getLogsSafe(client, { ...params, ...bisected[1] })
|
|
19
|
-
]);
|
|
20
|
-
return [...left, ...right];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function tryBisectBlockRange({ fromBlock, toBlock }, e) {
|
|
24
|
-
const alchemyMid = checkForAlchemyBlockRange(e);
|
|
25
|
-
if (alchemyMid && alchemyMid > fromBlock && alchemyMid < toBlock) {
|
|
26
|
-
return [
|
|
27
|
-
{ fromBlock, toBlock: alchemyMid },
|
|
28
|
-
{ fromBlock: alchemyMid + 1n, toBlock }
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
const blockRangeErrors = [
|
|
32
|
-
"query exceeds max block",
|
|
33
|
-
"range is too large",
|
|
34
|
-
"eth_getLogs is limited to",
|
|
35
|
-
"eth_getLogs requests with up to",
|
|
36
|
-
"exceeded max allowed range"
|
|
37
|
-
];
|
|
38
|
-
if (e instanceof Error && blockRangeErrors.some((errorText) => e.message.includes(errorText))) {
|
|
39
|
-
const middle = (fromBlock + toBlock) / 2n;
|
|
40
|
-
return [
|
|
41
|
-
{ fromBlock, toBlock: middle },
|
|
42
|
-
{ fromBlock: middle + 1n, toBlock }
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
const ALCHEMY_BLOCK_RANGE_REGEX = /this block range should work: \[(0x[0-9a-fA-F]+),\s*(0x[0-9a-fA-F]+)\]/;
|
|
48
|
-
function checkForAlchemyBlockRange(e) {
|
|
49
|
-
if (e instanceof HttpRequestError) {
|
|
50
|
-
try {
|
|
51
|
-
const err = JSON.parse(e.details);
|
|
52
|
-
if (typeof err.message === "string") {
|
|
53
|
-
const match = err.message.match(ALCHEMY_BLOCK_RANGE_REGEX);
|
|
54
|
-
if (match) {
|
|
55
|
-
return BigInt(match[2]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} catch {
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return void 0;
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
getLogsSafe
|
|
65
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AbiEvent, BlockNumber, Chain, Client, GetLogsParameters, GetLogsReturnType, MaybeAbiEventName, Transport } from "viem";
|
|
2
|
-
export type GetLogsPaginatedParameters<abiEvent extends AbiEvent | undefined = undefined, abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined, _eventName extends string | undefined = MaybeAbiEventName<abiEvent>> = GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber, _eventName> & {
|
|
3
|
-
pageSize: bigint;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Get logs in pages, to avoid rate limiting
|
|
7
|
-
* Must be used with client that has batching enabled
|
|
8
|
-
* @param client
|
|
9
|
-
* @param params
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
export declare function getLogsPaginated<chain extends Chain | undefined, const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined>(client: Client<Transport, chain>, params: GetLogsPaginatedParameters<abiEvent, abiEvents, strict>): Promise<GetLogsReturnType<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>>;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { AbiEvent } from "viem";
|
|
2
|
-
import { type BlockNumber, type Chain, type Client, type GetLogsParameters, type GetLogsReturnType, type Transport } from "viem";
|
|
3
|
-
export declare function getLogsSafe<chain extends Chain | undefined, const abiEvent extends AbiEvent | undefined = undefined, const abiEvents extends readonly AbiEvent[] | readonly unknown[] | undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined, strict extends boolean | undefined = undefined>(client: Client<Transport, chain>, params?: GetLogsParameters<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>): Promise<GetLogsReturnType<abiEvent, abiEvents, strict, BlockNumber, BlockNumber>>;
|