@etherisc/gif-next 0.0.2-98b8042-396 → 0.0.2-99c2cd1-219

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 (352) hide show
  1. package/README.md +136 -2
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  3. package/artifacts/contracts/components/Component.sol/Component.json +774 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +890 -198
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +4 -0
  7. package/artifacts/contracts/{shared/RegisterableUpgradable.sol/RegisterableUpgradable.json → components/IComponent.sol/IComponent.json} +164 -159
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +725 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +745 -58
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +592 -9
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +802 -251
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +562 -124
  18. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  19. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +764 -0
  20. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  21. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  22. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +954 -287
  24. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +183 -165
  26. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  27. package/artifacts/contracts/instance/Instance.sol/Instance.json +831 -1157
  28. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +211 -144
  30. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +91 -193
  32. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +410 -306
  34. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +297 -112
  36. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  37. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +261 -0
  38. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +4 -0
  39. package/artifacts/contracts/instance/base/{ComponentServiceBase.sol/ComponentServiceBase.json → ComponentService.sol/ComponentService.json} +181 -180
  40. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  42. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  44. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  46. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  47. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +59 -16
  48. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  50. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  52. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  54. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +4 -0
  55. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +858 -0
  56. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +4 -0
  57. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +657 -0
  58. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  59. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1085 -0
  60. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  61. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +661 -0
  62. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +4 -0
  63. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +743 -0
  64. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +4 -0
  65. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +637 -0
  66. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +434 -215
  68. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +316 -83
  70. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +4 -0
  71. package/artifacts/contracts/instance/service/{IComponentOwnerService.sol/IComponentOwnerService.json → IApplicationService.sol/IApplicationService.json} +200 -204
  72. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  73. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +622 -0
  74. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +4 -0
  75. package/artifacts/contracts/{components/BaseComponent.sol/BaseComponent.json → instance/service/IClaimService.sol/IClaimService.json} +154 -83
  76. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +197 -163
  78. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  79. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +572 -0
  80. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +73 -325
  82. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +30 -417
  84. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  85. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +1109 -0
  86. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  87. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +717 -0
  88. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +255 -421
  90. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +297 -104
  92. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +190 -571
  94. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +286 -125
  96. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  97. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  98. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +225 -133
  100. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  101. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +149 -217
  102. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  103. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  104. package/artifacts/contracts/registry/Registry.sol/Registry.json +238 -235
  105. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  106. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  107. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  108. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +195 -322
  109. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  110. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +298 -145
  111. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  112. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +547 -0
  113. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  114. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +141 -53
  115. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  116. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  117. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +41 -3
  118. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  119. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +40 -29
  120. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +4 -0
  121. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +129 -0
  122. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +21 -34
  124. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +4 -0
  125. package/artifacts/contracts/{experiment/inheritance/IB.sol/IB.json → shared/IRegistryLinked.sol/IRegistryLinked.json} +18 -20
  126. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.json +23 -186
  128. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +2 -152
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +120 -27
  132. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +4 -0
  133. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +248 -0
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  135. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +294 -61
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  137. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +129 -51
  138. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +4 -0
  139. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +84 -0
  140. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  141. package/artifacts/contracts/shared/Service.sol/Service.json +120 -174
  142. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  143. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  144. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  145. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  146. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  147. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +2 -152
  148. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +129 -51
  151. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  152. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  153. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  154. package/artifacts/contracts/test/TestService.sol/TestService.json +141 -231
  155. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  157. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +8 -190
  159. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  160. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +4 -0
  164. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +100 -0
  165. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  167. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  170. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  172. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  173. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  174. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  175. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  176. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  177. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +4 -0
  178. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +100 -0
  179. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  181. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  183. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  185. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  186. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  187. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +25 -7
  190. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  193. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  194. package/contracts/components/Component.sol +221 -0
  195. package/contracts/components/Distribution.sol +209 -64
  196. package/contracts/components/IComponent.sol +68 -0
  197. package/contracts/components/IDistributionComponent.sol +59 -3
  198. package/contracts/components/IPoolComponent.sol +93 -36
  199. package/contracts/components/IProductComponent.sol +10 -5
  200. package/contracts/components/Pool.sol +275 -161
  201. package/contracts/components/Product.sol +125 -121
  202. package/contracts/instance/BundleManager.sol +125 -0
  203. package/contracts/instance/Cloneable.sol +46 -0
  204. package/contracts/instance/IInstance.sol +50 -12
  205. package/contracts/instance/IInstanceService.sol +34 -4
  206. package/contracts/instance/Instance.sol +114 -265
  207. package/contracts/instance/InstanceAccessManager.sol +87 -78
  208. package/contracts/instance/InstanceReader.sol +6 -28
  209. package/contracts/instance/InstanceService.sol +398 -107
  210. package/contracts/instance/InstanceServiceManager.sol +6 -9
  211. package/contracts/instance/ObjectManager.sol +84 -0
  212. package/contracts/instance/base/ComponentService.sol +134 -0
  213. package/contracts/instance/module/IAccess.sol +27 -18
  214. package/contracts/instance/module/IBundle.sol +2 -1
  215. package/contracts/instance/module/IPolicy.sol +6 -3
  216. package/contracts/instance/module/ISetup.sol +32 -6
  217. package/contracts/instance/service/ApplicationService.sol +270 -0
  218. package/contracts/instance/service/ApplicationServiceManager.sol +35 -0
  219. package/contracts/instance/service/BundleService.sol +301 -0
  220. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  221. package/contracts/instance/service/ClaimService.sol +151 -0
  222. package/contracts/instance/service/ClaimServiceManager.sol +35 -0
  223. package/contracts/instance/service/DistributionService.sol +216 -27
  224. package/contracts/instance/service/DistributionServiceManager.sol +7 -10
  225. package/contracts/instance/service/IApplicationService.sol +83 -0
  226. package/contracts/instance/service/IBundleService.sol +55 -0
  227. package/contracts/instance/service/IClaimService.sol +61 -0
  228. package/contracts/instance/service/IDistributionService.sol +53 -0
  229. package/contracts/instance/service/IPolicyService.sol +90 -0
  230. package/contracts/instance/service/IPoolService.sol +20 -28
  231. package/contracts/instance/service/IProductService.sol +2 -72
  232. package/contracts/instance/service/PolicyService.sol +490 -0
  233. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  234. package/contracts/instance/service/PoolService.sol +94 -135
  235. package/contracts/instance/service/PoolServiceManager.sol +6 -9
  236. package/contracts/instance/service/ProductService.sol +123 -451
  237. package/contracts/instance/service/ProductServiceManager.sol +2 -2
  238. package/contracts/registry/ChainNft.sol +1 -1
  239. package/contracts/registry/IRegistry.sol +37 -19
  240. package/contracts/registry/IRegistryService.sol +30 -13
  241. package/contracts/registry/Registry.sol +233 -217
  242. package/contracts/registry/RegistryAccessManager.sol +216 -0
  243. package/contracts/registry/RegistryService.sol +96 -171
  244. package/contracts/registry/RegistryServiceManager.sol +21 -39
  245. package/contracts/registry/ReleaseManager.sol +322 -0
  246. package/contracts/registry/TokenRegistry.sol +22 -17
  247. package/contracts/shared/ERC165.sol +14 -12
  248. package/contracts/shared/INftOwnable.sol +11 -10
  249. package/contracts/shared/IPolicyHolder.sol +26 -0
  250. package/contracts/shared/IRegisterable.sol +4 -6
  251. package/contracts/shared/IRegistryLinked.sol +12 -0
  252. package/contracts/shared/IService.sol +2 -1
  253. package/contracts/shared/IVersionable.sol +4 -47
  254. package/contracts/shared/NftOwnable.sol +66 -80
  255. package/contracts/shared/PolicyHolder.sol +81 -0
  256. package/contracts/shared/ProxyManager.sol +100 -25
  257. package/contracts/shared/Registerable.sol +16 -32
  258. package/contracts/shared/RegistryLinked.sol +48 -0
  259. package/contracts/shared/Service.sol +25 -22
  260. package/contracts/shared/TokenHandler.sol +11 -5
  261. package/contracts/shared/Versionable.sol +4 -92
  262. package/contracts/test/TestRegisterable.sol +1 -1
  263. package/contracts/test/TestService.sol +4 -3
  264. package/contracts/types/ClaimId.sol +52 -0
  265. package/contracts/types/DistributorType.sol +2 -2
  266. package/contracts/types/NftId.sol +7 -0
  267. package/contracts/types/NftIdSet.sol +26 -24
  268. package/contracts/types/ObjectType.sol +9 -5
  269. package/contracts/types/PayoutId.sol +54 -0
  270. package/contracts/types/RoleId.sol +19 -14
  271. package/contracts/types/Seconds.sol +54 -0
  272. package/contracts/types/Timestamp.sol +12 -13
  273. package/package.json +3 -3
  274. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +0 -4
  275. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +0 -4
  276. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +0 -280
  277. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +0 -4
  278. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.json +0 -66
  279. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +0 -4
  280. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.json +0 -24
  281. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +0 -4
  282. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.json +0 -42
  283. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +0 -4
  284. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +0 -105
  285. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +0 -4
  286. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +0 -105
  287. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +0 -4
  288. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +0 -128
  289. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +0 -4
  290. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +0 -42
  291. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +0 -4
  292. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +0 -76
  293. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +0 -4
  294. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +0 -89
  295. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +0 -4
  296. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +0 -128
  297. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +0 -4
  298. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +0 -37
  299. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +0 -4
  300. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +0 -4
  301. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +0 -63
  302. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +0 -4
  303. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +0 -59
  304. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +0 -4
  305. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +0 -124
  306. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +0 -4
  307. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +0 -74
  308. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +0 -4
  309. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +0 -124
  310. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +0 -4
  311. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +0 -207
  312. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +0 -4
  313. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +0 -10
  314. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +0 -4
  315. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +0 -10
  316. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  317. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  318. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  319. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
  320. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
  321. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +0 -4
  322. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +0 -4
  323. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +0 -113
  324. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +0 -4
  325. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +0 -827
  326. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +0 -4
  327. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +0 -4
  328. package/contracts/components/BaseComponent.sol +0 -91
  329. package/contracts/components/IBaseComponent.sol +0 -25
  330. package/contracts/experiment/cloning/Cloner.sol +0 -47
  331. package/contracts/experiment/errors/Require.sol +0 -38
  332. package/contracts/experiment/errors/Revert.sol +0 -44
  333. package/contracts/experiment/inheritance/A.sol +0 -53
  334. package/contracts/experiment/inheritance/B.sol +0 -28
  335. package/contracts/experiment/inheritance/C.sol +0 -34
  336. package/contracts/experiment/inheritance/IA.sol +0 -13
  337. package/contracts/experiment/inheritance/IB.sol +0 -10
  338. package/contracts/experiment/inheritance/IC.sol +0 -12
  339. package/contracts/experiment/statemachine/Dummy.sol +0 -27
  340. package/contracts/experiment/statemachine/ISM.sol +0 -25
  341. package/contracts/experiment/statemachine/SM.sol +0 -57
  342. package/contracts/experiment/statemachine/SimpleStateMachine.sol +0 -31
  343. package/contracts/experiment/types/TypeA.sol +0 -47
  344. package/contracts/experiment/types/TypeB.sol +0 -29
  345. package/contracts/instance/AccessManagedSimple.sol +0 -115
  346. package/contracts/instance/AccessManagerSimple.sol +0 -692
  347. package/contracts/instance/IAccessManagerSimple.sol +0 -391
  348. package/contracts/instance/base/ComponentServiceBase.sol +0 -134
  349. package/contracts/instance/base/IInstanceBase.sol +0 -23
  350. package/contracts/instance/service/ComponentOwnerService.sol +0 -317
  351. package/contracts/instance/service/IComponentOwnerService.sol +0 -20
  352. package/contracts/shared/RegisterableUpgradable.sol +0 -16
