Skip to content

Commit

Permalink
feat(contracts): rm collateral whitelisting
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 18, 2024
1 parent 5ad010b commit 429352c
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 168 deletions.
14 changes: 12 additions & 2 deletions bolt-contracts/config/holesky/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
"vaultFactory": "0x5035c15F3cb4364CF2cF35ca53E3d6FC45FC8899",
"networkRegistry": "0xac5acD8A105C8305fb980734a5AD920b5920106A",
"networkMiddlewareService": "0x683F470440964E353b389391CdDDf8df381C282f",
"networkMiddleware": "0x61B626A562d39439Ab60fCbF19678Dac036D1209"
"networkMiddleware": "0x61B626A562d39439Ab60fCbF19678Dac036D1209",
"supportedVaults": [
"0x1df2fbfcD600ADd561013f44B2D055E2e974f605",
"0xf427d00c34609053d97167352061DD2F0F27F853"
]
},
"eigenLayer": {
"avsDirectory": "0x055733000064333CaDDbC92763c58BF0192fFeBf",
"delegationManager": "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
"strategyManager": "0xdfB5f6CE42aAA7830E94ECFCcAd411beF4d4D5b6",
"networkMiddleware": "0x2575d6D30767149c99589cce743656fA3866ca2e"
"networkMiddleware": "0x2575d6D30767149c99589cce743656fA3866ca2e",
"supportedStrategies": [
"0x54945180dB7943c0ed0FEE7EdaB2Bd24620256bc",
"0x93c4b944D05dfe6df7645A86cd2206016c51564D",
"0x1BeE69b7dFFfA4E2d53C2a2Df135C388AD25dCD2",
"0x298aFB19A105D59E74658C4C334Ff360BadE6dd2"
]
}
}
29 changes: 27 additions & 2 deletions bolt-contracts/script/holesky/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {Script, console} from "forge-std/Script.sol";

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Upgrades, Options} from "@openzeppelin-foundry-upgrades/src/Upgrades.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {IVault} from "@symbiotic/interfaces/vault/IVault.sol";
import {IStrategy} from "@eigenlayer/src/contracts/interfaces/IStrategy.sol";

import {BoltParametersV1} from "../../src/contracts/BoltParametersV1.sol";
import {BoltValidatorsV1} from "../../src/contracts/BoltValidatorsV1.sol";
Expand Down Expand Up @@ -96,7 +100,26 @@ contract DeployBolt is Script {
BoltManagerV1(managerProxy).addRestakingProtocol(address(eigenLayerMiddlewareProxy));
BoltManagerV1(managerProxy).addRestakingProtocol(address(symbioticMiddlewareProxy));

console.log("Whitelisted middleware contracts in BoltManager, adding supported collateral...");
console.log("Whitelisted middleware contracts in BoltManager");
console.log("Registering supported Symbiotic Vaults...");

for (uint256 i = 0; i < deployments.supportedVaults.length; i++) {
IVault vault = IVault(deployments.supportedVaults[i]);
console.log("Registering vault with collateral: %s (address: %s)", vault.collateral(), address(vault));
BoltSymbioticMiddlewareV1(symbioticMiddlewareProxy).registerVault(address(deployments.supportedVaults[i]));
}

console.log("Registering supported EigenLayer Strategies...");

for (uint256 i = 0; i < deployments.supportedStrategies.length; i++) {
IStrategy strategy = IStrategy(deployments.supportedStrategies[i]);
console.log(
"Registering strategy with collateral: %s (address: %s)",
address(strategy.underlyingToken()),
address(strategy)
);
BoltEigenLayerMiddlewareV1(eigenLayerMiddlewareProxy).registerStrategy(address(strategy));
}

vm.stopBroadcast();
}
Expand Down Expand Up @@ -141,9 +164,11 @@ contract DeployBolt is Script {
symbioticOperatorRegistry: vm.parseJsonAddress(json, ".symbiotic.operatorRegistry"),
symbioticOperatorNetOptIn: vm.parseJsonAddress(json, ".symbiotic.networkOptInService"),
symbioticVaultFactory: vm.parseJsonAddress(json, ".symbiotic.vaultFactory"),
supportedVaults: vm.parseJsonAddressArray(json, ".symbiotic.supportedVaults"),
eigenLayerAVSDirectory: vm.parseJsonAddress(json, ".eigenLayer.avsDirectory"),
eigenLayerDelegationManager: vm.parseJsonAddress(json, ".eigenLayer.delegationManager"),
eigenLayerStrategyManager: vm.parseJsonAddress(json, ".eigenLayer.strategyManager")
eigenLayerStrategyManager: vm.parseJsonAddress(json, ".eigenLayer.strategyManager"),
supportedStrategies: vm.parseJsonAddressArray(json, ".eigenLayer.supportedStrategies")
});
}
}
69 changes: 17 additions & 52 deletions bolt-contracts/src/contracts/BoltEigenLayerMiddlewareV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ contract BoltEigenLayerMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UU
/// @notice Set of EigenLayer protocol strategies that are used in Bolt Protocol.
EnumerableMap.AddressToUintMap private strategies;

