@etherisc/gif-next 0.0.2-00142a5-254

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 (334) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +478 -0
  3. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  4. package/artifacts/contracts/components/Component.sol/Component.json +842 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  6. package/artifacts/contracts/components/Distribution.sol/Distribution.json +1345 -0
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +4 -0
  8. package/artifacts/contracts/components/IComponent.sol/IComponent.json +605 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  10. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +969 -0
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +4 -0
  12. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +1064 -0
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +4 -0
  14. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +830 -0
  15. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  16. package/artifacts/contracts/components/Pool.sol/Pool.json +1376 -0
  17. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  18. package/artifacts/contracts/components/Product.sol/Product.json +1167 -0
  19. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  20. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  21. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  22. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +778 -0
  23. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  24. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +190 -0
  25. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  26. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +2611 -0
  27. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  28. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +633 -0
  29. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  30. package/artifacts/contracts/instance/Instance.sol/Instance.json +3276 -0
  31. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +4 -0
  32. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +1330 -0
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +4 -0
  34. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +1403 -0
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +4 -0
  36. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +1140 -0
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  38. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +741 -0
  39. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  40. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +256 -0
  41. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +4 -0
  42. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +639 -0
  43. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +4 -0
  44. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +429 -0
  45. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  46. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.json +115 -0
  47. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +4 -0
  48. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +532 -0
  49. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +4 -0
  50. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +194 -0
  51. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +4 -0
  52. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +237 -0
  53. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +4 -0
  54. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.json +10 -0
  55. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  56. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  57. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +4 -0
  58. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.json +10 -0
  59. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +4 -0
  60. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.json +10 -0
  61. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +4 -0
  62. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.json +10 -0
  63. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +4 -0
  64. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.json +10 -0
  65. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +4 -0
  66. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.json +10 -0
  67. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +4 -0
  68. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +1092 -0
  69. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +4 -0
  70. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +681 -0
  71. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  72. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1321 -0
  73. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  74. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +725 -0
  75. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +4 -0
  76. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +1072 -0
  77. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +4 -0
  78. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +685 -0
  79. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +1806 -0
  81. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  82. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +793 -0
  83. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +4 -0
  84. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +627 -0
  85. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  86. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +709 -0
  87. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +602 -0
  89. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  90. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +1090 -0
  91. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  92. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +969 -0
  93. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +4 -0
  94. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +960 -0
  95. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +4 -0
  96. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +450 -0
  97. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  98. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +1575 -0
  99. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +741 -0
  101. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +1481 -0
  103. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  104. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +709 -0
  105. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +872 -0
  107. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  108. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +653 -0
  109. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  110. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +784 -0
  111. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  112. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +756 -0
  113. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +4 -0
  114. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +866 -0
  115. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +4 -0
  116. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +52 -0
  117. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  118. package/artifacts/contracts/registry/Registry.sol/Registry.json +858 -0
  119. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  120. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  121. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +4 -0
  122. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +1158 -0
  123. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +4 -0
  124. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +670 -0
  125. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  126. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +559 -0
  127. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  128. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +498 -0
  129. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +4 -0
  130. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.json +107 -0
  131. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +4 -0
  132. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +73 -0
  133. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +4 -0
  134. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +138 -0
  135. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +4 -0
  136. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +129 -0
  137. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +4 -0
  138. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +188 -0
  139. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +4 -0
  140. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.json +48 -0
  141. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  142. package/artifacts/contracts/shared/IService.sol/IService.json +335 -0
  143. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +4 -0
  144. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +55 -0
  145. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +4 -0
  146. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +251 -0
  147. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +4 -0
  148. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +248 -0
  149. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +4 -0
  150. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +582 -0
  151. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +4 -0
  152. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +352 -0
  153. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +4 -0
  154. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +84 -0
  155. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  156. package/artifacts/contracts/shared/Service.sol/Service.json +496 -0
  157. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  158. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +96 -0
  159. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +4 -0
  160. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +129 -0
  161. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +4 -0
  162. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +78 -0
  163. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +4 -0
  164. package/artifacts/contracts/test/TestFee.sol/TestFee.json +119 -0
  165. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +4 -0
  166. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +383 -0
  167. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +4 -0
  168. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +116 -0
  169. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +4 -0
  170. package/artifacts/contracts/test/TestService.sol/TestService.json +596 -0
  171. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +4 -0
  172. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +376 -0
  173. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +4 -0
  174. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +218 -0
  175. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +4 -0
  176. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +104 -0
  177. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +4 -0
  178. package/artifacts/contracts/test/Usdc.sol/USDC.json +376 -0
  179. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +4 -0
  180. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.json +10 -0
  181. package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +4 -0
  182. package/artifacts/contracts/types/Amount.sol/AmountLib.json +209 -0
  183. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  184. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  185. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  186. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  187. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +4 -0
  188. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +179 -0
  189. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +4 -0
  190. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +104 -0
  191. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +4 -0
  192. package/artifacts/contracts/types/Fee.sol/FeeLib.json +288 -0
  193. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +4 -0
  194. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +125 -0
  195. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  196. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +166 -0
  197. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +4 -0
  198. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +33 -0
  199. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +4 -0
  200. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.json +100 -0
  201. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  202. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  203. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +4 -0
  204. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +209 -0
  205. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +4 -0
  206. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +142 -0
  207. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  208. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  209. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
  210. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +156 -0
  211. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  212. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  213. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  214. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  215. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  216. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +280 -0
  217. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  218. package/artifacts/contracts/types/UFixed.sol/MathLib.json +10 -0
  219. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +4 -0
  220. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +479 -0
  221. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +4 -0
  222. package/artifacts/contracts/types/Version.sol/VersionLib.json +177 -0
  223. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +4 -0
  224. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +49 -0
  225. package/contracts/components/Component.sol +253 -0
  226. package/contracts/components/Distribution.sol +284 -0
  227. package/contracts/components/IComponent.sol +76 -0
  228. package/contracts/components/IDistributionComponent.sol +71 -0
  229. package/contracts/components/IPoolComponent.sol +113 -0
  230. package/contracts/components/IProductComponent.sol +40 -0
  231. package/contracts/components/Pool.sol +302 -0
  232. package/contracts/components/Product.sol +371 -0
  233. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  234. package/contracts/instance/BundleManager.sol +126 -0
  235. package/contracts/instance/Cloneable.sol +51 -0
  236. package/contracts/instance/IInstance.sol +102 -0
  237. package/contracts/instance/IInstanceService.sol +68 -0
  238. package/contracts/instance/Instance.sol +310 -0
  239. package/contracts/instance/InstanceAccessManager.sol +527 -0
  240. package/contracts/instance/InstanceReader.sol +317 -0
  241. package/contracts/instance/InstanceService.sol +478 -0
  242. package/contracts/instance/InstanceServiceManager.sol +54 -0
  243. package/contracts/instance/ObjectManager.sol +82 -0
  244. package/contracts/instance/base/ComponentService.sol +130 -0
  245. package/contracts/instance/base/IKeyValueStore.sol +49 -0
  246. package/contracts/instance/base/ILifecycle.sol +30 -0
  247. package/contracts/instance/base/KeyValueStore.sol +180 -0
  248. package/contracts/instance/base/Lifecycle.sol +117 -0
  249. package/contracts/instance/module/IAccess.sol +54 -0
  250. package/contracts/instance/module/IBundle.sol +23 -0
  251. package/contracts/instance/module/IComponents.sol +41 -0
  252. package/contracts/instance/module/IDistribution.sol +41 -0
  253. package/contracts/instance/module/IPolicy.sol +77 -0
  254. package/contracts/instance/module/IRisk.sol +11 -0
  255. package/contracts/instance/module/ISetup.sol +33 -0
  256. package/contracts/instance/module/ITreasury.sol +23 -0
  257. package/contracts/instance/service/ApplicationService.sol +355 -0
  258. package/contracts/instance/service/ApplicationServiceManager.sol +35 -0
  259. package/contracts/instance/service/BundleService.sol +443 -0
  260. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  261. package/contracts/instance/service/ClaimService.sol +239 -0
  262. package/contracts/instance/service/ClaimServiceManager.sol +35 -0
  263. package/contracts/instance/service/DistributionService.sol +431 -0
  264. package/contracts/instance/service/DistributionServiceManager.sol +51 -0
  265. package/contracts/instance/service/IApplicationService.sol +78 -0
  266. package/contracts/instance/service/IBundleService.sol +102 -0
  267. package/contracts/instance/service/IClaimService.sol +92 -0
  268. package/contracts/instance/service/IDistributionService.sol +99 -0
  269. package/contracts/instance/service/IPolicyService.sol +139 -0
  270. package/contracts/instance/service/IPoolService.sol +102 -0
  271. package/contracts/instance/service/IProductService.sol +40 -0
  272. package/contracts/instance/service/PolicyService.sol +570 -0
  273. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  274. package/contracts/instance/service/PoolService.sol +336 -0
  275. package/contracts/instance/service/PoolServiceManager.sol +51 -0
  276. package/contracts/instance/service/ProductService.sol +210 -0
  277. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  278. package/contracts/registry/ChainNft.sol +210 -0
  279. package/contracts/registry/IRegistry.sol +101 -0
  280. package/contracts/registry/IRegistryService.sol +68 -0
  281. package/contracts/registry/ITransferInterceptor.sol +7 -0
  282. package/contracts/registry/Registry.sol +467 -0
  283. package/contracts/registry/RegistryAccessManager.sol +216 -0
  284. package/contracts/registry/RegistryService.sol +282 -0
  285. package/contracts/registry/RegistryServiceManager.sol +62 -0
  286. package/contracts/registry/ReleaseManager.sol +324 -0
  287. package/contracts/registry/TokenRegistry.sol +116 -0
  288. package/contracts/shared/ContractDeployerLib.sol +72 -0
  289. package/contracts/shared/ERC165.sol +27 -0
  290. package/contracts/shared/INftOwnable.sol +23 -0
  291. package/contracts/shared/IPolicyHolder.sol +26 -0
  292. package/contracts/shared/IRegisterable.sol +15 -0
  293. package/contracts/shared/IRegistryLinked.sol +12 -0
  294. package/contracts/shared/IService.sol +16 -0
  295. package/contracts/shared/IVersionable.sol +53 -0
  296. package/contracts/shared/NftOwnable.sol +120 -0
  297. package/contracts/shared/PolicyHolder.sol +81 -0
  298. package/contracts/shared/ProxyManager.sol +169 -0
  299. package/contracts/shared/Registerable.sol +74 -0
  300. package/contracts/shared/RegistryLinked.sol +48 -0
  301. package/contracts/shared/Service.sol +72 -0
  302. package/contracts/shared/TokenHandler.sol +33 -0
  303. package/contracts/shared/UpgradableProxyWithAdmin.sol +16 -0
  304. package/contracts/shared/Versionable.sol +59 -0
  305. package/contracts/test/TestFee.sol +25 -0
  306. package/contracts/test/TestRegisterable.sol +18 -0
  307. package/contracts/test/TestRoleId.sol +14 -0
  308. package/contracts/test/TestService.sol +25 -0
  309. package/contracts/test/TestToken.sol +26 -0
  310. package/contracts/test/TestVersion.sol +44 -0
  311. package/contracts/test/TestVersionable.sol +17 -0
  312. package/contracts/test/Usdc.sol +26 -0
  313. package/contracts/types/AddressSet.sol +58 -0
  314. package/contracts/types/Amount.sol +70 -0
  315. package/contracts/types/Blocknumber.sol +119 -0
  316. package/contracts/types/ChainId.sol +38 -0
  317. package/contracts/types/ClaimId.sol +75 -0
  318. package/contracts/types/DistributorType.sol +55 -0
  319. package/contracts/types/Fee.sol +64 -0
  320. package/contracts/types/Key32.sol +50 -0
  321. package/contracts/types/NftId.sol +80 -0
  322. package/contracts/types/NftIdSet.sol +62 -0
  323. package/contracts/types/NumberId.sol +52 -0
  324. package/contracts/types/ObjectType.sol +157 -0
  325. package/contracts/types/PayoutId.sol +82 -0
  326. package/contracts/types/Referral.sol +89 -0
  327. package/contracts/types/RiskId.sol +43 -0
  328. package/contracts/types/RoleId.sol +97 -0
  329. package/contracts/types/Seconds.sol +54 -0
  330. package/contracts/types/StateId.sol +110 -0
  331. package/contracts/types/Timestamp.sol +132 -0
  332. package/contracts/types/UFixed.sol +326 -0
  333. package/contracts/types/Version.sol +108 -0
  334. package/package.json +52 -0
