@etherisc/gif-next 0.0.2-cc4a5cb-898 → 0.0.2-cdac553-411

Sign up to get free protection for your applications and to get access to all the features.
Files changed (381) hide show
  1. package/README.md +148 -26
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +176 -23
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +308 -43
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +129 -23
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +36 -172
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +0 -238
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +0 -213
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +391 -96
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +409 -78
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.json +66 -0
  20. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.json +24 -0
  22. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.json +42 -0
  24. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  36. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  37. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
  40. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  42. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  43. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  44. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +4 -0
  45. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +101 -0
  46. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +4 -0
  47. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +1132 -0
  48. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +4 -0
  49. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +1082 -0
  50. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  51. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +238 -1492
  52. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  53. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +480 -0
  54. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  55. package/artifacts/contracts/instance/Instance.sol/Instance.json +2298 -1144
  56. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +4 -0
  57. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +917 -0
  58. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +4 -0
  59. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +1388 -0
  60. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +4 -0
  61. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +891 -0
  62. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  63. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +492 -0
  64. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +229 -43
  66. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +1 -1
  68. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +27 -158
  70. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  72. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +37 -245
  73. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  74. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  75. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +4 -0
  76. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +211 -0
  77. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +4 -0
  78. package/artifacts/contracts/instance/module/{bundle/IBundle.sol → IBundle.sol}/IBundle.json +1 -1
  79. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +4 -0
  80. package/artifacts/contracts/instance/module/{distribution/IDistribution.sol → IDistribution.sol}/IDistribution.json +1 -1
  81. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +4 -0
  82. package/artifacts/contracts/instance/module/{policy/IPolicy.sol → IPolicy.sol}/IPolicy.json +1 -1
  83. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +4 -0
  84. package/artifacts/contracts/instance/module/{risk/IRisk.sol → IRisk.sol}/IRisk.json +1 -1
  85. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +4 -0
  86. package/artifacts/contracts/instance/{base/ModuleBase.sol/ModuleBase.json → module/ISetup.sol/ISetup.json} +2 -2
  87. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +4 -0
  88. package/artifacts/contracts/instance/module/{treasury/ITreasury.sol → ITreasury.sol}/ITreasury.json +1 -1
  89. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +375 -79
  91. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +290 -53
  93. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  94. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +436 -0
  95. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +177 -75
  97. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +174 -53
  99. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  100. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +176 -55
  101. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  102. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +179 -58
  103. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +307 -54
  105. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +448 -0
  107. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  108. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +186 -12
  109. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  110. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +485 -37
  111. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +4 -0
  112. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +853 -0
  113. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +4 -0
  114. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +34 -0
  115. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  116. package/artifacts/contracts/registry/Registry.sol/Registry.json +597 -122
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +4 -0
  118. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +1237 -0
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +4 -0
  120. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +525 -0
  121. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
  123. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +4 -0
  124. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.json +107 -0
  125. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  126. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  127. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +4 -0
  128. package/artifacts/contracts/{instance/module/component/ComponentModule.sol/ComponentModule.json → shared/INftOwnable.sol/INftOwnable.json} +67 -57
  129. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +117 -37
  131. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  132. package/artifacts/contracts/{instance/base/InstanceBase.sol/InstanceBase.json → shared/IService.sol/IService.json} +168 -123
  133. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  134. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +55 -14
  135. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +4 -0
  136. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +158 -0
  137. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +4 -0
  138. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +349 -0
  139. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +190 -37
  141. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +4 -0
  142. package/artifacts/contracts/{instance/base/IService.sol/IService.json → shared/RegisterableUpgradable.sol/RegisterableUpgradable.json} +215 -73
  143. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  144. package/artifacts/contracts/{instance/base/ServiceBase.sol/ServiceBase.json → shared/Service.sol/Service.json} +222 -54
  145. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  146. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +96 -0
  147. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +4 -0
  148. package/artifacts/contracts/shared/{Proxy.sol/ProxyWithProxyAdminGetter.json → UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json} +4 -4
  149. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  150. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +78 -14
  151. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  152. package/artifacts/contracts/test/TestFee.sol/TestFee.json +4 -4
  153. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  154. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +204 -36
  155. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +14 -14
  157. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestService.sol/TestService.json +283 -62
  159. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  160. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +91 -53
  161. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  162. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  163. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  164. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +103 -23
  165. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  166. package/artifacts/contracts/test/Usdc.sol/USDC.json +91 -53
  167. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  168. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +4 -0
  171. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +104 -0
  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 +31 -17
  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/NumberId.sol/NumberIdLib.dbg.json +4 -0
  181. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.json +100 -0
  182. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  184. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +4 -0
  185. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +123 -0
  186. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  187. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  188. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +134 -8
  190. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  192. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  193. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +15 -2
  194. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  195. package/artifacts/contracts/types/UFixed.sol/MathLib.json +10 -0
  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 +40 -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/BaseComponent.sol +26 -29
  203. package/contracts/components/Distribution.sol +52 -18
  204. package/contracts/components/IBaseComponent.sol +9 -3
  205. package/contracts/components/IDistributionComponent.sol +5 -6
  206. package/contracts/components/IPoolComponent.sol +2 -11
  207. package/contracts/components/IProductComponent.sol +4 -7
  208. package/contracts/components/Pool.sol +87 -75
  209. package/contracts/components/Product.sol +111 -41
  210. package/contracts/experiment/cloning/Cloner.sol +47 -0
  211. package/contracts/instance/AccessManagedSimple.sol +115 -0
  212. package/contracts/instance/AccessManagerSimple.sol +692 -0
  213. package/contracts/instance/IAccessManagerSimple.sol +391 -0
  214. package/contracts/instance/IInstance.sol +31 -45
  215. package/contracts/instance/IInstanceService.sol +30 -0
  216. package/contracts/instance/Instance.sol +426 -57
  217. package/contracts/instance/InstanceAccessManager.sol +288 -0
  218. package/contracts/instance/InstanceReader.sol +306 -0
  219. package/contracts/instance/InstanceService.sol +180 -0
  220. package/contracts/instance/InstanceServiceManager.sol +56 -0
  221. package/contracts/instance/base/ComponentServiceBase.sol +12 -13
  222. package/contracts/instance/base/IInstanceBase.sol +3 -2
  223. package/contracts/instance/base/IKeyValueStore.sol +13 -14
  224. package/contracts/instance/base/ILifecycle.sol +3 -3
  225. package/contracts/instance/base/KeyValueStore.sol +49 -38
  226. package/contracts/instance/base/Lifecycle.sol +1 -1
  227. package/contracts/instance/module/IAccess.sol +38 -0
  228. package/contracts/instance/module/IBundle.sol +20 -0
  229. package/contracts/instance/module/IDistribution.sol +39 -0
  230. package/contracts/instance/module/IPolicy.sol +45 -0
  231. package/contracts/instance/module/IRisk.sol +11 -0
  232. package/contracts/instance/module/ISetup.sol +44 -0
  233. package/contracts/instance/module/ITreasury.sol +23 -0
  234. package/contracts/instance/service/ComponentOwnerService.sol +232 -72
  235. package/contracts/instance/service/DistributionService.sol +66 -20
  236. package/contracts/instance/service/DistributionServiceManager.sol +53 -0
  237. package/contracts/instance/service/IComponentOwnerService.sol +1 -3
  238. package/contracts/instance/service/IDistributionService.sol +1 -1
  239. package/contracts/instance/service/IPoolService.sol +1 -1
  240. package/contracts/instance/service/IProductService.sol +3 -3
  241. package/contracts/instance/service/PoolService.sol +116 -54
  242. package/contracts/instance/service/PoolServiceManager.sol +53 -0
  243. package/contracts/registry/ChainNft.sol +80 -37
  244. package/contracts/registry/IRegistry.sol +62 -25
  245. package/contracts/registry/IRegistryService.sol +33 -0
  246. package/contracts/registry/ITransferInterceptor.sol +6 -0
  247. package/contracts/registry/Registry.sol +374 -266
  248. package/contracts/registry/RegistryService.sol +399 -0
  249. package/contracts/registry/RegistryServiceManager.sol +80 -0
  250. package/contracts/registry/TokenRegistry.sol +111 -0
  251. package/contracts/shared/ContractDeployerLib.sol +72 -0
  252. package/contracts/shared/ERC165.sol +6 -2
  253. package/contracts/shared/INftOwnable.sol +22 -0
  254. package/contracts/shared/IRegisterable.sol +8 -15
  255. package/contracts/{instance/base → shared}/IService.sol +3 -3
  256. package/contracts/shared/IVersionable.sol +55 -11
  257. package/contracts/shared/NftOwnable.sol +136 -0
  258. package/contracts/shared/ProxyManager.sol +94 -0
  259. package/contracts/shared/Registerable.sol +63 -59
  260. package/contracts/shared/RegisterableUpgradable.sol +16 -0
  261. package/contracts/shared/Service.sol +54 -0
  262. package/contracts/shared/TokenHandler.sol +27 -0
  263. package/contracts/shared/UpgradableProxyWithAdmin.sol +16 -0
  264. package/contracts/shared/Versionable.sol +113 -55
  265. package/contracts/test/TestFee.sol +2 -2
  266. package/contracts/test/TestRegisterable.sol +5 -6
  267. package/contracts/test/TestRoleId.sol +1 -1
  268. package/contracts/test/TestService.sol +5 -13
  269. package/contracts/types/DistributorType.sol +55 -0
  270. package/contracts/types/Fee.sol +3 -3
  271. package/contracts/types/Key32.sol +8 -3
  272. package/contracts/types/NumberId.sol +52 -0
  273. package/contracts/types/ObjectType.sol +35 -14
  274. package/contracts/types/Referral.sol +85 -0
  275. package/contracts/types/RoleId.sol +60 -9
  276. package/contracts/types/StateId.sol +5 -1
  277. package/contracts/types/Timestamp.sol +7 -3
  278. package/contracts/types/UFixed.sol +128 -12
  279. package/contracts/types/Version.sol +13 -1
  280. package/package.json +4 -3
  281. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +0 -4
  282. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.json +0 -24
  283. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +0 -4
  284. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +0 -4
  285. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +0 -4
  286. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +0 -4
  287. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +0 -4
  288. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.json +0 -333
  289. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +0 -4
  290. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.json +0 -10
  291. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +0 -4
  292. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.json +0 -333
  293. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +0 -4
  294. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +0 -297
  295. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +0 -4
  296. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +0 -4
  297. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +0 -297
  298. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +0 -4
  299. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +0 -4
  300. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.json +0 -10
  301. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +0 -4
  302. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +0 -117
  303. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.dbg.json +0 -4
  304. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.json +0 -10
  305. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.dbg.json +0 -4
  306. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.dbg.json +0 -4
  307. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.json +0 -10
  308. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +0 -4
  309. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +0 -4
  310. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +0 -284
  311. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +0 -4
  312. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +0 -284
  313. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +0 -4
  314. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.json +0 -10
  315. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +0 -4
  316. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -144
  317. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +0 -4
  318. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -144
  319. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +0 -4
  320. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +0 -4
  321. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +0 -113
  322. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +0 -4
  323. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +0 -131
  324. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +0 -4
  325. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +0 -4
  326. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +0 -511
  327. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +0 -4
  328. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +0 -76
  329. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +0 -4
  330. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +0 -511
  331. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +0 -4
  332. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +0 -858
  333. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +0 -4
  334. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +0 -452
  335. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +0 -4
  336. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.json +0 -24
  337. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +0 -4
  338. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.json +0 -24
  339. package/artifacts/contracts/shared/Proxy.sol/Proxy.dbg.json +0 -4
  340. package/artifacts/contracts/shared/Proxy.sol/Proxy.json +0 -178
  341. package/artifacts/contracts/shared/Proxy.sol/ProxyWithProxyAdminGetter.dbg.json +0 -4
  342. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.dbg.json +0 -4
  343. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.json +0 -405
  344. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +0 -4
  345. package/artifacts/contracts/test/TestPool.sol/TestPool.json +0 -578
  346. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +0 -4
  347. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +0 -575
  348. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.dbg.json +0 -4
  349. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.json +0 -99
  350. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +0 -4
  351. package/contracts/experiment/statemachine/README.md +0 -112
  352. package/contracts/instance/IInstanceLinked.sol +0 -8
  353. package/contracts/instance/base/InstanceBase.sol +0 -91
  354. package/contracts/instance/base/ModuleBase.sol +0 -57
  355. package/contracts/instance/base/ServiceBase.sol +0 -37
  356. package/contracts/instance/module/access/Access.sol +0 -149
  357. package/contracts/instance/module/access/IAccess.sol +0 -53
  358. package/contracts/instance/module/bundle/BundleModule.sol +0 -134
  359. package/contracts/instance/module/bundle/IBundle.sol +0 -53
  360. package/contracts/instance/module/component/ComponentModule.sol +0 -70
  361. package/contracts/instance/module/component/IComponent.sol +0 -28
  362. package/contracts/instance/module/distribution/DistributionModule.sol +0 -17
  363. package/contracts/instance/module/distribution/IDistribution.sol +0 -10
  364. package/contracts/instance/module/policy/IPolicy.sol +0 -63
  365. package/contracts/instance/module/policy/PolicyModule.sol +0 -91
  366. package/contracts/instance/module/pool/IPoolModule.sol +0 -40
  367. package/contracts/instance/module/pool/PoolModule.sol +0 -90
  368. package/contracts/instance/module/risk/IRisk.sol +0 -26
  369. package/contracts/instance/module/risk/RiskModule.sol +0 -62
  370. package/contracts/instance/module/treasury/ITreasury.sol +0 -82
  371. package/contracts/instance/module/treasury/TokenHandler.sol +0 -48
  372. package/contracts/instance/module/treasury/TreasuryModule.sol +0 -138
  373. package/contracts/instance/service/ProductService.sol +0 -509
  374. package/contracts/registry/IChainNft.sol +0 -21
  375. package/contracts/registry/IRegistryLinked.sol +0 -8
  376. package/contracts/shared/IOwnable.sol +0 -6
  377. package/contracts/shared/Proxy.sol +0 -83
  378. package/contracts/test/TestDistribution.sol +0 -21
  379. package/contracts/test/TestPool.sol +0 -25
  380. package/contracts/test/TestProduct.sol +0 -72
  381. package/contracts/types/ReferralId.sol +0 -48
