@etherisc/gif-next 0.0.2-2e6787f-928 → 0.0.2-2eb7eeb-578

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