@etherisc/gif-next 0.0.2-cfc7167-648 → 0.0.2-cff7366-494

Sign up to get free protection for your applications and to get access to all the features.
Files changed (470) hide show
  1. package/README.md +32 -8
  2. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
  3. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +105 -65
  4. package/artifacts/contracts/authorization/AccessAdmin.sol/IAccessManagedChecker.dbg.json +4 -0
  5. package/artifacts/contracts/authorization/AccessAdmin.sol/IAccessManagedChecker.json +24 -0
  6. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
  7. package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
  8. package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +67 -11
  9. package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
  10. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
  11. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.json +60 -32
  12. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
  13. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.json +40 -3
  14. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
  15. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.json +19 -0
  16. package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.dbg.json +4 -0
  17. package/artifacts/contracts/authorization/ReleaseAccessManager.sol/ReleaseAccessManager.json +1196 -0
  18. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
  19. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +68 -5
  20. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
  21. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +159 -367
  22. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
  23. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +82 -22
  24. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  25. package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +99 -291
  26. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  27. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +227 -290
  28. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  29. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +125 -117
  30. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  31. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +89 -129
  32. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  33. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +101 -31
  34. package/artifacts/contracts/examples/fire/DamageLevel.sol/DamageLevelLib.dbg.json +4 -0
  35. package/artifacts/contracts/examples/fire/DamageLevel.sol/DamageLevelLib.json +22 -0
  36. package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.dbg.json +4 -0
  37. package/artifacts/contracts/examples/fire/FirePool.sol/FirePool.json +1415 -0
  38. package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.dbg.json +4 -0
  39. package/artifacts/contracts/examples/fire/FirePoolAuthorization.sol/FirePoolAuthorization.json +502 -0
  40. package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.dbg.json +4 -0
  41. package/artifacts/contracts/examples/fire/FireProduct.sol/FireProduct.json +1965 -0
  42. package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.dbg.json +4 -0
  43. package/artifacts/contracts/examples/fire/FireProductAuthorization.sol/FireProductAuthorization.json +470 -0
  44. package/artifacts/contracts/examples/fire/FireUSD.sol/FireUSD.dbg.json +4 -0
  45. package/artifacts/contracts/examples/fire/FireUSD.sol/FireUSD.json +376 -0
  46. package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.dbg.json +4 -0
  47. package/artifacts/contracts/examples/unpermissioned/SimpleDistribution.sol/SimpleDistribution.json +1429 -0
  48. package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.dbg.json +4 -0
  49. package/artifacts/contracts/examples/unpermissioned/SimpleOracle.sol/SimpleOracle.json +1163 -0
  50. package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.dbg.json +4 -0
  51. package/artifacts/contracts/examples/unpermissioned/SimplePool.sol/SimplePool.json +1592 -0
  52. package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.dbg.json +4 -0
  53. package/artifacts/contracts/examples/unpermissioned/SimpleProduct.sol/SimpleProduct.json +2267 -0
  54. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
  55. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +147 -42
  56. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  57. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +116 -48
  58. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +53 -101
  60. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  61. package/artifacts/contracts/instance/Instance.sol/Instance.json +141 -141
  62. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
  63. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +197 -139
  64. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
  65. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +58 -85
  66. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  67. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +726 -133
  68. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  69. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +118 -260
  70. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  71. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +99 -87
  72. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  73. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +337 -138
  74. package/artifacts/contracts/instance/RiskSet.sol/RiskSet.dbg.json +4 -0
  75. package/artifacts/contracts/instance/RiskSet.sol/RiskSet.json +810 -0
  76. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
  77. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +2 -2
  78. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  79. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
  80. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
  81. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
  82. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.json +46 -5
  83. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
  84. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +2 -2
  85. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  86. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  87. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  88. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  89. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  90. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  91. package/artifacts/contracts/mock/Dip.sol/Dip.dbg.json +1 -1
  92. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
  93. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +111 -319
  94. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
  95. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +84 -24
  96. package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
  97. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
  98. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +77 -117
  99. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
  100. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.json +43 -9
  101. package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
  102. package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +87 -279
  103. package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
  104. package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +147 -191
  105. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
  106. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +119 -83
  107. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
  108. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +106 -298
  109. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
  110. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +114 -22
  111. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  112. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +146 -307
  113. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  114. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +111 -119
  115. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  116. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +48 -33
  117. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  118. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +98 -149
  119. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  120. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +283 -180
  121. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  122. package/artifacts/contracts/pool/Pool.sol/Pool.json +106 -309
  123. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  124. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +382 -407
  125. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  126. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +123 -99
  127. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  128. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +119 -165
  129. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  130. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +93 -85
  131. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
  132. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.json +149 -295
  133. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
  134. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +82 -22
  135. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  136. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +282 -229
  137. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  138. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +132 -108
  139. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  140. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.json +63 -7
  141. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  142. package/artifacts/contracts/product/IClaimService.sol/IClaimService.json +161 -7
  143. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  144. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.json +179 -35
  145. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  146. package/artifacts/contracts/product/IPricingService.sol/IPricingService.json +114 -85
  147. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  148. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.json +136 -130
  149. package/artifacts/contracts/product/IRiskService.sol/IRiskService.dbg.json +4 -0
  150. package/artifacts/contracts/product/{IProductService.sol/IProductService.json → IRiskService.sol/IRiskService.json} +31 -2
  151. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  152. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +281 -323
  153. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  154. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +123 -119
  155. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  156. package/artifacts/contracts/product/PricingService.sol/PricingService.json +215 -309
  157. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  158. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +117 -117
  159. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  160. package/artifacts/contracts/product/Product.sol/Product.json +147 -293
  161. package/artifacts/contracts/product/RiskService.sol/RiskService.dbg.json +4 -0
  162. package/artifacts/contracts/product/RiskService.sol/RiskService.json +638 -0
  163. package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.dbg.json +4 -0
  164. package/artifacts/contracts/product/RiskServiceManager.sol/RiskServiceManager.json +718 -0
  165. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  166. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +59 -16
  167. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  168. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +310 -34
  169. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  170. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +114 -35
  171. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  172. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +5 -18
  173. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  174. package/artifacts/contracts/registry/Registry.sol/Registry.json +516 -95
  175. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
  176. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +296 -143
  177. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  178. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +94 -284
  179. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  180. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +91 -75
  181. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
  182. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.json +47 -6
  183. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
  184. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +131 -223
  185. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
  186. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +66 -8
  187. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  188. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  189. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  190. package/artifacts/contracts/shared/Component.sol/Component.json +76 -239
  191. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  192. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +492 -335
  193. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  194. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +143 -117
  195. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +1 -1
  196. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.json +47 -112
  197. package/artifacts/contracts/shared/ContractLib.sol/ContractLib.dbg.json +4 -0
  198. package/artifacts/contracts/shared/ContractLib.sol/ContractLib.json +488 -0
  199. package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.dbg.json +4 -0
  200. package/artifacts/contracts/shared/ContractLib.sol/IInstanceAdminHelper.json +24 -0
  201. package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.dbg.json +4 -0
  202. package/artifacts/contracts/shared/ContractLib.sol/ITargetHelper.json +30 -0
  203. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  204. package/artifacts/contracts/shared/IComponent.sol/IComponent.json +66 -77
  205. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
  206. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +467 -33
  207. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
  208. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.json +77 -117
  209. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  210. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.json +36 -0
  211. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  212. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.json +36 -0
  213. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  214. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +16 -0
  215. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  216. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +15 -47
  217. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  218. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +29 -0
  219. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  220. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  221. package/artifacts/contracts/shared/IService.sol/IService.json +29 -0
  222. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +1 -1
  223. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.json +2 -22
  224. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
  225. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.json +87 -279
  226. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  227. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.json +42 -1
  228. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  229. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.json +42 -1
  230. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
  231. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.json +2 -2
  232. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  233. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +22 -57
  234. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  235. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +19 -141
  236. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  237. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +58 -89
  238. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  239. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -15
  240. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  241. package/artifacts/contracts/shared/Service.sol/Service.json +47 -112
  242. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  243. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +674 -49
  244. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.dbg.json +4 -0
  245. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandlerBase.json +395 -0
  246. package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.dbg.json +4 -0
  247. package/artifacts/contracts/shared/TokenHandlerDeployerLib.sol/TokenHandlerDeployerLib.json +172 -0
  248. package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
  249. package/artifacts/contracts/staking/IStaking.sol/IStaking.json +111 -114
  250. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  251. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.json +29 -21
  252. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +1 -1
  253. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +63 -93
  254. package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
  255. package/artifacts/contracts/staking/Staking.sol/Staking.json +193 -368
  256. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
  257. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.json +46 -5
  258. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
  259. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +117 -110
  260. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
  261. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +6 -11
  262. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  263. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +87 -165
  264. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
  265. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +95 -79
  266. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
  267. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +169 -128
  268. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
  269. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +54 -23
  270. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  271. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  272. package/artifacts/contracts/type/Amount.sol/AmountLib.json +32 -8
  273. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  274. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  275. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.json +28 -4
  276. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  277. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.json +2 -2
  278. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  279. package/artifacts/contracts/type/Fee.sol/FeeLib.json +2 -2
  280. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  281. package/artifacts/contracts/type/Key32.sol/Key32Lib.json +2 -2
  282. package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.dbg.json +4 -0
  283. package/artifacts/contracts/type/Key32Set.sol/LibKey32Set.json +33 -0
  284. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  285. package/artifacts/contracts/type/NftId.sol/NftIdLib.json +23 -4
  286. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  287. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.json +2 -2
  288. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  289. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.json +2 -2
  290. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  291. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.json +19 -19
  292. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  293. package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
  294. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
  295. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.json +2 -2
  296. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  297. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.json +99 -5
  298. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  299. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.json +2 -2
  300. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  301. package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +26 -2
  302. package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
  303. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
  304. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  305. package/artifacts/contracts/type/StateId.sol/StateIdLib.json +15 -2
  306. package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
  307. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  308. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +2 -2
  309. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +1 -1
  310. package/artifacts/contracts/type/UFixed.sol/MathLib.json +2 -2
  311. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  312. package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +15 -2
  313. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  314. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  315. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
  316. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  317. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +71 -70
  318. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  319. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
  320. package/contracts/authorization/AccessAdmin.sol +83 -58
  321. package/contracts/authorization/Authorization.sol +111 -40
  322. package/contracts/authorization/IAccess.sol +1 -0
  323. package/contracts/authorization/IAccessAdmin.sol +4 -3
  324. package/contracts/authorization/IAuthorization.sol +13 -7
  325. package/contracts/authorization/IServiceAuthorization.sol +3 -1
  326. package/contracts/authorization/ReleaseAccessManager.sol +38 -0
  327. package/contracts/authorization/ServiceAuthorization.sol +26 -10
  328. package/contracts/distribution/BasicDistribution.sol +4 -3
  329. package/contracts/distribution/BasicDistributionAuthorization.sol +1 -1
  330. package/contracts/distribution/Distribution.sol +12 -23
  331. package/contracts/distribution/DistributionService.sol +97 -66
  332. package/contracts/distribution/DistributionServiceManager.sol +6 -6
  333. package/contracts/distribution/IDistributionComponent.sol +1 -1
  334. package/contracts/distribution/IDistributionService.sol +13 -8
  335. package/contracts/examples/fire/DamageLevel.sol +59 -0
  336. package/contracts/examples/fire/FirePool.sol +86 -0
  337. package/contracts/examples/fire/FirePoolAuthorization.sol +34 -0
  338. package/contracts/examples/fire/FireProduct.sol +431 -0
  339. package/contracts/examples/fire/FireProductAuthorization.sol +44 -0
  340. package/contracts/examples/fire/FireUSD.sol +26 -0
  341. package/contracts/examples/unpermissioned/SimpleDistribution.sol +65 -0
  342. package/contracts/examples/unpermissioned/SimpleOracle.sol +137 -0
  343. package/contracts/examples/unpermissioned/SimplePool.sol +108 -0
  344. package/contracts/examples/unpermissioned/SimpleProduct.sol +345 -0
  345. package/contracts/instance/BundleSet.sol +38 -34
  346. package/contracts/instance/IInstance.sol +16 -31
  347. package/contracts/instance/IInstanceService.sol +7 -29
  348. package/contracts/instance/Instance.sol +44 -59
  349. package/contracts/instance/InstanceAdmin.sol +58 -39
  350. package/contracts/instance/InstanceAuthorizationV3.sol +43 -29
  351. package/contracts/instance/InstanceReader.sol +190 -19
  352. package/contracts/instance/InstanceService.sol +61 -137
  353. package/contracts/instance/InstanceServiceManager.sol +6 -7
  354. package/contracts/instance/InstanceStore.sol +11 -1
  355. package/contracts/instance/RiskSet.sol +119 -0
  356. package/contracts/instance/base/ObjectLifecycle.sol +7 -1
  357. package/contracts/instance/base/ObjectSet.sol +24 -25
  358. package/contracts/instance/module/IComponents.sol +10 -6
  359. package/contracts/instance/module/IPolicy.sol +25 -24
  360. package/contracts/instance/module/IRisk.sol +1 -0
  361. package/contracts/oracle/BasicOracle.sol +0 -1
  362. package/contracts/oracle/IOracleService.sol +2 -1
  363. package/contracts/oracle/Oracle.sol +6 -16
  364. package/contracts/oracle/OracleService.sol +112 -81
  365. package/contracts/oracle/OracleServiceManager.sol +6 -6
  366. package/contracts/pool/BasicPool.sol +33 -24
  367. package/contracts/pool/BasicPoolAuthorization.sol +12 -2
  368. package/contracts/pool/BundleService.sol +69 -83
  369. package/contracts/pool/BundleServiceManager.sol +6 -6
  370. package/contracts/pool/IBundleService.sol +3 -14
  371. package/contracts/pool/IPoolComponent.sol +19 -15
  372. package/contracts/pool/IPoolService.sol +48 -42
  373. package/contracts/pool/Pool.sol +144 -127
  374. package/contracts/pool/PoolService.sol +277 -189
  375. package/contracts/pool/PoolServiceManager.sol +4 -4
  376. package/contracts/product/ApplicationService.sol +34 -25
  377. package/contracts/product/ApplicationServiceManager.sol +4 -4
  378. package/contracts/product/BasicProduct.sol +9 -12
  379. package/contracts/product/BasicProductAuthorization.sol +0 -1
  380. package/contracts/product/ClaimService.sol +312 -115
  381. package/contracts/product/ClaimServiceManager.sol +4 -4
  382. package/contracts/product/IApplicationService.sol +5 -2
  383. package/contracts/product/IClaimService.sol +30 -7
  384. package/contracts/product/IPolicyService.sol +31 -25
  385. package/contracts/product/IPricingService.sol +10 -10
  386. package/contracts/product/IProductComponent.sol +23 -4
  387. package/contracts/product/{IProductService.sol → IRiskService.sol} +1 -1
  388. package/contracts/product/PolicyService.sol +399 -261
  389. package/contracts/product/PolicyServiceManager.sol +4 -4
  390. package/contracts/product/PricingService.sol +49 -53
  391. package/contracts/product/PricingServiceManager.sol +3 -3
  392. package/contracts/product/Product.sol +101 -87
  393. package/contracts/product/{ProductService.sol → RiskService.sol} +21 -13
  394. package/contracts/product/RiskServiceManager.sol +39 -0
  395. package/contracts/registry/ChainNft.sol +68 -38
  396. package/contracts/registry/IRegistry.sol +57 -18
  397. package/contracts/registry/IRegistryService.sol +5 -12
  398. package/contracts/registry/ITransferInterceptor.sol +1 -2
  399. package/contracts/registry/Registry.sol +350 -201
  400. package/contracts/registry/RegistryAdmin.sol +140 -54
  401. package/contracts/registry/RegistryService.sol +35 -46
  402. package/contracts/registry/RegistryServiceManager.sol +2 -2
  403. package/contracts/registry/ReleaseLifecycle.sol +6 -3
  404. package/contracts/registry/ReleaseRegistry.sol +204 -204
  405. package/contracts/registry/ServiceAuthorizationV3.sol +23 -47
  406. package/contracts/shared/Component.sol +60 -119
  407. package/contracts/shared/ComponentService.sol +393 -167
  408. package/contracts/shared/ComponentServiceManager.sol +8 -5
  409. package/contracts/shared/ComponentVerifyingService.sol +28 -17
  410. package/contracts/shared/ContractLib.sol +224 -0
  411. package/contracts/shared/IComponent.sol +10 -14
  412. package/contracts/shared/IComponentService.sol +44 -18
  413. package/contracts/shared/IInstanceLinkedComponent.sol +2 -28
  414. package/contracts/shared/ILifecycle.sol +3 -1
  415. package/contracts/shared/INftOwnable.sol +2 -0
  416. package/contracts/shared/IPolicyHolder.sol +12 -22
  417. package/contracts/shared/IRegisterable.sol +11 -0
  418. package/contracts/shared/InitializableERC165.sol +2 -2
  419. package/contracts/shared/InstanceLinkedComponent.sol +71 -46
  420. package/contracts/shared/KeyValueStore.sol +1 -1
  421. package/contracts/shared/Lifecycle.sol +15 -4
  422. package/contracts/shared/NftOwnable.sol +27 -7
  423. package/contracts/shared/PolicyHolder.sol +15 -52
  424. package/contracts/shared/Registerable.sol +19 -11
  425. package/contracts/shared/RegistryLinked.sol +9 -14
  426. package/contracts/shared/Service.sol +20 -18
  427. package/contracts/shared/TokenHandler.sol +357 -30
  428. package/contracts/shared/TokenHandlerDeployerLib.sol +20 -0
  429. package/contracts/staking/IStaking.sol +11 -5
  430. package/contracts/staking/IStakingService.sol +0 -3
  431. package/contracts/staking/StakeManagerLib.sol +18 -25
  432. package/contracts/staking/Staking.sol +39 -50
  433. package/contracts/staking/StakingManager.sol +8 -6
  434. package/contracts/staking/StakingReader.sol +12 -5
  435. package/contracts/staking/StakingService.sol +58 -25
  436. package/contracts/staking/StakingServiceManager.sol +2 -2
  437. package/contracts/staking/TargetManagerLib.sol +7 -3
  438. package/contracts/type/Amount.sol +15 -0
  439. package/contracts/type/ClaimId.sol +6 -1
  440. package/contracts/type/Key32.sol +2 -2
  441. package/contracts/type/Key32Set.sol +62 -0
  442. package/contracts/type/NftId.sol +7 -0
  443. package/contracts/type/ObjectType.sol +18 -11
  444. package/contracts/type/PayoutId.sol +10 -10
  445. package/contracts/type/RiskId.sol +30 -4
  446. package/contracts/type/RoleId.sol +0 -12
  447. package/contracts/type/Seconds.sol +8 -0
  448. package/contracts/type/StateId.sol +15 -1
  449. package/contracts/type/UFixed.sol +4 -0
  450. package/contracts/upgradeability/ProxyManager.sol +68 -34
  451. package/contracts/upgradeability/Versionable.sol +2 -2
  452. package/package.json +4 -3
  453. package/artifacts/contracts/authorization/IModuleAuthorization.sol/IModuleAuthorization.dbg.json +0 -4
  454. package/artifacts/contracts/authorization/IModuleAuthorization.sol/IModuleAuthorization.json +0 -290
  455. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.dbg.json +0 -4
  456. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.json +0 -390
  457. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +0 -4
  458. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +0 -4
  459. package/artifacts/contracts/product/ProductService.sol/ProductService.json +0 -708
  460. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +0 -4
  461. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +0 -702
  462. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.dbg.json +0 -4
  463. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.json +0 -39
  464. package/artifacts/contracts/shared/TokenTransferLib.sol/TokenTransferLib.dbg.json +0 -4
  465. package/artifacts/contracts/shared/TokenTransferLib.sol/TokenTransferLib.json +0 -42
  466. package/contracts/authorization/IModuleAuthorization.sol +0 -21
  467. package/contracts/authorization/ModuleAuthorization.sol +0 -78
  468. package/contracts/product/ProductServiceManager.sol +0 -39
  469. package/contracts/shared/InitializableCustom.sol +0 -177
  470. package/contracts/shared/TokenTransferLib.sol +0 -60
