@etherisc/gif-next 0.0.2-8773a53-517 → 0.0.2-88095ce-205

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