@etherisc/gif-next 0.0.2-299fe4a-464 → 0.0.2-2b0ce11-013

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 (390) hide show
  1. package/README.md +192 -7
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +176 -23
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +618 -0
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +129 -23
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +152 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +74 -181
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +55 -177
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +455 -60
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +484 -70
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.json +66 -0
  20. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.json +24 -0
  22. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.json +42 -0
  24. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  26. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  28. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  30. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  32. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  37. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  40. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  42. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  43. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
  44. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  45. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  46. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  47. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  48. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  49. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  50. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +4 -0
  51. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +101 -0
  52. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +4 -0
  53. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +1132 -0
  54. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +4 -0
  55. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +1082 -0
  56. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  57. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +584 -1592
  58. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  59. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +480 -0
  60. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  61. package/artifacts/contracts/instance/Instance.sol/Instance.json +2460 -1196
  62. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +4 -0
  63. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +917 -0
  64. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +4 -0
  65. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +1388 -0
  66. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +4 -0
  67. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +931 -0
  68. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  69. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +508 -0
  70. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +4 -0
  71. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +540 -0
  72. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  73. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +113 -0
  74. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +4 -0
  75. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +429 -0
  76. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  77. package/artifacts/contracts/instance/{module/lifecycle/ILifecycle.sol/ILifecycleModule.json → base/ILifecycle.sol/ILifecycle.json} +10 -77
  78. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +4 -0
  79. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +502 -0
  80. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +4 -0
  81. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +169 -0
  82. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +4 -0
  83. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +211 -0
  84. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +4 -0
  85. package/artifacts/contracts/instance/module/{bundle/IBundle.sol → IBundle.sol}/IBundle.json +1 -1
  86. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +4 -0
  87. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.json +10 -0
  88. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +4 -0
  89. package/artifacts/contracts/instance/module/{policy/IPolicy.sol → IPolicy.sol}/IPolicy.json +1 -1
  90. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +4 -0
  91. package/artifacts/contracts/instance/module/{access/IAccess.sol/IAccess.json → IRisk.sol/IRisk.json} +2 -2
  92. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +4 -0
  93. package/artifacts/contracts/instance/module/{pool/IPoolModule.sol/IPool.json → ISetup.sol/ISetup.json} +2 -2
  94. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +4 -0
  95. package/artifacts/contracts/instance/module/{treasury/ITreasury.sol → ITreasury.sol}/ITreasury.json +1 -1
  96. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +393 -85
  98. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  99. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +716 -0
  100. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  101. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +444 -0
  102. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  103. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +182 -80
  104. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  105. package/artifacts/contracts/instance/service/{ComponentServiceBase.sol/ComponentServiceBase.json → IDistributionService.sol/IDistributionService.json} +209 -63
  106. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  107. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +240 -55
  108. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  109. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +318 -56
  110. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  111. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +416 -76
  112. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  113. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +448 -0
  114. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  115. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +504 -103
  116. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  117. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +468 -0
  118. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  119. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +186 -12
  120. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  121. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +358 -37
  122. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +4 -0
  123. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +947 -0
  124. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +4 -0
  125. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +34 -0
  126. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  127. package/artifacts/contracts/registry/Registry.sol/Registry.json +466 -129
  128. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +4 -0
  129. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +1293 -0
  130. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +4 -0
  131. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +513 -0
  132. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  133. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
  134. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +4 -0
  135. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.json +107 -0
  136. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  137. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  138. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +4 -0
  139. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +127 -0
  140. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  141. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +117 -37
  142. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  143. package/artifacts/contracts/{instance/service → shared}/IService.sol/IService.json +180 -59
  144. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  145. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +60 -19
  146. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +4 -0
  147. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +158 -0
  148. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +4 -0
  149. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +349 -0
  150. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  151. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +190 -37
  152. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +4 -0
  153. package/artifacts/contracts/{instance/InstanceBase.sol/InstanceBase.json → shared/RegisterableUpgradable.sol/RegisterableUpgradable.json} +209 -80
  154. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  155. package/artifacts/contracts/{instance/service/ServiceBase.sol/ServiceBase.json → shared/Service.sol/Service.json} +227 -59
  156. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  157. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +96 -0
  158. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +4 -0
  159. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +129 -0
  160. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  161. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +83 -19
  162. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  163. package/artifacts/contracts/test/TestFee.sol/TestFee.json +30 -6
  164. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  165. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +204 -36
  166. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  167. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +44 -10
  168. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  169. package/artifacts/contracts/test/TestService.sol/TestService.json +277 -84
  170. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  171. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +91 -53
  172. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  173. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +14 -18
  174. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  175. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +106 -50
  176. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +4 -0
  177. package/artifacts/contracts/test/Usdc.sol/USDC.json +376 -0
  178. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  179. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.json +2 -2
  180. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  182. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  184. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +4 -0
  185. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +104 -0
  186. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +4 -0
  187. package/artifacts/contracts/types/Fee.sol/FeeLib.json +257 -0
  188. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +4 -0
  189. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +125 -0
  190. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +65 -4
  192. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  193. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  194. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +4 -0
  195. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.json +100 -0
  196. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  197. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  198. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +4 -0
  199. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +123 -0
  200. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  201. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  202. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
  203. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +156 -0
  204. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  205. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  206. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  207. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +15 -2
  208. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  209. package/artifacts/contracts/types/UFixed.sol/MathLib.json +10 -0
  210. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +4 -0
  211. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +479 -0
  212. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  213. package/artifacts/contracts/types/Version.sol/VersionLib.json +101 -2
  214. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  215. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
  216. package/contracts/components/BaseComponent.sol +26 -24
  217. package/contracts/components/Distribution.sol +159 -0
  218. package/contracts/components/IBaseComponent.sol +9 -3
  219. package/contracts/components/IDistributionComponent.sol +44 -0
  220. package/contracts/components/IPoolComponent.sol +14 -9
  221. package/contracts/components/IProductComponent.sol +25 -9
  222. package/contracts/components/Pool.sol +96 -28
  223. package/contracts/components/Product.sol +199 -32
  224. package/contracts/experiment/cloning/Cloner.sol +47 -0
  225. package/contracts/instance/AccessManagedSimple.sol +115 -0
  226. package/contracts/instance/AccessManagerSimple.sol +692 -0
  227. package/contracts/instance/IAccessManagerSimple.sol +391 -0
  228. package/contracts/instance/IInstance.sol +38 -40
  229. package/contracts/instance/IInstanceService.sol +30 -0
  230. package/contracts/instance/Instance.sol +426 -45
  231. package/contracts/instance/InstanceAccessManager.sol +288 -0
  232. package/contracts/instance/InstanceReader.sol +306 -0
  233. package/contracts/instance/InstanceService.sol +195 -0
  234. package/contracts/instance/InstanceServiceManager.sol +57 -0
  235. package/contracts/instance/base/ComponentServiceBase.sol +127 -0
  236. package/contracts/instance/base/IInstanceBase.sol +23 -0
  237. package/contracts/instance/base/IKeyValueStore.sol +49 -0
  238. package/contracts/instance/base/ILifecycle.sol +30 -0
  239. package/contracts/instance/base/KeyValueStore.sol +172 -0
  240. package/contracts/instance/{module/lifecycle/LifecycleModule.sol → base/Lifecycle.sol} +51 -40
  241. package/contracts/instance/module/IAccess.sol +38 -0
  242. package/contracts/instance/module/IBundle.sol +20 -0
  243. package/contracts/instance/module/IDistribution.sol +39 -0
  244. package/contracts/instance/module/IPolicy.sol +45 -0
  245. package/contracts/instance/module/IRisk.sol +11 -0
  246. package/contracts/instance/module/ISetup.sol +44 -0
  247. package/contracts/instance/module/ITreasury.sol +23 -0
  248. package/contracts/instance/service/ComponentOwnerService.sol +246 -103
  249. package/contracts/instance/service/DistributionService.sol +88 -0
  250. package/contracts/instance/service/DistributionServiceManager.sol +54 -0
  251. package/contracts/instance/service/IComponentOwnerService.sol +1 -3
  252. package/contracts/instance/service/IDistributionService.sol +12 -0
  253. package/contracts/instance/service/IPoolService.sol +8 -1
  254. package/contracts/instance/service/IProductService.sol +56 -7
  255. package/contracts/instance/service/PoolService.sol +139 -43
  256. package/contracts/instance/service/PoolServiceManager.sol +54 -0
  257. package/contracts/instance/service/ProductService.sol +375 -179
  258. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  259. package/contracts/registry/ChainNft.sol +80 -37
  260. package/contracts/registry/IRegistry.sol +47 -25
  261. package/contracts/registry/IRegistryService.sol +50 -0
  262. package/contracts/registry/ITransferInterceptor.sol +6 -0
  263. package/contracts/registry/Registry.sol +333 -270
  264. package/contracts/registry/RegistryService.sol +358 -0
  265. package/contracts/registry/RegistryServiceManager.sol +80 -0
  266. package/contracts/registry/TokenRegistry.sol +111 -0
  267. package/contracts/shared/ContractDeployerLib.sol +72 -0
  268. package/contracts/shared/ERC165.sol +6 -2
  269. package/contracts/shared/INftOwnable.sol +22 -0
  270. package/contracts/shared/IRegisterable.sol +8 -15
  271. package/contracts/{instance/service → shared}/IService.sol +3 -3
  272. package/contracts/shared/IVersionable.sol +56 -12
  273. package/contracts/shared/NftOwnable.sol +134 -0
  274. package/contracts/shared/ProxyManager.sol +94 -0
  275. package/contracts/shared/Registerable.sol +63 -59
  276. package/contracts/shared/RegisterableUpgradable.sol +16 -0
  277. package/contracts/shared/Service.sol +55 -0
  278. package/contracts/shared/TokenHandler.sol +27 -0
  279. package/contracts/shared/UpgradableProxyWithAdmin.sol +16 -0
  280. package/contracts/shared/Versionable.sol +112 -57
  281. package/contracts/test/TestFee.sol +4 -4
  282. package/contracts/test/TestRegisterable.sol +5 -6
  283. package/contracts/test/TestRoleId.sol +2 -2
  284. package/contracts/test/TestService.sol +6 -17
  285. package/contracts/test/TestVersion.sol +4 -7
  286. package/contracts/test/TestVersionable.sol +2 -5
  287. package/contracts/test/Usdc.sol +26 -0
  288. package/contracts/types/DistributorType.sol +55 -0
  289. package/contracts/types/Fee.sol +44 -20
  290. package/contracts/types/Key32.sol +50 -0
  291. package/contracts/types/NftId.sol +16 -1
  292. package/contracts/types/NumberId.sol +52 -0
  293. package/contracts/types/ObjectType.sol +51 -14
  294. package/contracts/types/Referral.sol +85 -0
  295. package/contracts/types/RiskId.sol +43 -0
  296. package/contracts/types/RoleId.sol +65 -11
  297. package/contracts/types/StateId.sol +12 -2
  298. package/contracts/types/Timestamp.sol +7 -3
  299. package/contracts/types/UFixed.sol +144 -25
  300. package/contracts/types/Version.sol +42 -26
  301. package/package.json +7 -3
  302. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +0 -4
  303. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.json +0 -24
  304. package/artifacts/contracts/instance/IServiceLinked.sol/IServiceLinked.dbg.json +0 -4
  305. package/artifacts/contracts/instance/IServiceLinked.sol/IServiceLinked.json +0 -50
  306. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +0 -4
  307. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +0 -4
  308. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.json +0 -333
  309. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +0 -4
  310. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +0 -4
  311. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.json +0 -333
  312. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +0 -4
  313. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +0 -276
  314. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +0 -4
  315. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +0 -4
  316. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +0 -276
  317. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +0 -4
  318. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +0 -188
  319. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +0 -4
  320. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.json +0 -10
  321. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +0 -4
  322. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +0 -188
  323. package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +0 -4
  324. package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycle.json +0 -134
  325. package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +0 -4
  326. package/artifacts/contracts/instance/module/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +0 -4
  327. package/artifacts/contracts/instance/module/lifecycle/LifecycleModule.sol/LifecycleModule.json +0 -221
  328. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +0 -4
  329. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +0 -4
  330. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +0 -261
  331. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +0 -4
  332. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +0 -261
  333. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +0 -4
  334. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +0 -4
  335. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -149
  336. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +0 -4
  337. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -149
  338. package/artifacts/contracts/instance/module/product/IProductModule.sol/IProductModule.dbg.json +0 -4
  339. package/artifacts/contracts/instance/module/product/IProductModule.sol/IProductModule.json +0 -10
  340. package/artifacts/contracts/instance/module/product/ProductModule.sol/ProductModule.dbg.json +0 -4
  341. package/artifacts/contracts/instance/module/product/ProductModule.sol/ProductModule.json +0 -10
  342. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +0 -4
  343. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +0 -4
  344. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +0 -538
  345. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +0 -4
  346. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +0 -76
  347. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +0 -4
  348. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +0 -538
  349. package/artifacts/contracts/instance/service/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +0 -4
  350. package/artifacts/contracts/instance/service/IService.sol/IService.dbg.json +0 -4
  351. package/artifacts/contracts/instance/service/ServiceBase.sol/ServiceBase.dbg.json +0 -4
  352. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +0 -4
  353. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +0 -452
  354. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +0 -4
  355. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.json +0 -24
  356. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +0 -4
  357. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.json +0 -24
  358. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +0 -4
  359. package/artifacts/contracts/test/TestPool.sol/TestPool.json +0 -387
  360. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +0 -4
  361. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +0 -393
  362. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +0 -4
  363. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +0 -453
  364. package/contracts/experiment/statemachine/README.md +0 -112
  365. package/contracts/instance/IInstanceLinked.sol +0 -8
  366. package/contracts/instance/IServiceLinked.sol +0 -12
  367. package/contracts/instance/InstanceBase.sol +0 -74
  368. package/contracts/instance/module/access/Access.sol +0 -149
  369. package/contracts/instance/module/access/IAccess.sol +0 -53
  370. package/contracts/instance/module/bundle/BundleModule.sol +0 -228
  371. package/contracts/instance/module/bundle/IBundle.sol +0 -53
  372. package/contracts/instance/module/component/ComponentModule.sol +0 -104
  373. package/contracts/instance/module/component/IComponent.sol +0 -53
  374. package/contracts/instance/module/lifecycle/ILifecycle.sol +0 -47
  375. package/contracts/instance/module/policy/IPolicy.sol +0 -60
  376. package/contracts/instance/module/policy/PolicyModule.sol +0 -84
  377. package/contracts/instance/module/pool/IPoolModule.sol +0 -41
  378. package/contracts/instance/module/pool/PoolModule.sol +0 -87
  379. package/contracts/instance/module/product/IProductModule.sol +0 -6
  380. package/contracts/instance/module/product/ProductModule.sol +0 -8
  381. package/contracts/instance/module/treasury/ITreasury.sol +0 -104
  382. package/contracts/instance/module/treasury/TokenHandler.sol +0 -48
  383. package/contracts/instance/module/treasury/TreasuryModule.sol +0 -148
  384. package/contracts/instance/service/ComponentServiceBase.sol +0 -41
  385. package/contracts/instance/service/ServiceBase.sol +0 -39
  386. package/contracts/registry/IChainNft.sol +0 -21
  387. package/contracts/registry/IRegistryLinked.sol +0 -8
  388. package/contracts/shared/IOwnable.sol +0 -6
  389. package/contracts/test/TestPool.sol +0 -22
  390. package/contracts/test/TestProduct.sol +0 -44
