@etherisc/gif-next 0.0.2-f9905e1 → 0.0.2-f99f1d2-109

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. package/README.md +33 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +35 -9
  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 +84 -8
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +148 -15
  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 +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
  34. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
  38. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  40. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
  46. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
  62. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  63. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  64. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
  65. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
  66. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
  67. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
  68. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  70. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  71. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  76. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
  85. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  86. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
  87. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  88. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
  89. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  90. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
  91. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  92. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
  93. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  94. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  95. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  96. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  97. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  98. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  101. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +45 -128
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  103. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  104. package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
  105. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  106. package/artifacts/contracts/registry/Registry.sol/Registry.json +95 -128
  107. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  108. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  109. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  110. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  111. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  112. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  113. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  114. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  115. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  116. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  117. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  118. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  119. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  120. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  121. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  122. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  123. package/contracts/components/Component.sol +39 -24
  124. package/contracts/components/IPool.sol +9 -3
  125. package/contracts/components/IProduct.sol +11 -6
  126. package/contracts/components/Pool.sol +37 -14
  127. package/contracts/components/Product.sol +48 -24
  128. package/contracts/experiment/errors/Require.sol +38 -0
  129. package/contracts/experiment/errors/Revert.sol +44 -0
  130. package/contracts/experiment/inheritance/A.sol +8 -11
  131. package/contracts/experiment/inheritance/B.sol +10 -5
  132. package/contracts/experiment/inheritance/C.sol +11 -5
  133. package/contracts/experiment/inheritance/IA.sol +2 -7
  134. package/contracts/experiment/inheritance/IB.sol +3 -2
  135. package/contracts/experiment/inheritance/IC.sol +4 -3
  136. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  137. package/contracts/experiment/statemachine/ISM.sol +25 -0
  138. package/contracts/experiment/statemachine/README.md +112 -0
  139. package/contracts/experiment/statemachine/SM.sol +57 -0
  140. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  141. package/contracts/experiment/types/TypeA.sol +14 -9
  142. package/contracts/experiment/types/TypeB.sol +14 -9
  143. package/contracts/instance/IInstance.sol +9 -4
  144. package/contracts/instance/Instance.sol +24 -15
  145. package/contracts/instance/access/Access.sol +63 -116
  146. package/contracts/instance/access/IAccess.sol +28 -48
  147. package/contracts/instance/component/ComponentModule.sol +162 -147
  148. package/contracts/instance/component/IComponent.sol +41 -61
  149. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  150. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  151. package/contracts/instance/policy/IPolicy.sol +19 -35
  152. package/contracts/instance/policy/PolicyModule.sol +52 -44
  153. package/contracts/instance/pool/IPoolModule.sol +9 -26
  154. package/contracts/instance/pool/PoolModule.sol +43 -45
  155. package/contracts/instance/product/IProductService.sol +10 -19
  156. package/contracts/instance/product/ProductService.sol +86 -55
  157. package/contracts/instance/treasury/ITreasury.sol +91 -0
  158. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  159. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  160. package/contracts/registry/ChainNft.sol +135 -0
  161. package/contracts/registry/IChainNft.sol +21 -0
  162. package/contracts/registry/IRegistry.sol +41 -40
  163. package/contracts/registry/Registry.sol +82 -97
  164. package/contracts/types/Blocknumber.sol +118 -0
  165. package/contracts/types/ChainId.sol +24 -10
  166. package/contracts/types/Fee.sol +32 -0
  167. package/contracts/types/NftId.sol +51 -0
  168. package/contracts/types/ObjectType.sol +107 -0
  169. package/contracts/types/StateId.sol +91 -0
  170. package/contracts/types/Timestamp.sol +102 -0
  171. package/contracts/types/UFixed.sol +206 -0
  172. package/package.json +13 -5
@@ -1,194 +1,207 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {RegistryLinked} from "../../registry/Registry.sol";
5
7
  import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
