@asyncswap/eth-rpc 0.4.3 → 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 +16 -0
- package/README.md +3 -3
- package/example.ts +23 -6
- package/package.json +2 -2
- package/src/base.ts +34 -0
- package/src/engine-api.ts +9 -27
- package/src/eth-api.ts +13 -25
- package/src/index.ts +1 -0
- package/src/mev-api.ts +8 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @asyncswap/eth-rpc
|
|
2
2
|
|
|
3
|
+
## 0.4.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0d1be5d: upgrade with parameter typing
|
|
8
|
+
- Updated dependencies [882f94f]
|
|
9
|
+
- @asyncswap/jsonrpc@0.4.7
|
|
10
|
+
|
|
11
|
+
## 0.4.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- b2b631f: deprecated `EthExecutionClien` use `ExecutionClient`
|
|
16
|
+
- Updated dependencies [f7d28d9]
|
|
17
|
+
- @asyncswap/jsonrpc@0.4.4
|
|
18
|
+
|
|
3
19
|
## 0.4.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
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 {
|
|
16
|
+
import { ExecutionClient } from '@asyncswap/eth-rpc';
|
|
17
17
|
|
|
18
18
|
const url = 'http://localhost:8545'
|
|
19
|
-
const eth = new
|
|
19
|
+
const eth = new ExecutionClient(url);
|
|
20
20
|
|
|
21
21
|
const balance = await eth.eth_getBalance(
|
|
22
22
|
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
@@ -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
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExecutionClient } from "./src";
|
|
2
2
|
|
|
3
3
|
const url = "http://localhost:8545";
|
|
4
|
-
const eth = new
|
|
5
|
-
|
|
4
|
+
const eth = new ExecutionClient(url);
|
|
6
5
|
const balance = await eth.eth_getBalance(
|
|
7
6
|
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
8
7
|
"latest",
|
|
@@ -14,7 +13,7 @@ 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
|
|
|
@@ -22,5 +21,23 @@ import { FlashbotsClient } from "./src";
|
|
|
22
21
|
|
|
23
22
|
const rpc = "https://relay.flashbots.net";
|
|
24
23
|
const client = new FlashbotsClient(rpc);
|
|
25
|
-
const body = client.rpc.buildRequest("eth_sendBundle", [
|
|
26
|
-
|
|
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,28 +12,10 @@ export type EthRpcMethods<
|
|
|
6
12
|
[K in keyof T]: (...params: T[K]["params"]) => Promise<T[K]["result"]>;
|
|
7
13
|
};
|
|
8
14
|
|
|
9
|
-
export
|
|
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
|
-
}
|
|
15
|
+
export interface ExecutionClient extends EthRpcMethods<EthMethodsSpec> { }
|
|
32
16
|
|
|
33
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use `ExecutionClient` instead.
|
|
19
|
+
* This method will be removed in v0.5.0.
|
|
20
|
+
*/
|
|
21
|
+
export class EthExecutionClient extends ExecutionClient { }
|
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> { }
|