Skip to content
Verified contractPartialUNLICENSED

HybridControlledAuthority

Address0xa7287701f7ab8f38ef57cdb2a2a69a40128ec89c
Balance

0 ETH

 

Transactions

172

 

Compiler

solc 0.8.31

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.31+commit.fd3a2265
Language
solidity
Optimization
Yes, 0 runs
EVM version
paris
Via IR
yes
License
UNLICENSED
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,978,155
Creation transaction
0xfff92d5ce2…ddae16902d

96 files

The source code is large: one file is shown at a time. Choose a file in the list.

project/contracts/HybridControlledAuthority.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28 ;

import {IAccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import "./authz/interfaces/IControlAuthority.sol";
import "./authz/interfaces/IHybridControlAuthority.sol";
import "./hce/interfaces/IControllable.sol";
import "./hce/HybridControlEngine.sol";

contract HybridControlledAuthority is IControlAuthority, IHybridControlAuthority, IControllable, HybridControlEngine, AccessControlEnumerable {
    // ------------------- Constants  ----------------------------------
    string                 constant ERROR_403          = "[HCA]403/" ;
    string                 constant ERROR_404          = "[HCA]404/" ;

    bytes32 constant ADMIN_ROLE                        = keccak256("ADMIN_ROLE");

    // ------------------- Structures  ---------------------------------
    struct Entitlement {
        bytes32[] roles ;
        address[] users ;
    }

    struct AuthorityStructure {
        bytes32[]              transcientAuthorities ;
        bytes32[]              elevatedAuthorities ;
        Entitlement[]          genesisEntitlement ;
        AuthorizationMatrix[]  authorizationMatrixes ;
    }

    // ------------------- Properties ----------------------------------
    IControlAuthority          private  controlAuthority;
    string                     public   identifier ;

    mapping(bytes32    => bool )    internal isTranscientRole ;
    mapping(bytes32    => bool )    internal isElevatedRole   ;

    // ------------------- Errors / Events -----------------------------

    // ------------------- Modifiers -----------------------------------

    // ------------------- Constructors --------------------------------
    constructor(AuthorityStructure memory _controlStructure) {
        executionContract  = address(this) ;
        authorityContract  = this ;
        _grantRole(ADMIN_ROLE, address(this));

        // No admin, purposedly
        _grantRole(DEFAULT_ADMIN_ROLE, address(0)) ;

        for ( uint256 i = 0 ; i < _controlStructure.genesisEntitlement.length; i++ ) {
             _grantRoles(  _controlStructure.genesisEntitlement[i].roles,  _controlStructure.genesisEntitlement[i].users ) ;
        }

        for ( uint256 i=0; i < _controlStructure.authorizationMatrixes.length; i++ ) {
            if ( _controlStructure.authorizationMatrixes[i].method == IHybridControlEngine.changeAuthorizationMatrixes.selector ||
                    _controlStructure.authorizationMatrixes[i].method == IHybridControlEngine.changeExecutionContract.selector ) {
                policyAuthorizationMatrix = _controlStructure.authorizationMatrixes[i].matrix ;
                isModifiable = true ;
            } else {
                authorizationMatrix[_controlStructure.authorizationMatrixes[i].method] = _controlStructure.authorizationMatrixes[i].matrix ;
            }
        }

        for ( uint256 i=0; i < _controlStructure.elevatedAuthorities.length; i++ ) {
            isElevatedRole[_controlStructure.elevatedAuthorities[i]] = true ;
        }
    }


    /**
     * @dev Returns the current Control Authority
     */
    function getControlAuthority() external view override returns (IControlAuthority) {
        return controlAuthority ;
    }

    /**
     * @dev Change the control authority
     * @param _controlAuthority Address of the new Control Authority
     * Used to conform with the IControllable interface, but this contract is its ownn authority
     */
    function setControlAuthority( IControlAuthority _controlAuthority ) external override onlyElevatedRiskController() returns (IControlAuthority) {
    }

    // ------------------- Getters / Setters ---------------------------
    modifier onlyElevatedRiskController() {
        require ( false, string.concat(ERROR_403, "00") ) ;
        _;
    }

    // ------------------- Methods -------------------------------------

    /**
     * @dev Check wether an EOA is given the requested role
     * @param _role role tested
     * @param _account account tested
     */
    function hasRole( bytes32 _role, address _account ) public view override(AccessControl, IAccessControl, IControlAuthority) returns (bool hasIt ) {
        hasIt = false ;

        if ( isTranscientRole[ _role ] ) {
            try authorityContract.hasRole( _role, _account ) returns (bool b ) {
                hasIt = b ;
            }
            catch ( bytes memory reason ) {
                revert(string.concat( ERROR_404, "99 - ", string(reason))) ;
            }
        } else {
            hasIt = super.hasRole(_role, address(_account)) ;
        }
    }

    /**
     * @dev Check wether an EOA is given the requested role
     * @param _role     role tested
     * @param _scope    scope, when role is restricted on a certain scope of work (or scope of action)
     * @param _account  account tested
     */
    function hasRoleOverScope( bytes32 _role, bytes32 _scope, address _account ) external view returns (bool hasIt) {
        return hasRole( _role, _account ) ;
    }

    /**
     * @dev Grant the gven roles to the given adddresses
     * @param _roles roles to be granted
     * @param _addresses addresses of the accounts to be granted roles. Address can be an EOA or a smart contract
     */
    function _grantRoles( bytes32[] memory _roles, address[] memory _addresses ) internal  {
        for (uint j = 0; j < _roles.length; j++) {
            require( !isElevatedRole[_roles[j]], string.concat( ERROR_404, "93") ) ;
            _setRoleAdmin(_roles[j], ADMIN_ROLE);
            for (uint i = 0; i < _addresses.length; i++) {
                _grantRole(_roles[j], _addresses[i]);
            }
        }
    }

    /**
     * @dev External function, restricted to Admin Role, to grant roles to addresses
     * @param _roles roles to be granted
     * @param _addresses addresses of the accounts to be granted roles. Address can be an EOA or a smart contract
     */
    function grantRoles( bytes32[] memory _roles, address[] calldata _addresses ) external override onlyRole(ADMIN_ROLE) {
        _grantRoles(_roles, _addresses);
    }

    /**
     * @dev External function, restricted to Admin Role, to grant role to a specific address
     * @param _role role to be granted
     * @param _address address to be granted roles. Address can be an EOA or a smart contract
     */
    function grantRole( bytes32 _role, address _address ) public 
            override(AccessControl, IAccessControl) onlyRole(ADMIN_ROLE) {
        require( !isElevatedRole[_role], string.concat( ERROR_404, "94") ) ;
        _setRoleAdmin(_role, ADMIN_ROLE);
        _grantRole(_role, _address);
    }

    /**
     * @dev External function, restricted to Admin Role to revoke a role for a particular account
     * @param _role role to be revoked
     * @param _address address of the account. Address can be an EOA or a smart contract
     */
    function revokeRole( bytes32 _role, address _address ) public
            override(AccessControl, IAccessControl) onlyRole(ADMIN_ROLE) {
        require( !isElevatedRole[_role], string.concat( ERROR_404, "95") ) ;
        _revokeRole(_role, _address);
    }

    /**
     * @dev External function, restricted to Admin Role to revoke a role for a particular account
     * @param _roles roles to be revoked
     * @param _addresses addresses of the account. Address can be an EOA or a smart contract
     */
    function revokeRoles( bytes32[] memory _roles, address[] calldata _addresses ) external override onlyRole(ADMIN_ROLE) {
        for (uint j = 0; j < _roles.length; j++) {
            require( !isElevatedRole[_roles[j]], string.concat( ERROR_404, "96") ) ;
            for (uint i = 0; i < _addresses.length; i++) {
                _revokeRole(_roles[j], _addresses[i]);
            }
        }
    }

    /**
     * @dev External function, restricted to Admin Role to grant a role marked as elevated for a list of accounts 
     * @param _role elevated role to be granted
     * @param _addresses addresses of the account. Address can be an EOA or a smart contract
     */
    function grantElevatedRole( bytes32 _role, address[] memory _addresses ) external override onlyRole(ADMIN_ROLE) {
        require( isElevatedRole[_role], string.concat( ERROR_404, "98") ) ;
        _setRoleAdmin(_role, ADMIN_ROLE);
        for ( uint j = 0; j < _addresses.length;j++ ) {
            _grantRole(_role, _addresses[j]);
        }
    }

    /**
     * @dev External function, restricted to Admin Role to revoke a role marked as elevated for a list of accounts
     * @param _role elevated role to be revoked
     * @param _addresses addresses of the account. Address can be an EOA or a smart contract
     */
    function revokeElevatedRole( bytes32 _role, address[] memory _addresses ) external override onlyRole(ADMIN_ROLE) {
        require( isElevatedRole[_role], string.concat( ERROR_404, "97") ) ;
        
        for ( uint j = 0; j < _addresses.length;j++ ) {
            _revokeRole(_role, _addresses[j]);
        }
    }

    /**
     * @dev External function, restricted to Admin Role to mark a role as elevated
     * @param _role role to be elevated
     */
    function elevateRole( bytes32 _role ) external override onlyRole(ADMIN_ROLE) {
        require( !isElevatedRole[_role], string.concat( ERROR_404, "92") ) ;
        isElevatedRole[_role] = true ;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 0,
    "enabled": true
  },
  "evmVersion": "paris",
  "remappings": [
    "project/:@openzeppelin/contracts-upgradeable/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:forge-std/=project/lib/forge-std/src/",
    "project/:hardhat/=npm/[email protected]/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.