Skip to content

Commit f0d1620

Browse files
move component status handling to platform, minor refactoring
1 parent 8e88f23 commit f0d1620

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

contracts/components/Component.sol

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "../modules/IAccess.sol";
66
import "../modules/IComponentEvents.sol";
77
import "../modules/IRegistry.sol";
88
import "../services/IComponentOwnerService.sol";
9+
import "../services/IInstanceService.sol";
910
import "@openzeppelin/contracts/access/Ownable.sol";
1011

1112

@@ -17,20 +18,14 @@ abstract contract Component is
1718
{
1819
bytes32 private _componentName;
1920
uint256 private _componentId;
20-
ComponentType private _componentType;
21-
ComponentState private _componentState;
21+
IComponent.ComponentType private _componentType;
2222

2323
bytes32 private _requiredRole;
2424

2525
IRegistry private _registry;
2626
IAccess private _access;
2727
IComponentOwnerService private _componentOwnerService;
28-
29-
event LogComponentCreated (
30-
bytes32 componentName,
31-
ComponentType componentType,
32-
address componentAddress,
33-
address registryAddress);
28+
IInstanceService private _instanceService;
3429

3530
modifier onlyInstanceOperatorService() {
3631
require(
@@ -55,7 +50,7 @@ abstract contract Component is
5550

5651
constructor(
5752
bytes32 name,
58-
ComponentType componentType,
53+
IComponent.ComponentType componentType,
5954
address registry
6055
)
6156
Ownable()
@@ -68,7 +63,6 @@ abstract contract Component is
6863

6964
_componentName = name;
7065
_componentType = componentType;
71-
_componentState = ComponentState.Created;
7266
_requiredRole = _getRequiredRole();
7367

7468
emit LogComponentCreated(
@@ -79,17 +73,16 @@ abstract contract Component is
7973
}
8074

8175
function setId(uint256 id) external override onlyComponent { _componentId = id; }
82-
function setState(ComponentState state) external override onlyComponent { _componentState = state; }
8376

8477
function getName() public override view returns(bytes32) { return _componentName; }
8578
function getId() public override view returns(uint256) { return _componentId; }
86-
function getType() public override view returns(ComponentType) { return _componentType; }
87-
function getState() public override view returns(ComponentState) { return _componentState; }
79+
function getType() public override view returns(IComponent.ComponentType) { return _componentType; }
80+
function getState() public override view returns(IComponent.ComponentState) { return _instanceService.getComponentState(_componentId); }
8881
function getOwner() public override view returns(address) { return owner(); }
8982

90-
function isProduct() public override view returns(bool) { return _componentType == ComponentType.Product; }
91-
function isOracle() public override view returns(bool) { return _componentType == ComponentType.Oracle; }
92-
function isRiskpool() public override view returns(bool) { return _componentType == ComponentType.Riskpool; }
83+
function isProduct() public override view returns(bool) { return _componentType == IComponent.ComponentType.Product; }
84+
function isOracle() public override view returns(bool) { return _componentType == IComponent.ComponentType.Oracle; }
85+
function isRiskpool() public override view returns(bool) { return _componentType == IComponent.ComponentType.Riskpool; }
9386

9487
function getRequiredRole() public override view returns(bytes32) { return _requiredRole; }
9588

@@ -121,6 +114,10 @@ abstract contract Component is
121114
return IAccess(_getContractAddress("Access"));
122115
}
123116

117+
function _getInstanceService() internal returns (IInstanceService) {
118+
return IInstanceService(_getContractAddress("InstanceService"));
119+
}
120+
124121
function _getComponentOwnerService() internal returns (IComponentOwnerService) {
125122
return IComponentOwnerService(_getContractAddress("ComponentOwnerService"));
126123
}

contracts/components/IComponent.sol

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.0;
33

4-
enum ComponentType {
5-
Oracle,
6-
Product,
7-
Riskpool
8-
}
9-
10-
enum ComponentState {
11-
Created,
12-
Proposed,
13-
Declined,
14-
Active,
15-
Paused,
16-
Suspended
17-
}
18-
194
interface IComponent {
205

6+
enum ComponentType {
7+
Oracle,
8+
Product,
9+
Riskpool
10+
}
11+
12+
enum ComponentState {
13+
Created,
14+
Proposed,
15+
Declined,
16+
Active,
17+
Paused,
18+
Suspended
19+
}
20+
21+
event LogComponentCreated (
22+
bytes32 componentName,
23+
IComponent.ComponentType componentType,
24+
address componentAddress,
25+
address registryAddress);
26+
2127
function setId(uint256 id) external;
22-
function setState(ComponentState state) external;
2328

2429
function getName() external view returns(bytes32);
2530
function getId() external view returns(uint256);

contracts/modules/IComponentEvents.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface IComponentEvents {
77

88
event LogComponentProposed (
99
bytes32 componentName,
10-
ComponentType componentType,
10+
IComponent.ComponentType componentType,
1111
address componentAddress,
1212
uint256 id);
1313

@@ -20,5 +20,8 @@ interface IComponentEvents {
2020
event LogComponentPaused (uint256 id);
2121
event LogComponentUnpaused (uint256 id);
2222

23-
event LogComponentStateChanged (uint256 id, ComponentState stateOld, ComponentState stateNew);
23+
event LogComponentStateChanged (
24+
uint256 id,
25+
IComponent.ComponentState stateOld,
26+
IComponent.ComponentState stateNew);
2427
}

contracts/services/IInstanceService.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.0;
33

4+
import "../components/IComponent.sol";
45
import "../modules/IBundle.sol";
56
import "../modules/IPolicy.sol";
67
import "../tokens/IBundleToken.sol";
@@ -42,6 +43,8 @@ interface IInstanceService {
4243
function riskpools() external view returns(uint256 numberOfRiskpools);
4344

4445
function getComponent(uint256 componentId) external view returns(IComponent component);
46+
function getComponentType(uint256 componentId) external view returns(IComponent.ComponentType componentType);
47+
function getComponentState(uint256 componentId) external view returns(IComponent.ComponentState componentState);
4548

4649
// service staking
4750
function getStakingRequirements(uint256 componentId) external view returns(bytes memory data);

0 commit comments

Comments
 (0)