@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.
Files changed (137) hide show
  1. package/README.md +25 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +7 -7
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +6 -6
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +8 -8
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +29 -11
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +31 -13
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  28. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  30. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  32. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +60 -60
  40. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  41. package/artifacts/contracts/instance/Instance.sol/Instance.json +122 -64
  42. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  43. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +24 -24
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  50. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +48 -6
  51. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +6 -6
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +26 -26
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +3 -3
  58. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  59. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  60. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +18 -18
  62. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +18 -18
  64. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  65. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  66. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +10 -10
  67. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  68. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +10 -10
  69. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  70. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +8 -8
  72. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  74. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +54 -12
  75. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  76. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  77. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  78. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  79. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  80. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  81. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +6 -6
  82. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  83. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -33
  84. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  85. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  86. package/artifacts/contracts/registry/Registry.sol/Registerable.json +7 -7
  87. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  88. package/artifacts/contracts/registry/Registry.sol/Registry.json +100 -42
  89. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  90. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  91. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  92. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  93. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  94. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  95. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  96. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  97. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  98. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  99. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  100. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  101. package/contracts/components/Component.sol +17 -19
  102. package/contracts/components/IPool.sol +3 -3
  103. package/contracts/components/IProduct.sol +4 -6
  104. package/contracts/components/Pool.sol +6 -13
  105. package/contracts/components/Product.sol +12 -22
  106. package/contracts/experiment/errors/Require.sol +38 -0
  107. package/contracts/experiment/errors/Revert.sol +44 -0
  108. package/contracts/experiment/inheritance/A.sol +53 -0
  109. package/contracts/experiment/inheritance/B.sol +28 -0
  110. package/contracts/experiment/inheritance/C.sol +34 -0
  111. package/contracts/experiment/inheritance/IA.sol +13 -0
  112. package/contracts/experiment/inheritance/IB.sol +10 -0
  113. package/contracts/experiment/inheritance/IC.sol +12 -0
  114. package/contracts/experiment/types/TypeA.sol +47 -0
  115. package/contracts/experiment/types/TypeB.sol +29 -0
  116. package/contracts/instance/IInstance.sol +4 -6
  117. package/contracts/instance/Instance.sol +15 -14
  118. package/contracts/instance/access/Access.sol +63 -116
  119. package/contracts/instance/access/IAccess.sol +28 -48
  120. package/contracts/instance/component/ComponentModule.sol +84 -130
  121. package/contracts/instance/component/IComponent.sol +32 -53
  122. package/contracts/instance/policy/IPolicy.sol +12 -27
  123. package/contracts/instance/policy/PolicyModule.sol +25 -40
  124. package/contracts/instance/pool/IPoolModule.sol +10 -21
  125. package/contracts/instance/pool/PoolModule.sol +28 -38
  126. package/contracts/instance/product/IProductService.sol +9 -18
  127. package/contracts/instance/product/ProductService.sol +54 -47
  128. package/contracts/registry/ChainNft.sol +135 -0
  129. package/contracts/registry/IChainNft.sol +21 -0
  130. package/contracts/registry/IRegistry.sol +52 -38
  131. package/contracts/registry/Registry.sol +107 -95
  132. package/contracts/types/Blocknumber.sol +118 -0
  133. package/contracts/types/ChainId.sol +38 -0
  134. package/contracts/types/NftId.sol +51 -0
  135. package/contracts/types/Timestamp.sol +102 -0
  136. package/contracts/types/UFixed.sol +205 -0
  137. 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
- interface IAccessModule is
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 createRole(string memory roleName)
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(bytes32 role)
60
- external
61
- view
62
- returns(RoleInfo memory info);
45
+ function getRoleInfo(
46
+ bytes32 role
47
+ ) external view returns (RoleInfo memory info);
63
48
 
64
- function getRoleForName(string memory roleName)
65
- external
66
- pure
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(bytes32 role)
75
- external
76
- view
77
- returns(uint256 roleMembers);
55
+ function getRoleMemberCount(
56
+ bytes32 role
57
+ ) external view returns (uint256 roleMembers);
78
58
 
