From 4133ce6a63b09b2407593119ba33ab3e3ae8c003 Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Fri, 18 Oct 2024 16:57:05 +0200 Subject: [PATCH] feat(contracts/script): operator registration script --- bolt-contracts/config/holesky/operator.json | 5 ++ bolt-contracts/docs/admin/deploying.md | 6 +- .../RegisterEigenLayerOperator.s.sol | 88 +++++++++++++++++++ .../holesky/validators/RegisterOperator.s.sol | 4 - .../validators/RegisterValidators.s.sol | 4 - 5 files changed, 96 insertions(+), 11 deletions(-) create mode 100644 bolt-contracts/config/holesky/operator.json create mode 100644 bolt-contracts/script/holesky/validators/RegisterEigenLayerOperator.s.sol delete mode 100644 bolt-contracts/script/holesky/validators/RegisterOperator.s.sol delete mode 100644 bolt-contracts/script/holesky/validators/RegisterValidators.s.sol diff --git a/bolt-contracts/config/holesky/operator.json b/bolt-contracts/config/holesky/operator.json new file mode 100644 index 000000000..0b6373c92 --- /dev/null +++ b/bolt-contracts/config/holesky/operator.json @@ -0,0 +1,5 @@ +{ + "rpc": "localhost:50051", + "salt": "0x000000000000000abc0000000000000000000000000000000000000000000000", + "expiry": null +} \ No newline at end of file diff --git a/bolt-contracts/docs/admin/deploying.md b/bolt-contracts/docs/admin/deploying.md index 8cb11783e..36f448f35 100644 --- a/bolt-contracts/docs/admin/deploying.md +++ b/bolt-contracts/docs/admin/deploying.md @@ -5,8 +5,8 @@ ## Configuration There are 2 JSON configuration files: -- [`config/holesky/deployments.json`](../config/holesky/deployments.json): contains deployment addresses of EigenLayer ([here](https://github.com/Layr-Labs/eigenlayer-contracts/blob/dev/README.md#deployments)) and Symbiotic ([here](https://docs.symbiotic.fi/deployments)). -- [`config/holesky/parameters.json`](../config/holesky/parameters.json): contains the launch parameters for `BoltParameters`. +- [`config/holesky/deployments.json`](../../config/holesky/deployments.json): contains deployment addresses of EigenLayer ([here](https://github.com/Layr-Labs/eigenlayer-contracts/blob/dev/README.md#deployments)) and Symbiotic ([here](https://docs.symbiotic.fi/deployments)). +- [`config/holesky/parameters.json`](../../config/holesky/parameters.json): contains the launch parameters for `BoltParameters`. @@ -37,7 +37,7 @@ export ADMIN_PRIVATE_KEY=0x... Register a Symbiotic network for Bolt with the Symbiotic `NetworkRegistry`. The private key with which the script is run will determine the network address. This private key will also need to be used later. ```bash -forge script script/holesky/admin/helpers/Symbiotic.s.sol $HOLESKY_RPC --private-key $NETWORK_PRIVATE_KEY --broadcast -vvvv --sig "run(string memory arg)" registerNetwork +forge script script/holesky/admin/helpers/Symbiotic.s.sol --rpc-url $HOLESKY_RPC --private-key $NETWORK_PRIVATE_KEY --broadcast -vvvv --sig "run(string memory arg)" registerNetwork ``` Make sure `deployments.json` contains the correct address for the Symbiotic network. diff --git a/bolt-contracts/script/holesky/validators/RegisterEigenLayerOperator.s.sol b/bolt-contracts/script/holesky/validators/RegisterEigenLayerOperator.s.sol new file mode 100644 index 000000000..d72cb52dd --- /dev/null +++ b/bolt-contracts/script/holesky/validators/RegisterEigenLayerOperator.s.sol @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.25; + +import {Script, console} from "forge-std/Script.sol"; + +import {IAVSDirectory} from "@eigenlayer/src/contracts/interfaces/IAVSDirectory.sol"; +import {ISignatureUtils} from "@eigenlayer/src/contracts/interfaces/ISignatureUtils.sol"; + +import {BoltEigenLayerMiddlewareV1} from "../../../src/contracts/BoltEigenLayerMiddlewareV1.sol"; + +contract RegisterEigenLayerOperator is Script { + struct OperatorConfig { + string rpc; + bytes32 salt; + uint256 expiry; + } + + function run() public { + uint256 operatorSk = vm.envUint("OPERATOR_SK"); + + address operator = vm.addr(operatorSk); + + BoltEigenLayerMiddlewareV1 middleware = _readMiddleware(); + IAVSDirectory avsDirectory = _readAvsDirectory(); + OperatorConfig memory config = _readConfig("config/holesky/operator.json"); + + console.log("Registering EigenLayer operator"); + console.log("Operator address:", operator); + + vm.startBroadcast(operatorSk); + + bytes32 digest = avsDirectory.calculateOperatorAVSRegistrationDigestHash({ + operator: operator, + avs: address(middleware), + salt: config.salt, + expiry: config.expiry + }); + + (uint8 v, bytes32 r, bytes32 s) = vm.sign(operatorSk, digest); + bytes memory rawSignature = abi.encodePacked(r, s, v); + + ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = + ISignatureUtils.SignatureWithSaltAndExpiry(rawSignature, config.salt, config.expiry); + + middleware.registerOperator(config.rpc, operatorSignature); + + vm.stopBroadcast(); + } + + function _readMiddleware() public view returns (BoltEigenLayerMiddlewareV1) { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/config/holesky/deployments.json"); + string memory json = vm.readFile(path); + + return BoltEigenLayerMiddlewareV1(vm.parseJsonAddress(json, ".eigenLayer.networkMiddleware")); + } + + function _readAvsDirectory() public view returns (IAVSDirectory) { + string memory root = vm.projectRoot(); + string memory path = string.concat(root, "/config/holesky/deployments.json"); + string memory json = vm.readFile(path); + + return IAVSDirectory(vm.parseJsonAddress(json, ".eigenLayer.avsDirectory")); + } + + function _readConfig( + string memory path + ) public view returns (OperatorConfig memory) { + string memory json = vm.readFile(path); + + bytes32 salt = bytes32(0); + uint256 expiry = UINT256_MAX; + + try vm.parseJsonBytes32(json, ".salt") returns (bytes32 val) { + salt = val; + } catch { + console.log("No salt found in config, using 0"); + } + + try vm.parseJsonUint(json, ".expiry") returns (uint256 val) { + expiry = val; + } catch { + console.log("No expiry found in config, using UINT256_MAX"); + } + + return OperatorConfig({rpc: vm.parseJsonString(json, ".rpc"), salt: salt, expiry: expiry}); + } +} diff --git a/bolt-contracts/script/holesky/validators/RegisterOperator.s.sol b/bolt-contracts/script/holesky/validators/RegisterOperator.s.sol deleted file mode 100644 index 16adbc6d2..000000000 --- a/bolt-contracts/script/holesky/validators/RegisterOperator.s.sol +++ /dev/null @@ -1,4 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.25; - -import {Script, console} from "forge-std/Script.sol"; diff --git a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol b/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol deleted file mode 100644 index 16adbc6d2..000000000 --- a/bolt-contracts/script/holesky/validators/RegisterValidators.s.sol +++ /dev/null @@ -1,4 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.25; - -import {Script, console} from "forge-std/Script.sol";