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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. package/README.md +33 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +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 +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 +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/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 +8 -8
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
  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 +9 -9
  104. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
  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 +4 -0
  109. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  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 +85 -3
  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 +4 -0
  119. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  120. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  121. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
  122. package/contracts/components/Component.sol +39 -24
  123. package/contracts/components/IPool.sol +9 -3
  124. package/contracts/components/IProduct.sol +11 -6
  125. package/contracts/components/Pool.sol +37 -14
  126. package/contracts/components/Product.sol +48 -24
  127. package/contracts/experiment/errors/Require.sol +10 -5
  128. package/contracts/experiment/errors/Revert.sol +13 -8
  129. package/contracts/experiment/inheritance/A.sol +8 -11
  130. package/contracts/experiment/inheritance/B.sol +10 -5
  131. package/contracts/experiment/inheritance/C.sol +11 -5
  132. package/contracts/experiment/inheritance/IA.sol +2 -7
  133. package/contracts/experiment/inheritance/IB.sol +3 -2
  134. package/contracts/experiment/inheritance/IC.sol +4 -3
  135. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  136. package/contracts/experiment/statemachine/ISM.sol +25 -0
  137. package/contracts/experiment/statemachine/README.md +112 -0
  138. package/contracts/experiment/statemachine/SM.sol +57 -0
  139. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  140. package/contracts/experiment/types/TypeA.sol +14 -9
  141. package/contracts/experiment/types/TypeB.sol +14 -9
  142. package/contracts/instance/IInstance.sol +8 -3
  143. package/contracts/instance/Instance.sol +24 -15
  144. package/contracts/instance/access/Access.sol +63 -116
  145. package/contracts/instance/access/IAccess.sol +28 -48
  146. package/contracts/instance/component/ComponentModule.sol +163 -135
  147. package/contracts/instance/component/IComponent.sol +41 -61
  148. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  149. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  150. package/contracts/instance/policy/IPolicy.sol +19 -35
  151. package/contracts/instance/policy/PolicyModule.sol +52 -44
  152. package/contracts/instance/pool/IPoolModule.sol +9 -26
  153. package/contracts/instance/pool/PoolModule.sol +43 -45
  154. package/contracts/instance/product/IProductService.sol +10 -19
  155. package/contracts/instance/product/ProductService.sol +86 -55
  156. package/contracts/instance/treasury/ITreasury.sol +91 -0
  157. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  158. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  159. package/contracts/registry/ChainNft.sol +23 -61
  160. package/contracts/registry/IChainNft.sol +10 -7
  161. package/contracts/registry/IRegistry.sol +40 -41
  162. package/contracts/registry/Registry.sol +73 -67
  163. package/contracts/types/Blocknumber.sol +118 -0
  164. package/contracts/types/ChainId.sol +24 -10
  165. package/contracts/types/Fee.sol +32 -0
  166. package/contracts/types/NftId.sol +36 -10
  167. package/contracts/types/ObjectType.sol +107 -0
  168. package/contracts/types/StateId.sol +91 -0
  169. package/contracts/types/Timestamp.sol +102 -0
  170. package/contracts/types/UFixed.sol +210 -0
  171. package/package.json +13 -5
@@ -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
  }
@@ -1,7 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
-
5
4
  // import {IProduct} from "../../components/IProduct.sol";
6
5
  // import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
7
6
  // import {IInstance} from "../IInstance.sol";
@@ -9,39 +8,42 @@ import {IRegistry} from "../../registry/IRegistry.sol";
9
8
  import {IPolicyModule} from "../policy/IPolicy.sol";
10
9
  import {RegistryLinked} from "../../registry/Registry.sol";
11
10
  import {IProductService, IProductModule} from "./IProductService.sol";
12
- import {IComponentModule} from "../../instance/component/IComponent.sol";
11
+ import {ITreasuryModule} from "../../instance/treasury/ITreasury.sol";
13
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";
14
15
 
15
16
  // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
16
- contract ProductService is
17
- RegistryLinked,
18
- IProductService
19
- {
20
- constructor(address registry)
21
- RegistryLinked(registry)
22
- { }
17
+ contract ProductService is RegistryLinked, IProductService {
18
+ using NftIdLib for NftId;
23
19
 
20
+ constructor(
21
+ address registry
22
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
23
+ {
24
+
25
+ }
24
26
 
25
27
  function createApplication(
26
28
  address applicationOwner,
27
29
  uint256 sumInsuredAmount,
28
30
  uint256 premiumAmount,
29
31
  uint256 lifetime,
30
- uint256 bundleNftId
31
- )
32
- external
33
- override
34
- returns(uint256 nftId)
35
- {
32
+ NftId bundleNftId
33
+ ) external override returns (NftId nftId) {
36
34
  // same as only registered product
37
- uint256 productNftId = _registry.getNftId(msg.sender);
38
- require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
39
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
40
- require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
41
-
42
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
43
- require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
44
- require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
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");
45
47
 
46
48
  IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
47
49
  nftId = policyModule.createApplication(
@@ -50,56 +52,85 @@ contract ProductService is
50
52
  sumInsuredAmount,
51
53
  premiumAmount,
52
54
  lifetime,
53
- bundleNftId);
55
+ bundleNftId
56
+ );
54
57
 
55
58
  // add logging
56
59
  }
57
60
 
58
- function underwrite(uint256 nftId)
59
- external
60
- override
61
- {
61
+ function underwrite(NftId policyNftId) external override {
62
+ // validation
62
63
  // same as only registered product
63
- uint256 productNftId = _registry.getNftId(msg.sender);
64
- require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
65
- IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
66
- require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
67
-
68
- IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
69
- require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
70
- require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
71
-
72
- // get responsible pool
73
- IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
74
- uint256 poolNftId = componentModule.getPoolNftId(productNftId);
75
-
76
- // lock capital (and update pool accounting)
77
- IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
78
- poolModule.underwrite(
79
- poolNftId,
80
- nftId);
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
81
 
82
82
  // activate policy
83
- IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
84
- policyModule.activate(nftId);
83
+ IPolicyModule policyModule = IPolicyModule(instanceAddress);
84
+ policyModule.activate(policyNftId);
85
85
 
86
86
  // add logging
87
87
  }
88
88
 
89
- function close(uint256 nftId) external override {}
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
+ }
90
124
  }
91
125
 
92
- abstract contract ProductModule is
93
- IProductModule
94
- {
126
+ abstract contract ProductModule is IProductModule {
95
127
  IProductService private _productService;
96
128
 
97
129
  constructor(address productService) {
98
130
  _productService = IProductService(productService);
99
131
  }
100
132
 
101
- function getProductService() external view returns(IProductService) {
133
+ function getProductService() external view returns (IProductService) {
102
134
  return _productService;
103
135
  }
104
-
105
- }
136
+ }