@etherisc/gif-next 0.0.2-78bf628-134 → 0.0.2-7acbd99-227

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 (268) hide show
  1. package/README.md +71 -25
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +80 -41
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +445 -0
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +43 -40
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +343 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +199 -81
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +141 -47
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +299 -84
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +250 -53
  18. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  36. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  37. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +742 -425
  38. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
  39. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  40. package/artifacts/contracts/instance/Instance.sol/Instance.json +1014 -604
  41. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  42. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +139 -46
  43. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +33 -1
  45. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +1 -1
  48. package/artifacts/contracts/instance/base/IService.sol/IService.json +99 -55
  49. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  50. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +160 -48
  51. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  52. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +14 -14
  53. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  54. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +4 -4
  55. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +1 -1
  56. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +1 -1
  57. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.json +135 -55
  58. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
  62. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +55 -54
  63. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
  64. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +56 -55
  66. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +12 -7
  68. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +12 -7
  71. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.dbg.json +4 -0
  72. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.json +10 -0
  73. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.dbg.json +4 -0
  74. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensation.json → distribution/IDistribution.sol/IDistribution.json} +2 -2
  75. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.dbg.json +4 -0
  76. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensationModule.json → distribution/IDistribution.sol/IDistributionModule.json} +2 -2
  77. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  78. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  79. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +53 -40
  80. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  81. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +53 -40
  82. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  83. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  84. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +29 -14
  85. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  86. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +28 -13
  87. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +1 -1
  88. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +1 -1
  89. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +104 -1
  90. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +1 -1
  91. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +126 -5
  92. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
  93. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
  94. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +326 -221
  95. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  96. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +2 -2
  97. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
  98. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +326 -221
  99. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  100. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +251 -84
  101. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +526 -0
  103. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +99 -74
  105. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +369 -0
  107. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  108. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +158 -50
  109. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  110. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +246 -49
  111. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  112. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +230 -52
  113. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  114. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +361 -70
  115. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  116. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +141 -12
  117. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  118. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +5 -0
  119. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  120. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +293 -40
  121. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  122. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +4 -0
  123. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +668 -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 +471 -121
  128. package/artifacts/contracts/registry/Registry.sol/RegistryCreationCode.dbg.json +4 -0
  129. package/artifacts/contracts/registry/Registry.sol/RegistryCreationCode.json +150 -0
  130. package/artifacts/contracts/registry/RegistryInstaller.sol/RegistryInstaller.dbg.json +4 -0
  131. package/artifacts/contracts/registry/RegistryInstaller.sol/RegistryInstaller.json +344 -0
  132. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +4 -0
  133. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +861 -0
  134. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  135. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  136. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
  137. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  138. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +43 -40
  139. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  140. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +55 -14
  141. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +4 -0
  142. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +310 -0
  143. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  144. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +76 -37
  145. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +4 -0
  146. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +129 -0
  147. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  148. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +78 -14
  149. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.dbg.json +4 -0
  150. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.json +445 -0
  151. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  152. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  153. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
  154. package/artifacts/contracts/test/TestPool.sol/TestPool.json +299 -84
  155. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +297 -58
  157. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +93 -39
  159. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  160. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  161. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  162. package/artifacts/contracts/test/TestService.sol/TestService.json +161 -68
  163. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  164. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  165. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  166. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  167. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +89 -25
  168. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  169. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  170. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Fee.sol/FeeLib.json +50 -11
  174. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  175. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  176. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  177. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  178. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  179. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  180. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  182. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.dbg.json +4 -0
  183. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.json +99 -0
  184. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  185. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  186. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  187. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  188. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/Version.sol/VersionLib.json +40 -2
  193. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  194. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  195. package/contracts/components/BaseComponent.sol +12 -21
  196. package/contracts/components/Distribution.sol +155 -0
  197. package/contracts/components/IBaseComponent.sol +2 -2
  198. package/contracts/components/IDistributionComponent.sol +47 -0
  199. package/contracts/components/IPoolComponent.sol +14 -6
  200. package/contracts/components/IProductComponent.sol +26 -6
  201. package/contracts/components/Pool.sol +99 -27
  202. package/contracts/components/Product.sol +204 -22
  203. package/contracts/instance/IInstance.sol +11 -7
  204. package/contracts/instance/Instance.sol +25 -7
  205. package/contracts/instance/base/ComponentServiceBase.sol +13 -6
  206. package/contracts/instance/base/IInstanceBase.sol +6 -2
  207. package/contracts/instance/base/InstanceBase.sol +13 -8
  208. package/contracts/instance/base/Lifecycle.sol +10 -2
  209. package/contracts/instance/base/ModuleBase.sol +22 -17
  210. package/contracts/instance/base/ServiceBase.sol +19 -13
  211. package/contracts/instance/module/access/Access.sol +3 -3
  212. package/contracts/instance/module/bundle/BundleModule.sol +10 -12
  213. package/contracts/instance/module/bundle/IBundle.sol +6 -11
  214. package/contracts/instance/module/component/ComponentModule.sol +20 -24
  215. package/contracts/instance/module/component/IComponent.sol +5 -4
  216. package/contracts/instance/module/distribution/DistributionModule.sol +17 -0
  217. package/contracts/instance/module/distribution/IDistribution.sol +10 -0
  218. package/contracts/instance/module/policy/IPolicy.sol +10 -8
  219. package/contracts/instance/module/policy/PolicyModule.sol +33 -19
  220. package/contracts/instance/module/pool/IPoolModule.sol +4 -4
  221. package/contracts/instance/module/pool/PoolModule.sol +23 -15
  222. package/contracts/instance/module/risk/IRisk.sol +18 -2
  223. package/contracts/instance/module/risk/RiskModule.sol +56 -2
  224. package/contracts/instance/module/treasury/ITreasury.sol +32 -51
  225. package/contracts/instance/module/treasury/TokenHandler.sol +2 -2
  226. package/contracts/instance/module/treasury/TreasuryModule.sol +68 -89
  227. package/contracts/instance/service/ComponentOwnerService.sol +189 -79
  228. package/contracts/instance/service/DistributionService.sol +54 -0
  229. package/contracts/instance/service/IComponentOwnerService.sol +0 -2
  230. package/contracts/instance/service/IDistributionService.sol +12 -0
  231. package/contracts/instance/service/IPoolService.sol +7 -0
  232. package/contracts/instance/service/IProductService.sol +56 -7
  233. package/contracts/instance/service/PoolService.sol +49 -23
  234. package/contracts/instance/service/ProductService.sol +246 -91
  235. package/contracts/registry/ChainNft.sol +43 -15
  236. package/contracts/registry/IChainNft.sol +3 -2
  237. package/contracts/registry/IRegistry.sol +44 -28
  238. package/contracts/registry/IRegistryService.sol +29 -0
  239. package/contracts/registry/ITransferInterceptor.sol +6 -0
  240. package/contracts/registry/Registry.sol +388 -271
  241. package/contracts/registry/RegistryInstaller.sol +100 -0
  242. package/contracts/registry/RegistryService.sol +383 -0
  243. package/contracts/shared/ERC165.sol +1 -1
  244. package/contracts/shared/IRegisterable.sol +7 -9
  245. package/contracts/shared/IVersionable.sol +55 -11
  246. package/contracts/shared/ProxyManager.sol +115 -0
  247. package/contracts/shared/Registerable.sol +74 -43
  248. package/contracts/shared/UpgradableProxyWithAdmin.sol +16 -0
  249. package/contracts/shared/Versionable.sol +112 -54
  250. package/contracts/test/TestDistribution.sol +22 -0
  251. package/contracts/test/TestPool.sol +7 -2
  252. package/contracts/test/TestProduct.sol +37 -7
  253. package/contracts/test/TestRegisterable.sol +5 -6
  254. package/contracts/test/TestService.sol +5 -11
  255. package/contracts/types/Fee.sol +8 -3
  256. package/contracts/types/ObjectType.sol +17 -5
  257. package/contracts/types/ReferralId.sol +48 -0
  258. package/contracts/types/RiskId.sol +43 -0
  259. package/contracts/types/RoleId.sol +2 -2
  260. package/contracts/types/Version.sol +9 -0
  261. package/package.json +1 -1
  262. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +0 -4
  263. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +0 -10
  264. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +0 -4
  265. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +0 -4
  266. package/contracts/experiment/statemachine/README.md +0 -112
  267. package/contracts/instance/module/compensation/CompensationModule.sol +0 -8
  268. package/contracts/instance/module/compensation/ICompensation.sol +0 -10
