Skip to content

Commit

Permalink
feat(security): add security monitoring contract
Browse files Browse the repository at this point in the history
  • Loading branch information
LurkyLunk committed Jul 30, 2024
1 parent cea94a0 commit ef155f8
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/contracts/src/dollar/utils/securitymonitor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/Context.sol";

interface INotifiable {
function notify(string memory message) external;
}

contract SecurityMonitor is AccessControl, Pausable {
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MONITOR_ROLE = keccak256("MONITOR_ROLE");

address public notificationService;

event SecurityIncident(string message);

constructor(address admin, address _notificationService) {
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_setupRole(PAUSER_ROLE, admin);
_setupRole(MONITOR_ROLE, admin);

notificationService = _notificationService;
}

function setNotificationService(address _notificationService) external {
require(
hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),
"Must have admin role to set notification service"
);
notificationService = _notificationService;
}

function pauseAllContracts(address[] calldata contracts) external {
require(
hasRole(MONITOR_ROLE, _msgSender()),
"Must have monitor role to pause"
);

for (uint256 i = 0; i < contracts.length; i++) {
//Pausable(contracts[i]).pause();
}

string
memory message = "Security incident detected: all contracts paused.";
emit SecurityIncident(message);
INotifiable(notificationService).notify(message);
}

function unpauseAllContracts(address[] calldata contracts) external {
require(
hasRole(PAUSER_ROLE, _msgSender()),
"Must have pauser role to unpause"
);

for (uint256 i = 0; i < contracts.length; i++) {
//Pausable(contracts[i]).unpause();
}

string
memory message = "Security issue resolved: all contracts unpaused.";
emit SecurityIncident(message);
INotifiable(notificationService).notify(message);
}

//function _msgSender() internal view virtual returns (address) {
//return Context._msgSender();
// }
}

0 comments on commit ef155f8

Please sign in to comment.