@gearbox-protocol/sdk 9.0.1 → 9.0.3

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 = {
@@ -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
@@ -33,7 +33,13 @@ export interface TargetAccount {
33
33
  * These tokens will be transferred directly from faucet to credit account
34
34
  */
35
35
  directTransfer?: Address[];
36
+ /**
37
+ * Leverage, without percentage (e.g. "3" for 300%)
38
+ */
36
39
  leverage?: number;
40
+ /**
41
+ * Slippage with percentage (e.g. 100 = 1%)
42
+ */
37
43
  slippage?: number;
38
44
  }
39
45
  export interface OpenAccountResult {
@@ -1,4 +1,5 @@
1
- import type { EIP1193Parameters, HttpTransportConfig, PublicRpcSchema } from "viem";
1
+ import type { EIP1193Parameters, Hex, HttpTransportConfig, PublicRpcSchema, RequiredBy } from "viem";
2
+ import type { RpcResponse } from "viem/_types/types/rpc.js";
2
3
  import type { ILogger } from "../sdk/index.js";
3
4
  export type EthCallMethod = Extract<PublicRpcSchema[number], {
4
5
  Method: "eth_call";
@@ -6,19 +7,21 @@ export type EthCallMethod = Extract<PublicRpcSchema[number], {
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;
25
+ protected storeRequest(blockNumber: bigint, data: EthCallRequest): void;
26
+ protected storeResponse(call: RequiredBy<TCall, "response" | "responseHeaders">): void | Promise<void>;
24
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "9.0.1",
3
+ "version": "9.0.3",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",