@etherisc/gif-next 0.0.2-ebbe63d → 0.0.2-ebf1a6b-485

Sign up to get free protection for your applications and to get access to all the features.
Files changed (329) hide show
  1. package/README.md +524 -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 +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +1279 -0
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +447 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +829 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +4 -0
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +1029 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +4 -0
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +672 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +1451 -0
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  17. package/artifacts/contracts/components/Product.sol/Product.json +1099 -0
  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/Cloneable.sol/Cloneable.json +185 -0
  22. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +2422 -0
  24. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +509 -0
  26. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  27. package/artifacts/contracts/instance/Instance.sol/Instance.json +3326 -0
  28. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +4 -0
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +984 -0
  30. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +4 -0
  31. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +1355 -0
  32. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +4 -0
  33. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +1046 -0
  34. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  35. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +693 -0
  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/ComponentService.sol/ComponentService.json +552 -0
  40. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +4 -0
  41. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +429 -0
  42. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  43. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.json +115 -0
  44. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +4 -0
  45. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +502 -0
  46. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +4 -0
  47. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +169 -0
  48. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +4 -0
  49. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +254 -0
  50. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +4 -0
  51. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.json +10 -0
  52. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +4 -0
  53. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.json +10 -0
  54. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +4 -0
  55. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.json +10 -0
  56. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +4 -0
  57. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.json +10 -0
  58. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +4 -0
  59. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.json +10 -0
  60. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +4 -0
  61. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.json +10 -0
  62. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +4 -0
  63. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +968 -0
  64. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +4 -0
  65. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +665 -0
  66. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  67. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1096 -0
  68. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  69. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +661 -0
  70. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +4 -0
  71. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +754 -0
  72. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +4 -0
  73. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +637 -0
  74. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  75. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +1553 -0
  76. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  77. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +793 -0
  78. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +4 -0
  79. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +556 -0
  80. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  81. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +633 -0
  82. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +4 -0
  83. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +409 -0
  84. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  85. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +858 -0
  86. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  87. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +519 -0
  88. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +4 -0
  89. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +347 -0
  90. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +4 -0
  91. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +384 -0
  92. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  93. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +1000 -0
  94. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  95. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +689 -0
  96. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  97. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +727 -0
  98. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  99. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +649 -0
  100. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  101. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +777 -0
  102. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  103. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +649 -0
  104. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  105. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +771 -0
  106. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  107. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +737 -0
  108. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +4 -0
  109. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +890 -0
  110. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +4 -0
  111. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +34 -0
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +839 -0
  114. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  115. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  116. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +4 -0
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +1177 -0
  118. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +4 -0
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +670 -0
  120. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  121. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +547 -0
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +498 -0
  124. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +4 -0
  125. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.json +107 -0
  126. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +4 -0
  127. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +73 -0
  128. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +4 -0
  129. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +138 -0
  130. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +4 -0
  131. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +129 -0
  132. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +4 -0
  133. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +188 -0
  134. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +4 -0
  135. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.json +48 -0
  136. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  137. package/artifacts/contracts/shared/IService.sol/IService.json +269 -0
  138. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +4 -0
  139. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +55 -0
  140. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +4 -0
  141. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +251 -0
  142. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +4 -0
  143. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +248 -0
  144. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +4 -0
  145. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +582 -0
  146. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +4 -0
  147. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +352 -0
  148. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +4 -0
  149. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +84 -0
  150. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  151. package/artifacts/contracts/shared/Service.sol/Service.json +425 -0
  152. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  153. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +96 -0
  154. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +4 -0
  155. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +129 -0
  156. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +4 -0
  157. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +78 -0
  158. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +4 -0
  159. package/artifacts/contracts/test/TestFee.sol/TestFee.json +119 -0
  160. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +4 -0
  161. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +383 -0
  162. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +4 -0
  163. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +116 -0
  164. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +4 -0
  165. package/artifacts/contracts/test/TestService.sol/TestService.json +521 -0
  166. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +4 -0
  167. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +376 -0
  168. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +4 -0
  169. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +218 -0
  170. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +4 -0
  171. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +104 -0
  172. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +4 -0
  173. package/artifacts/contracts/test/Usdc.sol/USDC.json +376 -0
  174. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +4 -0
  175. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.json +10 -0
  176. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  177. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  178. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  179. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  180. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +4 -0
  181. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +100 -0
  182. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +4 -0
  183. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +104 -0
  184. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +4 -0
  185. package/artifacts/contracts/types/Fee.sol/FeeLib.json +257 -0
  186. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +4 -0
  187. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +125 -0
  188. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  189. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +153 -0
  190. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +4 -0
  191. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +33 -0
  192. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +4 -0
  193. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.json +100 -0
  194. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  195. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  196. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +4 -0
  197. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +100 -0
  198. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +4 -0
  199. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +123 -0
  200. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  201. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  202. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
  203. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +156 -0
  204. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  205. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  206. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  207. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  208. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  209. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +267 -0
  210. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  211. package/artifacts/contracts/types/UFixed.sol/MathLib.json +10 -0
  212. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +4 -0
  213. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +479 -0
  214. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +4 -0
  215. package/artifacts/contracts/types/Version.sol/VersionLib.json +177 -0
  216. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +4 -0
  217. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +49 -0
  218. package/contracts/components/Component.sol +221 -0
  219. package/contracts/components/Distribution.sol +293 -0
  220. package/contracts/components/IComponent.sol +68 -0
  221. package/contracts/components/IDistributionComponent.sol +79 -0
  222. package/contracts/components/IPoolComponent.sol +151 -0
  223. package/contracts/components/IProductComponent.sol +40 -0
  224. package/contracts/components/Pool.sol +378 -0
  225. package/contracts/components/Product.sol +289 -0
  226. package/contracts/instance/BundleManager.sol +125 -0
  227. package/contracts/instance/Cloneable.sol +46 -0
  228. package/contracts/instance/IInstance.sol +92 -0
  229. package/contracts/instance/IInstanceService.sol +59 -0
  230. package/contracts/instance/Instance.sol +291 -0
  231. package/contracts/instance/InstanceAccessManager.sol +297 -0
  232. package/contracts/instance/InstanceReader.sol +293 -0
  233. package/contracts/instance/InstanceService.sol +490 -0
  234. package/contracts/instance/InstanceServiceManager.sol +54 -0
  235. package/contracts/instance/ObjectManager.sol +84 -0
  236. package/contracts/instance/base/ComponentService.sol +134 -0
  237. package/contracts/instance/base/IKeyValueStore.sol +49 -0
  238. package/contracts/instance/base/ILifecycle.sol +30 -0
  239. package/contracts/instance/base/KeyValueStore.sol +172 -0
  240. package/contracts/instance/base/Lifecycle.sol +100 -0
  241. package/contracts/instance/module/IAccess.sol +47 -0
  242. package/contracts/instance/module/IBundle.sol +21 -0
  243. package/contracts/instance/module/IDistribution.sol +41 -0
  244. package/contracts/instance/module/IPolicy.sol +72 -0
  245. package/contracts/instance/module/IRisk.sol +11 -0
  246. package/contracts/instance/module/ISetup.sol +46 -0
  247. package/contracts/instance/module/ITreasury.sol +23 -0
  248. package/contracts/instance/service/ApplicationService.sol +349 -0
  249. package/contracts/instance/service/ApplicationServiceManager.sol +35 -0
  250. package/contracts/instance/service/BundleService.sol +299 -0
  251. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  252. package/contracts/instance/service/ClaimService.sol +151 -0
  253. package/contracts/instance/service/ClaimServiceManager.sol +35 -0
  254. package/contracts/instance/service/DistributionService.sol +394 -0
  255. package/contracts/instance/service/DistributionServiceManager.sol +51 -0
  256. package/contracts/instance/service/IApplicationService.sol +82 -0
  257. package/contracts/instance/service/IBundleService.sol +55 -0
  258. package/contracts/instance/service/IClaimService.sol +61 -0
  259. package/contracts/instance/service/IDistributionService.sol +86 -0
  260. package/contracts/instance/service/IPolicyService.sol +70 -0
  261. package/contracts/instance/service/IPoolService.sol +20 -0
  262. package/contracts/instance/service/IProductService.sol +40 -0
  263. package/contracts/instance/service/PolicyService.sol +402 -0
  264. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  265. package/contracts/instance/service/PoolService.sol +109 -0
  266. package/contracts/instance/service/PoolServiceManager.sol +51 -0
  267. package/contracts/instance/service/ProductService.sol +233 -0
  268. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  269. package/contracts/registry/ChainNft.sol +202 -0
  270. package/contracts/registry/IRegistry.sol +99 -0
  271. package/contracts/registry/IRegistryService.sol +67 -0
  272. package/contracts/registry/ITransferInterceptor.sol +6 -0
  273. package/contracts/registry/Registry.sol +464 -0
  274. package/contracts/registry/RegistryAccessManager.sol +216 -0
  275. package/contracts/registry/RegistryService.sol +283 -0
  276. package/contracts/registry/RegistryServiceManager.sol +62 -0
  277. package/contracts/registry/ReleaseManager.sol +322 -0
  278. package/contracts/registry/TokenRegistry.sol +116 -0
  279. package/contracts/shared/ContractDeployerLib.sol +72 -0
  280. package/contracts/shared/ERC165.sol +27 -0
  281. package/contracts/shared/INftOwnable.sol +23 -0
  282. package/contracts/shared/IPolicyHolder.sol +26 -0
  283. package/contracts/shared/IRegisterable.sol +15 -0
  284. package/contracts/shared/IRegistryLinked.sol +12 -0
  285. package/contracts/shared/IService.sol +18 -0
  286. package/contracts/shared/IVersionable.sol +53 -0
  287. package/contracts/shared/NftOwnable.sol +120 -0
  288. package/contracts/shared/PolicyHolder.sol +81 -0
  289. package/contracts/shared/ProxyManager.sol +169 -0
  290. package/contracts/shared/Registerable.sol +74 -0
  291. package/contracts/shared/RegistryLinked.sol +48 -0
  292. package/contracts/shared/Service.sol +58 -0
  293. package/contracts/shared/TokenHandler.sol +27 -0
  294. package/contracts/shared/UpgradableProxyWithAdmin.sol +16 -0
  295. package/contracts/shared/Versionable.sol +59 -0
  296. package/contracts/test/TestFee.sol +25 -0
  297. package/contracts/test/TestRegisterable.sol +18 -0
  298. package/contracts/test/TestRoleId.sol +14 -0
  299. package/contracts/test/TestService.sol +25 -0
  300. package/contracts/{Dip.sol → test/TestToken.sol} +5 -5
  301. package/contracts/test/TestVersion.sol +44 -0
  302. package/contracts/test/TestVersionable.sol +17 -0
  303. package/contracts/test/Usdc.sol +26 -0
  304. package/contracts/types/AddressSet.sol +58 -0
  305. package/contracts/types/Blocknumber.sol +118 -0
  306. package/contracts/types/ChainId.sol +38 -0
  307. package/contracts/types/ClaimId.sol +52 -0
  308. package/contracts/types/DistributorType.sol +55 -0
  309. package/contracts/types/Fee.sol +56 -0
  310. package/contracts/types/Key32.sol +50 -0
  311. package/contracts/types/NftId.sol +72 -0
  312. package/contracts/types/NftIdSet.sol +62 -0
  313. package/contracts/types/NumberId.sol +52 -0
  314. package/contracts/types/ObjectType.sol +156 -0
  315. package/contracts/types/PayoutId.sol +54 -0
  316. package/contracts/types/Referral.sol +85 -0
  317. package/contracts/types/RiskId.sol +43 -0
  318. package/contracts/types/RoleId.sol +95 -0
  319. package/contracts/types/Seconds.sol +54 -0
  320. package/contracts/types/StateId.sol +105 -0
  321. package/contracts/types/Timestamp.sol +126 -0
  322. package/contracts/types/UFixed.sol +325 -0
  323. package/contracts/types/Version.sol +107 -0
  324. package/package.json +26 -10
  325. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  326. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  327. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  328. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  329. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,86 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {NftId} from "../../types/NftId.sol";
