Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 39 additions & 102 deletions test/unit/InstantSlasher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ import {StakeRegistry} from "../../src/StakeRegistry.sol";
import {BLSApkRegistry} from "../../src/BLSApkRegistry.sol";
import {IndexRegistry} from "../../src/IndexRegistry.sol";
import {SocketRegistry} from "../../src/SocketRegistry.sol";
import {MiddlewareDeployLib} from "../utils/MiddlewareDeployLib.sol";

contract InstantSlasherTest is Test {
InstantSlasher public instantSlasher;
InstantSlasher public instantSlasherImplementation;
ProxyAdmin public proxyAdmin;
EmptyContract public emptyContract;
SlashingRegistryCoordinator public slashingRegistryCoordinator;
SlashingRegistryCoordinator public slashingRegistryCoordinatorImplementation;
CoreDeploymentLib.DeploymentData public coreDeployment;
PauserRegistry public pauserRegistry;
ERC20Mock public mockToken;
Expand Down Expand Up @@ -149,108 +148,51 @@ contract InstantSlasherTest is Test {
IERC20(address(mockToken))
)
);

// Deploy empty proxies for all registries
stakeRegistry = StakeRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

blsApkRegistry = BLSApkRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

indexRegistry = IndexRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

socketRegistry = SocketRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

slashingRegistryCoordinatorImplementation = new SlashingRegistryCoordinator(
IStakeRegistry(address(stakeRegistry)),
IBLSApkRegistry(address(blsApkRegistry)),
IIndexRegistry(address(indexRegistry)),
ISocketRegistry(address(socketRegistry)),
IAllocationManager(coreDeployment.allocationManager),
IPauserRegistry(address(pauserRegistry))
);

slashingRegistryCoordinator = SlashingRegistryCoordinator(
address(
new TransparentUpgradeableProxy(
address(slashingRegistryCoordinatorImplementation), address(proxyAdmin), ""
)
)
);

// Deploy registry implementations pointing to the coordinator
StakeRegistry stakeRegistryImplementation = new StakeRegistry(
ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)),
IDelegationManager(coreDeployment.delegationManager),
IAVSDirectory(coreDeployment.avsDirectory),
IAllocationManager(coreDeployment.allocationManager)
);
BLSApkRegistry blsApkRegistryImplementation =
new BLSApkRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
IndexRegistry indexRegistryImplementation =
new IndexRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
SocketRegistry socketRegistryImplementation =
new SocketRegistry(IRegistryCoordinator(address(slashingRegistryCoordinator)));

// Upgrade all registry proxies
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(socketRegistry))),
address(socketRegistryImplementation)
);

// Initialize the SlashingRegistryCoordinator first
slashingRegistryCoordinator.initialize(
proxyAdminOwner, churnApprover, ejector, 0, serviceManager
);

vm.stopPrank();

instantSlasherImplementation = new InstantSlasher(
IAllocationManager(coreDeployment.allocationManager),
ISlashingRegistryCoordinator(slashingRegistryCoordinator),
slasher
);
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
middlewareConfig.instantSlasher.slasher = slasher;
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
middlewareConfig.slashingRegistryCoordinator.churnApprover = churnApprover;
middlewareConfig.slashingRegistryCoordinator.ejector = ejector;
middlewareConfig.slashingRegistryCoordinator.initPausedStatus = 0;
middlewareConfig.slashingRegistryCoordinator.serviceManager = serviceManager;
middlewareConfig.socketRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.indexRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.stakeRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.stakeRegistry.minimumStake = 1 ether;
middlewareConfig.stakeRegistry.strategyParams = 0;
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});
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
}
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;

vm.startPrank(proxyAdminOwner);
instantSlasher = InstantSlasher(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(instantSlasher))),
address(instantSlasherImplementation)
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
.deployMiddleware(
address(proxyAdmin),
coreDeployment.allocationManager,
address(pauserRegistry),
middlewareConfig
);
vm.stopPrank();

instantSlasher.initialize(slasher);
instantSlasher = InstantSlasher(middlewareDeployments.instantSlasher);
slashingRegistryCoordinator =
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
socketRegistry = SocketRegistry(middlewareDeployments.socketRegistry);

