@gearbox-protocol/sdk 8.27.12 → 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.
- package/dist/cjs/dev/EthCallSpy.js +81 -0
- package/dist/cjs/dev/index.js +2 -0
- package/dist/cjs/sdk/constants/networks.js +14 -21
- package/dist/esm/dev/EthCallSpy.js +61 -0
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/sdk/constants/networks.js +14 -21
- package/dist/types/dev/EthCallSpy.d.ts +22 -0
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/sdk/constants/networks.d.ts +1 -1
- package/package.json +1 -1
|
@@ -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
|
+
}
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -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
|
});
|
|
@@ -23,6 +23,7 @@ __export(networks_exports, {
|
|
|
23
23
|
RAMP_DURATION_BY_NETWORK: () => RAMP_DURATION_BY_NETWORK
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(networks_exports);
|
|
26
|
+
var import_chain = require("../chain/index.js");
|
|
26
27
|
var import_mappers = require("../utils/mappers.js");
|
|
27
28
|
const ADDRESS_PROVIDER_BLOCK = {
|
|
28
29
|
Mainnet: 18433056n,
|
|
@@ -51,27 +52,19 @@ const ADDRESS_PROVIDER_BLOCK = {
|
|
|
51
52
|
Lisk: 18934260n
|
|
52
53
|
// arbitrary not deployed yet
|
|
53
54
|
};
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Berachain: 1.9,
|
|
66
|
-
Avalanche: 1.7,
|
|
67
|
-
BNB: 3,
|
|
68
|
-
WorldChain: 2,
|
|
69
|
-
Etherlink: 1,
|
|
70
|
-
Hemi: 12,
|
|
71
|
-
Lisk: 2
|
|
72
|
-
};
|
|
55
|
+
const BLOCK_DURATION_LOCAL = {};
|
|
56
|
+
const BLOCK_DURATION = Object.values(import_chain.chains).reduce(
|
|
57
|
+
(acc, chain) => {
|
|
58
|
+
const blockTime = chain.blockTime || BLOCK_DURATION_LOCAL[chain.network] || 0;
|
|
59
|
+
if (blockTime === 0)
|
|
60
|
+
console.error(`Block time for ${chain.name} is unknown`);
|
|
61
|
+
acc[chain.network] = blockTime / 1e3;
|
|
62
|
+
return acc;
|
|
63
|
+
},
|
|
64
|
+
{}
|
|
65
|
+
);
|
|
73
66
|
const RAMP_TIME = 30 * 24 * 60 * 60 * 1.2;
|
|
74
|
-
const RAMP_DURATION_BY_NETWORK = import_mappers.TypedObjectUtils.entries(
|
|
67
|
+
const RAMP_DURATION_BY_NETWORK = import_mappers.TypedObjectUtils.entries(BLOCK_DURATION).reduce(
|
|
75
68
|
(acc, [n, duration]) => {
|
|
76
69
|
acc[n] = BigInt(Math.floor(RAMP_TIME / duration));
|
|
77
70
|
return acc;
|
|
@@ -79,7 +72,7 @@ const RAMP_DURATION_BY_NETWORK = import_mappers.TypedObjectUtils.entries(BLOCK_D
|
|
|
79
72
|
{}
|
|
80
73
|
);
|
|
81
74
|
const WEEK = 7 * 24 * 60 * 60;
|
|
82
|
-
const BLOCKS_PER_WEEK_BY_NETWORK = import_mappers.TypedObjectUtils.entries(
|
|
75
|
+
const BLOCKS_PER_WEEK_BY_NETWORK = import_mappers.TypedObjectUtils.entries(BLOCK_DURATION).reduce(
|
|
83
76
|
(acc, [n, duration]) => {
|
|
84
77
|
acc[n] = BigInt(Math.floor(WEEK / duration));
|
|
85
78
|
return acc;
|
|
@@ -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
|
+
};
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chains as CHAINS } from "../chain/index.js";
|
|
1
2
|
import { TypedObjectUtils } from "../utils/mappers.js";
|
|
2
3
|
const ADDRESS_PROVIDER_BLOCK = {
|
|
3
4
|
Mainnet: 18433056n,
|
|
@@ -26,27 +27,19 @@ const ADDRESS_PROVIDER_BLOCK = {
|
|
|
26
27
|
Lisk: 18934260n
|
|
27
28
|
// arbitrary not deployed yet
|
|
28
29
|
};
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Berachain: 1.9,
|
|
41
|
-
Avalanche: 1.7,
|
|
42
|
-
BNB: 3,
|
|
43
|
-
WorldChain: 2,
|
|
44
|
-
Etherlink: 1,
|
|
45
|
-
Hemi: 12,
|
|
46
|
-
Lisk: 2
|
|
47
|
-
};
|
|
30
|
+
const BLOCK_DURATION_LOCAL = {};
|
|
31
|
+
const BLOCK_DURATION = Object.values(CHAINS).reduce(
|
|
32
|
+
(acc, chain) => {
|
|
33
|
+
const blockTime = chain.blockTime || BLOCK_DURATION_LOCAL[chain.network] || 0;
|
|
34
|
+
if (blockTime === 0)
|
|
35
|
+
console.error(`Block time for ${chain.name} is unknown`);
|
|
36
|
+
acc[chain.network] = blockTime / 1e3;
|
|
37
|
+
return acc;
|
|
38
|
+
},
|
|
39
|
+
{}
|
|
40
|
+
);
|
|
48
41
|
const RAMP_TIME = 30 * 24 * 60 * 60 * 1.2;
|
|
49
|
-
const RAMP_DURATION_BY_NETWORK = TypedObjectUtils.entries(
|
|
42
|
+
const RAMP_DURATION_BY_NETWORK = TypedObjectUtils.entries(BLOCK_DURATION).reduce(
|
|
50
43
|
(acc, [n, duration]) => {
|
|
51
44
|
acc[n] = BigInt(Math.floor(RAMP_TIME / duration));
|
|
52
45
|
return acc;
|
|
@@ -54,7 +47,7 @@ const RAMP_DURATION_BY_NETWORK = TypedObjectUtils.entries(BLOCK_DURATION_BY_NETW
|
|
|
54
47
|
{}
|
|
55
48
|
);
|
|
56
49
|
const WEEK = 7 * 24 * 60 * 60;
|
|
57
|
-
const BLOCKS_PER_WEEK_BY_NETWORK = TypedObjectUtils.entries(
|
|
50
|
+
const BLOCKS_PER_WEEK_BY_NETWORK = TypedObjectUtils.entries(BLOCK_DURATION).reduce(
|
|
58
51
|
(acc, [n, duration]) => {
|
|
59
52
|
acc[n] = BigInt(Math.floor(WEEK / duration));
|
|
60
53
|
return acc;
|
|
@@ -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
|
+
}
|