@etherisc/gif-next 0.0.2-ebbe63d → 0.0.2-f619be3-760

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. package/README.md +144 -1
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  3. package/artifacts/contracts/components/Component.sol/Component.json +205 -0
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +4 -0
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +35 -0
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +255 -0
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +74 -0
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +328 -0
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  13. package/artifacts/contracts/components/Product.sol/Product.json +346 -0
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  28. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  30. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  32. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  34. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
  36. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
  38. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
  39. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
  40. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
  41. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
  42. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
  43. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
  44. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  45. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  46. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  47. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  48. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  49. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1479 -0
  50. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  51. package/artifacts/contracts/instance/Instance.sol/Instance.json +1725 -0
  52. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
  53. package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
  54. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
  55. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
  56. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
  57. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
  58. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
  59. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
  60. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  61. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
  62. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  63. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +299 -0
  64. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
  65. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +202 -0
  66. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
  67. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
  68. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
  69. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +205 -0
  70. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +217 -0
  72. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
  73. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +141 -0
  74. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
  75. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
  76. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  77. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
  78. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
  79. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
  80. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
  81. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
  82. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  83. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
  84. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  85. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +254 -0
  86. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  87. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +254 -0
  88. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  89. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
  90. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  91. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +129 -0
  92. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  93. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +155 -0
  94. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
  95. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
  96. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
  97. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +127 -0
  98. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
  99. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
  100. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
  101. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +196 -0
  102. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  103. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
  104. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  105. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
  106. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  107. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
  108. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  109. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
  110. package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
  111. package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
  112. package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
  113. package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
  114. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
  115. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
  116. package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
  117. package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
  118. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  119. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  120. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  121. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  122. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
  123. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
  124. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
  125. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
  126. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  127. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +188 -0
  128. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
  129. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
  130. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
  131. package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
  132. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  133. package/artifacts/contracts/registry/Registry.sol/Registry.json +256 -0
  134. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
  135. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
  136. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  137. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  138. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  139. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  140. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  141. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  142. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  143. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  144. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  145. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  146. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  147. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  148. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  149. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
  150. package/contracts/components/Component.sol +77 -0
  151. package/contracts/components/IPool.sol +15 -0
  152. package/contracts/components/IProduct.sol +16 -0
  153. package/contracts/components/Pool.sol +52 -0
  154. package/contracts/components/Product.sol +89 -0
  155. package/contracts/experiment/errors/Require.sol +38 -0
  156. package/contracts/experiment/errors/Revert.sol +44 -0
  157. package/contracts/experiment/inheritance/A.sol +53 -0
  158. package/contracts/experiment/inheritance/B.sol +28 -0
  159. package/contracts/experiment/inheritance/C.sol +34 -0
  160. package/contracts/experiment/inheritance/IA.sol +13 -0
  161. package/contracts/experiment/inheritance/IB.sol +10 -0
  162. package/contracts/experiment/inheritance/IC.sol +12 -0
  163. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  164. package/contracts/experiment/statemachine/ISM.sol +25 -0
  165. package/contracts/experiment/statemachine/README.md +112 -0
  166. package/contracts/experiment/statemachine/SM.sol +57 -0
  167. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  168. package/contracts/experiment/types/TypeA.sol +47 -0
  169. package/contracts/experiment/types/TypeB.sol +29 -0
  170. package/contracts/instance/IInstance.sol +25 -0
  171. package/contracts/instance/Instance.sol +72 -0
  172. package/contracts/instance/access/Access.sol +165 -0
  173. package/contracts/instance/access/IAccess.sol +63 -0
  174. package/contracts/instance/component/ComponentModule.sol +274 -0
  175. package/contracts/instance/component/IComponent.sol +74 -0
  176. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  177. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  178. package/contracts/instance/policy/IPolicy.sol +50 -0
  179. package/contracts/instance/policy/PolicyModule.sol +114 -0
  180. package/contracts/instance/pool/IPoolModule.sol +23 -0
  181. package/contracts/instance/pool/PoolModule.sol +81 -0
  182. package/contracts/instance/product/IProductService.sol +36 -0
  183. package/contracts/instance/product/ProductService.sol +136 -0
  184. package/contracts/instance/treasury/ITreasury.sol +91 -0
  185. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  186. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  187. package/contracts/mock/TestPool.sol +16 -0
  188. package/contracts/mock/TestProduct.sol +39 -0
  189. package/contracts/mock/Usdc.sol +26 -0
  190. package/contracts/registry/ChainNft.sol +135 -0
  191. package/contracts/registry/IChainNft.sol +21 -0
  192. package/contracts/registry/IRegistry.sol +67 -0
  193. package/contracts/registry/Registry.sol +182 -0
  194. package/contracts/types/Blocknumber.sol +118 -0
  195. package/contracts/types/ChainId.sol +38 -0
  196. package/contracts/types/Fee.sol +32 -0
  197. package/contracts/types/NftId.sol +51 -0
  198. package/contracts/types/ObjectType.sol +107 -0
  199. package/contracts/types/StateId.sol +91 -0
  200. package/contracts/types/Timestamp.sol +102 -0
  201. package/contracts/types/UFixed.sol +210 -0
  202. package/package.json +19 -9
  203. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  204. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  205. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  206. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  207. package/contracts/Lock.sol +0 -34
  208. /package/contracts/{Dip.sol → mock/Dip.sol} +0 -0
