@etherisc/gif-next 0.0.2-9b7f7f5-445 → 0.0.2-9bed517-659

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 (417) 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 +58 -248
  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 -222
  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 +48 -238
  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 -222
  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 +45 -223
  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 +148 -222
  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 +40 -31
  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 +208 -138
  116. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  117. package/artifacts/contracts/pool/Pool.sol/Pool.json +45 -223
  118. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  119. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +283 -355
  120. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  121. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +96 -120
  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 -248
  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 +279 -181
  132. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  133. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +120 -100
  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 +163 -6
  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 +329 -345
  148. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  149. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +108 -104
  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 -248
  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 -211
  185. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  186. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +105 -212
  187. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  188. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +112 -114
  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 -222
  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 +330 -11
  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 -262
  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 -88
  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 -61
  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 -2
  330. package/contracts/instance/module/IPolicy.sol +24 -24
  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 +12 -13
  335. package/contracts/pool/BundleService.sol +42 -32
  336. package/contracts/pool/BundleServiceManager.sol +6 -6
  337. package/contracts/pool/IBundleService.sol +11 -3
  338. package/contracts/pool/IPoolComponent.sol +18 -8
  339. package/contracts/pool/IPoolService.sol +50 -28
  340. package/contracts/pool/Pool.sol +61 -32
  341. package/contracts/pool/PoolService.sol +122 -121
  342. package/contracts/pool/PoolServiceManager.sol +4 -4
  343. package/contracts/product/ApplicationService.sol +50 -29
  344. package/contracts/product/ApplicationServiceManager.sol +4 -4
  345. package/contracts/product/BasicProduct.sol +1 -0
  346. package/contracts/product/ClaimService.sol +251 -87
  347. package/contracts/product/ClaimServiceManager.sol +4 -4
  348. package/contracts/product/IApplicationService.sol +1 -0
  349. package/contracts/product/IClaimService.sol +31 -7
  350. package/contracts/product/IPolicyService.sol +31 -35
  351. package/contracts/product/IPricingService.sol +7 -7
  352. package/contracts/product/IProductComponent.sol +17 -4
  353. package/contracts/product/{IProductService.sol → IRiskService.sol} +1 -1
  354. package/contracts/product/PolicyService.sol +359 -202
  355. package/contracts/product/PolicyServiceManager.sol +4 -4
  356. package/contracts/product/PricingService.sol +47 -47
  357. package/contracts/product/PricingServiceManager.sol +3 -3
  358. package/contracts/product/Product.sol +76 -53
  359. package/contracts/product/{ProductService.sol → RiskService.sol} +7 -10
  360. package/contracts/product/RiskServiceManager.sol +39 -0
  361. package/contracts/registry/ChainNft.sol +65 -32
  362. package/contracts/registry/IRegistry.sol +55 -15
  363. package/contracts/registry/IRegistryService.sol +0 -9
  364. package/contracts/registry/Registry.sol +336 -197
  365. package/contracts/registry/RegistryAdmin.sol +150 -51
  366. package/contracts/registry/RegistryService.sol +55 -48
  367. package/contracts/registry/RegistryServiceManager.sol +2 -2
  368. package/contracts/registry/ReleaseRegistry.sol +12 -6
  369. package/contracts/registry/ServiceAuthorizationV3.sol +6 -8
  370. package/contracts/shared/Component.sol +17 -36
  371. package/contracts/shared/ComponentService.sol +20 -30
  372. package/contracts/shared/ComponentServiceManager.sol +8 -5
  373. package/contracts/shared/ComponentVerifyingService.sol +2 -3
  374. package/contracts/shared/ContractLib.sol +38 -0
  375. package/contracts/shared/IComponent.sol +4 -4
  376. package/contracts/shared/IInstanceLinkedComponent.sol +8 -15
  377. package/contracts/shared/INftOwnable.sol +2 -0
  378. package/contracts/shared/IPolicyHolder.sol +12 -22
  379. package/contracts/shared/InitializableERC165.sol +2 -2
  380. package/contracts/shared/InstanceLinkedComponent.sol +5 -6
  381. package/contracts/shared/NftOwnable.sol +21 -5
  382. package/contracts/shared/PolicyHolder.sol +15 -52
  383. package/contracts/shared/Registerable.sol +4 -4
  384. package/contracts/shared/RegistryLinked.sol +3 -2
  385. package/contracts/shared/Service.sol +16 -11
  386. package/contracts/shared/TokenHandler.sol +100 -19
  387. package/contracts/shared/TokenHandlerDeployerLib.sol +12 -0
  388. package/contracts/staking/IStaking.sol +2 -1
  389. package/contracts/staking/IStakingService.sol +0 -3
  390. package/contracts/staking/StakeManagerLib.sol +18 -25
  391. package/contracts/staking/Staking.sol +11 -29
  392. package/contracts/staking/StakingManager.sol +8 -6
  393. package/contracts/staking/StakingReader.sol +12 -5
  394. package/contracts/staking/StakingService.sol +11 -29
  395. package/contracts/staking/StakingServiceManager.sol +2 -2
  396. package/contracts/staking/TargetManagerLib.sol +7 -3
  397. package/contracts/type/Amount.sol +15 -0
  398. package/contracts/type/ClaimId.sol +6 -1
  399. package/contracts/type/NftId.sol +1 -0
  400. package/contracts/type/ObjectType.sol +16 -11
  401. package/contracts/type/PayoutId.sol +10 -10
  402. package/contracts/type/RiskId.sol +15 -1
  403. package/contracts/type/Seconds.sol +8 -0
  404. package/contracts/type/StateId.sol +1 -0
  405. package/contracts/type/UFixed.sol +4 -0
  406. package/contracts/upgradeability/ProxyManager.sol +67 -34
  407. package/contracts/upgradeability/Versionable.sol +2 -2
  408. package/package.json +2 -1
  409. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +0 -4
  410. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +0 -4
  411. package/artifacts/contracts/product/ProductService.sol/ProductService.json +0 -708
  412. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +0 -4
  413. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +0 -702
  414. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.dbg.json +0 -4
  415. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.json +0 -39
  416. package/contracts/product/ProductServiceManager.sol +0 -39
  417. package/contracts/shared/InitializableCustom.sol +0 -177
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {IRegistry} from "../registry/IRegistry.sol";
5
7
  import {Product} from "./Product.sol";
