@gearbox-protocol/sdk 9.0.2 → 9.0.4

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.
@@ -39,7 +39,7 @@ class EthCallSpy {
39
39
  const data = await request.json();
40
40
  const blockNumber = this.#shouldStore(data);
41
41
  if (blockNumber) {
42
- this.storeCall(blockNumber, data);
42
+ this.storeRequest(blockNumber, data);
43
43
  this.#logger?.debug(
44
44
  `spy stored eth_call at block ${blockNumber}, total calls: ${this.#detectedCalls.length}`
45
45
  );
@@ -58,6 +58,9 @@ class EthCallSpy {
58
58
  if (call) {
59
59
  call.response = resp;
60
60
  call.responseHeaders = Object.fromEntries(response.headers.entries());
61
+ await this.storeResponse(
62
+ call
63
+ );
61
64
  }
62
65
  };
63
66
  get detectedCalls() {
@@ -66,6 +69,16 @@ class EthCallSpy {
66
69
  get detectedBlock() {
67
70
  return this.#detectedBlock;
68
71
  }
72
+ storeRequest(blockNumber, data) {
73
+ if (blockNumber !== this.#detectedBlock) {
74
+ this.#detectedBlock = blockNumber;
75
+ this.#detectedCalls = [];
76
+ }
77
+ this.#detectedCalls.push({ request: data });
78
+ }
79
+ storeResponse(call) {
80
+ return;
81
+ }
69
82
  #shouldStore(data) {
70
83
  if (data.method === "eth_call" && typeof data.params[1] === "string" && // block number is present
71
84
  data.params[1]?.startsWith("0x") && // and it's a block number
@@ -74,13 +87,6 @@ class EthCallSpy {
74
87
  }
75
88
  return void 0;
76
89
  }
77
- storeCall(blockNumber, data) {
78
- if (blockNumber !== this.#detectedBlock) {
79
- this.#detectedBlock = blockNumber;
80
- this.#detectedCalls = [];
81
- }
82
- this.#detectedCalls.push({ request: data });
83
- }
84
90
  }
85
91
  // Annotate the CommonJS export names for ESM import in node:
86
92
  0 && (module.exports = {
@@ -26,6 +26,7 @@ __reExport(dev_exports, require("./detectChain.js"), module.exports);
26
26
  __reExport(dev_exports, require("./EthCallSpy.js"), module.exports);
27
27
  __reExport(dev_exports, require("./ltUtils.js"), module.exports);
28
28
  __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
29
+ __reExport(dev_exports, require("./types.js"), module.exports);
29
30
  // Annotate the CommonJS export names for ESM import in node:
30
31
  0 && (module.exports = {
31
32
  ...require("./AccountOpener.js"),
@@ -38,5 +39,6 @@ __reExport(dev_exports, require("./migrateFaucet.js"), module.exports);
38
39
  ...require("./detectChain.js"),
39
40
  ...require("./EthCallSpy.js"),
40
41
  ...require("./ltUtils.js"),
41
- ...require("./migrateFaucet.js")
42
+ ...require("./migrateFaucet.js"),
43
+ ...require("./types.js")
42
44
  });
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -16,7 +16,7 @@ class EthCallSpy {
16
16
  const data = await request.json();
17
17
  const blockNumber = this.#shouldStore(data);
18
18
  if (blockNumber) {
19
- this.storeCall(blockNumber, data);
19
+ this.storeRequest(blockNumber, data);
20
20
  this.#logger?.debug(
21
21
  `spy stored eth_call at block ${blockNumber}, total calls: ${this.#detectedCalls.length}`
22
22
  );
@@ -35,6 +35,9 @@ class EthCallSpy {
35
35
  if (call) {
36
36
  call.response = resp;
37
37
  call.responseHeaders = Object.fromEntries(response.headers.entries());
38
+ await this.storeResponse(
39
+ call
40
+ );
38
41
  }
39
42
  };
40
43
  get detectedCalls() {
@@ -43,6 +46,16 @@ class EthCallSpy {
43
46
  get detectedBlock() {
44
47
  return this.#detectedBlock;
45
48
  }
49
+ storeRequest(blockNumber, data) {
50
+ if (blockNumber !== this.#detectedBlock) {
51
+ this.#detectedBlock = blockNumber;
52
+ this.#detectedCalls = [];
53
+ }
54
+ this.#detectedCalls.push({ request: data });
55
+ }
56
+ storeResponse(call) {
57
+ return;
58
+ }
46
59
  #shouldStore(data) {
47
60
  if (data.method === "eth_call" && typeof data.params[1] === "string" && // block number is present
48
61
  data.params[1]?.startsWith("0x") && // and it's a block number
@@ -51,13 +64,6 @@ class EthCallSpy {
51
64
  }
52
65
  return void 0;
53
66
  }
54
- storeCall(blockNumber, data) {
55
- if (blockNumber !== this.#detectedBlock) {
56
- this.#detectedBlock = blockNumber;
57
- this.#detectedCalls = [];
58
- }
59
- this.#detectedCalls.push({ request: data });
60
- }
61
67
  }
62
68
  export {
63
69
  EthCallSpy
@@ -9,3 +9,4 @@ export * from "./detectChain.js";
9
9
  export * from "./EthCallSpy.js";
10
10
  export * from "./ltUtils.js";
11
11
  export * from "./migrateFaucet.js";
12
+ export * from "./types.js";
File without changes
@@ -1,25 +1,27 @@
1
- import type { EIP1193Parameters, HttpTransportConfig, PublicRpcSchema } from "viem";
1
+ import type { EIP1193Parameters, Hex, HttpTransportConfig, PublicRpcSchema, RequiredBy } from "viem";
2
2
  import type { ILogger } from "../sdk/index.js";
3
+ import type { RpcResponse } from "./types.js";
3
4
  export type EthCallMethod = Extract<PublicRpcSchema[number], {
4
5
  Method: "eth_call";
5
6
  }>;
6
7
  export type EthCallRequest = EIP1193Parameters<[EthCallMethod]>;
7
8
  export interface DetectedCall {
8
9
  request: EthCallRequest;
9
- response?: EthCallMethod["ReturnType"];
10
+ response?: RpcResponse<Hex>;
10
11
  responseHeaders?: Record<string, string>;
11
12
  }
12
13
  export type CheckMulticallFn = (data: EthCallRequest) => boolean;
13
14
  /**
14
15
  * Helper to spy on eth_call requests and responses in viem transport
15
16
  */
16
- export declare class EthCallSpy {
17
+ export declare class EthCallSpy<TCall extends DetectedCall = DetectedCall> {
17
18
  #private;
18
19
  enabled: boolean;
19
20
  constructor(check: CheckMulticallFn, logger?: ILogger, enabled?: boolean);
20
21
  onFetchRequest: Required<HttpTransportConfig>["onFetchRequest"];
21
22
  onFetchResponse: Required<HttpTransportConfig>["onFetchResponse"];
22
- get detectedCalls(): DetectedCall[];
23
+ get detectedCalls(): TCall[];
23
24
  get detectedBlock(): bigint;
24
- protected storeCall(blockNumber: bigint, data: EthCallRequest): void;
25
+ protected storeRequest(blockNumber: bigint, data: EthCallRequest): void;
26
+ protected storeResponse(call: RequiredBy<TCall, "response" | "responseHeaders">): void | Promise<void>;
25
27
  }
@@ -9,3 +9,4 @@ export * from "./detectChain.js";
9
9
  export * from "./EthCallSpy.js";
10
10
  export * from "./ltUtils.js";
11
11
  export * from "./migrateFaucet.js";
12
+ export * from "./types.js";
@@ -0,0 +1,14 @@
1
+ export type RpcSuccessResult<result> = {
2
+ method?: undefined;
3
+ result: result;
4
+ error?: undefined;
5
+ };
6
+ export type RpcErrorResult<error> = {
7
+ method?: undefined;
8
+ result?: undefined;
9
+ error: error;
10
+ };
11
+ export type RpcResponse<result = any, error = any> = {
12
+ jsonrpc: `${number}`;
13
+ id: number;
14
+ } & (RpcSuccessResult<result> | RpcErrorResult<error>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "9.0.2",
3
+ "version": "9.0.4",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",