Skip to content

Commit

Permalink
feat(contracts/symbiotic): pull in changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Jan 21, 2025
1 parent 0d2b66a commit a3967a4
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
Expand All @@ -22,6 +22,7 @@ import {INetworkMiddlewareService} from "@symbiotic/core/interfaces/service/INet
import {PauseableEnumerableSet} from "@symbiotic/middleware-sdk/libraries/PauseableEnumerableSet.sol";

import {IOperatorsRegistryV1} from "../interfaces/IOperatorsRegistryV1.sol";
import {IBoltRestakingMiddlewareV1} from "../interfaces/IBoltRestakingMiddlewareV1.sol";

/**
* @title SymbioticMiddlewareV1
Expand All @@ -35,7 +36,7 @@ import {IOperatorsRegistryV1} from "../interfaces/IOperatorsRegistryV1.sol";
* For more information on extensions, see <https://docs.symbiotic.fi/middleware-sdk/extensions>.
* All public view functions are implemented in the `BaseMiddlewareReader`: <https://docs.symbiotic.fi/middleware-sdk/api-reference/middleware/BaseMiddlewareReader>
*/
contract BoltSymbioticMiddlewareV1 is OwnableUpgradeable, UUPSUpgradeable {
contract BoltSymbioticMiddlewareV1 is IBoltRestakingMiddlewareV1, OwnableUpgradeable, UUPSUpgradeable {
using Subnetwork for address;
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableMap for EnumerableMap.AddressToAddressMap;
Expand All @@ -46,6 +47,9 @@ contract BoltSymbioticMiddlewareV1 is OwnableUpgradeable, UUPSUpgradeable {
// Most of these constants replicate view methods in the BaseMiddlewareReader.
// See <https://docs.symbiotic.fi/middleware-sdk/api-reference/middleware/BaseMiddlewareReader> for more information.

/// @notice The name hash of this middleware.
bytes32 public NAME_HASH;

/// @notice The timestamp of the first epoch (when this contract gets initialized).
uint48 public START_TIMESTAMP;

Expand Down Expand Up @@ -147,6 +151,7 @@ contract BoltSymbioticMiddlewareV1 is OwnableUpgradeable, UUPSUpgradeable {
OPERATOR_REGISTRY = operatorRegistry;
OPERATOR_NET_OPTIN = operatorNetOptin;
START_TIMESTAMP = _now();
NAME_HASH = keccak256("SYMBIOTIC");
}

function _authorizeUpgrade(
Expand Down
46 changes: 33 additions & 13 deletions smart-contracts/src/holesky/contracts/OperatorsRegistryV1.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";

import {IOperatorsRegistryV1} from "../interfaces/IOperatorsRegistryV1.sol";
import {IBoltRestakingMiddlewareV1} from "../interfaces/IBoltRestakingMiddlewareV1.sol";
import {OperatorsLibV1} from "../lib/OperatorsLibV1.sol";

/// @title OperatorsRegistryV1
/// @notice A smart contract to store and manage Bolt operators
contract OperatorsRegistryV1 is OwnableUpgradeable, UUPSUpgradeable, IOperatorsRegistryV1 {
using OperatorsLibV1 for OperatorsLibV1.OperatorMap;

/// @notice The start timestamp of the contract, used as reference for time-based operations
uint48 public START_TIMESTAMP;

/// @notice The duration of an epoch in seconds, used for delaying opt-in/out operations
uint48 public EPOCH_DURATION;

/// @notice The set of bolt operators, indexed by their signer address
OperatorsLibV1.OperatorMap private OPERATORS;

/// @notice the address of the EigenLayer restaking middleware
address public EIGENLAYER_RESTAKING_MIDDLEWARE;
IBoltRestakingMiddlewareV1 public EIGENLAYER_RESTAKING_MIDDLEWARE;

/// @notice The address of the Symbiotic restaking middleware
address public SYMBIOTIC_RESTAKING_MIDDLEWARE;
IBoltRestakingMiddlewareV1 public SYMBIOTIC_RESTAKING_MIDDLEWARE;

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -29,16 +37,17 @@ contract OperatorsRegistryV1 is OwnableUpgradeable, UUPSUpgradeable, IOperatorsR
*
* Total storage slots: 50
*/
uint256[45] private __gap;
uint256[43] private __gap;

// ========= Initializer & Proxy functionality ========= //

/// @notice Initialize the contract
/// @param owner The address of the owner
function initialize(
address owner
) public initializer {
function initialize(address owner, uint48 epochDuration) public initializer {
__Ownable_init(owner);

START_TIMESTAMP = uint48(block.timestamp);
EPOCH_DURATION = epochDuration;
}

/// @notice Upgrade the contract
Expand All @@ -59,15 +68,23 @@ contract OperatorsRegistryV1 is OwnableUpgradeable, UUPSUpgradeable, IOperatorsR
_;
}

// ========= Public helpers ========= //

/// @notice Returns the timestamp of when the current epoch started
function getCurrentEpochStartTimestamp() public view returns (uint48) {
uint48 currentEpoch = (Time.timestamp() - START_TIMESTAMP) / EPOCH_DURATION;
return START_TIMESTAMP + currentEpoch * EPOCH_DURATION;
}

// ========= Operators functions ========= //
//
// The operator lifecycle looks as follows:
// 1. Register, and become active immediately. The operator can then manage their
// restaking positions through the EL AllocationManager contract.
// 2. Pause, and become inactive (with a delay). The operator won't be slashable anymore,
// restaking positions through the restaking protocol.
// 2. Pause, and become inactive. After a delay, the operator won't be slashable anymore,
// but they can still manage and rebalance their positions.
// 3. Unpause, and become active again (with a delay). The operator can be slashed again.
// 4. Deregister, and become inactive (with a delay). The operator won't be part of the AVS anymore.
// 3. Unpause, and become active again. After a delay, the operator can be slashed again.
// 4. Deregister, and become inactive. After a delay, the operator won't be part of the AVS anymore.

/// @notice Register an operator in the registry
/// @param signer The address of the operator
Expand Down Expand Up @@ -151,8 +168,11 @@ contract OperatorsRegistryV1 is OwnableUpgradeable, UUPSUpgradeable, IOperatorsR
/// @notice Update the address of a restaking middleware contract address
/// @param restakingProtocol The name of the restaking protocol
/// @param newMiddleware The address of the new restaking middleware
function updateRestakingMiddleware(string calldata restakingProtocol, address newMiddleware) public onlyOwner {
require(newMiddleware != address(0), "Invalid middleware address");
function updateRestakingMiddleware(
string calldata restakingProtocol,
IBoltRestakingMiddlewareV1 newMiddleware
) public onlyOwner {
require(address(newMiddleware) != address(0), "Invalid middleware address");

bytes32 protocolNameHash = keccak256(abi.encodePacked(restakingProtocol));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

/// @title IBoltRestakingMiddlewareV1
/// @notice An interface for generalized restaking protocol middlewares in Bolt
interface IBoltRestakingMiddlewareV1 {
function NAME_HASH() external view returns (bytes32);

function getOperatorCollaterals(
address operator
) external view returns (address[] memory, uint256[] memory);

function getOperatorStake(address operator, address collateral) external view returns (uint256);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

/// @title IOperatorsRegistryV1
/// @notice An interface for the OperatorsRegistryV1 contract
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/src/holesky/lib/OperatorsLibV1.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

import {PauseableEnumerableSet} from "@symbiotic/middleware-sdk/libraries/PauseableEnumerableSet.sol";

Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/test/holesky/OperatorsRegistryV1.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

import {Test, console} from "forge-std/Test.sol";
import {OperatorsRegistryV1} from "../../src/holesky/contracts/OperatorsRegistryV1.sol";
Expand Down
6 changes: 3 additions & 3 deletions smart-contracts/test/holesky/SymbioticMiddleware.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
pragma solidity ^0.8.27;

import {Test, console} from "forge-std/Test.sol";

Expand Down Expand Up @@ -51,11 +51,11 @@ contract SymbioticMiddlewareTest is Test {
vm.startPrank(admin);

registry = new OperatorsRegistryV1();
registry.initialize(admin);
registry.initialize(admin, 1 days);

middleware = new BoltSymbioticMiddlewareV1();
// Set the restaking middleware
registry.updateRestakingMiddleware("SYMBIOTIC", address(middleware));
registry.updateRestakingMiddleware("SYMBIOTIC", middleware);

vm.stopPrank();

Expand Down

0 comments on commit a3967a4

Please sign in to comment.