Skip to content

Commit

Permalink
feat(contracts): implement UUPSProxy everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 9, 2024
1 parent 5e37a6b commit 242df15
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 50 deletions.
4 changes: 2 additions & 2 deletions bolt-contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ remappings = [
"@relic/=lib/relic-sdk/packages/contracts",
"@symbiotic/=lib/core/src/",
"@eigenlayer/=lib/eigenlayer-contracts/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin/contracts-upgradeable=lib/openzeppelin-contracts-upgradeable/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",

# Symbiotic remappings contexts
"lib/core/:forge-std/=lib/core/lib/forge-std/src/",
Expand Down
37 changes: 21 additions & 16 deletions bolt-contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,42 +32,47 @@ contract DeployBolt is Script {
// on the underlying implementations through the proxy.
// We can however call them directly if needed.

address validatorsImplementation = address(new BoltValidators(admin));
address validatorsImplementation = address(new BoltValidators());
console.log("BoltValidators implementation deployed at", validatorsImplementation);

address validatorsProxy = address(new ERC1967Proxy(validatorsImplementation, ""));
bytes memory initValidators = abi.encodeCall(BoltValidators.initialize, admin);
address validatorsProxy = address(new ERC1967Proxy(validatorsImplementation, initValidators));
console.log("BoltValidators proxy deployed at", validatorsProxy);

address managerImplementation = address(new BoltManager(admin, validatorsProxy));
address managerImplementation = address(new BoltManager());
console.log("BoltManager implementation deployed at", managerImplementation);

address managerProxy = address(new ERC1967Proxy(managerImplementation, ""));
bytes memory initManager = abi.encodeCall(BoltManager.initialize, (admin, validatorsProxy));
address managerProxy = address(new ERC1967Proxy(managerImplementation, initManager));
console.log("BoltManager proxy deployed at", managerProxy);

address eigenLayerMiddlewareImplementation = address(
new BoltEigenLayerMiddleware(
admin, managerProxy, eigenlayerAVSDirectory, eigenlayerDelegationManager, eigenlayerStrategyManager
)
);
address eigenLayerMiddlewareImplementation = address(new BoltEigenLayerMiddleware());

console.log("BoltEigenLayerMiddleware implementation deployed at", eigenLayerMiddlewareImplementation);

address eigenLayerMiddlewareProxy = address(new ERC1967Proxy(eigenLayerMiddlewareImplementation, ""));
bytes memory initEigenLayerMiddleware = abi.encodeCall(
BoltEigenLayerMiddleware.initialize,
(admin, managerProxy, eigenlayerAVSDirectory, eigenlayerDelegationManager, eigenlayerStrategyManager)
);
address eigenLayerMiddlewareProxy =
address(new ERC1967Proxy(eigenLayerMiddlewareImplementation, initEigenLayerMiddleware));
console.log("BoltEigenLayerMiddleware proxy deployed at", eigenLayerMiddlewareProxy);

address symbioticMiddleware = address(
new BoltSymbioticMiddleware(
address symbioticMiddleware = address(new BoltSymbioticMiddleware());
console.log("BoltSymbioticMiddleware deployed at", address(symbioticMiddleware));

bytes memory initSymbioticMiddleware = abi.encodeCall(
BoltSymbioticMiddleware.initialize,
(
admin,
address(managerProxy),
managerProxy,
symbioticNetwork,
symbioticOperatorRegistry,
symbioticOperatorNetOptIn,
symbioticVaultRegistry
)
);
console.log("BoltSymbioticMiddleware deployed at", address(symbioticMiddleware));

address symbioticMiddlewareProxy = address(new ERC1967Proxy(symbioticMiddleware, ""));
address symbioticMiddlewareProxy = address(new ERC1967Proxy(symbioticMiddleware, initSymbioticMiddleware));
console.log("BoltSymbioticMiddleware proxy deployed at", address(symbioticMiddlewareProxy));

vm.stopBroadcast();
Expand Down
26 changes: 15 additions & 11 deletions bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

import {MapWithTimeData} from "../lib/MapWithTimeData.sol";
import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
Expand All @@ -21,7 +22,7 @@ import {AVSDirectoryStorage} from "@eigenlayer/src/contracts/core/AVSDirectorySt
import {DelegationManagerStorage} from "@eigenlayer/src/contracts/core/DelegationManagerStorage.sol";
import {StrategyManagerStorage} from "@eigenlayer/src/contracts/core/StrategyManagerStorage.sol";

contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
contract BoltEigenLayerMiddleware is IBoltMiddleware, OwnableUpgradeable, UUPSUpgradeable {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableMap for EnumerableMap.AddressToUintMap;
using MapWithTimeData for EnumerableMap.AddressToUintMap;
Expand All @@ -38,19 +39,17 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
/// @notice Set of EigenLayer collaterals addresses that are allowed.
EnumerableSet.AddressSet private whitelistedCollaterals;

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

/// @notice Address of the EigenLayer AVS Directory contract.
AVSDirectoryStorage public immutable AVS_DIRECTORY;
AVSDirectoryStorage public AVS_DIRECTORY;

/// @notice Address of the EigenLayer Delegation Manager contract.
DelegationManagerStorage public immutable DELEGATION_MANAGER;
DelegationManagerStorage public DELEGATION_MANAGER;

/// @notice Address of the EigenLayer Strategy Manager contract.
StrategyManagerStorage public immutable STRATEGY_MANAGER;
StrategyManagerStorage public STRATEGY_MANAGER;

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

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

Expand All @@ -68,20 +67,21 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
error StrategyNotAllowed();
error OperatorAlreadyRegisteredToAVS();

// ========= CONSTRUCTOR =========
// ========= INITIALIZER & PROXY FUNCTIONALITY ========= //

/// @notice Constructor for the BoltEigenLayerMiddleware contract.
/// @param _boltManager The address of the Bolt Manager contract.
/// @param _eigenlayerAVSDirectory The address of the EigenLayer AVS Directory contract.
/// @param _eigenlayerDelegationManager The address of the EigenLayer Delegation Manager contract.
/// @param _eigenlayerStrategyManager The address of the EigenLayer Strategy Manager.
constructor(
function initialize(
address _owner,
address _boltManager,
address _eigenlayerAVSDirectory,
address _eigenlayerDelegationManager,
address _eigenlayerStrategyManager
) Ownable(_owner) {
) public initializer {
__Ownable_init(_owner);
boltManager = IBoltManager(_boltManager);
START_TIMESTAMP = Time.timestamp();

Expand All @@ -90,6 +90,10 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, Ownable {
STRATEGY_MANAGER = StrategyManagerStorage(_eigenlayerStrategyManager);
}

function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}

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

/// @notice Get the start timestamp of an epoch.
Expand Down
17 changes: 11 additions & 6 deletions bolt-contracts/src/contracts/BoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.25;

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 {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -21,7 +22,7 @@ import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
import {IBoltMiddleware} from "../interfaces/IBoltMiddleware.sol";
import {IBoltManager} from "../interfaces/IBoltManager.sol";

contract BoltManager is IBoltManager, OwnableUpgradeable {
contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableMap for EnumerableMap.OperatorMap;
using OperatorMapWithTime for EnumerableMap.OperatorMap;
Expand All @@ -43,9 +44,8 @@ contract BoltManager is IBoltManager, OwnableUpgradeable {
/// associated Bolt Middleware contract.
EnumerableSet.AddressSet private restakingProtocols;

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

// ============= CONSTANTS ================= //
/// @notice Duration of an epoch in seconds.
Expand All @@ -56,15 +56,20 @@ contract BoltManager is IBoltManager, OwnableUpgradeable {
_;
}

// ========= CONSTRUCTOR =========
// ========= INITIALIZER & PROXY FUNCTIONALITY ========== //

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

function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}

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

function getEpochStartTs(
Expand Down
26 changes: 15 additions & 11 deletions bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

import {IBaseDelegator} from "@symbiotic/interfaces/delegator/IBaseDelegator.sol";
import {Subnetwork} from "@symbiotic/contracts/libraries/Subnetwork.sol";
Expand All @@ -21,7 +22,7 @@ import {IBoltValidators} from "../interfaces/IBoltValidators.sol";
import {IBoltMiddleware} from "../interfaces/IBoltMiddleware.sol";
import {IBoltManager} from "../interfaces/IBoltManager.sol";

contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
contract BoltSymbioticMiddleware is IBoltMiddleware, OwnableUpgradeable, UUPSUpgradeable {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableMap for EnumerableMap.AddressToUintMap;
using MapWithTimeData for EnumerableMap.AddressToUintMap;
Expand All @@ -39,22 +40,20 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
/// @notice Set of Symbiotic collateral addresses that are whitelisted.
EnumerableSet.AddressSet private whitelistedCollaterals;

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

/// @notice Address of the Bolt network in Symbiotic Protocol.
address public immutable BOLT_SYMBIOTIC_NETWORK;
address public BOLT_SYMBIOTIC_NETWORK;

/// @notice Address of the Symbiotic Operator Registry contract.
address public immutable OPERATOR_REGISTRY;
address public OPERATOR_REGISTRY;

/// @notice Address of the Symbiotic Vault Registry contract.
address public immutable VAULT_REGISTRY;
address public VAULT_REGISTRY;

/// @notice Address of the Symbiotic Operator Network Opt-In contract.
address public immutable OPERATOR_NET_OPTIN;
address public OPERATOR_NET_OPTIN;

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

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

Expand Down Expand Up @@ -86,14 +85,15 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
/// @param _symbioticOperatorRegistry The address of the Symbiotic operator registry.
/// @param _symbioticOperatorNetOptIn The address of the Symbiotic operator network opt-in contract.
/// @param _symbioticVaultRegistry The address of the Symbiotic vault registry.
constructor(
function initialize(
address _owner,
address _boltManager,
address _symbioticNetwork,
address _symbioticOperatorRegistry,
address _symbioticOperatorNetOptIn,
address _symbioticVaultRegistry
) Ownable(_owner) {
) public initializer {
__Ownable_init(_owner);
boltManager = IBoltManager(_boltManager);
START_TIMESTAMP = Time.timestamp();

Expand All @@ -103,6 +103,10 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, Ownable {
VAULT_REGISTRY = _symbioticVaultRegistry;
}

function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}

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

/// @notice Get the start timestamp of an epoch.
Expand Down
15 changes: 11 additions & 4 deletions bolt-contracts/src/contracts/BoltValidators.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

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

/// @title Bolt Validators
/// @notice This contract is responsible for registering validators and managing their configuration
contract BoltValidators is IBoltValidators, BLSSignatureVerifier, Ownable {
contract BoltValidators is IBoltValidators, BLSSignatureVerifier, OwnableUpgradeable, UUPSUpgradeable {
using BLS12381 for BLS12381.G1Point;

// ========= STORAGE =========
Expand Down Expand Up @@ -48,9 +49,15 @@ contract BoltValidators is IBoltValidators, BLSSignatureVerifier, Ownable {

/// @notice Constructor
/// @param _owner Address of the owner of the contract
constructor(
function initialize(
address _owner
) Ownable(_owner) {}
) public initializer {
__Ownable_init(_owner);
}

function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}

// ========= ADMIN FUNCTIONS =========

Expand Down

0 comments on commit 242df15

Please sign in to comment.