@@ -4,25 +4,27 @@ import { delegationABI } from "./abis/delegationABI";
4
4
import { contractABI } from './abis/contractABI' ;
5
5
import { registryABI } from './abis/registryABI' ;
6
6
import { avsDirectoryABI } from './abis/avsDirectoryABI' ;
7
+ import { RemoteSigner } from "./remoteSigner" ;
7
8
dotenv . config ( ) ;
8
9
10
+ const remoteSignerUrl = process . env . REMOTE_SIGNER_URL ! ;
11
+ const operatorAddress = process . env . OPERATOR_ADDRESS ! ;
9
12
const provider = new ethers . providers . JsonRpcProvider ( process . env . RPC_URL ) ;
10
13
const wallet = new ethers . Wallet ( process . env . PRIVATE_KEY ! , provider ) ;
14
+ const signer = new RemoteSigner ( operatorAddress , provider , remoteSignerUrl ) ;
15
+ let address = "" ;
11
16
12
17
const delegationManagerAddress = process . env . DELEGATION_MANAGER_ADDRESS ! ;
13
18
const contractAddress = process . env . CONTRACT_ADDRESS ! ;
14
19
const stakeRegistryAddress = process . env . STAKE_REGISTRY_ADDRESS ! ;
15
20
const avsDirectoryAddress = process . env . AVS_DIRECTORY_ADDRESS ! ;
16
21
17
- const remoteSignerUrl = process . env . REMOTE_SIGNER_URL ! ;
18
- const operatorAddress = process . env . OPERATOR_ADDRESS ! ;
19
-
20
22
const signerType = process . env . SIGNER_TYPE ! ;
21
23
22
- const delegationManager = new ethers . Contract ( delegationManagerAddress , delegationABI , wallet ) ;
23
- const contract = new ethers . Contract ( contractAddress , contractABI , wallet ) ;
24
- const registryContract = new ethers . Contract ( stakeRegistryAddress , registryABI , wallet ) ;
25
- const avsDirectory = new ethers . Contract ( avsDirectoryAddress , avsDirectoryABI , wallet ) ;
24
+ let delegationManager : ethers . Contract ;
25
+ let contract : ethers . Contract ;
26
+ let registryContract : ethers . Contract ;
27
+ let avsDirectory : ethers . Contract ;
26
28
27
29
const signAndRespondToTask = async ( taskIndex : number , taskCreatedBlock : number , taskName : string ) => {
28
30
const message = `Hello, ${ taskName } ` ;
@@ -35,11 +37,7 @@ const signAndRespondToTask = async (taskIndex: number, taskCreatedBlock: number,
35
37
signature = await wallet . signMessage ( messageBytes ) ;
36
38
} else if ( signerType === "remote" ) {
37
39
console . log ( "Using remote signer to sign message" )
38
- signature = await callJsonRpcEndpoint (
39
- remoteSignerUrl ,
40
- "eth_sign" ,
41
- [ operatorAddress , messageHash ]
42
- ) ;
40
+ signature = await signer . signMessage ( messageHash ) ;
43
41
}
44
42
45
43
console . log (
@@ -58,7 +56,7 @@ const signAndRespondToTask = async (taskIndex: number, taskCreatedBlock: number,
58
56
const registerOperator = async ( ) => {
59
57
console . log ( "check" )
60
58
const tx1 = await delegationManager . registerAsOperator ( {
61
- earningsReceiver : await wallet . address ,
59
+ earningsReceiver : address ,
62
60
delegationApprover : "0x0000000000000000000000000000000000000000" ,
63
61
stakerOptOutWindowBlocks : 0
64
62
} , "" ) ;
@@ -77,13 +75,15 @@ const registerOperator = async () => {
77
75
78
76
// Calculate the digest hash using the avsDirectory's method
79
77
const digestHash = await avsDirectory . calculateOperatorAVSRegistrationDigestHash (
80
- wallet . address ,
78
+ address ,
81
79
contract . address ,
82
80
salt ,
83
81
expiry
84
82
) ;
85
83
86
84
// // Sign the digest hash with the operator's private key
85
+ // TODO(shrimalmadhur): I am not completely sure about how to make this work with remote signer
86
+ // as the signDigest function is not available on the remote signer.
87
87
const signingKey = new ethers . utils . SigningKey ( process . env . PRIVATE_KEY ! ) ;
88
88
const signature = signingKey . signDigest ( digestHash ) ;
89
89
@@ -92,7 +92,7 @@ const registerOperator = async () => {
92
92
93
93
const tx2 = await registryContract . registerOperatorWithSignature (
94
94
operatorSignature ,
95
- wallet . address
95
+ address
96
96
) ;
97
97
await tx2 . wait ( ) ;
98
98
console . log ( "Operator registered on AVS successfully" ) ;
@@ -110,6 +110,19 @@ const monitorNewTasks = async () => {
110
110
} ;
111
111
112
112
const main = async ( ) => {
113
+ if ( signerType === "local" ) {
114
+ address = wallet . address ;
115
+ delegationManager = new ethers . Contract ( delegationManagerAddress , delegationABI , wallet ) ;
116
+ contract = new ethers . Contract ( contractAddress , contractABI , wallet ) ;
117
+ registryContract = new ethers . Contract ( stakeRegistryAddress , registryABI , wallet ) ;
118
+ avsDirectory = new ethers . Contract ( avsDirectoryAddress , avsDirectoryABI , wallet ) ;
119
+ } else {
120
+ address = await signer . getAddress ( ) ;
121
+ delegationManager = new ethers . Contract ( delegationManagerAddress , delegationABI , signer ) ;
122
+ contract = new ethers . Contract ( contractAddress , contractABI , signer ) ;
123
+ registryContract = new ethers . Contract ( stakeRegistryAddress , registryABI , signer ) ;
124
+ avsDirectory = new ethers . Contract ( avsDirectoryAddress , avsDirectoryABI , signer ) ;
125
+ }
113
126
await registerOperator ( ) ;
114
127
monitorNewTasks ( ) . catch ( ( error ) => {
115
128
console . error ( "Error monitoring tasks:" , error ) ;
0 commit comments