// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.2; import "./IComponent.sol"; import "../modules/IAccess.sol"; import "../modules/IComponentEvents.sol"; import "../modules/IRegistry.sol"; import "../services/IComponentOwnerService.sol"; import "../services/IInstanceService.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/GUIDELINES.md#style-guidelines abstract contract Component is IComponent, IComponentEvents, Ownable { bytes32 private _componentName; uint256 private _componentId; IComponent.ComponentType private _componentType; IRegistry private _registry; IAccess private _access; IComponentOwnerService private _componentOwnerService; IInstanceService private _instanceService; modifier onlyInstanceOperatorService() { require( _msgSender() == _getContractAddress("InstanceOperatorService"), "ERROR:CMP-001:NOT_INSTANCE_OPERATOR_SERVICE"); _; } modifier onlyComponent() { require( _msgSender() == _getContractAddress("Component"), "ERROR:CMP-002:NOT_COMPONENT"); _; } modifier onlyComponentOwnerService() { require( _msgSender() == address(_componentOwnerService), "ERROR:CMP-003:NOT_COMPONENT_OWNER_SERVICE"); _; } constructor( bytes32 name, IComponent.ComponentType componentType, address registry ) Ownable() { require(registry != address(0), "ERROR:CMP-004:REGISTRY_ADDRESS_ZERO"); _registry = IRegistry(registry); _access = _getAccess(); _componentOwnerService = _getComponentOwnerService(); _instanceService = _getInstanceService(); _componentName = name; _componentType = componentType; emit LogComponentCreated( _componentName, _componentType, address(this), address(_registry)); } function setId(uint256 id) external override onlyComponent { _componentId = id; } function getName() public override view returns(bytes32) { return _componentName; } function getId() public override view returns(uint256) { return _componentId; } function getType() public override view returns(IComponent.ComponentType) { return _componentType; } function getState() public override view returns(IComponent.ComponentState) { return _instanceService.getComponentState(_componentId); } function getOwner() public override view returns(address) { return owner(); } function isProduct() public override view returns(bool) { return _componentType == IComponent.ComponentType.Product; } function isOracle() public override view returns(bool) { return _componentType == IComponent.ComponentType.Oracle; } function isRiskpool() public override view returns(bool) { return _componentType == IComponent.ComponentType.Riskpool; } function getRegistry() external override view returns(IRegistry) { return _registry; } function proposalCallback() public override onlyComponent { _afterPropose(); } function approvalCallback() public override onlyComponent { _afterApprove(); } function declineCallback() public override onlyComponent { _afterDecline(); } function suspendCallback() public override onlyComponent { _afterSuspend(); } function resumeCallback() public override onlyComponent { _afterResume(); } function pauseCallback() public override onlyComponent { _afterPause(); } function unpauseCallback() public override onlyComponent { _afterUnpause(); } function archiveCallback() public override onlyComponent { _afterArchive(); } // these functions are intended to be overwritten to implement // component specific notification handling function _afterPropose() internal virtual {} function _afterApprove() internal virtual {} function _afterDecline() internal virtual {} function _afterSuspend() internal virtual {} function _afterResume() internal virtual {} function _afterPause() internal virtual {} function _afterUnpause() internal virtual {} function _afterArchive() internal virtual {} function _getAccess() internal view returns (IAccess) { return IAccess(_getContractAddress("Access")); } function _getInstanceService() internal view returns (IInstanceService) { return IInstanceService(_getContractAddress("InstanceService")); } function _getComponentOwnerService() internal view returns (IComponentOwnerService) { return IComponentOwnerService(_getContractAddress("ComponentOwnerService")); } function _getContractAddress(bytes32 contractName) internal view returns (address) { return _registry.getContract(contractName); } }