@etherisc/gif-next 0.0.2-93de5de-423 → 0.0.2-94237b7-984

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 (264) 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 +78 -89
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +123 -183
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +156 -64
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +169 -143
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +353 -176
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +162 -138
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +299 -245
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +83 -162
  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 +199 -316
  26. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  27. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +185 -50
  28. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  29. package/artifacts/contracts/instance/Instance.sol/Instance.json +288 -387
  30. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +472 -126
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +137 -234
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +313 -169
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +71 -23
  38. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  39. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +8 -13
  40. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +86 -20
  42. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +40 -10
  46. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
  48. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +56 -73
  50. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  52. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  53. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  58. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +261 -80
  60. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +41 -25
  62. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +387 -241
  64. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +74 -14
  66. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +105 -31
  68. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +11 -7
  70. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +933 -70
  72. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +142 -14
  74. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +200 -40
  76. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +220 -183
  78. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +90 -13
  80. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +630 -20
  82. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +103 -69
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +521 -13
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +90 -13
  88. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +150 -167
  90. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +27 -47
  92. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +562 -41
  94. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +24 -12
  96. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +115 -41
  98. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  100. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  103. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
  104. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -13
  106. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  107. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
  108. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
  110. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  112. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  113. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +18 -26
  114. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  116. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  117. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  118. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  119. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  120. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  121. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  122. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  124. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.json +90 -13
  128. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  131. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  132. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +3 -3
  137. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  138. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  139. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Service.sol/Service.json +97 -15
  141. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  142. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  143. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  144. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  145. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  147. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  148. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +3 -3
  150. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +6 -6
  152. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestService.sol/TestService.json +112 -26
  154. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  155. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  157. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  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/Blocknumber.sol/BlocknumberLib.json +2 -2
  165. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  169. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  171. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  173. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  175. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  176. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  177. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  178. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  179. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  180. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
  183. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  185. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  186. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  187. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  188. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  189. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  191. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +25 -7
  193. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  194. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  195. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  196. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  197. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  198. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  199. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  200. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  201. package/contracts/components/Component.sol +99 -87
  202. package/contracts/components/Distribution.sol +16 -44
  203. package/contracts/components/IComponent.sol +40 -18
  204. package/contracts/components/IDistributionComponent.sol +1 -30
  205. package/contracts/components/IPoolComponent.sol +73 -47
  206. package/contracts/components/IProductComponent.sol +3 -2
  207. package/contracts/components/Pool.sol +177 -128
  208. package/contracts/components/Product.sol +26 -18
  209. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  210. package/contracts/instance/BundleManager.sol +7 -5
  211. package/contracts/instance/Cloneable.sol +7 -2
  212. package/contracts/instance/IInstance.sol +16 -10
  213. package/contracts/instance/IInstanceService.sol +18 -5
  214. package/contracts/instance/Instance.sol +45 -9
  215. package/contracts/instance/InstanceAccessManager.sol +388 -158
  216. package/contracts/instance/InstanceReader.sol +8 -10
  217. package/contracts/instance/InstanceService.sol +184 -165
  218. package/contracts/instance/ObjectManager.sol +6 -8
  219. package/contracts/instance/base/ComponentService.sol +17 -30
  220. package/contracts/instance/base/KeyValueStore.sol +13 -5
  221. package/contracts/instance/base/Lifecycle.sol +11 -2
  222. package/contracts/instance/module/IAccess.sol +21 -14
  223. package/contracts/instance/module/IBundle.sol +8 -5
  224. package/contracts/instance/module/IComponents.sol +41 -0
  225. package/contracts/instance/module/IDistribution.sol +2 -0
  226. package/contracts/instance/module/IPolicy.sol +26 -1
  227. package/contracts/instance/module/ISetup.sol +7 -21
  228. package/contracts/instance/service/ApplicationService.sol +130 -48
  229. package/contracts/instance/service/BundleService.sol +213 -80
  230. package/contracts/instance/service/ClaimService.sol +3 -3
  231. package/contracts/instance/service/DistributionService.sol +212 -54
  232. package/contracts/instance/service/IApplicationService.sol +7 -7
  233. package/contracts/instance/service/IBundleService.sol +65 -26
  234. package/contracts/instance/service/IDistributionService.sol +37 -3
  235. package/contracts/instance/service/IPolicyService.sol +3 -20
  236. package/contracts/instance/service/IPoolService.sol +82 -3
  237. package/contracts/instance/service/PolicyService.sol +107 -219
  238. package/contracts/instance/service/PoolService.sol +214 -20
  239. package/contracts/instance/service/ProductService.sol +30 -53
  240. package/contracts/registry/ChainNft.sol +8 -0
  241. package/contracts/registry/IRegistry.sol +2 -0
  242. package/contracts/registry/IRegistryService.sol +4 -3
  243. package/contracts/registry/ITransferInterceptor.sol +1 -0
  244. package/contracts/registry/Registry.sol +23 -20
  245. package/contracts/registry/RegistryService.sol +15 -16
  246. package/contracts/registry/ReleaseManager.sol +20 -18
  247. package/contracts/shared/IService.sol +4 -4
  248. package/contracts/shared/Registerable.sol +2 -2
  249. package/contracts/shared/Service.sol +21 -7
  250. package/contracts/shared/TokenHandler.sol +11 -5
  251. package/contracts/test/TestService.sol +1 -1
  252. package/contracts/types/Amount.sol +60 -0
  253. package/contracts/types/Blocknumber.sol +1 -0
  254. package/contracts/types/Fee.sol +13 -5
  255. package/contracts/types/NftId.sol +8 -0
  256. package/contracts/types/ObjectType.sol +1 -0
  257. package/contracts/types/Referral.sol +4 -0
  258. package/contracts/types/RoleId.sol +13 -6
  259. package/contracts/types/Seconds.sol +54 -0
  260. package/contracts/types/StateId.sol +1 -0
  261. package/contracts/types/Timestamp.sol +13 -13
  262. package/contracts/types/UFixed.sol +1 -0
  263. package/contracts/types/Version.sol +1 -0
  264. package/package.json +1 -1