@@ -2,28 +2,42 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IProductComponent} from "../../components/IProductComponent.sol";
6
+ import {Product} from "../../components/Product.sol";
5
7
  import {IPoolComponent} from "../../components/IPoolComponent.sol";
6
- import {IInstance} from "../../instance/IInstance.sol";
7
- import {IPolicy, IPolicyModule} from "../module/policy/IPolicy.sol";
8
- import {IPool} from "../module/pool/IPoolModule.sol";
9
- import {IBundle} from "../module/bundle/IBundle.sol";
8
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
+ import {IInstance} from "../IInstance.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
11
+ import {IRisk} from "../module/IRisk.sol";
12
+ import {IBundle} from "../module/IBundle.sol";
10
13
  import {IProductService} from "./IProductService.sol";
11
- import {ITreasury, ITreasuryModule, TokenHandler} from "../../instance/module/treasury/ITreasury.sol";
14
+ import {ITreasury} from "../module/ITreasury.sol";
15
+ import {ISetup} from "../module/ISetup.sol";
16
+
17
+ import {TokenHandler} from "../../shared/TokenHandler.sol";
12
18
 
13
19
  import {IVersionable} from "../../shared/IVersionable.sol";
14
20
  import {Versionable} from "../../shared/Versionable.sol";
15
21
 
