@etherisc/gif-next 0.0.2-f034782-101 → 0.0.2-f080b71-868

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 (234) hide show
  1. package/README.md +6 -83
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +10 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +10 -0
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +100 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +100 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +110 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +100 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +20 -0
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +10 -0
  18. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  19. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  20. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  21. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  22. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +214 -1988
  24. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +101 -14
  26. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  27. package/artifacts/contracts/instance/Instance.sol/Instance.json +379 -2729
  28. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +95 -58
  30. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.dbg.json +4 -0
  31. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.json +124 -0
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +45 -25
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +157 -126
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +30 -58
  38. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +4 -0
  39. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +2677 -0
  40. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  41. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  42. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +108 -21
  44. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  48. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  50. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +6 -6
  52. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  60. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +119 -227
  61. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  62. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +11 -35
  63. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  64. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +330 -147
  65. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  66. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +70 -14
  67. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +127 -32
  69. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +11 -7
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +193 -386
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +38 -74
  75. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +68 -149
  77. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +163 -113
  79. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  80. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +80 -14
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +89 -231
  83. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +132 -24
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +430 -14
  87. package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.json +518 -0
  89. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +80 -14
  91. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +210 -65
  93. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +27 -19
  95. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +493 -48
  97. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +18 -14
  99. package/artifacts/contracts/instance/service/PricingService.sol/PricingService.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PricingService.sol/PricingService.json +988 -0
  101. package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.json +689 -0
  103. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +139 -44
  105. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  106. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  107. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  110. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -24
  111. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  114. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  116. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +17 -36
  118. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  120. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  121. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  124. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  125. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  126. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  131. package/artifacts/contracts/shared/IService.sol/IService.json +80 -14
  132. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  133. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  134. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  135. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  136. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  137. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  138. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  139. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  141. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  142. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  143. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  144. package/artifacts/contracts/shared/Service.sol/Service.json +86 -15
  145. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  146. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  147. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  150. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  152. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  154. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  155. package/artifacts/contracts/test/TestService.sol/TestService.json +101 -26
  156. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  157. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  159. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  160. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +4 -0
  162. package/artifacts/contracts/types/Amount.sol/AmountLib.json +161 -0
  163. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  168. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  170. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  172. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  174. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  175. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  176. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  177. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  178. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  179. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  182. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  184. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  185. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  186. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  187. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  193. package/contracts/components/Component.sol +4 -2
  194. package/contracts/components/IComponent.sol +3 -1
  195. package/contracts/components/Pool.sol +8 -4
  196. package/contracts/components/Product.sol +8 -5
  197. package/contracts/instance/IInstance.sol +16 -54
  198. package/contracts/instance/IInstanceService.sol +14 -2
  199. package/contracts/instance/Instance.sol +88 -188
  200. package/contracts/instance/InstanceAccessManager.sol +41 -23
  201. package/contracts/instance/InstanceAuthorizationsLib.sol +299 -0
  202. package/contracts/instance/InstanceReader.sol +15 -6
  203. package/contracts/instance/InstanceService.sol +59 -234
  204. package/contracts/instance/InstanceStore.sol +219 -0
  205. package/contracts/instance/base/ComponentService.sol +51 -38
  206. package/contracts/instance/base/KeyValueStore.sol +8 -3
  207. package/contracts/instance/module/IAccess.sol +2 -2
  208. package/contracts/instance/module/IBundle.sol +6 -4
  209. package/contracts/instance/module/IComponents.sol +6 -0
  210. package/contracts/instance/service/ApplicationService.sol +35 -202
  211. package/contracts/instance/service/BundleService.sol +165 -70
  212. package/contracts/instance/service/ClaimService.sol +2 -8
  213. package/contracts/instance/service/DistributionService.sol +30 -151
  214. package/contracts/instance/service/IApplicationService.sol +0 -18
  215. package/contracts/instance/service/IBundleService.sol +54 -22
  216. package/contracts/instance/service/IDistributionService.sol +1 -14
  217. package/contracts/instance/service/IPolicyService.sol +2 -0
  218. package/contracts/instance/service/IPoolService.sol +65 -1
  219. package/contracts/instance/service/IPricingService.sol +36 -0
  220. package/contracts/instance/service/PolicyService.sol +88 -115
  221. package/contracts/instance/service/PoolService.sol +136 -53
  222. package/contracts/instance/service/PricingService.sol +275 -0
  223. package/contracts/instance/service/PricingServiceManager.sol +51 -0
  224. package/contracts/instance/service/ProductService.sol +25 -56
  225. package/contracts/registry/IRegistryService.sol +4 -3
  226. package/contracts/registry/RegistryService.sol +25 -22
  227. package/contracts/registry/ReleaseManager.sol +20 -18
  228. package/contracts/shared/IService.sol +4 -6
  229. package/contracts/shared/Service.sol +21 -7
  230. package/contracts/test/TestService.sol +1 -1
  231. package/contracts/types/Amount.sol +60 -0
  232. package/contracts/types/Fee.sol +12 -5
  233. package/contracts/types/ObjectType.sol +4 -0
  234. package/package.json +1 -1
