@asyncswap/eth-rpc 0.4.4 → 0.4.6

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,19 @@
1
1
  # @asyncswap/eth-rpc
2
2
 
3
+ ## 0.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d6ec6e: add clinet version spec
8
+
9
+ ## 0.4.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 0d1be5d: upgrade with parameter typing
14
+ - Updated dependencies [882f94f]
15
+ - @asyncswap/jsonrpc@0.4.7
16
+
3
17
  ## 0.4.4
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -33,6 +33,21 @@ import { FlashbotsClient } from "@asyncswap/eth-rpc";
33
33
 
34
34
  const rpc = "https://relay.flashbots.net";
35
35
  const client = new FlashbotsClient(rpc);
36
+ const bundle = {
37
+ txs: ["0x123abc", "0x456def..."] as Hex[],
38
+
39
+ blockNumber: "0xb63dcd" as Hex,
40
+ minTimestamp: 0,
41
+ maxTimestamp: 1615920932,
42
+ };
43
+ const body = client.rpc.buildRequest("eth_sendBundle", [bundle]);
44
+ // const signature = wallet.sign(body)
45
+ // const sender = wallet.address
46
+ client
47
+ .setHeaders({
48
+ "X-Flashbots-Signature": `0x<sender>:0x<signature>`,
49
+ })
50
+ .eth_sendBundle(bundle);
36
51
  ```
37
52
 
38
53
  ### Engine API Client
@@ -42,14 +57,9 @@ import { EngineExecutionClient } from '@asyncswap/eth-rpc';
42
57
 
43
58
  const engineUrl = 'https://localhost:8551';
44
59
  const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
45
- const payload = engine.engine_getPayloadV1("0x1");
60
+ const payload = await engine.engine_getPayloadV1("0x1");
46
61
 
47
62
  console.log(payload);
48
-
49
- import { FlashbotsClient } from '@asyncswap/eth-rpc';
50
-
51
- const rpc = 'https://relay.flashbots.net';
52
- const client = new FlashbotsClient(rpc);
53
63
  ```
54
64
 
55
65
  ## Error Handling
package/example.ts CHANGED
@@ -13,7 +13,11 @@ import { EngineExecutionClient } from "./src";
13
13
 
14
14
  const engineUrl = "https://localhost:8551";
15
15
  const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
16
- const payload = await engine.engine_getPayloadV1("0x1");
16
+ const payload = await engine
17
+ .setHeaders({
18
+ Authorization: `Bearer <jwt-token>`,
19
+ })
20
+ .engine_getPayloadV1("0x1");
17
21
 
18
22
  console.log(payload);
19
23
 
@@ -21,3 +25,18 @@ import { FlashbotsClient } from "./src";
21
25
 
22
26
  const rpc = "https://relay.flashbots.net";
23
27
  const client = new FlashbotsClient(rpc);
28
+ const bundle = {
29
+ txs: ["0x123abc", "0x456def..."] as Hex[],
30
+
31
+ blockNumber: "0xb63dcd" as Hex,
32
+ minTimestamp: 0,
33
+ maxTimestamp: 1615920932,
34
+ };
35
+ const body = client.rpc.buildRequest("eth_sendBundle", [bundle]);
36
+ // const signature = wallet.sign(body)
37
+ // const sender = wallet.address
38
+ client
39
+ .setHeaders({
40
+ "X-Flashbots-Signature": `0x<sender>:0x<signature>`,
41
+ })
42
+ .eth_sendBundle(bundle);
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.4",
5
+ "version": "0.4.6",
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.4"
44
+ "@asyncswap/jsonrpc": "^0.4.7"
45
45
  }
46
46
  }
package/src/base.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { JsonRpcClient } from "@asyncswap/jsonrpc";
2
+
3
+ export type RpcMethodSpec = {
4
+ params: readonly unknown[];
5
+ result: unknown;
6
+ };
7
+ export type RpcSpecBase = Record<string, RpcMethodSpec>;
8
+
9
+ export abstract class BaseClient<MethodsSpec extends RpcSpecBase> {
10
+ rpc: JsonRpcClient<MethodsSpec>;
11
+ protected headers: Record<string, string> = {};
12
+
13
+ constructor(url: string) {
14
+ this.rpc = new JsonRpcClient(url);
15
+
16
+ return new Proxy(this, {
17
+ get: (_: this, prop: string | symbol) => {
18
+ if (typeof prop !== "string") return undefined;
19
+
20
+ const method = prop as keyof MethodsSpec;
21
+
22
+ return (
23
+ ...params: MethodsSpec[typeof method]["params"]
24
+ ): MethodsSpec[typeof method]["result"] =>
25
+ this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
26
+ },
27
+ });
28
+ }
29
+
30
+ setHeaders(headers: Record<string, string>) {
31
+ this.headers = {
32
+ ...headers,
33
+ };
34
+ return this;
35
+ }
36
+ }
package/src/engine-api.ts CHANGED
@@ -1,37 +1,19 @@
1
- import { JsonRpcClient } from "@asyncswap/jsonrpc";
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
-
9
- export class EngineExecutionClient {
10
- rpc: JsonRpcClient;
11
- headers: Record<string, string>;
1
+ import { BaseClient } from "./base";
12
2
 
3
+ export class EngineExecutionClient extends BaseClient<EngineMethodsSpec> {
13
4
  constructor(url: string, jwt_token: string) {
5
+ super(url);
14
6
  this.headers = {
15
7
  Authorization: `Bearer ${jwt_token}`,
16
8
  };
17
- this.rpc = new JsonRpcClient(url);
18
-
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
- });
25
- }
26
-
27
- setHeaders(headers: Record<string, string>) {
28
- this.headers = {
29
- ...this.headers,
30
- ...headers,
31
- };
32
- return this;
33
9
  }