@@ -1,381 +1,489 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.19;
2
+ pragma solidity ^0.8.20;
3
3
 
4
4
  import {IRegisterable} from "../shared/IRegisterable.sol";
5
- import {IService} from "../instance/base/IService.sol";
5
+ import {IService} from "../shared/IService.sol";
6
6
 
7
- import {IChainNft} from "./IChainNft.sol";
8
7
  import {ChainNft} from "./ChainNft.sol";
9
8
  import {IRegistry} from "./IRegistry.sol";
10
9
  import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
11
- import {VersionPart} from "../types/Version.sol";
10
+ import {Version, VersionPart, VersionLib, VersionPartLib} from "../types/Version.sol";
12
11
  import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, DISTRIBUTION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
12
+ import {ITransferInterceptor} from "./ITransferInterceptor.sol";
13
+
14
+ import {ERC165} from "../shared/ERC165.sol";
15
+
16
+
17
+ // IMPORTANT
18
+ // Each NFT minted by registry is accosiated with:
19
+ // 1) NFT owner
20
+ // 2) registred contract OR object stored in registered (parent) contract
21
+ // Four registration flows:
22
+ // 1) non IRegisterable address by registryOwner (TOKEN)
23
+ // 2) IRegisterable address by registryOwner (SERVICE)
24
+ // 3) IRegisterable address by approved service (INSTANCE, COMPONENT)
25
+ // 4) state object by approved service (POLICY, BUNDLE, STAKE)
13
26
 
