@etherisc/gif-next 0.0.2-d250c72 → 0.0.2-d3543ee-345

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