6
8
  import {IComponents} from "../instance/module/IComponents.sol";
@@ -12,13 +14,14 @@ import {TokenHandler} from "../shared/TokenHandler.sol";
12
14
  import {Amount, AmountLib} from "../type/Amount.sol";
13
15
  import {Timestamp, TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";
14
16
  import {ObjectType, APPLICATION, COMPONENT, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM, PRICE} from "../type/ObjectType.sol";
15
- 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";
16
18
  import {NftId, NftIdLib} from "../type/NftId.sol";
17
19
  import {ReferralId} from "../type/Referral.sol";
18
20
  import {StateId} from "../type/StateId.sol";
19
21
  import {VersionPart} from "../type/Version.sol";
20
22
 
21
23
  import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";
24
+ import {ContractLib} from "../shared/ContractLib.sol";
22
25
  import {IApplicationService} from "./IApplicationService.sol";
23
26
  import {IBundleService} from "../pool/IBundleService.sol";
24
27
  import {IClaimService} from "./IClaimService.sol";
@@ -26,6 +29,7 @@ import {IComponentService} from "../shared/IComponentService.sol";
26
29
  import {IDistributionService} from "../distribution/IDistributionService.sol";
27
30
  import {InstanceReader} from "../instance/InstanceReader.sol";
28
31
  import {InstanceStore} from "../instance/InstanceStore.sol";
32
+ import {IPolicyHolder} from "../shared/IPolicyHolder.sol";
29
33
  import {IPolicyService} from "./IPolicyService.sol";
30
34
  import {IPoolService} from "../pool/IPoolService.sol";
31
35
  import {IPricingService} from "./IPricingService.sol";
@@ -45,8 +49,6 @@ contract PolicyService is
45
49
  IPoolService internal _poolService;
46
50
  IPricingService internal _pricingService;
47
51
 
48
- event LogProductServiceSender(address sender);
49
-
50
52
  function _initialize(
51
53
  address owner,
52
54
  bytes memory data
@@ -56,12 +58,11 @@ contract PolicyService is
56
58
  initializer
57
59
  {
58
60
  (
59
- address registryAddress,,
60
- //address managerAddress
61
+ address registryAddress,
61
62
  address authority
62
- ) = abi.decode(data, (address, address, address));
63
+ ) = abi.decode(data, (address, address));
63
64
 
64
- initializeService(registryAddress, authority, owner);
65
+ _initializeService(registryAddress, authority, owner);
65
66
 
66
67
  VersionPart majorVersion = getVersion().toMajorPart();
67
68
  _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
@@ -72,22 +73,16 @@ contract PolicyService is
72
73
  _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
73
74
  _pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion));