6
8
  import {IAccessComponentTypeRoles, IAccessCheckRole} from "../access/IAccess.sol";
7
9
  import {IInstance} from "../IInstance.sol";
8
10
 
11
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
12
+ import {ITreasuryModule} from "../treasury/ITreasury.sol";
13
+ import {TreasuryModule} from "../treasury/TreasuryModule.sol";
9
14
  import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
10
15
  import {IProductComponent} from "../../components/IProduct.sol";
16
+ import {IPoolComponent} from "../../components/IPool.sol";
11
17
  import {IPoolModule} from "../pool/IPoolModule.sol";
18
+ import {ObjectType, PRODUCT, ORACLE, POOL} from "../../types/ObjectType.sol";
19
+ import {StateId, ACTIVE, PAUSED} from "../../types/StateId.sol";
20
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
21
+ import {Fee, zeroFee} from "../../types/Fee.sol";
12
22
 
13
-
14
- abstract contract ComponentModule is
23
+ abstract contract ComponentModule is
15
24
  IRegistryLinked,
16
25
  IAccessComponentTypeRoles,
17
26
  IAccessCheckRole,
18
27
  IComponentModule
19
28
  {
29
+ using NftIdLib for NftId;
20
30
 
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;
31
+ mapping(NftId nftId => ComponentInfo info) private _componentInfo;
32
+ mapping(address cAddress => NftId nftId) private _nftIdByAddress;
33
+ NftId[] private _nftIds;
25
34
 
26
- mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
35
+ mapping(ObjectType cType => bytes32 role) private _componentOwnerRole;
27
36
 
37
+ // TODO maybe move this to Instance contract as internal variable?
38
+ LifecycleModule private _lifecycleModule;
39
+ TreasuryModule private _treasuryModule;
40
+ IPoolModule private _poolModule;
28
41
  IComponentOwnerService private _componentOwnerService;
29
42
 
30
43
  modifier onlyComponentOwnerService() {
31
- require(address(_componentOwnerService) == msg.sender, "ERROR:CMP-001:NOT_OWNER_SERVICE");
44
+ require(
45
+ address(_componentOwnerService) == msg.sender,
46
+ "ERROR:CMP-001:NOT_OWNER_SERVICE"
47
+ );
32
48
  _;
33
49
  }
34
50
 
35
51
  constructor(address componentOwnerService) {
52
+ address componentAddress = address(this);
53
+ _lifecycleModule = LifecycleModule(componentAddress);
54
+ _treasuryModule = TreasuryModule(componentAddress);
55
+ _poolModule = IPoolModule(componentAddress);
36
56
  _componentOwnerService = ComponentOwnerService(componentOwnerService);
37
57
  }
38
58
 
39
- function registerComponent(IComponentContract component)
40
- external
41
- override
42
- onlyComponentOwnerService
43
- returns(uint256 nftId)
44
- {
45
- bytes32 typeRole = getRoleForType(component.getType());
59
+ function registerComponent(
60
+ IComponentContract component
61
+ ) external override onlyComponentOwnerService returns (NftId nftId) {
62
+ ObjectType objectType = component.getType();
63
+ bytes32 typeRole = getRoleForType(objectType);
46
64
  require(
47
65
  this.hasRole(typeRole, component.getInitialOwner()),
48
- "ERROR:CMP-004:TYPE_ROLE_MISSING");
49
-
66
+ "ERROR:CMP-004:TYPE_ROLE_MISSING"
67
+ );
68
+
50
69
  nftId = this.getRegistry().register(address(component));
70
+ IERC20Metadata token = component.getToken();
71
+ address wallet = component.getWallet();
51
72
 
73
+ // create component info
52
74
  _componentInfo[nftId] = ComponentInfo(
53
75
  nftId,
54
- CState.Active);
76
+ _lifecycleModule.getInitialState(objectType),
77
+ token
78
+ );
55
79
 
56
- // special case product -> persist product - pool assignment
57
- if(component.getType() == this.getRegistry().PRODUCT()) {
80
+ // component type specific registration actions
81
+ if (component.getType() == PRODUCT()) {
58
82
  IProductComponent product = IProductComponent(address(component));
59
- uint256 poolNftId = product.getPoolNftId();
60
- require(poolNftId > 0, "ERROR:CMP-005:POOL_UNKNOWN");
61
- // add more validation (type, token, ...)
83
+ NftId poolNftId = product.getPoolNftId();
84
+ require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
85
+ // validate pool token and product token are same
86
+
87
+ // register with tresury
88
+ // implement and add validation
89
+ NftId distributorNftId = zeroNftId();
90
+ _treasuryModule.registerProduct(
91
+ nftId,
92
+ distributorNftId,
93
+ poolNftId,
94
+ token,
95
+ wallet,
96
+ product.getPolicyFee(),
97
+ product.getProcessingFee()
98
+ );
99
+ } else if (component.getType() == POOL()) {
100
+ IPoolComponent pool = IPoolComponent(address(component));
62
101
 
63
- _poolNftIdForProduct[nftId] = poolNftId;
102
+ // register with pool
103
+ _poolModule.registerPool(nftId);
64
104
 
65
- // add creation of productInfo
66
- }
67
- else if(component.getType() == this.getRegistry().POOL()) {
68
- IPoolModule poolModule = IPoolModule(address(this));
69
- poolModule.createPoolInfo(
105
+ // register with tresury
106
+ _treasuryModule.registerPool(
70
107
  nftId,
71
- address(component), // set pool as its wallet
72
- address(0) // don't deal with token yet
108
+ wallet,
109
+ pool.getStakingFee(),
110
+ pool.getPerformanceFee()
73
111
  );
74
112
  }
113
+ // TODO add distribution
75
114
 
76
- _idByAddress[address(component)] = nftId;
77
- _ids.push(nftId);
78
-
79
- // add logging
80
- }
115
+ _nftIdByAddress[address(component)] = nftId;
116
+ _nftIds.push(nftId);
81
117
 
82
- function getPoolNftId(uint256 productNftId)
83
- external
84
- view
85
- override
86
- returns(uint256 poolNftId)
87
- {
88
- poolNftId = _poolNftIdForProduct[productNftId];
118
+ // TODO add loggingx
89
119
  }
90
120
 
91
-
92
121
  function getComponentOwnerService()
93
122
  external
94
- override
95
123
  view
96
- returns(IComponentOwnerService)
124
+ override
125
+ returns (IComponentOwnerService)
97
126
  {
98
127
  return _componentOwnerService;
99
128
  }
100
129
 
101
- function setComponentInfo(ComponentInfo memory info)
102
- external
103
- onlyComponentOwnerService
104
- returns(uint256 nftId)
105
- {
106
- uint256 id = info.nftId;
130
+ function setComponentInfo(
131
+ ComponentInfo memory info
132
+ ) external onlyComponentOwnerService returns (NftId nftId) {
133
+ nftId = info.nftId;
107
134
  require(
108
- id > 0 && _componentInfo[id].nftId == id,
109
- "ERROR:CMP-005:COMPONENT_UNKNOWN");
110
-
111
- _componentInfo[id] = info;
135
+ nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
136
+ "ERROR:CMP-006:COMPONENT_UNKNOWN"
137
+ );
112
138
 
113
- // add logging
139
+ // TODO decide if state changes should have explicit functions and not
140
+ // just a generic setXYZInfo and implicit state transitions
141
+ // when in doubt go for the explicit approach ...
142
+ ObjectType objectType = this.getRegistry().getInfo(nftId).objectType;
143
+ _lifecycleModule.checkAndLogTransition(
144
+ nftId,
145
+ objectType,
146
+ _componentInfo[nftId].state,
147
+ info.state
148
+ );
149
+ _componentInfo[nftId] = info;
114
150
  }
115
151
 
116
- function getComponentInfo(uint256 id)
117
- external
118
- override
119
- view
120
- returns(ComponentInfo memory)
121
- {
122
- return _componentInfo[id];
152
+ function getComponentInfo(
153
+ NftId nftId
154
+ ) external view override returns (ComponentInfo memory) {
155
+ return _componentInfo[nftId];
123
156
  }
124
157
 
125
- function getComponentOwner(uint256 id)
126
- external
127
- view
128
- returns(address owner)
129
- {
130
-
158
+ function getComponentId(
159
+ address componentAddress
160
+ ) external view returns (NftId componentNftId) {
161
+ return _nftIdByAddress[componentAddress];
131
162
  }
132
163
 
133
- function getComponentId(address componentAddress)
134
- external
135
- view
136
- returns(uint256 id)
137
- {
138
- return _idByAddress[componentAddress];
139
- }
140
-
141
-
142
- function getComponentId(uint256 idx)
143
- external
144
- override
145
- view
146
- returns(uint256 id)
147
- {
148
- return _ids[idx];
164
+ function getComponentId(
165
+ uint256 idx
166
+ ) external view override returns (NftId componentNftId) {
167
+ return _nftIds[idx];
149
168
  }
150
169
 
151
-
152
170
  function components()
153
171
  external
154
- override
155
172
  view
156
- returns(uint256 numberOfCompnents)
173
+ override
174
+ returns (uint256 numberOfCompnents)
157
175
  {
158
- return _ids.length;
176
+ return _nftIds.length;
159
177
  }
160
178
 
161
- function getRoleForType(uint256 cType)
162
- public
163
- view
164
- returns(bytes32 role)
165
- {
166
- if(cType == this.getRegistry().PRODUCT()) {
179
+ function getRoleForType(
180
+ ObjectType cType
181
+ ) public view returns (bytes32 role) {
182
+ if (cType == PRODUCT()) {
167
183
  return this.PRODUCT_OWNER_ROLE();
168
184
  }
169
- if(cType == this.getRegistry().POOL()) {
185
+ if (cType == POOL()) {
170
186
  return this.POOL_OWNER_ROLE();
171
187
  }
172
- if(cType == this.getRegistry().ORACLE()) {
188
+ if (cType == ORACLE()) {
173
189
  return this.ORACLE_OWNER_ROLE();
174
190
  }
175
-
176
191
  }
177
192
  }
178
193
 
179
-
180
194
  // this is actually the component owner service
181
195
  contract ComponentOwnerService is
182
196
  RegistryLinked,
183
197
  IComponent,
184
198
  IComponentOwnerService
185
199
  {
200
+ using NftIdLib for NftId;
186
201
 
187
202
  modifier onlyComponentOwner(IComponentContract component) {
188
- uint256 nftId = _registry.getNftId(address(component));
189
- require(
190
- nftId > 0,
191
- "ERROR:COS-001:COMPONENT_UNKNOWN");
203
+ NftId nftId = _registry.getNftId(address(component));
204
+ require(nftId.gtz(), "ERROR:COS-001:COMPONENT_UNKNOWN");
192
205
  require(
193
206
  msg.sender == _registry.getOwner(nftId),
194
207
  "ERROR:COS-002:NOT_OWNER"
@@ -196,64 +209,66 @@ contract ComponentOwnerService is
196
209
  _;
197
210
  }
198
211
 
199
- constructor(address registry)
200
- RegistryLinked(registry)
201
- { }
202
-
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
- // }
212
+ constructor(
213
+ address registry
214
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
215
+ {
214
216
 
217
+ }
215
218
 
216
- function register(IComponentContract component)
217
- external
218
- override
219
- returns(uint256 nftId)
220
- {
219
+ function register(
220
+ IComponentContract component
221
+ ) external override returns (NftId nftId) {
221
222
  require(
222
- msg.sender == component.getInitialOwner(),
223
- "ERROR:COS-003:NOT_OWNER");
223
+ msg.sender == component.getInitialOwner(),
224
+ "ERROR:COS-003:NOT_OWNER"
225
+ );
224
226
 
225
227
  IInstance instance = component.getInstance();
226
228
  nftId = instance.registerComponent(component);
227
229
  }
228
230
 
229
-
230
- function lock(IComponentContract component)
231
- external
232
- override
233
- onlyComponentOwner(component)
234
- {
231
+ function lock(
232
+ IComponentContract component
233
+ ) external override onlyComponentOwner(component) {
235
234
  IInstance instance = component.getInstance();
236
- ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
237
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
238
- // TODO add state change validation
235
+ ComponentInfo memory info = instance.getComponentInfo(
236
+ component.getNftId()
237
+ );
238
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
239
239
 
240
- info.state = CState.Locked;
240
+ info.state = PAUSED();
241
+ // setComponentInfo checks for valid state changes
241
242
  instance.setComponentInfo(info);
242
243
  }
243
244
 
244
-
245
- function unlock(IComponentContract component)
246
- external
247
- override
248
- onlyComponentOwner(component)
249
- {
245
+ function unlock(
246
+ IComponentContract component
247
+ ) external override onlyComponentOwner(component) {
250
248
  IInstance instance = component.getInstance();
251
- ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
252
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
253
- // TODO state change validation
249
+ ComponentInfo memory info = instance.getComponentInfo(
250
+ component.getNftId()
251
+ );
252
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
254
253
 
255
- info.state = CState.Active;
254
+ info.state = ACTIVE();
255
+ // setComponentInfo checks for valid state changes
256
256
  instance.setComponentInfo(info);
257
257
  }
258
258
 
259
- }
259
+ function setProductFees(
260
+ IComponentContract product,
261
+ Fee memory policyFee,
262
+ Fee memory processingFee
263
+ ) external override onlyComponentOwner(product) {
264
+ require(product.getType() == PRODUCT(), "ERROR_NOT_PRODUCT");
265
+
266
+ address instanceAddress = address(product.getInstance());
267
+ ITreasuryModule treasuryModule = ITreasuryModule(instanceAddress);
268
+ treasuryModule.setProductFees(
269
+ product.getNftId(),
270
+ policyFee,
271
+ processingFee
272
+ );
273
+ }
274
+ }
@@ -1,94 +1,74 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
4
5
 
5
6
  import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
7
  import {IInstance} from "../IInstance.sol";
8
+ import {StateId} from "../../types/StateId.sol";
9
+ import {NftId} from "../../types/NftId.sol";
10
+ import {Fee} from "../../types/Fee.sol";
11
+ import {UFixed} from "../../types/UFixed.sol";
7
12
 
8
13
  interface IComponent {
9
-
10
- // TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
11
- enum CState {
12
- Undefined,
13
- Active,
14
- Locked
15
- }
16
-
17
14
  // component dynamic info (static info kept in registry)
18
15
  struct ComponentInfo {
19
- uint256 nftId;
20
- CState state;
16
+ NftId nftId;
17
+ StateId state;
18
+ IERC20Metadata token;
21
19
  }
22
20
  }
23
21
 
24
-
25
22
  interface IInstanceLinked {
26
23
  // function setInstance(address instance) external;
27
- function getInstance() external view returns(IInstance instance);
24
+ function getInstance() external view returns (IInstance instance);
28
25
  }
29
26
 
27
+ interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {
28
+ function getToken() external view returns (IERC20Metadata token);
30
29
 
31
- interface IComponentContract is
32
- IRegisterable,
33
- IInstanceLinked,
34
- IComponent
35
- { }
36
-
30
+ function getWallet() external view returns (address walletAddress);
31
+ }
37
32
 
38
- interface IComponentOwnerService is IRegistryLinked{
33
+ interface IComponentOwnerService is IRegistryLinked {
34
+ function register(
35
+ IComponentContract component
36
+ ) external returns (NftId nftId);
39
37
 
40
- function register(IComponentContract component) external returns(uint256 id);
41
38
  function lock(IComponentContract component) external;
39
+
42
40
  function unlock(IComponentContract component) external;
41
+
42
+ function setProductFees(
43
+ IComponentContract product,
44
+ Fee memory policyFee,
45
+ Fee memory processingFee
46
+ ) external;
43
47
  }
44
48
 
49
+ interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
50
+ function registerComponent(
51
+ IComponentContract component
52
+ ) external returns (NftId nftId);
45
53
 
46
- interface IComponentModule is
47
- IOwnable,
48
- IRegistryLinked,
49
- IComponent
50
- {
54
+ function setComponentInfo(
55
+ ComponentInfo memory info
56
+ ) external returns (NftId componentNftId);
51
57
 
52
- function registerComponent(IComponentContract component)
53
- external
54
- returns(uint256 nftInfo);
58
+ function getComponentInfo(
59
+ NftId nftId
60
+ ) external view returns (ComponentInfo memory info);
55
61
 
56
- function setComponentInfo(ComponentInfo memory info)
57
- external
58
- returns(uint256 componentId);
62
+ function getComponentId(
63
+ address componentAddress
64
+ ) external view returns (NftId nftId);
59
65
 
60
- function getComponentInfo(uint256 id)
61
- external
62
- view
63
- returns(ComponentInfo memory info);
66
+ function getComponentId(uint256 idx) external view returns (NftId nftId);
64
67
 
65
- function getComponentOwner(uint256 id)
66
- external
67
- view
68
- returns(address owner);
69
-
70
- function getComponentId(address componentAddress)
71
- external
72
- view
73
- returns(uint256 id);
74
-
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);
68
+ function components() external view returns (uint256 numberOfCompnents);
89
69
 
90
70
  function getComponentOwnerService()
91
71
  external
92
72
  view
93
- returns(IComponentOwnerService);
94
- }
73
+ returns (IComponentOwnerService);
74
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ObjectType} from "../../types/ObjectType.sol";
5
+ import {StateId, toStateId, zeroStateId} from "../../types/StateId.sol";
6
+ import {NftId} from "../../types/NftId.sol";
7
+
8
+ interface ILifecycle {
9
+ event LogComponentStateChanged(
10
+ NftId nftId,
11
+ ObjectType objectType,
12
+ StateId fromStateId,
13
+ StateId toStateId
14
+ );
15
+ event LogBundleStateChanged(
16
+ NftId nftId,
17
+ StateId fromStateId,
18
+ StateId toStateId
19
+ );
20
+ event LogPolicyStateChanged(
21
+ NftId nftId,
22
+ StateId fromStateId,
23
+ StateId toStateId
24
+ );
25
+ // event LogClaimStateChanged(NftId nftId, ClaimId claimId, StateId fromStateId, StateId toStateId);
26
+ // event LogPayoutStateChanged(NftId nftId, ClaimId claimId, PayoutId payoutId, StateId fromStateId, StateId toStateId);
27
+
28
+ error ErrorNoLifecycle(NftId nftId, ObjectType objectType);
29
+ error ErrorInvalidStateTransition(
30
+ NftId nftId,
31
+ ObjectType objectType,
32
+ StateId fromStateId,
33
+ StateId toStateId
34
+ );
35
+ }
36
+
37
+ interface ILifecycleModule is ILifecycle {
38
+ function getInitialState(
39
+ ObjectType objectType
40
+ ) external view returns (StateId);
41
+
42
+ function isValidTransition(
43
+ ObjectType objectType,
44
+ StateId fromId,
45
+ StateId toId
46
+ ) external view returns (bool);
47
+ }