14
- // TODO make registry upgradable
15
27
  contract Registry is
16
- IRegisterable,
28
+ ERC165,
17
29
  IRegistry
18
30
  {
19
- using NftIdLib for NftId;
20
-
31
+ uint256 public constant GIF_MAJOR_VERSION_AT_DEPLOYMENT = 3;
32
+ address public constant NFT_LOCK_ADDRESS = address(0x1);
33
+ uint256 public constant REGISTRY_SERVICE_TOKEN_SEQUENCE_ID = 3;
21
34
  string public constant EMPTY_URI = "";
22
35
 
23
- mapping(NftId nftId => ObjectInfo info) private _info;
24
- mapping(address object => NftId nftId) private _nftIdByAddress;
25
- mapping(ObjectType objectType => bool) private _isValidType;
26
- mapping(ObjectType objectType => mapping(ObjectType objectParentType => bool)) private _isValidParentType;
27
-
28
- mapping(NftId nftId => string stringValue) private _string;
29
- mapping(bytes32 serviceNameHash => mapping(VersionPart majorVersion => address service)) _service;
30
-
31
- NftId private _nftId;
32
- IChainNft private _chainNft;
33
- ChainNft private _chainNftInternal;
34
- address private _initialOwner;
35
-
36
- // @dev will own protocol nft and registry nft(s) minted during initialize
37
- address private _protocolOwner;
38
-
39
- // TODO refactor once registry becomes upgradable
40
- // @Dev the protocol owner will get ownership of the
41
- // protocol nft and the global registry nft minted in this
42
- // initializer function
43
- function initialize(
44
- address chainNft,
45
- address protocolOwner
46
- )
47
- public
36
+ VersionPart internal _majorVersion;
37
+
38
+ mapping(NftId nftId => ObjectInfo info) internal _info;
39
+ mapping(address object => NftId nftId) internal _nftIdByAddress;
40
+
41
+ mapping(NftId registrator => mapping(
42
+ ObjectType objectType => bool)) internal _isApproved;
43
+
44
+ mapping(ObjectType objectType => mapping(
45
+ ObjectType parentType => bool)) internal _isValidContractCombination;
46
+
47
+ mapping(ObjectType objectType => mapping(
48
+ ObjectType parentType => bool)) internal _isValidObjectCombination;
49
+
50
+ mapping(address token => mapping(
51
+ VersionPart majorVersion => bool isActive)) internal _tokenIsActive;
52
+
53
+ mapping(NftId nftId => string name) internal _string;
54
+ mapping(bytes32 serviceNameHash => mapping(
55
+ VersionPart majorVersion => address service)) internal _service;
56
+
57
+ NftId internal _registryNftId;
58
+ NftId internal _serviceNftId; // set in stone upon registry creation
59
+ ChainNft internal _chainNft;
60
+
61
+
62
+ modifier onlyOwner() {
63
+ if(msg.sender != getOwner()) {
64
+ revert NotOwner(msg.sender);
65
+ }
66
+ _;
67
+ }
68
+
69
+ modifier onlyRegistryService() {
70
+
71
+ if(msg.sender != _info[_serviceNftId].objectAddress) {
72
+ revert NotRegistryService();
73
+ }
74
+ _;
75
+ }
76
+
77
+ constructor(address registryOwner, VersionPart majorVersion)
48
78
  {
49
- require(
50
- address(_chainNft) == address(0),
51
- "ERROR:REG-001:ALREADY_INITIALIZED"
52
- );
79
+ require(registryOwner > address(0), "Registry: registry owner is 0");
53
80
 
54
- _initialOwner = msg.sender;
55
- _protocolOwner = protocolOwner;
81
+ // major version at constructor time
82
+ _majorVersion = VersionLib.toVersionPart(GIF_MAJOR_VERSION_AT_DEPLOYMENT);
83
+ emit LogInitialMajorVersionSet(_majorVersion);
56
84
 
57
- _chainNft = IChainNft(chainNft);
58
- _chainNftInternal = ChainNft(chainNft);
85
+ // deploy NFT
86
+ _chainNft = new ChainNft(address(this));// adds 10kb to deployment size
59
87
 
60
88
  // initial registry setup
61
89
  _registerProtocol();
62
- _nftId = _registerRegistry();
90
+ _registerRegistry(registryOwner);
91
+ _registerRegistryService(registryOwner);
63
92
 
64
- // setup rules for further registrations
65
- _setupValidTypes();
66
- _setupValidParentTypes();
93
+ // set object parent relations
94
+ _setupValidObjectParentCombinations();
95
+
96
+ _registerInterface(type(IRegistry).interfaceId);
67
97
  }
68
98
 
99
+ // from IRegistry
69
100
 
70
- function register(
71
- address objectAddress
72
- )
73
- // TODO add authz (only services may register components etc)
74
- // we have to check how we do authz for registring services (just restrict to protocol owner/registry owner)
75
- external override returns (NftId nftId) {
76
- require(
77
- _nftIdByAddress[objectAddress].eqz(),
78
- "ERROR:REG-002:ALREADY_REGISTERED"
79
- );
101
+ /// @dev latest GIF release version
102
+ function setMajorVersion(VersionPart newMajorVersion)
103
+ external
104
+ onlyOwner
105
+ {
106
+ // ensure major version increments is one
107
+ uint256 oldMax = _majorVersion.toInt();
108
+ uint256 newMax = newMajorVersion.toInt();
109
+ if (newMax <= oldMax || newMax - oldMax != 1) {
110
+ revert MajorVersionMaxIncreaseInvalid(newMajorVersion, _majorVersion);
111
+ }
80
112
 
81
- IRegisterable registerable = IRegisterable(objectAddress);
82
- require(
83
- registerable.supportsInterface(type(IRegisterable).interfaceId),
84
- "ERROR:REG-003:NOT_REGISTERABLE"
85
- );
113
+ _majorVersion = newMajorVersion;
114
+ emit LogMajorVersionSet(_majorVersion);
115
+ }
86
116
 
87
- ObjectType objectType = registerable.getType();
88
- require(
89
- _isValidType[objectType],
90
- "ERROR:REG-004:TYPE_INVALID"
91
- );
117
+ /// @dev registry protects only against tampering existing records, registering with invalid types pairs and 0 parent address
118
+ // TODO service registration means its approval for some type?
119
+ // TODO registration of precompile addresses
120
+ function register(ObjectInfo memory info)
121
+ external
122
+ onlyRegistryService
123
+ returns(NftId nftId)
124
+ {
125
+ ObjectType objectType = info.objectType;
126
+ NftId parentNftId = info.parentNftId;
127
+ ObjectInfo memory parentInfo = _info[parentNftId];
128
+ ObjectType parentType = parentInfo.objectType; // see function header
129
+ address parentAddress = parentInfo.objectAddress;
130
+
131
+ // parent is contract -> need to check? -> check before minting
132
+ // special case: global registry nft as parent when not on mainnet -> global registry address is 0
133
+ // special case: when parentNftId == _chainNft.mint(), check for zero parent address before mint
134
+ // special case: when parentNftId == _chainNft.mint() && objectAddress == initialOwner
135
+ if(parentAddress == address(0)) {
136
+ revert ZeroParentAddress();
137
+ }
92
138
 
93
- NftId parentNftId = registerable.getParentNftId();
94
- require(
95
- isRegistered(parentNftId),
96
- "ERROR:REG-005:PARENT_NOT_REGISTERED"
97
- );
139
+ address interceptor = _getInterceptor(info.isInterceptor, info.objectAddress, parentInfo.isInterceptor, parentAddress);
98
140
 
99
- require(
100
- _isValidParentType[objectType][_info[parentNftId].objectType],
101
- "ERROR:REG-006:PARENT_TYPE_INVALID"
102
- );
141
+ // TODO does external call
142
+ uint256 mintedTokenId = _chainNft.mint(
143
+ info.initialOwner,
144
+ interceptor,
145
+ EMPTY_URI);
146
+ nftId = toNftId(mintedTokenId);
103
147
 
104
- // also check that nftId and parentNFtId are on the same chain if applicable
148
+ // TODO move nftId out of info struct
149
+ // getters by nftId -> return struct without nftId
150
+ // getters by address -> return nftId AND struct
151
+ info.nftId = nftId;
152
+ _info[nftId] = info;
105
153
 
106
- // nft minting
107
- uint256 mintedTokenId = _chainNft.mint(
108
- registerable.getOwner(),
109
- EMPTY_URI
110
- );
154
+ if(info.objectAddress > address(0))
155
+ {
156
+ // TODO if need to add types latter -> at least call this check from registry service
157
+ // parent is registered + object-parent types are valid
158
+ if(_isValidContractCombination[objectType][parentType] == false) {
159
+ revert InvalidTypesCombination(objectType, parentType);
160
+ }
111
161
 
112
- nftId = toNftId(mintedTokenId);
162
+ address contractAddress = info.objectAddress;
163
+
164
+ if(_nftIdByAddress[contractAddress].gtz()) {
165
+ revert ContractAlreadyRegistered(contractAddress);
166
+ }
113
167
 
114
- // special case services
115
- if(registerable.getType() == SERVICE()) {
116
- IService service = IService(objectAddress);
117
- require(
118
- service.supportsInterface(type(IService).interfaceId),
119
- "ERROR:REG-007:NOT_SERVICE"
120
- );
121
-
122
- string memory serviceName = service.getName();
123
- VersionPart majorVersion = service.getMajorVersion();
124
- bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
125
-
126
- // service specific state
127
- _string[nftId] = serviceName;
128
-
129
- require(
130
- _service[serviceNameHash][majorVersion] == address(0),
131
- "ERROR:REG-008:ALREADY_REGISTERED"
132
- );
133
- _service[serviceNameHash][majorVersion] = objectAddress;
168
+ _nftIdByAddress[contractAddress] = nftId;
169
+
170
+ // special case
171
+ if(objectType == SERVICE()) {
172
+ _registerService(info);
173
+ }
174
+ }
175
+ else
176
+ {
177
+ if(_isValidObjectCombination[objectType][parentType] == false) {
178
+ revert InvalidTypesCombination(objectType, parentType);
179
+ }
134
180
  }
135
181
 
136
- // create object info and link nft id with it
137
- _registerObjectInfo(registerable, nftId);
182
+ emit LogRegistration(info);
138
183
  }
139
184
 
140
-
141
- function registerObjectForInstance(
142
- NftId parentNftId,
143
- ObjectType objectType,
144
- address initialOwner,
145
- bytes memory data
146
- )
185
+ /// @dev token state is informative, registry have no clue about used tokens
186
+ // component owner is responsible for token selection and operations
187
+ // service MUST deny registration of component with inactive token
188
+ function setTokenActive(address token, VersionPart majorVersion, bool active)
147
189
  external
148
- override
149
- returns (
150
- // TODO add onlyRegisteredInstance
151
- NftId nftId
152
- )
190
+ onlyOwner
153
191
  {
154
- // TODO add more validation
155
- require(
156
- objectType == POLICY() || objectType == BUNDLE(),
157
- "ERROR:REG-010:TYPE_INVALID"
158
- );
192
+ // verify that token is registered
193
+ ObjectInfo memory info = _info[_nftIdByAddress[token]];
194
+ if (info.nftId.eqz()) {
195
+ revert TokenNotRegistered(token);
196
+ }
159
197
 
160
- uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
161
- nftId = toNftId(mintedTokenId);
198
+ // verify provided address is a registered token
199
+ if (info.objectType != TOKEN()) {
200
+ revert NotToken(token);
201
+ }
162
202
 
163
- ObjectInfo memory info = ObjectInfo(
164
- nftId,
165
- parentNftId,
166
- objectType,
167
- address(0),
168
- initialOwner,
169
- data
170
- );
203
+ // verify valid major version
204
+ // ensure major version increments is one
205
+ uint256 version = majorVersion.toInt();
206
+ uint256 versionNow = _majorVersion.toInt();
207
+ if (version < GIF_MAJOR_VERSION_AT_DEPLOYMENT || version > versionNow) {
208
+ revert TokenMajorVersionInvalid(majorVersion);
209
+ }
171
210
 
172
- _info[nftId] = info;
211
+ _tokenIsActive[token][majorVersion] = active;
212
+
213
+ emit LogTokenStateSet(token, majorVersion, active);
214
+ }
173
215
 
174
- // add logging
216
+ /// @dev earliest GIF major version
217
+ function getMajorVersionMin() external view returns (VersionPart) {
218
+ return VersionLib.toVersionPart(GIF_MAJOR_VERSION_AT_DEPLOYMENT);
175
219
  }
176
220
 
221
+ // TODO make distinction between active an not yet active version
222
+ // need to be thought trough, not yet clear if necessary
223
+ // need to answer question: what is the latest version during the upgrade process?
224
+ // likely setting up a new gif version does not fit into a single tx
225
+ // in this case we might want to have a period where the latest version is
226
+ // in the process of being set up while the latest active version is 1 major release smaller
227
+ /// @dev latest GIF major version (might not yet be active)
228
+ function getMajorVersionMax() external view returns (VersionPart) {
229
+ return _majorVersion;
230
+ }
231
+
232
+ /// @dev latest active GIF release version
233
+ function getMajorVersion() external view returns (VersionPart) {
234
+ return _majorVersion;
235
+ }
236
+
237
+
177
238
  function getObjectCount() external view override returns (uint256) {
178
239
  return _chainNft.totalSupply();
179
240
  }
180
241
 
181
- function getNftId(
182
- address object
183
- ) external view override returns (NftId id) {
242
+ function getNftId() external view returns (NftId nftId) {
243
+ return _registryNftId;
244
+ }
245
+
246
+ function getNftId(address object) external view override returns (NftId id) {
184
247
  return _nftIdByAddress[object];
185
248
  }
186
249
 
187
- function isRegistered(
188
- NftId nftId
189
- ) public view override returns (bool) {
190
- return _info[nftId].objectType.gtz();
250
+ function ownerOf(NftId nftId) public view override returns (address) {
251
+ return _chainNft.ownerOf(nftId.toInt());
191
252
  }
192
253
 
193
- function isRegistered(
194
- address object
195
- ) external view override returns (bool) {
196
- return _nftIdByAddress[object].gtz();
254
+ function ownerOf(address contractAddress) public view returns (address) {
255
+
256
+ return _chainNft.ownerOf(_nftIdByAddress[contractAddress].toInt());
197
257
  }
198
258
 
199
- function getObjectInfo(
200
- NftId nftId
201
- ) external view override returns (ObjectInfo memory info) {
259
+ function getObjectInfo(NftId nftId) external view override returns (ObjectInfo memory) {
202
260
  return _info[nftId];
203
261
  }
204
262
 
205
- function getName(
206
- NftId nftId
207
- ) external view returns (string memory name) {
208
- return _string[nftId];
263
+ function getObjectInfo(address object) external view override returns (ObjectInfo memory) {
264
+
265
+ return _info[_nftIdByAddress[object]];
209
266
  }
210
267
 
211
- function getOwner(NftId nftId) external view override returns (address) {
212
- return _chainNft.ownerOf(nftId.toInt());
268
+ function isRegistered(NftId nftId) public view override returns (bool) {
269
+ return _info[nftId].objectType.gtz();
213
270
  }
214
271
 
215
- function getChainNft() external view override returns (IChainNft) {
216
- return _chainNft;
272
+ function isRegistered(address object) external view override returns (bool) {
273
+ return _nftIdByAddress[object].gtz();
274
+ }
275
+
276
+ function isTokenActive(address token, VersionPart majorVersion) external view returns (bool) {
277
+ return _tokenIsActive[token][majorVersion];
278
+ }
279
+
280
+ function getServiceName(NftId nftId) external view returns (string memory) {
281
+ return _string[nftId];
217
282
  }
218
283
 
219
284
  // special case to retrive a gif service
220
- function getServiceAddress(string memory serviceName, VersionPart majorVersion) external view override returns (address serviceAddress) {
285
+ function getServiceAddress(
286
+ string memory serviceName,
287
+ VersionPart majorVersion
288
+ ) external view returns (address)
289
+ {
221
290
  bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
222
291
  return _service[serviceNameHash][majorVersion];
223
292
  }
224
293
 
225
- // from IERC165
226
- function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
227
- return interfaceId == type(IRegistry).interfaceId;
294
+ function getChainNft() external view override returns (ChainNft) {
295
+ return _chainNft;
228
296
  }
229
297
 
230
- // from IRegistryLinked
231
- function getRegistry() external view override returns (IRegistry registry) {
232
- return this;
298
+ function getOwner() public view returns (address owner) {
299
+ return ownerOf(address(this));
233
300
  }
234
301
 
235
- // from IRegisterable
236
- function register() external pure override returns (NftId nftId) {
237
- return zeroNftId();
238
- }
302
+ // Internals
239
303
 
240
- function getType() external pure override returns (ObjectType objectType) {
241
- return REGISTRY();
242
- }
304
+ function _registerService(ObjectInfo memory info)
305
+ internal
306
+ {
307
+ (
308
+ string memory serviceName,
309
+ VersionPart majorVersion
310
+ ) = abi.decode(info.data, (string, VersionPart));
311
+ bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
243
312
 
313
+ // ensures consistency of service.getVersion() and majorVersion here
314
+ if(majorVersion != _majorVersion) {
315
+ revert InvalidServiceVersion(majorVersion);
316
+ }
317
+
318
+ if(_service[serviceNameHash][majorVersion] != address(0)) {
319
+ revert ServiceNameAlreadyRegistered(serviceName, majorVersion);
320
+ }
244
321
 
245
- function getOwner() public view override returns (address owner) {
246
- return _nftId.gtz() ? this.getOwner(_nftId) : _initialOwner;
247
- }
322
+ _string[info.nftId] = serviceName;
323
+ _service[serviceNameHash][majorVersion] = info.objectAddress;
248
324
 
249
- function getNftId() external view override (IRegisterable, IRegistry) returns (NftId nftId) {
250
- return _nftId;
325
+ emit LogServiceNameRegistration(serviceName, majorVersion);
251
326
  }
252
327
 
253
- function getParentNftId() external view returns (NftId nftId) {
254
- // we're the global registry
255
- if(block.chainid == 1) {
256
- return toNftId(_chainNftInternal.PROTOCOL_NFT_ID());
328
+ /// @dev obtain interceptor address for this nft if applicable, address(0) otherwise
329
+ function _getInterceptor(
330
+ bool isInterceptor,
331
+ address objectAddress,
332
+ bool parentIsInterceptor,
333
+ address parentObjectAddress
334
+ )
335
+ internal
336
+ view
337
+ returns (address interceptor)
338
+ {
339
+ if (objectAddress == address(0)) {
340
+ if (parentIsInterceptor) {
341
+ return parentObjectAddress;
342
+ } else {
343
+ return address(0);
344
+ }
257
345
  }
258
- else {
259
- return toNftId(_chainNftInternal.GLOBAL_REGISTRY_ID());
346
+
347
+ if (isInterceptor) {
348
+ return objectAddress;
260
349
  }
261
- }
262
350
 
263
- function getData() external pure returns (bytes memory data) {
264
- return "";
351
+ return address(0);
265
352
  }
266
353
 
267
- // registry specific functions
268
- function getProtocolOwner() external view override returns (address) {
269
- return _protocolOwner;
270
- }
354
+ // Internals called only in constructor
271
355
 
272
- /// @dev defines which types are allowed to register
273
- function _setupValidTypes() internal {
274
- _isValidType[REGISTRY()] = true; // only for global registry
275
- _isValidType[TOKEN()] = true;
276
- _isValidType[SERVICE()] = true;
277
- _isValidType[INSTANCE()] = true;
278
- _isValidType[STAKE()] = true;
279
- _isValidType[PRODUCT()] = true;
280
- _isValidType[ORACLE()] = true;
281
- _isValidType[POOL()] = true;
282
- _isValidType[DISTRIBUTION()] = true;
283
- _isValidType[POLICY()] = true;
284
- _isValidType[BUNDLE()] = true;
285
- }
356
+ /// @dev protocol registration used to anchor the dip ecosystem relations
357
+ function _registerProtocol()
358
+ internal
359
+ {
360
+ uint256 protocolId = _chainNft.PROTOCOL_NFT_ID();
361
+ NftId protocolNftId = toNftId(protocolId);
286
362
 
287
- /// @dev defines which types - parent type relations are allowed to register
288
- function _setupValidParentTypes() internal {
289
- // registry as parent
290
- _isValidParentType[TOKEN()][REGISTRY()] = true;
291
- _isValidParentType[SERVICE()][REGISTRY()] = true;
292
- _isValidParentType[INSTANCE()][REGISTRY()] = true;
293
-
294
- // instance as parent
295
- _isValidParentType[PRODUCT()][INSTANCE()] = true;
296
- _isValidParentType[DISTRIBUTION()][INSTANCE()] = true;
297
- _isValidParentType[ORACLE()][INSTANCE()] = true;
298
- _isValidParentType[POOL()][INSTANCE()] = true;
299
-
300
- // product as parent
301
- _isValidParentType[POLICY()][PRODUCT()] = true;
302
-
303
- // pool as parent
304
- _isValidParentType[BUNDLE()][POOL()] = true;
305
- _isValidParentType[STAKE()][POOL()] = true;
306
- }
363
+ _chainNft.mint(NFT_LOCK_ADDRESS, protocolId);
307
364
 
308
- /// @dev protocol registration used to anchor the dip ecosystem relations
309
- function _registerProtocol() virtual internal {
310
- uint256 protocolId = _chainNftInternal.PROTOCOL_NFT_ID();
311
- _chainNftInternal.mint(_protocolOwner, protocolId);
312
-
313
- NftId protocolNftid = toNftId(protocolId);
314
- ObjectInfo memory protocolInfo = ObjectInfo(
315
- protocolNftid,
316
- zeroNftId(), // parent nft id
365
+ _info[protocolNftId] = ObjectInfo(
366
+ protocolNftId,
367
+ zeroNftId(), // parent
317
368
  PROTOCOL(),
318
- address(0), // contract address
319
- _protocolOwner,
320
- "" // data
369
+ false, // isInterceptor
370
+ address(0), // objectAddress
371
+ NFT_LOCK_ADDRESS,// initialOwner
372
+ ""
321
373
  );
322
-
323
- _info[protocolNftid] = protocolInfo;
324
374
  }
325
375
 
326
376
  /// @dev registry registration
327
377
  /// might also register the global registry when not on mainnet
328
- function _registerRegistry() virtual internal returns (NftId registryNftId) {
329
- uint256 registryId = _chainNftInternal.calculateTokenId(2);
330
- registryNftId = toNftId(registryId);
378
+ function _registerRegistry(address registryOwner)
379
+ internal
380
+ {
381
+ uint256 registryId = _chainNft.calculateTokenId(2);
382
+ NftId registryNftId = toNftId(registryId);
383
+
384
+ NftId parentNftId;
331
385
 
332
- // we're not the global registry
333
- if(registryId != _chainNftInternal.GLOBAL_REGISTRY_ID()) {
386
+ if(registryId != _chainNft.GLOBAL_REGISTRY_ID())
387
+ {// we're not the global registry
334
388
  _registerGlobalRegistry();
389
+ parentNftId = toNftId(_chainNft.GLOBAL_REGISTRY_ID());
335
390
  }
391
+ else
392
+ {// we are global registry
393
+ parentNftId = toNftId(_chainNft.PROTOCOL_NFT_ID());
394
+ }
395
+
396
+ _chainNft.mint(registryOwner, registryId);
336
397
 
337
- _chainNftInternal.mint(_protocolOwner, registryId);
338
- _registerObjectInfo(this, registryNftId);
398
+ _info[registryNftId] = ObjectInfo(
399
+ registryNftId,
400
+ parentNftId,
401
+ REGISTRY(),
402
+ false, // isInterceptor
403
+ address(this),
404
+ registryOwner,
405
+ ""
406
+ );
407
+ _nftIdByAddress[address(this)] = registryNftId;
408
+ _registryNftId = registryNftId;
339
409
  }
340
410
 
341
411
 
342
412
  /// @dev global registry registration for non mainnet registries
343
- function _registerGlobalRegistry() virtual internal {
344
- uint256 globalRegistryId = _chainNftInternal.GLOBAL_REGISTRY_ID();
345
- _chainNftInternal.mint(_protocolOwner, globalRegistryId);
413
+ function _registerGlobalRegistry()
414
+ internal
415
+ {
416
+ uint256 globalRegistryId = _chainNft.GLOBAL_REGISTRY_ID();
417
+
418
+ _chainNft.mint(NFT_LOCK_ADDRESS, globalRegistryId);
346
419
 
347
420
  NftId globalRegistryNftId = toNftId(globalRegistryId);
348
- ObjectInfo memory globalRegistryInfo = ObjectInfo(
421
+
422
+ _info[globalRegistryNftId] = ObjectInfo(
349
423
  globalRegistryNftId,
350
- toNftId(_chainNftInternal.PROTOCOL_NFT_ID()),
424
+ toNftId(_chainNft.PROTOCOL_NFT_ID()), // parent
351
425
  REGISTRY(),
352
- address(0), // contract address
353
- _protocolOwner,
426
+ false, // isInterceptor
427
+ address(0), // objectAddress
428
+ NFT_LOCK_ADDRESS, // initialOwner
354
429
  "" // data
355
430
  );
356
-
357
- _info[globalRegistryNftId] = globalRegistryInfo;
358
431
  }
359
432
 
360
-
361
- function _registerObjectInfo(
362
- IRegisterable registerable,
363
- NftId nftId
364
- ) internal virtual {
365
- address objectAddress = address(registerable);
366
- ObjectInfo memory info = ObjectInfo(
367
- nftId,
368
- registerable.getParentNftId(),
369
- registerable.getType(),
370
- objectAddress,
371
- registerable.getOwner(),
372
- registerable.getData()
433
+ function _registerRegistryService(address registryOwner)
434
+ internal
435
+ {
436
+ uint256 serviceId = _chainNft.calculateTokenId(REGISTRY_SERVICE_TOKEN_SEQUENCE_ID);
437
+ NftId serviceNftId = toNftId(serviceId);
438
+
439
+ _chainNft.mint(registryOwner, serviceId);
440
+
441
+ _info[serviceNftId] = ObjectInfo(
442
+ serviceNftId,
443
+ _registryNftId,
444
+ SERVICE(),
445
+ false, // isInterceptor
446
+ msg.sender, // service deploys registry
447
+ registryOwner, // initialOwner,
448
+ ""
373
449
  );
374
450
 
375
- _info[nftId] = info;
376
- _nftIdByAddress[objectAddress] = nftId;
451
+ _nftIdByAddress[msg.sender] = serviceNftId;
377
452
 
378
- // add logging
453
+ string memory serviceName = "RegistryService";
454
+ bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
455
+ _service[serviceNameHash][VersionLib.toVersionPart(GIF_MAJOR_VERSION_AT_DEPLOYMENT)] = msg.sender;
456
+ _string[serviceNftId] = serviceName;
457
+ _serviceNftId = serviceNftId;
379
458
  }
380
459
 
460
+ /// @dev defines which object - parent types relations are allowed to register
461
+ // IMPORTANT:
462
+ // 1) EACH object type MUST have only one parent type across ALL mappings
463
+ // 2) DO NOT use object type (e.g. POLCY, BUNDLE, STAKE) as parent type
464
+ // 3) DO NOT use REGISTRY as object type
465
+ // 2) DO NOT use PROTOCOL and "zeroObjectType"
466
+ function _setupValidObjectParentCombinations()
467
+ internal
468
+ {
469
+ // registry as parent, ONLY registry owner
470
+ _isValidContractCombination[TOKEN()][REGISTRY()] = true;
471
+ _isValidContractCombination[SERVICE()][REGISTRY()] = true;
472
+
473
+ // registry as parent, ONLY approved
474
+ _isValidContractCombination[INSTANCE()][REGISTRY()] = true;
475
+
476
+ // instance as parent, ONLY approved
477
+ _isValidContractCombination[PRODUCT()][INSTANCE()] = true;
478
+ _isValidContractCombination[DISTRIBUTION()][INSTANCE()] = true;
479
+ _isValidContractCombination[ORACLE()][INSTANCE()] = true;
480
+ _isValidContractCombination[POOL()][INSTANCE()] = true;
481
+
482
+ // product as parent, ONLY approved
483
+ _isValidObjectCombination[POLICY()][PRODUCT()] = true;
484
+
485
+ // pool as parent, ONLY approved
486
+ _isValidObjectCombination[BUNDLE()][POOL()] = true;
487
+ _isValidObjectCombination[STAKE()][POOL()] = true;
488
+ }
381
489
  }