/// @notice Set of EigenLayer collaterals addresses that are allowed.
EnumerableSet.AddressSet private whitelistedCollaterals;

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

Expand All @@ -65,7 +62,7 @@ contract BoltEigenLayerMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UU
/// @notice Name hash of the restaking protocol for identifying the instance of `IBoltMiddleware`.
bytes32 public NAME_HASH;

// --> Storage layout marker: 11 slots
// --> Storage layout marker: 9 slots

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -75,7 +72,7 @@ contract BoltEigenLayerMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UU
*
* Total storage slots: 50
*/
uint256[39] private __gap;
uint256[41] private __gap;

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

Expand Down Expand Up @@ -134,37 +131,26 @@ contract BoltEigenLayerMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UU
return getEpochAtTs(Time.timestamp());
}

/// @notice Get the list of EigenLayer strategies addresses that are allowed.
/// @return _strategies The list of strategies addresses that are allowed.
function getWhitelistedCollaterals() public view returns (address[] memory _strategies) {
return whitelistedCollaterals.values();
}

/// @notice Check if an EigenLayer strategy address is allowed.
/// @param strategy The strategy address to check if it is allowed.
/// @return true if the strategy address is allowed, false otherwise.
function isCollateralWhitelisted(
address strategy
) public view returns (bool) {
return whitelistedCollaterals.contains(strategy);
function getWhitelistedStrategies() public view returns (address[] memory) {
return strategies.keys();
}

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

/// @notice Add a collateral address to the whitelist.
/// @param collateral The collateral address to add to the whitelist.
function addWhitelistedCollateral(
address collateral
/// @notice Register a strategy to work in Bolt Protocol.
/// @param strategy The EigenLayer strategy address
function registerStrategy(
address strategy
) public onlyOwner {
whitelistedCollaterals.add(collateral);
}
if (strategies.contains(strategy)) {
revert AlreadyRegistered();
}

/// @notice Remove a collateral address from the whitelist.
/// @param collateral The collateral address to remove from the whitelist.
function removeWhitelistedCollateral(
address collateral
) public onlyOwner {
whitelistedCollaterals.remove(collateral);
if (!STRATEGY_MANAGER.strategyIsWhitelistedForDeposit(IStrategy(strategy))) {
revert StrategyNotAllowed();
}

strategies.add(strategy);
strategies.enable(strategy);
}

// ========= EIGENLAYER MIDDLEWARE LOGIC =========
Expand Down Expand Up @@ -217,27 +203,6 @@ contract BoltEigenLayerMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UU
manager.unpauseOperator(msg.sender);
}

/// @notice Register a strategy to work in Bolt Protocol.
/// @param strategy The EigenLayer strategy address
function registerStrategy(
address strategy
) public {
if (strategies.contains(strategy)) {
revert AlreadyRegistered();
}

if (!STRATEGY_MANAGER.strategyIsWhitelistedForDeposit(IStrategy(strategy))) {
revert StrategyNotAllowed();
}

if (!isCollateralWhitelisted(address(IStrategy(strategy).underlyingToken()))) {
revert CollateralNotWhitelisted();
}

strategies.add(strategy);
strategies.enable(strategy);
}

/// @notice Allow a strategy to signal indefinite opt-out from Bolt Protocol.
function pauseStrategy() public {
if (!strategies.contains(msg.sender)) {
Expand Down
75 changes: 21 additions & 54 deletions bolt-contracts/src/contracts/BoltSymbioticMiddlewareV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ contract BoltSymbioticMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UUP
/// @notice Set of Symbiotic protocol vaults that are used in Bolt Protocol.
EnumerableMap.AddressToUintMap private vaults;

/// @notice Set of Symbiotic collateral addresses that are whitelisted.
EnumerableSet.AddressSet private whitelistedCollaterals;

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

Expand All @@ -75,7 +72,7 @@ contract BoltSymbioticMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UUP

bytes32 public NAME_HASH;

// --> Storage layout marker: 14 slots
// --> Storage layout marker: 12 slots

/**
* @dev This empty reserved space is put in place to allow future versions to add new
Expand All @@ -85,7 +82,7 @@ contract BoltSymbioticMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UUP
*
* Total storage slots: 50
*/
uint256[36] private __gap;
uint256[38] private __gap;

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

Expand Down Expand Up @@ -148,37 +145,30 @@ contract BoltSymbioticMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UUP
return getEpochAtTs(Time.timestamp());
}

/// @notice Get the list of collateral addresses that are whitelisted.
/// @return collaterals The list of collateral addresses that are whitelisted.
function getWhitelistedCollaterals() public view returns (address[] memory collaterals) {
return whitelistedCollaterals.values();
}

/// @notice Check if a collateral address is whitelisted.
/// @param collateral The collateral address to check the whitelist status for.
/// @return True if the collateral address is whitelisted, false otherwise.
function isCollateralWhitelisted(
address collateral
) public view returns (bool) {
return whitelistedCollaterals.contains(collateral);
/// @notice Get the whitelisted vaults.
function getWhitelistedVaults() public view returns (address[] memory) {
return vaults.keys();
}

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

/// @notice Add a collateral address to the whitelist.
/// @param collateral The collateral address to add to the whitelist.
function addWhitelistedCollateral(
address collateral
/// @notice Allow a vault to signal opt-in to Bolt Protocol.
/// @param vault The vault address to signal opt-in for.
function registerVault(
address vault
) public onlyOwner {
whitelistedCollaterals.add(collateral);
}
if (vaults.contains(vault)) {
revert AlreadyRegistered();
}

/// @notice Remove a collateral address from the whitelist.
/// @param collateral The collateral address to remove from the whitelist.
function removeWhitelistedCollateral(
address collateral
) public onlyOwner {
whitelistedCollaterals.remove(collateral);
if (!IRegistry(VAULT_FACTORY).isEntity(vault)) {
revert NotVault();
}

// TODO: check slashing conditions and veto duration

vaults.add(vault);
vaults.enable(vault);
}

// ========= SYMBIOTIC MIDDLEWARE LOGIC =========
Expand Down Expand Up @@ -225,29 +215,6 @@ contract BoltSymbioticMiddlewareV1 is IBoltMiddlewareV1, OwnableUpgradeable, UUP
manager.unpauseOperator(msg.sender);
}

/// @notice Allow a vault to signal opt-in to Bolt Protocol.
/// @param vault The vault address to signal opt-in for.
function registerVault(
address vault
) public {
if (vaults.contains(vault)) {
revert AlreadyRegistered();
}

if (!IRegistry(VAULT_FACTORY).isEntity(vault)) {
revert NotVault();
}

if (!isCollateralWhitelisted(IVault(vault).collateral())) {
revert CollateralNotWhitelisted();
}

// TODO: check slashing conditions and veto duration

vaults.add(vault);
vaults.enable(vault);
}

/// @notice Allow a vault to signal indefinite opt-out from Bolt Protocol.
function pauseVault() public {
if (!vaults.contains(msg.sender)) {
Expand Down
15 changes: 0 additions & 15 deletions bolt-contracts/src/interfaces/IBoltMiddlewareV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ interface IBoltMiddlewareV1 {
error NotRegistered();
error OperatorNotOptedIn();
error NotOperator();
error CollateralNotWhitelisted();
error NotAllowed();

function NAME_HASH() external view returns (bytes32);
Expand All @@ -25,20 +24,6 @@ interface IBoltMiddlewareV1 {

function getCurrentEpoch() external view returns (uint48);

function addWhitelistedCollateral(
address collateral
) external;

function removeWhitelistedCollateral(
address collateral
) external;

function getWhitelistedCollaterals() external view returns (address[] memory);

function isCollateralWhitelisted(
address collateral
) external view returns (bool);

function getOperatorStake(address operator, address collateral) external view returns (uint256);

function getOperatorCollaterals(
Expand Down
2 changes: 2 additions & 0 deletions bolt-contracts/src/lib/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ library BoltConfig {
address symbioticOperatorRegistry;
address symbioticOperatorNetOptIn;
address symbioticVaultFactory;
address[] supportedVaults;
address eigenLayerAVSDirectory;
address eigenLayerDelegationManager;
address eigenLayerStrategyManager;
address[] supportedStrategies;
}

struct SymbioticDeployments {
Expand Down
32 changes: 7 additions & 25 deletions bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ contract BoltManagerEigenLayerTest is Test {

function _adminRoutine() internal {
// PART 0: Admin setup -- Collateral whitelist
vm.startPrank(admin);
middleware.addWhitelistedCollateral(address(eigenLayerDeployer.weth()));
vm.stopPrank();
assertEq(middleware.getWhitelistedCollaterals().length, 1);
assertEq(middleware.getWhitelistedCollaterals()[0], address(eigenLayerDeployer.weth()));
// vm.startPrank(admin);
// middleware.addWhitelistedCollateral(address(eigenLayerDeployer.weth()));
// vm.stopPrank();
// assertEq(middleware.getWhitelistedCollaterals().length, 1);
// assertEq(middleware.getWhitelistedCollaterals()[0], address(eigenLayerDeployer.weth()));
}

function _eigenLayerOptInRoutine() internal {
Expand Down Expand Up @@ -194,7 +194,9 @@ contract BoltManagerEigenLayerTest is Test {

// 2. --- Operator and strategy registration into BoltManager (middleware) ---

vm.startPrank(admin);
middleware.registerStrategy(address(eigenLayerDeployer.wethStrat()));
vm.stopPrank();
assertEq(middleware.isStrategyEnabled(address(eigenLayerDeployer.wethStrat())), true);
}

Expand Down Expand Up @@ -258,26 +260,6 @@ contract BoltManagerEigenLayerTest is Test {
manager.getProposerStatus(pubkeyHash);
}

function testWhitelistedCollaterals() public {
_adminRoutine();
address[] memory collaterals = middleware.getWhitelistedCollaterals();
assertEq(collaterals.length, 1);
assertEq(collaterals[0], address(eigenLayerDeployer.weth()));
}

function testNonWhitelistedCollateral() public {
_adminRoutine();
vm.startPrank(admin);
middleware.removeWhitelistedCollateral(address(eigenLayerDeployer.weth()));
vm.stopPrank();

address strat = address(eigenLayerDeployer.wethStrat());
vm.startPrank(admin);
vm.expectRevert(IBoltMiddlewareV1.CollateralNotWhitelisted.selector);
middleware.registerStrategy(strat);
vm.stopPrank();
}

/// @notice Compute the hash of a BLS public key
function _pubkeyHash(
BLS12381.G1Point memory _pubkey
Expand Down
Loading

0 comments on commit 429352c

Please sign in to comment.