@etherisc/gif-next 0.0.2-e5ea33d → 0.0.2-e6ad61d-739

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 (153) hide show
  1. package/README.md +10 -1
  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 +37 -11
  122. package/contracts/components/Component.sol +24 -7
  123. package/contracts/components/IPool.sol +6 -0
  124. package/contracts/components/IProduct.sol +9 -2
  125. package/contracts/components/Pool.sol +34 -4
  126. package/contracts/components/Product.sol +38 -4
  127. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  128. package/contracts/experiment/statemachine/ISM.sol +25 -0
  129. package/contracts/experiment/statemachine/README.md +112 -0
  130. package/contracts/experiment/statemachine/SM.sol +57 -0
  131. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  132. package/contracts/instance/IInstance.sol +9 -2
  133. package/contracts/instance/Instance.sol +13 -5
  134. package/contracts/instance/component/ComponentModule.sol +99 -38
  135. package/contracts/instance/component/IComponent.sol +18 -17
  136. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  137. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  138. package/contracts/instance/policy/IPolicy.sol +8 -9
  139. package/contracts/instance/policy/PolicyModule.sol +32 -9
  140. package/contracts/instance/pool/IPoolModule.sol +2 -8
  141. package/contracts/instance/pool/PoolModule.sol +24 -16
  142. package/contracts/instance/product/IProductService.sol +1 -1
  143. package/contracts/instance/product/ProductService.sol +54 -30
  144. package/contracts/instance/treasury/ITreasury.sol +91 -0
  145. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  146. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  147. package/contracts/registry/IRegistry.sol +4 -17
  148. package/contracts/registry/Registry.sol +4 -31
  149. package/contracts/types/Fee.sol +32 -0
  150. package/contracts/types/ObjectType.sol +107 -0
  151. package/contracts/types/StateId.sol +91 -0
  152. package/contracts/types/UFixed.sol +19 -14
  153. package/package.json +7 -4
@@ -5,21 +5,26 @@ import {Registerable} from "../registry/Registry.sol";
5
5
  import {IRegistry} from "../registry/IRegistry.sol";
6
6
 
7
7
  import {IAccessModule, AccessModule} from "./access/Access.sol";
8
+ import {LifecycleModule} from "./lifecycle/LifecycleModule.sol";
8
9
  import {ComponentModule} from "./component/ComponentModule.sol";
9
10
  import {ProductModule} from "./product/ProductService.sol";
10
11
  import {PolicyModule} from "./policy/PolicyModule.sol";
11
12
  import {PoolModule} from "./pool/PoolModule.sol";
13
+ import {TreasuryModule} from "./treasury/TreasuryModule.sol";
12
14
 
13
15
  import {IInstance} from "./IInstance.sol";
16
+ import {ObjectType, INSTANCE} from "../types/ObjectType.sol";
14
17
  import {NftId, toNftId} from "../types/NftId.sol";
15
18
 
16
19
  contract Instance is
17
20
  Registerable,
18
21
  AccessModule,
22
+ LifecycleModule,
19
23
  ComponentModule,
20
24
  PolicyModule,
21
25
  PoolModule,
22
26
  ProductModule,
27
+ TreasuryModule,
23
28
  IInstance
