From 3b7a8bd9a208d261f367b2c6a54d48cd27ac3e39 Mon Sep 17 00:00:00 2001 From: AnshuJalan Date: Sat, 15 Jun 2024 14:20:41 +0530 Subject: [PATCH] feat: add service manager contract --- .../src/avs/PreconfServiceManager.sol | 51 +++++++++++++++++++ .../src/interfaces/IPreconfTaskManager.sol | 2 +- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 SmartContracts/src/avs/PreconfServiceManager.sol diff --git a/SmartContracts/src/avs/PreconfServiceManager.sol b/SmartContracts/src/avs/PreconfServiceManager.sol new file mode 100644 index 0000000..fb4a308 --- /dev/null +++ b/SmartContracts/src/avs/PreconfServiceManager.sol @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.25; + +import {IPreconfServiceManager} from "../interfaces/IPreconfServiceManager.sol"; +import {IPreconfTaskManager} from "../interfaces/IPreconfTaskManager.sol"; +import {ISlasher} from "../interfaces/eigenlayer-mvp/ISlasher.sol"; +import { + IAVSDirectory, + IRegistryCoordinator, + IRewardsCoordinator, + IStakeRegistry, + ServiceManagerBase +} from "eigenlayer-middleware/ServiceManagerBase.sol"; + +contract PreconfServiceManager is ServiceManagerBase, IPreconfServiceManager { + IPreconfTaskManager internal immutable preconfTaskManager; + ISlasher internal immutable slasher; + + mapping(address operator => uint256 timestamp) public stakeLockedUntil; + + constructor( + IAVSDirectory _avsDirectory, + IRewardsCoordinator _rewardsCoordinator, + IRegistryCoordinator _registryCoordinator, + IStakeRegistry _stakeRegistry, + IPreconfTaskManager _taskManager, + ISlasher _slasher + ) ServiceManagerBase(_avsDirectory, _rewardsCoordinator, _registryCoordinator, _stakeRegistry) { + preconfTaskManager = _taskManager; + slasher = _slasher; + } + + modifier onlyPreconfTaskManager() { + if (msg.sender != address(preconfTaskManager)) { + revert IPreconfServiceManager.SenderIsNotPreconfTaskManager(msg.sender); + } + _; + } + + function lockStakeUntil(address operator, uint256 timestamp) external onlyPreconfTaskManager { + stakeLockedUntil[operator] = timestamp; + emit StakeLockedUntil(operator, timestamp); + } + + function slashOperator(address operator) external onlyPreconfTaskManager { + if (slasher.isOperatorSlashed(operator)) { + revert IPreconfServiceManager.OperatorAlreadySlashed(operator); + } + slasher.slashOperator(operator); + } +} diff --git a/SmartContracts/src/interfaces/IPreconfTaskManager.sol b/SmartContracts/src/interfaces/IPreconfTaskManager.sol index d0085e1..a050977 100644 --- a/SmartContracts/src/interfaces/IPreconfTaskManager.sol +++ b/SmartContracts/src/interfaces/IPreconfTaskManager.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.25; -interface PreconfTaskManager { +interface IPreconfTaskManager { event LookaheadUpdated(bytes lookahead); event ProvedIncorrectPreconfirmation(address indexed preconfer, uint256 indexed blockId, address indexed disputer); event ProvedIncorrectLookahead(address indexed poster, uint256 indexed slot, address indexed disputer);