-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathregister-executor.ts
More file actions
140 lines (124 loc) · 3.98 KB
/
register-executor.ts
File metadata and controls
140 lines (124 loc) · 3.98 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
Address,
ConsoleExecutorConfig,
ConsoleKit,
KernelExecutorConfig
} from "brahma-console-kit";
import { ethers, Wallet } from "ethers";
import { ExecutorMetadata } from "./entity";
const ExecutorEoaPK = process.env.EXECUTOR_EOA_PRIVATE_KEY!;
const JsonRpcUrl = process.env.JSON_RPC_URL!;
const ConsoleApiKey = process.env.CONSOLE_API_KEY!;
const ConsoleBaseUrl = process.env.CONSOLE_BASE_URL!;
const ExecutorClientID = process.env.EXECUTOR_CLIENT_ID!;
/// configure according to required executor config for console registration
const ExecutorConfigConsole: ConsoleExecutorConfig = {
clientId: ExecutorClientID,
executor: ethers.computeAddress(ExecutorEoaPK),
feeReceiver: ethers.ZeroAddress as Address,
hopAddresses: ["0xAE75B29ADe678372D77A8B41225654138a7E6ff1"], // addresses that tokens will be moved through during execution
inputTokens: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], // base usdc
limitPerExecution: true,
timestamp: new Date().getTime()
};
/// configure according to required executor metadata
const ExecutorMetadata: ExecutorMetadata = {
name: "scaffold-agent-executor",
logo: "",
metadata: {}
};
/// configure according to required executor config for kernel registration
const ExecutorConfigKernel: KernelExecutorConfig = {
defaultEvery: "120s",
executionTTL: "120s",
type: "INTERVAL"
};
const registerExecutor = async (
_consoleKit: ConsoleKit,
_chainId: number,
_executorWallet: Wallet,
_executorConfig: ConsoleExecutorConfig,
_executorMetadata: ExecutorMetadata
) => {
const { domain, message, types } =
await _consoleKit.automationContext.generateConsoleExecutorRegistration712Message(
_chainId,
_executorConfig
);
const executorRegistrationSignature = await _executorWallet.signTypedData(
domain,
types,
message
);
console.log("[executor-console-sig]", executorRegistrationSignature);
try {
const executorData =
await _consoleKit.automationContext.registerExecutorOnConsole(
executorRegistrationSignature,
_chainId,
_executorConfig,
_executorMetadata.name,
_executorMetadata.logo,
_executorMetadata.metadata
);
if (!executorData) throw new Error("register executor on console fail");
console.log("[executor-reg]", { executorData });
return executorData;
} catch (e) {
console.log(e);
throw new Error("register executor on console fail");
}
};
const registerExecutorOnKernel = async (
_consoleKit: ConsoleKit,
_chainId: number,
_executorWallet: Wallet,
_registryId: string,
_executorConfig: KernelExecutorConfig
) => {
const { domain, message, types } =
await _consoleKit.automationContext.generateKernelExecutorRegistration712Message(
_chainId,
_registryId,
_executorConfig
);
const executorRegistrationSignature = await _executorWallet.signTypedData(
domain,
types,
message
);
console.log("[executor-kernel-sig]", executorRegistrationSignature);
try {
await _consoleKit.automationContext.registerExecutorOnKernel(
_registryId,
executorRegistrationSignature,
_executorConfig
);
} catch (e) {
console.log(e);
throw new Error("register executor on kernel fail");
}
return await _consoleKit.automationContext.fetchExecutorDetails(_registryId);
};
(async () => {
const consoleKit = new ConsoleKit(ConsoleApiKey, ConsoleBaseUrl);
const provider = new ethers.JsonRpcProvider(JsonRpcUrl);
const executorWallet = new ethers.Wallet(ExecutorEoaPK, provider);
const { chainId: chainIdBig } = await provider.getNetwork();
const chainId = parseInt(chainIdBig.toString(), 10);
const { id: registryId } = await registerExecutor(
consoleKit,
chainId,
executorWallet,
ExecutorConfigConsole,
ExecutorMetadata
);
const registeredExecutorData = await registerExecutorOnKernel(
consoleKit,
chainId,
executorWallet,
registryId,
ExecutorConfigKernel
);
console.log("[complete]", { registeredExecutorData });
})();