@etherisc/gif-next 0.0.2-ec436bf-674 → 0.0.2-ecbd488-936

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  2. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.json +9 -9
  4. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  5. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  9. package/artifacts/contracts/components/Pool.sol/Pool.json +7 -7
  10. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  11. package/artifacts/contracts/components/Product.sol/Product.json +8 -64
  12. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  13. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  14. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  32. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  33. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  34. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  35. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  36. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +261 -0
  37. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  38. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  39. package/artifacts/contracts/instance/Instance.sol/Instance.json +94 -81
  40. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  41. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  42. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  43. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +2 -2
  44. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  45. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +48 -8
  46. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  47. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +48 -32
  48. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  50. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  51. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  52. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  53. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  62. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +16 -16
  63. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  64. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +22 -22
  65. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  66. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +17 -21
  67. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +19 -31
  72. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +24 -40
  74. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +18 -30
  76. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  77. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +1046 -0
  78. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  79. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +448 -0
  80. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  81. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  82. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +0 -127
  83. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  84. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -0
  85. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  86. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  87. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -169
  88. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  89. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +76 -20
  90. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +25 -37
  92. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  93. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +12 -12
  94. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  95. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  96. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  97. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  98. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  99. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  100. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  101. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  102. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  103. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  104. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  106. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  107. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  108. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  109. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  110. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  111. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  112. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  113. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  114. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  115. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  116. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  117. package/artifacts/contracts/test/TestService.sol/TestService.json +9 -9
  118. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  119. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  120. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  121. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  122. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  123. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  124. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  125. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  126. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  127. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  128. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  129. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  130. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  131. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  132. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  133. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  136. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  142. package/contracts/components/Distribution.sol +1 -2
  143. package/contracts/components/Pool.sol +1 -2
  144. package/contracts/components/Product.sol +28 -41
  145. package/contracts/instance/IInstance.sol +12 -3
  146. package/contracts/instance/Instance.sol +4 -4
  147. package/contracts/instance/InstanceService.sol +16 -3
  148. package/contracts/instance/InstanceServiceManager.sol +6 -5
  149. package/contracts/instance/base/ComponentServiceBase.sol +7 -1
  150. package/contracts/instance/service/DistributionService.sol +3 -2
  151. package/contracts/instance/service/DistributionServiceManager.sol +6 -5
  152. package/contracts/instance/service/IProductService.sol +3 -3
  153. package/contracts/instance/service/PoolService.sol +4 -3
  154. package/contracts/instance/service/PoolServiceManager.sol +6 -5
  155. package/contracts/instance/service/ProductService.sol +543 -0
  156. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  157. package/contracts/registry/IRegistry.sol +4 -19
  158. package/contracts/registry/IRegistryService.sol +28 -11
  159. package/contracts/registry/Registry.sol +2 -47
  160. package/contracts/registry/RegistryService.sol +30 -71
  161. package/contracts/shared/NftOwnable.sol +2 -4
  162. package/contracts/types/RoleId.sol +1 -0
  163. package/package.json +1 -1
