@etherisc/gif-next 0.0.2-ce8407f-016 → 0.0.2-ce87da3-250

Sign up to get free protection for your applications and to get access to all the features.
Files changed (353) hide show
  1. package/README.md +243 -2
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  3. package/artifacts/contracts/components/Component.sol/Component.json +853 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +1346 -0
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +4 -0
  7. package/artifacts/contracts/{instance/base/ServiceBase.sol/ServiceBase.json → components/IComponent.sol/IComponent.json} +195 -150
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +900 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +4 -0
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +887 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +4 -0
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +806 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +1322 -0
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  17. package/artifacts/contracts/components/Product.sol/Product.json +1246 -0
  18. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  19. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +764 -0
  20. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  21. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  22. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +2475 -1
  24. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +509 -0
  26. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  27. package/artifacts/contracts/instance/Instance.sol/Instance.json +1051 -1183
  28. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +211 -144
  30. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +562 -54
  32. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +958 -29
  34. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  35. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +693 -0
  36. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  37. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +261 -0
  38. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +4 -0
  39. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +552 -0
  40. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +0 -77
  42. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +10 -244
  45. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  47. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +59 -16
  49. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  50. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  52. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  55. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +4 -0
  56. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +869 -0
  57. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +4 -0
  58. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +657 -0
  59. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  60. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1096 -0
  61. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  62. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +661 -0
  63. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +4 -0
  64. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +754 -0
  65. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +4 -0
  66. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +637 -0
  67. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  68. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +1254 -0
  69. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  70. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +753 -0
  71. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +4 -0
  72. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +473 -0
  73. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  74. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +633 -0
  75. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +4 -0
  76. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +409 -0
  77. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  78. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +639 -0
  79. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +583 -0
  81. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +4 -0
  82. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +347 -0
  83. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +4 -0
  84. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +384 -0
  85. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  86. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +1120 -0
  87. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +717 -0
  89. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  90. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +727 -0
  91. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  92. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +649 -0
  93. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  94. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +777 -0
  95. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  96. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +649 -0
  97. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  98. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +47 -2
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +236 -63
  101. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  102. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +323 -178
  103. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  104. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/Registry.sol/Registry.json +210 -212
  106. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  107. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  108. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  109. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +432 -268
  110. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +323 -129
  112. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  113. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +547 -0
  114. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  115. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +498 -0
  116. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  117. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  118. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +41 -3
  119. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  120. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.json +40 -29
  121. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +4 -0
  122. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.json +129 -0
  123. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  124. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +21 -34
  125. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +4 -0
  126. package/artifacts/contracts/{experiment/inheritance/IB.sol/IB.json → shared/IRegistryLinked.sol/IRegistryLinked.json} +18 -20
  127. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  128. package/artifacts/contracts/{components/IBaseComponent.sol/IBaseComponent.json → shared/IService.sol/IService.json} +67 -39
  129. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +2 -152
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +120 -27
  133. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +4 -0
  134. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +248 -0
  135. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  136. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +294 -61
  137. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  138. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +129 -51
  139. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +4 -0
  140. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +84 -0
  141. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  142. package/artifacts/contracts/{instance/base/IService.sol/IService.json → shared/Service.sol/Service.json} +155 -151
  143. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  144. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  145. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  146. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  147. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  148. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +2 -152
  149. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestFee.sol/TestFee.json +4 -4
  151. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  152. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +129 -51
  153. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  154. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +111 -5
  155. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestService.sol/TestService.json +147 -226
  157. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +91 -53
  159. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  160. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  161. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  162. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +8 -190
  163. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  164. package/artifacts/contracts/test/Usdc.sol/USDC.json +91 -53
  165. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  166. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +4 -0
  169. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +100 -0
  170. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  172. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Fee.sol/FeeLib.json +4 -4
  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 +26 -3
  180. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  183. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +4 -0
  184. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +100 -0
  185. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  186. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  187. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  189. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  191. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  193. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  194. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  195. package/artifacts/contracts/{experiment/types/TypeB.sol/TypeBLib.json → types/UFixed.sol/MathLib.json} +4 -4
  196. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +4 -0
  197. package/artifacts/contracts/types/UFixed.sol/{UFixedMathLib.json → UFixedLib.json} +3 -3
  198. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  199. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  200. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  201. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
  202. package/contracts/components/Component.sol +241 -0
  203. package/contracts/components/Distribution.sol +287 -0
  204. package/contracts/components/IComponent.sol +54 -0
  205. package/contracts/components/IDistributionComponent.sol +92 -0
  206. package/contracts/components/IPoolComponent.sol +87 -0
  207. package/contracts/components/IProductComponent.sol +39 -0
  208. package/contracts/components/Pool.sol +254 -0
  209. package/contracts/components/Product.sol +285 -0
  210. package/contracts/instance/BundleManager.sol +125 -0
  211. package/contracts/instance/Cloneable.sol +46 -0
  212. package/contracts/instance/IInstance.sol +87 -1
  213. package/contracts/instance/IInstanceService.sol +59 -0
  214. package/contracts/instance/Instance.sol +137 -238
  215. package/contracts/instance/InstanceAccessManager.sol +90 -81
  216. package/contracts/instance/InstanceReader.sol +86 -28
  217. package/contracts/instance/InstanceService.sol +453 -22
  218. package/contracts/instance/InstanceServiceManager.sol +54 -0
  219. package/contracts/instance/ObjectManager.sol +84 -0
  220. package/contracts/instance/base/ComponentService.sol +134 -0
  221. package/contracts/instance/base/IKeyValueStore.sol +5 -4
  222. package/contracts/instance/base/KeyValueStore.sol +4 -20
  223. package/contracts/instance/module/IAccess.sol +28 -19
  224. package/contracts/instance/module/IBundle.sol +1 -0
  225. package/contracts/instance/module/IDistribution.sol +1 -0
  226. package/contracts/instance/module/IPolicy.sol +4 -2
  227. package/contracts/instance/module/ISetup.sol +10 -3
  228. package/contracts/instance/module/ITreasury.sol +1 -1
  229. package/contracts/instance/service/ApplicationService.sol +268 -0
  230. package/contracts/instance/service/ApplicationServiceManager.sol +35 -0
  231. package/contracts/instance/service/BundleService.sol +298 -0
  232. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  233. package/contracts/instance/service/ClaimService.sol +151 -0
  234. package/contracts/instance/service/ClaimServiceManager.sol +35 -0
  235. package/contracts/instance/service/DistributionService.sol +366 -0
  236. package/contracts/instance/service/DistributionServiceManager.sol +51 -0
  237. package/contracts/instance/service/IApplicationService.sol +82 -0
  238. package/contracts/instance/service/IBundleService.sol +54 -0
  239. package/contracts/instance/service/IClaimService.sol +61 -0
  240. package/contracts/instance/service/IDistributionService.sol +81 -0
  241. package/contracts/instance/service/IPolicyService.sol +89 -0
  242. package/contracts/instance/service/IPoolService.sol +20 -0
  243. package/contracts/instance/service/IProductService.sol +40 -0
  244. package/contracts/instance/service/PolicyService.sol +476 -0
  245. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  246. package/contracts/instance/service/PoolService.sol +109 -0
  247. package/contracts/instance/service/PoolServiceManager.sol +51 -0
  248. package/contracts/instance/service/ProductService.sol +233 -0
  249. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  250. package/contracts/registry/ChainNft.sol +41 -26
  251. package/contracts/registry/IRegistry.sol +51 -25
  252. package/contracts/registry/IRegistryService.sol +54 -16
  253. package/contracts/registry/Registry.sol +279 -306
  254. package/contracts/registry/RegistryAccessManager.sol +216 -0
  255. package/contracts/registry/RegistryService.sol +170 -256
  256. package/contracts/registry/RegistryServiceManager.sol +30 -11
  257. package/contracts/registry/ReleaseManager.sol +322 -0
  258. package/contracts/registry/TokenRegistry.sol +116 -0
  259. package/contracts/shared/ERC165.sol +15 -9
  260. package/contracts/shared/INftOwnable.sol +11 -10
  261. package/contracts/shared/IPolicyHolder.sol +26 -0
  262. package/contracts/shared/IRegisterable.sol +4 -6
  263. package/contracts/shared/IRegistryLinked.sol +12 -0
  264. package/contracts/shared/IService.sol +18 -0
  265. package/contracts/shared/IVersionable.sol +4 -47
  266. package/contracts/shared/NftOwnable.sol +67 -83
  267. package/contracts/shared/PolicyHolder.sol +81 -0
  268. package/contracts/shared/ProxyManager.sol +101 -26
  269. package/contracts/shared/Registerable.sol +15 -30
  270. package/contracts/shared/RegistryLinked.sol +48 -0
  271. package/contracts/shared/Service.sol +58 -0
  272. package/contracts/shared/TokenHandler.sol +2 -2
  273. package/contracts/shared/UpgradableProxyWithAdmin.sol +2 -2
  274. package/contracts/shared/Versionable.sol +5 -93
  275. package/contracts/test/TestFee.sol +2 -2
  276. package/contracts/test/TestRegisterable.sol +1 -1
  277. package/contracts/test/TestRoleId.sol +6 -6
  278. package/contracts/test/TestService.sol +6 -7
  279. package/contracts/types/ClaimId.sol +52 -0
  280. package/contracts/types/DistributorType.sol +2 -2
  281. package/contracts/types/Fee.sol +3 -3
  282. package/contracts/types/NftIdSet.sol +26 -24
  283. package/contracts/types/ObjectType.sol +9 -5
  284. package/contracts/types/PayoutId.sol +54 -0
  285. package/contracts/types/RoleId.sol +19 -4
  286. package/contracts/types/StateId.sol +4 -0
  287. package/contracts/types/UFixed.sol +128 -12
  288. package/contracts/types/Version.sol +4 -1
  289. package/package.json +6 -5
  290. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +0 -4
  291. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +0 -4
  292. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +0 -105
  293. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +0 -4
  294. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +0 -105
  295. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +0 -4
  296. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +0 -128
  297. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +0 -4
  298. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +0 -42
  299. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +0 -4
  300. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +0 -76
  301. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +0 -4
  302. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +0 -89
  303. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +0 -4
  304. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +0 -128
  305. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +0 -4
  306. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +0 -37
  307. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +0 -4
  308. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +0 -4
  309. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +0 -63
  310. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +0 -4
  311. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +0 -59
  312. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +0 -4
  313. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +0 -124
  314. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +0 -4
  315. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +0 -74
  316. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +0 -4
  317. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +0 -124
  318. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +0 -4
  319. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +0 -207
  320. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +0 -4
  321. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +0 -10
  322. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +0 -4
  323. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  324. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  325. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1119
  326. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
  327. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
  328. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +0 -4
  329. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +0 -4
  330. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +0 -4
  331. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +0 -457
  332. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +0 -4
  333. package/contracts/components/IBaseComponent.sol +0 -19
  334. package/contracts/experiment/errors/Require.sol +0 -38
  335. package/contracts/experiment/errors/Revert.sol +0 -44
  336. package/contracts/experiment/inheritance/A.sol +0 -53
  337. package/contracts/experiment/inheritance/B.sol +0 -28
  338. package/contracts/experiment/inheritance/C.sol +0 -34
  339. package/contracts/experiment/inheritance/IA.sol +0 -13
  340. package/contracts/experiment/inheritance/IB.sol +0 -10
  341. package/contracts/experiment/inheritance/IC.sol +0 -12
  342. package/contracts/experiment/statemachine/Dummy.sol +0 -27
  343. package/contracts/experiment/statemachine/ISM.sol +0 -25
  344. package/contracts/experiment/statemachine/SM.sol +0 -57
  345. package/contracts/experiment/statemachine/SimpleStateMachine.sol +0 -31
  346. package/contracts/experiment/types/TypeA.sol +0 -47
  347. package/contracts/experiment/types/TypeB.sol +0 -29
  348. package/contracts/instance/AccessManagedSimple.sol +0 -114
  349. package/contracts/instance/AccessManagerSimple.sol +0 -682
  350. package/contracts/instance/IAccessManagerSimple.sol +0 -391
  351. package/contracts/instance/base/IService.sol +0 -15
  352. package/contracts/instance/base/ServiceBase.sol +0 -44
  353. package/contracts/registry/IChainNft.sol +0 -22
