@asyncswap/eth-rpc 0.4.4 → 0.4.5
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 +8 -0
- package/README.md +1 -1
- package/example.ts +20 -0
- package/package.json +2 -2
- package/src/base.ts +34 -0
- package/src/engine-api.ts +9 -27
- package/src/eth-api.ts +7 -25
- package/src/index.ts +1 -0
- package/src/mev-api.ts +8 -19
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ import { EngineExecutionClient } from '@asyncswap/eth-rpc';
|
|
|
42
42
|
|
|
43
43
|
const engineUrl = 'https://localhost:8551';
|
|
44
44
|
const engine = new EngineExecutionClient(engineUrl, process.env.JWT_TOKEN!);
|
|
45
|
-
const payload = engine.engine_getPayloadV1("0x1");
|
|
45
|
+
const payload = await engine.engine_getPayloadV1("0x1");
|
|
46
46
|
|
|
47
47
|
console.log(payload);
|
|
48
48
|
|
package/example.ts
CHANGED
|
@@ -21,3 +21,23 @@ import { FlashbotsClient } from "./src";
|
|
|
21
21
|
|
|
22
22
|
const rpc = "https://relay.flashbots.net";
|
|
23
23
|
const client = new FlashbotsClient(rpc);
|
|
24
|
+
const body = client.rpc.buildRequest("eth_sendBundle", [
|
|
25
|
+
{
|
|
26
|
+
txs: ["0x123abc", "0x456def..."],
|
|
27
|
+
blockNumber: "0xb63dcd",
|
|
28
|
+
minTimestamp: 0,
|
|
29
|
+
maxTimestamp: 1615920932,
|
|
30
|
+
} as EthSendBundleParams,
|
|
31
|
+
]);
|
|
32
|
+
// const signature = wallet.sign(body)
|
|
33
|
+
// const signature = wallet.address
|
|
34
|
+
client
|
|
35
|
+
.setHeaders({
|
|
36
|
+
"X-Flashbots-Signature": `0x<sender>:0x<signature>`,
|
|
37
|
+
})
|
|
38
|
+
.eth_sendBundle({
|
|
39
|
+
txs: ["0x123abc...", "0x456def..."],
|
|
40
|
+
blockNumber: "0xb63dcd",
|
|
41
|
+
minTimestamp: 0,
|
|
42
|
+
maxTimestamp: 1615920932,
|
|
43
|
+
});
|
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.5",
|
|
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.7"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/base.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 (...params: MethodsSpec[typeof method]["params"]) =>
|
|
23
|
+
this.rpc.call(this.rpc.buildRequest(method, params), this.headers);
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setHeaders(headers: Record<string, string>) {
|
|
29
|
+
this.headers = {
|
|
30
|
+
...headers,
|
|
31
|
+
};
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/engine-api.ts
CHANGED
|
@@ -1,37 +1,19 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
package/src/mev-api.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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> { }
|