@@ -3,53 +3,42 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
5
 
6
- import {IRegistry} from "../registry/IRegistry.sol";
7
- import {Product} from "./Product.sol";
6
+ import {IComponentService} from "../shared/IComponentService.sol";
8
7
  import {IComponents} from "../instance/module/IComponents.sol";
8
+ import {IDistributionService} from "../distribution/IDistributionService.sol";
9
+ import {InstanceReader} from "../instance/InstanceReader.sol";
10
+ import {InstanceStore} from "../instance/InstanceStore.sol";
9
11
  import {IInstance} from "../instance/IInstance.sol";
10
12
  import {IPolicy} from "../instance/module/IPolicy.sol";
13
+ import {IPolicyHolder} from "../shared/IPolicyHolder.sol";
14
+ import {IPolicyService} from "./IPolicyService.sol";
15
+ import {IPoolService} from "../pool/IPoolService.sol";
16
+ import {IPricingService} from "./IPricingService.sol";
17
+ import {IRegistry} from "../registry/IRegistry.sol";
11
18
 
12
- import {TokenHandler} from "../shared/TokenHandler.sol";
13
- import {TokenTransferLib} from "../shared/TokenTransferLib.sol";
14
-
15
- import {Amount, AmountLib} from "../type/Amount.sol";
16
- import {Timestamp, TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";
17
- import {ObjectType, APPLICATION, COMPONENT, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM, PRICE} from "../type/ObjectType.sol";
18
- import {APPLIED, COLLATERALIZED, KEEP_STATE, CLOSED, DECLINED} from "../type/StateId.sol";
19
- import {NftId, NftIdLib} from "../type/NftId.sol";
19
+ import {Amount} from "../type/Amount.sol";
20
+ import {APPLIED, COLLATERALIZED, KEEP_STATE, CLOSED, DECLINED, PAID} from "../type/StateId.sol";
21
+ import {ContractLib} from "../shared/ContractLib.sol";
22
+ import {NftId} from "../type/NftId.sol";
23
+ import {ObjectType, COMPONENT, DISTRIBUTION, PRODUCT, POOL, POLICY, PRICE} from "../type/ObjectType.sol";
20
24
  import {ReferralId} from "../type/Referral.sol";
25
+ import {RiskId} from "../type/RiskId.sol";
26
+ import {Service} from "../shared/Service.sol";
21
27
  import {StateId} from "../type/StateId.sol";
28
+ import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
29
+ import {TokenHandler} from "../shared/TokenHandler.sol";
22
30
  import {VersionPart} from "../type/Version.sol";
23
31
 
24
- import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";
25
- import {IApplicationService} from "./IApplicationService.sol";
26
- import {IBundleService} from "../pool/IBundleService.sol";
27
- import {IClaimService} from "./IClaimService.sol";
28
- import {IComponentService} from "../shared/IComponentService.sol";
29
- import {IDistributionService} from "../distribution/IDistributionService.sol";
30
- import {InstanceReader} from "../instance/InstanceReader.sol";
31
- import {InstanceStore} from "../instance/InstanceStore.sol";
32
- import {IPolicyService} from "./IPolicyService.sol";
33
- import {IPoolService} from "../pool/IPoolService.sol";
34
- import {IPricingService} from "./IPricingService.sol";
35
32
 
36
33
  contract PolicyService is
37
- ComponentVerifyingService,
34
+ Service,
38
35
  IPolicyService
39
36
  {
40
- using NftIdLib for NftId;
41
- using TimestampLib for Timestamp;
42
-
43
- IApplicationService internal _applicationService;
44
37
  IComponentService internal _componentService;
45
- IBundleService internal _bundleService;
46
- IClaimService internal _claimService;
47
38
  IDistributionService internal _distributionService;
48
39
  IPoolService internal _poolService;
49
40
  IPricingService internal _pricingService;
50
41
 
51
- event LogProductServiceSender(address sender);
52
-
53
42
  function _initialize(
54
43
  address owner,
55
44
  bytes memory data
@@ -59,23 +48,19 @@ contract PolicyService is
59
48
  initializer
60
49
  {
61
50
  (
62
- address registryAddress,,
63
- //address managerAddress
51
+ address registryAddress,
64
52
  address authority
65
- ) = abi.decode(data, (address, address, address));
53
+ ) = abi.decode(data, (address, address));
66
54
 
67
- initializeService(registryAddress, authority, owner);
55
+ _initializeService(registryAddress, authority, owner);
68
56
 
69
57
  VersionPart majorVersion = getVersion().toMajorPart();
70
- _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
71
- _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), majorVersion));
72
58
  _componentService = IComponentService(getRegistry().getServiceAddress(COMPONENT(), majorVersion));
