diff --git a/contracts/components/Roles.sol b/contracts/components/Roles.sol index d9776930..2b94a381 100644 --- a/contracts/components/Roles.sol +++ b/contracts/components/Roles.sol @@ -34,5 +34,5 @@ bytes32 constant ALLOCATOR_CONTRACT_ROLE = keccak256("ALLOCATOR_CONTRACT_ROLE"); bytes32 constant SCANNER_VERSION_ROLE = keccak256("SCANNER_VERSION_ROLE"); bytes32 constant SCANNER_BETA_VERSION_ROLE = keccak256("SCANNER_BETA_VERSION_ROLE"); -// Threat Oracles +// Threat Oracle bytes32 constant THREAT_ORACLE_ADMIN_ROLE = keccak256("THREAT_ORACLE_ADMIN_ROLE"); \ No newline at end of file diff --git a/contracts/components/threat_oracle/ThreatOracle.sol b/contracts/components/threat_oracle/ThreatOracle.sol index f881aea3..2c0d915b 100644 --- a/contracts/components/threat_oracle/ThreatOracle.sol +++ b/contracts/components/threat_oracle/ThreatOracle.sol @@ -16,7 +16,7 @@ contract ThreatOracle is BaseComponentUpgradeable, ThreatOracleCore { * @param __manager address of AccessManager. */ function initialize( - address __manager, + address __manager ) public initializer { __BaseComponentUpgradeable_init(__manager); } diff --git a/contracts/components/threat_oracle/ThreatOracleCore.sol b/contracts/components/threat_oracle/ThreatOracleCore.sol index 6ef53c5b..9a45a2e4 100644 --- a/contracts/components/threat_oracle/ThreatOracleCore.sol +++ b/contracts/components/threat_oracle/ThreatOracleCore.sol @@ -11,10 +11,10 @@ abstract contract ThreatOracleCore is BaseComponentUpgradeable { EnumerableMap.AddressToUintMap private _addressThreatLevel; - event AddressThreatLevelSet(address indexed address, uint256 indexed threatLevel); + event AddressThreatLevelSet(address indexed _address, uint256 indexed threatLevel); error IncorrectAmounts(uint256 addressAmount, uint256 threatLevelAmount); - error ThreatLevelAlreadySet(address address, uint256 threatLevel); + error ThreatLevelAlreadySet(address _address, uint256 threatLevel); function setThreatLevels(address[] calldata addresses, uint256[] calldata threatLevels) external onlyRole(THREAT_ORACLE_ADMIN_ROLE) { if (addresses.length != threatLevels.length) revert IncorrectAmounts(addresses.length, threatLevels.length); @@ -24,19 +24,19 @@ abstract contract ThreatOracleCore is BaseComponentUpgradeable { } } - function _setThreatLevel(address address, uint256 threatLevel) private { - if (getThreatLevel(address) == threatLevel) revert ThreatLevelAlreadySet(address, threatLevel); + function _setThreatLevel(address _address, uint256 threatLevel) private { + if (getThreatLevel(_address) == threatLevel) revert ThreatLevelAlreadySet(_address, threatLevel); - _addressThreatLevel.set(address, threatLevel); - emit AddressThreatLevelSet(address, threatLevel); + _addressThreatLevel.set(_address, threatLevel); + emit AddressThreatLevelSet(_address, threatLevel); } - function getThreatLevel(address address) public view returns (uint) { - return _addressThreatLevel.get(address); + function getThreatLevel(address _address) public view returns (uint) { + return _addressThreatLevel.get(_address); } - function isRegistered(address address) public view returns (bool) { - return _addressThreatLevel.contains(address); + function isRegistered(address _address) public view returns (bool) { + return _addressThreatLevel.contains(_address); } function totalAddressesRegistered() public view returns (uint256) { diff --git a/scripts/deployments/platform.js b/scripts/deployments/platform.js index 0ba5cc11..da11ee6f 100644 --- a/scripts/deployments/platform.js +++ b/scripts/deployments/platform.js @@ -274,6 +274,22 @@ async function migrate(config = {}) { CACHE ); DEBUG(`[${Object.keys(contracts).length}] dispatch: ${contracts.dispatch.address}`); + + // Threat Oracle + + DEBUG(`Deploying ThreatOracle...`); + contracts.threatOracle = await contractHelpers.tryFetchProxy( + hre, + 'ThreatOracle', + 'uups', + [contracts.access.address], + { + constructorArgs: [contracts.forwarder.address], + unsafeAllow: 'delegatecall', + }, + CACHE + ); + DEBUG(`[${Object.keys(contracts).length}] threat oracle: ${contracts.dispatch.address}`); } // Roles dictionary diff --git a/test/components/threat.oracle.test.js b/test/components/threat.oracle.test.js index ad371dfb..b5ac4bfa 100644 --- a/test/components/threat.oracle.test.js +++ b/test/components/threat.oracle.test.js @@ -1,7 +1,34 @@ +const { ethers } = require('hardhat'); +const { expect } = require('chai'); +const { prepare } = require('../fixture'); +function createAddress(address) { + const paddedAddress = ethers.utils.hexZeroPad(address, 20); + return paddedAddress.toLowerCase(); +} -describe('Threat Oracles', function () { - it('registers multiple addresses to the threat oracle', { - +function createAddresses(addressAmount) { + const generatedAddresses = []; + for (let i = 1; i <= addressAmount; i++) { + generatedAddresses.push(createAddress(i)); + } + return generatedAddresses; +} + +const mockAddresses = [...createAddresses(10)]; + +describe('Threat Oracles', async function () { + prepare(/*{ stake: { agents: { min: '100', max: '500', activated: true } } }*/); + + it('registers multiple addresses to the threat oracle', async function () { + // TODO: Update `getThreatOracle` to use `tryGet` instead + console.log(await this.threatOracle.getThreatLevel(mockAddresses[0])); + // expect(await this.threatOracle.getThreatLevel()).to.be.equal(); + + /* + await expect(this.agents.connect(this.accounts.manager).setFrontRunningDelay('1800')) + .to.emit(this.agents, 'FrontRunningDelaySet') + .withArgs(ethers.BigNumber.from('1800')); + */ }); }) \ No newline at end of file diff --git a/test/fixture.js b/test/fixture.js index 338716a1..a5e0cf51 100644 --- a/test/fixture.js +++ b/test/fixture.js @@ -48,6 +48,7 @@ function prepare(config = {}) { this.access.connect(this.accounts.admin).grantRole(this.roles.STAKING_CONTRACT, this.contracts.staking.address), this.access.connect(this.accounts.admin).grantRole(this.roles.ALLOCATOR_CONTRACT, this.contracts.stakeAllocator.address), this.access.connect(this.accounts.admin).grantRole(this.roles.MIGRATION_EXECUTOR, this.accounts.manager.address), + this.access.connect(this.accounts.admin).grantRole(this.roles.THREAT_ORACLE_ADMIN, this.accounts.manager.address), this.token.connect(this.accounts.admin).grantRole(this.roles.MINTER, this.accounts.minter.address), this.otherToken.connect(this.accounts.admin).grantRole(this.roles.MINTER, this.accounts.minter.address), ].map((txPromise) => txPromise.then((tx) => tx.wait()).catch(() => {}))