@@ -2,10 +2,13 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IProductComponent} from "../../components/IProductComponent.sol";
5
6
  import {IPoolComponent} from "../../components/IPoolComponent.sol";
7
+ import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
6
8
  import {IInstance} from "../../instance/IInstance.sol";
7
9
  import {IPolicy, IPolicyModule} from "../module/policy/IPolicy.sol";
8
10
  import {IPool} from "../module/pool/IPoolModule.sol";
11
+ import {IRisk} from "../module/risk/IRisk.sol";
9
12
  import {IBundle} from "../module/bundle/IBundle.sol";
10
13
  import {IProductService} from "./IProductService.sol";
11
14
  import {ITreasury, ITreasuryModule, TokenHandler} from "../../instance/module/treasury/ITreasury.sol";
@@ -15,13 +18,18 @@ import {Versionable} from "../../shared/Versionable.sol";
15
18
 
16
19
  import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
17
20
  import {UFixed, UFixedMathLib} from "../../types/UFixed.sol";
21
+ import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
18
22
  import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
19
23
  import {APPLIED, UNDERWRITTEN, ACTIVE} from "../../types/StateId.sol";
20
- import {NftId, NftIdLib} from "../../types/NftId.sol";
21
- import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
24
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
22
25
  import {Fee, FeeLib} from "../../types/Fee.sol";
