@asyncswap/eth-rpc 0.4.2 → 0.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @asyncswap/eth-rpc
2
2
 
3
+ ## 0.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - b2b631f: deprecated `EthExecutionClien` use `ExecutionClient`
8
+ - Updated dependencies [f7d28d9]
9
+ - @asyncswap/jsonrpc@0.4.4
10
+
11
+ ## 0.4.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 7ae86a0: new refactor on methods as data
16
+ - Updated dependencies [40a79dc]
17
+ - @asyncswap/jsonrpc@0.4.3
18
+
3
19
  ## 0.4.2
4
20
 
5
21
  ### Patch Changes
@@ -8,13 +24,13 @@
8
24
  - Updated dependencies [9512db5]
9
25
  - @asyncswap/jsonrpc@0.4.2
10
26
 
11
- ## 0.5.1
27
+ ## 0.4.1
12
28
 
13
29
  ### Patch Changes
14
30
 
15
31
  - 2598f09: updates docs
16
32
 
17
- ## 0.5.0
33
+ ## 0.4.0
18
34
 
19
35
  ### Minor Changes
20
36
 
package/README.md CHANGED
@@ -13,10 +13,10 @@ bun add @asyncswap/eth-rpc
13
13
  ### Execution API Client
14
14
 
15
15
  ```typescript
16
- import { EthExecutionClient } from '@asyncswap/eth-rpc';
16
+ import { ExecutionClient } from '@asyncswap/eth-rpc';
17
17
 
18
18
  const url = 'http://localhost:8545'
19
- const eth = new EthExecutionClient(url);
19
+ const eth = new ExecutionClient(url);
20
20
 
21
21
  const balance = await eth.eth_getBalance(
22
22
  "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
@@ -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 { EthFlashbotsClient } from '@asyncswap/eth-rpc';
49
+ import { FlashbotsClient } from '@asyncswap/eth-rpc';
41
50
 
42
51
  const rpc = 'https://relay.flashbots.net';
43
- const client = new EthFlashbotsClient(rpc);
52
+ const client = new FlashbotsClient(rpc);
44
53
  ```
45
54
 
46
55
  ## Error Handling
package/example.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { EthExecutionClient } from "./src";
1
+ import { ExecutionClient } from "./src";
2
2
 
3
3
  const url = "http://localhost:8545";
4
- const eth = new EthExecutionClient(url);
5
-
4
+ const eth = new ExecutionClient(url);
6
5
  const balance = await eth.eth_getBalance(
7
6
  "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
8
7
  "latest",
@@ -14,11 +13,11 @@ import { EngineExecutionClient } from "./src";
14
13
 
15
14
  const engineUrl = "https://localhost:8551";
16
15
  const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
17
- const payload = engine.engine_getPayloadV1("0x1");
16
+ const payload = await engine.engine_getPayloadV1("0x1");
18
17
 
19
18
  console.log(payload);
20
19
 
21
- import { EthFlashbotsClient } from "./src";
20
+ import { FlashbotsClient } from "./src";
22
21
 
23
22
  const rpc = "https://relay.flashbots.net";
24
- const client = new EthFlashbotsClient(rpc);
23
+ const client = new FlashbotsClient(rpc);
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.2",
5
+ "version": "0.4.4",
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.2"
44
+ "@asyncswap/jsonrpc": "^0.4.4"
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
- private client: JsonRpcClient;
5
- private headers: Record<string, string>;
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.client = new JsonRpcClient(url);
12
- }
17
+ this.rpc = new JsonRpcClient(url);
13
18
 
14
- // eth/transaction
15
- async eth_sendRawTransaction(transaction: Bytes): Promise<Hash32> {
16
- return await this.client.call(
17
- EngineMethods.eth_sendRawTransaction,
18
- [transaction],
19
- this.headers,
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
- // engine/payload
156
- async engine_newPayloadV1(
157
- executionPayload: ExecutionPayloadV1,
158
- ): Promise<PayloadStatusV1> {
159
- return await this.client.call(
160
- EngineMethods.engine_newPayloadV1,
161
- [executionPayload],
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> { }