5
+ import {Fee} from "../../types/Fee.sol";
6
+ import {IPolicy} from "../module/IPolicy.sol";
7
+ import {IService} from "../../shared/IService.sol";
8
+ import {UFixed} from "../../types/UFixed.sol";
9
+ import {DistributorType} from "../../types/DistributorType.sol";
10
+ import {ReferralId} from "../../types/Referral.sol";
11
+ import {Timestamp} from "../../types/Timestamp.sol";
12
+
13
+
14
+ interface IDistributionService is IService {
15
+ error ErrorIDistributionServiceParentNftIdNotInstance(NftId nftId, NftId parentNftId);
16
+ error ErrorIDistributionServiceCallerNotDistributor(address caller);
17
+ error ErrorIDistributionServiceInvalidReferralId(ReferralId referralId);
18
+ error ErrorIDistributionServiceMaxReferralsExceeded(uint256 maxReferrals);
19
+ error ErrorIDistributionServiceDiscountTooLow(uint256 minDiscountPercentage, uint256 discountPercentage);
20
+ error ErrorIDistributionServiceDiscountTooHigh(uint256 maxDiscountPercentage, uint256 discountPercentage);
21
+ error ErrorIDistributionServiceExpiryTooLong(uint256 maxReferralLifetime, uint256 expiryAt);
22
+ error ErrorIDistributionServiceInvalidReferral(string code);
23
+ error ErrorIDistributionServiceExpirationInvalid(Timestamp expiryAt);
24
+ error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
25
+ error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
26
+ error ErrorIDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
27
+
28
+ function setFees(
29
+ Fee memory minDistributionOwnerFee,
30
+ Fee memory distributionFee
31
+ ) external;
32
+
33
+ function createDistributorType(
34
+ string memory name,
35
+ UFixed minDiscountPercentage,
36
+ UFixed maxDiscountPercentage,
37
+ UFixed commissionPercentage,
38
+ uint32 maxReferralCount,
39
+ uint32 maxReferralLifetime,
40
+ bool allowSelfReferrals,
41
+ bool allowRenewals,
42
+ bytes memory data
43
+ )
44
+ external
45
+ returns (DistributorType distributorType);
46
+
47
+ function createDistributor(
48
+ address distributor,
49
+ DistributorType distributorType,
50
+ bytes memory data
51
+ ) external returns (NftId distributorNftId);
52
+
53
+ function updateDistributorType(
54
+ NftId distributorNftId,
55
+ DistributorType distributorType,
56
+ bytes memory data
57
+ ) external;
58
+
59
+ function createReferral(
60
+ NftId distributorNftId,
61
+ string memory code,
62
+ UFixed discountPercentage,
63
+ uint32 maxReferrals,
64
+ Timestamp expiryAt,
65
+ bytes memory data
66
+ )
67
+ external
68
+ returns (ReferralId referralId);
69
+
70
+ /// @dev callback from product service when selling a policy for a specific referralId
71
+ function processSale(
72
+ ReferralId referralId,
73
+ uint256 premiumAmount
74
+ ) external;
75
+
76
+ function calculateFeeAmount(
77
+ NftId distributionNftId,
78
+ ReferralId referralId,
79
+ IPolicy.Premium memory premium
80
+ ) external view returns (IPolicy.Premium memory finalPremium);
81
+
82
+ function referralIsValid(
83
+ NftId distributorNftId,
84
+ ReferralId referralId
85
+ ) external view returns (bool isValid);
86
+ }
@@ -0,0 +1,70 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRisk} from "../module/IRisk.sol";
5
+ import {IService} from "../../shared/IService.sol";
6
+
7
+ import {NftId} from "../../types/NftId.sol";
8
+ import {ReferralId} from "../../types/Referral.sol";
9
+ import {RiskId} from "../../types/RiskId.sol";
10
+ import {Seconds} from "../../types/Seconds.sol";
11
+ import {StateId} from "../../types/StateId.sol";
12
+ import {Timestamp} from "../../types/Timestamp.sol";
13
+ import {UFixed} from "../../types/UFixed.sol";
14
+ import {Fee} from "../../types/Fee.sol";
15
+
16
+ interface IPolicyService is IService {
17
+
18
+ error ErrorIPolicyServiceInsufficientAllowance(address customer, address tokenHandlerAddress, uint256 amount);
19
+ error ErrorIPolicyServicePremiumAlreadyPaid(NftId policyNftId, uint256 premiumPaidAmount);
20
+ error ErrorIPolicyServicePolicyNotActivated(NftId policyNftId);
21
+ error ErrorIPolicyServicePolicyAlreadyClosed(NftId policyNftId);
22
+ error ErrorIPolicyServicePolicyNotActive(NftId policyNftId, StateId state);
23
+ error ErrorIPolicyServicePremiumNotFullyPaid(NftId policyNftId, uint256 premiumAmount, uint256 premiumPaidAmount);
24
+ error ErrorIPolicyServiceOpenClaims(NftId policyNftId, uint16 openClaimsCount);
25
+ error ErrorIPolicyServicePolicyHasNotExpired(NftId policyNftId, Timestamp expiredAt);
26
+
27
+ /// @dev declines an application represented by {policyNftId}
28
+ /// an application can only be declined in applied state
29
+ /// only the related product may decline an application
30
+ function decline(NftId policyNftId) external;
31
+
32
+ /// @dev underwrites the policy represented by {policyNftId}
33
+ /// sets the policy state to underwritten
34
+ /// may set the policy state to activated and set the activation date
35
+ /// optionally collects premiums and activates the policy.
36
+ /// - premium payment is only attempted if requirePremiumPayment is set to true
37
+ /// - activation is only done if activateAt is a non-zero timestamp
38
+ /// an application can only be underwritten in applied state
39
+ /// only the related product may underwrite an application
40
+ function underwrite(
41
+ NftId policyNftId,
42
+ bool requirePremiumPayment,
43
+ Timestamp activateAt
44
+ ) external;
45
+
46
+ /// @dev collects the premium token for the specified policy
47
+ function collectPremium(NftId policyNftId, Timestamp activateAt) external;
48
+
49
+ /// @dev activates the specified policy and sets the activation date in the policy metadata
50
+ /// to activate a policy it needs to be in underwritten state
51
+ function activate(NftId policyNftId, Timestamp activateAt) external;
52
+
53
+ /// @dev expires the specified policy and sets the expiry date in the policy metadata
54
+ /// to expire a policy it must be in active state, policies may be expired even when the predefined expiry date is still in the future
55
+ /// a policy can only be closed when it has been expired. in addition, it must not have any open claims
56
+ /// this function can only be called by a product. the policy needs to match with the calling product
57
+ function expire(NftId policyNftId) external;
58
+
59
+ /// @dev closes the specified policy and sets the closed data in the policy metadata
60
+ /// a policy can only be closed when it has been expired. in addition, it must not have any open claims
61
+ /// this function can only be called by a product. the policy needs to match with the calling product
62
+ function close(NftId policyNftId) external;
63
+
64
+ // TODO move function to pool service
65
+ function calculateRequiredCollateral(
66
+ UFixed collateralizationLevel,
67
+ uint256 sumInsuredAmount
68
+ ) external pure returns(uint256 collateralAmount);
69
+
70
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {NftId} from "../../types/NftId.sol";
5
+ import {Fee} from "../../types/Fee.sol";
6
+ import {StateId} from "../../types/StateId.sol";
7
+ import {IService} from "../../shared/IService.sol";
8
+ import {IBundle} from "../module/IBundle.sol";
9
+ import {IInstance} from "../../instance/IInstance.sol";
10
+
11
+ interface IPoolService is IService {
12
+
13
+ function register(address poolAddress) external returns(NftId);
14
+
15
+ function setFees(
16
+ Fee memory poolFee,
17
+ Fee memory stakingFee,
18
+ Fee memory performanceFee
19
+ ) external;
20
+ }
@@ -0,0 +1,40 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRisk} from "../module/IRisk.sol";
5
+ import {IService} from "../../shared/IService.sol";
6
+
7
+ import {NftId} from "../../types/NftId.sol";
8
+ import {ReferralId} from "../../types/Referral.sol";
9
+ import {RiskId} from "../../types/RiskId.sol";
10
+ import {StateId} from "../../types/StateId.sol";
11
+ import {Timestamp} from "../../types/Timestamp.sol";
12
+ import {UFixed} from "../../types/UFixed.sol";
13
+ import {Fee} from "../../types/Fee.sol";
14
+
15
+ interface IProductService is IService {
16
+
17
+ function register(address productAddress) external returns(NftId);
18
+
19
+ function setFees(
20
+ Fee memory productFee,
21
+ Fee memory processingFee
22
+ ) external;
23
+
24
+ function createRisk(
25
+ RiskId riskId,
26
+ bytes memory data
27
+ ) external;
28
+
29
+
30
+ function updateRisk(
31
+ RiskId riskId,
32
+ bytes memory data
33
+ ) external;
34
+
35
+
36
+ function updateRiskState(
37
+ RiskId riskId,
38
+ StateId newState
39
+ ) external;
40
+ }
@@ -0,0 +1,402 @@
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, APPLICATION, 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 {IApplicationService} from "./IApplicationService.sol";
40
+ import {IPolicyService} from "./IPolicyService.sol";
41
+ import {InstanceReader} from "../InstanceReader.sol";
42
+ import {IPoolService} from "./IPoolService.sol";
43
+ import {IBundleService} from "./IBundleService.sol";
44
+
45
+
46
+ contract PolicyService is
47
+ ComponentService,
48
+ IPolicyService
49
+ {
50
+ using NftIdLib for NftId;
51
+ using TimestampLib for Timestamp;
52
+
53
+ IPoolService internal _poolService;
54
+ IBundleService internal _bundleService;
55
+ IApplicationService internal _applicationService;
56
+
57
+ event LogProductServiceSender(address sender);
58
+
59
+ function _initialize(
60
+ address owner,
61
+ bytes memory data
62
+ )
63
+ internal
64
+ virtual override
65
+ initializer
66
+ {
67
+ address registryAddress;
68
+ address initialOwner;
69
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
70
+
71
+ initializeService(registryAddress, owner);
72
+
73
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
74
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
75
+ _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), getMajorVersion()));
76
+
77
+ registerInterface(type(IPolicyService).interfaceId);
78
+ }
79
+
80
+
81
+ function getDomain() public pure override(IService, Service) returns(ObjectType) {
82
+ return POLICY();
83
+ }
84
+
85
+
86
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
87
+ IRegistry.ObjectInfo memory productInfo;
88
+ (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
89
+ product = Product(productInfo.objectAddress);
90
+ }
91
+
92
+ function _getAndVerifyUnderwritingSetup(
93
+ IInstance instance,
94
+ InstanceReader instanceReader,
95
+ IPolicy.PolicyInfo memory policyInfo,
96
+ ISetup.ProductSetupInfo memory productSetupInfo
97
+ )
98
+ internal
99
+ view
100
+ returns (
101
+ NftId poolNftId,
102
+ NftId bundleNftId,
103
+ IBundle.BundleInfo memory bundleInfo,
104
+ uint256 collateralAmount
105
+ )
106
+ {
107
+ // check match between policy and bundle (via pool)
108
+ poolNftId = productSetupInfo.poolNftId;
109
+ bundleNftId = policyInfo.bundleNftId;
110
+ bundleInfo = instanceReader.getBundleInfo(bundleNftId);
111
+ require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
112
+
113
+ // calculate required collateral
114
+ ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
115
+
116
+ // obtain remaining return values
117
+ // TODO required collateral amount should be calculated by pool service, not policy service
118
+ collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
119
+ }
120
+
121
+
122
+ function decline(
123
+ NftId policyNftId
124
+ )
125
+ external
126
+ override
127
+ {
128
+ require(false, "ERROR:PRS-235:NOT_YET_IMPLEMENTED");
129
+ }
130
+
131
+
132
+ /// @dev underwites application which includes the locking of the required collateral from the pool.
133
+ function underwrite(
134
+ NftId applicationNftId, // = policyNftId
135
+ bool requirePremiumPayment,
136
+ Timestamp activateAt
137
+ )
138
+ external
139
+ virtual override
140
+ {
141
+ // check caller is registered product
142
+ IInstance instance;
143
+ InstanceReader instanceReader;
144
+ NftId productNftId;
145
+ {
146
+ IRegistry.ObjectInfo memory productInfo;
147
+ (productInfo, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
148
+ instanceReader = instance.getInstanceReader();
149
+ productNftId = productInfo.nftId;
150
+ }
151
+
152
+ // check policy matches with calling product
153
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(applicationNftId);
154
+ require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
155
+
156
+ // check policy is in state applied
157
+ require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
158
+
159
+ (
160
+ NftId poolNftId,
161
+ NftId bundleNftId,
162
+ IBundle.BundleInfo memory bundleInfo,
163
+ uint256 collateralAmount
164
+ ) = _getAndVerifyUnderwritingSetup(
165
+ instance,
166
+ instanceReader,
167
+ policyInfo,
168
+ instanceReader.getProductSetupInfo(productNftId)
169
+ );
170
+
171
+ StateId newPolicyState = UNDERWRITTEN();
172
+
173
+ // optional activation of policy
174
+ if(activateAt > zeroTimestamp()) {
175
+ newPolicyState = ACTIVE();
176
+ policyInfo.activatedAt = activateAt;
177
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
178
+ }
179
+
180
+ // lock bundle collateral
181
+ uint256 netPremiumAmount = 0; // > 0 if immediate premium payment
182
+
183
+ // optional collection of premium
184
+ if(requirePremiumPayment) {
185
+ netPremiumAmount = _processPremiumByTreasury(
186
+ instance,
187
+ productNftId,
188
+ applicationNftId,
189
+ policyInfo.premiumAmount);
190
+
191
+ policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
192
+ }
193
+
194
+ // lock collateral and update bundle book keeping
195
+ // TODO introduct indirection via pool service?
196
+ // well pool would only need to be involved when a part of the collateral
197
+ // is provided by a "re insurance policy" of the pool
198
+ // but then again the policiy would likely best be attached to the bundle. really? why?
199
+ // retention level: fraction of sum insured that product will cover from pool funds directly
200
+ // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
201
+ // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
202
+ // open points:
203
+ // - do we need a link of a bundle to this policy or is it enough to know that the pool has an active policy?
204
+ // - when to buy such policies and for which amount? manual trigger or link to bundle creation and/or funding?
205
+ bundleInfo = _bundleService.lockCollateral(
206
+ instance,
207
+ applicationNftId,
208
+ bundleNftId,
209
+ collateralAmount,
210
+ netPremiumAmount);
211
+
212
+ instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
213
+
214
+ // also verify/confirm application by pool if necessary
215
+ if(instanceReader.getPoolSetupInfo(poolNftId).isVerifyingApplications) {
216
+ IPoolComponent pool = IPoolComponent(
217
+ getRegistry().getObjectInfo(poolNftId).objectAddress);
218
+
219
+ pool.verifyApplication(
220
+ applicationNftId,
221
+ policyInfo.applicationData,
222
+ bundleNftId,
223
+ bundleInfo.filter,
224
+ collateralAmount);
225
+ }
226
+
227
+ // TODO: add logging
228
+ }
229
+
230
+
231
+ function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
232
+ UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
233
+ UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
234
+ return collateralUFixed.toInt();
235
+ }
236
+
237
+ function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
238
+ // check caller is registered product
239
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
240
+ InstanceReader instanceReader = instance.getInstanceReader();
241
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
242
+
243
+ if (policyInfo.premiumPaidAmount == policyInfo.premiumAmount) {
244
+ revert ErrorIPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
245
+ }
246
+
247
+ uint256 unpaidPremiumAmount = policyInfo.premiumAmount - policyInfo.premiumPaidAmount;
248
+
249
+ uint256 netPremiumAmount = _processPremiumByTreasury(
250
+ instance,
251
+ productInfo.nftId,
252
+ policyNftId,
253
+ unpaidPremiumAmount);
254
+
255
+ policyInfo.premiumPaidAmount += unpaidPremiumAmount;
256
+
257
+ _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
258
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
259
+
260
+ if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
261
+ activate(policyNftId, activateAt);
262
+ }
263
+
264
+ // TODO: add logging
265
+ }
266
+
267
+ function activate(NftId policyNftId, Timestamp activateAt) public override {
268
+ // check caller is registered product
269
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
270
+ InstanceReader instanceReader = instance.getInstanceReader();
271
+
272
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
273
+
274
+ require(
275
+ policyInfo.activatedAt.eqz(),
276
+ "ERROR:PRS-020:ALREADY_ACTIVATED");
277
+
278
+ policyInfo.activatedAt = activateAt;
279
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
280
+
281
+ instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
282
+
283
+ // TODO: add logging
284
+ }
285
+
286
+
287
+ function expire(
288
+ NftId policyNftId
289
+ )
290
+ external
291
+ override
292
+ // solhint-disable-next-line no-empty-blocks
293
+ {
294
+
295
+ }
296
+
297
+ function close(
298
+ NftId policyNftId
299
+ )
300
+ external
301
+ override
302
+ {
303
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
304
+ InstanceReader instanceReader = instance.getInstanceReader();
305
+
306
+ 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);
315
+ }
316
+
317
+ if (policyInfo.closedAt.gtz()) {
318
+ revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
319
+ }
320
+
321
+ if (policyInfo.premiumAmount != policyInfo.premiumPaidAmount) {
322
+ revert ErrorIPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
323
+ }
324
+
325
+ if (policyInfo.openClaimsCount > 0) {
326
+ revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
327
+ }
328
+
329
+ if (TimestampLib.blockTimestamp().lte(policyInfo.expiredAt) && (policyInfo.payoutAmount < policyInfo.sumInsuredAmount)) {
330
+ revert ErrorIPolicyServicePolicyHasNotExpired(policyNftId, policyInfo.expiredAt);
331
+ }
332
+
333
+ policyInfo.closedAt = TimestampLib.blockTimestamp();
334
+
335
+ _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
336
+ instance.updatePolicy(policyNftId, policyInfo, CLOSED());
337
+ }
338
+
339
+ function _getPoolNftId(
340
+ IInstance instance,
341
+ NftId productNftId
342
+ )
343
+ internal
344
+ view
345
+ returns (NftId poolNftid)
346
+ {
347
+ InstanceReader instanceReader = instance.getInstanceReader();
348
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
349
+ return productSetupInfo.poolNftId;
350
+ }
351
+
352
+
353
+ function _processPremiumByTreasury(
354
+ IInstance instance,
355
+ NftId productNftId,
356
+ NftId policyNftId,
357
+ uint256 premiumAmount
358
+ )
359
+ internal
360
+ returns (uint256 netPremiumAmount)
361
+ {
362
+ // process token transfer(s)
363
+ if(premiumAmount > 0) {
364
+ ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
365
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
366
+ TokenHandler tokenHandler = productSetupInfo.tokenHandler;
367
+ address policyOwner = getRegistry().ownerOf(policyNftId);
368
+ ISetup.PoolSetupInfo memory poolSetupInfo = instance.getInstanceReader().getPoolSetupInfo(productSetupInfo.poolNftId);
369
+ address poolWallet = poolSetupInfo.wallet;
370
+ IPolicy.Premium memory premium = _applicationService.calculatePremium(
371
+ productNftId,
372
+ policyInfo.riskId,
373
+ policyInfo.sumInsuredAmount,
374
+ policyInfo.lifetime,
375
+ policyInfo.applicationData,
376
+ policyInfo.bundleNftId,
377
+ policyInfo.referralId
378
+ );
379
+
380
+ // if (FeeLib.feeIsZero(premium.productFeeAmount)) {
381
+ // tokenHandler.transfer(
382
+ // policyOwner,
383
+ // poolWallet,
384
+ // premiumAmount
385
+ // );
386
+ // } else {
387
+ address productWallet = productSetupInfo.wallet;
388
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
389
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
390
+ }
391
+ tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
392
+ tokenHandler.transfer(policyOwner, poolWallet, premium.netPremiumAmount);
393
+ netPremiumAmount = premium.netPremiumAmount;
394
+ // TODO: also move distribution tokens to distribution wallet and call `Distribution.processSale` to update distribution balances
395
+ // }
396
+ // TODO: move pool/bundle related tokens too
397
+
398
+ }
399
+
400
+ // TODO: add logging
401
+ }
402
+ }
@@ -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
+ }