@@ -0,0 +1,490 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IProductComponent} from "../../components/IProductComponent.sol";
6
+ import {Product} from "../../components/Product.sol";
7
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
8
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
+ import {IInstance} from "../IInstance.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
11
+ import {IRisk} from "../module/IRisk.sol";
12
+ import {IBundle} from "../module/IBundle.sol";
13
+ import {IProductService} from "./IProductService.sol";
14
+ import {ITreasury} from "../module/ITreasury.sol";
15
+ import {ISetup} from "../module/ISetup.sol";
16
+
17
+ import {TokenHandler} from "../../shared/TokenHandler.sol";
18
+
19
+ import {IVersionable} from "../../shared/IVersionable.sol";
20
+ import {Versionable} from "../../shared/Versionable.sol";
21
+
22
+ import {Seconds} from "../../types/Seconds.sol";
23
+ import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
24
+ import {UFixed, UFixedLib} from "../../types/UFixed.sol";
25
+ import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
26
+ import {ObjectType, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
27
+ import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
28
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
29
+ import {Fee, FeeLib} from "../../types/Fee.sol";
30
+ import {ReferralId} from "../../types/Referral.sol";
31
+ import {RiskId} from "../../types/RiskId.sol";
32
+ import {StateId} from "../../types/StateId.sol";
33
+ import {Version, VersionLib} from "../../types/Version.sol";
34
+ //import {RoleId, PRODUCT_OWNER_ROLE} from "../../types/RoleId.sol";
35
+
36
+ import {IService} from "../../shared/IService.sol";
37
+ import {Service} from "../../shared/Service.sol";
38
+ import {ComponentService} from "../base/ComponentService.sol";
39
+ import {IPolicyService} from "./IPolicyService.sol";
40
+ import {InstanceReader} from "../InstanceReader.sol";
41
+ import {IPoolService} from "./IPoolService.sol";
42
+ import {IBundleService} from "./IBundleService.sol";
43
+
44
+
45
+ contract PolicyService is
46
+ ComponentService,
47
+ IPolicyService
48
+ {
49
+ using NftIdLib for NftId;
50
+ using TimestampLib for Timestamp;
51
+
52
+ IPoolService internal _poolService;
53
+ IBundleService internal _bundleService;
54
+
55
+ event LogProductServiceSender(address sender);
56
+
57
+ function _initialize(
58
+ address owner,
59
+ bytes memory data
60
+ )
61
+ internal
62
+ virtual override
63
+ initializer
64
+ {
65
+ address registryAddress;
66
+ address initialOwner;
67
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
68
+
69
+ initializeService(registryAddress, owner);
70
+
71
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
72
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
73
+
74
+ registerInterface(type(IPolicyService).interfaceId);
75
+ }
76
+
77
+
78
+ function getDomain() public pure override(IService, Service) returns(ObjectType) {
79
+ return POLICY();
80
+ }
81
+
82
+
83
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
84
+ IRegistry.ObjectInfo memory productInfo;
85
+ (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
86
+ product = Product(productInfo.objectAddress);
87
+ }
88
+
89
+ // TODO: no access restrictions
90
+ function calculatePremium(
91
+ RiskId riskId,
92
+ uint256 sumInsuredAmount,
93
+ Seconds lifetime,
94
+ bytes memory applicationData,
95
+ NftId bundleNftId,
96
+ ReferralId referralId
97
+ )
98
+ public
99
+ view
100
+ virtual override
101
+ returns (
102
+ uint256 premiumAmount,
103
+ uint256 productFeeAmount,
104
+ uint256 poolFeeAmount,
105
+ uint256 bundleFeeAmount,
106
+ uint256 distributionFeeAmount
107
+ )
108
+ {
109
+ Product product = _getAndVerifyInstanceAndProduct();
110
+ uint256 netPremiumAmount = product.calculateNetPremium(
111
+ sumInsuredAmount,
112
+ riskId,
113
+ lifetime,
114
+ applicationData
115
+ );
116
+
117
+ (
118
+ productFeeAmount,
119
+ poolFeeAmount,
120
+ bundleFeeAmount,
121
+ distributionFeeAmount
122
+ ) = _calculateFeeAmounts(
123
+ netPremiumAmount,
124
+ product,
125
+ bundleNftId,
126
+ referralId
127
+ );
128
+
129
+ premiumAmount = netPremiumAmount + productFeeAmount;
130
+ premiumAmount += poolFeeAmount + bundleFeeAmount;
131
+ premiumAmount += distributionFeeAmount;
132
+ }
133
+
134
+ function _calculateFeeAmounts(
135
+ uint256 netPremiumAmount,
136
+ Product product,
137
+ NftId bundleNftId,
138
+ ReferralId referralId
139
+ )
140
+ internal
141
+ view
142
+ returns (
143
+ uint256 productFeeAmount,
144
+ uint256 poolFeeAmount,
145
+ uint256 bundleFeeAmount,
146
+ uint256 distributionFeeAmount
147
+ )
148
+ {
149
+ InstanceReader instanceReader;
150
+ {
151
+ IInstance instance = product.getInstance();
152
+ instanceReader = instance.getInstanceReader();
153
+ }
154
+
155
+ NftId poolNftId = product.getPoolNftId();
156
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
157
+ require(bundleInfo.poolNftId == poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
158
+
159
+ {
160
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(product.getProductNftId());
161
+ (productFeeAmount,) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
162
+ }
163
+ {
164
+ ISetup.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
165
+ ISetup.PoolInfo memory poolInfo = abi.decode(
166
+ componentInfo.data, (ISetup.PoolInfo));
167
+ (poolFeeAmount,) = FeeLib.calculateFee(poolInfo.poolFee, netPremiumAmount);
168
+ }
169
+ {
170
+ NftId distributionNftId = product.getDistributionNftId();
171
+ ISetup.DistributionSetupInfo memory distributionSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
172
+ (distributionFeeAmount,) = FeeLib.calculateFee(distributionSetupInfo.distributionFee, netPremiumAmount);
173
+ }
174
+
175
+ (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
176
+ }
177
+
178
+ function _getAndVerifyUnderwritingSetup(
179
+ IInstance instance,
180
+ InstanceReader instanceReader,
181
+ IPolicy.PolicyInfo memory policyInfo,
182
+ ISetup.ProductSetupInfo memory productSetupInfo
183
+ )
184
+ internal
185
+ view
186
+ returns (
187
+ NftId poolNftId,
188
+ NftId bundleNftId,
189
+ IBundle.BundleInfo memory bundleInfo,
190
+ uint256 collateralAmount
191
+ )
192
+ {
193
+ // check match between policy and bundle (via pool)
194
+ poolNftId = productSetupInfo.poolNftId;
195
+ bundleNftId = policyInfo.bundleNftId;
196
+ bundleInfo = instanceReader.getBundleInfo(bundleNftId);
197
+ require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
198
+
199
+ // calculate required collateral
200
+ ISetup.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
201
+ ISetup.PoolInfo memory poolInfo = abi.decode(
202
+ componentInfo.data, (ISetup.PoolInfo));
203
+
204
+ // obtain remaining return values
205
+ // TODO required collateral amount should be calculated by pool service, not policy service
206
+ collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
207
+ }
208
+
209
+
210
+ function decline(
211
+ NftId policyNftId
212
+ )
213
+ external
214
+ override
215
+ {
216
+ require(false, "ERROR:PRS-235:NOT_YET_IMPLEMENTED");
217
+ }
218
+
219
+
220
+ /// @dev underwites application which includes the locking of the required collateral from the pool.
221
+ function underwrite(
222
+ NftId applicationNftId, // = policyNftId
223
+ bool requirePremiumPayment,
224
+ Timestamp activateAt
225
+ )
226
+ external
227
+ virtual override
228
+ {
229
+ // check caller is registered product
230
+ IInstance instance;
231
+ InstanceReader instanceReader;
232
+ NftId productNftId;
233
+ {
234
+ IRegistry.ObjectInfo memory productInfo;
235
+ (productInfo, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
236
+ instanceReader = instance.getInstanceReader();
237
+ productNftId = productInfo.nftId;
238
+ }
239
+
240
+ // check policy matches with calling product
241
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(applicationNftId);
242
+ require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
243
+
244
+ // check policy is in state applied
245
+ require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
246
+
247
+ (
248
+ NftId poolNftId,
249
+ NftId bundleNftId,
250
+ IBundle.BundleInfo memory bundleInfo,
251
+ uint256 collateralAmount
252
+ ) = _getAndVerifyUnderwritingSetup(
253
+ instance,
254
+ instanceReader,
255
+ policyInfo,
256
+ instanceReader.getProductSetupInfo(productNftId)
257
+ );
258
+
259
+ StateId newPolicyState = UNDERWRITTEN();
260
+
261
+ // optional activation of policy
262
+ if(activateAt > zeroTimestamp()) {
263
+ newPolicyState = ACTIVE();
264
+ policyInfo.activatedAt = activateAt;
265
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
266
+ }
267
+
268
+ // lock bundle collateral
269
+ uint256 netPremiumAmount = 0; // > 0 if immediate premium payment
270
+
271
+ // optional collection of premium
272
+ if(requirePremiumPayment) {
273
+ netPremiumAmount = _processPremiumByTreasury(
274
+ instance,
275
+ productNftId,
276
+ applicationNftId,
277
+ policyInfo.premiumAmount);
278
+
279
+ policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
280
+ }
281
+
282
+ // lock collateral and update bundle book keeping
283
+ // TODO introduct indirection via pool service?
284
+ // well pool would only need to be involved when a part of the collateral
285
+ // is provided by a "re insurance policy" of the pool
286
+ // but then again the policiy would likely best be attached to the bundle. really? why?
287
+ // retention level: fraction of sum insured that product will cover from pool funds directly
288
+ // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
289
+ // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
290
+ // open points:
291
+ // - do we need a link of a bundle to this policy or is it enough to know that the pool has an active policy?
292
+ // - when to buy such policies and for which amount? manual trigger or link to bundle creation and/or funding?
293
+ bundleInfo = _bundleService.lockCollateral(
294
+ instance,
295
+ applicationNftId,
296
+ bundleNftId,
297
+ collateralAmount,
298
+ netPremiumAmount);
299
+
300
+ instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
301
+
302
+ // also verify/confirm application by pool if necessary
303
+ if(abi.decode(
304
+ instanceReader.getComponentInfo(poolNftId).data,
305
+ (ISetup.PoolInfo)
306
+ ).isVerifyingApplications
307
+ )
308
+ {
309
+ IPoolComponent pool = IPoolComponent(
310
+ getRegistry().getObjectInfo(poolNftId).objectAddress);
311
+
312
+ pool.verifyApplication(
313
+ applicationNftId,
314
+ policyInfo.applicationData,
315
+ bundleNftId,
316
+ bundleInfo.filter,
317
+ collateralAmount);
318
+ }
319
+
320
+ // TODO: add logging
321
+ }
322
+
323
+
324
+ function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
325
+ UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
326
+ UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
327
+ return collateralUFixed.toInt();
328
+ }
329
+
330
+ function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
331
+ // check caller is registered product
332
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
333
+ InstanceReader instanceReader = instance.getInstanceReader();
334
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
335
+
336
+ if (policyInfo.premiumPaidAmount == policyInfo.premiumAmount) {
337
+ revert ErrorIPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
338
+ }
339
+
340
+ uint256 unpaidPremiumAmount = policyInfo.premiumAmount - policyInfo.premiumPaidAmount;
341
+
342
+ uint256 netPremiumAmount = _processPremiumByTreasury(
343
+ instance,
344
+ productInfo.nftId,
345
+ policyNftId,
346
+ unpaidPremiumAmount);
347
+
348
+ policyInfo.premiumPaidAmount += unpaidPremiumAmount;
349
+
350
+ _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
351
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
352
+
353
+ if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
354
+ activate(policyNftId, activateAt);
355
+ }
356
+
357
+ // TODO: add logging
358
+ }
359
+
360
+ function activate(NftId policyNftId, Timestamp activateAt) public override {
361
+ // check caller is registered product
362
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
363
+ InstanceReader instanceReader = instance.getInstanceReader();
364
+
365
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
366
+
367
+ require(
368
+ policyInfo.activatedAt.eqz(),
369
+ "ERROR:PRS-020:ALREADY_ACTIVATED");
370
+
371
+ policyInfo.activatedAt = activateAt;
372
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
373
+
374
+ instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
375
+
376
+ // TODO: add logging
377
+ }
378
+
379
+
380
+ function expire(
381
+ NftId policyNftId
382
+ )
383
+ external
384
+ override
385
+ // solhint-disable-next-line no-empty-blocks
386
+ {
387
+
388
+ }
389
+
390
+ function close(
391
+ NftId policyNftId
392
+ )
393
+ external
394
+ override
395
+ {
396
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
397
+ InstanceReader instanceReader = instance.getInstanceReader();
398
+
399
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
400
+
401
+ if (policyInfo.activatedAt.eqz()) {
402
+ revert ErrorIPolicyServicePolicyNotActivated(policyNftId);
403
+ }
404
+
405
+ StateId state = instanceReader.getPolicyState(policyNftId);
406
+ if (state != ACTIVE()) {
407
+ revert ErrorIPolicyServicePolicyNotActive(policyNftId, state);
408
+ }
409
+
410
+ if (policyInfo.closedAt.gtz()) {
411
+ revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
412
+ }
413
+
414
+ if (policyInfo.premiumAmount != policyInfo.premiumPaidAmount) {
415
+ revert ErrorIPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
416
+ }
417
+
418
+ if (policyInfo.openClaimsCount > 0) {
419
+ revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
420
+ }
421
+
422
+ if (TimestampLib.blockTimestamp().lte(policyInfo.expiredAt) && (policyInfo.payoutAmount < policyInfo.sumInsuredAmount)) {
423
+ revert ErrorIPolicyServicePolicyHasNotExpired(policyNftId, policyInfo.expiredAt);
424
+ }
425
+
426
+ policyInfo.closedAt = TimestampLib.blockTimestamp();
427
+
428
+ _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
429
+ instance.updatePolicy(policyNftId, policyInfo, CLOSED());
430
+ }
431
+
432
+ function _getPoolNftId(
433
+ IInstance instance,
434
+ NftId productNftId
435
+ )
436
+ internal
437
+ view
438
+ returns (NftId poolNftid)
439
+ {
440
+ InstanceReader instanceReader = instance.getInstanceReader();
441
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
442
+ return productSetupInfo.poolNftId;
443
+ }
444
+
445
+
446
+ function _processPremiumByTreasury(
447
+ IInstance instance,
448
+ NftId productNftId,
449
+ NftId policyNftId,
450
+ uint256 premiumAmount
451
+ )
452
+ internal
453
+ returns (uint256 netPremiumAmount)
454
+ {
455
+ // process token transfer(s)
456
+ if(premiumAmount > 0) {
457
+ InstanceReader instanceReader = instance.getInstanceReader();
458
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
459
+ TokenHandler tokenHandler = productSetupInfo.tokenHandler;
460
+ address policyOwner = getRegistry().ownerOf(policyNftId);
461
+
462
+ ISetup.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(productSetupInfo.poolNftId);
463
+ ISetup.PoolInfo memory poolInfo = abi.decode(
464
+ componentInfo.data, (ISetup.PoolInfo));
465
+
466
+ address poolWallet = componentInfo.wallet;
467
+ netPremiumAmount = premiumAmount;
468
+ Fee memory productFee = productSetupInfo.productFee;
469
+
470
+ if (FeeLib.feeIsZero(productFee)) {
471
+ tokenHandler.transfer(
472
+ policyOwner,
473
+ poolWallet,
474
+ premiumAmount
475
+ );
476
+ } else {
477
+ (uint256 productFeeAmount, uint256 netAmount) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
478
+ address productWallet = productSetupInfo.wallet;
479
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premiumAmount) {
480
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premiumAmount);
481
+ }
482
+ tokenHandler.transfer(policyOwner, productWallet, productFeeAmount);
483
+ tokenHandler.transfer(policyOwner, poolWallet, netAmount);
484
+ netPremiumAmount = netAmount;
485
+ }
486
+ }
487
+
488
+ // TODO: add logging
489
+ }
490
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IVersionable} from "../../shared/IVersionable.sol";
5
+ import {ProxyManager} from "../../shared/ProxyManager.sol";
6
+ import {PolicyService} from "./PolicyService.sol";
7
+ import {Registry} from "../../registry/Registry.sol";
8
+ import {RegistryService} from "../../registry/RegistryService.sol";
9
+ import {VersionLib} from "../../types/Version.sol";
10
+
11
+ contract PolicyServiceManager is ProxyManager {
12
+
13
+ PolicyService private _policyService;
14
+
15
+ /// @dev initializes proxy manager with product service implementation
16
+ constructor(
17
+ address registryAddress
18
+ )
19
+ ProxyManager(registryAddress)
20
+ {
21
+ PolicyService svc = new PolicyService();
22
+ bytes memory data = abi.encode(registryAddress, address(this));
23
+ IVersionable versionable = deploy(
24
+ address(svc),
25
+ data);
26
+
27
+ _policyService = PolicyService(address(versionable));
28
+
29
+ // Registry registry = Registry(registryAddress);
30
+ // address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
31
+ // RegistryService registryService = RegistryService(registryServiceAddress);
32
+ // TODO this must have a role or own nft to register service
33
+ //registryService.registerService(_productService);
34
+
35
+ // TODO no nft to link yet
36
+ // link ownership of instance service manager ot nft owner of instance service
37
+ //_linkToNftOwnable(
38
+ // address(registryAddress),
39
+ // address(_productService));
40
+
41
+ // implies that after this constructor call only upgrade functionality is available
42
+ // _isDeployed = true;
43
+ }
44
+
45
+ //--- view functions ----------------------------------------------------//
46
+ function getPolicyService()
47
+ external
48
+ view
49
+ returns (PolicyService policyService)
50
+ {
51
+ return _policyService;
52
+ }
53
+
54
+ }