@etherisc/gif-next 0.0.2-e922e07-736 → 0.0.2-e9a637d-547

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. package/README.md +0 -71
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +68 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +68 -0
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +158 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +158 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +184 -149
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +158 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +114 -189
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +68 -0
  18. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  19. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  20. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  21. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +64 -50
  22. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  23. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +5 -0
  24. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  25. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +214 -2063
  26. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  27. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +196 -51
  28. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  29. package/artifacts/contracts/instance/Instance.sol/Instance.json +363 -2832
  30. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +491 -127
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +101 -167
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +333 -171
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +75 -23
  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 +8 -13
  42. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +85 -30
  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 +40 -10
  48. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
  50. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +56 -73
  52. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  54. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  55. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  60. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +124 -53
  62. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +21 -13
  64. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +384 -249
  66. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +74 -14
  68. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +104 -41
  70. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +11 -7
  72. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +195 -121
  74. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +51 -47
  76. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +80 -14
  78. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +212 -186
  80. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +80 -14
  82. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +101 -24
  84. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +90 -24
  86. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +511 -14
  88. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +80 -14
  90. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +136 -65
  92. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +27 -19
  94. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +561 -51
  96. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +24 -12
  98. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +114 -51
  100. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  101. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  102. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  103. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  104. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
  106. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  107. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -24
  108. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  109. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
  110. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  111. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
  112. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  113. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  114. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +17 -36
  116. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  117. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  118. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  119. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  120. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  121. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  122. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  123. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  124. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IService.sol/IService.json +80 -14
  130. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  133. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  134. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  135. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  136. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  137. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  138. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  139. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  140. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  141. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  142. package/artifacts/contracts/shared/Service.sol/Service.json +86 -15
  143. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  144. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  145. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  146. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  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 +6 -6
  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/TestVersion.sol/TestVersion.json +2 -2
  159. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  160. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  161. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  162. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  163. package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +4 -0
  164. package/artifacts/contracts/types/Amount.sol/AmountLib.json +161 -0
  165. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  167. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  171. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  173. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  174. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  175. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  176. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  177. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  178. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  179. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  182. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  185. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  186. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  187. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  189. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  192. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  193. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
  194. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  195. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  196. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  197. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  198. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  199. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  200. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  201. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  202. package/contracts/components/Component.sol +42 -10
  203. package/contracts/components/IComponent.sol +9 -1
  204. package/contracts/components/IPoolComponent.sol +5 -43
  205. package/contracts/components/Pool.sol +47 -122
  206. package/contracts/components/Product.sol +4 -0
  207. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  208. package/contracts/instance/BundleManager.sol +6 -4
  209. package/contracts/instance/Cloneable.sol +7 -2
  210. package/contracts/instance/IInstance.sol +23 -55
  211. package/contracts/instance/IInstanceService.sol +31 -6
  212. package/contracts/instance/Instance.sol +90 -182
  213. package/contracts/instance/InstanceAccessManager.sol +402 -159
  214. package/contracts/instance/InstanceReader.sol +12 -12
  215. package/contracts/instance/InstanceService.sol +287 -246
  216. package/contracts/instance/InstanceStore.sol +219 -0
  217. package/contracts/instance/ObjectManager.sol +6 -8
  218. package/contracts/instance/base/ComponentService.sol +17 -30
  219. package/contracts/instance/base/KeyValueStore.sol +13 -5
  220. package/contracts/instance/base/Lifecycle.sol +11 -2
  221. package/contracts/instance/module/IAccess.sol +21 -14
  222. package/contracts/instance/module/IBundle.sol +6 -4
  223. package/contracts/instance/module/IComponents.sol +41 -0
  224. package/contracts/instance/module/ISetup.sol +3 -16
  225. package/contracts/instance/service/ApplicationService.sol +18 -16
  226. package/contracts/instance/service/BundleService.sol +213 -81
  227. package/contracts/instance/service/ClaimService.sol +3 -3
  228. package/contracts/instance/service/DistributionService.sol +57 -70
  229. package/contracts/instance/service/IBundleService.sol +63 -25
  230. package/contracts/instance/service/IDistributionService.sol +1 -0
  231. package/contracts/instance/service/IPoolService.sol +82 -3
  232. package/contracts/instance/service/PolicyService.sol +68 -100
  233. package/contracts/instance/service/PoolService.sol +214 -20
  234. package/contracts/instance/service/ProductService.sol +34 -58
  235. package/contracts/registry/ChainNft.sol +8 -0
  236. package/contracts/registry/IRegistry.sol +2 -0
  237. package/contracts/registry/IRegistryService.sol +4 -3
  238. package/contracts/registry/ITransferInterceptor.sol +1 -0
  239. package/contracts/registry/Registry.sol +23 -20
  240. package/contracts/registry/RegistryService.sol +10 -11
  241. package/contracts/registry/ReleaseManager.sol +20 -18
  242. package/contracts/shared/IService.sol +4 -6
  243. package/contracts/shared/Service.sol +21 -7
  244. package/contracts/shared/TokenHandler.sol +11 -5
  245. package/contracts/test/TestService.sol +1 -1
  246. package/contracts/types/Amount.sol +60 -0
  247. package/contracts/types/Blocknumber.sol +1 -0
  248. package/contracts/types/Fee.sol +13 -5
  249. package/contracts/types/NftId.sol +8 -0
  250. package/contracts/types/ObjectType.sol +1 -0
  251. package/contracts/types/RoleId.sol +6 -4
  252. package/contracts/types/StateId.sol +1 -0
  253. package/contracts/types/Timestamp.sol +1 -0
  254. package/contracts/types/UFixed.sol +1 -0
  255. package/contracts/types/Version.sol +1 -0
  256. package/package.json +1 -1