24
29
  {
25
30
  constructor(
@@ -33,7 +38,10 @@ contract Instance is
33
38
  PolicyModule(productService)
34
39
  ProductModule(productService)
35
40
  PoolModule(productService)
36
- {}
41
+ // solhint-disable-next-line no-empty-blocks
42
+ {
43
+
44
+ }
37
45
 
38
46
  // from registerable
39
47
  function register() external override returns (NftId nftId) {
@@ -45,7 +53,7 @@ contract Instance is
45
53
  }
46
54
 
47
55
  // from registerable
48
- function getParentNftId() public view override returns (NftId) {
56
+ function getParentNftId() public pure override returns (NftId) {
49
57
  // TODO add self registry and exchange 0 for_registry.getNftId();
50
58
  // define parent tree for all registerables
51
59
  // eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
@@ -53,12 +61,12 @@ contract Instance is
53
61
  }
54
62
 
55
63
  // from registerable
56
- function getType() external view override returns (uint256 objectType) {
57
- return _registry.INSTANCE();
64
+ function getType() external pure override returns (ObjectType objectType) {
65
+ return INSTANCE();
58
66
  }
59
67
 
60
68
  // from registerable
61
- function getData() external view override returns (bytes memory data) {
69
+ function getData() external pure override returns (bytes memory data) {
62
70
  return bytes(abi.encode(0));
63
71
  }
64
72
  }
@@ -1,15 +1,24 @@
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
23
  abstract contract ComponentModule is
15
24
  IRegistryLinked,
@@ -20,12 +29,15 @@ 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() {
@@ -37,51 +49,73 @@ abstract contract ComponentModule is
37
49
  }
38
50
 
39
51
  constructor(address componentOwnerService) {
52
+ address componentAddress = address(this);
53
+ _lifecycleModule = LifecycleModule(componentAddress);
54
+ _treasuryModule = TreasuryModule(componentAddress);
55
+ _poolModule = IPoolModule(componentAddress);
40
56
  _componentOwnerService = ComponentOwnerService(componentOwnerService);
41
57
  }
42
58
 
43
59
  function registerComponent(
44
60
  IComponentContract component
45
61
  ) external override onlyComponentOwnerService returns (NftId nftId) {
46
- bytes32 typeRole = getRoleForType(component.getType());
62
+ ObjectType objectType = component.getType();
63
+ bytes32 typeRole = getRoleForType(objectType);
47
64
  require(
48
65
  this.hasRole(typeRole, component.getInitialOwner()),
49
66
  "ERROR:CMP-004:TYPE_ROLE_MISSING"
50
67
  );
51
68
 
52
69
  nftId = this.getRegistry().register(address(component));
70
+ IERC20Metadata token = component.getToken();
71
+ address wallet = component.getWallet();
72
+
73
+ // create component info
74
+ _componentInfo[nftId] = ComponentInfo(
75
+ nftId,
76
+ _lifecycleModule.getInitialState(objectType),
77
+ token
78
+ );
53
79
 
54
- _componentInfo[nftId] = ComponentInfo(nftId, CState.Active);
55
-
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
83
  NftId poolNftId = product.getPoolNftId();
60
84
  require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
61
- // add more validation (type, token, ...)
85
+ // validate pool token and product token are same
62
86
 
63
- _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));
64
101
 
65
- // add creation of productInfo
66
- } else if (component.getType() == this.getRegistry().POOL()) {
67
- IPoolModule poolModule = IPoolModule(address(this));
68
- poolModule.createPoolInfo(
102
+ // register with pool
103
+ _poolModule.registerPool(nftId);
104
+
105
+ // register with tresury
106
+ _treasuryModule.registerPool(
69
107
  nftId,
70
- address(component), // set pool as its wallet
71
- address(0) // don't deal with token yet
108
+ wallet,
109
+ pool.getStakingFee(),
110
+ pool.getPerformanceFee()
72
111
  );
73
112
  }
113
+ // TODO add distribution
74
114
 
75
115
  _nftIdByAddress[address(component)] = nftId;
76
116
  _nftIds.push(nftId);
77
117
 
78
- // add logging
79
- }
80
-
81
- function getPoolNftId(
82
- NftId productNftId
83
- ) external view override returns (NftId poolNftId) {
84
- poolNftId = _poolNftIdForProduct[productNftId];
118
+ // TODO add loggingx
85
119
  }
86
120
 
87
121
  function getComponentOwnerService()
@@ -102,9 +136,17 @@ abstract contract ComponentModule is
102
136
  "ERROR:CMP-006:COMPONENT_UNKNOWN"
103
137
  );
104
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
+ );
105
149
  _componentInfo[nftId] = info;
106
-
107
- // add logging
108
150
  }
109
151
 
110
152
  function getComponentInfo(
@@ -113,10 +155,6 @@ abstract contract ComponentModule is
113
155
  return _componentInfo[nftId];
114
156
  }
115
157
 
116
- function getComponentOwner(
117
- NftId nftId
118
- ) external view returns (address owner) {}
119
-
120
158
  function getComponentId(
121
159
  address componentAddress
122
160
  ) external view returns (NftId componentNftId) {
@@ -138,14 +176,16 @@ abstract contract ComponentModule is
138
176
  return _nftIds.length;
139
177
  }
140
178
 