@@ -1,20 +1,99 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {NftId} from "../../types/NftId.sol";
4
+ import {Amount} from "../../types/Amount.sol";
5
5
  import {Fee} from "../../types/Fee.sol";
6
- import {StateId} from "../../types/StateId.sol";
7
- import {IService} from "../../shared/IService.sol";
6
+ import {NftId} from "../../types/NftId.sol";
8
7
  import {IBundle} from "../module/IBundle.sol";
9
8
  import {IInstance} from "../../instance/IInstance.sol";
9
+ import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IService} from "../../shared/IService.sol";
11
+ import {RoleId} from "../../types/RoleId.sol";
12
+ import {Seconds} from "../../types/Seconds.sol";
13
+ import {StateId} from "../../types/StateId.sol";
10
14
 
11
15
  interface IPoolService is IService {
12
16
 
17
+ event LogPoolServiceMaxCapitalAmountUpdated(NftId poolNftId, uint256 previousMaxCapitalAmount, uint256 currentMaxCapitalAmount);
18
+ event LogPoolServiceBundleOwnerRoleSet(NftId poolNftId, RoleId bundleOwnerRole);
19
+
20
+ event LogPoolServiceBundleCreated(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
21
+ event LogPoolServiceBundleClosed(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
22
+
23
+ error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
24
+ error ErrorPoolServiceBundlePoolMismatch(NftId bundlePoolNftId, NftId productPoolNftId);
25
+
26
+ /// @dev registers a new pool with the registry service
13
27
  function register(address poolAddress) external returns(NftId);
14
28
 
29
+ /// @dev defines the required role for bundle owners for the calling pool
30
+ /// default implementation returns PUBLIC ROLE
31
+ function setBundleOwnerRole(RoleId bundleOwnerRole) external;
32
+
33
+ /// @dev sets the max capital amount for the calling pool
34
+ function setMaxCapitalAmount(uint256 maxCapitalAmount) external;
35
+
36
+ /// @dev set pool sepecific fees
15
37
  function setFees(
16
38
  Fee memory poolFee,
17
39
  Fee memory stakingFee,
18
40
  Fee memory performanceFee
19
41
  ) external;
42
+
43
+
44
+ /// @dev locks required collateral to cover the specified application (and turn it into a policy)
45
+ /// - retention level == 1: the full collateral amount will be locked by the specified bundle
46
+ /// - retention level < 1: a part of the coverage is provided by the specified bundle, the rest by the pool component
47
+ /// in which case the pool component might hold a re-insurance policy
48
+ /// may only be called by the policy service for unlocked pool components
49
+ function lockCollateral(
50
+ IInstance instance,
51
+ NftId productNftId,
52
+ NftId applicationNftId,
53
+ IPolicy.PolicyInfo memory applicationInfo,
54
+ uint256 premiumAmount
55
+ ) external;
56
+
57
+
58
+ /// @dev releases the remaining collateral linked to the specified policy
59
+ /// may only be called by the policy service for unlocked pool components
60
+ function releaseCollateral(
61
+ IInstance instance,
62
+ NftId policyNftId,
63
+ IPolicy.PolicyInfo memory policyInfo
64
+ ) external;
65
+
66
+
67
+ /// @dev create a new bundle for the provided parameters
68
+ /// staking fees will be deducted by the pool service from the staking amount
69
+ /// may only be called by registered and unlocked pool components
70
+ function createBundle(
71
+ address owner, // initial bundle owner
72
+ Fee memory fee, // fees deducted from premium that go to bundle owner
73
+ Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
74
+ Seconds lifetime, // initial duration for which new policies are covered
75
+ bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
76
+ )
77
+ external
78
+ returns(NftId bundleNftId); // the nft id of the newly created bundle
79
+
80
+
81
+ /// @dev closes the specified bundle
82
+ /// only open bundles (active or locked) may be closed
83
+ /// to close a bundle it may not have any non-closed polices attached to it
84
+ /// bundle fees and remaining capital (after deduction of the performance fee) will be transferred to the bundle owner
85
+ /// may only be called by registered and unlocked pool components
86
+ function closeBundle(NftId bundleNftId) external;
87
+
88
+
89
+ /// @dev increase stakes for bundle
90
+ /// staking fees will be deducted by the pool service from the staking amount
91
+ /// may only be called by registered and unlocked pool components
92
+ // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
93
+
94
+
95
+ /// @dev decrease stakes for bundle
96
+ /// performance fees will be deducted by the pool service from the staking amount
97
+ /// may only be called by registered and unlocked pool components
98
+ // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
20
99
  }
@@ -2,43 +2,35 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
- import {IProductComponent} from "../../components/IProductComponent.sol";
6
5
  import {Product} from "../../components/Product.sol";
7
- import {IPoolComponent} from "../../components/IPoolComponent.sol";
6
+ import {IComponents} from "../module/IComponents.sol";
8
7
  import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
8
  import {IInstance} from "../IInstance.sol";
10
9
  import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
11
11
  import {IRisk} from "../module/IRisk.sol";
12
12
  import {IBundle} from "../module/IBundle.sol";
13
- import {IProductService} from "./IProductService.sol";
14
- import {ITreasury} from "../module/ITreasury.sol";
15
13
  import {ISetup} from "../module/ISetup.sol";
16
14
 
17
15
  import {TokenHandler} from "../../shared/TokenHandler.sol";
18
16
 
19
- import {IVersionable} from "../../shared/IVersionable.sol";
20
- import {Versionable} from "../../shared/Versionable.sol";
21
-
22
17
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
23
18
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
24
- import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
25
- import {ObjectType, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
19
+ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
26
20
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
27
- import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
28
- import {Fee, FeeLib} from "../../types/Fee.sol";
29
- import {ReferralId} from "../../types/Referral.sol";
30
- import {RiskId} from "../../types/RiskId.sol";
21
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
31
22
  import {StateId} from "../../types/StateId.sol";
32
- import {Version, VersionLib} from "../../types/Version.sol";
33
- //import {RoleId, PRODUCT_OWNER_ROLE} from "../../types/RoleId.sol";
23
+ import {VersionPart} from "../../types/Version.sol";
34
24
 
35
- import {IService} from "../../shared/IService.sol";
36
- import {Service} from "../../shared/Service.sol";
37
25
  import {ComponentService} from "../base/ComponentService.sol";
38
- import {IPolicyService} from "./IPolicyService.sol";
26
+ import {IApplicationService} from "./IApplicationService.sol";
27
+ import {IBundleService} from "./IBundleService.sol";
28
+ import {IDistributionService} from "./IDistributionService.sol";
39
29
  import {InstanceReader} from "../InstanceReader.sol";
30
+ import {IPolicyService} from "./IPolicyService.sol";
40
31
  import {IPoolService} from "./IPoolService.sol";
41
- import {IBundleService} from "./IBundleService.sol";
32
+ import {IService} from "../../shared/IService.sol";
33
+ import {Service} from "../../shared/Service.sol";
42
34
 
43
35
 
44
36
  contract PolicyService is
@@ -50,6 +42,8 @@ contract PolicyService is
50
42
 
51
43
  IPoolService internal _poolService;
52
44
  IBundleService internal _bundleService;
45
+ IApplicationService internal _applicationService;
46
+ IDistributionService internal _distributionService;
53
47
 
54
48
  event LogProductServiceSender(address sender);
55
49
 
@@ -65,141 +59,54 @@ contract PolicyService is
65
59
  address initialOwner;
66
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
67
61
 
68
- initializeService(registryAddress, owner);
62
+ initializeService(registryAddress, address(0), owner);
69
63
 
70
- _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
71
- _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), 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));
72
69
 