@@ -3,9 +3,12 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
5
  import {Product} from "../../components/Product.sol";
6
- import {IPoolComponent} from "../../components/IPoolComponent.sol";
6
+ import {IComponents} from "../module/IComponents.sol";
7
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
7
8
  import {IInstance} from "../IInstance.sol";
8
9
  import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
11
+ import {IRisk} from "../module/IRisk.sol";
9
12
  import {IBundle} from "../module/IBundle.sol";
10
13
  import {ISetup} from "../module/ISetup.sol";
11
14
 
@@ -17,6 +20,7 @@ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE} fr
17
20
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
18
21
  import {NftId, NftIdLib} from "../../types/NftId.sol";
19
22
  import {StateId} from "../../types/StateId.sol";
23
+ import {VersionPart} from "../../types/Version.sol";
20
24
 
21
25
  import {ComponentService} from "../base/ComponentService.sol";
22
26
  import {IApplicationService} from "./IApplicationService.sol";
@@ -55,56 +59,54 @@ contract PolicyService is
55
59
  address initialOwner;
56
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
57
61
 
58
- initializeService(registryAddress, owner);
62
+ initializeService(registryAddress, address(0), owner);
59
63
 
60
- _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
61
- _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
62
- _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), getMajorVersion()));
63
- _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), getMajorVersion()));
64
+ VersionPart majorVersion = getVersion().toMajorPart();
65
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion));
66
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), majorVersion));
67
+ _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
68
+ _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
64
69
 
65
70
  registerInterface(type(IPolicyService).interfaceId);
66
71
  }
67
72
 
68
73
 
