@etherisc/gif-next 0.0.2-b3a8633-027 → 0.0.2-b3a9c97-695

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 (332) hide show
  1. package/README.md +16 -2
  2. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
  3. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +21 -21
  4. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
  5. package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
  6. package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +2 -2
  7. package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
  8. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
  9. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
  10. package/artifacts/contracts/authorization/IModuleAuthorization.sol/IModuleAuthorization.dbg.json +1 -1
  11. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
  12. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.dbg.json +1 -1
  13. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.json +2 -2
  14. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
  15. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +2 -2
  16. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
  17. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +77 -64
  18. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
  19. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +16 -16
  20. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  21. package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +43 -38
  22. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  23. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +237 -74
  24. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  25. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +66 -38
  26. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  27. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +43 -0
  28. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  29. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +71 -0
  30. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
  31. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +2 -2
  32. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  33. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  34. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  35. package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
  36. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +44 -44
  38. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
  39. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +14 -14
  40. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  41. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +80 -122
  42. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +16 -16
  44. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  45. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +9 -9
  46. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  47. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +72 -194
  48. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +2 -2
  50. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  51. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
  52. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
  53. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
  54. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.json +2 -2
  55. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
  56. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +2 -2
  57. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  61. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  62. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  63. package/artifacts/contracts/mock/Dip.sol/Dip.dbg.json +1 -1
  64. package/artifacts/contracts/mock/Dip.sol/Dip.json +2 -2
  65. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
  66. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +51 -51
  67. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
  68. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +2 -2
  69. package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
  70. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
  71. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +30 -0
  72. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
  73. package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
  74. package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +27 -35
  75. package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
  76. package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +2 -2
  77. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
  78. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +2 -2
  79. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
  80. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +54 -99
  81. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
  82. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +16 -16
  83. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  84. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +438 -51
  85. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  86. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +102 -26
  87. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  88. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +205 -1
  89. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  90. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +44 -57
  91. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  92. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +158 -54
  93. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  94. package/artifacts/contracts/pool/Pool.sol/Pool.json +44 -95
  95. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  96. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +281 -90
  97. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  98. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +47 -19
  99. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  100. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +21 -32
  101. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  102. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +9 -17
  103. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
  104. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.json +19 -38
  105. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
  106. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +16 -16
  107. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  108. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +129 -58
  109. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  110. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +42 -30
  111. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  112. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.json +5 -0
  113. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  114. package/artifacts/contracts/product/IClaimService.sol/IClaimService.json +16 -0
  115. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  116. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.json +188 -108
  117. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  118. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  119. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.json +19 -0
  120. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +1 -1
  121. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  122. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +339 -167
  123. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  124. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +66 -26
  125. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  126. package/artifacts/contracts/product/PricingService.sol/PricingService.json +7 -2
  127. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  128. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +2 -2
  129. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  130. package/artifacts/contracts/product/Product.sol/Product.json +19 -38
  131. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +1 -1
  132. package/artifacts/contracts/product/ProductService.sol/ProductService.json +2 -2
  133. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  134. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  135. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  136. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +16 -40
  137. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  138. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +12 -1
  139. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  140. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  141. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  142. package/artifacts/contracts/registry/Registry.sol/Registry.json +50 -165
  143. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
  144. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +114 -239
  145. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  146. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  147. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  148. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  149. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
  150. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
  151. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +35 -16
  152. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
  153. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +2 -2
  154. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  155. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  156. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  157. package/artifacts/contracts/shared/Component.sol/Component.json +0 -38
  158. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  159. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +326 -62
  160. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  161. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +72 -32
  162. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +1 -1
  163. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  164. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
  165. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +153 -0
  166. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
  167. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.json +19 -0
  168. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  169. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  170. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  171. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  172. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  173. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  174. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  175. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.dbg.json +1 -1
  176. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +4 -0
  177. package/artifacts/contracts/shared/{ERC165.sol/ERC165.json → InitializableERC165.sol/InitializableERC165.json} +4 -4
  178. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
  179. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.json +19 -38
  180. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  181. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  182. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
  183. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  184. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  185. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  186. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  187. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  188. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  189. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  190. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  191. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  192. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  193. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +53 -6
  194. package/artifacts/contracts/shared/TokenTransferLib.sol/TokenTransferLib.dbg.json +4 -0
  195. package/artifacts/contracts/shared/TokenTransferLib.sol/TokenTransferLib.json +42 -0
  196. package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
  197. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  198. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +1 -1
  199. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +12 -2
  200. package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
  201. package/artifacts/contracts/staking/Staking.sol/Staking.json +60 -74
  202. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
  203. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
  204. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +31 -19
  205. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
  206. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +2 -2
  207. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  208. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +22 -22
  209. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
  210. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +12 -12
  211. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
  212. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +17 -12
  213. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
  214. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +7 -2
  215. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  216. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  217. package/artifacts/contracts/type/Amount.sol/AmountLib.json +37 -8
  218. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  219. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.json +2 -2
  220. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  221. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  222. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  223. package/artifacts/contracts/type/Fee.sol/FeeLib.json +7 -2
  224. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  225. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  226. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  227. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  228. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  229. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  230. package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
  231. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
  232. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  233. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  234. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  235. package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +26 -2
  236. package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
  237. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
  238. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  239. package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
  240. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  241. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +23 -4
  242. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +1 -1
  243. package/artifacts/contracts/type/UFixed.sol/MathLib.json +9 -3
  244. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  245. package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +39 -2
  246. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  247. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  248. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
  249. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  250. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +2 -2
  251. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  252. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
  253. package/contracts/authorization/AccessAdmin.sol +1 -0
  254. package/contracts/distribution/BasicDistribution.sol +4 -15
  255. package/contracts/distribution/BasicDistributionAuthorization.sol +5 -1
  256. package/contracts/distribution/Distribution.sol +22 -10
  257. package/contracts/distribution/DistributionService.sol +46 -11
  258. package/contracts/distribution/IDistributionComponent.sol +8 -4
  259. package/contracts/distribution/IDistributionService.sol +10 -0
  260. package/contracts/instance/InstanceAuthorizationV3.sol +2 -0
  261. package/contracts/instance/InstanceReader.sol +10 -7
  262. package/contracts/instance/InstanceService.sol +51 -27
  263. package/contracts/instance/InstanceStore.sol +2 -1
  264. package/contracts/instance/base/ObjectLifecycle.sol +2 -3
  265. package/contracts/instance/module/IBundle.sol +1 -1
  266. package/contracts/instance/module/IComponents.sol +1 -7
  267. package/contracts/instance/module/IDistribution.sol +0 -1
  268. package/contracts/instance/module/IPolicy.sol +1 -1
  269. package/contracts/mock/Dip.sol +1 -1
  270. package/contracts/oracle/IOracleComponent.sol +2 -1
  271. package/contracts/oracle/Oracle.sol +15 -6
  272. package/contracts/pool/BasicPool.sol +7 -5
  273. package/contracts/pool/BasicPoolAuthorization.sol +11 -2
  274. package/contracts/pool/BundleService.sol +169 -16
  275. package/contracts/pool/IBundleService.sol +32 -5
  276. package/contracts/pool/IPoolComponent.sol +6 -0
  277. package/contracts/pool/IPoolService.sol +14 -17
  278. package/contracts/pool/Pool.sol +32 -15
  279. package/contracts/pool/PoolService.sol +146 -58
  280. package/contracts/product/ApplicationService.sol +37 -17
  281. package/contracts/product/BasicProduct.sol +3 -33
  282. package/contracts/product/BasicProductAuthorization.sol +3 -0
  283. package/contracts/product/ClaimService.sol +9 -8
  284. package/contracts/product/IApplicationService.sol +1 -0
  285. package/contracts/product/IClaimService.sol +1 -0
  286. package/contracts/product/IPolicyService.sol +23 -17
  287. package/contracts/product/IProductComponent.sol +1 -0
  288. package/contracts/product/PolicyService.sol +251 -131
  289. package/contracts/product/PricingService.sol +5 -1
  290. package/contracts/product/Product.sol +27 -6
  291. package/contracts/registry/ChainNft.sol +27 -28
  292. package/contracts/registry/IRegistry.sol +3 -2
  293. package/contracts/registry/Registry.sol +69 -60
  294. package/contracts/registry/RegistryAdmin.sol +49 -131
  295. package/contracts/registry/ReleaseRegistry.sol +24 -72
  296. package/contracts/shared/Component.sol +21 -21
  297. package/contracts/shared/ComponentService.sol +73 -14
  298. package/contracts/shared/IComponent.sol +4 -3
  299. package/contracts/shared/IComponentService.sol +15 -9
  300. package/contracts/shared/IInstanceLinkedComponent.sol +9 -3
  301. package/contracts/shared/{ERC165.sol → InitializableERC165.sol} +1 -1
  302. package/contracts/shared/InstanceLinkedComponent.sol +21 -0
  303. package/contracts/shared/NftOwnable.sol +2 -2
  304. package/contracts/shared/PolicyHolder.sol +2 -5
  305. package/contracts/shared/TokenHandler.sol +4 -0
  306. package/contracts/shared/TokenTransferLib.sol +60 -0
  307. package/contracts/staking/Staking.sol +9 -3
  308. package/contracts/staking/StakingService.sol +8 -12
  309. package/contracts/type/Amount.sol +12 -5
  310. package/contracts/type/Blocknumber.sol +7 -1
  311. package/contracts/type/Referral.sol +1 -0
  312. package/contracts/type/Seconds.sol +13 -1
  313. package/contracts/type/Timestamp.sol +11 -1
  314. package/contracts/type/UFixed.sol +29 -10
  315. package/package.json +1 -1
  316. package/artifacts/contracts/registry/GlobalRegistry.sol/GlobalRegistry.dbg.json +0 -4
  317. package/artifacts/contracts/registry/GlobalRegistry.sol/GlobalRegistry.json +0 -1503
  318. package/artifacts/contracts/registry/GlobalRegistryAdmin.sol/GlobalRegistryAdmin.dbg.json +0 -4
  319. package/artifacts/contracts/registry/GlobalRegistryAdmin.sol/GlobalRegistryAdmin.json +0 -1881
  320. package/artifacts/contracts/registry/IGlobalRegistry.sol/IGlobalRegistry.dbg.json +0 -4
  321. package/artifacts/contracts/registry/IGlobalRegistry.sol/IGlobalRegistry.json +0 -974
  322. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +0 -4
  323. package/artifacts/contracts/shared/MainnetId.sol/MainnetContract.dbg.json +0 -4
  324. package/artifacts/contracts/shared/MainnetId.sol/MainnetContract.json +0 -34
  325. package/artifacts/contracts/shared/MainnetId.sol/MainnetId.dbg.json +0 -4
  326. package/artifacts/contracts/shared/MainnetId.sol/MainnetId.json +0 -24
  327. package/artifacts/contracts/shared/MainnetId.sol/SidenetContract.dbg.json +0 -4
  328. package/artifacts/contracts/shared/MainnetId.sol/SidenetContract.json +0 -34
  329. package/contracts/registry/GlobalRegistry.sol +0 -95
  330. package/contracts/registry/GlobalRegistryAdmin.sol +0 -38
  331. package/contracts/registry/IGlobalRegistry.sol +0 -17
  332. package/contracts/shared/MainnetId.sol +0 -29
