Skip to content

Commit

Permalink
feat(security): further work on security monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
LurkyLunk committed Jul 31, 2024
1 parent ef155f8 commit 33c7f6b
Show file tree
Hide file tree
Showing 5 changed files with 821 additions and 85 deletions.
3 changes: 3 additions & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ src = 'src/dollar'
[profile.intense.fuzz]
runs = 100000
max_test_rejects = 900000

[lint]
foundry-test-functions = false
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"url": "https://github.com/ubiquity/ubiquity-dollar.git"
},
"dependencies": {
"@chainlink/contracts": "^1.2.0",
"@types/command-line-args": "5.2.0",
"command-line-args": "5.2.1",
"dotenv": "^16.0.3",
Expand Down
62 changes: 62 additions & 0 deletions packages/contracts/src/dollar/utils/SecurityMonitor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@chainlink/contracts/src/v0.8/AutomationCompatible.sol";

contract SecurityMonitor is AccessControl, AutomationCompatibleInterface {
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
uint256 public lastCheckBlock;
uint256 public liquidityThreshold; // Set this according to your needs

event SecurityIncident(string message);

constructor(address admin, uint256 _liquidityThreshold) {
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_setupRole(PAUSER_ROLE, admin);
liquidityThreshold = _liquidityThreshold;
lastCheckBlock = block.number;
}

// This function should contain the logic to check liquidity levels
function checkLiquidity() internal view returns (bool) {
// Implement your liquidity checking logic here
// Return true if liquidity is below the threshold
return false; // Example placeholder
}

function checkUpkeep(
bytes calldata
) external view override returns (bool upkeepNeeded, bytes memory) {
upkeepNeeded = checkLiquidity();
}

function performUpkeep(bytes calldata) external override {
if (checkLiquidity()) {
pauseAllContracts();
notifyTeam(
"Security incident detected: Liquidity threshold breached. Contracts paused."
);
}
lastCheckBlock = block.number;
}

function pauseAllContracts() public onlyRole(PAUSER_ROLE) {
// Implement logic to pause all relevant contracts
emit SecurityIncident(
"All contracts paused due to a security incident."
);
}

function notifyTeam(string memory message) public onlyRole(PAUSER_ROLE) {
// Implement logic to notify the team
emit SecurityIncident(message);
}

function supportsInterface(
bytes4 interfaceId
) public view virtual override returns (bool) {
return super.supportsInterface(interfaceId);
}
}
72 changes: 0 additions & 72 deletions packages/contracts/src/dollar/utils/securitymonitor.sol

This file was deleted.

Loading

0 comments on commit 33c7f6b

Please sign in to comment.