@etherisc/gif-next 0.0.2-c40f9a5 → 0.0.2-c6846dc-026

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