@@ -1,45 +1,476 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import {Clones} from "@openzeppelin5/contracts/proxy/Clones.sol";
4
+ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5
5
 
6
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
7
- import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
6
  import {Instance} from "./Instance.sol";
7
+ import {IInstance} from "./IInstance.sol";
8
+ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
9
+ import {IInstanceService} from "./IInstanceService.sol";
10
+ import {InstanceReader} from "./InstanceReader.sol";
11
+ import {BundleManager} from "./BundleManager.sol";
12
+ import {IRegistry} from "../registry/IRegistry.sol";
13
+ import {IRegistryService} from "../registry/IRegistryService.sol";
14
+ import {ChainNft} from "../registry/ChainNft.sol";
15
+ import {Service} from "../../contracts/shared/Service.sol";
16
+ import {IService} from "../shared/IService.sol";
17
+ import {NftId} from "../../contracts/types/NftId.sol";
18
+ import {RoleId} from "../types/RoleId.sol";
19
+ import {ADMIN_ROLE, DISTRIBUTION_OWNER_ROLE, POOL_OWNER_ROLE, PRODUCT_OWNER_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE, PRODUCT_SERVICE_ROLE, APPLICATION_SERVICE_ROLE, POLICY_SERVICE_ROLE, CLAIM_SERVICE_ROLE, BUNDLE_SERVICE_ROLE} from "../types/RoleId.sol";
20
+ import {ObjectType, INSTANCE, BUNDLE, APPLICATION, POLICY, CLAIM, PRODUCT, DISTRIBUTION, REGISTRY, POOL} from "../types/ObjectType.sol";
21
+ import {IDistributionComponent} from "../components/IDistributionComponent.sol";
22
+ import {IPoolComponent} from "../components/IPoolComponent.sol";
23
+ import {IProductComponent} from "../components/IProductComponent.sol";
24
+
25
+ contract InstanceService is
26
+ Service,
27
+ IInstanceService
28
+ {
9
29
 
10
- contract InstanceService {
30
+ address internal _masterInstanceAccessManager;
31
+ address internal _masterInstance;
32
+ address internal _masterInstanceReader;
33
+ address internal _masterInstanceBundleManager;
11
34
 
12
- address internal _accessManagerMaster;
13
- address internal _instanceAccessManagerMaster;
14
- address internal _instanceMaster;
35
+ // TODO update to real hash when instance is stable
36
+ bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
37
+
38
+ modifier onlyInstanceOwner(NftId instanceNftId) {
39
+ IRegistry registry = getRegistry();
40
+ ChainNft chainNft = ChainNft(registry.getChainNftAddress());
41
+
42
+ if( msg.sender != chainNft.ownerOf(instanceNftId.toInt())) {
43
+ revert ErrorInstanceServiceNotInstanceOwner(msg.sender, instanceNftId);
44
+ }
45
+ _;
46
+ }
47
+
48
+ modifier onlyRegisteredService() {
49
+ address caller = msg.sender;
50
+ if (! getRegistry().isRegisteredService(caller)) {
51
+ revert ErrorInstanceServiceRequestUnauhorized(caller);
52
+ }
53
+ _;
54
+ }
15
55
 
16
56
  function createInstanceClone()
17
57
  external
18
58
  returns (
19
- AccessManagerSimple am,
20
- InstanceAccessManager im,
21
- Instance i
59
+ InstanceAccessManager clonedAccessManager,
60
+ Instance clonedInstance,
61
+ NftId clonedInstanceNftId,
62
+ InstanceReader clonedInstanceReader,
63
+ BundleManager clonedBundleManager
22
64
  )
23
65
  {
24
- am = AccessManagerSimple(Clones.clone(_accessManagerMaster));
25
- im = InstanceAccessManager(Clones.clone(_instanceAccessManagerMaster));
26
- i = Instance(Clones.clone(_instanceMaster));
66
+ address instanceOwner = msg.sender;
67
+ IRegistry registry = getRegistry();
68
+ address registryAddress = address(registry);
69
+ NftId registryNftId = registry.getNftId(registryAddress);
70
+ address registryServiceAddress = registry.getServiceAddress(REGISTRY(), getMajorVersion());
71
+ IRegistryService registryService = IRegistryService(registryServiceAddress);
72
+
73
+ // initially set the authority of the access managar to this (being the instance service).
74
+ // This will allow the instance service to bootstrap the authorizations of the instance
75
+ // and then transfer the ownership of the access manager to the instance owner once everything is setup
76
+ clonedAccessManager = InstanceAccessManager(Clones.clone(_masterInstanceAccessManager));
77
+ clonedAccessManager.initialize(address(this));
78
+
79
+ clonedInstance = Instance(Clones.clone(_masterInstance));
80
+ clonedInstance.initialize(address(clonedAccessManager), registryAddress, registryNftId, msg.sender);
81
+
82
+ clonedInstanceReader = InstanceReader(Clones.clone(address(_masterInstanceReader)));
83
+ clonedInstanceReader.initialize(registryAddress, address(clonedInstance));
84
+ clonedInstance.setInstanceReader(clonedInstanceReader);
85
+
86
+ clonedBundleManager = BundleManager(Clones.clone(_masterInstanceBundleManager));
87
+ clonedBundleManager.initialize(address(clonedAccessManager), registryAddress, address(clonedInstance));
88
+ clonedInstance.setBundleManager(clonedBundleManager);
89
+
90
+ // TODO amend setters with instance specific , policy manager ...
91
+
92
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
93
+
94
+ // to complete setup switch instance ownership to the instance owner
95
+ // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
96
+ clonedAccessManager.grantRole(ADMIN_ROLE(), instanceOwner);
97
+ clonedAccessManager.revokeRole(ADMIN_ROLE(), address(this));
98
+
99
+ IRegistry.ObjectInfo memory info = registryService.registerInstance(clonedInstance, instanceOwner);
100
+ clonedInstanceNftId = info.nftId;
101
+ // clonedInstance.linkToRegisteredNftId();
102
+
103
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
104
+ }
105
+
106
+ function _grantInitialAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
107
+ _createGifRoles(clonedAccessManager);
108
+ _createGifTargets(clonedAccessManager, clonedInstance, clonedBundleManager);
109
+ _grantDistributionServiceAuthorizations(clonedAccessManager, clonedInstance);
110
+ _grantPoolServiceAuthorizations(clonedAccessManager, clonedInstance);
111
+ _grantProductServiceAuthorizations(clonedAccessManager, clonedInstance);
112
+ _grantApplicationServiceAuthorizations(clonedAccessManager, clonedInstance);
113
+ _grantPolicyServiceAuthorizations(clonedAccessManager, clonedInstance);
114
+ _grantClaimServiceAuthorizations(clonedAccessManager, clonedInstance);
115
+ _grantBundleServiceAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
116
+ _grantInstanceServiceAuthorizations(clonedAccessManager, clonedInstance);
117
+ }
118
+
119
+ function _createGifRoles(InstanceAccessManager clonedAccessManager) internal {
120
+ clonedAccessManager.createGifRole(DISTRIBUTION_OWNER_ROLE(), "DistributionOwnerRole");
121
+ clonedAccessManager.createGifRole(POOL_OWNER_ROLE(), "PoolOwnerRole");
122
+ clonedAccessManager.createGifRole(PRODUCT_OWNER_ROLE(), "ProductOwnerRole");
123
+
124
+ clonedAccessManager.createGifRole(DISTRIBUTION_SERVICE_ROLE(), "DistributionServiceRole");
125
+ clonedAccessManager.createGifRole(POOL_SERVICE_ROLE(), "PoolServiceRole");
126
+ clonedAccessManager.createGifRole(PRODUCT_SERVICE_ROLE(), "ProductServiceRole");
127
+ clonedAccessManager.createGifRole(APPLICATION_SERVICE_ROLE(), "ApplicationServiceRole");
128
+ clonedAccessManager.createGifRole(POLICY_SERVICE_ROLE(), "PolicyServiceRole");
129
+ clonedAccessManager.createGifRole(CLAIM_SERVICE_ROLE(), "ClaimServiceRole");
130
+ clonedAccessManager.createGifRole(BUNDLE_SERVICE_ROLE(), "BundleServiceRole");
131
+ clonedAccessManager.createGifRole(INSTANCE_SERVICE_ROLE(), "InstanceServiceRole");
132
+ }
133
+
134
+ function _createGifTargets(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
135
+ clonedAccessManager.createGifTarget(address(clonedAccessManager), "InstanceAccessManager");
136
+ clonedAccessManager.createGifTarget(address(clonedInstance), "Instance");
137
+ clonedAccessManager.createGifTarget(address(clonedBundleManager), "BundleManager");
138
+ }
139
+
140
+ function _grantDistributionServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
141
+ // configure authorization for distribution service on instance
142
+ IRegistry registry = getRegistry();
143
+ address distributionServiceAddress = registry.getServiceAddress(DISTRIBUTION(), getMajorVersion());
144
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE(), distributionServiceAddress);
145
+ bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](11);
146
+ instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
147
+ instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
148
+ instanceDistributionServiceSelectors[2] = clonedInstance.createDistributorType.selector;
149
+ instanceDistributionServiceSelectors[3] = clonedInstance.updateDistributorType.selector;
150
+ instanceDistributionServiceSelectors[4] = clonedInstance.updateDistributorTypeState.selector;
151
+ instanceDistributionServiceSelectors[5] = clonedInstance.createDistributor.selector;
152
+ instanceDistributionServiceSelectors[6] = clonedInstance.updateDistributor.selector;
153
+ instanceDistributionServiceSelectors[7] = clonedInstance.updateDistributorState.selector;
154
+ instanceDistributionServiceSelectors[8] = clonedInstance.createReferral.selector;
155
+ instanceDistributionServiceSelectors[9] = clonedInstance.updateReferral.selector;
156
+ instanceDistributionServiceSelectors[10] = clonedInstance.updateReferralState.selector;
157
+ clonedAccessManager.setTargetFunctionRole(
158
+ "Instance",
159
+ instanceDistributionServiceSelectors,
160
+ DISTRIBUTION_SERVICE_ROLE());
161
+ }
162
+
163
+ function _grantPoolServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
164
+ // configure authorization for pool service on instance
165
+ address poolServiceAddress = getRegistry().getServiceAddress(POOL(), getMajorVersion());
166
+ clonedAccessManager.grantRole(POOL_SERVICE_ROLE(), address(poolServiceAddress));
167
+ bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
168
+ instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
169
+ instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
170
+ clonedAccessManager.setTargetFunctionRole(
171
+ "Instance",
172
+ instancePoolServiceSelectors,
173
+ POOL_SERVICE_ROLE());
174
+ }
175
+
176
+ function _grantProductServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
177
+ // configure authorization for product service on instance
178
+ address productServiceAddress = getRegistry().getServiceAddress(PRODUCT(), getMajorVersion());
179
+ clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE(), address(productServiceAddress));
180
+ bytes4[] memory instanceProductServiceSelectors = new bytes4[](5);
181
+ instanceProductServiceSelectors[0] = clonedInstance.createProductSetup.selector;
182
+ instanceProductServiceSelectors[1] = clonedInstance.updateProductSetup.selector;
183
+ instanceProductServiceSelectors[2] = clonedInstance.createRisk.selector;
184
+ instanceProductServiceSelectors[3] = clonedInstance.updateRisk.selector;
185
+ instanceProductServiceSelectors[4] = clonedInstance.updateRiskState.selector;
186
+ clonedAccessManager.setTargetFunctionRole(
187
+ "Instance",
188
+ instanceProductServiceSelectors,
189
+ PRODUCT_SERVICE_ROLE());
190
+ }
191
+
192
+ function _grantApplicationServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
193
+ // configure authorization for application services on instance
194
+ address applicationServiceAddress = getRegistry().getServiceAddress(APPLICATION(), getMajorVersion());
195
+ clonedAccessManager.grantRole(APPLICATION_SERVICE_ROLE(), applicationServiceAddress);
196
+ bytes4[] memory instanceApplicationServiceSelectors = new bytes4[](3);
197
+ instanceApplicationServiceSelectors[0] = clonedInstance.createApplication.selector;
198
+ instanceApplicationServiceSelectors[1] = clonedInstance.updateApplication.selector;
199
+ instanceApplicationServiceSelectors[2] = clonedInstance.updateApplicationState.selector;
200
+ clonedAccessManager.setTargetFunctionRole(
201
+ "Instance",
202
+ instanceApplicationServiceSelectors,
203
+ APPLICATION_SERVICE_ROLE());
204
+ }
205
+
206
+ function _grantPolicyServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
207
+ // configure authorization for policy services on instance
208
+ address policyServiceAddress = getRegistry().getServiceAddress(POLICY(), getMajorVersion());
209
+ clonedAccessManager.grantRole(POLICY_SERVICE_ROLE(), policyServiceAddress);
210
+ bytes4[] memory instancePolicyServiceSelectors = new bytes4[](2);
211
+ instancePolicyServiceSelectors[0] = clonedInstance.updatePolicy.selector;
212
+ instancePolicyServiceSelectors[1] = clonedInstance.updatePolicyState.selector;
213
+ clonedAccessManager.setTargetFunctionRole(
214
+ "Instance",
215
+ instancePolicyServiceSelectors,
216
+ POLICY_SERVICE_ROLE());
217
+ }
218
+
219
+ function _grantClaimServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
220
+ // configure authorization for claim/payout services on instance
221
+ address claimServiceAddress = getRegistry().getServiceAddress(CLAIM(), getMajorVersion());
222
+ clonedAccessManager.grantRole(POLICY_SERVICE_ROLE(), claimServiceAddress);
223
+ // TODO add claims function authz
224
+ bytes4[] memory instanceClaimServiceSelectors = new bytes4[](0);
225
+ // instanceClaimServiceSelectors[0] = clonedInstance.updatePolicy.selector;
226
+ // instanceClaimServiceSelectors[1] = clonedInstance.updatePolicyState.selector;
227
+ clonedAccessManager.setTargetFunctionRole(
228
+ "Instance",
229
+ instanceClaimServiceSelectors,
230
+ CLAIM_SERVICE_ROLE());
231
+ }
232
+
233
+ function _grantBundleServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
234
+ // configure authorization for bundle service on instance
235
+ address bundleServiceAddress = getRegistry().getServiceAddress(BUNDLE(), getMajorVersion());
236
+ clonedAccessManager.grantRole(BUNDLE_SERVICE_ROLE(), address(bundleServiceAddress));
237
+ bytes4[] memory instanceBundleServiceSelectors = new bytes4[](2);
238
+ instanceBundleServiceSelectors[0] = clonedInstance.createBundle.selector;
239
+ instanceBundleServiceSelectors[1] = clonedInstance.updateBundle.selector;
240
+ clonedAccessManager.setTargetFunctionRole(
241
+ "Instance",
242
+ instanceBundleServiceSelectors,
243
+ BUNDLE_SERVICE_ROLE());
244
+
245
+ // configure authorization for bundle service on bundle manager
246
+ bytes4[] memory bundleManagerBundleServiceSelectors = new bytes4[](5);
247
+ bundleManagerBundleServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
248
+ bundleManagerBundleServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
249
+ bundleManagerBundleServiceSelectors[2] = clonedBundleManager.add.selector;
250
+ bundleManagerBundleServiceSelectors[3] = clonedBundleManager.lock.selector;
251
+ bundleManagerBundleServiceSelectors[4] = clonedBundleManager.unlock.selector;
252
+ clonedAccessManager.setTargetFunctionRole(
253
+ "BundleManager",
254
+ bundleManagerBundleServiceSelectors,
255
+ BUNDLE_SERVICE_ROLE());
256
+ }
257
+
258
+ function _grantInstanceServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
259
+ // configure authorization for instance service on instance
260
+ address instanceServiceAddress = getRegistry().getServiceAddress(INSTANCE(), getMajorVersion());
261
+ clonedAccessManager.grantRole(INSTANCE_SERVICE_ROLE(), instanceServiceAddress);
262
+ bytes4[] memory instanceInstanceServiceSelectors = new bytes4[](1);
263
+ instanceInstanceServiceSelectors[0] = clonedInstance.setInstanceReader.selector;
264
+ clonedAccessManager.setTargetFunctionRole(
265
+ "Instance",
266
+ instanceInstanceServiceSelectors,
267
+ INSTANCE_SERVICE_ROLE());
268
+
269
+ bytes4[] memory instanceAccessManagerInstanceServiceSelectors = new bytes4[](1);
270
+ instanceAccessManagerInstanceServiceSelectors[0] = clonedAccessManager.createGifTarget.selector;
271
+ clonedAccessManager.setTargetFunctionRole(
272
+ "InstanceAccessManager",
273
+ instanceAccessManagerInstanceServiceSelectors,
274
+ INSTANCE_SERVICE_ROLE());
275
+ }
276
+
277
+ function setAndRegisterMasterInstance(address instanceAddress)
278
+ external
279
+ onlyOwner
280
+ returns(NftId masterInstanceNftId)
281
+ {
282
+ if(_masterInstance != address(0)) { revert ErrorInstanceServiceMasterInstanceAlreadySet(); }
283
+ if(_masterInstanceAccessManager != address(0)) { revert ErrorInstanceServiceMasterInstanceAccessManagerAlreadySet(); }
284
+ if(_masterInstanceBundleManager != address(0)) { revert ErrorInstanceServiceMasterBundleManagerAlreadySet(); }
285
+
286
+ if(instanceAddress == address(0)) { revert ErrorInstanceServiceInstanceAddressZero(); }
287
+
288
+ IInstance instance = IInstance(instanceAddress);
289
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
290
+ address accessManagerAddress = address(accessManager);
291
+ InstanceReader instanceReader = instance.getInstanceReader();
292
+ address instanceReaderAddress = address(instanceReader);
293
+ BundleManager bundleManager = instance.getBundleManager();
294
+ address bundleManagerAddress = address(bundleManager);
295
+
296
+ if(accessManagerAddress == address(0)) { revert ErrorInstanceServiceAccessManagerZero(); }
297
+ if(instanceReaderAddress == address(0)) { revert ErrorInstanceServiceInstanceReaderZero(); }
298
+ if(bundleManagerAddress == address(0)) { revert ErrorInstanceServiceBundleManagerZero(); }
299
+
300
+ if(instance.authority() != accessManagerAddress) { revert ErrorInstanceServiceInstanceAuthorityMismatch(); }
301
+ if(instanceReader.getInstance() != instance) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch2(); }
302
+ if(bundleManager.getInstance() != instance) { revert ErrorInstanceServiceBundleMangerInstanceMismatch(); }
303
+
304
+ _masterInstanceAccessManager = accessManagerAddress;
305
+ _masterInstance = instanceAddress;
306
+ _masterInstanceReader = instanceReaderAddress;
307
+ _masterInstanceBundleManager = bundleManagerAddress;
308
+
309
+ IRegistryService registryService = IRegistryService(getRegistry().getServiceAddress(REGISTRY(), getMajorVersion()));
310
+ IInstance masterInstance = IInstance(_masterInstance);
311
+ IRegistry.ObjectInfo memory info = registryService.registerInstance(masterInstance, getOwner());
312
+ masterInstanceNftId = info.nftId;
313
+
314
+ // masterInstance.linkToRegisteredNftId();
315
+ }
316
+
317
+ function setMasterInstanceReader(address instanceReaderAddress) external onlyOwner {
318
+ if(_masterInstanceReader == address(0)) { revert ErrorInstanceServiceMasterInstanceReaderNotSet(); }
319
+ if(instanceReaderAddress == address(0)) { revert ErrorInstanceServiceInstanceReaderAddressZero(); }
320
+ if(instanceReaderAddress == _masterInstanceReader) { revert ErrorInstanceServiceInstanceReaderSameAsMasterInstanceReader(); }
321
+
322
+ InstanceReader instanceReader = InstanceReader(instanceReaderAddress);
323
+ if(instanceReader.getInstance() != IInstance(_masterInstance)) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch(); }
324
+
325
+ _masterInstanceReader = instanceReaderAddress;
326
+ }
327
+
328
+ // TODO access restriction
329
+ function upgradeInstanceReader(NftId instanceNftId) external {
330
+ IRegistry registry = getRegistry();
331
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
332
+ Instance instance = Instance(instanceInfo.objectAddress);
333
+ address owner = instance.getOwner();
334
+
335
+ if (msg.sender != owner) {
336
+ revert ErrorInstanceServiceRequestUnauhorized(msg.sender);
337
+ }
338
+
339
+ InstanceReader upgradedInstanceReaderClone = InstanceReader(Clones.clone(address(_masterInstanceReader)));
340
+ upgradedInstanceReaderClone.initialize(address(registry), address(instance));
341
+ instance.setInstanceReader(upgradedInstanceReaderClone);
342
+ }
343
+
344
+ function getMasterInstanceReader() external view returns (address) {
345
+ return _masterInstanceReader;
346
+ }
347
+
348
+ function getMasterInstance() external view returns (address) {
349
+ return _masterInstance;
350
+ }
351
+
352
+ function getMasterInstanceAccessManager() external view returns (address) {
353
+ return _masterInstanceAccessManager;
354
+ }
355
+
356
+ function getMasterInstanceBundleManager() external view returns (address) {
357
+ return _masterInstanceBundleManager;
358
+ }
359
+
360
+ // From IService
361
+ function getDomain() public pure override(Service, IService) returns(ObjectType) {
362
+ return INSTANCE();
363
+ }
364
+
365
+ /// @dev top level initializer
366
+ function _initialize(
367
+ address owner,
368
+ bytes memory data
369
+ )
370
+ internal
371
+ initializer
372
+ virtual override
373
+ {
374
+ address initialOwner;
375
+ address registryAddress;
376
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
377
+ // TODO while InstanceService is not deployed in InstanceServiceManager constructor
378
+ // owner is InstanceServiceManager deployer
379
+ initializeService(registryAddress, owner);
380
+ registerInterface(type(IInstanceService).interfaceId);
27
381
  }
