@etherisc/gif-next 0.0.2-b9b3e89 → 0.0.2-c4efd5e
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +25 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +7 -7
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +6 -6
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +8 -8
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +29 -11
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +31 -13
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +122 -64
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -33
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +100 -42
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
- package/contracts/components/Component.sol +17 -19
- package/contracts/components/IPool.sol +3 -3
- package/contracts/components/IProduct.sol +4 -6
- package/contracts/components/Pool.sol +6 -13
- package/contracts/components/Product.sol +12 -22
- package/contracts/experiment/errors/Require.sol +38 -0
- package/contracts/experiment/errors/Revert.sol +44 -0
- package/contracts/experiment/inheritance/A.sol +53 -0
- package/contracts/experiment/inheritance/B.sol +28 -0
- package/contracts/experiment/inheritance/C.sol +34 -0
- package/contracts/experiment/inheritance/IA.sol +13 -0
- package/contracts/experiment/inheritance/IB.sol +10 -0
- package/contracts/experiment/inheritance/IC.sol +12 -0
- package/contracts/experiment/types/TypeA.sol +47 -0
- package/contracts/experiment/types/TypeB.sol +29 -0
- package/contracts/instance/IInstance.sol +4 -6
- package/contracts/instance/Instance.sol +15 -14
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +84 -130
- package/contracts/instance/component/IComponent.sol +32 -53
- package/contracts/instance/policy/IPolicy.sol +12 -27
- package/contracts/instance/policy/PolicyModule.sol +25 -40
- package/contracts/instance/pool/IPoolModule.sol +10 -21
- package/contracts/instance/pool/PoolModule.sol +28 -38
- package/contracts/instance/product/IProductService.sol +9 -18
- package/contracts/instance/product/ProductService.sol +54 -47
- package/contracts/registry/ChainNft.sol +135 -0
- package/contracts/registry/IChainNft.sol +21 -0
- package/contracts/registry/IRegistry.sol +52 -38
- package/contracts/registry/Registry.sol +107 -95
- package/contracts/types/Blocknumber.sol +118 -0
- package/contracts/types/ChainId.sol +38 -0
- package/contracts/types/NftId.sol +51 -0
- package/contracts/types/Timestamp.sol +102 -0
- package/contracts/types/UFixed.sol +205 -0
- package/package.json +7 -3
@@ -4,7 +4,6 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {IOwnable, IRegistryLinked} from "../../registry/IRegistry.sol";
|
5
5
|
|
6
6
|
interface IAccess {
|
7
|
-
|
8
7
|
struct RoleInfo {
|
9
8
|
bytes32 id;
|
10
9
|
string name;
|
@@ -13,71 +12,52 @@ interface IAccess {
|
|
13
12
|
}
|
14
13
|
|
15
14
|
interface IAccessCheckRole {
|
16
|
-
|
17
|
-
function hasRole(bytes32 role, address member)
|
18
|
-
external
|
19
|
-
view
|
20
|
-
returns(bool);
|
15
|
+
function hasRole(bytes32 role, address member) external view returns (bool);
|
21
16
|
}
|
22
17
|
|
23
18
|
interface IAccessComponentTypeRoles {
|
24
|
-
function PRODUCT_OWNER_ROLE() external view returns(bytes32 role);
|
25
|
-
function ORACLE_OWNER_ROLE() external view returns(bytes32 role);
|
26
|
-
function POOL_OWNER_ROLE() external view returns(bytes32 role);
|
27
|
-
}
|
19
|
+
function PRODUCT_OWNER_ROLE() external view returns (bytes32 role);
|
28
20
|
|
21
|
+
function ORACLE_OWNER_ROLE() external view returns (bytes32 role);
|
29
22
|
|
30
|
-
|
23
|
+
function POOL_OWNER_ROLE() external view returns (bytes32 role);
|
24
|
+
}
|
25
|
+
|
26
|
+
interface IAccessModule is
|
31
27
|
IOwnable,
|
32
28
|
IRegistryLinked,
|
33
29
|
IAccess,
|
34
30
|
IAccessComponentTypeRoles,
|
35
31
|
IAccessCheckRole
|
36
32
|
{
|
33
|
+
function createRole(string memory roleName) external returns (bytes32 role);
|
37
34
|
|
38
|
-
function
|
39
|
-
external
|
40
|
-
returns(bytes32 role);
|
41
|
-
|
42
|
-
function enableRole(bytes32 role)
|
43
|
-
external;
|
35
|
+
function enableRole(bytes32 role) external;
|
44
36
|
|
45
|
-
function disableRole(bytes32 role)
|
46
|
-
external;
|
37
|
+
function disableRole(bytes32 role) external;
|
47
38
|
|
48
|
-
function grantRole(bytes32 role, address member)
|
49
|
-
external;
|
39
|
+
function grantRole(bytes32 role, address member) external;
|
50
40
|
|
51
|
-
function revokeRole(bytes32 role, address member)
|
52
|
-
external;
|
41
|
+
function revokeRole(bytes32 role, address member) external;
|
53
42
|
|
54
|
-
function getRole(uint256 idx)
|
55
|
-
external
|
56
|
-
view
|
57
|
-
returns(bytes32 role);
|
43
|
+
function getRole(uint256 idx) external view returns (bytes32 role);
|
58
44
|
|
59
|
-
function getRoleInfo(
|
60
|
-
|
61
|
-
|
62
|
-
returns(RoleInfo memory info);
|
45
|
+
function getRoleInfo(
|
46
|
+
bytes32 role
|
47
|
+
) external view returns (RoleInfo memory info);
|
63
48
|
|
64
|
-
function getRoleForName(
|
65
|
-
|
66
|
-
|
67
|
-
returns(bytes32 role);
|
49
|
+
function getRoleForName(
|
50
|
+
string memory roleName
|
51
|
+
) external pure returns (bytes32 role);
|
68
52
|
|
69
|
-
function getRoleCount()
|
70
|
-
external
|
71
|
-
view
|
72
|
-
returns(uint256 roles);
|
53
|
+
function getRoleCount() external view returns (uint256 roles);
|
73
54
|
|
74
|
-
function getRoleMemberCount(
|
75
|
-
|
76
|
-
|
77
|
-
returns(uint256 roleMembers);
|
55
|
+
function getRoleMemberCount(
|
56
|
+
bytes32 role
|
57
|
+
) external view returns (uint256 roleMembers);
|
78
58
|
|
79
|
-
function getRoleMember(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
59
|
+
function getRoleMember(
|
60
|
+
bytes32 role,
|
61
|
+
uint256 idx
|
62
|
+
) external view returns (address roleMembers);
|
63
|
+
}
|
@@ -9,26 +9,30 @@ import {IInstance} from "../IInstance.sol";
|
|
9
9
|
import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
|
10
10
|
import {IProductComponent} from "../../components/IProduct.sol";
|
11
11
|
import {IPoolModule} from "../pool/IPoolModule.sol";
|
12
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
12
13
|
|
13
|
-
|
14
|
-
abstract contract ComponentModule is
|
14
|
+
abstract contract ComponentModule is
|
15
15
|
IRegistryLinked,
|
16
16
|
IAccessComponentTypeRoles,
|
17
17
|
IAccessCheckRole,
|
18
18
|
IComponentModule
|
19
19
|
{
|
20
|
+
using NftIdLib for NftId;
|
20
21
|
|
21
|
-
mapping(
|
22
|
-
mapping(
|
23
|
-
mapping(address cAddress =>
|
24
|
-
|
22
|
+
mapping(NftId nftId => ComponentInfo info) private _componentInfo;
|
23
|
+
mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
|
24
|
+
mapping(address cAddress => NftId nftId) private _nftIdByAddress;
|
25
|
+
NftId[] private _nftIds;
|
25
26
|
|
26
27
|
mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
|
27
28
|
|
28
29
|
IComponentOwnerService private _componentOwnerService;
|
29
30
|
|
30
31
|
modifier onlyComponentOwnerService() {
|
31
|
-
require(
|
32
|
+
require(
|
33
|
+
address(_componentOwnerService) == msg.sender,
|
34
|
+
"ERROR:CMP-001:NOT_OWNER_SERVICE"
|
35
|
+
);
|
32
36
|
_;
|
33
37
|
}
|
34
38
|
|
@@ -36,35 +40,30 @@ abstract contract ComponentModule is
|
|
36
40
|
_componentOwnerService = ComponentOwnerService(componentOwnerService);
|
37
41
|
}
|
38
42
|
|
39
|
-
function registerComponent(
|
40
|
-
|
41
|
-
|
42
|
-
onlyComponentOwnerService
|
43
|
-
returns(uint256 nftId)
|
44
|
-
{
|
43
|
+
function registerComponent(
|
44
|
+
IComponentContract component
|
45
|
+
) external override onlyComponentOwnerService returns (NftId nftId) {
|
45
46
|
bytes32 typeRole = getRoleForType(component.getType());
|
46
47
|
require(
|
47
48
|
this.hasRole(typeRole, component.getInitialOwner()),
|
48
|
-
"ERROR:CMP-004:TYPE_ROLE_MISSING"
|
49
|
-
|
49
|
+
"ERROR:CMP-004:TYPE_ROLE_MISSING"
|
50
|
+
);
|
51
|
+
|
50
52
|
nftId = this.getRegistry().register(address(component));
|
51
53
|
|
52
|
-
_componentInfo[nftId] = ComponentInfo(
|
53
|
-
nftId,
|
54
|
-
CState.Active);
|
54
|
+
_componentInfo[nftId] = ComponentInfo(nftId, CState.Active);
|
55
55
|
|
56
56
|
// special case product -> persist product - pool assignment
|
57
|
-
if(component.getType() == this.getRegistry().PRODUCT()) {
|
57
|
+
if (component.getType() == this.getRegistry().PRODUCT()) {
|
58
58
|
IProductComponent product = IProductComponent(address(component));
|
59
|
-
|
60
|
-
require(poolNftId
|
59
|
+
NftId poolNftId = product.getPoolNftId();
|
60
|
+
require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
|
61
61
|
// add more validation (type, token, ...)
|
62
62
|
|
63
63
|
_poolNftIdForProduct[nftId] = poolNftId;
|
64
64
|
|
65
65
|
// add creation of productInfo
|
66
|
-
}
|
67
|
-
else if(component.getType() == this.getRegistry().POOL()) {
|
66
|
+
} else if (component.getType() == this.getRegistry().POOL()) {
|
68
67
|
IPoolModule poolModule = IPoolModule(address(this));
|
69
68
|
poolModule.createPoolInfo(
|
70
69
|
nftId,
|
@@ -73,122 +72,96 @@ abstract contract ComponentModule is
|
|
73
72
|
);
|
74
73
|
}
|
75
74
|
|
76
|
-
|
77
|
-
|
75
|
+
_nftIdByAddress[address(component)] = nftId;
|
76
|
+
_nftIds.push(nftId);
|
78
77
|
|
79
78
|
// add logging
|
80
79
|
}
|
81
80
|
|
82
|
-
function getPoolNftId(
|
83
|
-
|
84
|
-
|
85
|
-
override
|
86
|
-
returns(uint256 poolNftId)
|
87
|
-
{
|
81
|
+
function getPoolNftId(
|
82
|
+
NftId productNftId
|
83
|
+
) external view override returns (NftId poolNftId) {
|
88
84
|
poolNftId = _poolNftIdForProduct[productNftId];
|
89
85
|
}
|
90
86
|
|
91
|
-
|
92
87
|
function getComponentOwnerService()
|
93
88
|
external
|
94
|
-
override
|
95
89
|
view
|
96
|
-
|
90
|
+
override
|
91
|
+
returns (IComponentOwnerService)
|
97
92
|
{
|
98
93
|
return _componentOwnerService;
|
99
94
|
}
|
100
95
|
|
101
|
-
function setComponentInfo(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
{
|
106
|
-
uint256 id = info.nftId;
|
96
|
+
function setComponentInfo(
|
97
|
+
ComponentInfo memory info
|
98
|
+
) external onlyComponentOwnerService returns (NftId nftId) {
|
99
|
+
nftId = info.nftId;
|
107
100
|
require(
|
108
|
-
|
109
|
-
"ERROR:CMP-
|
101
|
+
nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
|
102
|
+
"ERROR:CMP-006:COMPONENT_UNKNOWN"
|
103
|
+
);
|
110
104
|
|
111
|
-
_componentInfo[
|
105
|
+
_componentInfo[nftId] = info;
|
112
106
|
|
113
107
|
// add logging
|
114
108
|
}
|
115
109
|
|
116
|
-
function getComponentInfo(
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
returns(ComponentInfo memory)
|
121
|
-
{
|
122
|
-
return _componentInfo[id];
|
110
|
+
function getComponentInfo(
|
111
|
+
NftId nftId
|
112
|
+
) external view override returns (ComponentInfo memory) {
|
113
|
+
return _componentInfo[nftId];
|
123
114
|
}
|
124
115
|
|
125
|
-
function getComponentOwner(
|
126
|
-
|
127
|
-
|
128
|
-
returns(address owner)
|
129
|
-
{
|
116
|
+
function getComponentOwner(
|
117
|
+
NftId nftId
|
118
|
+
) external view returns (address owner) {}
|
130
119
|
|
120
|
+
function getComponentId(
|
121
|
+
address componentAddress
|
122
|
+
) external view returns (NftId componentNftId) {
|
123
|
+
return _nftIdByAddress[componentAddress];
|
131
124
|
}
|
132
125
|
|
133
|
-
function getComponentId(
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
{
|
138
|
-
return _idByAddress[componentAddress];
|
126
|
+
function getComponentId(
|
127
|
+
uint256 idx
|
128
|
+
) external view override returns (NftId componentNftId) {
|
129
|
+
return _nftIds[idx];
|
139
130
|
}
|
140
131
|
|
141
|
-
|
142
|
-
function getComponentId(uint256 idx)
|
143
|
-
external
|
144
|
-
override
|
145
|
-
view
|
146
|
-
returns(uint256 id)
|
147
|
-
{
|
148
|
-
return _ids[idx];
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
132
|
function components()
|
153
133
|
external
|
154
|
-
override
|
155
134
|
view
|
156
|
-
|
135
|
+
override
|
136
|
+
returns (uint256 numberOfCompnents)
|
157
137
|
{
|
158
|
-
return
|
138
|
+
return _nftIds.length;
|
159
139
|
}
|
160
140
|
|
161
|
-
function getRoleForType(uint256 cType)
|
162
|
-
|
163
|
-
view
|
164
|
-
returns(bytes32 role)
|
165
|
-
{
|
166
|
-
if(cType == this.getRegistry().PRODUCT()) {
|
141
|
+
function getRoleForType(uint256 cType) public view returns (bytes32 role) {
|
142
|
+
if (cType == this.getRegistry().PRODUCT()) {
|
167
143
|
return this.PRODUCT_OWNER_ROLE();
|
168
144
|
}
|
169
|
-
if(cType == this.getRegistry().POOL()) {
|
145
|
+
if (cType == this.getRegistry().POOL()) {
|
170
146
|
return this.POOL_OWNER_ROLE();
|
171
147
|
}
|
172
|
-
if(cType == this.getRegistry().ORACLE()) {
|
148
|
+
if (cType == this.getRegistry().ORACLE()) {
|
173
149
|
return this.ORACLE_OWNER_ROLE();
|
174
150
|
}
|
175
|
-
|
176
151
|
}
|
177
152
|
}
|
178
153
|
|
179
|
-
|
180
154
|
// this is actually the component owner service
|
181
155
|
contract ComponentOwnerService is
|
182
156
|
RegistryLinked,
|
183
157
|
IComponent,
|
184
158
|
IComponentOwnerService
|
185
159
|
{
|
160
|
+
using NftIdLib for NftId;
|
186
161
|
|
187
162
|
modifier onlyComponentOwner(IComponentContract component) {
|
188
|
-
|
189
|
-
require(
|
190
|
-
nftId > 0,
|
191
|
-
"ERROR:COS-001:COMPONENT_UNKNOWN");
|
163
|
+
NftId nftId = _registry.getNftId(address(component));
|
164
|
+
require(nftId.gtz(), "ERROR:COS-001:COMPONENT_UNKNOWN");
|
192
165
|
require(
|
193
166
|
msg.sender == _registry.getOwner(nftId),
|
194
167
|
"ERROR:COS-002:NOT_OWNER"
|
@@ -196,64 +169,45 @@ contract ComponentOwnerService is
|
|
196
169
|
_;
|
197
170
|
}
|
198
171
|
|
199
|
-
constructor(address registry)
|
200
|
-
RegistryLinked(registry)
|
201
|
-
{ }
|
172
|
+
constructor(address registry) RegistryLinked(registry) {}
|
202
173
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
// // TODO add set/getComponentOwnerRole to IComonentModule
|
207
|
-
// bytes32 typeRole = instance.getComponentTypeRole(component.getType());
|
208
|
-
// require(
|
209
|
-
// instance.hasRole(typeRole, msg.sender),
|
210
|
-
// "ERROR:COS-003:COMPONENT_ROLE_MISSING"
|
211
|
-
// );
|
212
|
-
// _;
|
213
|
-
// }
|
214
|
-
|
215
|
-
|
216
|
-
function register(IComponentContract component)
|
217
|
-
external
|
218
|
-
override
|
219
|
-
returns(uint256 nftId)
|
220
|
-
{
|
174
|
+
function register(
|
175
|
+
IComponentContract component
|
176
|
+
) external override returns (NftId nftId) {
|
221
177
|
require(
|
222
|
-
msg.sender == component.getInitialOwner(),
|
223
|
-
"ERROR:COS-003:NOT_OWNER"
|
178
|
+
msg.sender == component.getInitialOwner(),
|
179
|
+
"ERROR:COS-003:NOT_OWNER"
|
180
|
+
);
|
224
181
|
|
225
182
|
IInstance instance = component.getInstance();
|
226
183
|
nftId = instance.registerComponent(component);
|
227
184
|
}
|
228
185
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
override
|
233
|
-
onlyComponentOwner(component)
|
234
|
-
{
|
186
|
+
function lock(
|
187
|
+
IComponentContract component
|
188
|
+
) external override onlyComponentOwner(component) {
|
235
189
|
IInstance instance = component.getInstance();
|
236
|
-
ComponentInfo memory info = instance.getComponentInfo(
|
237
|
-
|
190
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
191
|
+
component.getNftId()
|
192
|
+
);
|
193
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
238
194
|
// TODO add state change validation
|
239
195
|
|
240
196
|
info.state = CState.Locked;
|
241
197
|
instance.setComponentInfo(info);
|
242
198
|
}
|
243
199
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
override
|
248
|
-
onlyComponentOwner(component)
|
249
|
-
{
|
200
|
+
function unlock(
|
201
|
+
IComponentContract component
|
202
|
+
) external override onlyComponentOwner(component) {
|
250
203
|
IInstance instance = component.getInstance();
|
251
|
-
ComponentInfo memory info = instance.getComponentInfo(
|
252
|
-
|
204
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
205
|
+
component.getNftId()
|
206
|
+
);
|
207
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
253
208
|
// TODO state change validation
|
254
209
|
|
255
210
|
info.state = CState.Active;
|
256
211
|
instance.setComponentInfo(info);
|
257
212
|
}
|
258
|
-
|
259
|
-
}
|
213
|
+
}
|
@@ -1,12 +1,11 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
6
|
+
import {NftId} from "../../types/NftId.sol";
|
7
7
|
|
8
8
|
interface IComponent {
|
9
|
-
|
10
9
|
// TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
|
11
10
|
enum CState {
|
12
11
|
Undefined,
|
@@ -16,79 +15,59 @@ interface IComponent {
|
|
16
15
|
|
17
16
|
// component dynamic info (static info kept in registry)
|
18
17
|
struct ComponentInfo {
|
19
|
-
|
18
|
+
NftId nftId;
|
20
19
|
CState state;
|
21
20
|
}
|
22
21
|
}
|
23
22
|
|
24
|
-
|
25
23
|
interface IInstanceLinked {
|
26
24
|
// function setInstance(address instance) external;
|
27
|
-
function getInstance() external view returns(IInstance instance);
|
25
|
+
function getInstance() external view returns (IInstance instance);
|
28
26
|
}
|
29
27
|
|
28
|
+
interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {}
|
30
29
|
|
31
|
-
interface
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
{ }
|
30
|
+
interface IComponentOwnerService is IRegistryLinked {
|
31
|
+
function register(
|
32
|
+
IComponentContract component
|
33
|
+
) external returns (NftId nftId);
|
36
34
|
|
37
|
-
|
38
|
-
interface IComponentOwnerService is IRegistryLinked{
|
39
|
-
|
40
|
-
function register(IComponentContract component) external returns(uint256 id);
|
41
35
|
function lock(IComponentContract component) external;
|
36
|
+
|
42
37
|
function unlock(IComponentContract component) external;
|
43
38
|
}
|
44
39
|
|
40
|
+
interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
|
41
|
+
function registerComponent(
|
42
|
+
IComponentContract component
|
43
|
+
) external returns (NftId nftId);
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
IComponent
|
50
|
-
{
|
45
|
+
function setComponentInfo(
|
46
|
+
ComponentInfo memory info
|
47
|
+
) external returns (NftId componentNftId);
|
51
48
|
|
52
|
-
function
|
53
|
-
|
54
|
-
|
49
|
+
function getComponentInfo(
|
50
|
+
NftId nftId
|
51
|
+
) external view returns (ComponentInfo memory info);
|
55
52
|
|
56
|
-
function
|
57
|
-
|
58
|
-
|
53
|
+
function getComponentOwner(
|
54
|
+
NftId nftId
|
55
|
+
) external view returns (address owner);
|
59
56
|
|
60
|
-
function
|
61
|
-
|
62
|
-
|
63
|
-
returns(ComponentInfo memory info);
|
57
|
+
function getComponentId(
|
58
|
+
address componentAddress
|
59
|
+
) external view returns (NftId nftId);
|
64
60
|
|
65
|
-
function
|
66
|
-
external
|
67
|
-
view
|
68
|
-
returns(address owner);
|
61
|
+
function getComponentId(uint256 idx) external view returns (NftId nftId);
|
69
62
|
|
70
|
-
function
|
71
|
-
|
72
|
-
|
73
|
-
returns(uint256 id);
|
63
|
+
function getPoolNftId(
|
64
|
+
NftId productNftId
|
65
|
+
) external view returns (NftId poolNftId);
|
74
66
|
|
75
|
-
function
|
76
|
-
external
|
77
|
-
view
|
78
|
-
returns(uint256 id);
|
79
|
-
|
80
|
-
function getPoolNftId(uint256 productNftId)
|
81
|
-
external
|
82
|
-
view
|
83
|
-
returns(uint256 poolNftId);
|
84
|
-
|
85
|
-
function components()
|
86
|
-
external
|
87
|
-
view
|
88
|
-
returns(uint256 numberOfCompnents);
|
67
|
+
function components() external view returns (uint256 numberOfCompnents);
|
89
68
|
|
90
69
|
function getComponentOwnerService()
|
91
70
|
external
|
92
71
|
view
|
93
|
-
returns(IComponentOwnerService);
|
94
|
-
}
|
72
|
+
returns (IComponentOwnerService);
|
73
|
+
}
|
@@ -1,15 +1,13 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
7
|
-
|
8
6
|
import {IProductService} from "../product/IProductService.sol";
|
7
|
+
import {NftId} from "../../types/NftId.sol";
|
9
8
|
|
10
9
|
// TODO check if there is value to introuce IContract and let IPolicy derive from IContract
|
11
10
|
interface IPolicy {
|
12
|
-
|
13
11
|
enum PolicyState {
|
14
12
|
Undefined,
|
15
13
|
Applied,
|
@@ -19,13 +17,11 @@ interface IPolicy {
|
|
19
17
|
}
|
20
18
|
|
21
19
|
struct PolicyInfo {
|
22
|
-
|
20
|
+
NftId nftId;
|
23
21
|
PolicyState state; // applied, withdrawn, rejected, active, closed
|
24
|
-
|
25
22
|
uint256 sumInsuredAmount;
|
26
23
|
uint256 premiumAmount;
|
27
24
|
uint256 lifetime; // activatedAt + lifetime >= expiredAt
|
28
|
-
|
29
25
|
uint256 createdAt;
|
30
26
|
uint256 activatedAt; // time of underwriting
|
31
27
|
uint256 expiredAt; // no new claims
|
@@ -33,34 +29,23 @@ interface IPolicy {
|
|
33
29
|
}
|
34
30
|
}
|
35
31
|
|
36
|
-
interface IPolicyModule is
|
37
|
-
IOwnable,
|
38
|
-
IRegistryLinked,
|
39
|
-
IPolicy
|
40
|
-
{
|
41
|
-
|
32
|
+
interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
42
33
|
function createApplication(
|
43
34
|
IRegistry.RegistryInfo memory productInfo,
|
44
35
|
address applicationOwner,
|
45
36
|
uint256 sumInsuredAmount,
|
46
37
|
uint256 premiumAmount,
|
47
38
|
uint256 lifetime,
|
48
|
-
|
49
|
-
)
|
50
|
-
external
|
51
|
-
returns(uint256 nftId);
|
52
|
-
|
53
|
-
function activate(uint256 nftId)
|
54
|
-
external;
|
39
|
+
NftId bundleNftId
|
40
|
+
) external returns (NftId nftId);
|
55
41
|
|
56
|
-
function
|
57
|
-
external
|
58
|
-
view
|
59
|
-
returns(uint256 bundleNft);
|
42
|
+
function activate(NftId nftId) external;
|
60
43
|
|
61
|
-
function
|
62
|
-
|
63
|
-
|
64
|
-
returns(PolicyInfo memory info);
|
44
|
+
function getBundleNftForPolicy(
|
45
|
+
NftId nftId
|
46
|
+
) external view returns (NftId bundleNft);
|
65
47
|
|
48
|
+
function getPolicyInfo(
|
49
|
+
NftId nftId
|
50
|
+
) external view returns (PolicyInfo memory info);
|
66
51
|
}
|