Skip to content

Commit

Permalink
refactor!(contracts): remove everything extra from BoltManager
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Sep 24, 2024
1 parent 3af4582 commit cf60814
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 95 deletions.
7 changes: 3 additions & 4 deletions bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.so
import {MapWithTimeData} from "../lib/MapWithTimeData.sol";
import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
import {IBoltMiddleware} from "../interfaces/IBoltMiddleware.sol";
import {IBoltManager} from "../interfaces/IBoltManager.sol";

import {IStrategyManager} from "@eigenlayer/src/contracts/interfaces/IStrategyManager.sol";
import {IAVSDirectory} from "@eigenlayer/src/contracts/interfaces/IAVSDirectory.sol";
Expand Down Expand Up @@ -268,8 +267,8 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
/// @return statuses The statuses of the proposers, including their operator and active stake.
function getProposersStatus(
bytes32[] memory pubkeyHashes
) public view returns (IBoltManager.ProposerStatus[] memory statuses) {
statuses = new IBoltManager.ProposerStatus[](pubkeyHashes.length);
) public view returns (IBoltValidators.ProposerStatus[] memory statuses) {
statuses = new IBoltValidators.ProposerStatus[](pubkeyHashes.length);
for (uint256 i = 0; i < pubkeyHashes.length; ++i) {
statuses[i] = getProposerStatus(pubkeyHashes[i]);
}
Expand All @@ -280,7 +279,7 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
/// @return status The status of the proposer, including their operator and active stake.
function getProposerStatus(
bytes32 pubkeyHash
) public view returns (IBoltManager.ProposerStatus memory status) {
) public view returns (IBoltValidators.ProposerStatus memory status) {
if (pubkeyHash == bytes32(0)) {
revert InvalidQuery();
}
Expand Down
48 changes: 5 additions & 43 deletions bolt-contracts/src/contracts/BoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ import {IEntity} from "@symbiotic/interfaces/common/IEntity.sol";

import {MapWithTimeData} from "../lib/MapWithTimeData.sol";
import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
import {IBoltManager} from "../interfaces/IBoltManager.sol";
import {IBoltMiddleware} from "../interfaces/IBoltMiddleware.sol";

contract BoltManager is IBoltManager, Ownable {
contract BoltManager is Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableMap for EnumerableMap.AddressToUintMap;
using MapWithTimeData for EnumerableMap.AddressToUintMap;
using Subnetwork for address;

// ========= ERRORS =========

error InvalidQuery();

// ========= STORAGE =========

/// @notice Validators registry, where validators are registered via their
Expand All @@ -37,46 +40,16 @@ contract BoltManager is IBoltManager, Ownable {
/// associated Bolt Middleware contract.
EnumerableSet.AddressSet private restakingProtocols;

// ========= IMMUTABLES =========

/// @notice Start timestamp of the first epoch.
uint48 public immutable START_TIMESTAMP;

// ========= CONSTANTS =========

/// @notice Duration of an epoch in seconds.
uint48 public constant EPOCH_DURATION = 1 days;

// ========= CONSTRUCTOR =========

/// @notice Constructor for the BoltManager contract.
/// @param _validators The address of the validators registry.
constructor(address _owner, address _validators) Ownable(_owner) {
validators = IBoltValidators(_validators);
START_TIMESTAMP = Time.timestamp();
}

// ========= VIEW FUNCTIONS =========

/// @notice Get the start timestamp of an epoch.
function getEpochStartTs(
uint48 epoch
) public view returns (uint48 timestamp) {
return START_TIMESTAMP + epoch * EPOCH_DURATION;
}

/// @notice Get the epoch at a given timestamp.
function getEpochAtTs(
uint48 timestamp
) public view returns (uint48 epoch) {
return (timestamp - START_TIMESTAMP) / EPOCH_DURATION;
}

/// @notice Get the current epoch.
function getCurrentEpoch() public view returns (uint48 epoch) {
return getEpochAtTs(Time.timestamp());
}

/// @notice Check if an operator address is authorized to work for a validator,
/// given the validator's pubkey hash. This function performs a lookup in the
/// validators registry to check if they explicitly authorized the operator.
Expand Down Expand Up @@ -113,15 +86,4 @@ contract BoltManager is IBoltManager, Ownable {
) public onlyOwner {
restakingProtocols.remove(address(protocolMiddleware));
}

// ========= HELPER FUNCTIONS =========

/// @notice Check if a map entry was active at a given timestamp.
/// @param enabledTime The enabled time of the map entry.
/// @param disabledTime The disabled time of the map entry.
/// @param timestamp The timestamp to check the map entry status at.
/// @return True if the map entry was active at the given timestamp, false otherwise.
function _wasEnabledAt(uint48 enabledTime, uint48 disabledTime, uint48 timestamp) private pure returns (bool) {
return enabledTime != 0 && enabledTime <= timestamp && (disabledTime == 0 || disabledTime >= timestamp);
}
}
7 changes: 3 additions & 4 deletions bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {IEntity} from "@symbiotic/interfaces/common/IEntity.sol";

import {MapWithTimeData} from "../lib/MapWithTimeData.sol";
import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
import {IBoltManager} from "../interfaces/IBoltManager.sol";
import {IBoltMiddleware} from "../interfaces/IBoltMiddleware.sol";

contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
Expand Down Expand Up @@ -283,8 +282,8 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
/// @return statuses The statuses of the proposers, including their operator and active stake.
function getProposersStatus(
bytes32[] memory pubkeyHashes
) public view returns (IBoltManager.ProposerStatus[] memory statuses) {
statuses = new IBoltManager.ProposerStatus[](pubkeyHashes.length);
) public view returns (IBoltValidators.ProposerStatus[] memory statuses) {
statuses = new IBoltValidators.ProposerStatus[](pubkeyHashes.length);
for (uint256 i = 0; i < pubkeyHashes.length; ++i) {
statuses[i] = getProposerStatus(pubkeyHashes[i]);
}
Expand All @@ -295,7 +294,7 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
/// @return status The status of the proposer, including their operator and active stake.
function getProposerStatus(
bytes32 pubkeyHash
) public view returns (IBoltManager.ProposerStatus memory status) {
) public view returns (IBoltValidators.ProposerStatus memory status) {
if (pubkeyHash == bytes32(0)) {
revert InvalidQuery();
}
Expand Down
34 changes: 0 additions & 34 deletions bolt-contracts/src/interfaces/IBoltManager.sol

This file was deleted.

5 changes: 2 additions & 3 deletions bolt-contracts/src/interfaces/IBoltMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.25;

import {BLS12381} from "../lib/bls/BLS12381.sol";
import {IBoltValidators} from "./IBoltValidators.sol";
import {IBoltManager} from "./IBoltManager.sol";

interface IBoltMiddleware {
error InvalidQuery();
Expand Down Expand Up @@ -54,11 +53,11 @@ interface IBoltMiddleware {

function getProposersStatus(
bytes32[] memory pubkeyHashes
) external view returns (IBoltManager.ProposerStatus[] memory);
) external view returns (IBoltValidators.ProposerStatus[] memory);

function getProposerStatus(
bytes32 pubkeyHash
) external view returns (IBoltManager.ProposerStatus memory);
) external view returns (IBoltValidators.ProposerStatus memory);

function isOperatorAuthorizedForValidator(address operator, bytes32 pubkeyHash) external view returns (bool);

Expand Down
8 changes: 8 additions & 0 deletions bolt-contracts/src/interfaces/IBoltValidators.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ interface IBoltValidators {
bool exists;
}

struct ProposerStatus {
bytes32 pubkeyHash;
bool active;
address operator;
address[] collaterals;
uint256[] amounts;
}

error InvalidBLSSignature();
error InvalidAuthorizedCollateralProvider();
error InvalidAuthorizedOperator();
Expand Down
8 changes: 4 additions & 4 deletions bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {BoltValidators} from "../src/contracts/BoltValidators.sol";
import {BoltManager} from "../src/contracts/BoltManager.sol";
import {BoltEigenLayerMiddleware} from "../src/contracts/BoltEigenLayerMiddleware.sol";
import {IBoltValidators} from "../src/interfaces/IBoltValidators.sol";
import {IBoltManager} from "../src/interfaces/IBoltManager.sol";
import {IBoltMiddleware} from "../src/interfaces/IBoltMiddleware.sol";

import {AVSDirectoryStorage} from "@eigenlayer/src/contracts/core/AVSDirectoryStorage.sol";
import {DelegationManagerStorage} from "@eigenlayer/src/contracts/core/DelegationManagerStorage.sol";
Expand Down Expand Up @@ -187,7 +187,7 @@ contract BoltManagerEigenLayerTest is Test {

bytes32 pubkeyHash = _pubkeyHash(validatorPubkey);

BoltManager.ProposerStatus memory status = middleware.getProposerStatus(pubkeyHash);
IBoltValidators.ProposerStatus memory status = middleware.getProposerStatus(pubkeyHash);
assertEq(status.pubkeyHash, pubkeyHash);
assertEq(status.operator, operator);
assertEq(status.active, true);
Expand All @@ -212,7 +212,7 @@ contract BoltManagerEigenLayerTest is Test {
validators.registerValidatorUnsafe(pubkey, staker, operator);
}

BoltManager.ProposerStatus[] memory statuses = middleware.getProposersStatus(pubkeyHashes);
IBoltValidators.ProposerStatus[] memory statuses = middleware.getProposersStatus(pubkeyHashes);
assertEq(statuses.length, 10);
}

Expand Down Expand Up @@ -240,7 +240,7 @@ contract BoltManagerEigenLayerTest is Test {

address strat = address(eigenLayerDeployer.wethStrat());
vm.startPrank(admin);
vm.expectRevert(IBoltManager.CollateralNotWhitelisted.selector);
vm.expectRevert(IBoltMiddleware.CollateralNotWhitelisted.selector);
middleware.registerStrategy(strat);
vm.stopPrank();
}
Expand Down
5 changes: 2 additions & 3 deletions bolt-contracts/test/BoltManager.Symbiotic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {IMigratablesFactory} from "@symbiotic/interfaces/common/IMigratablesFact
import {Subnetwork} from "@symbiotic/contracts/libraries/Subnetwork.sol";
import {SimpleCollateral} from "@symbiotic/../test/mocks/SimpleCollateral.sol";

import {IBoltManager} from "../src/interfaces/IBoltManager.sol";
import {IBoltValidators} from "../src/interfaces/IBoltValidators.sol";
import {IBoltMiddleware} from "../src/interfaces/IBoltMiddleware.sol";

Expand Down Expand Up @@ -308,7 +307,7 @@ contract BoltManagerTest is Test {
vm.warp(block.timestamp + EPOCH_DURATION * 2 + 1);
assertEq(vault.currentEpoch(), 2);

BoltManager.ProposerStatus memory status = middleware.getProposerStatus(pubkeyHash);
IBoltValidators.ProposerStatus memory status = middleware.getProposerStatus(pubkeyHash);
assertEq(status.pubkeyHash, pubkeyHash);
assertEq(status.operator, operator);
assertEq(status.active, true);
Expand Down Expand Up @@ -336,7 +335,7 @@ contract BoltManagerTest is Test {
vm.warp(block.timestamp + EPOCH_DURATION * 2 + 1);
assertEq(vault.currentEpoch(), 2);

BoltManager.ProposerStatus[] memory statuses = middleware.getProposersStatus(pubkeyHashes);
IBoltValidators.ProposerStatus[] memory statuses = middleware.getProposersStatus(pubkeyHashes);
assertEq(statuses.length, 10);
}

Expand Down

0 comments on commit cf60814

Please sign in to comment.