Skip to content

Commit

Permalink
feat(contracts/script): operator registration script
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 18, 2024
1 parent eb29ff7 commit 4133ce6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 11 deletions.
5 changes: 5 additions & 0 deletions bolt-contracts/config/holesky/operator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rpc": "localhost:50051",
"salt": "0x000000000000000abc0000000000000000000000000000000000000000000000",
"expiry": null
}
6 changes: 3 additions & 3 deletions bolt-contracts/docs/admin/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.



Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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});
}
}

This file was deleted.

This file was deleted.

0 comments on commit 4133ce6

Please sign in to comment.