@etherisc/gif-next 0.0.2-81f8acb → 0.0.2-836a512-798

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