74
75
 
75
- registerInterface(type(IPolicyService).interfaceId);
76
+ _registerInterface(type(IPolicyService).interfaceId);
76
77
  }
77
78
 
78
79
 
79
- function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
80
- IRegistry.ObjectInfo memory productInfo;
81
- (, productInfo,) = _getAndVerifyActiveComponent(PRODUCT());
82
- product = Product(productInfo.objectAddress);
83
- }
84
-
85
-
86
80
  function decline(
87
81
  NftId applicationNftId // = policyNftId
88
82
  )
89
83
  external
90
- virtual override
84
+ virtual
85
+ nonReentrant()
91
86
  {
92
87
  (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
93
88
  InstanceReader instanceReader = instance.getInstanceReader();
@@ -115,16 +110,15 @@ contract PolicyService is
115
110
  emit LogPolicyServicePolicyDeclined(applicationNftId);
116
111
  }
117
112
 
118
- event LogDebug(uint idx, string message);
119
113
 
120
- /// @dev underwites application which includes the locking of the required collateral from the pool.
121
- function collateralize(
114
+ /// @inheritdoc IPolicyService
115
+ function createPolicy(
122
116
  NftId applicationNftId, // = policyNftId
123
- bool requirePremiumPayment,
124
117
  Timestamp activateAt
125
118
  )
126
119
  external
127
- virtual override
120
+ virtual
121
+ nonReentrant()
128
122
  {
129
123
  // check caller is registered product
130
124
  (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
@@ -144,13 +138,8 @@ contract PolicyService is
144
138
  productNftId);
145
139
  }
146
140
 
147
- StateId newPolicyState = COLLATERALIZED();
148
-
149
141
  // actual collateralizaion
150
- (
151
- Amount localCollateralAmount,
152
- Amount totalCollateralAmount
153
- ) = _poolService.lockCollateral(
142
+ _poolService.lockCollateral(
154
143
  instance,
155
144
  address(instanceReader.getComponentInfo(productNftId).token),
156
145
  productNftId,
@@ -160,39 +149,61 @@ contract PolicyService is
160
149
 
161
150
  // optional activation of policy
162
151
  if(activateAt > zeroTimestamp()) {
163
- newPolicyState = ACTIVE();
164
- applicationInfo.activatedAt = activateAt;
165
- applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
166
- }
167
-
168
- // optional collection of premium
169
- if(requirePremiumPayment) {
170
- Amount premiumPaidAmount = _calculateAndCollectPremium(
171
- instance,
172
- applicationNftId,
173
- applicationInfo);
174
-
175
- applicationInfo.premiumPaidAmount = premiumPaidAmount;
152
+ applicationInfo = _activate(
153
+ applicationNftId,
154
+ applicationInfo,
155
+ activateAt);
176
156
  }
177
157
 
178
- // store updated policy info
158
+ // update policy and set state to collateralized
179
159
  instance.getInstanceStore().updatePolicy(
180
160
  applicationNftId,
181
161
  applicationInfo,
182
- newPolicyState);
162
+ COLLATERALIZED());
163
+
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);
173
+
174
+ instance.getInstanceStore().createPremium(
175
+ applicationNftId,
176
+ premium);
177
+
178
+ // update referral counter
179
+ {
180
+ IComponents.ProductInfo memory productInfo = instanceReader.getProductInfo(productNftId);
181
+
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
+ }
187
+ }
188
+
189
+ // log policy creation before interactions with token and policy holder
190
+ emit LogPolicyServicePolicyCreated(applicationNftId, premium.premiumAmount, activateAt);
183
191
 
184
192
  // TODO add calling pool contract if it needs to validate application
185
193
 
186
- // TODO: add logging
194
+ // callback to policy holder if applicable
195
+ _policyHolderPolicyActivated(applicationNftId, activateAt);
187
196
  }