73
- _claimService = IClaimService(getRegistry().getServiceAddress(CLAIM(), majorVersion));
74
59
  _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion));
75
60
  _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
76
61
  _pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion));
77
62
 
78
- registerInterface(type(IPolicyService).interfaceId);
63
+ _registerInterface(type(IPolicyService).interfaceId);
79
64
  }
80
65
 
81
66
 
@@ -83,26 +68,18 @@ contract PolicyService is
83
68
  NftId applicationNftId // = policyNftId
84
69
  )
85
70
  external
86
- virtual override
71
+ virtual
72
+ nonReentrant()
87
73
  {
88
- (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
89
- InstanceReader instanceReader = instance.getInstanceReader();
74
+ // checks
75
+ (IInstance instance,,) = _getAndVerifyCallerForPolicy(applicationNftId);
90
76
 
91
77
  // check policy is in state applied
92
- if (instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
78
+ if (instance.getInstanceReader().getPolicyState(applicationNftId) != APPLIED()) {
93
79
  revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId);
94
80
  }
95
81
 
96
- // check policy matches with calling product
97
- IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
98
- if(applicationInfo.productNftId != productNftId) {
99
- revert ErrorPolicyServicePolicyProductMismatch(
100
- applicationNftId,
101
- applicationInfo.productNftId,
102
- productNftId);
103
- }
104
-
105
-
82
+ // effects
106
83
  // store updated policy info
107
84
  instance.getInstanceStore().updatePolicyState(
108
85
  applicationNftId,
@@ -115,37 +92,29 @@ contract PolicyService is
115
92
  /// @inheritdoc IPolicyService
116
93
  function createPolicy(
117
94
  NftId applicationNftId, // = policyNftId
118
- bool requirePremiumPayment,
119
95
  Timestamp activateAt
120
96
  )
121
97
  external
122
- virtual override
98
+ virtual
99
+ nonReentrant()
100
+ returns (Amount premiumAmount)
123
101
  {
124
- // check caller is registered product
125
- (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
126
- InstanceReader instanceReader = instance.getInstanceReader();
102
+ // checks
103
+ (
104
+ IInstance instance,
105
+ NftId productNftId,
106
+ IPolicy.PolicyInfo memory applicationInfo
107
+ ) = _getAndVerifyCallerForPolicy(applicationNftId);
127
108
 
128
109
  // check policy is in state applied
110
+ InstanceReader instanceReader = instance.getInstanceReader();
129
111
  if (instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
130
112
  revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId);
131
113
  }
132
114
 
133
- // check policy matches with calling product
134
- IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
135
- if(applicationInfo.productNftId != productNftId) {
136
- revert ErrorPolicyServicePolicyProductMismatch(
137
- applicationNftId,
138
- applicationInfo.productNftId,
139
- productNftId);
140
- }
141
-
142
- StateId newPolicyState = COLLATERALIZED();
143
-
115
+ // effects
144
116
  // actual collateralizaion
145
- (
146
- Amount localCollateralAmount,
147
- Amount totalCollateralAmount
148
- ) = _poolService.lockCollateral(
117
+ _poolService.lockCollateral(
149
118
  instance,
150
119
  address(instanceReader.getComponentInfo(productNftId).token),
151
120
  productNftId,
@@ -154,39 +123,55 @@ contract PolicyService is
154
123
  applicationInfo.sumInsuredAmount);
155
124
 
156
125
  // optional activation of policy
157
- if(activateAt > zeroTimestamp()) {
158
- applicationInfo.activatedAt = activateAt;
159
- applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
126
+ if(activateAt > TimestampLib.zero()) {
127
+ applicationInfo = _activate(applicationNftId, applicationInfo, activateAt);
160
128
  }
161
129
 
162
- IPolicy.Premium memory premium;
163
-
164
- // optional: calculate the premium and update counters for collection at the end of this function
165
- if(requirePremiumPayment) {
166
- premium = _calculateAndProcessPremium(
167
- instance,
168
- applicationNftId,
169
- applicationInfo);
170
-
171
- applicationInfo.premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
172
- }
173
-
174
- // store updated policy info
130
+ // update policy and set state to collateralized
175
131
  instance.getInstanceStore().updatePolicy(
176
132
  applicationNftId,
177
133
  applicationInfo,
178
- newPolicyState);
134
+ COLLATERALIZED());
135
+
136
+ // calculate and store premium
137
+ RiskId riskId = applicationInfo.riskId;
138
+ NftId bundleNftId = applicationInfo.bundleNftId;
179
139
 
180
- // TODO add calling pool contract if it needs to validate application
140
+ IPolicy.PremiumInfo memory premium = _pricingService.calculatePremium(
141
+ productNftId,
142
+ riskId,
143
+ applicationInfo.sumInsuredAmount,
144
+ applicationInfo.lifetime,
145
+ applicationInfo.applicationData,
146
+ bundleNftId,
147
+ applicationInfo.referralId);
181
148
 
182
- // TODO: add logging
149
+ premiumAmount = premium.fullPremiumAmount;
150
+ instance.getInstanceStore().createPremium(
151
+ applicationNftId,
152
+ premium);
183
153
 
184
- // optional: transfer funds for premium
185
- if(requirePremiumPayment) {
186
- _transferFunds(instanceReader, applicationNftId, applicationInfo.productNftId, premium);
154
+ // update referral counter if product has linked distributino component
155
+ {
156
+ IComponents.ProductInfo memory productInfo = instanceReader.getProductInfo(productNftId);
157
+ if (productInfo.hasDistribution) {
158
+ _distributionService.processReferral(
159
+ productInfo.distributionNftId,
160
+ applicationInfo.referralId);
161
+ }
187
162
  }
188
163
 
189
- // TODO: add callback IPolicyHolder.policyActivated() if applicable
164
+ // link policy to risk and bundle
165
+ NftId poolNftId = getRegistry().getObjectInfo(bundleNftId).parentNftId;
166
+ instance.getRiskSet().linkPolicy(productNftId, riskId, applicationNftId);
167
+ instance.getBundleSet().linkPolicy(poolNftId, bundleNftId, applicationNftId);
168
+
169
+ // log policy creation before interactions with token and policy holder
170
+ emit LogPolicyServicePolicyCreated(applicationNftId, premium.premiumAmount, activateAt);
171
+
172
+ // interactions
173
+ // callback to policy holder if applicable
174
+ _policyHolderPolicyActivated(applicationNftId, activateAt);
190
175
  }
191
176
 
192
177
 
@@ -197,31 +182,43 @@ contract PolicyService is
197
182
  )
198
183
  external
199
184
  virtual
185
+ nonReentrant()
200
186
  {
201
- // check caller is registered product
202
- (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
203
- InstanceReader instanceReader = instance.getInstanceReader();
204
- StateId stateId = instanceReader.getPolicyState(policyNftId);
187
+ // checks
188
+ (
189
+ IInstance instance,
190
+ NftId productNftId,
191
+ IPolicy.PolicyInfo memory policyInfo
192
+ ) = _getAndVerifyCallerForPolicy(policyNftId);
205
193
 
206
- // check policy is in state collateralized or active
207
- if (!(stateId == COLLATERALIZED())) {
194
+ // check policy is in state collateralized
195
+ InstanceReader instanceReader = instance.getInstanceReader();
196
+ if (instanceReader.getPolicyState(policyNftId) != COLLATERALIZED()) {
208
197
  revert ErrorPolicyServicePolicyStateNotCollateralized(policyNftId);
209
198
  }
210
199
 
211
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
212
-
213
- // check if premium is already collected
214
- if (policyInfo.premiumPaidAmount.gtz()) {
215
- revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
200
+ // check if premium has already been collected
201
+ if (instanceReader.getPremiumInfoState(policyNftId) == PAID()) {
202
+ revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId);
216
203
  }
217
204
 
218
- // calculate premium
219
- IPolicy.Premium memory premium = _calculateAndProcessPremium(
220
- instance,
221
- policyNftId,
222
- policyInfo);
205
+ // check funds and allowance of policy holder
206
+ IPolicy.PremiumInfo memory premium = instanceReader.getPremiumInfo(policyNftId);
207
+ TokenHandler tokenHandler = _getTokenHandler(instanceReader, policyInfo.productNftId);
208
+ _checkPremiumBalanceAndAllowance(
209
+ tokenHandler.TOKEN(),
210
+ address(tokenHandler),
211
+ getRegistry().ownerOf(policyNftId),
212
+ premium.premiumAmount);
223
213
 
224
- policyInfo.premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
214
+ // effects
215
+ _processSale(
216
+ instanceReader,
217
+ instance.getInstanceStore(),
218
+ productNftId,
219
+ policyInfo.bundleNftId,
220
+ policyInfo.referralId,
221
+ premium);
225
222
 
226
223
  // optionally activate policy
227
224
  if(activateAt.gtz()) {
@@ -229,28 +226,38 @@ contract PolicyService is
229
226
  }
230
227
 
231
228
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
229
+ instance.getInstanceStore().updatePremiumState(policyNftId, PAID());
232
230
 
233
- // TODO: add logging
231
+ // log premium collection before interactions with token
232
+ emit LogPolicyServicePolicyPremiumCollected(policyNftId, premium.premiumAmount);
234
233
 
234
+ // interactions
235
235
  _transferFunds(instanceReader, policyNftId, policyInfo.productNftId, premium);
236
-
237
- // TODO: add callback IPolicyHolder.policyActivated() if applicable
238
236
  }
239
237
 
238
+
240
239
  /// @inheritdoc IPolicyService
241
- function activate(NftId policyNftId, Timestamp activateAt) public override {
242
- // check caller is registered product
243
- (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
244
- InstanceReader instanceReader = instance.getInstanceReader();
240
+ function activate(NftId policyNftId, Timestamp activateAt)
241
+ external
242
+ virtual
243
+ nonReentrant()
244
+ {
245
+ // checks
246
+ (
247
+ IInstance instance,,
248
+ IPolicy.PolicyInfo memory policyInfo
249
+ ) = _getAndVerifyCallerForPolicy(policyNftId);
245
250
 
246
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
251
+ // effects
247
252
  policyInfo = _activate(policyNftId, policyInfo, activateAt);
248
-
249
253
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
250
254
 
251
- // TODO: add logging
255
+ // log policy activation before interactions with policy holder
256
+ emit LogPolicyServicePolicyActivated(policyNftId, activateAt);
252
257
 
253
- // TODO: add callback IPolicyHolder.policyActivated() if applicable
258
+ // interactions
259
+ // callback to policy holder if applicable
260
+ _policyHolderPolicyActivated(policyNftId, activateAt);
254
261
  }
255
262
 
256
263
 
@@ -260,145 +267,199 @@ contract PolicyService is
260
267
  Timestamp expireAt
261
268
  )
262
269
  external
263
- override
264
270
  virtual
271
+ nonReentrant()
265
272
  returns (Timestamp expiredAt)
266
273
  {
267
- (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
268
- InstanceReader instanceReader = instance.getInstanceReader();
269
-
270
- // check policy matches with calling product
271
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
272
- if(policyInfo.productNftId != productNftId) {
273
- revert ErrorPolicyServicePolicyProductMismatch(
274
- policyNftId,
275
- policyInfo.productNftId,
276
- productNftId);
277
- }
278
-
279
- // check policy is active
280
- StateId policyState = instanceReader.getPolicyState(policyNftId);
281
- if (!_policyHasBeenActivated(policyState, policyInfo)) {
282
- revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
283
- }
284
-
285
- // set return value to provided timestamp
286
- expiredAt = expireAt;
287
-
288
- // update expiredAt to current block timestamp if not set
289
- if (expiredAt.eqz()) {
290
- expiredAt = TimestampLib.blockTimestamp();
291
- }
274
+ // checks
275
+ (
276
+ IInstance instance,,
277
+ IPolicy.PolicyInfo memory policyInfo
278
+ ) = _getAndVerifyCallerForPolicy(policyNftId);
292
279
 
293
- // check expiredAt represents a valid expiry time
294
- if (expiredAt >= policyInfo.expiredAt) {
295
- revert ErrorPolicyServicePolicyExpirationTooLate(policyNftId, policyInfo.expiredAt, expireAt);
296
- }
297
- if (expiredAt < TimestampLib.blockTimestamp()) {
298
- revert ErrorPolicyServicePolicyExpirationTooEarly(policyNftId, TimestampLib.blockTimestamp(), expireAt);
299
- }
280
+ // more checks, effects + interactions
281
+ return _expire(
282
+ instance,
283
+ policyNftId,
284
+ policyInfo,
285
+ expireAt
286
+ );
287
+ }
300
288
 
301
- // update policyInfo with new expiredAt timestamp
302
- policyInfo.expiredAt = expiredAt;
303
- instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
304
289
 
305
- emit LogPolicyServicePolicyExpirationUpdated(policyNftId, expiredAt);
290
+ /// @inheritdoc IPolicyService
291
+ function expirePolicy(
292
+ IInstance instance,
293
+ NftId policyNftId,
294
+ Timestamp expireAt
295
+ )
296
+ external
297
+ virtual
298
+ nonReentrant()
299
+ returns (Timestamp expiredAt)
300
+ {
301
+ // checks
302
+ _checkNftType(policyNftId, POLICY());
303
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(
304
+ policyNftId);
306
305
 
307
- // TODO: add callback IPolicyHolder.policyExpired() if applicable
306
+ // more checks, effects + interactions
307
+ return _expire(
308
+ instance,
309
+ policyNftId,
310
+ policyInfo,
311
+ expireAt
312
+ );
308
313
  }
309
314
 
310
315
 
316
+ /// @inheritdoc IPolicyService
311
317
  function close(
312
318
  NftId policyNftId
313
319
  )
314
320
  external
315
- override
321
+ virtual
322
+ nonReentrant()
316
323
  {
317
- (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
324
+ // checks
325
+ (
326
+ IInstance instance,
327
+ NftId productNftId,
328
+ IPolicy.PolicyInfo memory policyInfo
329
+ ) = _getAndVerifyCallerForPolicy(policyNftId);
318
330
  InstanceReader instanceReader = instance.getInstanceReader();
319
331
 
320
- // check that policy has been activated
321
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
322
- StateId policyState = instanceReader.getPolicyState(policyNftId);
323
- if (!_policyHasBeenActivated(policyState, policyInfo)) {
324
- revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
325
- }
326
-
327
- // check that policy has not already been closed
328
- if (policyInfo.closedAt.gtz()) {
329
- revert ErrorPolicyServicePolicyAlreadyClosed(policyNftId);
332
+ // check policy is in a closeable state
333
+ if (!policyIsCloseable(instanceReader, policyNftId)) {
334
+ revert ErrorPolicyServicePolicyNotCloseable(policyNftId);
330
335
  }
331
336
 
332
- // check that policy does not have any open claims
333
- if (policyInfo.openClaimsCount > 0) {
334
- revert ErrorPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
335
- }
337
+ // check that policy has been activated
338
+ RiskId riskId = policyInfo.riskId;
339
+ NftId bundleNftId = policyInfo.bundleNftId;
336
340
 
337
- // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
338
- if (!(policyInfo.premiumAmount == policyInfo.premiumPaidAmount)) {
339
- revert ErrorPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
341
+ if (instanceReader.getPremiumInfoState(policyNftId) != PAID()) {
342
+ revert ErrorPolicyServicePremiumNotPaid(policyNftId, policyInfo.premiumAmount);
340
343
  }
341
344
 
345
+ // effects
342
346
  // release (remaining) collateral that was blocked by policy
343
347
  _poolService.releaseCollateral(
344
348
  instance,
345
- address(instanceReader.getComponentInfo(policyInfo.productNftId).token),
349
+ address(instanceReader.getComponentInfo(productNftId).token),
346
350
  policyNftId,
347
351
  policyInfo);
348
352
 
353
+ // TODO consider to also set expiredAt to current block timestamp if that timestamp is still in the futue
354
+
349
355
  // update policy state to closed
350
356
  policyInfo.closedAt = TimestampLib.blockTimestamp();
351
357
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
358
+
359
+ // unlink policy from risk and bundle
360
+ NftId poolNftId = getRegistry().getObjectInfo(bundleNftId).parentNftId;
361
+ instance.getRiskSet().unlinkPolicy(productNftId, riskId, policyNftId);
362
+ instance.getBundleSet().unlinkPolicy(poolNftId, bundleNftId, policyNftId);
363
+
364
+ emit LogPolicyServicePolicyClosed(policyNftId);
352
365
  }
353
366
 
354
367
 
355
- /// @dev calculates the premium and updates all counters in the other services
356
- function _calculateAndProcessPremium(
368
+ function policyIsCloseable(InstanceReader instanceReader, NftId policyNftId)
369
+ public
370
+ view
371
+ returns (bool isCloseable)
372
+ {
373
+ // policy already closed
374
+ if (instanceReader.getPolicyState(policyNftId) == CLOSED()) {
375
+ return false;
376
+ }
377
+
378
+ IPolicy.PolicyInfo memory info = instanceReader.getPolicyInfo(policyNftId);
379
+
380
+ if (info.productNftId.eqz()) { return false; } // not closeable: policy does not exist (or does not belong to this instance)
381
+ if (info.activatedAt.eqz()) { return false; } // not closeable: not yet activated
382
+ if (info.openClaimsCount > 0) { return false; } // not closeable: has open claims
383
+
384
+ // closeable: if sum of claims matches sum insured a policy may be closed prior to the expiry date
385
+ if (info.claimAmount == info.sumInsuredAmount) { return true; }
386
+
387
+ // not closeable: not yet expired
388
+ if (TimestampLib.blockTimestamp() < info.expiredAt) { return false; }
389
+
390
+ // all conditions to close the policy are met
391
+ return true;
392
+ }
393
+
394
+ /// @dev shared functionality for expire() and policyExpire().
395
+ function _expire(
357
396
  IInstance instance,
358
- NftId applicationNftId,
359
- IPolicy.PolicyInfo memory applicationInfo
397
+ NftId policyNftId,
398
+ IPolicy.PolicyInfo memory policyInfo,
399
+ Timestamp expireAt
360
400
  )
361
401
  internal
362
- virtual
363
- returns (
364
- IPolicy.Premium memory premium
365
- )
402
+ returns (Timestamp expiredAt)
366
403
  {
367
- NftId productNftId = applicationInfo.productNftId;
368
- InstanceReader instanceReader = instance.getInstanceReader();
404
+ // checks
405
+ // check policy is active
406
+ StateId policyState = instance.getInstanceReader().getPolicyState(policyNftId);
407
+ if (!_policyHasBeenActivated(policyState, policyInfo)) {
408
+ revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
409
+ }
369
410
 
370
- // calculate premium details
371
- premium = _pricingService.calculatePremium(
372
- productNftId,
373
- applicationInfo.riskId,
374
- applicationInfo.sumInsuredAmount,
375
- applicationInfo.lifetime,
376
- applicationInfo.applicationData,
377
- applicationInfo.bundleNftId,
378
- applicationInfo.referralId);
411
+ // set return value to provided timestamp
412
+ expiredAt = expireAt;
379
413
 
380
- // check if premium balance and allowance of policy holder is sufficient
381
- {
382
- TokenHandler tokenHandler = _getTokenHandler(instanceReader, productNftId);
383
- address policyHolder = getRegistry().ownerOf(applicationNftId);
384
-
385
- _checkPremiumBalanceAndAllowance(
386
- tokenHandler.getToken(),
387
- address(tokenHandler),
388
- policyHolder,
389
- AmountLib.toAmount(premium.premiumAmount));
414
+ // update expiredAt to current block timestamp if not set
415
+ if (expiredAt.eqz()) {
416
+ expiredAt = TimestampLib.blockTimestamp();
390
417
  }
391
418
 
392
- // update the counters
393
- _processSale(
394
- instanceReader,
395
- instance.getInstanceStore(),
396
- productNftId,
397
- applicationInfo.bundleNftId,
398
- applicationInfo.referralId,
399
- premium);
419
+ // check expiredAt represents a valid expiry time
420
+ if (expiredAt >= policyInfo.expiredAt) {
421
+ revert ErrorPolicyServicePolicyExpirationTooLate(policyNftId, policyInfo.expiredAt, expireAt);
422
+ }
423
+
424
+ if (expiredAt < TimestampLib.blockTimestamp()) {
425
+ revert ErrorPolicyServicePolicyExpirationTooEarly(policyNftId, TimestampLib.blockTimestamp(), expireAt);
426
+ }
427
+
428
+ // effects
429
+ // update policyInfo with new expiredAt timestamp
430
+ Timestamp originalExpiredAt = policyInfo.expiredAt;
431
+ policyInfo.expiredAt = expiredAt;
432
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
433
+
434
+ emit LogPolicyServicePolicyExpirationUpdated(policyNftId, originalExpiredAt, expiredAt);
435
+
436
+ // interactions
437
+ // callback to policy holder if applicable
438
+ _policyHolderPolicyExpired(policyNftId, expiredAt);
400
439
  }
401
440
 
441
+ // TODO cleanup
442
+ // /// @dev Calculates the premium and updates all counters in the other services.
443
+ // /// Only book keeping, no token transfers.
444
+ // function _processPremium(
445
+ // IInstance instance,
446
+ // NftId applicationNftId,
447
+ // IPolicy.PolicyInfo memory applicationInfo,
448
+ // IPolicy.PremiumInfo memory premium
449
+ // )
450
+ // internal
451
+ // virtual
452
+ // {
453
+ // // update the counters
454
+ // _processSale(
455
+ // instanceReader,
456
+ // instance.getInstanceStore(),
457
+ // productNftId,
458
+ // applicationInfo.bundleNftId,
459
+ // applicationInfo.referralId,
460
+ // premium);
461
+ // }
462
+
402
463
 
403
464
  function _activate(
404
465
  NftId policyNftId,
@@ -410,10 +471,16 @@ contract PolicyService is
410
471
  view
411
472
  returns (IPolicy.PolicyInfo memory)
412
473
  {
413
- if(! policyInfo.activatedAt.eqz()) {
474
+ // fail if policy has already been activated and activateAt is different
475
+ if(! policyInfo.activatedAt.eqz() && activateAt != policyInfo.activatedAt) {
414
476
  revert ErrorPolicyServicePolicyAlreadyActivated(policyNftId);
415
477
  }
416
478
 
479
+ // ignore if policy has already been activated and activateAt is the same
480
+ if (policyInfo.activatedAt == activateAt) {
481
+ return policyInfo;
482
+ }
483
+
417
484
  policyInfo.activatedAt = activateAt;
418
485
  policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
419
486
 
@@ -427,17 +494,12 @@ contract PolicyService is
427
494
  NftId productNftId,
428
495
  NftId bundleNftId,
429
496
  ReferralId referralId,
430
- IPolicy.Premium memory premium
497
+ IPolicy.PremiumInfo memory premium
431
498
  )
432
499
  internal
433
500
  virtual
434
501
  {
435
- (
436
- NftId distributionNftId,
437
- address distributionWallet,
438
- address poolWallet,
439
- address productWallet
440
- ) = _getDistributionNftAndWallets(
502
+ (NftId distributionNftId,,,) = _getDistributionNftAndWallets(
441
503
  instanceReader,
442
504
  productNftId);
443
505
 
@@ -445,13 +507,15 @@ contract PolicyService is
445
507
  _componentService.increaseProductFees(
446
508
  instanceStore,
447
509
  productNftId,
448
- AmountLib.toAmount(premium.productFeeVarAmount + premium.productFeeFixAmount));
510
+ premium.productFeeVarAmount + premium.productFeeFixAmount);
449
511
 
450
512
  // update distribution fees and distributor commission and pool fees
451
- _distributionService.processSale(
452
- distributionNftId,
453
- referralId,
454
- premium);
513
+ if (!distributionNftId.eqz()) { // only call distribution service if a distribution component is connected to the product
514
+ _distributionService.processSale(
515
+ distributionNftId,
516
+ referralId,
517
+ premium);
518
+ }
455
519
 
456
520
  // update pool and bundle fees
457
521
  _poolService.processSale(
@@ -465,7 +529,7 @@ contract PolicyService is
465
529
  InstanceReader instanceReader,
466
530
  NftId policyNftId,
467
531
  NftId productNftId,
468
- IPolicy.Premium memory premium
532
+ IPolicy.PremiumInfo memory premium
469
533
  )
470
534
  internal
471
535
  virtual
@@ -482,27 +546,14 @@ contract PolicyService is
482
546
  instanceReader,
483
547
  productNftId);
484
548
 
485
- if (premium.productFeeAmount.gtz()) {
486
- TokenTransferLib.collectTokens(
487
- policyHolder,
488
- productWallet,
489
- premium.productFeeAmount,
490
- tokenHandler);
491
- }
492
- if (premium.distributionFeeAndCommissionAmount.gtz()) {
493
- TokenTransferLib.collectTokens(
494
- policyHolder,
495
- distributionWallet,
496
- premium.distributionFeeAndCommissionAmount,
497
- tokenHandler);
498
- }
499
- if (premium.poolPremiumAndFeeAmount.gtz()) {
500
- TokenTransferLib.collectTokens(
501
- policyHolder,
502
- poolWallet,
503
- premium.poolPremiumAndFeeAmount,
504
- tokenHandler);
505
- }
549
+ tokenHandler.collectTokensToThreeRecipients(
550
+ policyHolder,
551
+ productWallet,
552
+ premium.productFeeAmount,
553
+ distributionWallet,
554
+ premium.distributionFeeAndCommissionAmount,
555
+ poolWallet,
556
+ premium.poolPremiumAndFeeAmount);
506
557
  }
507
558
 
508
559
 
@@ -547,6 +598,64 @@ contract PolicyService is
547
598
  }
548
599
 
549
600
 
601
+ function _policyHolderPolicyActivated(
602
+ NftId policyNftId,
603
+ Timestamp activateAt
604
+ )
605
+ internal
606
+ virtual
607
+ {
608
+ // immediately return if policy is not activated
609
+ if (activateAt.eqz()) {
610
+ return;
611
+ }
612
+
613
+ // get policy holder address
614
+ IPolicyHolder policyHolder = _getPolicyHolder(policyNftId);
615
+
616
+ // execute callback if policy holder implements IPolicyHolder
617
+ if (address(policyHolder) != address(0)) {
618
+ policyHolder.policyActivated(policyNftId, activateAt);
619
+ }
620
+ }
621
+
622
+
623
+ function _policyHolderPolicyExpired(
624
+ NftId policyNftId,
625
+ Timestamp expiredAt
626
+ )
627
+ internal
628
+ virtual
629
+ {
630
+ // immediately return if policy is not activated
631
+ if (expiredAt.eqz()) {
632
+ return;
633
+ }
634
+
635
+ // get policy holder address
636
+ IPolicyHolder policyHolder = _getPolicyHolder(policyNftId);
637
+
638
+ // execute callback if policy holder implements IPolicyHolder
639
+ if (address(policyHolder) != address(0)) {
640
+ policyHolder.policyExpired(policyNftId, expiredAt);
641
+ }
642
+ }
643
+
644
+
645
+ function _getPolicyHolder(NftId policyNftId)
646
+ internal
647
+ view
648
+ returns (IPolicyHolder policyHolder)
649
+ {
650
+ address policyHolderAddress = getRegistry().ownerOf(policyNftId);
651
+ policyHolder = IPolicyHolder(policyHolderAddress);
652
+
653
+ if (!ContractLib.isPolicyHolder(policyHolderAddress)) {
654
+ policyHolder = IPolicyHolder(address(0));
655
+ }
656
+ }
657
+
658
+
550
659
  function _getTokenHandler(
551
660
  InstanceReader instanceReader,
552
661
  NftId productNftId
@@ -561,6 +670,7 @@ contract PolicyService is
561
670
  tokenHandler = instanceReader.getComponentInfo(productNftId).tokenHandler;
562
671
  }
563
672
 
673
+
564
674
  function _getDistributionNftAndWallets(
565
675
  InstanceReader instanceReader,
566
676
  NftId productNftId
@@ -575,17 +685,45 @@ contract PolicyService is
575
685
  )
576
686
  {
577
687
  IComponents.ProductInfo memory productInfo = instanceReader.getProductInfo(productNftId);
578
- distributionNftId = productInfo.distributionNftId;
579
- distributionWallet = instanceReader.getComponentInfo(distributionNftId).wallet;
580
- poolWallet = instanceReader.getComponentInfo(productInfo.poolNftId).wallet;
581
- productWallet = instanceReader.getComponentInfo(productNftId).wallet;
688
+ productWallet = instanceReader.getComponentInfo(productNftId).tokenHandler.getWallet();
689
+ poolWallet = instanceReader.getComponentInfo(productInfo.poolNftId).tokenHandler.getWallet();
690
+
691
+ if (productInfo.hasDistribution) {
692
+ distributionNftId = productInfo.distributionNftId;
693
+ distributionWallet = instanceReader.getComponentInfo(distributionNftId).tokenHandler.getWallet();
694
+ }
582
695
  }
583
696
 
584
697
 
585
- function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
586
- IRegistry.ObjectInfo memory productInfo;
587
- (, productInfo,) = _getAndVerifyActiveComponent(PRODUCT());
588
- product = Product(productInfo.objectAddress);
698
+ function _getAndVerifyCallerForPolicy(NftId policyNftId)
699
+ internal
700
+ virtual
701
+ view
702
+ returns (
703
+ IInstance instance,
704
+ NftId productNftId,
705
+ IPolicy.PolicyInfo memory policyInfo
706
+ )
707
+ {
708
+ (
709
+ IRegistry.ObjectInfo memory productInfo,
710
+ address instanceAddress
711
+ ) = ContractLib.getAndVerifyComponent(
712
+ getRegistry(),
713
+ msg.sender, // caller contract
714
+ PRODUCT(), // caller must be product
715
+ true); // only active caller
716
+
717
+ productNftId = productInfo.nftId;
718
+ instance = IInstance(instanceAddress);
719
+ policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
720
+
721
+ if (policyInfo.productNftId != productNftId) {
722
+ revert ErrorPolicyServicePolicyProductMismatch(
723
+ policyNftId,
724
+ productNftId,
725
+ policyInfo.productNftId);
726
+ }
589
727
  }
590
728
 
591
729