26
+ import {ReferralId} from "../../types/ReferralId.sol";
27
+ import {RiskId} from "../../types/RiskId.sol";
28
+ import {StateId} from "../../types/StateId.sol";
23
29
  import {Version, VersionLib} from "../../types/Version.sol";
24
30
 
31
+ import {IService} from "../base/IService.sol";
32
+ import {ServiceBase} from "../base/ServiceBase.sol";
25
33
  import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
26
34
  import {IProductService} from "./IProductService.sol";
27
35
 
@@ -35,57 +43,186 @@ contract ProductService is ComponentServiceBase, IProductService {
35
43
 
36
44
  constructor(
37
45
  address registry,
38
- NftId registryNftId
39
- ) ComponentServiceBase(registry, registryNftId) // solhint-disable-next-line no-empty-blocks
46
+ NftId registryNftId,
47
+ address initialOwner
48
+ ) ComponentServiceBase(registry, registryNftId, initialOwner)
40
49
  {
41
50
  _registerInterface(type(IProductService).interfaceId);
42
51
  }
43
52
 
44
- function getVersion()
45
- public
46
- pure
47
- virtual override (IVersionable, Versionable)
48
- returns(Version)
49
- {
50
- return VersionLib.toVersion(3,0,0);
51
- }
52
53
 