188
197
 
189
198
 
199
+ /// @inheritdoc IPolicyService
190
200
  function collectPremium(
191
201
  NftId policyNftId,
192
202
  Timestamp activateAt
193
203
  )
194
204
  external
195
205
  virtual
206
+ nonReentrant()
196
207
  {
197
208
  // check caller is registered product
198
209
  (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
@@ -200,70 +211,75 @@ contract PolicyService is
200
211
  StateId stateId = instanceReader.getPolicyState(policyNftId);
201
212
 
202
213
  // check policy is in state collateralized or active
203
- if (!(stateId == COLLATERALIZED() || stateId == ACTIVE())) {
204
- revert ErrorPolicyServicePolicyStateNotCollateralizedOrApplied(policyNftId);
214
+ if (!(stateId == COLLATERALIZED())) {
215
+ revert ErrorPolicyServicePolicyStateNotCollateralized(policyNftId);
205
216
  }
206
217
 
207
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
208
-
209
218
  // check if premium is already collected
210
- if (policyInfo.premiumPaidAmount.gtz()) {
211
- revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
219
+ if (instanceReader.getPremiumInfoState(policyNftId) == PAID()) {
220
+ revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId);
212
221
  }
213
222
 
214
- policyInfo.premiumPaidAmount = _calculateAndCollectPremium(
215
- instance,
216
- policyNftId,
217
- 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);
231
+
232
+ // optionally activate policy
233
+ if(activateAt.gtz()) {
234
+ policyInfo = _activate(policyNftId, policyInfo, activateAt);
235
+ }
218
236
 
219
237
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
238
+ instance.getInstanceStore().updatePremiumState(policyNftId, PAID());
220
239
 
221
- if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
222
- activate(policyNftId, activateAt);
223
- }
240
+ // log premium collection before interactions with token
241
+ emit LogPolicyServicePolicyPremiumCollected(policyNftId, premium.premiumAmount);
224
242
 
225
- // TODO: add logging
243
+ _transferFunds(instanceReader, policyNftId, policyInfo.productNftId, premium);
226
244
  }
227
245
 
228
- function activate(NftId policyNftId, Timestamp activateAt) public override {
246
+ /// @inheritdoc IPolicyService
247
+ function activate(NftId policyNftId, Timestamp activateAt)
248
+ external
249
+ virtual
250
+ nonReentrant()
251
+ {
229
252
  // check caller is registered product
230
253
  (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
231
254
  InstanceReader instanceReader = instance.getInstanceReader();
232
255
 
233
256
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
257
+ policyInfo = _activate(policyNftId, policyInfo, activateAt);
234
258
 
235
- require(
236
- policyInfo.activatedAt.eqz(),
237
- "ERROR:PRS-020:ALREADY_ACTIVATED");
238
-
239
- policyInfo.activatedAt = activateAt;
240
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
259
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
241
260
 
242
- instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, ACTIVE());
261
+ // log policy activation before interactions with policy holder
262
+ emit LogPolicyServicePolicyActivated(policyNftId, activateAt);
243
263
 
244
- // TODO: add logging
264
+ // callback to policy holder if applicable
265
+ _policyHolderPolicyActivated(policyNftId, activateAt);
245
266
  }
246
267
 
268
+
247
269
  /// @inheritdoc IPolicyService
248
270
  function expire(
249
271
  NftId policyNftId,
250
272
  Timestamp expireAt
251
273
  )
252
274
  external
253
- override
254
275
  virtual
255
- returns (Timestamp)
276
+ nonReentrant()
277
+ returns (Timestamp expiredAt)
256
278
  {
257
279
  (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
258
- InstanceReader instanceReader = instance.getInstanceReader();
259
-
260
- // check policy is in state applied
261
- if (instanceReader.getPolicyState(policyNftId) != ACTIVE()) {
262
- revert ErrorIPolicyServicePolicyNotActive(policyNftId, instanceReader.getPolicyState(policyNftId));
263
- }
264
-
280
+
265
281
  // check policy matches with calling product
266
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
282
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
267
283
  if(policyInfo.productNftId != productNftId) {
268
284
  revert ErrorPolicyServicePolicyProductMismatch(
269
285
  policyNftId,
@@ -271,195 +287,200 @@ contract PolicyService is
271
287
  productNftId);
272
288
  }
273
289
 
274
- if (expireAt.eqz()) {
275
- 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);
276
330
  }
277
331
 
278
- // check preconditions
279
- if (expireAt >= policyInfo.expiredAt) {
280
- 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();
281
338
  }
282
- if (expireAt < TimestampLib.blockTimestamp()) {
283
- 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);
284
343
  }
285
- if (policyInfo.openClaimsCount > 0) {
286
- revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
344
+ if (expiredAt < TimestampLib.blockTimestamp()) {
345
+ revert ErrorPolicyServicePolicyExpirationTooEarly(policyNftId, TimestampLib.blockTimestamp(), expireAt);
287
346
  }
288
347
 
289
- policyInfo.expiredAt = expireAt;
348
+ // update policyInfo with new expiredAt timestamp
349
+ Timestamp originalExpiredAt = policyInfo.expiredAt;
350
+ policyInfo.expiredAt = expiredAt;
290
351
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
291
352
 
292
- emit LogPolicyServicePolicyExpirationUpdated(policyNftId, expireAt);
353
+ emit LogPolicyServicePolicyExpirationUpdated(policyNftId, originalExpiredAt, expiredAt);
293
354
 
294
- return expireAt;
355
+ // callback to policy holder if applicable
356
+ _policyHolderPolicyExpired(policyNftId, expiredAt);
295
357
  }
296
358
 
359
+
297
360
  function close(
298
361
  NftId policyNftId
299
362
  )
300
363
  external
301
- override
364
+ virtual
365
+ nonReentrant()
302
366
  {
303
367
  (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
304
368
  InstanceReader instanceReader = instance.getInstanceReader();
305
369
 
370
+ // check that policy has been activated
306
371
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
307
-
308
- if (policyInfo.activatedAt.eqz()) {
309
- revert ErrorIPolicyServicePolicyNotActivated(policyNftId);
310
- }
311
-
312
- StateId state = instanceReader.getPolicyState(policyNftId);
313
- if (state != ACTIVE()) {
314
- revert ErrorIPolicyServicePolicyNotActive(policyNftId, state);
372
+ StateId policyState = instanceReader.getPolicyState(policyNftId);
373
+ if (!_policyHasBeenActivated(policyState, policyInfo)) {
374
+ revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
315
375
  }
316
376
 
377
+ // check that policy has not already been closed
317
378
  if (policyInfo.closedAt.gtz()) {
318
- revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
319
- }
320
-
321
- // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
322
- if (!(policyInfo.premiumAmount == policyInfo.premiumPaidAmount)) {
323
- revert ErrorPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
379
+ revert ErrorPolicyServicePolicyAlreadyClosed(policyNftId);
324
380
  }
325
381
 
382
+ // check that policy does not have any open claims
326
383
  if (policyInfo.openClaimsCount > 0) {
327
- revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
384
+ revert ErrorPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
328
385
  }
329
386
 
330
- 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
+ }
331
392
 
393
+ // release (remaining) collateral that was blocked by policy
332
394
  _poolService.releaseCollateral(
333
395
  instance,
334
396
  address(instanceReader.getComponentInfo(policyInfo.productNftId).token),
335
397
  policyNftId,
336
398
  policyInfo);
337
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();
338
404
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
405
+
406
+ emit LogPolicyServicePolicyClosed(policyNftId);
339
407
  }
340
408
 
341
409
 
342
- function _calculateAndCollectPremium(
410
+ /// @dev calculates the premium and updates all counters in the other services
411
+ function _processPremium(
343
412
  IInstance instance,
344
413
  NftId applicationNftId,
345
- IPolicy.PolicyInfo memory applicationInfo
414
+ IPolicy.PolicyInfo memory applicationInfo,
415
+ IPolicy.PremiumInfo memory premium
346
416
  )
347
417
  internal
348
418
  virtual
349
- returns (
350
- Amount premiumPaidAmount
351
- )
352
419
  {
353
420
  NftId productNftId = applicationInfo.productNftId;
354
-
355
- // calculate premium details
356
- IPolicy.Premium memory premium = _pricingService.calculatePremium(
357
- productNftId,
358
- applicationInfo.riskId,
359
- applicationInfo.sumInsuredAmount,
360
- applicationInfo.lifetime,
361
- applicationInfo.applicationData,
362
- applicationInfo.bundleNftId,
363
- applicationInfo.referralId);
364
-
365
-
366
- // update financials and transfer premium tokens
367
- premiumPaidAmount = _processAndCollect(
368
- instance,
369
- productNftId,
370
- applicationNftId,
371
- applicationInfo.premiumAmount,
372
- applicationInfo.bundleNftId,
373
- applicationInfo.referralId,
374
- premium);
375
- }
376
-
377
-
378
- function _processAndCollect(
379
- IInstance instance,
380
- NftId productNftId,
381
- NftId policyNftId,
382
- Amount premiumExpectedAmount,
383
- NftId bundleNftId,
384
- ReferralId referralId,
385
- IPolicy.Premium memory premium
386
- )
387
- internal
388
- virtual
389
- returns (Amount premiumPaidAmount)
390
- {
391
421
  InstanceReader instanceReader = instance.getInstanceReader();
392
- TokenHandler tokenHandler = instanceReader.getComponentInfo(productNftId).tokenHandler;
393
- address policyHolder = getRegistry().ownerOf(policyNftId);
394
- premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
395
422
 
396
- _checkPremiumBalanceAndAllowance(
397
- tokenHandler,
398
- policyHolder,
399
- premiumExpectedAmount,
400
- premiumPaidAmount);
423
+ // check if premium balance and allowance of policy holder is sufficient
424
+ {
425
+ TokenHandler tokenHandler = _getTokenHandler(instanceReader, productNftId);
426
+ address policyHolder = getRegistry().ownerOf(applicationNftId);
427
+
428
+ _checkPremiumBalanceAndAllowance(
429
+ tokenHandler.getToken(),
430
+ address(tokenHandler),
431
+ policyHolder,
432
+ premium.premiumAmount);
433
+ }
401
434
 
402
- _processSaleAndTransferFunds(
435
+ // update the counters
436
+ _processSale(
403
437
  instanceReader,
404
438
  instance.getInstanceStore(),
405
- tokenHandler,
406
- policyHolder,
407
439
  productNftId,
408
- bundleNftId,
409
- referralId,
440
+ applicationInfo.bundleNftId,
441
+ applicationInfo.referralId,
410
442
  premium);
411
443
  }
412
444
 
413
-
414
- function _checkPremiumBalanceAndAllowance(
415
- TokenHandler tokenHandler,
416
- address policyHolder,
417
- Amount premiumExpectedAmount,
418
- Amount premiumPaidAmount
445
+ function _activate(
446
+ NftId policyNftId,
447
+ IPolicy.PolicyInfo memory policyInfo,
448
+ Timestamp activateAt
419
449
  )
420
450
  internal
421
451
  virtual
422
- view
452
+ view
453
+ returns (IPolicy.PolicyInfo memory)
423
454
  {
424
- // TODO decide how to handle this properly
425
- // not clear if this is the best way to handle this
426
- if (premiumExpectedAmount < premiumPaidAmount) {
427
- revert ErrorPolicyServicePremiumHigherThanExpected(premiumExpectedAmount, premiumPaidAmount);
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
- uint256 premiumAmount = premiumPaidAmount.toInt();
431
- uint256 balance = tokenHandler.getToken().balanceOf(policyHolder);
432
- uint256 allowance = tokenHandler.getToken().allowance(policyHolder, address(tokenHandler));
433
-
434
- if (balance < premiumAmount) {
435
- revert ErrorPolicyServiceBalanceInsufficient(policyHolder, premiumAmount, balance);
460
+ // ignore if policy has already been activated and activateAt is the same
461
+ if (policyInfo.activatedAt == activateAt) {
462
+ return policyInfo;
436
463
  }
437
464
 
438
- if (allowance < premiumAmount) {
439
- revert ErrorPolicyServiceAllowanceInsufficient(policyHolder, address(tokenHandler), premiumAmount, allowance);
440
- }
441
- }
465
+ policyInfo.activatedAt = activateAt;
466
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
442
467
 
468
+ return policyInfo;
469
+ }
443
470
 
444
- function _processSaleAndTransferFunds(
471
+ /// @dev update counters by calling the involved services
472
+ function _processSale(
445
473
  InstanceReader instanceReader,
446
474
  InstanceStore instanceStore,
447
- TokenHandler tokenHandler,
448
- address policyHolder,
449
475
  NftId productNftId,
450
476
  NftId bundleNftId,
451
477
  ReferralId referralId,
452
- IPolicy.Premium memory premium
478
+ IPolicy.PremiumInfo memory premium
453
479
  )
454
480
  internal
455
481
  virtual
456
482
  {
457
- (
458
- NftId distributionNftId,
459
- address distributionWallet,
460
- address poolWallet,
461
- address productWallet
462
- ) = _getDistributionNftAndWallets(
483
+ (NftId distributionNftId, , , ) = _getDistributionNftAndWallets(
463
484
  instanceReader,
464
485
  productNftId);
465
486
 
@@ -467,28 +488,156 @@ contract PolicyService is
467
488
  _componentService.increaseProductFees(
468
489
  instanceStore,
469
490
  productNftId,
470
- AmountLib.toAmount(premium.productFeeVarAmount + premium.productFeeFixAmount));
491
+ premium.productFeeVarAmount + premium.productFeeFixAmount);
471
492
 
472
493
  // update distribution fees and distributor commission and pool fees
473
- _distributionService.processSale(
474
- distributionNftId,
475
- referralId,
476
- 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
+ }
477
500
 
478
501
  // update pool and bundle fees
479
502
  _poolService.processSale(
480
503
  bundleNftId,
481
504
  premium);
505
+ }
506
+
507
+
508
+ /// @dev transfer the premium to the wallets the premium is distributed to
509
+ function _transferFunds(
510
+ InstanceReader instanceReader,
511
+ NftId policyNftId,
512
+ NftId productNftId,
513
+ IPolicy.PremiumInfo memory premium
514
+ )
515
+ internal
516
+ virtual
517
+ {
518
+ TokenHandler tokenHandler = _getTokenHandler(instanceReader, productNftId);
519
+ address policyHolder = getRegistry().ownerOf(policyNftId);
520
+
521
+ (
522
+ ,
523
+ address distributionWallet,
524
+ address poolWallet,
525
+ address productWallet
526
+ ) = _getDistributionNftAndWallets(
527
+ instanceReader,
528
+ productNftId);
529
+
530
+ tokenHandler.collectTokensToThreeRecipients(
531
+ policyHolder,
532
+ productWallet,
533
+ premium.productFeeAmount,
534
+ distributionWallet,
535
+ premium.distributionFeeAndCommissionAmount,
536
+ poolWallet,
537
+ premium.poolPremiumAndFeeAmount);
538
+ }
539
+
482
540
 
483
- // TODO: centralize token handling (issue #471)
484
- // transfer premium amounts to target wallets
485
- tokenHandler.transfer(policyHolder, productWallet, premium.productFeeAmount);
486
- tokenHandler.transfer(policyHolder, distributionWallet, premium.distributionFeeAndCommissionAmount);
487
- tokenHandler.transfer(policyHolder, poolWallet, premium.poolPremiumAndFeeAmount);
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
+ }
488
579
  }
489
580
 
490
581
 
491
- function _getTokenHandlerAndProductWallet(
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
+ }
623
+ }
624
+
625
+
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(
492
641
  InstanceReader instanceReader,
493
642
  NftId productNftId
494
643
  )
@@ -502,6 +651,7 @@ contract PolicyService is
502
651
  tokenHandler = instanceReader.getComponentInfo(productNftId).tokenHandler;
503
652
  }
504
653
 
654
+
505
655
  function _getDistributionNftAndWallets(
506
656
  InstanceReader instanceReader,
507
657
  NftId productNftId
@@ -523,6 +673,13 @@ contract PolicyService is
523
673
  }
524
674
 
525
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
+
526
683
  function _getDomain() internal pure override returns(ObjectType) {
527
684
  return POLICY();
528
685
  }