@etherisc/gif-next 0.0.2-ed4dd55 → 0.0.2-f74fcad-685

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