141
- function getRoleForType(uint256 cType) public view returns (bytes32 role) {
142
- if (cType == this.getRegistry().PRODUCT()) {
179
+ function getRoleForType(
180
+ ObjectType cType
181
+ ) public view returns (bytes32 role) {
182
+ if (cType == PRODUCT()) {
143
183
  return this.PRODUCT_OWNER_ROLE();
144
184
  }
145
- if (cType == this.getRegistry().POOL()) {
185
+ if (cType == POOL()) {
146
186
  return this.POOL_OWNER_ROLE();
147
187
  }
148
- if (cType == this.getRegistry().ORACLE()) {
188
+ if (cType == ORACLE()) {
149
189
  return this.ORACLE_OWNER_ROLE();
150
190
  }
151
191
  }
@@ -169,7 +209,12 @@ contract ComponentOwnerService is
169
209
  _;
170
210
  }
171
211
 
172
- constructor(address registry) RegistryLinked(registry) {}
212
+ constructor(
213
+ address registry
214
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
215
+ {
216
+
217
+ }
173
218
 
174
219
  function register(
175
220
  IComponentContract component
@@ -191,9 +236,9 @@ contract ComponentOwnerService is
191
236
  component.getNftId()
192
237
  );
193
238
  require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
194
- // TODO add state change validation
195
239
 
196
- info.state = CState.Locked;
240
+ info.state = PAUSED();
241
+ // setComponentInfo checks for valid state changes
197
242
  instance.setComponentInfo(info);
198
243
  }
199
244
 
@@ -205,9 +250,25 @@ contract ComponentOwnerService is
205
250
  component.getNftId()
206
251
  );
207
252
  require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
208
- // TODO state change validation
209
253
 
210
- info.state = CState.Active;
254
+ info.state = ACTIVE();
255
+ // setComponentInfo checks for valid state changes
211
256
  instance.setComponentInfo(info);
212
257
  }
258
+
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
+ }
213
274
  }
@@ -1,22 +1,21 @@
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 {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
5
7
  import {IInstance} from "../IInstance.sol";
8
+ import {StateId} from "../../types/StateId.sol";
6
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
- // TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
10
- enum CState {
11
- Undefined,
12
- Active,
13
- Locked
14
- }
15
-
16
14
  // component dynamic info (static info kept in registry)
17
15
  struct ComponentInfo {
18
16
  NftId nftId;
19
- CState state;
17
+ StateId state;
18
+ IERC20Metadata token;
20
19
  }
21
20
  }
22
21
 
@@ -25,7 +24,11 @@ interface IInstanceLinked {
25
24
  function getInstance() external view returns (IInstance instance);
26
25
  }
27
26
 
28
- interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {}
27
+ interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {
28
+ function getToken() external view returns (IERC20Metadata token);
29
+
30
+ function getWallet() external view returns (address walletAddress);
31
+ }
29
32
 
30
33
  interface IComponentOwnerService is IRegistryLinked {
31
34
  function register(
@@ -35,6 +38,12 @@ interface IComponentOwnerService is IRegistryLinked {
35
38
  function lock(IComponentContract component) external;
36
39
 
37
40
  function unlock(IComponentContract component) external;
41
+
42
+ function setProductFees(
43
+ IComponentContract product,
44
+ Fee memory policyFee,
45
+ Fee memory processingFee
46
+ ) external;
38
47
  }
39
48
 
40
49
  interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
@@ -50,20 +59,12 @@ interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
50
59
  NftId nftId
51
60
  ) external view returns (ComponentInfo memory info);
52
61
 
53
- function getComponentOwner(
54
- NftId nftId
55
- ) external view returns (address owner);
56
-
57
62
  function getComponentId(
58
63
  address componentAddress
59
64
  ) external view returns (NftId nftId);
60
65
 
61
66
  function getComponentId(uint256 idx) external view returns (NftId nftId);
62
67
 
63
- function getPoolNftId(
64
- NftId productNftId
65
- ) external view returns (NftId poolNftId);
66
-
67
68
  function components() external view returns (uint256 numberOfCompnents);
68
69
 
69
70
  function getComponentOwnerService()
@@ -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
+ }
@@ -5,24 +5,20 @@ import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registr
5
5
  import {IInstance} from "../IInstance.sol";
6
6
  import {IProductService} from "../product/IProductService.sol";
7
7
  import {NftId} from "../../types/NftId.sol";
8
+ import {StateId} from "../../types/StateId.sol";
8
9
 
9
10
  // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