vm.startPrank(serviceManager);
PermissionController(coreDeployment.permissionController).setAppointee(
Expand Down Expand Up @@ -295,12 +237,7 @@ contract InstantSlasherTest is Test {
vm.stopPrank();

vm.label(address(instantSlasher), "InstantSlasher Proxy");
vm.label(address(instantSlasherImplementation), "InstantSlasher Implementation");
vm.label(address(slashingRegistryCoordinator), "SlashingRegistryCoordinator Proxy");
vm.label(
address(slashingRegistryCoordinatorImplementation),
"SlashingRegistryCoordinator Implementation"
);
vm.label(address(proxyAdmin), "ProxyAdmin");
vm.label(coreDeployment.allocationManager, "AllocationManager Proxy");
}
Expand Down
118 changes: 40 additions & 78 deletions test/unit/VetoableSlasher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {IVetoableSlasherTypes} from "../../src/interfaces/IVetoableSlasher.sol";
import {SocketRegistry} from "../../src/SocketRegistry.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IVetoableSlasherErrors} from "../../src/interfaces/IVetoableSlasher.sol";
import {MiddlewareDeployLib} from "../utils/MiddlewareDeployLib.sol";

contract VetoableSlasherTest is Test {
VetoableSlasher public vetoableSlasher;
Expand Down Expand Up @@ -155,87 +156,49 @@ contract VetoableSlasherTest is Test {
)
);

// Deploy empty proxies for all registries
stakeRegistry = StakeRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

blsApkRegistry = BLSApkRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

indexRegistry = IndexRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

socketRegistry = SocketRegistry(
address(
new TransparentUpgradeableProxy(address(emptyContract), address(proxyAdmin), "")
)
);

slashingRegistryCoordinatorImplementation = new SlashingRegistryCoordinator(
IStakeRegistry(address(stakeRegistry)),
IBLSApkRegistry(address(blsApkRegistry)),
IIndexRegistry(address(indexRegistry)),
ISocketRegistry(address(socketRegistry)),
IAllocationManager(coreDeployment.allocationManager),
IPauserRegistry(address(pauserRegistry))
);

slashingRegistryCoordinator = SlashingRegistryCoordinator(
address(
new TransparentUpgradeableProxy(
address(slashingRegistryCoordinatorImplementation), address(proxyAdmin), ""
)
)
);

// Deploy registry implementations pointing to the coordinator
StakeRegistry stakeRegistryImplementation = new StakeRegistry(
ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)),
IDelegationManager(coreDeployment.delegationManager),
IAVSDirectory(coreDeployment.avsDirectory),
IAllocationManager(coreDeployment.allocationManager)
);
BLSApkRegistry blsApkRegistryImplementation =
new BLSApkRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
IndexRegistry indexRegistryImplementation =
new IndexRegistry(ISlashingRegistryCoordinator(address(slashingRegistryCoordinator)));
SocketRegistry socketRegistryImplementation =
new SocketRegistry(IRegistryCoordinator(address(slashingRegistryCoordinator)));

// Upgrade all registry proxies
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
proxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(socketRegistry))),
address(socketRegistryImplementation)
);
MiddlewareDeployLib.MiddlewareDeployConfig memory middlewareConfig;
middlewareConfig.instantSlasher.initialOwner = proxyAdminOwner;
middlewareConfig.instantSlasher.slasher = slasher;
middlewareConfig.slashingRegistryCoordinator.initialOwner = proxyAdminOwner;
middlewareConfig.slashingRegistryCoordinator.churnApprover = churnApprover;
middlewareConfig.slashingRegistryCoordinator.ejector = ejector;
middlewareConfig.slashingRegistryCoordinator.initPausedStatus = 0;
middlewareConfig.slashingRegistryCoordinator.serviceManager = serviceManager;
middlewareConfig.socketRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.indexRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.stakeRegistry.initialOwner = proxyAdminOwner;
middlewareConfig.stakeRegistry.minimumStake = 1 ether;
middlewareConfig.stakeRegistry.strategyParams = 0;
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});
middlewareConfig.stakeRegistry.strategyParamsArray = stratParams;
}
middlewareConfig.stakeRegistry.lookAheadPeriod = 0;
middlewareConfig.stakeRegistry.stakeType = IStakeRegistryTypes.StakeType(1);
middlewareConfig.blsApkRegistry.initialOwner = proxyAdminOwner;

// Initialize the SlashingRegistryCoordinator first
slashingRegistryCoordinator.initialize(
proxyAdminOwner, churnApprover, ejector, 0, serviceManager
MiddlewareDeployLib.MiddlewareDeployData memory middlewareDeployments = MiddlewareDeployLib
.deployMiddleware(
address(proxyAdmin),
coreDeployment.allocationManager,
address(pauserRegistry),
middlewareConfig
);

vm.stopPrank();

vetoableSlasher = VetoableSlasher(middlewareDeployments.instantSlasher);
slashingRegistryCoordinator =
SlashingRegistryCoordinator(middlewareDeployments.slashingRegistryCoordinator);
stakeRegistry = StakeRegistry(middlewareDeployments.stakeRegistry);
blsApkRegistry = BLSApkRegistry(middlewareDeployments.blsApkRegistry);
indexRegistry = IndexRegistry(middlewareDeployments.indexRegistry);
socketRegistry = SocketRegistry(middlewareDeployments.socketRegistry);

vetoableSlasherImplementation = new VetoableSlasher(
IAllocationManager(coreDeployment.allocationManager),
ISlashingRegistryCoordinator(slashingRegistryCoordinator)
Expand Down Expand Up @@ -413,7 +376,6 @@ contract VetoableSlasherTest is Test {
}

function test_fulfillSlashingRequest() public {
vm.skip(false);
vm.startPrank(operatorWallet.key.addr);
IDelegationManager(coreDeployment.delegationManager).registerAsOperator(
address(0), 1, "metadata"
Expand Down
Loading
Loading