@@ -1,26 +1,22 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {IRegistry} from "../registry/IRegistry.sol";
5
7
  import {Product} from "./Product.sol";
6
8
  import {IComponents} from "../instance/module/IComponents.sol";
7
- import {IDistributionComponent} from "../distribution/IDistributionComponent.sol";
8
9
  import {IInstance} from "../instance/IInstance.sol";
9
10
  import {IPolicy} from "../instance/module/IPolicy.sol";
10
- import {IPoolComponent} from "../pool/IPoolComponent.sol";
11
- import {IRisk} from "../instance/module/IRisk.sol";
12
- import {IBundle} from "../instance/module/IBundle.sol";
13
11
 
14
12
  import {TokenHandler} from "../shared/TokenHandler.sol";
13
+ import {TokenTransferLib} from "../shared/TokenTransferLib.sol";
15
14
 
16
15
  import {Amount, AmountLib} from "../type/Amount.sol";
17
- import {ClaimId, ClaimIdLib} from "../type/ClaimId.sol";
18
16
  import {Timestamp, TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";
19
- import {UFixed, UFixedLib} from "../type/UFixed.sol";
20
17
  import {ObjectType, APPLICATION, COMPONENT, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM, PRICE} from "../type/ObjectType.sol";
21
- import {APPLIED, COLLATERALIZED, ACTIVE, KEEP_STATE, CLOSED, DECLINED, CONFIRMED} from "../type/StateId.sol";
18
+ import {APPLIED, COLLATERALIZED, KEEP_STATE, CLOSED, DECLINED} from "../type/StateId.sol";
22
19
  import {NftId, NftIdLib} from "../type/NftId.sol";
23
- import {PayoutId, PayoutIdLib} from "../type/PayoutId.sol";
24
20
  import {ReferralId} from "../type/Referral.sol";
25
21
  import {StateId} from "../type/StateId.sol";
26
22
  import {VersionPart} from "../type/Version.sol";
@@ -36,8 +32,6 @@ import {InstanceStore} from "../instance/InstanceStore.sol";
36
32
  import {IPolicyService} from "./IPolicyService.sol";
37
33
  import {IPoolService} from "../pool/IPoolService.sol";
38
34
  import {IPricingService} from "./IPricingService.sol";
39
- import {IService} from "../shared/IService.sol";
40
- import {Service} from "../shared/Service.sol";
41
35
 
42
36
  contract PolicyService is
43
37
  ComponentVerifyingService,
@@ -85,26 +79,41 @@ contract PolicyService is
85
79
  }