34
10
  }
35
11
 
12
+ export type EngineRpcMethods<
13
+ T extends Record<string, { params: unknown[]; result: unknown }>,
14
+ > = {
15
+ [K in keyof T]: (...params: T[K]["params"]) => Promise<T[K]["result"]>;
16
+ };
17
+
36
18
  export interface EngineExecutionClient
37
19
  extends EngineRpcMethods<EngineMethodsSpec> { }
package/src/eth-api.ts CHANGED
@@ -1,4 +1,10 @@
1
- import { JsonRpcClient } from "@asyncswap/jsonrpc";
1
+ import { BaseClient } from "./base";
2
+
3
+ export class ExecutionClient extends BaseClient<EthMethodsSpec> {
4
+ constructor(url: string) {
5
+ super(url);
6
+ }
7
+ }
2
8
 
3
9
  export type EthRpcMethods<
4
10
  T extends Record<string, { params: unknown[]; result: unknown }>,
@@ -6,30 +12,6 @@ export type EthRpcMethods<
6
12
  [K in keyof T]: (...params: T[K]["params"]) => Promise<T[K]["result"]>;
7
13
  };
8
14
 
9
- export class ExecutionClient {
10
- rpc: JsonRpcClient;
11
- headers: Record<string, string> = {};
12
-
13
- constructor(url: string) {
14
- this.rpc = new JsonRpcClient(url);
15
-
16
- return new Proxy(this, {
17
- get: (_, method: string) => {
18
- return (...params: unknown[]) =>
19
- this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
20
- },
21
- });
22
- }
23
-
24
- setAuth(headers: Record<string, string>) {
25
- this.headers = {
26
- ...this.headers,
27
- ...headers,
28
- };
29
- return this;
30
- }
31
- }
32
-
33
15
  export interface ExecutionClient extends EthRpcMethods<EthMethodsSpec> { }
34
16
 
35
17
  /**
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./base";
1
2
  export * from "./engine-api";
2
3
  export * from "./eth-api";
3
4
  export * from "./mev-api";
package/src/mev-api.ts CHANGED
@@ -1,28 +1,17 @@
1
- import { JsonRpcClient } from "@asyncswap/jsonrpc";
2
-
3
- export type FlashbotsRpcMethods<
4
- T extends Record<string, { params: unknown[]; result: unknown }>,
5
- > = {
6
- [M in keyof T]: (...params: T[M]["params"]) => Promise<T[M]["result"]>;
7
- };
8
-
9
- export class FlashbotsClient {
10
- rpc: JsonRpcClient;
11
- private headers: Record<string, string> = {};
1
+ import { BaseClient } from "./base";
12
2
 
3
+ export class FlashbotsClient extends BaseClient<FlashbotsMethodsSpec> {
13
4
  constructor(url: string) {
14
- this.rpc = new JsonRpcClient(url);
15
-
16
- return new Proxy(this, {
17
- get: (_, method: string) => {
18
- return (...params: unknown[]) =>
19
- this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
20
- },
21
- });
5
+ super(url);
22
6
  }
23
7
 
24
8
  // "X-Flashbots-Signature": `${sender}:${signature}`,
25
9
  }
26
10
 
11
+ export type FlashbotsRpcMethods<
12
+ T extends Record<string, { params: unknown[]; result: unknown }>,
13
+ > = {
14
+ [M in keyof T]: (...params: T[M]["params"]) => Promise<T[M]["result"]>;
15
+ };
27
16
  export interface FlashbotsClient
28
17
  extends FlashbotsRpcMethods<FlashbotsMethodsSpec> { }
@@ -0,0 +1,24 @@
1
+ declare global {
2
+ export type ClientVersionV1 = {
3
+ code: ClientCode;
4
+ name: string;
5
+ varsion: string;
6
+ commit: string;
7
+ };
8
+ export type ClientCode =
9
+ | "BU" // besu
10
+ | "EJ" // ethereumJs
11
+ | "EG" // erigon
12
+ | "GE" // go-ethereum
13
+ | "GR" // gradine
14
+ | "LH" // lighthouse
15
+ | "LS" // lodestar
16
+ | "NM" // nethermind
17
+ | "NB" // nimbus
18
+ | "TE" // thin-execution
19
+ | "TK" // teku
20
+ | "PM" // prysm
21
+ | "RH"; // reth
22
+ }
23
+
24
+ export { };
@@ -1,5 +1,11 @@
1
1
  declare global {
2
2
  export type EngineMethodsSpec = {
3
+ // identification
4
+ engine_getClientVersionV1: {
5
+ params: [ClientVersionV1];
6
+ result: ClientVersionV1[];
7
+ };
8
+ // share methods
3
9
  eth_blockNumber: { params: []; result: Uint };
4
10
  eth_call: {
5
11
  params: [GenericTransaction, BlockNumberOrTagOrHash];