@@ -16,10 +16,11 @@ import {TokenHandler} from "../../shared/TokenHandler.sol";
16
16
 
17
17
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
18
18
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
19
- import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
19
+ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, PRICE} from "../../types/ObjectType.sol";
20
20
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
21
21
  import {NftId, NftIdLib} from "../../types/NftId.sol";
22
22
  import {StateId} from "../../types/StateId.sol";
23
+ import {VersionPart} from "../../types/Version.sol";
23
24
 
24
25
  import {ComponentService} from "../base/ComponentService.sol";
25
26
  import {IApplicationService} from "./IApplicationService.sol";
@@ -28,6 +29,7 @@ import {IDistributionService} from "./IDistributionService.sol";
28
29
  import {InstanceReader} from "../InstanceReader.sol";
29
30
  import {IPolicyService} from "./IPolicyService.sol";
30
31
  import {IPoolService} from "./IPoolService.sol";
32
+ import {IPricingService} from "./IPricingService.sol";
31
33
  import {IService} from "../../shared/IService.sol";
32
34
  import {Service} from "../../shared/Service.sol";
33
35
 
@@ -43,6 +45,7 @@ contract PolicyService is
43
45
  IBundleService internal _bundleService;
44
46
  IApplicationService internal _applicationService;
45
47
  IDistributionService internal _distributionService;
48
+ IPricingService internal _pricingService;
46
49
 
47
50
  event LogProductServiceSender(address sender);
48
51
 
@@ -58,58 +61,55 @@ contract PolicyService is
58
61
  address initialOwner;
59
62
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
60
63
 
61
- initializeService(registryAddress, owner);
64
+ initializeService(registryAddress, address(0), owner);
62
65
 
63
- _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
64
- _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
65
- _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), getMajorVersion()));
66
- _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), getMajorVersion()));
66
+ VersionPart majorVersion = getVersion().toMajorPart();
67
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion));
68
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), majorVersion));
69
+ _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
70
+ _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
71
+ _pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion));
67
72
 
68
73
  registerInterface(type(IPolicyService).interfaceId);
69
74
  }
70
75
 
71
76
 
