Skip to content

Commit

Permalink
chore: refactor and cleanup naming
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Feb 7, 2025
1 parent f5278ec commit 0af5ab3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 80 deletions.
32 changes: 21 additions & 11 deletions test/unit/InstantSlasher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ contract InstantSlasherTest is Test {
);
vm.stopPrank();

MiddlewareDeployLib.DeploymentConfigData memory middlewareConfig;
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
middlewareConfig.instantSlasher.slasher = slasher;
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
Expand All @@ -166,16 +166,19 @@ contract InstantSlasherTest is Test {
middlewareConfig.stakeRegistry.delegationManager = coreDeployment.delegationManager;
middlewareConfig.stakeRegistry.avsDirectory = coreDeployment.avsDirectory;
{
IStakeRegistryTypes.StrategyParams[] memory stratParams = new IStakeRegistryTypes.StrategyParams[](1);
stratParams[0] = IStakeRegistryTypes.StrategyParams({ strategy: mockStrategy, multiplier: 1 ether });
IStakeRegistryTypes.StrategyParams[] memory stratParams =
new IStakeRegistryTypes.StrategyParams[](1);
stratParams[0] =
IStakeRegistryTypes.StrategyParams({strategy: mockStrategy, multiplier: 1 ether});
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
}
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;

vm.startPrank(proxyAdminOwner);
MiddlewareDeployLib.DeploymentData memory middlewareDeployments = MiddlewareDeployLib.deployContracts(
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
.deployMiddleware(
address(proxyAdmin),
coreDeployment.allocationManager,
address(pauserRegistry),
Expand All @@ -184,7 +187,8 @@ contract InstantSlasherTest is Test {
vm.stopPrank();

instantSlasher = InstantSlasher(middlewareDeployments.instantSlasher);
slashingRegistryCoordinator = SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
slashingRegistryCoordinator =
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
Expand Down Expand Up @@ -214,10 +218,13 @@ contract InstantSlasherTest is Test {
uint96[] memory minimumStakes = new uint96[](1);
minimumStakes[0] = 1 ether;

IStakeRegistryTypes.StrategyParams[] memory strategyParams = new IStakeRegistryTypes.StrategyParams[](1);
strategyParams[0] = IStakeRegistryTypes.StrategyParams({ strategy: mockStrategy, multiplier: 1 ether });
IStakeRegistryTypes.StrategyParams[] memory strategyParams =
new IStakeRegistryTypes.StrategyParams[](1);
strategyParams[0] =
IStakeRegistryTypes.StrategyParams({strategy: mockStrategy, multiplier: 1 ether});

ISlashingRegistryCoordinatorTypes.OperatorSetParam memory operatorSetParams = ISlashingRegistryCoordinatorTypes.OperatorSetParam({
ISlashingRegistryCoordinatorTypes.OperatorSetParam memory operatorSetParams =
ISlashingRegistryCoordinatorTypes.OperatorSetParam({
maxOperatorCount: 10,
kickBIPsOfOperatorStake: 0,
kickBIPsOfTotalStake: 0
Expand Down Expand Up @@ -305,16 +312,19 @@ contract InstantSlasherTest is Test {
OperatorSet memory operatorSet = OperatorSet({avs: address(serviceManager), id: 0});

vm.startPrank(serviceManager);
IAllocationManagerTypes.CreateSetParams[] memory createParams = new IAllocationManagerTypes.CreateSetParams[](1);
createParams[0] = IAllocationManagerTypes.CreateSetParams({operatorSetId: 0, strategies: allocStrategies});
IAllocationManagerTypes.CreateSetParams[] memory createParams =
new IAllocationManagerTypes.CreateSetParams[](1);
createParams[0] =
IAllocationManagerTypes.CreateSetParams({operatorSetId: 0, strategies: allocStrategies});
IAllocationManager(coreDeployment.allocationManager).setAVSRegistrar(
address(serviceManager), IAVSRegistrar(address(slashingRegistryCoordinator))
);
vm.stopPrank();

vm.startPrank(operatorWallet.key.addr);

IAllocationManagerTypes.AllocateParams[] memory allocParams = new IAllocationManagerTypes.AllocateParams[](1);
IAllocationManagerTypes.AllocateParams[] memory allocParams =
new IAllocationManagerTypes.AllocateParams[](1);
allocParams[0] = IAllocationManagerTypes.AllocateParams({
operatorSet: operatorSet,
strategies: allocStrategies,
Expand Down
14 changes: 9 additions & 5 deletions test/unit/VetoableSlasher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ contract VetoableSlasherTest is Test {
)
);

MiddlewareDeployLib.DeploymentConfigData memory middlewareConfig;
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
middlewareConfig.instantSlasher.slasher = slasher;
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
Expand All @@ -172,15 +172,18 @@ contract VetoableSlasherTest is Test {
middlewareConfig.stakeRegistry.delegationManager = coreDeployment.delegationManager;
middlewareConfig.stakeRegistry.avsDirectory = coreDeployment.avsDirectory;
{
IStakeRegistryTypes.StrategyParams[] memory stratParams = new IStakeRegistryTypes.StrategyParams[](1);
stratParams[0] = IStakeRegistryTypes.StrategyParams({ strategy: mockStrategy, multiplier: 1 ether });
IStakeRegistryTypes.StrategyParams[] memory stratParams =
new IStakeRegistryTypes.StrategyParams[](1);
stratParams[0] =
IStakeRegistryTypes.StrategyParams({strategy: mockStrategy, multiplier: 1 ether});
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
}
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;

MiddlewareDeployLib.DeploymentData memory middlewareDeployments = MiddlewareDeployLib.deployContracts(
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
.deployMiddleware(
address(proxyAdmin),
coreDeployment.allocationManager,
address(pauserRegistry),
Expand All @@ -189,7 +192,8 @@ contract VetoableSlasherTest is Test {
vm.stopPrank();

vetoableSlasher = VetoableSlasher(middlewareDeployments.instantSlasher);
slashingRegistryCoordinator = SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
slashingRegistryCoordinator =
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
Expand Down
127 changes: 63 additions & 64 deletions test/utils/MiddlewareDeployLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
pragma solidity ^0.8.0;

import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {UpgradeableBeacon} from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IAllocationManager} from
"eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IPauserRegistry} from "eigenlayer-contracts/src/contracts/interfaces/IPauserRegistry.sol";
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IDelegationManager} from
"eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";

import {InstantSlasher} from "../../src/slashers/InstantSlasher.sol";
Expand All @@ -32,10 +35,10 @@ library MiddlewareDeployLib {
}

struct SlashingRegistryCoordinatorConfig {
uint256 initPausedStatus;
address initialOwner;
address churnApprover;
address ejector;
uint256 initPausedStatus;
address serviceManager;
}

Expand All @@ -62,7 +65,7 @@ library MiddlewareDeployLib {
address initialOwner;
}

struct DeploymentConfigData {
struct MiddlewareDeployConfig {
InstantSlasherConfig instantSlasher;
SlashingRegistryCoordinatorConfig slashingRegistryCoordinator;
SocketRegistryConfig socketRegistry;
Expand All @@ -71,7 +74,7 @@ library MiddlewareDeployLib {
BLSApkRegistryConfig blsApkRegistry;
}

struct DeploymentData {
struct MiddlewareDeployData {
address instantSlasher;
address slashingRegistryCoordinator;
address socketRegistry;
Expand All @@ -80,55 +83,26 @@ library MiddlewareDeployLib {
address blsApkRegistry;
}

function deployContracts(
function deployMiddleware(
address proxyAdmin,
address allocationManager,
address pauserRegistry,
DeploymentConfigData memory configData
) internal returns (DeploymentData memory result) {
MiddlewareDeployConfig memory config
) internal returns (MiddlewareDeployData memory result) {
result = deployEmptyProxies(proxyAdmin);

// First, deploy and configure registries
deployAndConfigureRegistries(
result,
allocationManager,
pauserRegistry,
configData
upgradeRegistries(result, allocationManager, pauserRegistry, config);
upgradeCoordinator(
result, allocationManager, pauserRegistry, config.slashingRegistryCoordinator
);

// Now, deploy and initialize SlashingRegistryCoordinator
address slashingRegistryCoordinatorImpl = address(
new SlashingRegistryCoordinator(
IStakeRegistry(result.stakeRegistry),
IBLSApkRegistry(result.blsApkRegistry),
IIndexRegistry(result.indexRegistry),
ISocketRegistry(result.socketRegistry),
IAllocationManager(allocationManager),
IPauserRegistry(pauserRegistry)
)
);
bytes memory upgradeCall = abi.encodeCall(
SlashingRegistryCoordinator.initialize,
(
configData.slashingRegistryCoordinator.initialOwner,
configData.slashingRegistryCoordinator.churnApprover,
configData.slashingRegistryCoordinator.ejector,
configData.slashingRegistryCoordinator.initPausedStatus,
configData.slashingRegistryCoordinator.serviceManager
)
);
UpgradeableProxyLib.upgradeAndCall(
result.slashingRegistryCoordinator,
slashingRegistryCoordinatorImpl,
upgradeCall
);

deployAndConfigureSlasher(result, allocationManager, configData);
upgradeInstantSlasher(result, allocationManager, config.instantSlasher);

return result;
}

function deployEmptyProxies(address proxyAdmin) internal returns (DeploymentData memory proxies) {
function deployEmptyProxies(
address proxyAdmin
) internal returns (MiddlewareDeployData memory proxies) {
proxies.instantSlasher = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
proxies.slashingRegistryCoordinator = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
proxies.socketRegistry = UpgradeableProxyLib.setUpEmptyProxy(proxyAdmin);
Expand All @@ -138,11 +112,11 @@ library MiddlewareDeployLib {
return proxies;
}

function deployAndConfigureRegistries(
DeploymentData memory deployments,
function upgradeRegistries(
MiddlewareDeployData memory deployments,
address allocationManager,
address pauserRegistry,
DeploymentConfigData memory config
MiddlewareDeployConfig memory config
) internal {
address blsApkRegistryImpl = address(
new BLSApkRegistry(
Expand All @@ -152,9 +126,7 @@ library MiddlewareDeployLib {
UpgradeableProxyLib.upgrade(deployments.blsApkRegistry, blsApkRegistryImpl);

address indexRegistryImpl = address(
new IndexRegistry(
ISlashingRegistryCoordinator(deployments.slashingRegistryCoordinator)
)
new IndexRegistry(ISlashingRegistryCoordinator(deployments.slashingRegistryCoordinator))
);
UpgradeableProxyLib.upgrade(deployments.indexRegistry, indexRegistryImpl);

Expand All @@ -165,6 +137,7 @@ library MiddlewareDeployLib {
);
UpgradeableProxyLib.upgrade(deployments.socketRegistry, socketRegistryImpl);

// StakeRegistry upgrade
address stakeRegistryImpl = address(
new StakeRegistry(
ISlashingRegistryCoordinator(deployments.slashingRegistryCoordinator),
Expand All @@ -174,30 +147,56 @@ library MiddlewareDeployLib {
)
);
UpgradeableProxyLib.upgrade(deployments.stakeRegistry, stakeRegistryImpl);
}

function upgradeCoordinator(
MiddlewareDeployData memory deployments,
address allocationManager,
address pauserRegistry,
SlashingRegistryCoordinatorConfig memory coordinatorConfig
) internal {
address coordinatorImpl = address(
new SlashingRegistryCoordinator(
IStakeRegistry(deployments.stakeRegistry),
IBLSApkRegistry(deployments.blsApkRegistry),
IIndexRegistry(deployments.indexRegistry),
ISocketRegistry(deployments.socketRegistry),
IAllocationManager(allocationManager),
IPauserRegistry(pauserRegistry)
)
);
bytes memory upgradeCall = abi.encodeCall(
SlashingRegistryCoordinator.initialize,
(
coordinatorConfig.initialOwner,
coordinatorConfig.churnApprover,
coordinatorConfig.ejector,
coordinatorConfig.initPausedStatus,
coordinatorConfig.serviceManager
)
);
UpgradeableProxyLib.upgradeAndCall(
deployments.slashingRegistryCoordinator, coordinatorImpl, upgradeCall
);
}

function deployAndConfigureSlasher(
DeploymentData memory deployments,
// Upgrade and initialize InstantSlasher with its config data
function upgradeInstantSlasher(
MiddlewareDeployData memory deployments,
address allocationManager,
DeploymentConfigData memory config
InstantSlasherConfig memory slasherConfig
) internal {
address instantSlasherImpl = address(
new InstantSlasher(
IAllocationManager(allocationManager),
ISlashingRegistryCoordinator(deployments.slashingRegistryCoordinator),
config.instantSlasher.slasher
slasherConfig.slasher
)
);

bytes memory upgradeCall = abi.encodeCall(
InstantSlasher.initialize,
(config.instantSlasher.slasher)
);
bytes memory upgradeCall =
abi.encodeCall(InstantSlasher.initialize, (slasherConfig.slasher));
UpgradeableProxyLib.upgradeAndCall(
deployments.instantSlasher,
instantSlasherImpl,
upgradeCall
deployments.instantSlasher, instantSlasherImpl, upgradeCall
);
}
}
}

0 comments on commit 0af5ab3

Please sign in to comment.