28
382
 
29
- function setAccessManagerMaster(address accessManager) external {
30
- _accessManagerMaster = accessManager;
383
+ function hasRole(address account, RoleId role, address instanceAddress) public view returns (bool) {
384
+ Instance instance = Instance(instanceAddress);
385
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
386
+ return accessManager.hasRole(role, account);
31
387
  }
32
388
 
33
- function setInstanceAccessManagerMaster(address instanceAccessManager) external {
34
- _instanceAccessManagerMaster = instanceAccessManager;
389
+ function createGifTarget(NftId instanceNftId, address targetAddress, string memory targetName) external onlyRegisteredService {
390
+ IRegistry registry = getRegistry();
391
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
392
+ Instance instance = Instance(instanceInfo.objectAddress);
393
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
394
+ accessManager.createGifTarget(targetAddress, targetName);
35
395
  }
36
396
 
37
- function setInstanceMaster(address instance) external {
38
- _instanceMaster = instance;
397
+ function grantDistributionDefaultPermissions(NftId instanceNftId, address distributionAddress, string memory distributionName) external onlyRegisteredService {
398
+ IRegistry registry = getRegistry();
399
+ IRegistry.ObjectInfo memory distributionInfo = registry.getObjectInfo(distributionAddress);
400
+
401
+ if (distributionInfo.objectType != DISTRIBUTION()) {
402
+ revert ErrorInstanceServiceInvalidComponentType(distributionAddress, DISTRIBUTION(), distributionInfo.objectType);
403
+ }
404
+
405
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
406
+ Instance instance = Instance(instanceInfo.objectAddress);
407
+ InstanceAccessManager instanceAccessManager = InstanceAccessManager(instance.authority());
408
+
409
+ bytes4[] memory fctSelectors = new bytes4[](1);
410
+ fctSelectors[0] = IDistributionComponent.setFees.selector;
411
+ instanceAccessManager.setTargetFunctionRole(distributionName, fctSelectors, DISTRIBUTION_OWNER_ROLE());
412
+
413
+ bytes4[] memory fctSelectors2 = new bytes4[](2);
414
+ fctSelectors2[0] = IDistributionComponent.processSale.selector;
415
+ fctSelectors2[1] = IDistributionComponent.processRenewal.selector;
416
+ instanceAccessManager.setTargetFunctionRole(distributionName, fctSelectors2, PRODUCT_SERVICE_ROLE());
417
+ }
418
+
419
+ function grantPoolDefaultPermissions(NftId instanceNftId, address poolAddress, string memory poolName) external onlyRegisteredService {
420
+ IRegistry registry = getRegistry();
421
+ IRegistry.ObjectInfo memory poolInfo = registry.getObjectInfo(poolAddress);
422
+
423
+ if (poolInfo.objectType != POOL()) {
424
+ revert ErrorInstanceServiceInvalidComponentType(poolAddress, POOL(), poolInfo.objectType);
425
+ }
426
+
427
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
428
+ Instance instance = Instance(instanceInfo.objectAddress);
429
+ InstanceAccessManager instanceAccessManager = InstanceAccessManager(instance.authority());
430
+
431
+ bytes4[] memory fctSelectors = new bytes4[](1);
432
+ fctSelectors[0] = IPoolComponent.setFees.selector;
433
+ instanceAccessManager.setTargetFunctionRole(poolName, fctSelectors, POOL_OWNER_ROLE());
434
+
435
+ bytes4[] memory fctSelectors2 = new bytes4[](1);
436
+ fctSelectors2[0] = IPoolComponent.verifyApplication.selector;
437
+ instanceAccessManager.setTargetFunctionRole(poolName, fctSelectors2, POLICY_SERVICE_ROLE());
39
438
  }
40
439
 
41
- function getAccessManagerMaster() external view returns (address) { return address(_accessManagerMaster); }
42
- function getInstanceAccessManagerMaster() external view returns (address) { return address(_instanceAccessManagerMaster); }
43
- function getInstanceMaster() external view returns (address) { return address(_instanceMaster); }
440
+ function grantProductDefaultPermissions(NftId instanceNftId, address productAddress, string memory productName) external onlyRegisteredService {
441
+ IRegistry registry = getRegistry();
442
+ IRegistry.ObjectInfo memory productInfo = registry.getObjectInfo(productAddress);
443
+
444
+ if (productInfo.objectType != PRODUCT()) {
445
+ revert ErrorInstanceServiceInvalidComponentType(productAddress, PRODUCT(), productInfo.objectType);
446
+ }
447
+
448
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
449
+ Instance instance = Instance(instanceInfo.objectAddress);
450
+ InstanceAccessManager instanceAccessManager = InstanceAccessManager(instance.authority());
451
+
452
+ bytes4[] memory fctSelectors = new bytes4[](1);
453
+ fctSelectors[0] = IProductComponent.setFees.selector;
454
+ instanceAccessManager.setTargetFunctionRole(productName, fctSelectors, PRODUCT_OWNER_ROLE());
455
+ }
456
+
457
+ function setTargetLocked(string memory targetName, bool locked) external {
458
+ address componentAddress = msg.sender;
459
+ IRegistry registry = getRegistry();
460
+ IRegistry.ObjectInfo memory componentInfo = registry.getObjectInfo(componentAddress);
461
+ if (componentInfo.nftId.eqz()) {
462
+ revert ErrorInstanceServiceComponentNotRegistered(componentAddress);
463
+ }
464
+
465
+ // TODO validate component type
466
+
467
+
468
+ address instanceAddress = registry.getObjectInfo(componentInfo.parentNftId).objectAddress;
469
+ IInstance instance = IInstance(instanceAddress);
470
+
471
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
472
+ accessManager.setTargetClosed(targetName, locked);
473
+ }
474
+
44
475
  }
45
476
 
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Instance} from "./Instance.sol";
5
+ import {IVersionable} from "../shared/IVersionable.sol";
6
+ import {ProxyManager} from "../shared/ProxyManager.sol";
7
+ import {InstanceService} from "./InstanceService.sol";
8
+ import {Registry} from "../registry/Registry.sol";
9
+ import {RegistryService} from "../registry/RegistryService.sol";
10
+ import {REGISTRY} from "../types/ObjectType.sol";
11
+
12
+ contract InstanceServiceManager is ProxyManager {
13
+
14
+ InstanceService private _instanceService;
15
+
16
+ /// @dev initializes proxy manager with instance service implementation and deploys instance
17
+ constructor(
18
+ address registryAddress
19
+ )
20
+ ProxyManager(registryAddress)
21
+ {
22
+ InstanceService instSrv = new InstanceService();
23
+ // bytes memory initCode = type(InstanceService).creationCode;
24
+ bytes memory data = abi.encode(registryAddress, address(this));
25
+ IVersionable versionable = deploy(
26
+ address(instSrv),
27
+ data);
28
+
29
+ _instanceService = InstanceService(address(versionable));
30
+
31
+ // TODO `this` must have a role or own nft to register service
32
+ //Registry registry = Registry(registryAddress);
33
+ //address registryServiceAddress = registry.getServiceAddress(REGISTRY(), _instanceService.getMajorVersion());
34
+ //RegistryService registryService = RegistryService(registryServiceAddress);
35
+ //registryService.registerService(_instanceService);
36
+ // RegistryService registryService = _instanceService.getRegistryService();
37
+
38
+ // TODO no nft to link yet
39
+ // link ownership of instance service manager ot nft owner of instance service
40
+ //_linkToNftOwnable(
41
+ // address(registryAddress),
42
+ // address(_instanceService));
43
+ }
44
+
45
+ //--- view functions ----------------------------------------------------//
46
+ function getInstanceService()
47
+ external
48
+ view
49
+ returns (InstanceService instanceService)
50
+ {
51
+ return _instanceService;
52
+ }
53
+
54
+ }
@@ -0,0 +1,84 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Cloneable} from "./Cloneable.sol";
5
+
6
+ import {IInstance} from "./IInstance.sol";
7
+ import {INSTANCE} from "../types/ObjectType.sol";
8
+ import {InstanceReader} from "./InstanceReader.sol";
9
+ import {IRegistry} from "../registry/IRegistry.sol";
10
+ import {LibNftIdSet} from "../types/NftIdSet.sol";
11
+ import {NftId} from "../types/NftId.sol";
12
+
13
+ contract ObjectManager is
14
+ Cloneable
15
+ {
16
+
17
+ event LogObjectManagerInitialized(address instance);
18
+
19
+ error ErrorObjectManagerNftIdInvalid(NftId instanceNftId);
20
+ error ErrorObjectManagerAlreadyAdded(NftId componentNftId, NftId objectNftId);
21
+
22
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _activeObjects;
23
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _allObjects;
24
+ IInstance internal _instance; // store instance address -> more flexible, instance may not be registered during ObjectManager initialization
25
+
26
+ /// @dev call to initialize MUST be made in the same transaction as cloning of the contract
27
+ function initialize(
28
+ address authority,
29
+ address registry,
30
+ address instance
31
+ )
32
+ external
33
+ {
34
+ initialize(authority, registry);
35
+
36
+ _instance = IInstance(instance);
37
+
38
+ emit LogObjectManagerInitialized(instance);
39
+ }
40
+
41
+ function getInstance() external view returns (IInstance) {
42
+ return _instance;
43
+ }
44
+
45
+ function _add(NftId componentNftId, NftId objectNftId) internal {
46
+ LibNftIdSet.Set storage allSet = _allObjects[componentNftId];
47
+ LibNftIdSet.Set storage activeSet = _activeObjects[componentNftId];
48
+
49
+ LibNftIdSet.add(allSet, objectNftId);
50
+ LibNftIdSet.add(activeSet, objectNftId);
51
+ }
52
+
53
+ function _activate(NftId componentNftId, NftId objectNftId) internal {
54
+ LibNftIdSet.add(_activeObjects[componentNftId], objectNftId);
55
+ }
56
+
57
+ function _deactivate(NftId componentNftId, NftId objectNftId) internal {
58
+ LibNftIdSet.remove(_activeObjects[componentNftId], objectNftId);
59
+ }
60
+
61
+ function _objects(NftId componentNftId) internal view returns (uint256) {
62
+ return LibNftIdSet.size(_allObjects[componentNftId]);
63
+ }
64
+
65
+ function _contains(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
66
+ return LibNftIdSet.contains(_allObjects[componentNftId], objectNftId);
67
+ }
68
+
69
+ function _getObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
70
+ return LibNftIdSet.getElementAt(_allObjects[componentNftId], idx);
71
+ }
72
+
73
+ function _activeObjs(NftId componentNftId) internal view returns (uint256) {
74
+ return LibNftIdSet.size(_activeObjects[componentNftId]);
75
+ }
76
+
77
+ function _isActive(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
78
+ return LibNftIdSet.contains(_activeObjects[componentNftId], objectNftId);
79
+ }
80
+
81
+ function _getActiveObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
82
+ return LibNftIdSet.getElementAt(_activeObjects[componentNftId], idx);
83
+ }
84
+ }