53
- function getName() external pure override returns(string memory name) {
54
+ function getName() public pure override(IService, ServiceBase) returns(string memory name) {
54
55
  return NAME;
55
56
  }
56
57
 
57
58
  function setFees(
58
- Fee memory policyFee,
59
+ Fee memory productFee,
59
60
  Fee memory processingFee
60
61
  )
61
62
  external
62
63
  override
63
64
  {
64
65
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
65
- instance.setProductFees(productInfo.nftId, policyFee, processingFee);
66
+ NftId productNftId = productInfo.nftId;
67
+ ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productNftId);
68
+ treasuryInfo.productFee = productFee;
69
+ treasuryInfo.processingFee = processingFee;
70
+ instance.setTreasuryInfo(productNftId, treasuryInfo);
71
+ }
72
+
73
+ function createRisk(
74
+ RiskId riskId,
75
+ bytes memory data
76
+ ) external override {
77
+ (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
78
+ NftId productNftId = productInfo.nftId;
79
+ instance.createRisk(
80
+ riskId,
81
+ productNftId,
82
+ data
83
+ );
84
+ }
85
+
86
+ function setRiskInfo(
87
+ RiskId riskId,
88
+ IRisk.RiskInfo memory info
89
+ ) external {
90
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
91
+ instance.setRiskInfo(
92
+ riskId,
93
+ info
94
+ );
95
+ }
96
+
97
+ function updateRiskState(
98
+ RiskId riskId,
99
+ StateId state
100
+ ) external {
101
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
102
+ instance.updateRiskState(
103
+ riskId,
104
+ state
105
+ );
106
+ }
107
+
108
+ function _getAndVerifyInstanceAndProduct() internal view returns (IProductComponent product) {
109
+ IRegistry.ObjectInfo memory productInfo;
110
+ (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
111
+ product = IProductComponent(productInfo.objectAddress);
112
+ }
113
+
114
+ function calculatePremium(
115
+ RiskId riskId,
116
+ uint256 sumInsuredAmount,
117
+ uint256 lifetime,
118
+ bytes memory applicationData,
119
+ NftId bundleNftId,
120
+ ReferralId referralId
121
+ )
122
+ public
123
+ view
124
+ override
125
+ returns (
126
+ uint256 premiumAmount,
127
+ uint256 productFeeAmount,
128
+ uint256 poolFeeAmount,
129
+ uint256 bundleFeeAmount,
130
+ uint256 distributionFeeAmount
131
+ )
132
+ {
133
+ IProductComponent product = _getAndVerifyInstanceAndProduct();
134
+ uint256 netPremiumAmount = product.calculateNetPremium(
135
+ sumInsuredAmount,
136
+ riskId,
137
+ lifetime,
138
+ applicationData
139
+ );
140
+
141
+ (
142
+ productFeeAmount,
143
+ poolFeeAmount,
144
+ bundleFeeAmount,
145
+ distributionFeeAmount
146
+ ) = _calculateFeeAmounts(
147
+ netPremiumAmount,
148
+ product,
149
+ bundleNftId,
150
+ referralId
151
+ );
152
+
153
+ premiumAmount = netPremiumAmount + productFeeAmount;
154
+ premiumAmount += poolFeeAmount + bundleFeeAmount;
155
+ premiumAmount += distributionFeeAmount;
156
+ }
157
+
158
+ function _calculateFeeAmounts(
159
+ uint256 netPremiumAmount,
160
+ IProductComponent product,
161
+ NftId bundleNftId,
162
+ ReferralId referralId
163
+ )
164
+ internal
165
+ view
166
+ returns (
167
+ uint256 productFeeAmount,
168
+ uint256 poolFeeAmount,
169
+ uint256 bundleFeeAmount,
170
+ uint256 distributionFeeAmount
171
+ )
172
+ {
173
+ IInstance instance = product.getInstance();
174
+ ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(product.getNftId());
175
+ IBundle.BundleInfo memory bundleInfo = instance.getBundleInfo(bundleNftId);
176
+ require(bundleInfo.poolNftId == treasuryInfo.poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
177
+
178
+ (productFeeAmount,) = FeeLib.calculateFee(treasuryInfo.productFee, netPremiumAmount);
179
+ (poolFeeAmount,) = FeeLib.calculateFee(treasuryInfo.poolFee, netPremiumAmount);
180
+ (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
181
+
182
+ IRegistry.ObjectInfo memory distributionInfo = getRegistry().getObjectInfo(treasuryInfo.distributionNftId);
183
+ IDistributionComponent distribution = IDistributionComponent(distributionInfo.objectAddress);
184
+ distributionFeeAmount = distribution.calculateFeeAmount(referralId, netPremiumAmount);
66
185
  }
67
186
 
187
+
68
188
  function createApplication(
69
189
  address applicationOwner,
190
+ RiskId riskId,
70
191
  uint256 sumInsuredAmount,
71
- uint256 premiumAmount,
72
192
  uint256 lifetime,
73
- NftId bundleNftId
193
+ bytes memory applicationData,
194
+ NftId bundleNftId,
195
+ ReferralId referralId
74
196
  ) external override returns (NftId policyNftId) {
75
197
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
76
- NftId productNftId = productInfo.nftId;
77
198
  // TODO add validations (see create bundle in pool service)
78
199
 
79
- policyNftId = this.getRegistry().registerObjectForInstance(
80
- productNftId,
81
- POLICY(),
82
- applicationOwner,
83
- ""
200
+ policyNftId = getRegistryService().registerPolicy(
201
+ IRegistry.ObjectInfo(
202
+ zeroNftId(),
203
+ productInfo.nftId,
204
+ POLICY(),
205
+ false, // intercepting property for policies is defined on product
206
+ address(0),
207
+ applicationOwner,
208
+ ""
209
+ )
84
210
  );
85
211
 
86
- instance.createApplication(
87
- productNftId,
212
+ (uint256 premiumAmount,,,,) = calculatePremium(
213
+ riskId,
214
+ sumInsuredAmount,
215
+ lifetime,
216
+ applicationData,
217
+ bundleNftId,
218
+ referralId
219
+ );
220
+
221
+ instance.createPolicyInfo(
88
222
  policyNftId,
223
+ productInfo.nftId,
224
+ referralId,
225
+ riskId,
89
226
  sumInsuredAmount,
90
227
  premiumAmount,
91
228
  lifetime,
@@ -102,30 +239,29 @@ contract ProductService is ComponentServiceBase, IProductService {
102
239
  internal
103
240
  view
104
241
  returns (
105
- ITreasury.ProductSetup memory productSetup,
242
+ ITreasury.TreasuryInfo memory treasuryInfo,
243
+ NftId bundleNftId,
106
244
  IBundle.BundleInfo memory bundleInfo,
107
- uint256 collateralAmount,
108
- bool poolIsVerifying,
109
- bytes memory bundleFilter
245
+ uint256 collateralAmount
110
246
  )
111
247
  {
112
248
  // check match between policy and bundle (via pool)
113
- productSetup = instance.getProductSetup(policyInfo.productNftId);
114
- bundleInfo = instance.getBundleInfo(policyInfo.bundleNftId);
115
- require(bundleInfo.poolNftId == productSetup.poolNftId, "POLICY_BUNDLE_MISMATCH");
249
+ treasuryInfo = instance.getTreasuryInfo(policyInfo.productNftId);
250
+ bundleNftId = policyInfo.bundleNftId;
251
+ bundleInfo = instance.getBundleInfo(bundleNftId);
252
+ require(bundleInfo.poolNftId == treasuryInfo.poolNftId, "POLICY_BUNDLE_MISMATCH");
116
253
 
117
254
  // calculate required collateral
118
- NftId poolNftId = productSetup.poolNftId;
255
+ NftId poolNftId = treasuryInfo.poolNftId;
119
256
  IPool.PoolInfo memory poolInfo = instance.getPoolInfo(poolNftId);
120
257
 
121
258
  // obtain remaining return values
122
- poolIsVerifying = poolInfo.isVerifying;
123
259
  collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
124
- bundleFilter = bundleInfo.filter;
125
260
  }
126
261
 
127
262
  function _lockCollateralInBundle(
128
263
  IInstance instance,
264
+ NftId bundleNftId,
129
265
  IBundle.BundleInfo memory bundleInfo,
130
266
  NftId policyNftId,
131
267
  uint256 collateralAmount
@@ -134,28 +270,39 @@ contract ProductService is ComponentServiceBase, IProductService {
134
270
  returns (IBundle.BundleInfo memory)
135
271
  {
136
272
  bundleInfo.lockedAmount += collateralAmount;
137
- instance.collateralizePolicy(bundleInfo.nftId, policyNftId, collateralAmount);
273
+ instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
138
274
  return bundleInfo;
139
275
  }
140
276
 
141
277
  function _underwriteByPool(
142
- ITreasury.ProductSetup memory productSetup,
278
+ ITreasury.TreasuryInfo memory treasuryInfo,
279
+ NftId policyNftId,
143
280
  IPolicy.PolicyInfo memory policyInfo,
144
281
  bytes memory bundleFilter,
145
282
  uint256 collateralAmount
146
283
  )
147
284
  internal
148
285
  {
149
- address poolAddress = _registry.getObjectInfo(productSetup.poolNftId).objectAddress;
286
+ address poolAddress = getRegistry().getObjectInfo(treasuryInfo.poolNftId).objectAddress;
150
287
  IPoolComponent pool = IPoolComponent(poolAddress);
151
288
  pool.underwrite(
152
- policyInfo.nftId,
289
+ policyNftId,
153
290
  policyInfo.applicationData,
154
291
  bundleFilter,
155
292
  collateralAmount);
156
293
  }
157
294
 
158
295
 
296
+ function revoke(
297
+ NftId policyNftId
298
+ )
299
+ external
300
+ override
301
+ {
302
+ require(false, "ERROR:PRS-234:NOT_YET_IMPLEMENTED");
303
+ }
304
+
305
+
159
306
  function underwrite(
160
307
  NftId policyNftId,
161
308
  bool requirePremiumPayment,
@@ -174,14 +321,18 @@ contract ProductService is ComponentServiceBase, IProductService {
174
321
  NftId productNftId = productInfo.nftId;
175
322
  IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
176
323
  require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
177
- require(policyInfo.state == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
324
+ require(instance.getState(policyNftId.toKey32(POLICY())) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
325
+
326
+ ITreasury.TreasuryInfo memory treasuryInfo;
327
+ NftId bundleNftId;
328
+ IBundle.BundleInfo memory bundleInfo;
329
+ uint256 collateralAmount;
178
330
 
179
331
  (
180
- ITreasury.ProductSetup memory productSetup,
181
- IBundle.BundleInfo memory bundleInfo,
182
- uint256 collateralAmount,
183
- bool poolIsVerifying,
184
- bytes memory bundleFilter
332
+ treasuryInfo,
333
+ bundleNftId,
334
+ bundleInfo,
335
+ collateralAmount
185
336
  ) = _getAndVerifyUnderwritingSetup(
186
337
  instance,
187
338
  policyInfo
@@ -190,15 +341,28 @@ contract ProductService is ComponentServiceBase, IProductService {
190
341
  // lock bundle collateral
191
342
  bundleInfo = _lockCollateralInBundle(
192
343
  instance,
344
+ bundleNftId,
193
345
  bundleInfo,
194
346
  policyNftId,
195
347
  collateralAmount);
196
348
 
197
- // collect premium
349
+ // set policy state to underwritten
350
+ instance.updatePolicyState(policyNftId, UNDERWRITTEN());
351
+
352
+ // optional activation of policy
353
+ if(activateAt > zeroTimestamp()) {
354
+ policyInfo.activatedAt = activateAt;
355
+ policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
356
+
357
+ instance.updatePolicyState(policyNftId, ACTIVE());
358
+ }
359
+
360
+ // optional collection of premium
198
361
  if(requirePremiumPayment) {
199
362
  uint256 netPremiumAmount = _processPremiumByTreasury(
200
363
  instance,
201
- productSetup,
364
+ productInfo.nftId,
365
+ treasuryInfo,
202
366
  policyNftId,
203
367
  policyInfo.premiumAmount);
204
368
 
@@ -206,31 +370,23 @@ contract ProductService is ComponentServiceBase, IProductService {
206
370
  bundleInfo.balanceAmount += netPremiumAmount;
207
371
  }
208
372
 
209
- // set policy state to underwritten
210
- // TODO add require for state change
211
- policyInfo.state = UNDERWRITTEN();
212
- policyInfo.updatedIn = blockNumber();
213
-
214
- // optional activation of policy
215
- if(activateAt > zeroTimestamp()) {
216
- policyInfo.activatedAt = activateAt;
217
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
218
-
219
- // TODO add require for state change
220
- policyInfo.state = ACTIVE();
221
- }
222
-
223
- instance.setPolicyInfo(policyInfo);
224
- instance.setBundleInfo(bundleInfo);
225
-
226
- // integrate pool component
227
- if(poolIsVerifying) {
228
- _underwriteByPool(
229
- productSetup,
230
- policyInfo,
231
- bundleFilter,
232
- collateralAmount
233
- );
373
+ instance.setPolicyInfo(policyNftId, policyInfo);
374
+ instance.setBundleInfo(bundleNftId, bundleInfo);
375
+
376
+ // involve pool if necessary
377
+ {
378
+ NftId poolNftId = treasuryInfo.poolNftId;
379
+ IPool.PoolInfo memory poolInfo = instance.getPoolInfo(poolNftId);
380
+
381
+ if(poolInfo.isVerifying) {
382
+ _underwriteByPool(
383
+ treasuryInfo,
384
+ policyNftId,
385
+ policyInfo,
386
+ bundleInfo.filter,
387
+ collateralAmount
388
+ );
389
+ }
234
390
  }
235
391
 
236
392
  // TODO add logging
@@ -248,14 +404,13 @@ contract ProductService is ComponentServiceBase, IProductService {
248
404
 
249
405
  // perform actual token transfers
250
406
  IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
251
- ITreasury.ProductSetup memory product = instance.getProductSetup(productInfo.nftId);
407
+ ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productInfo.nftId);
252
408
 
253
409
  uint256 premiumAmount = policyInfo.premiumAmount;
254
- _processPremiumByTreasury(instance, product, policyNftId, premiumAmount);
410
+ _processPremiumByTreasury(instance, productInfo.nftId, treasuryInfo, policyNftId, premiumAmount);
255
411
 
256
412
  // policy level book keeping for premium paid
257
413
  policyInfo.premiumPaidAmount += premiumAmount;
258
- policyInfo.updatedIn = blockNumber();
259
414
 
260
415
  // optional activation of policy
261
416
  if(activateAt > zeroTimestamp()) {
@@ -266,11 +421,10 @@ contract ProductService is ComponentServiceBase, IProductService {
266
421
  policyInfo.activatedAt = activateAt;
267
422
  policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
268
423
 
269
- // TODO add require for state change
270
- policyInfo.state = ACTIVE();
424
+ instance.updatePolicyState(policyNftId, ACTIVE());
271
425
  }
272
426
 
273
- instance.setPolicyInfo(policyInfo);
427
+ instance.setPolicyInfo(policyNftId, policyInfo);
274
428
 
275
429
  // TODO add logging
276
430
  }
@@ -288,10 +442,8 @@ contract ProductService is ComponentServiceBase, IProductService {
288
442
  policyInfo.activatedAt = activateAt;
289
443
  policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
290
444
 
291
- // TODO add require for state change
292
- policyInfo.state = ACTIVE();
293
-
294
- instance.setPolicyInfo(policyInfo);
445
+ instance.setPolicyInfo(policyNftId, policyInfo);
446
+ instance.updatePolicyState(policyNftId, ACTIVE());
295
447
 
296
448
  // TODO add logging
297
449
  }
@@ -311,12 +463,14 @@ contract ProductService is ComponentServiceBase, IProductService {
311
463
  view
312
464
  returns (NftId poolNftid)
313
465
  {
314
- return instance.getProductSetup(productNftId).poolNftId;
466
+ return instance.getTreasuryInfo(productNftId).poolNftId;
315
467
  }
316
468
 
469
+
317
470
  function _processPremiumByTreasury(
318
471
  IInstance instance,
319
- ITreasury.ProductSetup memory product,
472
+ NftId productNftId,
473
+ ITreasury.TreasuryInfo memory treasuryInfo,
320
474
  NftId policyNftId,
321
475
  uint256 premiumAmount
322
476
  )
@@ -325,13 +479,13 @@ contract ProductService is ComponentServiceBase, IProductService {
325
479
  {
326
480
  // process token transfer(s)
327
481
  if(premiumAmount > 0) {
328
- TokenHandler tokenHandler = instance.getTokenHandler(product.productNftId);
329
- address policyOwner = _registry.getOwner(policyNftId);
330
- address poolWallet = instance.getPoolSetup(product.poolNftId).wallet;
482
+ TokenHandler tokenHandler = instance.getTokenHandler(productNftId);
483
+ address policyOwner = getRegistry().ownerOf(policyNftId);
484
+ address poolWallet = instance.getComponentWallet(treasuryInfo.poolNftId);
331
485
  netPremiumAmount = premiumAmount;
332
- Fee memory policyFee = product.policyFee;
486
+ Fee memory productFee = treasuryInfo.productFee;
333
487
 
334
- if (FeeLib.feeIsZero(policyFee)) {
488
+ if (FeeLib.feeIsZero(productFee)) {
335
489
  tokenHandler.transfer(
336
490
  policyOwner,
337
491
  poolWallet,
@@ -340,10 +494,11 @@ contract ProductService is ComponentServiceBase, IProductService {
340
494
  } else {
341
495
  (uint256 feeAmount, uint256 netAmount) = instance.calculateFeeAmount(
342
496
  premiumAmount,
343
- policyFee
497
+ productFee
344
498
  );
345
499
 
346
- tokenHandler.transfer(policyOwner, product.wallet, feeAmount);
500
+ address productWallet = instance.getComponentWallet(productNftId);
501
+ tokenHandler.transfer(policyOwner, productWallet, feeAmount);
347
502
  tokenHandler.transfer(policyOwner, poolWallet, netAmount);
348
503
  netPremiumAmount = netAmount;
349
504
  }
@@ -1,8 +1,11 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.19;
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {ERC721, ERC721Enumerable} from "@openzeppelin5/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
+ import {IERC721} from "@openzeppelin5/contracts/token/ERC721/IERC721.sol";
3
6
 
4
- import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
7
  import {IChainNft} from "./IChainNft.sol";
8
+ import {ITransferInterceptor} from "./ITransferInterceptor.sol";
6
9
 
7
10
  contract ChainNft is ERC721Enumerable, IChainNft {
8
11
  string public constant NAME = "Dezentralized Insurance Protocol Registry";
@@ -11,6 +14,9 @@ contract ChainNft is ERC721Enumerable, IChainNft {
11
14
  uint256 public constant PROTOCOL_NFT_ID = 1101;
12
15
  uint256 public constant GLOBAL_REGISTRY_ID = 2101;
13
16
 
17
+ // remember interceptors
18
+ mapping(uint256 tokenId => address interceptor) private _interceptor;
19
+
14
20
  // remember token uri
15
21
  mapping(uint256 tokenId => string uri) private _uri;
16
22
 
@@ -37,18 +43,36 @@ contract ChainNft is ERC721Enumerable, IChainNft {
37
43
  _chainIdInt = block.chainid;
38
44
  _chainIdDigits = _countDigits(_chainIdInt);
39
45
  _chainIdMultiplier = 10 ** _chainIdDigits;
40
- _idNext = 3;
46
+ _idNext = 4;
41
47
  }
42
48
 
49
+ /**
50
+ * @dev mints a token for a specified token id
51
+ * not part of the IRegistry interface only needed for
52
+ * initial registry setup (protocol and global registry objects)
53
+ */
54
+ function mint(address to, uint256 tokenId) external onlyRegistry {
55
+ _totalMinted++;
56
+ _safeMint(to, tokenId);
57
+ }
58
+
59
+
43
60
  /**
44
61
  * @dev mints the next token to register new objects
62
+ * non-zero transferInterceptors are recorded and called during nft token transfers.
63
+ * the contract receiving such a notification may decides to revert or record the transfer
45
64
  */
46
65
  function mint(
47
66
  address to,
67
+ address interceptor,
48
68
  string memory uri
49
- ) external override onlyRegistry returns (uint256 tokenId) {
69
+ ) public onlyRegistry returns (uint256 tokenId) {
50
70
  tokenId = _getNextTokenId();
51
71
 
72
+ if (interceptor != address(0)) {
73
+ _interceptor[tokenId] = interceptor;
74
+ }
75
+
52
76
  if (bytes(uri).length > 0) {
53
77
  _uri[tokenId] = uri;
54
78
  }
@@ -57,18 +81,22 @@ contract ChainNft is ERC721Enumerable, IChainNft {
57
81
  _totalMinted++;
58
82
  }
59
83
 
84
+
60
85
  /**
61
- * @dev mints a token for a specified token id
62
- * not part of the IRegistry interface only needed for
63
- * initial registry setup (protocol and global registry objects)
64
- */
65
- function mint(address to, uint256 tokenId) external onlyRegistry {
66
- _totalMinted++;
67
- _safeMint(to, tokenId);
86
+ * @dev amend the open zeppelin transferFrom function by an interceptor call if such an interceptor is defined for the nft token id
87
+ * this allows distribution, product and pool components to be notified when distributors, policies and bundles are transferred.
88
+ */
89
+ function transferFrom(address from, address to, uint256 tokenId) public override (ERC721, IERC721) {
90
+ super.transferFrom(from, to, tokenId);
91
+
92
+ if (_interceptor[tokenId] != address(0)) {
93
+ ITransferInterceptor(_interceptor[tokenId]).nftTransferFrom(from, to, tokenId);
94
+ }
68
95
  }
69
96
 
97
+
70
98
  function burn(uint256 tokenId) external override onlyRegistry {
71
- _requireMinted(tokenId);
99
+ _requireOwned(tokenId);
72
100
  _burn(tokenId);
73
101
  delete _uri[tokenId];
74
102
  }
@@ -79,18 +107,18 @@ contract ChainNft is ERC721Enumerable, IChainNft {
79
107
  ) external override onlyRegistry {
80
108
  require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
81
109
 
82
- _requireMinted(tokenId);
110
+ _requireOwned(tokenId);
83
111
  _uri[tokenId] = uri;
84
112
  }
85
113
 
86
114
  function exists(uint256 tokenId) external view override returns (bool) {
87
- return _exists(tokenId);
115
+ return _ownerOf(tokenId) != address(0);
88
116
  }
89
117
 
90
118
  function tokenURI(
91
119
  uint256 tokenId
92
120
  ) public view override returns (string memory) {
93
- _requireMinted(tokenId);
121
+ _requireOwned(tokenId);
94
122
  return _uri[tokenId];
95
123
  }
96
124
 
@@ -1,11 +1,12 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.19;
2
+ pragma solidity ^0.8.20;
3
3
 
4
- import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
4
+ import {IERC721Enumerable} from "@openzeppelin5/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
5
5
 
6
6
  interface IChainNft is IERC721Enumerable {
7
7
  function mint(
8
8
  address to,
9
+ address interceptor,
9
10
  string memory uri
10
11
  ) external returns (uint256 tokenId);
11
12