@asyncswap/eth-rpc 0.4.2 → 0.4.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.
- package/CHANGELOG.md +10 -2
- package/README.md +11 -2
- package/example.ts +4 -2
- package/package.json +2 -2
- package/src/engine-api.ts +25 -308
- package/src/eth-api.ts +21 -252
- package/src/mev-api.ts +23 -150
- package/src/types/debug/methods.d.ts +7 -7
- package/src/types/engine/methods.d.ts +115 -33
- package/src/types/eth/methods.d.ts +96 -43
- package/src/types/mev/methods.d.ts +70 -19
- package/CLAUDE.md +0 -111
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @asyncswap/eth-rpc
|
|
2
2
|
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7ae86a0: new refactor on methods as data
|
|
8
|
+
- Updated dependencies [40a79dc]
|
|
9
|
+
- @asyncswap/jsonrpc@0.4.3
|
|
10
|
+
|
|
3
11
|
## 0.4.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -8,13 +16,13 @@
|
|
|
8
16
|
- Updated dependencies [9512db5]
|
|
9
17
|
- @asyncswap/jsonrpc@0.4.2
|
|
10
18
|
|
|
11
|
-
## 0.
|
|
19
|
+
## 0.4.1
|
|
12
20
|
|
|
13
21
|
### Patch Changes
|
|
14
22
|
|
|
15
23
|
- 2598f09: updates docs
|
|
16
24
|
|
|
17
|
-
## 0.
|
|
25
|
+
## 0.4.0
|
|
18
26
|
|
|
19
27
|
### Minor Changes
|
|
20
28
|
|
package/README.md
CHANGED
|
@@ -26,6 +26,15 @@ console.log("Balance:", balance);
|
|
|
26
26
|
eth.eth_getTransactionCount("0x34", "safe");
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
### Flashbots Client API
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { FlashbotsClient } from "@asyncswap/eth-rpc";
|
|
33
|
+
|
|
34
|
+
const rpc = "https://relay.flashbots.net";
|
|
35
|
+
const client = new FlashbotsClient(rpc);
|
|
36
|
+
```
|
|
37
|
+
|
|
29
38
|
### Engine API Client
|
|
30
39
|
|
|
31
40
|
```typescript
|
|
@@ -37,10 +46,10 @@ const payload = engine.engine_getPayloadV1("0x1");
|
|
|
37
46
|
|
|
38
47
|
console.log(payload);
|
|
39
48
|
|
|
40
|
-
import {
|
|
49
|
+
import { FlashbotsClient } from '@asyncswap/eth-rpc';
|
|
41
50
|
|
|
42
51
|
const rpc = 'https://relay.flashbots.net';
|
|
43
|
-
const client = new
|
|
52
|
+
const client = new FlashbotsClient(rpc);
|
|
44
53
|
```
|
|
45
54
|
|
|
46
55
|
## Error Handling
|
package/example.ts
CHANGED
|
@@ -18,7 +18,9 @@ const payload = engine.engine_getPayloadV1("0x1");
|
|
|
18
18
|
|
|
19
19
|
console.log(payload);
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { FlashbotsClient } from "./src";
|
|
22
22
|
|
|
23
23
|
const rpc = "https://relay.flashbots.net";
|
|
24
|
-
const client = new
|
|
24
|
+
const client = new FlashbotsClient(rpc);
|
|
25
|
+
const body = client.rpc.buildRequest("eth_sendBundle", []);
|
|
26
|
+
client.eth_accounts();
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@asyncswap/eth-rpc",
|
|
3
3
|
"description": "A library for ethereum execution clients apis.",
|
|
4
4
|
"author": "Meek Msaki",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"typescript": "^5"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@asyncswap/jsonrpc": "^0.4.
|
|
44
|
+
"@asyncswap/jsonrpc": "^0.4.3"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/engine-api.ts
CHANGED
|
@@ -1,320 +1,37 @@
|
|
|
1
1
|
import { JsonRpcClient } from "@asyncswap/jsonrpc";
|
|
2
2
|
|
|
3
|
+
export type EngineRpcMethods<
|
|
4
|
+
T extends Record<string, { params: unknown[]; result: unknown }>,
|
|
5
|
+
> = {
|
|
6
|
+
[K in keyof T]: (...params: T[K]["params"]) => Promise<T[K]["result"]>;
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
export class EngineExecutionClient {
|
|
4
|
-
|
|
5
|
-
|
|
10
|
+
rpc: JsonRpcClient;
|
|
11
|
+
headers: Record<string, string>;
|
|
6
12
|
|
|
7
13
|
constructor(url: string, jwt_token: string) {
|
|
8
14
|
this.headers = {
|
|
9
15
|
Authorization: `Bearer ${jwt_token}`,
|
|
10
16
|
};
|
|
11
|
-
this.
|
|
12
|
-
}
|
|
17
|
+
this.rpc = new JsonRpcClient(url);
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
// eth/state
|
|
23
|
-
async eth_getCode(
|
|
24
|
-
address: Address,
|
|
25
|
-
block: BlockNumberOrTagOrHash,
|
|
26
|
-
): Promise<Bytes> {
|
|
27
|
-
return await this.client.call(
|
|
28
|
-
EngineMethods.eth_getCode,
|
|
29
|
-
[address, block],
|
|
30
|
-
this.headers,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
async eth_getLogs(filter: Filter): Promise<FilterResults> {
|
|
34
|
-
return await this.client.call(
|
|
35
|
-
EngineMethods.eth_getLogs,
|
|
36
|
-
[filter],
|
|
37
|
-
this.headers,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
// eth/execute
|
|
41
|
-
async eth_call(
|
|
42
|
-
transaction: GenericTransaction,
|
|
43
|
-
block: BlockNumberOrTagOrHash,
|
|
44
|
-
): Promise<Bytes> {
|
|
45
|
-
return this.client.call(
|
|
46
|
-
EngineMethods.eth_call,
|
|
47
|
-
[transaction, block],
|
|
48
|
-
this.headers,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
// eth/client
|
|
52
|
-
async eth_chainId(): Promise<Uint> {
|
|
53
|
-
return await this.client.call(EngineMethods.eth_chainId, [], this.headers);
|
|
54
|
-
}
|
|
55
|
-
async eth_syncing(): Promise<SyncingStatus> {
|
|
56
|
-
return await this.client.call(EngineMethods.eth_syncing, [], this.headers);
|
|
57
|
-
}
|
|
58
|
-
async eth_blockNumber(): Promise<Uint> {
|
|
59
|
-
return await this.client.call(
|
|
60
|
-
EngineMethods.eth_blockNumber,
|
|
61
|
-
[],
|
|
62
|
-
this.headers,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
// eth/block
|
|
66
|
-
async eth_getBlockByHash(
|
|
67
|
-
blockHash: Hash32,
|
|
68
|
-
hydratedTransactions: boolean,
|
|
69
|
-
): Promise<NotFound | Block> {
|
|
70
|
-
return await this.client.call(
|
|
71
|
-
EngineMethods.eth_getBlockByHash,
|
|
72
|
-
[blockHash, hydratedTransactions],
|
|
73
|
-
this.headers,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
async eth_getBlockByNumber(
|
|
77
|
-
block: BlockNumberOrTag,
|
|
78
|
-
hydratedTransactions: boolean,
|
|
79
|
-
): Promise<NotFound | Block> {
|
|
80
|
-
return await this.client.call(
|
|
81
|
-
EngineMethods.eth_getBlockByNumber,
|
|
82
|
-
[block, hydratedTransactions],
|
|
83
|
-
this.headers,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
// engine/blob
|
|
87
|
-
async engine_getBlobsV1(
|
|
88
|
-
blobedVersionedHashes: Hash32[],
|
|
89
|
-
): Promise<BlobAndProofV1[]> {
|
|
90
|
-
return await this.client.call(
|
|
91
|
-
EngineMethods.engine_getBlobsV1,
|
|
92
|
-
[blobedVersionedHashes],
|
|
93
|
-
this.headers,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
async engine_getBlobsV2(
|
|
97
|
-
blobedVersionedHashes: Hash32[],
|
|
98
|
-
): Promise<BlobAndProofV2[]> {
|
|
99
|
-
return await this.client.call(
|
|
100
|
-
EngineMethods.engine_getBlobsV2,
|
|
101
|
-
[blobedVersionedHashes],
|
|
102
|
-
this.headers,
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
async engine_getBlobsV3(
|
|
106
|
-
blobedVersionedHashes: Hash32[],
|
|
107
|
-
): Promise<Array<BlobAndProofV2[] | null> | null> {
|
|
108
|
-
return await this.client.call(
|
|
109
|
-
EngineMethods.engine_getBlobsV3,
|
|
110
|
-
[blobedVersionedHashes],
|
|
111
|
-
this.headers,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
// engine/capabilities
|
|
115
|
-
async engine_exchangeCapabilities(
|
|
116
|
-
consensusClientMethods: string[],
|
|
117
|
-
): Promise<string[]> {
|
|
118
|
-
return await this.client.call(
|
|
119
|
-
EngineMethods.engine_exchangeCapabilities,
|
|
120
|
-
[consensusClientMethods],
|
|
121
|
-
this.headers,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
// engine/forkchoice
|
|
125
|
-
async engine_forkchoiceUpdatedV1(
|
|
126
|
-
forkchoiceState: ForkchoiceStateV1,
|
|
127
|
-
payloadAttribute: PayloadAttributesV1,
|
|
128
|
-
): Promise<ForkchoiceUpdatedResponseV1> {
|
|
129
|
-
return await this.client.call(
|
|
130
|
-
EngineMethods.engine_forkchoiceUpdatedV1,
|
|
131
|
-
[forkchoiceState, payloadAttribute],
|
|
132
|
-
this.headers,
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
async engine_forkchoiceUpdatedV2(
|
|
136
|
-
forkchoiceState: ForkchoiceStateV1,
|
|
137
|
-
payloadAttribute: PayloadAttributesV2,
|
|
138
|
-
): Promise<ForkchoiceUpdatedResponseV1> {
|
|
139
|
-
return await this.client.call(
|
|
140
|
-
EngineMethods.engine_forkchoiceUpdatedV2,
|
|
141
|
-
[forkchoiceState, payloadAttribute],
|
|
142
|
-
this.headers,
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
async engine_forkchoiceUpdatedV3(
|
|
146
|
-
forkchoiceState: ForkchoiceStateV1,
|
|
147
|
-
payloadAttribute: PayloadAttributesV3,
|
|
148
|
-
): Promise<ForkchoiceUpdatedResponseV1> {
|
|
149
|
-
return await this.client.call(
|
|
150
|
-
EngineMethods.engine_forkchoiceUpdatedV3,
|
|
151
|
-
[forkchoiceState, payloadAttribute],
|
|
152
|
-
this.headers,
|
|
153
|
-
);
|
|
19
|
+
return new Proxy(this, {
|
|
20
|
+
get: (_, method: string) => {
|
|
21
|
+
return (...params: unknown[]) =>
|
|
22
|
+
this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
154
25
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.headers,
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
async engine_newPayloadV2(
|
|
166
|
-
executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2,
|
|
167
|
-
): Promise<PayloadStatusNoInvalidBlockHash> {
|
|
168
|
-
return await this.client.call(
|
|
169
|
-
EngineMethods.engine_newPayloadV2,
|
|
170
|
-
[executionPayload],
|
|
171
|
-
this.headers,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
async engine_newPayloadV3(
|
|
175
|
-
executionPayload: ExecutionPayloadV3,
|
|
176
|
-
expectedBlobVersionedHashes: Hash32[],
|
|
177
|
-
rootOfTheParentBeaconBlock: Hash32,
|
|
178
|
-
): Promise<PayloadStatusNoInvalidBlockHash> {
|
|
179
|
-
return await this.client.call(
|
|
180
|
-
EngineMethods.engine_newPayloadV3,
|
|
181
|
-
[
|
|
182
|
-
executionPayload,
|
|
183
|
-
expectedBlobVersionedHashes,
|
|
184
|
-
rootOfTheParentBeaconBlock,
|
|
185
|
-
],
|
|
186
|
-
this.headers,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
async engine_newPayloadV4(
|
|
190
|
-
executionPayload: ExecutionPayloadV3,
|
|
191
|
-
expectedBlobVersionedHashes: Hash32[],
|
|
192
|
-
rootOfTheParentBeaconBlock: Hash32,
|
|
193
|
-
executionRequests: Bytes[],
|
|
194
|
-
): Promise<PayloadStatusNoInvalidBlockHash> {
|
|
195
|
-
return await this.client.call(
|
|
196
|
-
EngineMethods.engine_newPayloadV4,
|
|
197
|
-
[
|
|
198
|
-
executionPayload,
|
|
199
|
-
expectedBlobVersionedHashes,
|
|
200
|
-
rootOfTheParentBeaconBlock,
|
|
201
|
-
executionRequests,
|
|
202
|
-
],
|
|
203
|
-
this.headers,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
async engine_getPayloadV1(payloadId: Bytes8): Promise<ExecutionPayloadV1> {
|
|
207
|
-
return await this.client.call(
|
|
208
|
-
EngineMethods.engine_getPayloadV1,
|
|
209
|
-
[payloadId],
|
|
210
|
-
this.headers,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
async engine_getPayloadV2(payloadId: Bytes8): Promise<{
|
|
214
|
-
executionPayload: ExecutionPayloadV1 | ExecutionPayloadV2;
|
|
215
|
-
blockValue: Uint256;
|
|
216
|
-
}> {
|
|
217
|
-
return await this.client.call(
|
|
218
|
-
EngineMethods.engine_getPayloadV2,
|
|
219
|
-
[payloadId],
|
|
220
|
-
this.headers,
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
async engine_getPayloadV3(payloadId: Bytes8): Promise<{
|
|
224
|
-
executionPayload: ExecutionPayloadV3;
|
|
225
|
-
blockValue: Uint256;
|
|
226
|
-
blobsBundle: BlobsBundleV1;
|
|
227
|
-
shouldOverrideBuilder: boolean;
|
|
228
|
-
}> {
|
|
229
|
-
return await this.client.call(
|
|
230
|
-
EngineMethods.engine_getPayloadV3,
|
|
231
|
-
[payloadId],
|
|
232
|
-
this.headers,
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
async engine_getPayloadV4(payloadId: Bytes8): Promise<{
|
|
236
|
-
executionPayload: ExecutionPayloadV3;
|
|
237
|
-
blockValue: Uint256;
|
|
238
|
-
blobsBundle: BlobsBundleV1;
|
|
239
|
-
shouldOverrideBuilder: boolean;
|
|
240
|
-
executionRequests: Bytes[];
|
|
241
|
-
}> {
|
|
242
|
-
return await this.client.call(
|
|
243
|
-
EngineMethods.engine_getPayloadV4,
|
|
244
|
-
[payloadId],
|
|
245
|
-
this.headers,
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
async engine_getPayloadV5(payloadId: Bytes8): Promise<{
|
|
249
|
-
executionPayload: ExecutionPayloadV3;
|
|
250
|
-
blockValue: Uint256;
|
|
251
|
-
blobsBundle: BlobsBundleV2;
|
|
252
|
-
shouldOverrideBuilder: boolean;
|
|
253
|
-
executionRequests: Bytes[];
|
|
254
|
-
}> {
|
|
255
|
-
return await this.client.call(
|
|
256
|
-
EngineMethods.engine_getPayloadV5,
|
|
257
|
-
[payloadId],
|
|
258
|
-
this.headers,
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
async engine_getPayloadBodiesByHashV1(
|
|
262
|
-
arrayOfBlockHashes: Hash32[],
|
|
263
|
-
): Promise<ExecutionPayloadBodyV1[]> {
|
|
264
|
-
return await this.client.call(
|
|
265
|
-
EngineMethods.engine_getPayloadBodiesByHashV1,
|
|
266
|
-
[arrayOfBlockHashes],
|
|
267
|
-
this.headers,
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
async engine_getPayloadBodiesByRangeV1(
|
|
271
|
-
startingBlockNumber: Uint64,
|
|
272
|
-
numberOfBlocksToReturn: Uint64,
|
|
273
|
-
): Promise<ExecutionPayloadBodyV1[]> {
|
|
274
|
-
return await this.client.call(
|
|
275
|
-
EngineMethods.engine_getPayloadBodiesByRangeV1,
|
|
276
|
-
[startingBlockNumber, numberOfBlocksToReturn],
|
|
277
|
-
this.headers,
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
async engine_newPayloadV5(
|
|
281
|
-
executionPayload: ExecutionPayloadV4,
|
|
282
|
-
expectedBlobVersionedHashes: Hash32[],
|
|
283
|
-
parentBeaconBlockRoot: Hash32,
|
|
284
|
-
executionRequests: Bytes[],
|
|
285
|
-
): Promise<PayloadStatusNoInvalidBlockHash> {
|
|
286
|
-
return await this.client.call(
|
|
287
|
-
EngineMethods.engine_newPayloadV5,
|
|
288
|
-
[
|
|
289
|
-
executionPayload,
|
|
290
|
-
expectedBlobVersionedHashes,
|
|
291
|
-
parentBeaconBlockRoot,
|
|
292
|
-
executionRequests,
|
|
293
|
-
],
|
|
294
|
-
this.headers,
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
async engine_getPayloadV6(payloadId: Bytes8): Promise<{
|
|
298
|
-
executionPayload: ExecutionPayloadV4;
|
|
299
|
-
blockValue: Uint256;
|
|
300
|
-
blobsBundle: BlobsBundleV2;
|
|
301
|
-
shouldOverrideBuilder: boolean;
|
|
302
|
-
executionRequests: Bytes[];
|
|
303
|
-
}> {
|
|
304
|
-
return await this.client.call(
|
|
305
|
-
EngineMethods.engine_getPayloadV6,
|
|
306
|
-
[payloadId],
|
|
307
|
-
this.headers,
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
// engine/transition-configuration
|
|
311
|
-
async engine_exchangeTransitionConfigurationV1(
|
|
312
|
-
consensusClientConfiguration: TransitionConfigurationV1,
|
|
313
|
-
): Promise<TransitionConfigurationV1> {
|
|
314
|
-
return await this.client.call(
|
|
315
|
-
EngineMethods.engine_exchangeTransitionConfigurationV1,
|
|
316
|
-
[consensusClientConfiguration],
|
|
317
|
-
this.headers,
|
|
318
|
-
);
|
|
26
|
+
|
|
27
|
+
setHeaders(headers: Record<string, string>) {
|
|
28
|
+
this.headers = {
|
|
29
|
+
...this.headers,
|
|
30
|
+
...headers,
|
|
31
|
+
};
|
|
32
|
+
return this;
|
|
319
33
|
}
|
|
320
34
|
}
|
|
35
|
+
|
|
36
|
+
export interface EngineExecutionClient
|
|
37
|
+
extends EngineRpcMethods<EngineMethodsSpec> { }
|