72
- function getDomain() public pure override(IService, Service) returns(ObjectType) {
77
+ function getDomain() public pure override returns(ObjectType) {
73
78
  return POLICY();
74
79
  }
75
80
 
76
81
 
77
82
  function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
78
83
  IRegistry.ObjectInfo memory productInfo;
79
- (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
84
+ (, productInfo,) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
80
85
  product = Product(productInfo.objectAddress);
81
86
  }
82
87
 
83
- function _getAndVerifyUnderwritingSetup(
84
- IInstance instance,
85
- InstanceReader instanceReader,
86
- IPolicy.PolicyInfo memory policyInfo,
87
- ISetup.ProductSetupInfo memory productSetupInfo
88
- )
89
- internal
90
- view
91
- returns (
92
- NftId poolNftId,
93
- NftId bundleNftId,
94
- IBundle.BundleInfo memory bundleInfo,
95
- uint256 collateralAmount
96
- )
97
- {
98
- // check match between policy and bundle (via pool)
99
- poolNftId = productSetupInfo.poolNftId;
100
- bundleNftId = policyInfo.bundleNftId;
101
- bundleInfo = instanceReader.getBundleInfo(bundleNftId);
102
- require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
103
-
104
- // calculate required collateral
105
- IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
106
- IComponents.PoolInfo memory poolInfo = abi.decode(
107
- componentInfo.data, (IComponents.PoolInfo));
108
-
109
- // obtain remaining return values
110
- // TODO required collateral amount should be calculated by pool service, not policy service
111
- collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
112
- }
88
+ // function _getAndVerifyUnderwritingSetup(
89
+ // IInstance instance,
90
+ // InstanceReader instanceReader,
91
+ // IPolicy.PolicyInfo memory policyInfo,
92
+ // ISetup.ProductSetupInfo memory productSetupInfo
93
+ // )
94
+ // internal
95
+ // view
96
+ // returns (
97
+ // NftId poolNftId,
98
+ // IComponents.PoolInfo memory poolInfo,
99
+ // NftId bundleNftId,
100
+ // IBundle.BundleInfo memory bundleInfo
101
+ // )
102
+ // {
103
+ // // check match between policy and bundle (via pool)
104
+ // poolNftId = productSetupInfo.poolNftId;
105
+ // bundleNftId = policyInfo.bundleNftId;
106
+ // bundleInfo = instanceReader.getBundleInfo(bundleNftId);
107
+ // equire(bundleInfo.poolNftId == poolNftId, "BUNDLE_POOL_MISMATCH");
108
+
109
+ // // calculate required collateral
110
+ // IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
111
+ // poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
112
+ // }
113
113
 
114
114
 
115
115
  function decline(
@@ -118,7 +118,7 @@ contract PolicyService is
118
118
  external
119
119
  override
120
120
  {
121
- require(false, "ERROR:PRS-235:NOT_YET_IMPLEMENTED");
121
+ revert();
122
122
  }
123
123
 
124
124
 
@@ -132,42 +132,33 @@ contract PolicyService is
132
132
  virtual override
133
133
  {
134
134
  // check caller is registered product
135
- IInstance instance;
136
- InstanceReader instanceReader;
137
- NftId productNftId;
138
- {
139
- IRegistry.ObjectInfo memory productInfo;
140
- (productInfo, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
141
- instanceReader = instance.getInstanceReader();
142
- productNftId = productInfo.nftId;
143
- }
135
+ (NftId productNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
136
+ InstanceReader instanceReader = instance.getInstanceReader();
144
137
 
145
138
  // check policy matches with calling product
146
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(applicationNftId);
147
- require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
139
+ IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
140
+ if(applicationInfo.productNftId != productNftId) {
141
+ revert ErrorIPolicyServicePolicyProductMismatch(
142
+ applicationNftId,
143
+ applicationInfo.productNftId,
144
+ productNftId);
145
+ }
148
146
 
149
147
  // check policy is in state applied
150
- require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
151
-
152
- (
153
- NftId poolNftId,
154
- NftId bundleNftId,
155
- IBundle.BundleInfo memory bundleInfo,
156
- uint256 collateralAmount
157
- ) = _getAndVerifyUnderwritingSetup(
158
- instance,
159
- instanceReader,
160
- policyInfo,
161
- instanceReader.getProductSetupInfo(productNftId)
162
- );
148
+ if(instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
149
+ revert ErrorIPolicyServicePolicyStateInvalid(
150
+ applicationNftId,
151
+ APPLIED(),
152
+ instanceReader.getPolicyState(applicationNftId));
153
+ }
163
154
 
164
155
  StateId newPolicyState = UNDERWRITTEN();
165
156
 
166
157
  // optional activation of policy
167
158
  if(activateAt > zeroTimestamp()) {
168
159
  newPolicyState = ACTIVE();
169
- policyInfo.activatedAt = activateAt;
170
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
160
+ applicationInfo.activatedAt = activateAt;
161
+ applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
171
162
  }
172
163
 
173
164
  // lock bundle collateral
@@ -178,48 +169,25 @@ contract PolicyService is
178
169
  netPremiumAmount = _processPremiumByTreasury(
179
170
  instance,
180
171
  applicationNftId,
181
- policyInfo.premiumAmount);
172
+ applicationInfo.premiumAmount);
182
173
 
183
- policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
174
+ applicationInfo.premiumPaidAmount += applicationInfo.premiumAmount;
184
175
  }
185
176
 
186
- // lock collateral and update bundle book keeping
187
- // TODO introduct indirection via pool service?
188
- // well pool would only need to be involved when a part of the collateral
189
- // is provided by a "re insurance policy" of the pool
190
- // but then again the policiy would likely best be attached to the bundle. really? why?
191
- // retention level: fraction of sum insured that product will cover from pool funds directly
177
+ // store updated policy info
178
+ instance.getInstanceStore().updatePolicy(applicationNftId, applicationInfo, newPolicyState);
179
+
180
+ // lock collateral and update pool and bundle book keeping
181
+ // pool retention level: fraction of sum insured that product will cover from pool funds directly
192
182
  // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
193
183
  // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
194
- // open points:
195
- // - do we need a link of a bundle to this policy or is it enough to know that the pool has an active policy?
196
- // - when to buy such policies and for which amount? manual trigger or link to bundle creation and/or funding?
197
- bundleInfo = _bundleService.lockCollateral(
184
+ // might also call pool component (for isVerifyingApplications pools)
185
+ _poolService.lockCollateral(
198
186
  instance,
187
+ productNftId,
199
188
  applicationNftId,
200
- bundleNftId,
201
- collateralAmount,
202
- netPremiumAmount);
203
-
204
- instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
205
-
206
- // also verify/confirm application by pool if necessary
207
- if(abi.decode(
208
- instanceReader.getComponentInfo(poolNftId).data,
209
- (IComponents.PoolInfo)
210
- ).isVerifyingApplications
211
- )
212
- {
213
- IPoolComponent pool = IPoolComponent(
214
- getRegistry().getObjectInfo(poolNftId).objectAddress);
215
-
216
- pool.verifyApplication(
217
- applicationNftId,
218
- policyInfo.applicationData,
219
- bundleNftId,
220
- bundleInfo.filter,
221
- collateralAmount);
222
- }
189
+ applicationInfo,
190
+ netPremiumAmount); // for pool book keeping (fee + additional capital)
223
191
 
224
192
  // TODO: add logging
225
193
  }
@@ -233,7 +201,7 @@ contract PolicyService is
233
201
 
234
202
  function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
235
203
  // check caller is registered product
236
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
204
+ (NftId productNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
237
205
  InstanceReader instanceReader = instance.getInstanceReader();
238
206
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
239
207
 
@@ -251,7 +219,7 @@ contract PolicyService is
251
219
  policyInfo.premiumPaidAmount += unpaidPremiumAmount;
252
220
 
253
221
  _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
254
- instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
222
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
255
223
 
256
224
  if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
257
225
  activate(policyNftId, activateAt);
@@ -262,7 +230,7 @@ contract PolicyService is
262
230
 
263
231
  function activate(NftId policyNftId, Timestamp activateAt) public override {
264
232
  // check caller is registered product
265
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
233
+ (,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
266
234
  InstanceReader instanceReader = instance.getInstanceReader();
267
235
 
268
236
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -274,7 +242,7 @@ contract PolicyService is
274
242
  policyInfo.activatedAt = activateAt;
275
243
  policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
276
244
 
277
- instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
245
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, ACTIVE());
278
246
 
279
247
  // TODO: add logging
280
248
  }
@@ -296,7 +264,7 @@ contract PolicyService is
296
264
  external
297
265
  override
298
266
  {
299
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
267
+ (,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(PRODUCT());
300
268
  InstanceReader instanceReader = instance.getInstanceReader();
301
269
 
302
270
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -328,8 +296,12 @@ contract PolicyService is
328
296
 
329
297
  policyInfo.closedAt = TimestampLib.blockTimestamp();
330
298
 
331
- _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
332
- instance.updatePolicy(policyNftId, policyInfo, CLOSED());
299
+ _poolService.releaseCollateral(
300
+ instance,
301
+ policyNftId,
302
+ policyInfo);
303
+
304
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
333
305
  }
334
306
 
335
307
  function _getPoolNftId(
@@ -357,20 +329,21 @@ contract PolicyService is
357
329
  // process token transfer(s)
358
330
  if(premiumAmount > 0) {
359
331
  NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
360
- ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
361
- IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
332
+ InstanceReader reader = instance.getInstanceReader();
333
+ ISetup.ProductSetupInfo memory productSetupInfo = reader.getProductSetupInfo(productNftId);
334
+ IPolicy.PolicyInfo memory policyInfo = reader.getPolicyInfo(policyNftId);
362
335
  TokenHandler tokenHandler = productSetupInfo.tokenHandler;
363
336
  address policyOwner = getRegistry().ownerOf(policyNftId);
364
- address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
365
- IPolicy.Premium memory premium = _applicationService.calculatePremium(
337
+ address poolWallet = reader.getComponentInfo(productSetupInfo.poolNftId).wallet;
338
+ // TODO calculated for the second time -> can differ from the first calculation during applicationService.create()?
339
+ IPolicy.Premium memory premium = _pricingService.calculatePremium(
366
340
  productNftId,
341
+ policyInfo.bundleNftId,
367
342
  policyInfo.riskId,
343
+ policyInfo.referralId,
368
344
  policyInfo.sumInsuredAmount,
369
345
  policyInfo.lifetime,
370
- policyInfo.applicationData,
371
- policyInfo.bundleNftId,
372
- policyInfo.referralId
373
- );
346
+ policyInfo.applicationData);
374
347
 
375
348
  if (premium.premiumAmount != premiumAmount) {
376
349
  revert ErrorIPolicyServicePremiumMismatch(policyNftId, premiumAmount, premium.premiumAmount);
@@ -13,6 +13,7 @@ import {IVersionable} from "../../shared/IVersionable.sol";
13
13
  import {Versionable} from "../../shared/Versionable.sol";
14
14
  import {INftOwnable} from "../../shared/INftOwnable.sol";
15
15
 
16
+ import {Amount} from "../../types/Amount.sol";
16
17
  import {Fee, FeeLib} from "../../types/Fee.sol";
17
18
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
18
19
  import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
@@ -20,6 +21,7 @@ import {PUBLIC_ROLE, POOL_OWNER_ROLE, POLICY_SERVICE_ROLE, RoleId} from "../../t
20
21
  import {Fee, FeeLib} from "../../types/Fee.sol";
21
22
  import {Version, VersionLib} from "../../types/Version.sol";
22
23
  import {KEEP_STATE, StateId} from "../../types/StateId.sol";
24
+ import {Seconds} from "../../types/Seconds.sol";
23
25
  import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
24
26
  import {Version, VersionLib} from "../../types/Version.sol";
25
27
 
@@ -27,6 +29,7 @@ import {IService} from "../../shared/IService.sol";
27
29
  import {Service} from "../../shared/Service.sol";
28
30
  import {BundleManager} from "../BundleManager.sol";
29
31
  import {ComponentService} from "../base/ComponentService.sol";
32
+ import {IBundleService} from "./IBundleService.sol";
30
33
  import {IPoolService} from "./IPoolService.sol";
31
34
  import {IRegistryService} from "../../registry/IRegistryService.sol";
32
35
  import {InstanceService} from "../InstanceService.sol";
@@ -42,7 +45,7 @@ contract PoolService is
42
45
  {
43
46
  using NftIdLib for NftId;
44
47
 
45
- address internal _registryAddress;
48
+ IBundleService internal _bundleService;
46
49
 
47
50
  function _initialize(
48
51
  address owner,
@@ -57,54 +60,17 @@ contract PoolService is
57
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
58
61
  // TODO while PoolService is not deployed in PoolServiceManager constructor
59
62
  // owner is PoolServiceManager deployer
60
- initializeService(registryAddress, owner);
63
+ initializeService(registryAddress, address(0), owner);
64
+
65
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getVersion().toMajorPart()));
66
+
61
67
  registerInterface(type(IPoolService).interfaceId);
62
68
  }
63
69
 
64
- function getDomain() public pure override(Service, IService) returns(ObjectType) {
70
+ function getDomain() public pure override returns(ObjectType) {
65
71
  return POOL();
66
72
  }
67
73
 
68
- /*function register(address poolAddress)
69
- external
70
- returns(NftId poolNftId)
71
- {
72
- (
73
- IComponent component,
74
- address owner,
75
- IInstance instance,
76
- NftId instanceNftId
77
- ) = _checkComponentForRegistration(
78
- poolAddress,
79
- POOL(),
80
- POOL_OWNER_ROLE());
81
-
82
- IPoolComponent pool = IPoolComponent(poolAddress);
83
- IRegistry.ObjectInfo memory registryInfo = getRegistryService().registerPool(pool, owner);
84
- pool.linkToRegisteredNftId();
85
- poolNftId = registryInfo.nftId;
86
-
87
- instance.createPoolSetup(poolNftId, pool.getSetupInfo());
88
-
89
- bytes4[][] memory selectors = new bytes4[][](2);
90
- selectors[0] = new bytes4[](1);
91
- selectors[1] = new bytes4[](1);
92
-
93
- selectors[0][0] = IPoolComponent.setFees.selector;
94
- selectors[1][0] = IPoolComponent.verifyApplication.selector;
95
-
96
- RoleId[] memory roles = new RoleId[](2);
97
- roles[0] = POOL_OWNER_ROLE();
98
- roles[1] = POLICY_SERVICE_ROLE();
99
-
100
- getInstanceService().createGifTarget(
101
- instanceNftId,
102
- poolAddress,
103
- pool.getName(),
104
- selectors,
105
- roles);
106
- }*/
107
-
108
74
  function register(address poolAddress)
109
75
  external
110
76
  returns(NftId poolNftId)
@@ -129,7 +95,7 @@ contract PoolService is
129
95
  componentInfo.tokenHandler = new TokenHandler(address(componentInfo.token));
130
96
 
131
97
  // save amended component info with instance
132
- instance.createPoolSetup(poolNftId, componentInfo);
98
+ instance.getInstanceStore().createPoolSetup(poolNftId, componentInfo);
133
99
 
134
100
  bytes4[][] memory selectors = new bytes4[][](2);
135
101
  selectors[0] = new bytes4[](1);
@@ -155,9 +121,8 @@ contract PoolService is
155
121
  external
156
122
  virtual
157
123
  {
158
- (IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
124
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
159
125
  InstanceReader instanceReader = instance.getInstanceReader();
160
- NftId poolNftId = registryInfo.nftId;
161
126
 
162
127
  IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
163
128
  IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
@@ -165,7 +130,7 @@ contract PoolService is
165
130
 
166
131
  poolInfo.maxCapitalAmount = maxCapitalAmount;
167
132
  componentInfo.data = abi.encode(poolInfo);
168
- instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
133
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
169
134
 
170
135
  emit LogPoolServiceMaxCapitalAmountUpdated(poolNftId, previousMaxCapitalAmount, maxCapitalAmount);
171
136
  }
@@ -174,9 +139,8 @@ contract PoolService is
174
139
  external
175
140
  virtual
176
141
  {
177
- (IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
142
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
178
143
  InstanceReader instanceReader = instance.getInstanceReader();
179
- NftId poolNftId = registryInfo.nftId;
180
144
 
181
145
  IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
182
146
  IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
@@ -188,7 +152,7 @@ contract PoolService is
188
152
 
189
153
  poolInfo.bundleOwnerRole = bundleOwnerRole;
190
154
  componentInfo.data = abi.encode(poolInfo);
191
- instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
155
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
192
156
 
193
157
  emit LogPoolServiceBundleOwnerRoleSet(poolNftId, bundleOwnerRole);
194
158
  }
@@ -202,9 +166,8 @@ contract PoolService is
202
166
  external
203
167
  virtual
204
168
  {
205
- (IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
169
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
206
170
  InstanceReader instanceReader = instance.getInstanceReader();
207
- NftId poolNftId = registryInfo.nftId;
208
171
 
209
172
  IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
210
173
  IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
@@ -213,8 +176,128 @@ contract PoolService is
213
176
  poolInfo.stakingFee = stakingFee;
214
177
  poolInfo.performanceFee = performanceFee;
215
178
  componentInfo.data = abi.encode(poolInfo);
216
- instance.updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
179
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
217
180
 
218
181
  // TODO add logging
219
182
  }
183
+
184
+
185
+ function createBundle(
186
+ address owner, // initial bundle owner
187
+ Fee memory fee, // fees deducted from premium that go to bundle owner
188
+ Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
189
+ Seconds lifetime, // initial duration for which new policies are covered
190
+ bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
191
+ )
192
+ external
193
+ virtual
194
+ returns(NftId bundleNftId)
195
+ {
196
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
197
+ InstanceReader instanceReader = instance.getInstanceReader();
198
+
199
+ // TODO add implementation that takes care of staking fees
200
+ Amount stakingAfterFeesAmount = stakingAmount;
201
+
202
+ bundleNftId = _bundleService.create(
203
+ instance,
204
+ poolNftId,
205
+ owner,
206
+ fee,
207
+ stakingAfterFeesAmount,
208
+ lifetime,
209
+ filter);
210
+
211
+ emit LogPoolServiceBundleCreated(instance.getNftId(), poolNftId, bundleNftId);
212
+ }
213
+
214
+
215
+ function closeBundle(NftId bundleNftId)
216
+ external
217
+ virtual
218
+ {
219
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(POOL());
220
+
221
+ // TODO book keeping for pool collateral released outside of retention level
222
+
223
+ // releasing collateral in bundle
224
+ _bundleService.close(instance, bundleNftId);
225
+
226
+ // TODO get performance fee for pool, transfer of remaining funds + bundle fees to bundle owner
227
+
228
+ emit LogPoolServiceBundleClosed(instance.getNftId(), poolNftId, bundleNftId);
229
+ }
230
+
231
+
232
+ function lockCollateral(
233
+ IInstance instance,
234
+ NftId productNftId,
235
+ NftId applicationNftId,
236
+ IPolicy.PolicyInfo memory applicationInfo,
237
+ uint256 premiumAmount // premium amount after product and distribution fees
238
+ )
239
+ external
240
+ virtual
241
+ // TODO add restricted and granting for policy service
242
+ {
243
+ InstanceReader instanceReader = instance.getInstanceReader();
244
+ NftId poolNftId = instanceReader.getProductSetupInfo(productNftId).poolNftId;
245
+ NftId bundleNftId = applicationInfo.bundleNftId;
246
+
247
+ // TODO move this check to application creation and don't repeat this here
248
+ // ensure that pool for bundle from application matches with pool for product of application
249
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
250
+ if(bundleInfo.poolNftId != poolNftId) {
251
+ revert ErrorPoolServiceBundlePoolMismatch(bundleInfo.poolNftId, poolNftId);
252
+ }
253
+
254
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
255
+ IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
256
+
257
+ // TODO add correct required collateral calculation (collateralization level mibht be != 1, retention level might be < 1)
258
+ uint256 collateralAmount = applicationInfo.sumInsuredAmount;
259
+
260
+ // TODO add correct net premium calculation (pool fee might be > 0)
261
+ uint256 premiumAfterPoolFeeAmount = premiumAmount;
262
+
263
+ // lock collateral amount from involvedd bundle
264
+ _bundleService.lockCollateral(
265
+ instance,
266
+ applicationNftId,
267
+ bundleNftId,
268
+ collateralAmount,
269
+ premiumAfterPoolFeeAmount);
270
+
271
+ // also verify/confirm application by pool if necessary
272
+ if(poolInfo.isVerifyingApplications) {
273
+ address poolAddress = getRegistry().getObjectInfo(poolNftId).objectAddress;
274
+ IPoolComponent(poolAddress).verifyApplication(
275
+ applicationNftId,
276
+ applicationInfo.applicationData,
277
+ bundleNftId,
278
+ bundleInfo.filter,
279
+ collateralAmount);
280
+ }
281
+ }
282
+
283
+
284
+ /// @dev releases the remaining collateral linked to the specified policy
285
+ /// may only be called by the policy service for unlocked pool components
286
+ function releaseCollateral(
287
+ IInstance instance,
288
+ NftId policyNftId,
289
+ IPolicy.PolicyInfo memory policyInfo
290
+ )
291
+ external
292
+ virtual
293
+ // TODO add restricted and granting for policy service
294
+ {
295
+ // release collateral from involved bundle
296
+ _bundleService.releaseCollateral(
297
+ instance,
298
+ policyNftId,
299
+ policyInfo.bundleNftId,
300
+ policyInfo.sumInsuredAmount);
301
+ }
302
+
220
303
  }