69
- function getDomain() public pure override(IService, Service) returns(ObjectType) {
74
+ function getDomain() public pure override returns(ObjectType) {
70
75
  return POLICY();
71
76
  }
72
77
 
73
78
 
74
79
  function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
75
80
  IRegistry.ObjectInfo memory productInfo;
76
- (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
81
+ (, productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
77
82
  product = Product(productInfo.objectAddress);
78
83
  }
79
84
 
80
- function _getAndVerifyUnderwritingSetup(
81
- IInstance instance,
82
- InstanceReader instanceReader,
83
- IPolicy.PolicyInfo memory policyInfo,
84
- ISetup.ProductSetupInfo memory productSetupInfo
85
- )
86
- internal
87
- view
88
- returns (
89
- NftId poolNftId,
90
- NftId bundleNftId,
91
- IBundle.BundleInfo memory bundleInfo,
92
- uint256 collateralAmount
93
- )
94
- {
95
- // check match between policy and bundle (via pool)
96
- poolNftId = productSetupInfo.poolNftId;
97
- bundleNftId = policyInfo.bundleNftId;
98
- bundleInfo = instanceReader.getBundleInfo(bundleNftId);
99
- require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
100
-
101
- // calculate required collateral
102
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
103
-
104
- // obtain remaining return values
105
- // TODO required collateral amount should be calculated by pool service, not policy service
106
- collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
107
- }
85
+ // function _getAndVerifyUnderwritingSetup(
86
+ // IInstance instance,
87
+ // InstanceReader instanceReader,
88
+ // IPolicy.PolicyInfo memory policyInfo,
89
+ // ISetup.ProductSetupInfo memory productSetupInfo
90
+ // )
91
+ // internal
92
+ // view
93
+ // returns (
94
+ // NftId poolNftId,
95
+ // IComponents.PoolInfo memory poolInfo,
96
+ // NftId bundleNftId,
97
+ // IBundle.BundleInfo memory bundleInfo
98
+ // )
99
+ // {
100
+ // // check match between policy and bundle (via pool)
101
+ // poolNftId = productSetupInfo.poolNftId;
102
+ // bundleNftId = policyInfo.bundleNftId;
103
+ // bundleInfo = instanceReader.getBundleInfo(bundleNftId);
104
+ // require(bundleInfo.poolNftId == poolNftId, "BUNDLE_POOL_MISMATCH");
105
+
106
+ // // calculate required collateral
107
+ // IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
108
+ // poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
109
+ // }
108
110
 
109
111
 
110
112
  function decline(
@@ -127,42 +129,23 @@ contract PolicyService is
127
129
  virtual override
128
130
  {
129
131
  // check caller is registered product
130
- IInstance instance;
131
- InstanceReader instanceReader;
132
- NftId productNftId;
133
- {
134
- IRegistry.ObjectInfo memory productInfo;
135
- (productInfo, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
136
- instanceReader = instance.getInstanceReader();
137
- productNftId = productInfo.nftId;
138
- }
132
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
133
+ InstanceReader instanceReader = instance.getInstanceReader();
139
134
 
140
135
  // check policy matches with calling product
141
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(applicationNftId);
142
- require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
136
+ IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
137
+ require(applicationInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
143
138
 
144
139
  // check policy is in state applied
145
140
  require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
146
141
 
147
- (
148
- NftId poolNftId,
149
- NftId bundleNftId,
150
- IBundle.BundleInfo memory bundleInfo,
151
- uint256 collateralAmount
152
- ) = _getAndVerifyUnderwritingSetup(
153
- instance,
154
- instanceReader,
155
- policyInfo,
156
- instanceReader.getProductSetupInfo(productNftId)
157
- );
158
-
159
142
  StateId newPolicyState = UNDERWRITTEN();
160
143
 
161
144
  // optional activation of policy
162
145
  if(activateAt > zeroTimestamp()) {
163
146
  newPolicyState = ACTIVE();
164
- policyInfo.activatedAt = activateAt;
165
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
147
+ applicationInfo.activatedAt = activateAt;
148
+ applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
166
149
  }
167
150
 
168
151
  // lock bundle collateral
@@ -173,43 +156,25 @@ contract PolicyService is
173
156
  netPremiumAmount = _processPremiumByTreasury(
174
157
  instance,
175
158
  applicationNftId,
176
- policyInfo.premiumAmount);
159
+ applicationInfo.premiumAmount);
177
160
 
178
- policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
161
+ applicationInfo.premiumPaidAmount += applicationInfo.premiumAmount;
179
162
  }
180
163
 
181
- // lock collateral and update bundle book keeping
182
- // TODO introduct indirection via pool service?
183
- // well pool would only need to be involved when a part of the collateral
184
- // is provided by a "re insurance policy" of the pool
185
- // but then again the policiy would likely best be attached to the bundle. really? why?
186
- // retention level: fraction of sum insured that product will cover from pool funds directly
164
+ // store updated policy info
165
+ instance.getInstanceStore().updatePolicy(applicationNftId, applicationInfo, newPolicyState);
166
+
167
+ // lock collateral and update pool and bundle book keeping
168
+ // pool retention level: fraction of sum insured that product will cover from pool funds directly
187
169
  // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
188
170
  // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
189
- // open points:
190
- // - do we need a link of a bundle to this policy or is it enough to know that the pool has an active policy?
191
- // - when to buy such policies and for which amount? manual trigger or link to bundle creation and/or funding?
192
- bundleInfo = _bundleService.lockCollateral(
171
+ // might also call pool component (for isVerifyingApplications pools)
172
+ _poolService.lockCollateral(
193
173
  instance,
174
+ productNftId,
194
175
  applicationNftId,
195
- bundleNftId,
196
- collateralAmount,
197
- netPremiumAmount);
198
-
199
- instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
200
-
201
- // also verify/confirm application by pool if necessary
202
- if(instanceReader.getPoolSetupInfo(poolNftId).isVerifyingApplications) {
203
- IPoolComponent pool = IPoolComponent(
204
- getRegistry().getObjectInfo(poolNftId).objectAddress);
205
-
206
- pool.verifyApplication(
207
- applicationNftId,
208
- policyInfo.applicationData,
209
- bundleNftId,
210
- bundleInfo.filter,
211
- collateralAmount);
212
- }
176
+ applicationInfo,
177
+ netPremiumAmount); // for pool book keeping (fee + additional capital)
213
178
 
214
179
  // TODO: add logging
215
180
  }
@@ -223,7 +188,7 @@ contract PolicyService is
223
188
 
224
189
  function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
225
190
  // check caller is registered product
226
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
191
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
227
192
  InstanceReader instanceReader = instance.getInstanceReader();
228
193
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
229
194
 
@@ -241,7 +206,7 @@ contract PolicyService is
241
206
  policyInfo.premiumPaidAmount += unpaidPremiumAmount;
242
207
 
243
208
  _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
244
- instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
209
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
245
210
 
246
211
  if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
247
212
  activate(policyNftId, activateAt);
@@ -252,7 +217,7 @@ contract PolicyService is
252
217
 
253
218
  function activate(NftId policyNftId, Timestamp activateAt) public override {
254
219
  // check caller is registered product
255
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
220
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
256
221
  InstanceReader instanceReader = instance.getInstanceReader();
257
222
 
258
223
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -264,7 +229,7 @@ contract PolicyService is
264
229
  policyInfo.activatedAt = activateAt;
265
230
  policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
266
231
 
267
- instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
232
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, ACTIVE());
268
233
 
269
234
  // TODO: add logging
270
235
  }
@@ -286,7 +251,7 @@ contract PolicyService is
286
251
  external
287
252
  override
288
253
  {
289
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
254
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
290
255
  InstanceReader instanceReader = instance.getInstanceReader();
291
256
 
292
257
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -318,8 +283,12 @@ contract PolicyService is
318
283
 
319
284
  policyInfo.closedAt = TimestampLib.blockTimestamp();
320
285
 
321
- _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
322
- instance.updatePolicy(policyNftId, policyInfo, CLOSED());
286
+ _poolService.releaseCollateral(
287
+ instance,
288
+ policyNftId,
289
+ policyInfo);
290
+
291
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
323
292
  }
324
293
 
325
294
  function _getPoolNftId(
@@ -351,8 +320,7 @@ contract PolicyService is
351
320
  IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
352
321
  TokenHandler tokenHandler = productSetupInfo.tokenHandler;
353
322
  address policyOwner = getRegistry().ownerOf(policyNftId);
354
- ISetup.PoolSetupInfo memory poolSetupInfo = instance.getInstanceReader().getPoolSetupInfo(productSetupInfo.poolNftId);
355
- address poolWallet = poolSetupInfo.wallet;
323
+ address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
356
324
  IPolicy.Premium memory premium = _applicationService.calculatePremium(
357
325
  productNftId,
358
326
  policyInfo.riskId,
@@ -6,25 +6,30 @@ import {IRegistry} from "../../registry/IRegistry.sol";
6
6
  import {IInstance} from "../../instance/IInstance.sol";
7
7
  import {IBundle} from "../../instance/module/IBundle.sol";
8
8
  import {TokenHandler} from "../../instance/module/ITreasury.sol";
9
- import {ISetup} from "../module/ISetup.sol";
9
+ import {IComponents} from "../module/IComponents.sol";
10
10
  import {IPolicy} from "../module/IPolicy.sol";
11
11
 
12
12
  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";
17
+ import {Fee, FeeLib} from "../../types/Fee.sol";
16
18
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
17
19
  import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
18
- import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
20
+ import {PUBLIC_ROLE, POOL_OWNER_ROLE, POLICY_SERVICE_ROLE, RoleId} from "../../types/RoleId.sol";
19
21
  import {Fee, FeeLib} from "../../types/Fee.sol";
20
22
  import {Version, VersionLib} from "../../types/Version.sol";
21
23
  import {KEEP_STATE, StateId} from "../../types/StateId.sol";
24
+ import {Seconds} from "../../types/Seconds.sol";
22
25
  import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
26
+ import {Version, VersionLib} from "../../types/Version.sol";
23
27
 
24
28
  import {IService} from "../../shared/IService.sol";
25
29
  import {Service} from "../../shared/Service.sol";
26
30
  import {BundleManager} from "../BundleManager.sol";
27
31
  import {ComponentService} from "../base/ComponentService.sol";
32
+ import {IBundleService} from "./IBundleService.sol";
28
33
  import {IPoolService} from "./IPoolService.sol";
29
34
  import {IRegistryService} from "../../registry/IRegistryService.sol";
30
35
  import {InstanceService} from "../InstanceService.sol";
@@ -40,7 +45,7 @@ contract PoolService is
40
45
  {
41
46
  using NftIdLib for NftId;
42
47
 
43
- address internal _registryAddress;
48
+ IBundleService internal _bundleService;
44
49
 
45
50
  function _initialize(
46
51
  address owner,
@@ -55,11 +60,14 @@ contract PoolService is
55
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
56
61
  // TODO while PoolService is not deployed in PoolServiceManager constructor
57
62
  // owner is PoolServiceManager deployer
58
- initializeService(registryAddress, owner);
63
+ initializeService(registryAddress, address(0), owner);
64
+
65
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getVersion().toMajorPart()));
66
+
59
67
  registerInterface(type(IPoolService).interfaceId);
60
68
  }
61
69
 
62
- function getDomain() public pure override(Service, IService) returns(ObjectType) {
70
+ function getDomain() public pure override returns(ObjectType) {
63
71
  return POOL();
64
72
  }
65
73
 
@@ -78,32 +86,218 @@ contract PoolService is
78
86
  POOL_OWNER_ROLE());
79
87
 
80
88
  IPoolComponent pool = IPoolComponent(poolAddress);
81
- IRegistry.ObjectInfo memory poolInfo = getRegistryService().registerPool(pool, owner);
89
+ IRegistry.ObjectInfo memory registryInfo = getRegistryService().registerPool(pool, owner);
82
90
  pool.linkToRegisteredNftId();
83
- poolNftId = poolInfo.nftId;
91
+ poolNftId = registryInfo.nftId;
92
+
93
+ // amend component info with pool specific token handler
94
+ IComponents.ComponentInfo memory componentInfo = pool.getComponentInfo();
95
+ componentInfo.tokenHandler = new TokenHandler(address(componentInfo.token));
96
+
97
+ // save amended component info with instance
98
+ instance.getInstanceStore().createPoolSetup(poolNftId, componentInfo);
99
+
100
+ bytes4[][] memory selectors = new bytes4[][](2);
101
+ selectors[0] = new bytes4[](1);
102
+ selectors[1] = new bytes4[](1);
103
+
104
+ selectors[0][0] = IPoolComponent.setFees.selector;
105
+ selectors[1][0] = IPoolComponent.verifyApplication.selector;
106
+
107
+ RoleId[] memory roles = new RoleId[](2);
108
+ roles[0] = POOL_OWNER_ROLE();
109
+ roles[1] = POLICY_SERVICE_ROLE();
110
+
111
+ getInstanceService().createGifTarget(
112
+ instanceNftId,
113
+ poolAddress,
114
+ pool.getName(),
115
+ selectors,
116
+ roles);
117
+ }
118
+
119
+
120
+ function setMaxCapitalAmount(uint256 maxCapitalAmount)
121
+ external
122
+ virtual
123
+ {
124
+ (NftId poolNftId, IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
125
+ InstanceReader instanceReader = instance.getInstanceReader();
126
+
127
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
128
+ IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
129
+ uint256 previousMaxCapitalAmount = poolInfo.maxCapitalAmount;
130
+
131
+ poolInfo.maxCapitalAmount = maxCapitalAmount;
132
+ componentInfo.data = abi.encode(poolInfo);
133
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
84
134
 
85
- instance.createPoolSetup(poolNftId, pool.getSetupInfo());
86
- getInstanceService().createGifTarget(instanceNftId, poolAddress, pool.getName());
87
- getInstanceService().grantPoolDefaultPermissions(instanceNftId, poolAddress, pool.getName());
135
+ emit LogPoolServiceMaxCapitalAmountUpdated(poolNftId, previousMaxCapitalAmount, maxCapitalAmount);
88
136
  }
89
137
 
138
+ function setBundleOwnerRole(RoleId bundleOwnerRole)
139
+ external
140
+ virtual
141
+ {
142
+ (NftId poolNftId, IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
143
+ InstanceReader instanceReader = instance.getInstanceReader();
144
+
145
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
146
+ IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
147
+
148
+ // bundle owner role may only be set once per pool
149
+ if(poolInfo.bundleOwnerRole != PUBLIC_ROLE()) {
150
+ revert ErrorPoolServiceBundleOwnerRoleAlreadySet(poolNftId);
151
+ }
152
+
153
+ poolInfo.bundleOwnerRole = bundleOwnerRole;
154
+ componentInfo.data = abi.encode(poolInfo);
155
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
156
+
157
+ emit LogPoolServiceBundleOwnerRoleSet(poolNftId, bundleOwnerRole);
158
+ }
159
+
160
+
90
161
  function setFees(
91
162
  Fee memory poolFee,
92
163
  Fee memory stakingFee,
93
164
  Fee memory performanceFee
94
165
  )
95
166
  external
96
- override
167
+ virtual
97
168
  {
98
- (IRegistry.ObjectInfo memory poolInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
169
+ (NftId poolNftId, IRegistry.ObjectInfo memory registryInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
99
170
  InstanceReader instanceReader = instance.getInstanceReader();
100
- NftId poolNftId = poolInfo.nftId;
101
-
102
- ISetup.PoolSetupInfo memory poolSetupInfo = instanceReader.getPoolSetupInfo(poolNftId);
103
- poolSetupInfo.poolFee = poolFee;
104
- poolSetupInfo.stakingFee = stakingFee;
105
- poolSetupInfo.performanceFee = performanceFee;
106
-
107
- instance.updatePoolSetup(poolNftId, poolSetupInfo, KEEP_STATE());
171
+
172
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
173
+ IComponents.PoolInfo memory poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
174
+
175
+ poolInfo.poolFee = poolFee;
176
+ poolInfo.stakingFee = stakingFee;
177
+ poolInfo.performanceFee = performanceFee;
178
+ componentInfo.data = abi.encode(poolInfo);
179
+ instance.getInstanceStore().updatePoolSetup(poolNftId, componentInfo, KEEP_STATE());
180
+
181
+ // TODO add logging
108
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) = _getAndVerifyComponentInfoAndInstance(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) = _getAndVerifyComponentInfoAndInstance(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
+
109
303
  }