79
- function getRoleMember(bytes32 role, uint256 idx)
80
- external
81
- view
82
- returns(address roleMembers);
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(uint256 nftId => ComponentInfo info) private _componentInfo;
22
- mapping(uint256 nftId => uint256 poolNftId) private _poolNftIdForProduct;
23
- mapping(address cAddress => uint256 id) private _idByAddress;
24
- uint256 [] private _ids;
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(address(_componentOwnerService) == msg.sender, "ERROR:CMP-001:NOT_OWNER_SERVICE");
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(IComponentContract component)
40
- external
41
- override
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
- uint256 poolNftId = product.getPoolNftId();
60
- require(poolNftId > 0, "ERROR:CMP-005:POOL_UNKNOWN");
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
- _idByAddress[address(component)] = nftId;
77
- _ids.push(nftId);
75
+ _nftIdByAddress[address(component)] = nftId;
76
+ _nftIds.push(nftId);
78
77
 
79
78
  // add logging
80
79
  }
81
80
 
82
- function getPoolNftId(uint256 productNftId)
83
- external
84
- view
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
- returns(IComponentOwnerService)
90
+ override
91
+ returns (IComponentOwnerService)
97
92
  {
98
93
  return _componentOwnerService;
99
94
  }
100
95
 
101
- function setComponentInfo(ComponentInfo memory info)
102
- external
103
- onlyComponentOwnerService
104
- returns(uint256 nftId)
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
- id > 0 && _componentInfo[id].nftId == id,
109
- "ERROR:CMP-005:COMPONENT_UNKNOWN");
101
+ nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
102
+ "ERROR:CMP-006:COMPONENT_UNKNOWN"
103
+ );
110
104
 
111
- _componentInfo[id] = info;
105
+ _componentInfo[nftId] = info;
112
106
 
113
107
  // add logging
114
108
  }
115
109
 
116
- function getComponentInfo(uint256 id)
117
- external
118
- override
119
- view
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(uint256 id)
126
- external
127
- view
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(address componentAddress)
134
- external
135
- view
136
- returns(uint256 id)
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
- returns(uint256 numberOfCompnents)
135
+ override
136
+ returns (uint256 numberOfCompnents)
157
137
  {
158
- return _ids.length;
138
+ return _nftIds.length;
159
139
  }
160
140
 
161
- function getRoleForType(uint256 cType)
162
- public
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
- uint256 nftId = _registry.getNftId(address(component));
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
- // modifier onlyComponentOwnerRole(IComponentContract component) {
205
- // IInstance instance = component.getInstance();
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
- function lock(IComponentContract component)
231
- external
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(component.getNftId());
237
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
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
- function unlock(IComponentContract component)
246
- external
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(component.getNftId());
252
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
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
- uint256 nftId;
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 IComponentContract is
32
- IRegisterable,
33
- IInstanceLinked,
34
- IComponent
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
- interface IComponentModule is
47
- IOwnable,
48
- IRegistryLinked,
49
- IComponent
50
- {
45
+ function setComponentInfo(
46
+ ComponentInfo memory info
47
+ ) external returns (NftId componentNftId);
51
48
 
52
- function registerComponent(IComponentContract component)
53
- external
54
- returns(uint256 nftInfo);
49
+ function getComponentInfo(
50
+ NftId nftId
51
+ ) external view returns (ComponentInfo memory info);
55
52
 
56
- function setComponentInfo(ComponentInfo memory info)
57
- external
58
- returns(uint256 componentId);
53
+ function getComponentOwner(
54
+ NftId nftId
55
+ ) external view returns (address owner);
59
56
 
60
- function getComponentInfo(uint256 id)
61
- external
62
- view
63
- returns(ComponentInfo memory info);
57
+ function getComponentId(
58
+ address componentAddress
59
+ ) external view returns (NftId nftId);
64
60
 
65
- function getComponentOwner(uint256 id)
66
- external
67
- view
68
- returns(address owner);
61
+ function getComponentId(uint256 idx) external view returns (NftId nftId);
69
62
 
70
- function getComponentId(address componentAddress)
71
- external
72
- view
73
- returns(uint256 id);
63
+ function getPoolNftId(
64
+ NftId productNftId
65
+ ) external view returns (NftId poolNftId);
74
66
 
75
- function getComponentId(uint256 idx)
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
- uint256 nftId;
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
- uint256 bundleNftId
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 getBundleNftForPolicy(uint256 nftId)
57
- external
58
- view
59
- returns(uint256 bundleNft);
42
+ function activate(NftId nftId) external;
60
43
 
61
- function getPolicyInfo(uint256 nftId)
62
- external
63
- view
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
  }