16
22
  import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
17
- import {UFixed, UFixedMathLib} from "../../types/UFixed.sol";
18
- import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
19
- import {APPLIED, UNDERWRITTEN, ACTIVE} from "../../types/StateId.sol";
20
- import {NftId, NftIdLib} from "../../types/NftId.sol";
23
+ import {UFixed, UFixedLib} from "../../types/UFixed.sol";
21
24
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
22
- import {Fee, feeIsZero} from "../../types/Fee.sol";
23
- import {Version, toVersion, toVersionPart} from "../../types/Version.sol";
24
-
25
- import {ComponentServiceBase} from "./ComponentServiceBase.sol";
25
+ import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
26
+ import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
27
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
28
+ import {Fee, FeeLib} from "../../types/Fee.sol";
29
+ import {ReferralId} from "../../types/Referral.sol";
30
+ import {RiskId} from "../../types/RiskId.sol";
31
+ import {StateId} from "../../types/StateId.sol";
32
+ import {Version, VersionLib} from "../../types/Version.sol";
33
+
34
+ import {IService} from "../../shared/IService.sol";
35
+ import {Service} from "../../shared/Service.sol";
36
+ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
26
37
  import {IProductService} from "./IProductService.sol";
38
+ import {InstanceReader} from "../InstanceReader.sol";
39
+
40
+ string constant PRODUCT_SERVICE_NAME = "ProductService";
27
41
 