@@ -0,0 +1,570 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {Product} from "../../components/Product.sol";
6
+ import {IComponents} from "../module/IComponents.sol";
7
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
8
+ import {IInstance} from "../IInstance.sol";
9
+ import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
11
+ import {IRisk} from "../module/IRisk.sol";
12
+ import {IBundle} from "../module/IBundle.sol";
13
+ import {ISetup} from "../module/ISetup.sol";
14
+
15
+ import {TokenHandler} from "../../shared/TokenHandler.sol";
16
+
17
+ import {Amount, AmountLib} from "../../types/Amount.sol";
18
+ import {ClaimId, ClaimIdLib} from "../../types/ClaimId.sol";
19
+ import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
20
+ import {UFixed, UFixedLib} from "../../types/UFixed.sol";
21
+ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM} from "../../types/ObjectType.sol";
22
+ import {APPLIED, COLLATERALIZED, ACTIVE, KEEP_STATE, CLOSED, DECLINED, CONFIRMED} from "../../types/StateId.sol";
23
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
24
+ import {PayoutId, PayoutIdLib} from "../../types/PayoutId.sol";
25
+ import {StateId} from "../../types/StateId.sol";
26
+ import {VersionPart} from "../../types/Version.sol";
27
+
28
+ import {ComponentService} from "../base/ComponentService.sol";
29
+ import {IApplicationService} from "./IApplicationService.sol";
30
+ import {IBundleService} from "./IBundleService.sol";
31
+ import {IClaimService} from "./IClaimService.sol";
32
+ import {IDistributionService} from "./IDistributionService.sol";
33
+ import {InstanceReader} from "../InstanceReader.sol";
34
+ import {IPolicyService} from "./IPolicyService.sol";
35
+ import {IPoolService} from "./IPoolService.sol";
36
+ import {IService} from "../../shared/IService.sol";
37
+ import {Service} from "../../shared/Service.sol";
38
+
39
+
40
+ contract PolicyService is
41
+ ComponentService,
42
+ IPolicyService
43
+ {
44
+ using NftIdLib for NftId;
45
+ using TimestampLib for Timestamp;
46
+
47
+ IApplicationService internal _applicationService;
48
+ IBundleService internal _bundleService;
49
+ IClaimService internal _claimService;
50
+ IDistributionService internal _distributionService;
51
+ IPoolService internal _poolService;
52
+
53
+ event LogProductServiceSender(address sender);
54
+
55
+ function _initialize(
56
+ address owner,
57
+ bytes memory data
58
+ )
59
+ internal
60
+ virtual override
61
+ initializer
62
+ {
63
+ address registryAddress;
64
+ address initialOwner;
65
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
66
+
67
+ initializeService(registryAddress, address(0), owner);
68
+
69
+ VersionPart majorVersion = getVersion().toMajorPart();
70
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion));
71
+ _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), majorVersion));
72
+ _claimService = IClaimService(getRegistry().getServiceAddress(CLAIM(), majorVersion));
73
+ _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
74
+ _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
75
+
76
+ registerInterface(type(IPolicyService).interfaceId);
77
+ }
78
+
79
+
80
+ function getDomain() public pure override returns(ObjectType) {
81
+ return POLICY();
82
+ }
83
+
84
+
85
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
86
+ IRegistry.ObjectInfo memory productInfo;
87
+ (, productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
88
+ product = Product(productInfo.objectAddress);
89
+ }
90
+
91
+
92
+ function decline(
93
+ NftId policyNftId
94
+ )
95
+ external
96
+ override
97
+ {
98
+ revert();
99
+ }
100
+
101
+
102
+ /// @dev underwites application which includes the locking of the required collateral from the pool.
103
+ function collateralize(
104
+ NftId applicationNftId, // = policyNftId
105
+ bool requirePremiumPayment,
106
+ Timestamp activateAt
107
+ )
108
+ external
109
+ virtual override
110
+ {
111
+ // check caller is registered product
112
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
113
+ InstanceReader instanceReader = instance.getInstanceReader();
114
+
115
+ // check policy matches with calling product
116
+ IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
117
+
118
+ if (applicationInfo.productNftId != productNftId) {
119
+ revert ErrorPolicyServiceProductMismatch(applicationNftId, applicationInfo.productNftId, productNftId);
120
+ }
121
+
122
+ // check policy is in state applied
123
+ if (instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
124
+ revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId);
125
+ }
126
+
127
+ StateId newPolicyState = COLLATERALIZED();
128
+
129
+ // optional activation of policy
130
+ if(activateAt > zeroTimestamp()) {
131
+ newPolicyState = ACTIVE();
132
+ applicationInfo.activatedAt = activateAt;
133
+ applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
134
+ }
135
+
136
+ // lock bundle collateral
137
+ uint256 netPremiumAmount = 0; // > 0 if immediate premium payment
138
+
139
+ // optional collection of premium
140
+ if(requirePremiumPayment) {
141
+ netPremiumAmount = _processPremiumByTreasury(
142
+ instance,
143
+ applicationNftId,
144
+ applicationInfo.premiumAmount);
145
+
146
+ applicationInfo.premiumPaidAmount += applicationInfo.premiumAmount;
147
+ }
148
+
149
+ // store updated policy info
150
+ instance.updatePolicy(applicationNftId, applicationInfo, newPolicyState);
151
+
152
+ // lock collateral and update pool and bundle book keeping
153
+ // pool retention level: fraction of sum insured that product will cover from pool funds directly
154
+ // eg retention level 30%, payouts up to 30% of the sum insured will be made from the product's pool directly
155
+ // for the remaining 70% the pool owns a policy that will cover claims that exceed the 30% of the sum insured
156
+ // might also call pool component (for isVerifyingApplications pools)
157
+ _poolService.lockCollateral(
158
+ instance,
159
+ productNftId,
160
+ applicationNftId,
161
+ applicationInfo,
162
+ netPremiumAmount); // for pool book keeping (fee + additional capital)
163
+
164
+ // TODO: add logging
165
+ }
166
+
167
+
168
+ function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
169
+ UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
170
+ UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
171
+ return collateralUFixed.toInt();
172
+ }
173
+
174
+ function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
175
+ // check caller is registered product
176
+ (NftId productNftId,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
177
+ InstanceReader instanceReader = instance.getInstanceReader();
178
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
179
+
180
+ if (policyInfo.premiumPaidAmount == policyInfo.premiumAmount) {
181
+ revert ErrorIPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
182
+ }
183
+
184
+ uint256 unpaidPremiumAmount = policyInfo.premiumAmount - policyInfo.premiumPaidAmount;
185
+
186
+ uint256 netPremiumAmount = _processPremiumByTreasury(
187
+ instance,
188
+ policyNftId,
189
+ unpaidPremiumAmount);
190
+
191
+ policyInfo.premiumPaidAmount += unpaidPremiumAmount;
192
+
193
+ _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
194
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
195
+
196
+ if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
197
+ activate(policyNftId, activateAt);
198
+ }
199
+
200
+ // TODO: add logging
201
+ }
202
+
203
+ function activate(NftId policyNftId, Timestamp activateAt) public override {
204
+ // check caller is registered product
205
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
206
+ InstanceReader instanceReader = instance.getInstanceReader();
207
+
208
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
209
+
210
+ require(
211
+ policyInfo.activatedAt.eqz(),
212
+ "ERROR:PRS-020:ALREADY_ACTIVATED");
213
+
214
+ policyInfo.activatedAt = activateAt;
215
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
216
+
217
+ instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
218
+
219
+ // TODO: add logging
220
+ }
221
+
222
+
223
+ function expire(
224
+ NftId policyNftId
225
+ )
226
+ external
227
+ override
228
+ // solhint-disable-next-line no-empty-blocks
229
+ {
230
+
231
+ }
232
+
233
+ function close(
234
+ NftId policyNftId
235
+ )
236
+ external
237
+ override
238
+ {
239
+ (,, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
240
+ InstanceReader instanceReader = instance.getInstanceReader();
241
+
242
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
243
+
244
+ if (policyInfo.activatedAt.eqz()) {
245
+ revert ErrorIPolicyServicePolicyNotActivated(policyNftId);
246
+ }
247
+
248
+ StateId state = instanceReader.getPolicyState(policyNftId);
249
+ if (state != ACTIVE()) {
250
+ revert ErrorIPolicyServicePolicyNotActive(policyNftId, state);
251
+ }
252
+
253
+ if (policyInfo.closedAt.gtz()) {
254
+ revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
255
+ }
256
+
257
+ // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
258
+ if (policyInfo.premiumAmount != policyInfo.premiumPaidAmount) {
259
+ revert ErrorIPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
260
+ }
261
+
262
+ if (policyInfo.openClaimsCount > 0) {
263
+ revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
264
+ }
265
+
266
+ policyInfo.closedAt = TimestampLib.blockTimestamp();
267
+
268
+ _poolService.releaseCollateral(
269
+ instance,
270
+ policyNftId,
271
+ policyInfo);
272
+
273
+ instance.updatePolicy(policyNftId, policyInfo, CLOSED());
274
+ }
275
+
276
+ function submitClaim(
277
+ NftId policyNftId,
278
+ Amount claimAmount,
279
+ bytes memory claimData
280
+ )
281
+ external
282
+ virtual
283
+ returns (ClaimId claimId)
284
+ {
285
+ (
286
+ IInstance instance,
287
+ InstanceReader instanceReader,
288
+ IPolicy.PolicyInfo memory policyInfo
289
+ ) = _verifyCallerWithPolicy(policyNftId);
290
+
291
+ // check policy is in its active period
292
+ if(policyInfo.activatedAt.eqz() || TimestampLib.blockTimestamp() >= policyInfo.expiredAt) {
293
+ revert ErrorPolicyServicePolicyNotOpen(policyNftId);
294
+ }
295
+
296
+ // check policy including this claim is still within sum insured
297
+ if(policyInfo.payoutAmount.toInt() + claimAmount.toInt() > policyInfo.sumInsuredAmount) {
298
+ revert ErrorPolicyServiceClaimExceedsSumInsured(
299
+ policyNftId,
300
+ AmountLib.toAmount(policyInfo.sumInsuredAmount),
301
+ AmountLib.toAmount(policyInfo.payoutAmount.toInt() + claimAmount.toInt()));
302
+ }
303
+
304
+ // create new claim
305
+ claimId = ClaimIdLib.toClaimId(policyInfo.claimsCount + 1);
306
+ _claimService.submit(instance, policyNftId, claimId, claimAmount, claimData);
307
+
308
+ // update and save policy info with instance
309
+ policyInfo.claimsCount += 1;
310
+ policyInfo.openClaimsCount += 1;
311
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
312
+
313
+ emit LogPolicyServiceClaimSubmitted(policyNftId, claimId, claimAmount);
314
+ }
315
+
316
+ function confirmClaim(
317
+ NftId policyNftId,
318
+ ClaimId claimId,
319
+ Amount confirmedAmount
320
+ )
321
+ external
322
+ {
323
+ (
324
+ IInstance instance,
325
+ InstanceReader instanceReader,
326
+ IPolicy.PolicyInfo memory policyInfo
327
+ ) = _verifyCallerWithPolicy(policyNftId);
328
+
329
+ // check/update claim info
330
+ _claimService.confirm(instance, instanceReader, policyNftId, claimId, confirmedAmount);
331
+
332
+ // update and save policy info with instance
333
+ instance.updatePolicy(policyNftId, policyInfo, CONFIRMED());
334
+
335
+ emit LogPolicyServiceClaimConfirmed(policyNftId, claimId, confirmedAmount);
336
+ }
337
+
338
+ function declineClaim(
339
+ NftId policyNftId,
340
+ ClaimId claimId
341
+ )
342
+ external
343
+ {
344
+ (
345
+ IInstance instance,
346
+ InstanceReader instanceReader,
347
+ IPolicy.PolicyInfo memory policyInfo
348
+ ) = _verifyCallerWithPolicy(policyNftId);
349
+
350
+ // check/update claim info
351
+ _claimService.decline(instance, instanceReader, policyNftId, claimId);
352
+
353
+ // update and save policy info with instance
354
+ policyInfo.openClaimsCount -= 1;
355
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
356
+
357
+ emit LogPolicyServiceClaimDeclined(policyNftId, claimId);
358
+ }
359
+
360
+ function closeClaim(
361
+ NftId policyNftId,
362
+ ClaimId claimId
363
+ )
364
+ external
365
+ {
366
+ (
367
+ IInstance instance,
368
+ InstanceReader instanceReader,
369
+ IPolicy.PolicyInfo memory policyInfo
370
+ ) = _verifyCallerWithPolicy(policyNftId);
371
+
372
+ // check/update claim info
373
+ _claimService.close(instance, instanceReader, policyNftId, claimId);
374
+
375
+ // update and save policy info with instance
376
+ policyInfo.openClaimsCount -= 1;
377
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
378
+
379
+ emit LogPolicyServiceClaimClosed(policyNftId, claimId);
380
+ }
381
+
382
+ function createPayout(
383
+ NftId policyNftId,
384
+ ClaimId claimId,
385
+ Amount amount,
386
+ bytes memory data
387
+ )
388
+ external
389
+ returns (PayoutId payoutId)
390
+ {
391
+ (
392
+ IInstance instance,
393
+ InstanceReader instanceReader,
394
+ IPolicy.PolicyInfo memory policyInfo
395
+ ) = _verifyCallerWithPolicy(policyNftId);
396
+
397
+ IPolicy.ClaimInfo memory claimInfo = instanceReader.getClaimInfo(policyNftId, claimId);
398
+ StateId claimState = instanceReader.getClaimState(policyNftId, claimId);
399
+
400
+ // TODO add checks
401
+ // claim needs to be open
402
+ // claim.paidAmount + amount <= claim.claimAmount
403
+
404
+ // check/update claim info
405
+ uint8 claimNo = claimInfo.payoutsCount + 1;
406
+ payoutId = PayoutIdLib.toPayoutId(claimId, claimNo);
407
+ _claimService.createPayout(
408
+ instance,
409
+ policyNftId,
410
+ payoutId,
411
+ amount,
412
+ data);
413
+
414
+ // update and save policy info with instance
415
+ policyInfo.payoutAmount.add(amount);
416
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
417
+
418
+ emit LogPolicyServicePayoutCreated(policyNftId, payoutId, amount);
419
+ }
420
+
421
+ function processPayout(
422
+ NftId policyNftId,
423
+ PayoutId payoutId
424
+ )
425
+ external
426
+ {
427
+ (
428
+ IInstance instance,
429
+ InstanceReader instanceReader,
430
+ IPolicy.PolicyInfo memory policyInfo
431
+ ) = _verifyCallerWithPolicy(policyNftId);
432
+
433
+ // check/update claim info
434
+ (
435
+ Amount amount,
436
+ bool payoutIsClosingClaim
437
+ ) = _claimService.processPayout(
438
+ instance,
439
+ instanceReader,
440
+ policyNftId,
441
+ payoutId);
442
+
443
+ // update policy info if affected by processed payout
444
+ if(payoutIsClosingClaim) {
445
+ policyInfo.openClaimsCount -= 1;
446
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
447
+ }
448
+
449
+ emit LogPolicyServicePayoutProcessed(policyNftId, payoutId, amount);
450
+ }
451
+
452
+ function _verifyCallerWithPolicy(
453
+ NftId policyNftId
454
+ )
455
+ internal
456
+ returns (
457
+ IInstance instance,
458
+ InstanceReader instanceReader,
459
+ IPolicy.PolicyInfo memory policyInfo
460
+ )
461
+ {
462
+ NftId productNftId;
463
+ (productNftId,, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
464
+ instanceReader = instance.getInstanceReader();
465
+
466
+ // check caller(product) policy match
467
+ policyInfo = instanceReader.getPolicyInfo(policyNftId);
468
+ if(policyInfo.productNftId != productNftId) {
469
+ revert ErrorPolicyServiceProductMismatch(policyNftId,
470
+ policyInfo.productNftId,
471
+ productNftId);
472
+ }
473
+ }
474
+
475
+ function _getPoolNftId(
476
+ IInstance instance,
477
+ NftId productNftId
478
+ )
479
+ internal
480
+ view
481
+ returns (NftId poolNftid)
482
+ {
483
+ InstanceReader instanceReader = instance.getInstanceReader();
484
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
485
+ return productSetupInfo.poolNftId;
486
+ }
487
+
488
+
489
+ function _processPremiumByTreasury(
490
+ IInstance instance,
491
+ NftId policyNftId,
492
+ uint256 premiumExpectedAmount
493
+ )
494
+ internal
495
+ returns (uint256 netPremiumAmount)
496
+ {
497
+ // process token transfer(s)
498
+ if(premiumExpectedAmount == 0) {
499
+ return 0;
500
+ }
501
+
502
+ NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
503
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
504
+ IPolicy.Premium memory premium = _applicationService.calculatePremium(
505
+ productNftId,
506
+ policyInfo.riskId,
507
+ policyInfo.sumInsuredAmount,
508
+ policyInfo.lifetime,
509
+ policyInfo.applicationData,
510
+ policyInfo.bundleNftId,
511
+ policyInfo.referralId
512
+ );
513
+
514
+ if (premium.premiumAmount != premiumExpectedAmount) {
515
+ revert ErrorIPolicyServicePremiumMismatch(
516
+ policyNftId,
517
+ premiumExpectedAmount,
518
+ premium.premiumAmount);
519
+ }
520
+
521
+ address policyOwner = getRegistry().ownerOf(policyNftId);
522
+ ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
523
+ TokenHandler tokenHandler = productSetupInfo.tokenHandler;
524
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
525
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
526
+ }
527
+
528
+ uint256 productFeeAmountToTransfer = premium.productFeeFixAmount + premium.productFeeVarAmount;
529
+ uint256 distributionFeeAmountToTransfer = premium.distributionFeeFixAmount + premium.distributionFeeVarAmount - premium.discountAmount;
530
+ uint256 poolFeeAmountToTransfer = premium.poolFeeFixAmount + premium.poolFeeVarAmount;
531
+ uint256 bundleFeeAmountToTransfer = premium.bundleFeeFixAmount + premium.bundleFeeVarAmount;
532
+ uint256 poolAmountToTransfer = premium.netPremiumAmount + poolFeeAmountToTransfer + bundleFeeAmountToTransfer;
533
+ netPremiumAmount = premium.netPremiumAmount;
534
+
535
+ // move product fee to product wallet
536
+ {
537
+ address productWallet = productSetupInfo.wallet;
538
+ tokenHandler.transfer(policyOwner, productWallet, productFeeAmountToTransfer);
539
+ }
540
+
541
+ // move distribution fee to distribution wallet
542
+ {
543
+ ISetup.DistributionSetupInfo memory distributionSetupInfo = instance.getInstanceReader().getDistributionSetupInfo(productSetupInfo.distributionNftId);
544
+ address distributionWallet = distributionSetupInfo.wallet;
545
+ tokenHandler.transfer(policyOwner, distributionWallet, distributionFeeAmountToTransfer);
546
+ _distributionService.processSale(productSetupInfo.distributionNftId, policyInfo.referralId, premium, distributionFeeAmountToTransfer);
547
+ }
548
+
549
+ // move netpremium, bundleFee and poolFee to pool wallet
550
+ {
551
+ address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
552
+ tokenHandler.transfer(policyOwner, poolWallet, poolAmountToTransfer);
553
+ _poolService.processSale(policyInfo.bundleNftId, premium, poolAmountToTransfer);
554
+ }
555
+
556
+ // validate total amount transferred
557
+ {
558
+ uint256 totalTransferred = distributionFeeAmountToTransfer + poolAmountToTransfer + productFeeAmountToTransfer;
559
+
560
+ if (premium.premiumAmount != totalTransferred) {
561
+ revert ErrorPolicyServiceTransferredPremiumMismatch(
562
+ policyNftId,
563
+ premium.premiumAmount,
564
+ totalTransferred);
565
+ }
566
+ }
567
+
568
+ // TODO: add logging
569
+ }
570
+ }
@@ -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
+ }