86
80
 
87
81
 
88
- function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
89
- IRegistry.ObjectInfo memory productInfo;
90
- (, productInfo,) = _getAndVerifyActiveComponent(PRODUCT());
91
- product = Product(productInfo.objectAddress);
92
- }
93
-
94
-
95
82
  function decline(
96
- NftId policyNftId
83
+ NftId applicationNftId // = policyNftId
97
84
  )
98
85
  external
99
- override
86
+ virtual override
100
87
  {
101
- revert();
88
+ (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
89
+ InstanceReader instanceReader = instance.getInstanceReader();
90
+
91
+ // check policy is in state applied
92
+ if (instanceReader.getPolicyState(applicationNftId) != APPLIED()) {
93
+ revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId);
94
+ }
95
+
96
+ // check policy matches with calling product
97
+ IPolicy.PolicyInfo memory applicationInfo = instanceReader.getPolicyInfo(applicationNftId);
98
+ if(applicationInfo.productNftId != productNftId) {
99
+ revert ErrorPolicyServicePolicyProductMismatch(
100
+ applicationNftId,
101
+ applicationInfo.productNftId,
102
+ productNftId);
103
+ }
104
+
105
+
106
+ // store updated policy info
107
+ instance.getInstanceStore().updatePolicyState(
108
+ applicationNftId,
109
+ DECLINED());
110
+
111
+ emit LogPolicyServicePolicyDeclined(applicationNftId);
102
112
  }
