@etherisc/gif-next 0.0.2-79292f9-089 → 0.0.2-79a4d57-521

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