-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaaBundler.ts
55 lines (49 loc) · 2.4 KB
/
aaBundler.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import _ from "lodash";
import path from "path";
import process from "process";
import { task } from "hardhat/config";
import { deriveAccounts, networkRpcUrlFromDocker, runDockerCompose } from "../helpers";
export const TASK_BUNDLER = "aa-bundler";
task(TASK_BUNDLER, "Launch local Klaytn bundler")
.addOptionalParam("host", "HTTP JSON-RPC hostname", "0.0.0.0")
.addOptionalParam("port", "HTTP JSON-RPC port", "4337")
.addFlag("attachRemote", "Allow attach to remote RPC endpoint (may incur costs)")
.addOptionalParam("dockerImageId", "Docker image id", "stackupwallet/stackup-bundler:latest")
.addOptionalParam("entrypoints", "Comma-separated list of EntryPoint addresses", "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789")
.addOptionalParam("mnemonic", "Bundler account mnemonic", "test test test test test test test test test test test junk")
.addOptionalParam("derivationPath", "Bundler account derivation path", "m/44'/60'/0'/0/")
.addOptionalParam("index", "Bundler account index under the derivation path", "0")
.addOptionalParam("privkey", "Bundler account private key without hex prefix. Has priority over mnemonic.")
.setAction(async (taskArgs) => {
const { host, port, dockerImageId, attachRemote, entrypoints, mnemonic, derivationPath, index, privkey} = taskArgs;
const dir = path.resolve(__dirname, "../fixtures/bundler");
process.chdir(dir);
const rpcUrl = await networkRpcUrlFromDocker(attachRemote);
const accounts = deriveAccounts({
mnemonic: mnemonic,
path: derivationPath,
initialIndex: parseInt(index),
count: 1,
})
const privateKey = privkey ?? accounts[0].privateKey.substring(2);
const extraEnvs = {
"DOCKER_IMAGE": dockerImageId,
"DOCKER_LISTEN": `${host}:${port}`,
"BUNDLER_NODE_RPC": rpcUrl,
"BUNDLER_PRIVATE_KEY": privateKey,
"BUNDLER_ENTRYPOINT": entrypoints,
}
_.assign(process.env, extraEnvs);
console.log("[+] Using env:", extraEnvs);
console.log("[+] Starting ERC-4337 bundler at", `http://${host}:${port}/`);
// Having an empty SIGINT handler prevents this task to quit on Ctrl+C.
// This task is supposed to quit after docker-compose down.
process.on('SIGINT', () => {});
try {
// --force-recreate to remove old database and start over
runDockerCompose("up --force-recreate");
} catch (e) {
runDockerCompose("kill");
runDockerCompose("down");
}
});