103
113
 
104
- event LogDebug(uint idx, string message);
105
114
 
106
- /// @dev underwites application which includes the locking of the required collateral from the pool.
107
- function collateralize(
115
+ /// @inheritdoc IPolicyService
116
+ function createPolicy(
108
117
  NftId applicationNftId, // = policyNftId
109
118
  bool requirePremiumPayment,
110
119
  Timestamp activateAt
@@ -146,19 +155,20 @@ contract PolicyService is
146
155
 
147
156
  // optional activation of policy
148
157
  if(activateAt > zeroTimestamp()) {
149
- newPolicyState = ACTIVE();
150
158
  applicationInfo.activatedAt = activateAt;
151
159
  applicationInfo.expiredAt = activateAt.addSeconds(applicationInfo.lifetime);
152
160
  }
153
161
 
154
- // optional collection of premium
162
+ IPolicy.Premium memory premium;
163
+
164
+ // optional: calculate the premium and update counters for collection at the end of this function
155
165
  if(requirePremiumPayment) {
156
- Amount premiumPaidAmount = _calculateAndCollectPremium(
166
+ premium = _calculateAndProcessPremium(
157
167
  instance,
158
168
  applicationNftId,
159
169
  applicationInfo);
160
170
 
161
- applicationInfo.premiumPaidAmount = premiumPaidAmount;
171
+ applicationInfo.premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
162
172
  }
163
173
 
164
174
  // store updated policy info
@@ -170,9 +180,17 @@ contract PolicyService is
170
180
  // TODO add calling pool contract if it needs to validate application
171
181
 
172
182
  // TODO: add logging
183
+
184
+ // optional: transfer funds for premium
185
+ if(requirePremiumPayment) {
186
+ _transferFunds(instanceReader, applicationNftId, applicationInfo.productNftId, premium);
187
+ }
188
+
189
+ // TODO: add callback IPolicyHolder.policyActivated() if applicable
173
190
  }
174
191
 
175
192
 
193
+ /// @inheritdoc IPolicyService
176
194
  function collectPremium(
177
195
  NftId policyNftId,
178
196
  Timestamp activateAt
@@ -186,8 +204,8 @@ contract PolicyService is
186
204
  StateId stateId = instanceReader.getPolicyState(policyNftId);
187
205
 
188
206
  // check policy is in state collateralized or active
189
- if (!(stateId == COLLATERALIZED() || stateId == ACTIVE())) {
190
- revert ErrorPolicyServicePolicyStateNotCollateralizedOrApplied(policyNftId);
207
+ if (!(stateId == COLLATERALIZED())) {
208
+ revert ErrorPolicyServicePolicyStateNotCollateralized(policyNftId);
191
209
  }
192
210
 
193
211
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
@@ -197,50 +215,99 @@ contract PolicyService is
197
215
  revert ErrorPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
198
216
  }
199
217
 
200
- policyInfo.premiumPaidAmount = _calculateAndCollectPremium(
218
+ // calculate premium
219
+ IPolicy.Premium memory premium = _calculateAndProcessPremium(
201
220
  instance,
202
221
  policyNftId,
203
222
  policyInfo);
204
223
 
205
- instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
224
+ policyInfo.premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
206
225
 
207
- if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
208
- activate(policyNftId, activateAt);
226
+ // optionally activate policy
227
+ if(activateAt.gtz()) {
228
+ policyInfo = _activate(policyNftId, policyInfo, activateAt);
209
229
  }
210
230
 
231
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
232
+
211
233
  // TODO: add logging
234
+
235
+ _transferFunds(instanceReader, policyNftId, policyInfo.productNftId, premium);
236
+
237
+ // TODO: add callback IPolicyHolder.policyActivated() if applicable
212
238
  }
213
239
 
240
+ /// @inheritdoc IPolicyService
214
241
  function activate(NftId policyNftId, Timestamp activateAt) public override {
215
242
  // check caller is registered product
216
243
  (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
217
244
  InstanceReader instanceReader = instance.getInstanceReader();
218
245
 
219
246
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
247
+ policyInfo = _activate(policyNftId, policyInfo, activateAt);
220
248
 
221
- require(
222
- policyInfo.activatedAt.eqz(),
223
- "ERROR:PRS-020:ALREADY_ACTIVATED");
224
-
225
- policyInfo.activatedAt = activateAt;
226
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
227
-
228
- instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, ACTIVE());
249
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
229
250
 
230
251
  // TODO: add logging
252
+
253
+ // TODO: add callback IPolicyHolder.policyActivated() if applicable
231
254
  }
232
255
 
233
256
 
257
+ /// @inheritdoc IPolicyService
234
258
  function expire(
235
- NftId policyNftId
259
+ NftId policyNftId,
260
+ Timestamp expireAt
236
261
  )
237
262
  external
238
263
  override
239
- // solhint-disable-next-line no-empty-blocks
264
+ virtual
265
+ returns (Timestamp expiredAt)
240
266
  {
241
-
267
+ (NftId productNftId,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
268
+ InstanceReader instanceReader = instance.getInstanceReader();
269
+
270
+ // check policy matches with calling product
271
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
272
+ if(policyInfo.productNftId != productNftId) {
273
+ revert ErrorPolicyServicePolicyProductMismatch(
274
+ policyNftId,
275
+ policyInfo.productNftId,
276
+ productNftId);
277
+ }
278
+
279
+ // check policy is active
280
+ StateId policyState = instanceReader.getPolicyState(policyNftId);
281
+ if (!_policyHasBeenActivated(policyState, policyInfo)) {
282
+ revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
283
+ }
284
+
285
+ // set return value to provided timestamp
286
+ expiredAt = expireAt;
287
+
288
+ // update expiredAt to current block timestamp if not set
289
+ if (expiredAt.eqz()) {
290
+ expiredAt = TimestampLib.blockTimestamp();
291
+ }
292
+
293
+ // check expiredAt represents a valid expiry time
294
+ if (expiredAt >= policyInfo.expiredAt) {
295
+ revert ErrorPolicyServicePolicyExpirationTooLate(policyNftId, policyInfo.expiredAt, expireAt);
296
+ }
297
+ if (expiredAt < TimestampLib.blockTimestamp()) {
298
+ revert ErrorPolicyServicePolicyExpirationTooEarly(policyNftId, TimestampLib.blockTimestamp(), expireAt);
299
+ }
300
+
301
+ // update policyInfo with new expiredAt timestamp
302
+ policyInfo.expiredAt = expiredAt;
303
+ instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, KEEP_STATE());
304
+
305
+ emit LogPolicyServicePolicyExpirationUpdated(policyNftId, expiredAt);
306
+
307
+ // TODO: add callback IPolicyHolder.policyExpired() if applicable
242
308
  }
243
309
 
310
+
244
311
  function close(
245
312
  NftId policyNftId
246
313
  )
@@ -250,19 +317,21 @@ contract PolicyService is
250
317
  (,, IInstance instance) = _getAndVerifyActiveComponent(PRODUCT());
251
318
  InstanceReader instanceReader = instance.getInstanceReader();
252
319
 
320
+ // check that policy has been activated
253
321
  IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
254
-
255
- if (policyInfo.activatedAt.eqz()) {
256
- revert ErrorIPolicyServicePolicyNotActivated(policyNftId);
322
+ StateId policyState = instanceReader.getPolicyState(policyNftId);
323
+ if (!_policyHasBeenActivated(policyState, policyInfo)) {
324
+ revert ErrorPolicyServicePolicyNotActive(policyNftId, policyState);
257
325
  }
258
326
 
259
- StateId state = instanceReader.getPolicyState(policyNftId);
260
- if (state != ACTIVE()) {
261
- revert ErrorIPolicyServicePolicyNotActive(policyNftId, state);
327
+ // check that policy has not already been closed
328
+ if (policyInfo.closedAt.gtz()) {
329
+ revert ErrorPolicyServicePolicyAlreadyClosed(policyNftId);
262
330
  }
263
331
 
264
- if (policyInfo.closedAt.gtz()) {
265
- revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
332
+ // check that policy does not have any open claims
333
+ if (policyInfo.openClaimsCount > 0) {
334
+ revert ErrorPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
266
335
  }
267
336
 
268
337
  // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
@@ -270,23 +339,21 @@ contract PolicyService is
270
339
  revert ErrorPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
271
340
  }
272
341
 
273
- if (policyInfo.openClaimsCount > 0) {
274
- revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
275
- }
276
-
277
- policyInfo.closedAt = TimestampLib.blockTimestamp();
278
-
342
+ // release (remaining) collateral that was blocked by policy
279
343
  _poolService.releaseCollateral(
280
344
  instance,
281
345
  address(instanceReader.getComponentInfo(policyInfo.productNftId).token),
282
346
  policyNftId,
283
347
  policyInfo);
284
348
 
349
+ // update policy state to closed
350
+ policyInfo.closedAt = TimestampLib.blockTimestamp();
285
351
  instance.getInstanceStore().updatePolicy(policyNftId, policyInfo, CLOSED());
286
352
  }
287
353
 
288
354
 
289
- function _calculateAndCollectPremium(
355
+ /// @dev calculates the premium and updates all counters in the other services
356
+ function _calculateAndProcessPremium(
290
357
  IInstance instance,
291
358
  NftId applicationNftId,
292
359
  IPolicy.PolicyInfo memory applicationInfo
@@ -294,13 +361,14 @@ contract PolicyService is
294
361
  internal
295
362
  virtual
296
363
  returns (
297
- Amount premiumPaidAmount
364
+ IPolicy.Premium memory premium
298
365
  )
299
366
  {
300
367
  NftId productNftId = applicationInfo.productNftId;
368
+ InstanceReader instanceReader = instance.getInstanceReader();
301
369
 
302
370
  // calculate premium details
303
- IPolicy.Premium memory premium = _pricingService.calculatePremium(
371
+ premium = _pricingService.calculatePremium(
304
372
  productNftId,
305
373
  applicationInfo.riskId,
306
374
  applicationInfo.sumInsuredAmount,
@@ -309,90 +377,53 @@ contract PolicyService is
309
377
  applicationInfo.bundleNftId,
310
378
  applicationInfo.referralId);
311
379
 
380
+ // check if premium balance and allowance of policy holder is sufficient
381
+ {
382
+ TokenHandler tokenHandler = _getTokenHandler(instanceReader, productNftId);
383
+ address policyHolder = getRegistry().ownerOf(applicationNftId);
384
+
385
+ _checkPremiumBalanceAndAllowance(
386
+ tokenHandler.getToken(),
387
+ address(tokenHandler),
388
+ policyHolder,
389
+ AmountLib.toAmount(premium.premiumAmount));
390
+ }
312
391
 
313
- // update financials and transfer premium tokens
314
- premiumPaidAmount = _processAndCollect(
315
- instance,
316
- productNftId,
317
- applicationNftId,
318
- applicationInfo.premiumAmount,
319
- applicationInfo.bundleNftId,
320
- applicationInfo.referralId,
321
- premium);
322
- }
323
-
324
-
325
- function _processAndCollect(
326
- IInstance instance,
327
- NftId productNftId,
328
- NftId policyNftId,
329
- Amount premiumExpectedAmount,
330
- NftId bundleNftId,
331
- ReferralId referralId,
332
- IPolicy.Premium memory premium
333
- )
334
- internal
335
- virtual
336
- returns (Amount premiumPaidAmount)
337
- {
338
- InstanceReader instanceReader = instance.getInstanceReader();
339
- TokenHandler tokenHandler = instanceReader.getComponentInfo(productNftId).tokenHandler;
340
- address policyHolder = getRegistry().ownerOf(policyNftId);
341
- premiumPaidAmount = AmountLib.toAmount(premium.premiumAmount);
342
-
343
- _checkPremiumBalanceAndAllowance(
344
- tokenHandler,
345
- policyHolder,
346
- premiumExpectedAmount,
347
- premiumPaidAmount);
348
-
349
- _processSaleAndTransferFunds(
392
+ // update the counters
393
+ _processSale(
350
394
  instanceReader,
351
395
  instance.getInstanceStore(),
352
- tokenHandler,
353
- policyHolder,
354
396
  productNftId,
355
- bundleNftId,
356
- referralId,
397
+ applicationInfo.bundleNftId,
398
+ applicationInfo.referralId,
357
399
  premium);
358
400
  }
359
401
 
360
402
 
361
- function _checkPremiumBalanceAndAllowance(
362
- TokenHandler tokenHandler,
363
- address policyHolder,
364
- Amount premiumExpectedAmount,
365
- Amount premiumPaidAmount
403
+ function _activate(
404
+ NftId policyNftId,
405
+ IPolicy.PolicyInfo memory policyInfo,
406
+ Timestamp activateAt
366
407
  )
367
408
  internal
368
409
  virtual
369
- view
410
+ view
411
+ returns (IPolicy.PolicyInfo memory)
370
412
  {
371
- // TODO decide how to handle this properly
372
- // not clear if this is the best way to handle this
373
- if (premiumExpectedAmount < premiumPaidAmount) {
374
- revert ErrorPolicyServicePremiumHigherThanExpected(premiumExpectedAmount, premiumPaidAmount);
413
+ if(! policyInfo.activatedAt.eqz()) {
414
+ revert ErrorPolicyServicePolicyAlreadyActivated(policyNftId);
375
415
  }
376
416
 
377
- uint256 premiumAmount = premiumPaidAmount.toInt();
378
- uint256 balance = tokenHandler.getToken().balanceOf(policyHolder);
379
- uint256 allowance = tokenHandler.getToken().allowance(policyHolder, address(tokenHandler));
380
-
381
- if (balance < premiumAmount) {
382
- revert ErrorPolicyServiceBalanceInsufficient(policyHolder, premiumAmount, balance);
383
- }
417
+ policyInfo.activatedAt = activateAt;
418
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
384
419
 
385
- if (allowance < premiumAmount) {
386
- revert ErrorPolicyServiceAllowanceInsufficient(policyHolder, address(tokenHandler), premiumAmount, allowance);
387
- }
420
+ return policyInfo;
388
421
  }
389
422
 
390
-
391
- function _processSaleAndTransferFunds(
423
+ /// @dev update counters by calling the involved services
424
+ function _processSale(
392
425
  InstanceReader instanceReader,
393
426
  InstanceStore instanceStore,
394
- TokenHandler tokenHandler,
395
- address policyHolder,
396
427
  NftId productNftId,
397
428
  NftId bundleNftId,
398
429
  ReferralId referralId,
@@ -426,15 +457,97 @@ contract PolicyService is
426
457
  _poolService.processSale(
427
458
  bundleNftId,
428
459
  premium);
460
+ }
461
+
462
+
463
+ /// @dev transfer the premium to the wallets the premium is distributed to
464
+ function _transferFunds(
465
+ InstanceReader instanceReader,
466
+ NftId policyNftId,
467
+ NftId productNftId,
468
+ IPolicy.Premium memory premium
469
+ )
470
+ internal
471
+ virtual
472
+ {
473
+ TokenHandler tokenHandler = _getTokenHandler(instanceReader, productNftId);
474
+ address policyHolder = getRegistry().ownerOf(policyNftId);
475
+
476
+ (
477
+ ,
478
+ address distributionWallet,
479
+ address poolWallet,
480
+ address productWallet
481
+ ) = _getDistributionNftAndWallets(
482
+ instanceReader,
483
+ productNftId);
484
+
485
+ if (premium.productFeeAmount.gtz()) {
486
+ TokenTransferLib.collectTokens(
487
+ policyHolder,
488
+ productWallet,
489
+ premium.productFeeAmount,
490
+ tokenHandler);
491
+ }
492
+ if (premium.distributionFeeAndCommissionAmount.gtz()) {
493
+ TokenTransferLib.collectTokens(
494
+ policyHolder,
495
+ distributionWallet,
496
+ premium.distributionFeeAndCommissionAmount,
497
+ tokenHandler);
498
+ }
499
+ if (premium.poolPremiumAndFeeAmount.gtz()) {
500
+ TokenTransferLib.collectTokens(
501
+ policyHolder,
502
+ poolWallet,
503
+ premium.poolPremiumAndFeeAmount,
504
+ tokenHandler);
505
+ }
506
+ }
429
507
 
430
- // transfer premium amounts to target wallets
431
- tokenHandler.transfer(policyHolder, productWallet, premium.productFeeAmount);
432
- tokenHandler.transfer(policyHolder, distributionWallet, premium.distributionFeeAndCommissionAmount);
433
- tokenHandler.transfer(policyHolder, poolWallet, premium.poolPremiumAndFeeAmount);
508
+
509
+ /// @dev checks that policy has been collateralized and has been activated.
510
+ /// does not check if policy has been expired or closed.
511
+ function _policyHasBeenActivated(
512
+ StateId policyState,
513
+ IPolicy.PolicyInfo memory policyInfo
514
+ )
515
+ internal
516
+ view
517
+ returns (bool)
518
+ {
519
+ if (policyState != COLLATERALIZED()) { return false; }
520
+ if (TimestampLib.blockTimestamp() < policyInfo.activatedAt) { return false; }
521
+ return true;
434
522
  }
435
523
 
436
524
 
437
- function _getTokenHandlerAndProductWallet(
525
+ /// @dev checks the balance and allowance of the policy holder
526
+ function _checkPremiumBalanceAndAllowance(
527
+ IERC20Metadata token,
528
+ address tokenHandlerAddress,
529
+ address policyHolder,
530
+ Amount premiumAmount
531
+ )
532
+ internal
533
+ virtual
534
+ view
535
+ {
536
+ uint256 premium = premiumAmount.toInt();
537
+ uint256 balance = token.balanceOf(policyHolder);
538
+ uint256 allowance = token.allowance(policyHolder, tokenHandlerAddress);
539
+
540
+ if (balance < premium) {
541
+ revert ErrorPolicyServiceBalanceInsufficient(policyHolder, premium, balance);
542
+ }
543
+
544
+ if (allowance < premium) {
545
+ revert ErrorPolicyServiceAllowanceInsufficient(policyHolder, tokenHandlerAddress, premium, allowance);
546
+ }
547
+ }
548
+
549
+
550
+ function _getTokenHandler(
438
551
  InstanceReader instanceReader,
439
552
  NftId productNftId
440
553
  )
@@ -469,6 +582,13 @@ contract PolicyService is
469
582
  }
470
583
 
471
584
 
585
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
586
+ IRegistry.ObjectInfo memory productInfo;
587
+ (, productInfo,) = _getAndVerifyActiveComponent(PRODUCT());
588
+ product = Product(productInfo.objectAddress);
589
+ }
590
+
591
+
472
592
  function _getDomain() internal pure override returns(ObjectType) {
473
593
  return POLICY();
474
594
  }
@@ -84,6 +84,7 @@ contract PricingService is
84
84
  IInstance instance
85
85
  ) = _getAndVerifyComponentInfo(productNftId, PRODUCT(), false);
86
86
 
87
+ // get instance reader from local instance variable
87
88
  reader = instance.getInstanceReader();
88
89
 
89
90
  // calculate net premium
@@ -104,19 +105,21 @@ contract PricingService is
104
105
  revert ErrorIPricingServiceBundlePoolMismatch(bundleNftId, bundleInfo.poolNftId, productInfo.poolNftId);
105
106
  }
106
107
 
107
- // calculate premium, order is important
108
+ // calculate fixed fees for product, pool, bundle
108
109
  premium = _getFixedFeeAmounts(
109
110
  netPremiumAmount,
110
111
  productInfo,
111
112
  bundleInfo
112
113
  );
113
114
 
115
+ // calculate variable fees for product, pool, bundle
114
116
  premium = _calculateVariableFeeAmounts(
115
117
  premium,
116
118
  productInfo,
117
119
  bundleInfo
118
120
  );
119
121
 
122
+ // calculate distribution fee and (if applicable) commission
120
123
  premium = _calculateDistributionOwnerFeeAmount(
121
124
  premium,
122
125
  productInfo,
@@ -124,6 +127,7 @@ contract PricingService is
124
127
  reader
125
128
  );
126
129
 
130
+ // calculate resulting amounts for product, pool, and distribution wallets
127
131
  premium = _calculateTargetWalletAmounts(premium);
128
132
 
129
133
  // sanity check to validate the fee calculation
@@ -62,7 +62,7 @@ abstract contract Product is
62
62
  NftId bundleNftId,
63
63
  ReferralId referralId
64
64
  )
65
- external
65
+ public
66
66
  view
67
67
  override
68
68
  returns (Amount premiumAmount)
@@ -102,6 +102,7 @@ abstract contract Product is
102
102
  onlyOwner()
103
103
  {
104
104
  _getProductStorage()._componentService.registerProduct();
105
+ _approveTokenHandler(type(uint256).max);
105
106
  }
106
107
 
107
108
 
@@ -134,7 +135,6 @@ abstract contract Product is
134
135
  return getRegistry().getNftId(address(_getProductStorage()._distribution));
135
136
  }
136
137
 
137
-
138
138
  function _initializeProduct(
139
139
  address registry,
140
140
  NftId instanceNftId,
@@ -233,6 +233,7 @@ abstract contract Product is
233
233
  address applicationOwner,
234
234
  RiskId riskId,
235
235
  Amount sumInsuredAmount,
236
+ Amount premiumAmount,
236
237
  Seconds lifetime,
237
238
  NftId bundleNftId,
238
239
  ReferralId referralId,
@@ -245,6 +246,7 @@ abstract contract Product is
245
246
  applicationOwner,
246
247
  riskId,
247
248
  sumInsuredAmount,
249
+ premiumAmount,
248
250
  lifetime,
249
251
  bundleNftId,
250
252
  referralId,
@@ -252,19 +254,38 @@ abstract contract Product is
252
254
  );
253
255
  }
254
256
 
255
- function _collateralize(
256
- NftId policyNftId,
257
+ function _createPolicy(
258
+ NftId applicationNftId,
257
259
  bool requirePremiumPayment,
258
260
  Timestamp activateAt
259
261
  )
260
262
  internal
261
263
  {
262
- _getProductStorage()._policyService.collateralize(
263
- policyNftId,
264
+ _getProductStorage()._policyService.createPolicy(
265
+ applicationNftId,
264
266
  requirePremiumPayment,
265
267
  activateAt);
266
268
  }
267
269
 
270
+ function _decline(
271
+ NftId policyNftId
272
+ )
273
+ internal
274
+ {
275
+ _getProductStorage()._policyService.decline(
276
+ policyNftId);
277
+ }
278
+
279
+ function _expire(
280
+ NftId policyNftId,
281
+ Timestamp expireAt
282
+ )
283
+ internal
284
+ returns (Timestamp expiredAt)
285
+ {
286
+ expiredAt = _getProductStorage()._policyService.expire(policyNftId, expireAt);
287
+ }
288
+
268
289
  function _collectPremium(
269
290
  NftId policyNftId,
270
291
  Timestamp activateAt