28
42
  // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
29
43
  contract ProductService is ComponentServiceBase, IProductService {
@@ -31,70 +45,228 @@ contract ProductService is ComponentServiceBase, IProductService {
31
45
 
32
46
  string public constant NAME = "ProductService";
33
47
 
48
+ address internal _registryAddress;
49
+
34
50
  event LogProductServiceSender(address sender);
35
51
 
36
- constructor(
37
- address registry,
38
- NftId registryNftId
39
- ) ComponentServiceBase(registry, registryNftId) // solhint-disable-next-line no-empty-blocks
52
+ function _initialize(
53
+ address owner,
54
+ bytes memory data
55
+ )
56
+ internal
57
+ initializer
58
+ virtual override
40
59
  {
60
+ address initialOwner = address(0);
61
+ (_registryAddress, initialOwner) = abi.decode(data, (address, address));
62
+
63
+ _initializeService(_registryAddress, owner);
64
+
65
+ _registerInterface(type(IService).interfaceId);
41
66
  _registerInterface(type(IProductService).interfaceId);
42
67
  }
43
68
 
44
- function getVersion()
45
- public
46
- pure
47
- virtual override (IVersionable, Versionable)
48
- returns(Version)
49
- {
50
- return toVersion(
51
- toVersionPart(3),
52
- toVersionPart(0),
53
- toVersionPart(0));
54
- }
55
69
 
56
- function getName() external pure override returns(string memory name) {
70
+ function getName() public pure override(IService, Service) returns(string memory name) {
57
71
  return NAME;
58
72
  }
59
73
 
74
+ function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
75
+ ISetup.ProductSetupInfo memory initialSetup = abi.decode(
76
+ initialObjData,
77
+ (ISetup.ProductSetupInfo)
78
+ );
79
+ instance.createProductSetup(componentNftId, initialSetup);
80
+ }
81
+
60
82
  function setFees(
61
- Fee memory policyFee,
83
+ Fee memory productFee,
62
84
  Fee memory processingFee
63
85
  )
64
86
  external
65
87
  override
66
88
  {
67
89
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
68
- instance.setProductFees(productInfo.nftId, policyFee, processingFee);
90
+ InstanceReader instanceReader = instance.getInstanceReader();
91
+ NftId productNftId = productInfo.nftId;
92
+
93
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
94
+ productSetupInfo.productFee = productFee;
95
+ productSetupInfo.processingFee = processingFee;
96
+
97
+ instance.updateProductSetup(productNftId, productSetupInfo, KEEP_STATE());
98
+ }
99
+
100
+ function createRisk(
101
+ RiskId riskId,
102
+ bytes memory data
103
+ ) external override {
104
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
105
+ NftId productNftId = productInfo.nftId;
106
+ IRisk.RiskInfo memory riskInfo = IRisk.RiskInfo(productNftId, data);
107
+ instance.createRisk(
108
+ riskId,
109
+ riskInfo
110
+ );
111
+ }
112
+
113
+ function updateRisk(
114
+ RiskId riskId,
115
+ bytes memory data
116
+ ) external {
117
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
118
+ InstanceReader instanceReader = instance.getInstanceReader();
119
+ IRisk.RiskInfo memory riskInfo = instanceReader.getRiskInfo(riskId);
120
+ riskInfo.data = data;
121
+ instance.updateRisk(riskId, riskInfo, KEEP_STATE());
122
+ }
123
+
124
+ function updateRiskState(
125
+ RiskId riskId,
126
+ StateId state
127
+ ) external {
128
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
129
+ instance.updateRiskState(riskId, state);
130
+ }
131
+
132
+ function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
133
+ IRegistry.ObjectInfo memory productInfo;
134
+ (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
135
+ product = Product(productInfo.objectAddress);
136
+ }
137
+
138
+ function calculatePremium(
139
+ RiskId riskId,
140
+ uint256 sumInsuredAmount,
141
+ uint256 lifetime,
142
+ bytes memory applicationData,
143
+ NftId bundleNftId,
144
+ ReferralId referralId
145
+ )
146
+ public
147
+ view
148
+ override
149
+ returns (
150
+ uint256 premiumAmount,
151
+ uint256 productFeeAmount,
152
+ uint256 poolFeeAmount,
153
+ uint256 bundleFeeAmount,
154
+ uint256 distributionFeeAmount
155
+ )
156
+ {
157
+ Product product = _getAndVerifyInstanceAndProduct();
158
+ uint256 netPremiumAmount = product.calculateNetPremium(
159
+ sumInsuredAmount,
160
+ riskId,
161
+ lifetime,
162
+ applicationData
163
+ );
164
+
165
+ (
166
+ productFeeAmount,
167
+ poolFeeAmount,
168
+ bundleFeeAmount,
169
+ distributionFeeAmount
170
+ ) = _calculateFeeAmounts(
171
+ netPremiumAmount,
172
+ product,
173
+ bundleNftId,
174
+ referralId
175
+ );
176
+
177
+ premiumAmount = netPremiumAmount + productFeeAmount;
178
+ premiumAmount += poolFeeAmount + bundleFeeAmount;
179
+ premiumAmount += distributionFeeAmount;
69
180
  }
70
181
 
182
+ function _calculateFeeAmounts(
183
+ uint256 netPremiumAmount,
184
+ Product product,
185
+ NftId bundleNftId,
186
+ ReferralId referralId
187
+ )
188
+ internal
189
+ view
190
+ returns (
191
+ uint256 productFeeAmount,
192
+ uint256 poolFeeAmount,
193
+ uint256 bundleFeeAmount,
194
+ uint256 distributionFeeAmount
195
+ )
196
+ {
197
+ InstanceReader instanceReader;
198
+ {
199
+ IInstance instance = product.getInstance();
200
+ instanceReader = instance.getInstanceReader();
201
+ }
202
+
203
+ NftId poolNftId = product.getPoolNftId();
204
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
205
+ require(bundleInfo.poolNftId == poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
206
+
207
+ {
208
+ ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(product.getProductNftId());
209
+ (productFeeAmount,) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
210
+ }
211
+ {
212
+ ISetup.PoolSetupInfo memory poolSetupInfo = instanceReader.getPoolSetupInfo(poolNftId);
213
+ (poolFeeAmount,) = FeeLib.calculateFee(poolSetupInfo.poolFee, netPremiumAmount);
214
+ }
215
+ {
216
+ NftId distributionNftId = product.getDistributionNftId();
217
+ ISetup.DistributionSetupInfo memory distributionSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
218
+ (distributionFeeAmount,) = FeeLib.calculateFee(distributionSetupInfo.distributionFee, netPremiumAmount);
219
+ }
220
+
221
+ (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
222
+ }
223
+
224
+
71
225
  function createApplication(
72
226
  address applicationOwner,
227
+ RiskId riskId,
73
228
  uint256 sumInsuredAmount,
74
- uint256 premiumAmount,
75
229
  uint256 lifetime,
76
- NftId bundleNftId
230
+ bytes memory applicationData,
231
+ NftId bundleNftId,
232
+ ReferralId referralId
77
233
  ) external override returns (NftId policyNftId) {
78
234
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
79
- NftId productNftId = productInfo.nftId;
80
235
  // TODO add validations (see create bundle in pool service)
81
236
 
82
- policyNftId = this.getRegistry().registerObjectForInstance(
83
- productNftId,
84
- POLICY(),
85
- applicationOwner,
86
- ""
237
+ policyNftId = getRegistryService().registerPolicy(
238
+ IRegistry.ObjectInfo(
239
+ zeroNftId(),
240
+ productInfo.nftId,
241
+ POLICY(),
242
+ false, // intercepting property for policies is defined on product
243
+ address(0),
244
+ applicationOwner,
245
+ ""
246
+ )
87
247
  );
88
248
 
89
- instance.createApplication(
90
- productNftId,
91
- policyNftId,
249
+ (uint256 premiumAmount,,,,) = calculatePremium(
250
+ riskId,
92
251
  sumInsuredAmount,
93
- premiumAmount,
94
252
  lifetime,
95
- bundleNftId
253
+ applicationData,
254
+ bundleNftId,
255
+ referralId
96
256
  );
97
257
 
258
+ // FIXME: this
259
+ // instance.createPolicyInfo(
260
+ // policyNftId,
261
+ // productInfo.nftId,
262
+ // referralId,
263
+ // riskId,
264
+ // sumInsuredAmount,
265
+ // premiumAmount,
266
+ // lifetime,
267
+ // bundleNftId
268
+ // );
269
+
98
270
  // TODO add logging
99
271
  }
100
272
 
@@ -105,30 +277,30 @@ contract ProductService is ComponentServiceBase, IProductService {
105
277
  internal
106
278
  view
107
279
  returns (
108
- ITreasury.ProductSetup memory productSetup,
280
+ ITreasury.TreasuryInfo memory treasuryInfo,
281
+ NftId bundleNftId,
109
282
  IBundle.BundleInfo memory bundleInfo,
110
- uint256 collateralAmount,
111
- bool poolIsVerifying,
112
- bytes memory bundleFilter
283
+ uint256 collateralAmount
113
284
  )
114
285
  {
286
+ // FIXME: this
115
287
  // check match between policy and bundle (via pool)
116
- productSetup = instance.getProductSetup(policyInfo.productNftId);
117
- bundleInfo = instance.getBundleInfo(policyInfo.bundleNftId);
118
- require(bundleInfo.poolNftId == productSetup.poolNftId, "POLICY_BUNDLE_MISMATCH");
119
-
120
- // calculate required collateral
121
- NftId poolNftId = productSetup.poolNftId;
122
- IPool.PoolInfo memory poolInfo = instance.getPoolInfo(poolNftId);
123
-
124
- // obtain remaining return values
125
- poolIsVerifying = poolInfo.isVerifying;
126
- collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
127
- bundleFilter = bundleInfo.filter;
288
+ // treasuryInfo = instance.getTreasuryInfo(policyInfo.productNftId);
289
+ // bundleNftId = policyInfo.bundleNftId;
290
+ // bundleInfo = instance.getBundleInfo(bundleNftId);
291
+ // require(bundleInfo.poolNftId == treasuryInfo.poolNftId, "POLICY_BUNDLE_MISMATCH");
292
+
293
+ // // calculate required collateral
294
+ // NftId poolNftId = treasuryInfo.poolNftId;
295
+ // ISetup.PoolSetupInfo memory poolInfo = instance.getPoolInfo(poolNftId);
296
+
297
+ // // obtain remaining return values
298
+ // collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
128
299
  }
129
300
 
130
301
  function _lockCollateralInBundle(
131
302
  IInstance instance,
303
+ NftId bundleNftId,
132
304
  IBundle.BundleInfo memory bundleInfo,
133
305
  NftId policyNftId,
134
306
  uint256 collateralAmount
@@ -137,29 +309,40 @@ contract ProductService is ComponentServiceBase, IProductService {
137
309
  returns (IBundle.BundleInfo memory)
138
310
  {
139
311
  bundleInfo.lockedAmount += collateralAmount;
140
- bundleInfo.updatedIn = blockNumber();
141
- instance.collateralizePolicy(bundleInfo.nftId, policyNftId, collateralAmount);
312
+ // FIXME: this
313
+ // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
142
314
  return bundleInfo;
143
315
  }
144
316
 
145
317
  function _underwriteByPool(
146
- ITreasury.ProductSetup memory productSetup,
318
+ ITreasury.TreasuryInfo memory treasuryInfo,
319
+ NftId policyNftId,
147
320
  IPolicy.PolicyInfo memory policyInfo,
148
321
  bytes memory bundleFilter,
149
322
  uint256 collateralAmount
150
323
  )
151
324
  internal
152
325
  {
153
- address poolAddress = _registry.getObjectInfo(productSetup.poolNftId).objectAddress;
326
+ address poolAddress = getRegistry().getObjectInfo(treasuryInfo.poolNftId).objectAddress;
154
327
  IPoolComponent pool = IPoolComponent(poolAddress);
155
328
  pool.underwrite(
156
- policyInfo.nftId,
157
- policyInfo.data,
329
+ policyNftId,
330
+ policyInfo.applicationData,
158
331
  bundleFilter,
159
332
  collateralAmount);
160
333
  }
161
334
 
162
335
 
336
+ function revoke(
337
+ NftId policyNftId
338
+ )
339
+ external
340
+ override
341
+ {
342
+ require(false, "ERROR:PRS-234:NOT_YET_IMPLEMENTED");
343
+ }
344
+
345
+
163
346
  function underwrite(
164
347
  NftId policyNftId,
165
348
  bool requirePremiumPayment,
@@ -176,72 +359,82 @@ contract ProductService is ComponentServiceBase, IProductService {
176
359
 
177
360
  // check match between policy and calling product
178
361
  NftId productNftId = productInfo.nftId;
179
- IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
180
- require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
181
- require(policyInfo.state == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
182
-
183
- (
184
- ITreasury.ProductSetup memory productSetup,
185
- IBundle.BundleInfo memory bundleInfo,
186
- uint256 collateralAmount,
187
- bool poolIsVerifying,
188
- bytes memory bundleFilter
189
- ) = _getAndVerifyUnderwritingSetup(
190
- instance,
191
- policyInfo
192
- );
193
-
194
- // lock bundle collateral
195
- bundleInfo = _lockCollateralInBundle(
196
- instance,
197
- bundleInfo,
198
- policyNftId,
199
- collateralAmount);
200
-
201
- // collect premium
202
- if(requirePremiumPayment) {
203
- uint256 netPremiumAmount = _processPremiumByTreasury(
204
- instance,
205
- productSetup,
206
- policyNftId,
207
- policyInfo.premiumAmount);
208
-
209
- policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
210
- bundleInfo.balanceAmount += netPremiumAmount;
211
- }
212
-
213
- // set policy state to underwritten
214
- // TODO add require for state change
215
- policyInfo.state = UNDERWRITTEN();
216
- policyInfo.updatedIn = blockNumber();
217
-
218
- // optional activation of policy
219
- if(activateAt > zeroTimestamp()) {
220
- policyInfo.activatedAt = activateAt;
221
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
222
-
223
- // TODO add require for state change
224
- policyInfo.state = ACTIVE();
225
- }
226
-
227
- instance.setPolicyInfo(policyInfo);
228
- instance.setBundleInfo(bundleInfo);
229
-
230
- // integrate pool component
231
- if(poolIsVerifying) {
232
- _underwriteByPool(
233
- productSetup,
234
- policyInfo,
235
- bundleFilter,
236
- collateralAmount
237
- );
238
- }
362
+ // FIXME: this
363
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
364
+ // require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
365
+ // require(instance.getState(policyNftId.toKey32(POLICY())) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
366
+
367
+ // ITreasury.TreasuryInfo memory treasuryInfo;
368
+ // NftId bundleNftId;
369
+ // IBundle.BundleInfo memory bundleInfo;
370
+ // uint256 collateralAmount;
371
+
372
+ // (
373
+ // treasuryInfo,
374
+ // bundleNftId,
375
+ // bundleInfo,
376
+ // collateralAmount
377
+ // ) = _getAndVerifyUnderwritingSetup(
378
+ // instance,
379
+ // policyInfo
380
+ // );
381
+
382
+ // // lock bundle collateral
383
+ // bundleInfo = _lockCollateralInBundle(
384
+ // instance,
385
+ // bundleNftId,
386
+ // bundleInfo,
387
+ // policyNftId,
388
+ // collateralAmount);
389
+
390
+ // // set policy state to underwritten
391
+ // instance.updatePolicyState(policyNftId, UNDERWRITTEN());
392
+
393
+ // // optional activation of policy
394
+ // if(activateAt > zeroTimestamp()) {
395
+ // policyInfo.activatedAt = activateAt;
396
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
397
+
398
+ // instance.updatePolicyState(policyNftId, ACTIVE());
399
+ // }
400
+
401
+ // // optional collection of premium
402
+ // if(requirePremiumPayment) {
403
+ // uint256 netPremiumAmount = _processPremiumByTreasury(
404
+ // instance,
405
+ // productInfo.nftId,
406
+ // treasuryInfo,
407
+ // policyNftId,
408
+ // policyInfo.premiumAmount);
409
+
410
+ // policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
411
+ // bundleInfo.balanceAmount += netPremiumAmount;
412
+ // }
413
+
414
+ // instance.setPolicyInfo(policyNftId, policyInfo);
415
+ // instance.setBundleInfo(bundleNftId, bundleInfo);
416
+
417
+ // // involve pool if necessary
418
+ // {
419
+ // NftId poolNftId = treasuryInfo.poolNftId;
420
+ // ISetup.PoolSetupInfo memory poolInfo = instance.getPoolInfo(poolNftId);
421
+
422
+ // if(poolInfo.isVerifying) {
423
+ // _underwriteByPool(
424
+ // treasuryInfo,
425
+ // policyNftId,
426
+ // policyInfo,
427
+ // bundleInfo.filter,
428
+ // collateralAmount
429
+ // );
430
+ // }
431
+ // }
239
432
 
240
433
  // TODO add logging
241
434
  }
242
435
 
243
436
  function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
244
- UFixed sumInsuredUFixed = UFixedMathLib.toUFixed(sumInsuredAmount);
437
+ UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
245
438
  UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
246
439
  return collateralUFixed.toInt();
247
440
  }
@@ -251,51 +444,49 @@ contract ProductService is ComponentServiceBase, IProductService {
251
444
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
252
445
 
253
446
  // perform actual token transfers
254
- IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
255
- ITreasury.ProductSetup memory product = instance.getProductSetup(productInfo.nftId);
447
+ // FIXME: this
448
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
449
+ // ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productInfo.nftId);
256
450
 
257
- uint256 premiumAmount = policyInfo.premiumAmount;
258
- _processPremiumByTreasury(instance, product, policyNftId, premiumAmount);
451
+ // uint256 premiumAmount = policyInfo.premiumAmount;
452
+ // _processPremiumByTreasury(instance, productInfo.nftId, treasuryInfo, policyNftId, premiumAmount);
259
453
 
260
- // policy level book keeping for premium paid
261
- policyInfo.premiumPaidAmount += premiumAmount;
262
- policyInfo.updatedIn = blockNumber();
454
+ // // policy level book keeping for premium paid
455
+ // policyInfo.premiumPaidAmount += premiumAmount;
263
456
 
264
- // optional activation of policy
265
- if(activateAt > zeroTimestamp()) {
266
- require(
267
- policyInfo.activatedAt.eqz(),
268
- "ERROR:PRS-030:ALREADY_ACTIVATED");
457
+ // // optional activation of policy
458
+ // if(activateAt > zeroTimestamp()) {
459
+ // require(
460
+ // policyInfo.activatedAt.eqz(),
461
+ // "ERROR:PRS-030:ALREADY_ACTIVATED");
269
462
 
270
- policyInfo.activatedAt = activateAt;
271
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
463
+ // policyInfo.activatedAt = activateAt;
464
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
272
465
 
273
- // TODO add require for state change
274
- policyInfo.state = ACTIVE();
275
- }
466
+ // instance.updatePolicyState(policyNftId, ACTIVE());
467
+ // }
276
468
 
277
- instance.setPolicyInfo(policyInfo);
469
+ // instance.setPolicyInfo(policyNftId, policyInfo);
278
470
 
279
471
  // TODO add logging
280
472
  }
281
473
 
474
+ // FIXME: this
282
475
  function activate(NftId policyNftId, Timestamp activateAt) external override {
283
476
  // check caller is registered product
284
477
  (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
285
478
 
286
- IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
479
+ // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
287
480
 
288
- require(
289
- policyInfo.activatedAt.eqz(),
290
- "ERROR:PRS-020:ALREADY_ACTIVATED");
481
+ // require(
482
+ // policyInfo.activatedAt.eqz(),
483
+ // "ERROR:PRS-020:ALREADY_ACTIVATED");
291
484
 
292
- policyInfo.activatedAt = activateAt;
293
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
485
+ // policyInfo.activatedAt = activateAt;
486
+ // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
294
487
 
295
- // TODO add require for state change
296
- policyInfo.state = ACTIVE();
297
-
298
- instance.setPolicyInfo(policyInfo);
488
+ // instance.setPolicyInfo(policyNftId, policyInfo);
489
+ // instance.updatePolicyState(policyNftId, ACTIVE());
299
490
 
300
491
  // TODO add logging
301
492
  }
@@ -315,12 +506,15 @@ contract ProductService is ComponentServiceBase, IProductService {
315
506
  view
316
507
  returns (NftId poolNftid)
317
508
  {
318
- return instance.getProductSetup(productNftId).poolNftId;
509
+ // FIXME: this
510
+ // return instance.getTreasuryInfo(productNftId).poolNftId;
319
511
  }
320
512
 
513
+
321
514
  function _processPremiumByTreasury(
322
515
  IInstance instance,
323
- ITreasury.ProductSetup memory product,
516
+ NftId productNftId,
517
+ ITreasury.TreasuryInfo memory treasuryInfo,
324
518
  NftId policyNftId,
325
519
  uint256 premiumAmount
326
520
  )
@@ -329,28 +523,30 @@ contract ProductService is ComponentServiceBase, IProductService {
329
523
  {
330
524
  // process token transfer(s)
331
525
  if(premiumAmount > 0) {
332
- TokenHandler tokenHandler = product.tokenHandler;
333
- address policyOwner = _registry.getOwner(policyNftId);
334
- address poolWallet = instance.getPoolSetup(product.poolNftId).wallet;
335
- netPremiumAmount = premiumAmount;
336
- Fee memory policyFee = product.policyFee;
337
-
338
- if (feeIsZero(policyFee)) {
339
- tokenHandler.transfer(
340
- policyOwner,
341
- poolWallet,
342
- premiumAmount
343
- );
344
- } else {
345
- (uint256 feeAmount, uint256 netAmount) = instance.calculateFeeAmount(
346
- premiumAmount,
347
- policyFee
348
- );
349
-
350
- tokenHandler.transfer(policyOwner, product.wallet, feeAmount);
351
- tokenHandler.transfer(policyOwner, poolWallet, netAmount);
352
- netPremiumAmount = netAmount;
353
- }
526
+ // FIXME: this
527
+ // TokenHandler tokenHandler = instance.getTokenHandler(productNftId);
528
+ // address policyOwner = getRegistry().ownerOf(policyNftId);
529
+ // address poolWallet = instance.getComponentWallet(treasuryInfo.poolNftId);
530
+ // netPremiumAmount = premiumAmount;
531
+ // Fee memory productFee = treasuryInfo.productFee;
532
+
533
+ // if (FeeLib.feeIsZero(productFee)) {
534
+ // tokenHandler.transfer(
535
+ // policyOwner,
536
+ // poolWallet,
537
+ // premiumAmount
538
+ // );
539
+ // } else {
540
+ // (uint256 feeAmount, uint256 netAmount) = instance.calculateFeeAmount(
541
+ // premiumAmount,
542
+ // productFee
543
+ // );
544
+
545
+ // address productWallet = instance.getComponentWallet(productNftId);
546
+ // tokenHandler.transfer(policyOwner, productWallet, feeAmount);
547
+ // tokenHandler.transfer(policyOwner, poolWallet, netAmount);
548
+ // netPremiumAmount = netAmount;
549
+ // }
354
550
  }
355
551
 
356
552
  // TODO add logging