@@ -0,0 +1,543 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IProductComponent} from "../../components/IProductComponent.sol";
6
+ import {Product} from "../../components/Product.sol";
7
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
8
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
+ import {IInstance} from "../IInstance.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
11
+ import {IRisk} from "../module/IRisk.sol";
12
+ import {IBundle} from "../module/IBundle.sol";
13
+ import {IProductService} from "./IProductService.sol";
14
+ import {ITreasury} from "../module/ITreasury.sol";
15
+ import {ISetup} from "../module/ISetup.sol";
16
+
17
+ import {TokenHandler} from "../../shared/TokenHandler.sol";
18
+
19
+ import {IVersionable} from "../../shared/IVersionable.sol";
20
+ import {Versionable} from "../../shared/Versionable.sol";
21
+
22
+ import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
23
+ import {UFixed, UFixedLib} from "../../types/UFixed.sol";
24
+ import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
25
+ import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
26
+ import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
27
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
28
+ import {Fee, FeeLib} from "../../types/Fee.sol";
29
+ import {ReferralId} from "../../types/Referral.sol";
30
+ import {RiskId} from "../../types/RiskId.sol";
31
+ import {StateId} from "../../types/StateId.sol";
32
+ import {Version, VersionLib} from "../../types/Version.sol";
33
+
34
+ import {IService} from "../../shared/IService.sol";
35
+ import {Service} from "../../shared/Service.sol";
36
+ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
37
+ import {IProductService} from "./IProductService.sol";
38
+ import {InstanceReader} from "../InstanceReader.sol";
39
+
40
+ string constant PRODUCT_SERVICE_NAME = "ProductService";
41
+
42
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
43
+ contract ProductService is ComponentServiceBase, IProductService {
44
+ using NftIdLib for NftId;
45
+
46
+ string public constant NAME = "ProductService";
47
+
48
+ address internal _registryAddress;
49
+
50
+ event LogProductServiceSender(address sender);
51
+
52
+ function _initialize(
53
+ address owner,
54
+ bytes memory data
55
+ )
56
+ internal
57
+ initializer
58
+ virtual override
59
+ {
60
+ address initialOwner = address(0);
61
+ (_registryAddress, initialOwner) = abi.decode(data, (address, address));
62
+
63
+ _initializeService(_registryAddress, owner);
64
+
65
+ _registerInterface(type(IService).interfaceId);
66
+ _registerInterface(type(IProductService).interfaceId);
67
+ }
68
+
69
+
70
+ function getName() public pure override(IService, Service) returns(string memory name) {
71
+ return NAME;
72
+ }
73
+
74
+ function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
75
+ ISetup.ProductSetupInfo memory initialSetup = abi.decode(
76
+ initialObjData,
77
+ (ISetup.ProductSetupInfo)
78
+ );
79
+ instance.createProductSetup(componentNftId, initialSetup);
80
+ }
81
+
82
+ function setFees(
83
+ Fee memory productFee,
84
+ Fee memory processingFee
85
+ )
86
+ external
87
+ override
88
+ {
89
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
90
+ InstanceReader instanceReader = instance.getInstanceReader();
91
+ NftId productNftId = productInfo.nftId;
92
+
93
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
94
+ productSetupInfo.productFee = productFee;
95
+ productSetupInfo.processingFee = processingFee;
96
+
97
+ instance.updateProductSetup(productNftId, productSetupInfo, KEEP_STATE());
98
+ }
99
+
100
+ // FIXME: this
101
+ function createRisk(
102
+ RiskId riskId,
103
+ bytes memory data
104
+ ) external override {
105
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
106
+ NftId productNftId = productInfo.nftId;
107
+ IRisk.RiskInfo memory riskInfo = IRisk.RiskInfo(productNftId, data);
108
+ instance.createRisk(
109
+ riskId,
110
+ riskInfo
111
+ );
112
+ }
113
+
114
+ function updateRisk(
115
+ RiskId riskId,
116
+ bytes memory data
117
+ ) external {
118
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
119
+ InstanceReader instanceReader = instance.getInstanceReader();
120
+ IRisk.RiskInfo memory riskInfo = instanceReader.getRiskInfo(riskId);
121
+ riskInfo.data = data;
122
+ instance.updateRisk(riskId, riskInfo, KEEP_STATE());
123
+ }
124
+
125
+ function updateRiskState(
126
+ RiskId riskId,
127
+ StateId state
128
+ ) external {
129
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
130
+ instance.updateRiskState(riskId, state);
131
+ }
132
+
133
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
134
+ IRegistry.ObjectInfo memory productInfo;
135
+ (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
136
+ product = Product(productInfo.objectAddress);
137
+ }
138
+
139
+ function calculatePremium(
140
+ RiskId riskId,
141
+ uint256 sumInsuredAmount,
142
+ uint256 lifetime,
143
+ bytes memory applicationData,
144
+ NftId bundleNftId,
145
+ ReferralId referralId
146
+ )
147
+ public
148
+ view
149
+ override
150
+ returns (
151
+ uint256 premiumAmount,
152
+ uint256 productFeeAmount,
153
+ uint256 poolFeeAmount,
154
+ uint256 bundleFeeAmount,
155
+ uint256 distributionFeeAmount
156
+ )
157
+ {
158
+ Product product = _getAndVerifyInstanceAndProduct();
159
+ uint256 netPremiumAmount = product.calculateNetPremium(
160
+ sumInsuredAmount,
161
+ riskId,
162
+ lifetime,
163
+ applicationData
164
+ );
165
+
166
+ (
167
+ productFeeAmount,
168
+ poolFeeAmount,
169
+ bundleFeeAmount,
170
+ distributionFeeAmount
171
+ ) = _calculateFeeAmounts(
172
+ netPremiumAmount,
173
+ product,
174
+ bundleNftId,
175
+ referralId
176
+ );
177
+
178
+ premiumAmount = netPremiumAmount + productFeeAmount;
179
+ premiumAmount += poolFeeAmount + bundleFeeAmount;
180
+ premiumAmount += distributionFeeAmount;
181
+ }
182
+
183
+ function _calculateFeeAmounts(
184
+ uint256 netPremiumAmount,
185
+ Product product,
186
+ NftId bundleNftId,
187
+ ReferralId referralId
188
+ )
189
+ internal
190
+ view
191
+ returns (
192
+ uint256 productFeeAmount,
193
+ uint256 poolFeeAmount,
194
+ uint256 bundleFeeAmount,
195
+ uint256 distributionFeeAmount
196
+ )
197
+ {
198
+ IInstance instance = product.getInstance();
199
+ // FIXME: this
200
+ // ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(product.getNftId());
201
+ // IBundle.BundleInfo memory bundleInfo = instance.getBundleInfo(bundleNftId);
202
+ // require(bundleInfo.poolNftId == treasuryInfo.poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
203
+
204
+ // (productFeeAmount,) = FeeLib.calculateFee(treasuryInfo.productFee, netPremiumAmount);
205
+ // (poolFeeAmount,) = FeeLib.calculateFee(treasuryInfo.poolFee, netPremiumAmount);
206
+ // (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
207
+
208
+ // IRegistry.ObjectInfo memory distributionInfo = getRegistry().getObjectInfo(treasuryInfo.distributionNftId);
209
+ // IDistributionComponent distribution = IDistributionComponent(distributionInfo.objectAddress);
210
+ // distributionFeeAmount = distribution.calculateFeeAmount(referralId, netPremiumAmount);
211
+ }
212
+
213
+
214
+ function createApplication(
215
+ address applicationOwner,
216
+ RiskId riskId,
217
+ uint256 sumInsuredAmount,
218
+ uint256 lifetime,
219
+ bytes memory applicationData,
220
+ NftId bundleNftId,
221
+ ReferralId referralId
222
+ ) external override returns (NftId policyNftId) {
223
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
224
+ // TODO add validations (see create bundle in pool service)
225
+
226
+ policyNftId = getRegistryService().registerPolicy(
227
+ IRegistry.ObjectInfo(
228
+ zeroNftId(),
229
+ productInfo.nftId,
230
+ POLICY(),
231
+ false, // intercepting property for policies is defined on product
232
+ address(0),
233
+ applicationOwner,
234
+ ""
235
+ )
236
+ );
237
+
238
+ (uint256 premiumAmount,,,,) = calculatePremium(
239
+ riskId,
240
+ sumInsuredAmount,
241
+ lifetime,
242
+ applicationData,
243
+ bundleNftId,
244
+ referralId
245
+ );
246
+
247
+ // FIXME: this
248
+ // instance.createPolicyInfo(
249
+ // policyNftId,
250
+ // productInfo.nftId,
251
+ // referralId,
252
+ // riskId,
253
+ // sumInsuredAmount,
254
+ // premiumAmount,
255
+ // lifetime,
256
+ // bundleNftId
257
+ // );
258
+
259
+ // TODO add logging
260
+ }
261
+
262
+ function _getAndVerifyUnderwritingSetup(
263
+ IInstance instance,
264
+ IPolicy.PolicyInfo memory policyInfo
265
+ )
266
+ internal
267
+ view
268
+ returns (
269
+ ITreasury.TreasuryInfo memory treasuryInfo,
270
+ NftId bundleNftId,
271
+ IBundle.BundleInfo memory bundleInfo,
272
+ uint256 collateralAmount
273
+ )
274
+ {
275
+ // FIXME: this
276
+ // check match between policy and bundle (via pool)
277
+ // treasuryInfo = instance.getTreasuryInfo(policyInfo.productNftId);
278
+ // bundleNftId = policyInfo.bundleNftId;
279
+ // bundleInfo = instance.getBundleInfo(bundleNftId);
280
+ // require(bundleInfo.poolNftId == treasuryInfo.poolNftId, "POLICY_BUNDLE_MISMATCH");
281
+
282
+ // // calculate required collateral
283
+ // NftId poolNftId = treasuryInfo.poolNftId;
284
+ // ISetup.PoolSetupInfo memory poolInfo = instance.getPoolInfo(poolNftId);
285
+
286
+ // // obtain remaining return values
287
+ // collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
288
+ }
289
+
290
+ function _lockCollateralInBundle(
291
+ IInstance instance,
292
+ NftId bundleNftId,
293
+ IBundle.BundleInfo memory bundleInfo,
294
+ NftId policyNftId,
295
+ uint256 collateralAmount
296
+ )
297
+ internal
298
+ returns (IBundle.BundleInfo memory)
299
+ {
300
+ bundleInfo.lockedAmount += collateralAmount;
301
+ // FIXME: this
302
+ // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
303
+ return bundleInfo;
304
+ }
305
+
306
+ function _underwriteByPool(
307
+ ITreasury.TreasuryInfo memory treasuryInfo,
308
+ NftId policyNftId,
309
+ IPolicy.PolicyInfo memory policyInfo,
310
+ bytes memory bundleFilter,
311
+ uint256 collateralAmount
312
+ )
313
+ internal
314
+ {
315
+ address poolAddress = getRegistry().getObjectInfo(treasuryInfo.poolNftId).objectAddress;
316
+ IPoolComponent pool = IPoolComponent(poolAddress);
317
+ pool.underwrite(
318
+ policyNftId,
319
+ policyInfo.applicationData,
320
+ bundleFilter,
321
+ collateralAmount);
322
+ }
323
+
324
+
325
+ function revoke(
326
+ NftId policyNftId
327
+ )
328
+ external
329
+ override
330
+ {
331
+ require(false, "ERROR:PRS-234:NOT_YET_IMPLEMENTED");
332
+ }
333
+
334
+
335
+ function underwrite(
336
+ NftId policyNftId,
337
+ bool requirePremiumPayment,
338
+ Timestamp activateAt
339
+ )
340
+ external
341
+ override
342
+ {
343
+ // check caller is registered product
344
+ (
345
+ IRegistry.ObjectInfo memory productInfo,
346
+ IInstance instance
347
+ ) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
348
+
349
+ // check match between policy and calling product
350
+ NftId productNftId = productInfo.nftId;
351
+ // FIXME: this
352
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
353
+ // require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
354
+ // require(instance.getState(policyNftId.toKey32(POLICY())) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
355
+
356
+ // ITreasury.TreasuryInfo memory treasuryInfo;
357
+ // NftId bundleNftId;
358
+ // IBundle.BundleInfo memory bundleInfo;
359
+ // uint256 collateralAmount;
360
+
361
+ // (
362
+ // treasuryInfo,
363
+ // bundleNftId,
364
+ // bundleInfo,
365
+ // collateralAmount
366
+ // ) = _getAndVerifyUnderwritingSetup(
367
+ // instance,
368
+ // policyInfo
369
+ // );
370
+
371
+ // // lock bundle collateral
372
+ // bundleInfo = _lockCollateralInBundle(
373
+ // instance,
374
+ // bundleNftId,
375
+ // bundleInfo,
376
+ // policyNftId,
377
+ // collateralAmount);
378
+
379
+ // // set policy state to underwritten
380
+ // instance.updatePolicyState(policyNftId, UNDERWRITTEN());
381
+
382
+ // // optional activation of policy
383
+ // if(activateAt > zeroTimestamp()) {
384
+ // policyInfo.activatedAt = activateAt;
385
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
386
+
387
+ // instance.updatePolicyState(policyNftId, ACTIVE());
388
+ // }
389
+
390
+ // // optional collection of premium
391
+ // if(requirePremiumPayment) {
392
+ // uint256 netPremiumAmount = _processPremiumByTreasury(
393
+ // instance,
394
+ // productInfo.nftId,
395
+ // treasuryInfo,
396
+ // policyNftId,
397
+ // policyInfo.premiumAmount);
398
+
399
+ // policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
400
+ // bundleInfo.balanceAmount += netPremiumAmount;
401
+ // }
402
+
403
+ // instance.setPolicyInfo(policyNftId, policyInfo);
404
+ // instance.setBundleInfo(bundleNftId, bundleInfo);
405
+
406
+ // // involve pool if necessary
407
+ // {
408
+ // NftId poolNftId = treasuryInfo.poolNftId;
409
+ // ISetup.PoolSetupInfo memory poolInfo = instance.getPoolInfo(poolNftId);
410
+
411
+ // if(poolInfo.isVerifying) {
412
+ // _underwriteByPool(
413
+ // treasuryInfo,
414
+ // policyNftId,
415
+ // policyInfo,
416
+ // bundleInfo.filter,
417
+ // collateralAmount
418
+ // );
419
+ // }
420
+ // }
421
+
422
+ // TODO add logging
423
+ }
424
+
425
+ function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
426
+ UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
427
+ UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
428
+ return collateralUFixed.toInt();
429
+ }
430
+
431
+ function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
432
+ // check caller is registered product
433
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
434
+
435
+ // perform actual token transfers
436
+ // FIXME: this
437
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
438
+ // ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productInfo.nftId);
439
+
440
+ // uint256 premiumAmount = policyInfo.premiumAmount;
441
+ // _processPremiumByTreasury(instance, productInfo.nftId, treasuryInfo, policyNftId, premiumAmount);
442
+
443
+ // // policy level book keeping for premium paid
444
+ // policyInfo.premiumPaidAmount += premiumAmount;
445
+
446
+ // // optional activation of policy
447
+ // if(activateAt > zeroTimestamp()) {
448
+ // require(
449
+ // policyInfo.activatedAt.eqz(),
450
+ // "ERROR:PRS-030:ALREADY_ACTIVATED");
451
+
452
+ // policyInfo.activatedAt = activateAt;
453
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
454
+
455
+ // instance.updatePolicyState(policyNftId, ACTIVE());
456
+ // }
457
+
458
+ // instance.setPolicyInfo(policyNftId, policyInfo);
459
+
460
+ // TODO add logging
461
+ }
462
+
463
+ // FIXME: this
464
+ function activate(NftId policyNftId, Timestamp activateAt) external override {
465
+ // check caller is registered product
466
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
467
+
468
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
469
+
470
+ // require(
471
+ // policyInfo.activatedAt.eqz(),
472
+ // "ERROR:PRS-020:ALREADY_ACTIVATED");
473
+
474
+ // policyInfo.activatedAt = activateAt;
475
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
476
+
477
+ // instance.setPolicyInfo(policyNftId, policyInfo);
478
+ // instance.updatePolicyState(policyNftId, ACTIVE());
479
+
480
+ // TODO add logging
481
+ }
482
+
483
+ function close(
484
+ NftId policyNftId
485
+ ) external override // solhint-disable-next-line no-empty-blocks
486
+ {
487
+
488
+ }
489
+
490
+ function _getPoolNftId(
491
+ IInstance instance,
492
+ NftId productNftId
493
+ )
494
+ internal
495
+ view
496
+ returns (NftId poolNftid)
497
+ {
498
+ // FIXME: this
499
+ // return instance.getTreasuryInfo(productNftId).poolNftId;
500
+ }
501
+
502
+
503
+ function _processPremiumByTreasury(
504
+ IInstance instance,
505
+ NftId productNftId,
506
+ ITreasury.TreasuryInfo memory treasuryInfo,
507
+ NftId policyNftId,
508
+ uint256 premiumAmount
509
+ )
510
+ internal
511
+ returns (uint256 netPremiumAmount)
512
+ {
513
+ // process token transfer(s)
514
+ if(premiumAmount > 0) {
515
+ // FIXME: this
516
+ // TokenHandler tokenHandler = instance.getTokenHandler(productNftId);
517
+ // address policyOwner = getRegistry().ownerOf(policyNftId);
518
+ // address poolWallet = instance.getComponentWallet(treasuryInfo.poolNftId);
519
+ // netPremiumAmount = premiumAmount;
520
+ // Fee memory productFee = treasuryInfo.productFee;
521
+
522
+ // if (FeeLib.feeIsZero(productFee)) {
523
+ // tokenHandler.transfer(
524
+ // policyOwner,
525
+ // poolWallet,
526
+ // premiumAmount
527
+ // );
528
+ // } else {
529
+ // (uint256 feeAmount, uint256 netAmount) = instance.calculateFeeAmount(
530
+ // premiumAmount,
531
+ // productFee
532
+ // );
533
+
534
+ // address productWallet = instance.getComponentWallet(productNftId);
535
+ // tokenHandler.transfer(policyOwner, productWallet, feeAmount);
536
+ // tokenHandler.transfer(policyOwner, poolWallet, netAmount);
537
+ // netPremiumAmount = netAmount;
538
+ // }
539
+ }
540
+
541
+ // TODO add logging
542
+ }
543
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IVersionable} from "../../shared/IVersionable.sol";
5
+ import {ProxyManager} from "../../shared/ProxyManager.sol";
6
+ import {ProductService} from "./ProductService.sol";
7
+ import {Registry} from "../../registry/Registry.sol";
8
+ import {RegistryService} from "../../registry/RegistryService.sol";
9
+ import {VersionLib} from "../../types/Version.sol";
10
+
11
+ contract ProductServiceManager is ProxyManager {
12
+
13
+ ProductService private _productService;
14
+
15
+ /// @dev initializes proxy manager with product service implementation
16
+ constructor(
17
+ address registryAddress
18
+ )
19
+ ProxyManager()
20
+ {
21
+ ProductService svc = new ProductService();
22
+ bytes memory data = abi.encode(registryAddress, address(this));
23
+ IVersionable versionable = deploy(
24
+ address(svc),
25
+ data);
26
+
27
+ _productService = ProductService(address(versionable));
28
+
29
+ // Registry registry = Registry(registryAddress);
30
+ // address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
31
+ // RegistryService registryService = RegistryService(registryServiceAddress);
32
+ // TODO this must have a role or own nft to register service
33
+ //registryService.registerService(_productService);
34
+
35
+ // TODO no nft to link yet
36
+ // link ownership of instance service manager ot nft owner of instance service
37
+ //_linkToNftOwnable(
38
+ // address(registryAddress),
39
+ // address(_productService));
40
+
41
+ // implies that after this constructor call only upgrade functionality is available
42
+ _isDeployed = true;
43
+ }
44
+
45
+ //--- view functions ----------------------------------------------------//
46
+ function getProductService()
47
+ external
48
+ view
49
+ returns (ProductService productService)
50
+ {
51
+ return _productService;
52
+ }
53
+
54
+ }
@@ -13,30 +13,19 @@ interface IRegistry is IERC165 {
13
13
  event LogInitialMajorVersionSet(VersionPart majorVersion);
14
14
  event LogMajorVersionSet(VersionPart majorVersionMax);
15
15
  event LogRegistration(ObjectInfo info);
16
- event LogTokenStateSet(address token, VersionPart majorVersion, bool active);
17
16
  event LogServiceNameRegistration(string serviceName, VersionPart majorVersion);
18
17
 
19
- // supported versions
18
+ // setMajorVersion()
19
+ error NotOwner(address account);
20
20
  error MajorVersionMaxIncreaseInvalid(VersionPart newMajorVersionMax, VersionPart existingMaxMajorVersion);
21
21
 
22
- // token whitelisting
23
- error TokenNotRegistered(address token);
24
- error NotToken(address token);
25
- error TokenMajorVersionInvalid(VersionPart majorVersion);
26
-
27
- // register
22
+ // register()
28
23
  error NotRegistryService();
29
24
  error ZeroParentAddress();
25
+ error InvalidTypesCombination(ObjectType objectType, ObjectType parentType);
30
26
  error ContractAlreadyRegistered(address objectAddress);
31
27
  error InvalidServiceVersion(VersionPart majorVersion);
32
28
  error ServiceNameAlreadyRegistered(string name, VersionPart majorVersion);
33
-
34
- // approve
35
- error NotOwner(address account);
36
- error NotRegisteredContract(NftId registrarNftId);
37
- error NotService(NftId registrarNftId);
38
- error InvalidTypesCombination(ObjectType objectType, ObjectType parentType);
39
-
40
29
 
41
30
  struct ObjectInfo {
42
31
  NftId nftId;
@@ -53,8 +42,6 @@ interface IRegistry is IERC165 {
53
42
 
54
43
  function register(ObjectInfo memory info) external returns (NftId nftId);
55
44
 
56
- function setTokenActive(address token, VersionPart majorVersion, bool active) external;
57
-
58
45
  function getMajorVersionMin() external view returns (VersionPart);
59
46
 
60
47
  function getMajorVersionMax() external view returns (VersionPart);
@@ -79,8 +66,6 @@ interface IRegistry is IERC165 {
79
66
 
80
67
  function isRegistered(address contractAddress) external view returns (bool);
81
68
 
82
- function isTokenActive(address token, VersionPart majorVersion) external view returns (bool);
83
-
84
69
  function getServiceName(NftId nftId) external view returns (string memory name);
85
70
 
86
71
  function getServiceAddress(