10
11
  interface IPolicy {
11
- enum PolicyState {
12
- Undefined,
13
- Applied,
14
- Rejected,
15
- Active,
16
- Closed
17
- }
18
-
19
12
  struct PolicyInfo {
20
13
  NftId nftId;
21
- PolicyState state; // applied, withdrawn, rejected, active, closed
14
+ StateId state; // applied, withdrawn, rejected, active, closed
15
+ // TODO add beneficiary address
22
16
  uint256 sumInsuredAmount;
23
17
  uint256 premiumAmount;
18
+ uint256 premiumPaidAmount;
24
19
  uint256 lifetime; // activatedAt + lifetime >= expiredAt
25
20
  uint256 createdAt;
21
+ uint256 updatedAt;
26
22
  uint256 activatedAt; // time of underwriting
27
23
  uint256 expiredAt; // no new claims
28
24
  uint256 closedAt; // no locked capital
@@ -39,6 +35,9 @@ interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
39
35
  NftId bundleNftId
40
36
  ) external returns (NftId nftId);
41
37
 
38
+ // process full premium
39
+ function processPremium(NftId nftId) external;
40
+
42
41
  function activate(NftId nftId) external;
43
42
 
44
43
  function getBundleNftForPolicy(
@@ -4,16 +4,22 @@ pragma solidity ^0.8.19;
4
4
  // import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
5
5
  import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
6
6
 
7
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
7
8
  import {IProductService} from "../product/IProductService.sol";
8
9
  import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
+ import {ObjectType, POLICY} from "../../types/ObjectType.sol";
11
+ import {ACTIVE} from "../../types/StateId.sol";
9
12
  import {NftId, NftIdLib} from "../../types/NftId.sol";
10
13
 
14
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
15
+
11
16
  abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
12
17
  using NftIdLib for NftId;
13
18
 
14
19
  mapping(NftId nftId => PolicyInfo info) private _policyInfo;
15
20
  mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
16
21
 
22
+ LifecycleModule private _lifecycleModule;
17
23
  IProductService private _productService;
18
24
 
19
25
  // TODO find a better place to avoid dupliation
@@ -26,6 +32,7 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
26
32
  }
27
33
 
28
34
  constructor(address productService) {
35
+ _lifecycleModule = LifecycleModule(address(this));
29
36
  _productService = IProductService(productService);
30
37
  }
31
38
 
@@ -39,25 +46,29 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
39
46
  ) external override onlyProductService2 returns (NftId nftId) {
40
47
  // TODO add parameter validation
41
48
  if (bundleNftId.gtz()) {
42
- IRegistry.RegistryInfo memory bundleInfo = this
43
- .getRegistry()
44
- .getInfo(bundleNftId);
49
+ // IRegistry.RegistryInfo memory bundleInfo = this
50
+ // .getRegistry()
51
+ // .getInfo(bundleNftId);
45
52
  // IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
46
53
  }
47
54
 
48
55
  nftId = this.getRegistry().registerObjectForInstance(
49
56
  productInfo.nftId,
50
- this.getRegistry().POLICY(),
57
+ POLICY(),
51
58
  applicationOwner
52
59
  );
53
60
 
54
61
  _policyInfo[nftId] = PolicyInfo(
55
62
  nftId,
56
- PolicyState.Applied,
63
+ _lifecycleModule.getInitialState(POLICY()),
57
64
  sumInsuredAmount,
58
65
  premiumAmount,
66
+ 0, // premium paid amount
59
67
  lifetime,
60
- block.timestamp,
68
+ // solhint-disable-next-line not-rely-on-time
69
+ block.timestamp, // createdAt
70
+ // solhint-disable-next-line not-rely-on-time
71
+ block.timestamp, // updatedAt
61
72
  0, // activatedAt
62
73
  0, // expiredAt
63
74
  0 // closedAt
@@ -68,13 +79,25 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
68
79
  // add logging
69
80
  }
70
81
 
82
+ function processPremium(NftId nftId) external override onlyProductService2 {
83
+ PolicyInfo storage info = _policyInfo[nftId];
84
+ info.premiumPaidAmount = info.premiumAmount;
85
+ // solhint-disable-next-line not-rely-on-time
86
+ info.updatedAt = block.timestamp;
87
+ }
88
+
71
89
  function activate(NftId nftId) external override onlyProductService2 {
72
90
  PolicyInfo storage info = _policyInfo[nftId];
91
+ // solhint-disable-next-line not-rely-on-time
73
92
  info.activatedAt = block.timestamp;
93
+ // solhint-disable-next-line not-rely-on-time
74
94
  info.expiredAt = block.timestamp + info.lifetime;
75
- info.state = PolicyState.Active;
76
-
77
- // add logging
95
+ info.state = _lifecycleModule.checkAndLogTransition(
96
+ nftId,
97
+ POLICY(),
98
+ info.state,
99
+ ACTIVE()
100
+ );
78
101
  }
79
102
 
80
103
  function getBundleNftForPolicy(
@@ -7,21 +7,15 @@ import {NftId} from "../../types/NftId.sol";
7
7
  interface IPool {
8
8
  struct PoolInfo {
9
9
  NftId nftId;
10
- address wallet;
11
- address token;
12
10
  uint256 capital;
13
11
  uint256 lockedCapital;
14
12
  }
15
13
  }
16
14
 
17
15
  interface IPoolModule is IOwnable, IRegistryLinked, IPool {
18
- function underwrite(NftId poolNftId, NftId policyNftId) external;
16
+ function underwrite(NftId policyNftId, NftId productNftId) external;
19
17
 
20
- function createPoolInfo(
21
- NftId nftId,
22
- address wallet,
23
- address token
24
- ) external;
18
+ function registerPool(NftId nftId) external;
25
19
 
26
20
  function getPoolInfo(
27
21
  NftId nftId