@gearbox-protocol/sdk 8.27.13 → 8.28.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.
@@ -0,0 +1,81 @@
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 EthCallSpy_exports = {};
20
+ __export(EthCallSpy_exports, {
21
+ default: () => EthCallSpy
22
+ });
23
+ module.exports = __toCommonJS(EthCallSpy_exports);
24
+ class EthCallSpy {
25
+ #logger;
26
+ #detectedCalls = [];
27
+ #detectedBlock = 0n;
28
+ #check;
29
+ enabled;
30
+ constructor(check, logger, enabled) {
31
+ this.#check = check;
32
+ this.#logger = logger;
33
+ this.enabled = !!enabled;
34
+ }
35
+ onFetchRequest = async (request) => {
36
+ if (!this.enabled) {
37
+ return;
38
+ }
39
+ const data = await request.json();
40
+ const blockNumber = this.#shouldStore(data);
41
+ if (blockNumber) {
42
+ this.#storeCall(blockNumber, data);
43
+ this.#logger?.debug(
44
+ `spy stored eth_call at block ${blockNumber}, total calls: ${this.#detectedCalls.length}`
45
+ );
46
+ }
47
+ };
48
+ onFetchResponse = async (response) => {
49
+ if (!this.enabled) {
50
+ return;
51
+ }
52
+ const copy = response.clone();
53
+ const resp = await copy.json();
54
+ const id = resp.id;
55
+ const call = this.#detectedCalls.find(
56
+ ({ request }) => "id" in request && request.id === id
57
+ );
58
+ if (call) {
59
+ call.response = resp;
60
+ call.responseHeaders = Object.fromEntries(response.headers.entries());
61
+ }
62
+ };
63
+ get detectedCalls() {
64
+ return this.#detectedCalls;
65
+ }
66
+ #shouldStore(data) {
67
+ if (data.method === "eth_call" && typeof data.params[1] === "string" && // block number is present
68
+ data.params[1]?.startsWith("0x") && // and it's a block number
69
+ this.#check(data)) {
70
+ return BigInt(data.params[1]);
71
+ }
72
+ return void 0;
73
+ }
74
+ #storeCall(blockNumber, data) {
75
+ if (blockNumber !== this.#detectedBlock) {
76
+ this.#detectedBlock = blockNumber;
77
+ this.#detectedCalls = [];
78
+ }
79
+ this.#detectedCalls.push({ request: data });
80
+ }
81
+ }
@@ -23,6 +23,7 @@ __reExport(dev_exports, require("./create2.js"), module.exports);
23
23
  __reExport(dev_exports, require("./createAnvilClient.js"), module.exports);
24
24
  __reExport(dev_exports, require("./createTransport.js"), module.exports);
25
25
  __reExport(dev_exports, require("./detectChain.js"), module.exports);
26
+ __reExport(dev_exports, require("./EthCallSpy.js"), module.exports);
26
27
  __reExport(dev_exports, require("./ltUtils.js"), module.exports);
27
28
  __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
28
29
  // Annotate the CommonJS export names for ESM import in node:
@@ -35,6 +36,7 @@ __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
35
36
  ...require("./createAnvilClient.js"),
36
37
  ...require("./createTransport.js"),
37
38
  ...require("./detectChain.js"),
39
+ ...require("./EthCallSpy.js"),
38
40
  ...require("./ltUtils.js"),
39
41
  ...require("./migrateFaucet.js")
40
42
  });
@@ -0,0 +1,61 @@
1
+ class EthCallSpy {
2
+ #logger;
3
+ #detectedCalls = [];
4
+ #detectedBlock = 0n;
5
+ #check;
6
+ enabled;
7
+ constructor(check, logger, enabled) {
8
+ this.#check = check;
9
+ this.#logger = logger;
10
+ this.enabled = !!enabled;
11
+ }
12
+ onFetchRequest = async (request) => {
13
+ if (!this.enabled) {
14
+ return;
15
+ }
16
+ const data = await request.json();
17
+ const blockNumber = this.#shouldStore(data);
18
+ if (blockNumber) {
19
+ this.#storeCall(blockNumber, data);
20
+ this.#logger?.debug(
21
+ `spy stored eth_call at block ${blockNumber}, total calls: ${this.#detectedCalls.length}`
22
+ );
23
+ }
24
+ };
25
+ onFetchResponse = async (response) => {
26
+ if (!this.enabled) {
27
+ return;
28
+ }
29
+ const copy = response.clone();
30
+ const resp = await copy.json();
31
+ const id = resp.id;
32
+ const call = this.#detectedCalls.find(
33
+ ({ request }) => "id" in request && request.id === id
34
+ );
35
+ if (call) {
36
+ call.response = resp;
37
+ call.responseHeaders = Object.fromEntries(response.headers.entries());
38
+ }
39
+ };
40
+ get detectedCalls() {
41
+ return this.#detectedCalls;
42
+ }
43
+ #shouldStore(data) {
44
+ if (data.method === "eth_call" && typeof data.params[1] === "string" && // block number is present
45
+ data.params[1]?.startsWith("0x") && // and it's a block number
46
+ this.#check(data)) {
47
+ return BigInt(data.params[1]);
48
+ }
49
+ return void 0;
50
+ }
51
+ #storeCall(blockNumber, data) {
52
+ if (blockNumber !== this.#detectedBlock) {
53
+ this.#detectedBlock = blockNumber;
54
+ this.#detectedCalls = [];
55
+ }
56
+ this.#detectedCalls.push({ request: data });
57
+ }
58
+ }
59
+ export {
60
+ EthCallSpy as default
61
+ };
@@ -6,5 +6,6 @@ export * from "./create2.js";
6
6
  export * from "./createAnvilClient.js";
7
7
  export * from "./createTransport.js";
8
8
  export * from "./detectChain.js";
9
+ export * from "./EthCallSpy.js";
9
10
  export * from "./ltUtils.js";
10
11
  export * from "./migrateFaucet.js";
@@ -0,0 +1,22 @@
1
+ import type { HttpTransportConfig, PublicRpcSchema } from "viem";
2
+ import type { ILogger } from "../sdk/index.js";
3
+ export type EthCallMethod = Extract<PublicRpcSchema[number], {
4
+ Method: "eth_call";
5
+ }>;
6
+ export interface DetectedCall {
7
+ request: EthCallMethod;
8
+ response?: EthCallMethod["ReturnType"];
9
+ responseHeaders?: Record<string, string>;
10
+ }
11
+ export type CheckMulticallFn = (data: EthCallMethod) => boolean;
12
+ /**
13
+ * Helper to spy on eth_call requests and responses in viem transport
14
+ */
15
+ export default class EthCallSpy {
16
+ #private;
17
+ enabled: boolean;
18
+ constructor(check: CheckMulticallFn, logger?: ILogger, enabled?: boolean);
19
+ onFetchRequest: Required<HttpTransportConfig>["onFetchRequest"];
20
+ onFetchResponse: Required<HttpTransportConfig>["onFetchResponse"];
21
+ get detectedCalls(): DetectedCall[];
22
+ }
@@ -6,5 +6,6 @@ export * from "./create2.js";
6
6
  export * from "./createAnvilClient.js";
7
7
  export * from "./createTransport.js";
8
8
  export * from "./detectChain.js";
9
+ export * from "./EthCallSpy.js";
9
10
  export * from "./ltUtils.js";
10
11
  export * from "./migrateFaucet.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.27.13",
3
+ "version": "8.28.0",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",