@@ -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
+ }
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IInstance} from "../IInstance.sol";
6
+ import {IProductService} from "../product/IProductService.sol";
7
+ import {NftId} from "../../types/NftId.sol";
8
+ import {StateId} from "../../types/StateId.sol";
9
+
10
+ // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
11
+ interface IPolicy {
12
+ struct PolicyInfo {
13
+ NftId nftId;
14
+ StateId state; // applied, withdrawn, rejected, active, closed
15
+ // TODO add beneficiary address
16
+ uint256 sumInsuredAmount;
17
+ uint256 premiumAmount;
18
+ uint256 premiumPaidAmount;
19
+ uint256 lifetime; // activatedAt + lifetime >= expiredAt
20
+ uint256 createdAt;
21
+ uint256 updatedAt;
22
+ uint256 activatedAt; // time of underwriting
23
+ uint256 expiredAt; // no new claims
24
+ uint256 closedAt; // no locked capital
25
+ }
26
+ }
27
+
28
+ interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
29
+ function createApplication(
30
+ IRegistry.RegistryInfo memory productInfo,
31
+ address applicationOwner,
32
+ uint256 sumInsuredAmount,
33
+ uint256 premiumAmount,
34
+ uint256 lifetime,
35
+ NftId bundleNftId
36
+ ) external returns (NftId nftId);
37
+
38
+ // process full premium
39
+ function processPremium(NftId nftId) external;
40
+
41
+ function activate(NftId nftId) external;
42
+
43
+ function getBundleNftForPolicy(
44
+ NftId nftId
45
+ ) external view returns (NftId bundleNft);
46
+
47
+ function getPolicyInfo(
48
+ NftId nftId
49
+ ) external view returns (PolicyInfo memory info);
50
+ }
@@ -0,0 +1,114 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
5
+ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
6
+
7
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
8
+ import {IProductService} from "../product/IProductService.sol";
9
+ import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
+ import {ObjectType, POLICY} from "../../types/ObjectType.sol";
11
+ import {ACTIVE} from "../../types/StateId.sol";
12
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
13
+
14
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
15
+
16
+ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
17
+ using NftIdLib for NftId;
18
+
19
+ mapping(NftId nftId => PolicyInfo info) private _policyInfo;
20
+ mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
21
+
22
+ LifecycleModule private _lifecycleModule;
23
+ IProductService private _productService;
24
+
25
+ // TODO find a better place to avoid dupliation
26
+ modifier onlyProductService2() {
27
+ require(
28
+ address(_productService) == msg.sender,
29
+ "ERROR:POL-001:NOT_PRODUCT_SERVICE"
30
+ );
31
+ _;
32
+ }
33
+
34
+ constructor(address productService) {
35
+ _lifecycleModule = LifecycleModule(address(this));
36
+ _productService = IProductService(productService);
37
+ }
38
+
39
+ function createApplication(
40
+ IRegistry.RegistryInfo memory productInfo,
41
+ address applicationOwner,
42
+ uint256 sumInsuredAmount,
43
+ uint256 premiumAmount,
44
+ uint256 lifetime,
45
+ NftId bundleNftId
46
+ ) external override onlyProductService2 returns (NftId nftId) {
47
+ // TODO add parameter validation
48
+ if (bundleNftId.gtz()) {
49
+ // IRegistry.RegistryInfo memory bundleInfo = this
50
+ // .getRegistry()
51
+ // .getInfo(bundleNftId);
52
+ // IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
53
+ }
54
+
55
+ nftId = this.getRegistry().registerObjectForInstance(
56
+ productInfo.nftId,
57
+ POLICY(),
58
+ applicationOwner
59
+ );
60
+
61
+ _policyInfo[nftId] = PolicyInfo(
62
+ nftId,
63
+ _lifecycleModule.getInitialState(POLICY()),
64
+ sumInsuredAmount,
65
+ premiumAmount,
66
+ 0, // premium paid amount
67
+ lifetime,
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
72
+ 0, // activatedAt
73
+ 0, // expiredAt
74
+ 0 // closedAt
75
+ );
76
+
77
+ _bundleForPolicy[nftId] = bundleNftId;
78
+
79
+ // add logging
80
+ }
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
+
89
+ function activate(NftId nftId) external override onlyProductService2 {
90
+ PolicyInfo storage info = _policyInfo[nftId];
91
+ // solhint-disable-next-line not-rely-on-time
92
+ info.activatedAt = block.timestamp;
93
+ // solhint-disable-next-line not-rely-on-time
94
+ info.expiredAt = block.timestamp + info.lifetime;
95
+ info.state = _lifecycleModule.checkAndLogTransition(
96
+ nftId,
97
+ POLICY(),
98
+ info.state,
99
+ ACTIVE()
100
+ );
101
+ }
102
+
103
+ function getBundleNftForPolicy(
104
+ NftId nftId
105
+ ) external view returns (NftId bundleNft) {
106
+ return _bundleForPolicy[nftId];
107
+ }
108
+
109
+ function getPolicyInfo(
110
+ NftId nftId
111
+ ) external view returns (PolicyInfo memory info) {
112
+ return _policyInfo[nftId];
113
+ }
114
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+ import {NftId} from "../../types/NftId.sol";
6
+
7
+ interface IPool {
8
+ struct PoolInfo {
9
+ NftId nftId;
10
+ uint256 capital;
11
+ uint256 lockedCapital;
12
+ }
13
+ }
14
+
15
+ interface IPoolModule is IOwnable, IRegistryLinked, IPool {
16
+ function underwrite(NftId policyNftId, NftId productNftId) external;
17
+
18
+ function registerPool(NftId nftId) external;
19
+
20
+ function getPoolInfo(
21
+ NftId nftId
22
+ ) external view returns (PoolInfo memory info);
23
+ }
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+ import {IProductService} from "../product/IProductService.sol";
6
+ import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
7
+ import {ITreasuryModule} from "../treasury/ITreasury.sol";
8
+ import {IPoolModule} from "./IPoolModule.sol";
9
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
10
+
11
+ abstract contract PoolModule is IPoolModule {
12
+ using NftIdLib for NftId;
13
+
14
+ uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
15
+ uint256 public constant INITIAL_LOCKED_CAPITAL = 0;
16
+
17
+ mapping(NftId nftId => PoolInfo info) private _poolInfo;
18
+
19
+ IPolicyModule private _policyModule;
20
+ ITreasuryModule private _treasuryModule;
21
+ IProductService private _productService;
22
+
23
+ modifier onlyProductService() {
24
+ require(
25
+ address(_productService) == msg.sender,
26
+ "ERROR:POL-001:NOT_PRODUCT_SERVICE"
27
+ );
28
+ _;
29
+ }
30
+
31
+ constructor(address productService) {
32
+ _policyModule = IPolicyModule(address(this));
33
+ _treasuryModule = ITreasuryModule(address(this));
34
+ _productService = IProductService(productService);
35
+ }
36
+
37
+ function registerPool(NftId nftId) public override {
38
+ require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
39
+
40
+ _poolInfo[nftId] = PoolInfo(
41
+ nftId,
42
+ INITIAL_CAPITAL,
43
+ INITIAL_LOCKED_CAPITAL
44
+ );
45
+ }
46
+
47
+ function underwrite(
48
+ NftId policyNftId,
49
+ NftId productNftId
50
+ ) external override onlyProductService {
51
+ IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
52
+ policyNftId
53
+ );
54
+ require(policyInfo.nftId == policyNftId, "ERROR:PL-002:POLICY_UNKNOWN");
55
+
56
+ ITreasuryModule.ProductSetup memory product = _treasuryModule
57
+ .getProductSetup(productNftId);
58
+ require(
59
+ product.productNftId == productNftId,
60
+ "ERROR:PL-003:PRODUCT_SETUP_MISSING"
61
+ );
62
+
63
+ NftId poolNftId = product.poolNftId;
64
+ PoolInfo storage poolInfo = _poolInfo[poolNftId];
65
+ require(poolInfo.nftId == poolNftId, "ERROR:PL-004:POOL_UNKNOWN");
66
+
67
+ require(
68
+ poolInfo.capital - poolInfo.lockedCapital >=
69
+ policyInfo.sumInsuredAmount,
70
+ "ERROR:PL-005:CAPACITY_TOO_LOW"
71
+ );
72
+
73
+ poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
74
+ }
75
+
76
+ function getPoolInfo(
77
+ NftId nftId
78
+ ) external view override returns (PoolInfo memory info) {
79
+ info = _poolInfo[nftId];
80
+ }
81
+ }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
5
+ import {IInstance} from "../IInstance.sol";
6
+ import {NftId} from "../../types/NftId.sol";
7
+
8
+ // TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
9
+ interface IProductService is IRegistryLinked {
10
+ function createApplication(
11
+ address applicationOwner,
12
+ uint256 sumInsuredAmount,
13
+ uint256 premiumAmount,
14
+ uint256 lifetime,
15
+ NftId bundleNftId
16
+ ) external returns (NftId nftId);
17
+
18
+ // function revoke(unit256 nftId) external;
19
+
20
+ function underwrite(NftId nftId) external;
21
+
22
+ // function decline(uint256 nftId) external;
23
+ // function expire(uint256 nftId) external;
24
+ function close(NftId nftId) external;
25
+
26
+ function collectPremium(NftId nftId) external;
27
+
28
+ // function createClaim(uint256 nftId, uint256 claimAmount) external;
29
+ // function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
30
+ // function declineClaim(uint256 nftId, uint256 claimId) external;
31
+ // function closeClaim(uint256 nftId, uint256 claimId) external;
32
+ }
33
+
34
+ interface IProductModule is IOwnable, IRegistryLinked {
35
+ function getProductService() external view returns (IProductService);
36
+ }
@@ -0,0 +1,136 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // import {IProduct} from "../../components/IProduct.sol";
5
+ // import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
6
+ // import {IInstance} from "../IInstance.sol";
7
+ import {IRegistry} from "../../registry/IRegistry.sol";
8
+ import {IPolicyModule} from "../policy/IPolicy.sol";
9
+ import {RegistryLinked} from "../../registry/Registry.sol";
10
+ import {IProductService, IProductModule} from "./IProductService.sol";
11
+ import {ITreasuryModule} from "../../instance/treasury/ITreasury.sol";
12
+ import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
13
+ import {ObjectType, INSTANCE, PRODUCT} from "../../types/ObjectType.sol";
14
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
15
+
16
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
17
+ contract ProductService is RegistryLinked, IProductService {
18
+ using NftIdLib for NftId;
19
+
20
+ constructor(
21
+ address registry
22
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
23
+ {
24
+
25
+ }
26
+
27
+ function createApplication(
28
+ address applicationOwner,
29
+ uint256 sumInsuredAmount,
30
+ uint256 premiumAmount,
31
+ uint256 lifetime,
32
+ NftId bundleNftId
33
+ ) external override returns (NftId nftId) {
34
+ // same as only registered product
35
+ NftId productNftId = _registry.getNftId(msg.sender);
36
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
37
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
38
+ productNftId
39
+ );
40
+ require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
41
+
42
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
43
+ productInfo.parentNftId
44
+ );
45
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
46
+ require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
47
+
48
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
49
+ nftId = policyModule.createApplication(
50
+ productInfo,
51
+ applicationOwner,
52
+ sumInsuredAmount,
53
+ premiumAmount,
54
+ lifetime,
55
+ bundleNftId
56
+ );
57
+
58
+ // add logging
59
+ }
60
+
61
+ function underwrite(NftId policyNftId) external override {
62
+ // validation
63
+ // same as only registered product
64
+ NftId productNftId = _registry.getNftId(msg.sender);
65
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
66
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
67
+ productNftId
68
+ );
69
+ require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
70
+
71
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
72
+ productInfo.parentNftId
73
+ );
74
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
75
+ require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
76
+
77
+ // underwrite policy
78
+ address instanceAddress = instanceInfo.objectAddress;
79
+ IPoolModule poolModule = IPoolModule(instanceAddress);
80
+ poolModule.underwrite(policyNftId, productNftId);
81
+
82
+ // activate policy
83
+ IPolicyModule policyModule = IPolicyModule(instanceAddress);
84
+ policyModule.activate(policyNftId);
85
+
86
+ // add logging
87
+ }
88
+
89
+ function collectPremium(NftId policyNftId) external override {
90
+ // validation same as other functions, eg underwrite
91
+ // TODO unify validation into modifier and/or other suitable approaches
92
+ // same as only registered product
93
+ NftId productNftId = _registry.getNftId(msg.sender);
94
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
95
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
96
+ productNftId
97
+ );
98
+ require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
99
+
100
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
101
+ productInfo.parentNftId
102
+ );
103
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
104
+ require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
105
+
106
+ // process/collect premium: book keeping for policy
107
+ address instanceAddress = instanceInfo.objectAddress;
108
+ IPolicyModule policyModule = IPolicyModule(instanceAddress);
109
+ policyModule.processPremium(policyNftId);
110
+
111
+ // process/collect premium: actual token transfer
112
+ ITreasuryModule treasuryModule = ITreasuryModule(instanceAddress);
113
+ treasuryModule.processPremium(policyNftId, productNftId);
114
+
115
+ // TODO add logging
116
+ }
117
+
118
+ function close(
119
+ NftId policyNftId
120
+ ) external override // solhint-disable-next-line no-empty-blocks
121
+ {
122
+
123
+ }
124
+ }
125
+
126
+ abstract contract ProductModule is IProductModule {
127
+ IProductService private _productService;
128
+
129
+ constructor(address productService) {
130
+ _productService = IProductService(productService);
131
+ }
132
+
133
+ function getProductService() external view returns (IProductService) {
134
+ return _productService;
135
+ }
136
+ }
@@ -0,0 +1,91 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+
6
+ import {IRegistryLinked} from "../../registry/IRegistry.sol";
7
+
8
+ import {NftId} from "../../types/NftId.sol";
9
+ import {UFixed} from "../../types/UFixed.sol";
10
+ import {Fee} from "../../types/Fee.sol";
11
+
12
+ import {TokenHandler} from "./TokenHandler.sol";
13
+
14
+ interface ITreasury {
15
+ // TODO add events
16
+ // TODO add errors
17
+ }
18
+
19
+ interface ITreasuryModule is IRegistryLinked, ITreasury {
20
+ struct ProductSetup {
21
+ NftId productNftId;
22
+ NftId distributorNftId;
23
+ NftId poolNftId;
24
+ IERC20 token;
25
+ TokenHandler tokenHandler;
26
+ address wallet;
27
+ Fee policyFee;
28
+ Fee processingFee;
29
+ }
30
+
31
+ struct DistributorSetup {
32
+ NftId distributorNftId;
33
+ address wallet;
34
+ Fee commissionFees;
35
+ }
36
+
37
+ struct PoolSetup {
38
+ NftId poolNftId;
39
+ address wallet;
40
+ Fee stakingFee;
41
+ Fee performanceFee;
42
+ }
43
+
44
+ function registerProduct(
45
+ NftId productNftId,
46
+ NftId distributorNftId,
47
+ NftId poolNftId,
48
+ IERC20 token,
49
+ address wallet,
50
+ Fee memory policyFee,
51
+ Fee memory processingFee
52
+ ) external;
53
+
54
+ function setProductFees(
55
+ NftId productNftId,
56
+ Fee memory policyFee,
57
+ Fee memory processingFee
58
+ ) external;
59
+
60
+ function registerPool(
61
+ NftId poolNftId,
62
+ address wallet,
63
+ Fee memory stakingFee,
64
+ Fee memory performanceFee
65
+ ) external;
66
+
67
+ function setPoolFees(
68
+ NftId poolNftId,
69
+ Fee memory stakingFee,
70
+ Fee memory performanceFee
71
+ ) external;
72
+
73
+ function processPremium(NftId policyNftId, NftId productNftId) external;
74
+
75
+ function getTokenHandler(
76
+ NftId productNftId
77
+ ) external view returns (TokenHandler tokenHandler);
78
+
79
+ function getProductSetup(
80
+ NftId productNftId
81
+ ) external view returns (ProductSetup memory setup);
82
+
83
+ function getPoolSetup(
84
+ NftId poolNftId
85
+ ) external view returns (PoolSetup memory setup);
86
+
87
+ function calculateFeeAmount(
88
+ uint256 amount,
89
+ Fee memory fee
90
+ ) external pure returns (uint256 feeAmount, uint256 netAmount);
91
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+
6
+ contract TokenHandler {
7
+ // TODO use oz safeTransferFrom
8
+
9
+ IERC20 _token;
10
+
11
+ constructor(address token) {
12
+ _token = IERC20(token);
13
+ }
14
+
15
+ // TODO add logging
16
+ function transfer(
17
+ address from,
18
+ address to,
19
+ uint256 amount
20
+ ) external // TODO add authz (only treasury)
21
+ {
22
+ _token.transferFrom(from, to, amount);
23
+ }
24
+ }