73
70
  registerInterface(type(IPolicyService).interfaceId);
74
71
  }
75
72
 
76
73
 
77
- function getDomain() public pure override(IService, Service) returns(ObjectType) {
74
+ function getDomain() public pure override returns(ObjectType) {
78
75
  return POLICY();
79
76
  }
80
77
 
81
78
 
82
79
  function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
83
80
  IRegistry.ObjectInfo memory productInfo;
84
- (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
81
+ (, productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
85
82
  product = Product(productInfo.objectAddress);
86
83
  }
87
84
 
88
- // TODO: no access restrictions
89
- function calculatePremium(
90
- RiskId riskId,
91
- uint256 sumInsuredAmount,
92
- uint256 lifetime,
93
- bytes memory applicationData,
94
- NftId bundleNftId,
95
- ReferralId referralId
96
- )
97
- public
98
- view
99
- virtual override
100
- returns (
101
- uint256 premiumAmount,
102
- uint256 productFeeAmount,
103
- uint256 poolFeeAmount,
104
- uint256 bundleFeeAmount,
105
- uint256 distributionFeeAmount
106
- )
107
- {
108
- Product product = _getAndVerifyInstanceAndProduct();
109
- uint256 netPremiumAmount = product.calculateNetPremium(
110
- sumInsuredAmount,
111
- riskId,
112
- lifetime,
113
- applicationData
114
- );
115
-
116
- (
117
- productFeeAmount,
118
- poolFeeAmount,
119
- bundleFeeAmount,
120
- distributionFeeAmount
121
- ) = _calculateFeeAmounts(
122
- netPremiumAmount,
123
- product,
124
- bundleNftId,
125
- referralId
126
- );
127
-
128
- premiumAmount = netPremiumAmount + productFeeAmount;
129
- premiumAmount += poolFeeAmount + bundleFeeAmount;
130
- premiumAmount += distributionFeeAmount;
131
- }
132
-
133
- function _calculateFeeAmounts(
134
- uint256 netPremiumAmount,
135
- Product product,
136
- NftId bundleNftId,
137
- ReferralId referralId
138
- )
139
- internal
140
- view
141
- returns (
142
- uint256 productFeeAmount,
143
- uint256 poolFeeAmount,
144
- uint256 bundleFeeAmount,
145
- uint256 distributionFeeAmount
146
- )
147
- {
148
- InstanceReader instanceReader;
149
- {
150
- IInstance instance = product.getInstance();
151
- instanceReader = instance.getInstanceReader();
152
- }
153
-
154
- NftId poolNftId = product.getPoolNftId();
155
- IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
156
- require(bundleInfo.poolNftId == poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
157
-
158
- {
159
- ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(product.getProductNftId());
160
- (productFeeAmount,) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
161
- }
162
- {
163
- ISetup.PoolSetupInfo memory poolSetupInfo = instanceReader.getPoolSetupInfo(poolNftId);
164
- (poolFeeAmount,) = FeeLib.calculateFee(poolSetupInfo.poolFee, netPremiumAmount);
165
- }
166
- {
167
- NftId distributionNftId = product.getDistributionNftId();
168
- ISetup.DistributionSetupInfo memory distributionSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
169
- (distributionFeeAmount,) = FeeLib.calculateFee(distributionSetupInfo.distributionFee, netPremiumAmount);
170
- }
171
-
172
- (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
173
- }
174
-
175
- function _getAndVerifyUnderwritingSetup(
176
- IInstance instance,
177
- InstanceReader instanceReader,
178
- IPolicy.PolicyInfo memory policyInfo,
179
- ISetup.ProductSetupInfo memory productSetupInfo
180
- )
181
- internal
182
- view
183
- returns (
184
- NftId poolNftId,
185
- NftId bundleNftId,
186
- IBundle.BundleInfo memory bundleInfo,
187
- uint256 collateralAmount
188
- )
189
- {
190
- // check match between policy and bundle (via pool)
191
- poolNftId = productSetupInfo.poolNftId;
192
- bundleNftId = policyInfo.bundleNftId;
193
- bundleInfo = instanceReader.getBundleInfo(bundleNftId);
194
- require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
195
-
196
- // calculate required collateral
197
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
198
-
199
- // obtain remaining return values
200
- // TODO required collateral amount should be calculated by pool service, not policy service
201
- collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
202
- }
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
+ // }
203
110
 
204
111
 
205
112
  function decline(
@@ -222,42 +129,23 @@ contract PolicyService is
222
129
  virtual override
223
130
  {
224
131
  // check caller is registered product
225
- IInstance instance;
226
- InstanceReader instanceReader;
227
- NftId productNftId;
228
- {
229
- IRegistry.ObjectInfo memory productInfo;
230
- (productInfo, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
231
- instanceReader = instance.getInstanceReader();
232
- productNftId = productInfo.nftId;
233
- }
132
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
133
+ InstanceReader instanceReader = instance.getInstanceReader();
234
134
 
235
135
  // check policy matches with calling product
236
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(applicationNftId);
237
- require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
136
+ IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
137
+ require(applicationInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
238
138
 
239
139
  // check policy is in state applied
240
140
  require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
241
141
 
242
- (
243
- NftId poolNftId,
244
- NftId bundleNftId,
245
- IBundle.BundleInfo memory bundleInfo,
246
- uint256 collateralAmount
247
- ) = _getAndVerifyUnderwritingSetup(
248
- instance,
249
- instanceReader,
250
- policyInfo,
251
- instanceReader.getProductSetupInfo(productNftId)
252
- );
253
-
254
142
  StateId newPolicyState = UNDERWRITTEN();
255
143
 
256
144
  // optional activation of policy
257
145
  if(activateAt > zeroTimestamp()) {
258
146
  newPolicyState = ACTIVE();
259
- policyInfo.activatedAt = activateAt;
260
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
147
+ applicationInfo.activatedAt = activateAt;
148
+ applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
261
149
  }
262
150
 
263
151
  // lock bundle collateral
@@ -267,44 +155,26 @@ contract PolicyService is
267
155
  if(requirePremiumPayment) {
268
156
  netPremiumAmount = _processPremiumByTreasury(
269
157
  instance,
270
- productNftId,
271
158
  applicationNftId,
272
- policyInfo.premiumAmount);
159
+ applicationInfo.premiumAmount);
273
160
 
274
- policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
161
+ applicationInfo.premiumPaidAmount += applicationInfo.premiumAmount;
275
162
  }
276
163
 
277
- // lock collateral and update bundle book keeping
278
- // TODO introduct indirection via pool service?
279
- // well pool would only need to be involved when a part of the collateral
280
- // is provided by a "re insurance policy" of the pool
281
- // but then again the policiy would likely best be attached to the bundle. really? why?
282
- // retention level: fraction of sum insured that product will cover from pool funds directly
164
+ // store updated policy info
165
+ instance.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
283
169
  // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
284
170
  // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
285
- // open points:
286
- // - do we need a link of a bundle to this policy or is it enough to know that the pool has an active policy?
287
- // - when to buy such policies and for which amount? manual trigger or link to bundle creation and/or funding?
288
- bundleInfo = _bundleService.lockCollateral(
171
+ // might also call pool component (for isVerifyingApplications pools)
172
+ _poolService.lockCollateral(
289
173
  instance,
174
+ productNftId,
290
175
  applicationNftId,
291
- bundleNftId,
292
- collateralAmount,
293
- netPremiumAmount);
294
-
295
- instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
296
-
297
- // also verify/confirm application by pool if necessary
298
- if(instanceReader.getPoolSetupInfo(poolNftId).isVerifyingApplications) {
299
- IPoolComponent pool = IPoolComponent(
300
- getRegistry().getObjectInfo(poolNftId).objectAddress);
301
-
302
- pool.verifyApplication(
303
- applicationNftId,
304
- policyInfo.applicationData,
305
- bundleInfo.filter,
306
- collateralAmount);
307
- }
176
+ applicationInfo,
177
+ netPremiumAmount); // for pool book keeping (fee + additional capital)
308
178
 
309
179
  // TODO: add logging
310
180
  }
@@ -318,7 +188,7 @@ contract PolicyService is
318
188
 
319
189
  function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
320
190
  // check caller is registered product
321
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
191
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
322
192
  InstanceReader instanceReader = instance.getInstanceReader();
323
193
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
324
194
 
@@ -330,7 +200,6 @@ contract PolicyService is
330
200
 
331
201
  uint256 netPremiumAmount = _processPremiumByTreasury(
332
202
  instance,
333
- productInfo.nftId,
334
203
  policyNftId,
335
204
  unpaidPremiumAmount);
336
205
 
@@ -348,7 +217,7 @@ contract PolicyService is
348
217
 
349
218
  function activate(NftId policyNftId, Timestamp activateAt) public override {
350
219
  // check caller is registered product
351
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
220
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
352
221
  InstanceReader instanceReader = instance.getInstanceReader();
353
222
 
354
223
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -382,7 +251,7 @@ contract PolicyService is
382
251
  external
383
252
  override
384
253
  {
385
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
254
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
386
255
  InstanceReader instanceReader = instance.getInstanceReader();
387
256
 
388
257
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -414,7 +283,11 @@ contract PolicyService is
414
283
 
415
284
  policyInfo.closedAt = TimestampLib.blockTimestamp();
416
285
 
417
- _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
286
+ _poolService.releaseCollateral(
287
+ instance,
288
+ policyNftId,
289
+ policyInfo);
290
+
418
291
  instance.updatePolicy(policyNftId, policyInfo, CLOSED());
419
292
  }
420
293
 
@@ -434,7 +307,6 @@ contract PolicyService is
434
307
 
435
308
  function _processPremiumByTreasury(
436
309
  IInstance instance,
437
- NftId productNftId,
438
310
  NftId policyNftId,
439
311
  uint256 premiumAmount
440
312
  )
@@ -443,30 +315,46 @@ contract PolicyService is
443
315
  {
444
316
  // process token transfer(s)
445
317
  if(premiumAmount > 0) {
318
+ NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
446
319
  ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
320
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
447
321
  TokenHandler tokenHandler = productSetupInfo.tokenHandler;
448
322
  address policyOwner = getRegistry().ownerOf(policyNftId);
449
- ISetup.PoolSetupInfo memory poolSetupInfo = instance.getInstanceReader().getPoolSetupInfo(productSetupInfo.poolNftId);
450
- address poolWallet = poolSetupInfo.wallet;
451
- netPremiumAmount = premiumAmount;
452
- Fee memory productFee = productSetupInfo.productFee;
453
-
454
- if (FeeLib.feeIsZero(productFee)) {
455
- tokenHandler.transfer(
456
- policyOwner,
457
- poolWallet,
458
- premiumAmount
323
+ address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
324
+ IPolicy.Premium memory premium = _applicationService.calculatePremium(
325
+ productNftId,
326
+ policyInfo.riskId,
327
+ policyInfo.sumInsuredAmount,
328
+ policyInfo.lifetime,
329
+ policyInfo.applicationData,
330
+ policyInfo.bundleNftId,
331
+ policyInfo.referralId
459
332
  );
460
- } else {
461
- (uint256 productFeeAmount, uint256 netAmount) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
462
- address productWallet = productSetupInfo.wallet;
463
- if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premiumAmount) {
464
- revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premiumAmount);
465
- }
466
- tokenHandler.transfer(policyOwner, productWallet, productFeeAmount);
467
- tokenHandler.transfer(policyOwner, poolWallet, netAmount);
468
- netPremiumAmount = netAmount;
333
+
334
+ if (premium.premiumAmount != premiumAmount) {
335
+ revert ErrorIPolicyServicePremiumMismatch(policyNftId, premiumAmount, premium.premiumAmount);
336
+ }
337
+
338
+ // move product fee to product wallet
339
+ address productWallet = productSetupInfo.wallet;
340
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
341
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
469
342
  }
343
+ tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
344
+
345
+ // move distribution fee to distribution wallet
346
+ ISetup.DistributionSetupInfo memory distributionSetupInfo = instance.getInstanceReader().getDistributionSetupInfo(productSetupInfo.distributionNftId);
347
+ address distributionWallet = distributionSetupInfo.wallet;
348
+ uint256 distributionFeeAmountToTransfer = premium.distributionFeeFixAmount + premium.distributionFeeVarAmount - premium.discountAmount;
349
+ tokenHandler.transfer(policyOwner, distributionWallet, distributionFeeAmountToTransfer);
350
+ _distributionService.processSale(productSetupInfo.distributionNftId, policyInfo.referralId, premium, distributionFeeAmountToTransfer);
351
+
352
+ // move netpremium to pool wallet
353
+ tokenHandler.transfer(policyOwner, poolWallet, premium.netPremiumAmount);
354
+
355
+ // TODO: move pool related tokens too
356
+ // TODO: move bundle related tokens too
357
+ netPremiumAmount = premium.netPremiumAmount;
470
358
  }
471
359
 
472
360
  // TODO: add logging