@etherisc/gif-next 0.0.2-a04040f-684 → 0.0.2-a196164-289

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +145 -6
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +4 -0
  3. package/artifacts/contracts/components/{Component.sol/Component.json → BaseComponent.sol/BaseComponent.json} +26 -57
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +405 -0
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +4 -0
  7. package/artifacts/contracts/{instance/component/IComponent.sol/IComponentContract.json → components/IBaseComponent.sol/IBaseComponent.json} +26 -57
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/{IPool.sol/IPoolComponent.json → IDistributionComponent.sol/IDistributionComponent.json} +162 -77
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +4 -0
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +487 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +4 -0
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +370 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +290 -40
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +167 -69
  18. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
  34. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  36. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1177 -608
  40. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +4 -0
  41. package/artifacts/contracts/instance/{component/IComponent.sol → IInstanceLinked.sol}/IInstanceLinked.json +1 -1
  42. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  43. package/artifacts/contracts/instance/Instance.sol/Instance.json +1512 -765
  44. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +4 -0
  45. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +387 -0
  46. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  47. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +113 -0
  48. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +4 -0
  49. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +560 -0
  50. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  51. package/artifacts/contracts/instance/{lifecycle/ILifecycle.sol/ILifecycleModule.json → base/ILifecycle.sol/ILifecycle.json} +10 -77
  52. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +4 -0
  53. package/artifacts/contracts/instance/{component/ComponentModule.sol/ComponentModule.json → base/IService.sol/IService.json} +167 -125
  54. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  55. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +463 -0
  56. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +4 -0
  57. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +710 -0
  58. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +4 -0
  59. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +169 -0
  60. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +4 -0
  61. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.json +10 -0
  62. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +4 -0
  63. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.json +387 -0
  64. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +4 -0
  65. package/artifacts/contracts/instance/{access → module/access}/Access.sol/AccessModule.json +85 -152
  66. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +4 -0
  67. package/artifacts/contracts/instance/{access → module/access}/IAccess.sol/IAccess.json +1 -1
  68. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  69. package/artifacts/contracts/instance/{access → module/access}/IAccess.sol/IAccessModule.json +96 -99
  70. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +297 -0
  72. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +4 -0
  73. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.json +10 -0
  74. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +4 -0
  75. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +297 -0
  76. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  77. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +117 -0
  78. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +4 -0
  79. package/artifacts/contracts/instance/{component → module/component}/IComponent.sol/IComponent.json +1 -1
  80. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  81. package/artifacts/contracts/instance/{product/IProductService.sol/IProductService.json → module/component/IComponent.sol/IComponentModule.json} +51 -61
  82. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.dbg.json +4 -0
  83. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.json +10 -0
  84. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.dbg.json +4 -0
  85. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.json +10 -0
  86. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.dbg.json +4 -0
  87. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.json +10 -0
  88. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  89. package/artifacts/contracts/instance/{policy → module/policy}/IPolicy.sol/IPolicy.json +1 -1
  90. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  91. package/artifacts/contracts/instance/{policy → module/policy}/IPolicy.sol/IPolicyModule.json +147 -117
  92. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  93. package/artifacts/contracts/instance/{policy → module/policy}/PolicyModule.sol/PolicyModule.json +148 -118
  94. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  95. package/artifacts/contracts/instance/{pool → module/pool}/IPoolModule.sol/IPool.json +1 -1
  96. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  97. package/artifacts/contracts/instance/{pool → module/pool}/IPoolModule.sol/IPoolModule.json +67 -52
  98. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  99. package/artifacts/contracts/instance/{pool → module/pool}/PoolModule.sol/PoolModule.json +51 -62
  100. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +4 -0
  101. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.json +10 -0
  102. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +4 -0
  103. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +113 -0
  104. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +4 -0
  105. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +131 -0
  106. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  107. package/artifacts/contracts/instance/{treasury → module/treasury}/ITreasury.sol/ITreasury.json +1 -1
  108. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  109. package/artifacts/contracts/instance/{treasury → module/treasury}/ITreasury.sol/ITreasuryModule.json +278 -257
  110. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  111. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +76 -0
  112. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  113. package/artifacts/contracts/instance/{treasury → module/treasury}/TreasuryModule.sol/TreasuryModule.json +278 -257
  114. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +4 -0
  115. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +618 -0
  116. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  117. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +507 -0
  118. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +4 -0
  119. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +405 -0
  120. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  121. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +366 -0
  122. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +4 -0
  123. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +481 -0
  124. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +4 -0
  125. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +671 -0
  126. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  127. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +630 -0
  128. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  129. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +945 -0
  130. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  131. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +65 -2
  132. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  133. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  134. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +147 -30
  135. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +4 -0
  136. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.json +24 -0
  137. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  138. package/artifacts/contracts/registry/Registry.sol/Registry.json +241 -25
  139. package/artifacts/contracts/registry/RegistryUpgradeable.sol/RegistryUpgradeable.dbg.json +4 -0
  140. package/artifacts/contracts/registry/RegistryUpgradeable.sol/RegistryUpgradeable.json +711 -0
  141. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +4 -0
  142. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +35 -0
  143. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +4 -0
  144. package/artifacts/contracts/{registry/IRegistry.sol → shared/IOwnable.sol}/IOwnable.json +1 -1
  145. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +4 -0
  146. package/artifacts/contracts/{registry/IRegistry.sol → shared/IRegisterable.sol}/IRegisterable.json +16 -61
  147. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +4 -0
  148. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +205 -0
  149. package/artifacts/contracts/shared/Proxy.sol/Proxy.dbg.json +4 -0
  150. package/artifacts/contracts/shared/Proxy.sol/Proxy.json +235 -0
  151. package/artifacts/contracts/shared/Proxy.sol/ProxyWithProxyAdminGetter.dbg.json +4 -0
  152. package/artifacts/contracts/shared/Proxy.sol/ProxyWithProxyAdminGetter.json +129 -0
  153. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +4 -0
  154. package/artifacts/contracts/{registry/Registry.sol → shared/Registerable.sol}/Registerable.json +16 -61
  155. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +4 -0
  156. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +251 -0
  157. package/artifacts/contracts/shared/VersionableUpgradeable.sol/VersionableUpgradeable.dbg.json +4 -0
  158. package/artifacts/contracts/shared/VersionableUpgradeable.sol/VersionableUpgradeable.json +228 -0
  159. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.dbg.json +4 -0
  160. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.json +405 -0
  161. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +4 -0
  162. package/artifacts/contracts/test/TestFee.sol/TestFee.json +119 -0
  163. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +4 -0
  164. package/artifacts/contracts/test/TestPool.sol/TestPool.json +578 -0
  165. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +4 -0
  166. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +575 -0
  167. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +4 -0
  168. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +137 -0
  169. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +4 -0
  170. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +116 -0
  171. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +4 -0
  172. package/artifacts/contracts/test/TestService.sol/TestService.json +466 -0
  173. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +4 -0
  174. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +338 -0
  175. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +4 -0
  176. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +218 -0
  177. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +4 -0
  178. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +293 -0
  179. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +4 -0
  180. package/artifacts/contracts/{mock → test}/Usdc.sol/USDC.json +3 -3
  181. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +4 -0
  182. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.json +10 -0
  183. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  185. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +4 -0
  186. package/artifacts/contracts/types/Fee.sol/FeeLib.json +257 -0
  187. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +4 -0
  188. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +111 -0
  189. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +65 -4
  191. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +4 -0
  192. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +10 -0
  193. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  194. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  195. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.dbg.json +4 -0
  196. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.json +99 -0
  197. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  198. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  199. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
  200. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +30 -0
  201. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  202. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  203. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  204. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +64 -2
  205. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  206. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +58 -58
  207. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +4 -0
  208. package/artifacts/contracts/types/Version.sol/VersionLib.json +177 -0
  209. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +4 -0
  210. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +30 -0
  211. package/contracts/components/BaseComponent.sol +94 -0
  212. package/contracts/components/Distribution.sol +132 -0
  213. package/contracts/components/IBaseComponent.sol +19 -0
  214. package/contracts/components/IDistributionComponent.sol +47 -0
  215. package/contracts/components/IPoolComponent.sol +71 -0
  216. package/contracts/components/IProductComponent.sol +38 -0
  217. package/contracts/components/Pool.sol +199 -16
  218. package/contracts/components/Product.sol +169 -31
  219. package/contracts/instance/IInstance.sol +39 -11
  220. package/contracts/instance/IInstanceLinked.sol +8 -0
  221. package/contracts/instance/Instance.sol +51 -49
  222. package/contracts/instance/base/ComponentServiceBase.sol +42 -0
  223. package/contracts/instance/base/IInstanceBase.sol +22 -0
  224. package/contracts/instance/base/IKeyValueStore.sol +50 -0
  225. package/contracts/instance/{lifecycle → base}/ILifecycle.sol +4 -21
  226. package/contracts/instance/base/IService.sol +15 -0
  227. package/contracts/instance/base/InstanceBase.sol +91 -0
  228. package/contracts/instance/base/KeyValueStore.sol +161 -0
  229. package/contracts/instance/base/Lifecycle.sol +100 -0
  230. package/contracts/instance/base/ModuleBase.sol +57 -0
  231. package/contracts/instance/base/ServiceBase.sol +37 -0
  232. package/contracts/instance/module/access/Access.sol +149 -0
  233. package/contracts/instance/module/access/IAccess.sol +53 -0
  234. package/contracts/instance/module/bundle/BundleModule.sol +134 -0
  235. package/contracts/instance/module/bundle/IBundle.sol +53 -0
  236. package/contracts/instance/module/component/ComponentModule.sol +70 -0
  237. package/contracts/instance/module/component/IComponent.sol +28 -0
  238. package/contracts/instance/module/distribution/DistributionModule.sol +17 -0
  239. package/contracts/instance/module/distribution/IDistribution.sol +10 -0
  240. package/contracts/instance/module/policy/IPolicy.sol +63 -0
  241. package/contracts/instance/module/policy/PolicyModule.sol +91 -0
  242. package/contracts/instance/module/pool/IPoolModule.sol +40 -0
  243. package/contracts/instance/module/pool/PoolModule.sol +90 -0
  244. package/contracts/instance/module/risk/IRisk.sol +26 -0
  245. package/contracts/instance/module/risk/RiskModule.sol +62 -0
  246. package/contracts/instance/module/treasury/ITreasury.sol +82 -0
  247. package/contracts/instance/module/treasury/TokenHandler.sol +48 -0
  248. package/contracts/instance/module/treasury/TreasuryModule.sol +138 -0
  249. package/contracts/instance/service/ComponentOwnerService.sol +157 -0
  250. package/contracts/instance/service/DistributionService.sol +59 -0
  251. package/contracts/instance/service/IComponentOwnerService.sol +22 -0
  252. package/contracts/instance/service/IDistributionService.sol +12 -0
  253. package/contracts/instance/service/IPoolService.sol +37 -0
  254. package/contracts/instance/service/IProductService.sol +107 -0
  255. package/contracts/instance/service/PoolService.sol +149 -0
  256. package/contracts/instance/service/ProductService.sol +509 -0
  257. package/contracts/registry/ChainNft.sol +61 -37
  258. package/contracts/registry/IRegistry.sol +24 -34
  259. package/contracts/registry/IRegistryLinked.sol +8 -0
  260. package/contracts/registry/Registry.sol +285 -86
  261. package/contracts/registry/RegistryUpgradeable.sol +548 -0
  262. package/contracts/shared/ERC165.sol +21 -0
  263. package/contracts/shared/IOwnable.sol +6 -0
  264. package/contracts/shared/IRegisterable.sol +24 -0
  265. package/contracts/shared/IVersionable.sol +65 -0
  266. package/contracts/shared/Proxy.sol +89 -0
  267. package/contracts/shared/Registerable.sol +86 -0
  268. package/contracts/shared/Versionable.sol +99 -0
  269. package/contracts/shared/VersionableUpgradeable.sol +120 -0
  270. package/contracts/test/TestDistribution.sol +21 -0
  271. package/contracts/test/TestFee.sol +25 -0
  272. package/contracts/test/TestPool.sol +25 -0
  273. package/contracts/test/TestProduct.sol +72 -0
  274. package/contracts/test/TestRegisterable.sol +19 -0
  275. package/contracts/test/TestRoleId.sol +14 -0
  276. package/contracts/test/TestService.sol +32 -0
  277. package/contracts/{mock/Dip.sol → test/TestToken.sol} +5 -5
  278. package/contracts/test/TestVersion.sol +44 -0
  279. package/contracts/test/TestVersionable.sol +17 -0
  280. package/contracts/{mock → test}/Usdc.sol +1 -1
  281. package/contracts/types/AddressSet.sol +58 -0
  282. package/contracts/types/Fee.sol +44 -20
  283. package/contracts/types/Key32.sol +45 -0
  284. package/contracts/types/NftId.sol +22 -1
  285. package/contracts/types/NftIdSet.sol +60 -0
  286. package/contracts/types/ObjectType.sol +37 -13
  287. package/contracts/types/ReferralId.sol +48 -0
  288. package/contracts/types/RiskId.sol +43 -0
  289. package/contracts/types/RoleId.sol +38 -0
  290. package/contracts/types/StateId.sol +13 -3
  291. package/contracts/types/Timestamp.sol +22 -1
  292. package/contracts/types/UFixed.sol +12 -13
  293. package/contracts/types/Version.sol +103 -0
  294. package/package.json +8 -3
  295. package/artifacts/contracts/components/Component.sol/Component.dbg.json +0 -4
  296. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +0 -4
  297. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +0 -35
  298. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +0 -4
  299. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +0 -4
  300. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +0 -74
  301. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +0 -4
  302. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +0 -4
  303. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +0 -4
  304. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +0 -35
  305. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +0 -4
  306. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +0 -50
  307. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +0 -4
  308. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +0 -4
  309. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +0 -4
  310. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +0 -202
  311. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +0 -4
  312. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +0 -4
  313. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +0 -4
  314. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +0 -217
  315. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +0 -4
  316. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +0 -141
  317. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +0 -4
  318. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +0 -4
  319. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +0 -134
  320. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +0 -4
  321. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +0 -4
  322. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +0 -221
  323. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +0 -4
  324. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +0 -4
  325. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +0 -4
  326. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +0 -4
  327. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +0 -4
  328. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +0 -4
  329. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +0 -4
  330. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +0 -75
  331. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +0 -4
  332. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +0 -4
  333. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +0 -75
  334. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +0 -4
  335. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +0 -196
  336. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +0 -4
  337. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +0 -4
  338. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +0 -4
  339. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +0 -45
  340. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +0 -4
  341. package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +0 -4
  342. package/artifacts/contracts/mock/Dip.sol/DIP.json +0 -338
  343. package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +0 -4
  344. package/artifacts/contracts/mock/TestPool.sol/TestPool.json +0 -294
  345. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +0 -4
  346. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +0 -384
  347. package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +0 -4
  348. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +0 -4
  349. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +0 -4
  350. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +0 -4
  351. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +0 -49
  352. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +0 -4
  353. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +0 -4
  354. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +0 -60
  355. package/contracts/components/Component.sol +0 -77
  356. package/contracts/components/IPool.sol +0 -15
  357. package/contracts/components/IProduct.sol +0 -16
  358. package/contracts/instance/access/Access.sol +0 -165
  359. package/contracts/instance/access/IAccess.sol +0 -63
  360. package/contracts/instance/component/ComponentModule.sol +0 -274
  361. package/contracts/instance/component/IComponent.sol +0 -74
  362. package/contracts/instance/lifecycle/LifecycleModule.sol +0 -88
  363. package/contracts/instance/policy/IPolicy.sol +0 -50
  364. package/contracts/instance/policy/PolicyModule.sol +0 -114
  365. package/contracts/instance/pool/IPoolModule.sol +0 -23
  366. package/contracts/instance/pool/PoolModule.sol +0 -81
  367. package/contracts/instance/product/IProductService.sol +0 -36
  368. package/contracts/instance/product/ProductService.sol +0 -136
  369. package/contracts/instance/treasury/ITreasury.sol +0 -91
  370. package/contracts/instance/treasury/TokenHandler.sol +0 -24
  371. package/contracts/instance/treasury/TreasuryModule.sol +0 -168
  372. package/contracts/mock/TestPool.sol +0 -16
  373. package/contracts/mock/TestProduct.sol +0 -39
@@ -0,0 +1,548 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Initializable} from "@openzeppelin5/contracts/proxy/utils/Initializable.sol";
5
+
6
+ import {IRegisterable} from "../shared/IRegisterable.sol";
7
+ import {IService} from "../instance/base/IService.sol";
8
+
9
+ import {IChainNft} from "./IChainNft.sol";
10
+ import {ChainNft} from "./ChainNft.sol";
11
+ import {IRegistry} from "./IRegistry.sol";
12
+ import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
13
+ import {Version, VersionPart, VersionLib} from "../types/Version.sol";
14
+ import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, DISTRIBUTION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
15
+
16
+ import {VersionableUpgradeable} from "../shared/VersionableUpgradeable.sol";
17
+
18
+
19
+ /// IMPORTANT
20
+ // Upgradeable contract MUST:
21
+ // 1) inherit from Versionable
22
+ // 2) implement version() function
23
+ // 3) implement initialize() function with initializer modifier
24
+ // 4) implement upgrade() function with reinitializer(version().toInt()) modifier
25
+ // 5) have onlyInitialising modifier for each function callable during deployment and/or upgrade
26
+ // 6) use default empty constructor -> _disableInitializer() called from Versionable contructor
27
+ // 7) use namespace storage
28
+ contract RegistryUpgradeable is
29
+ VersionableUpgradeable,
30
+ IRegisterable,
31
+ IRegistry
32
+ {
33
+ //--- constants -----------------------------------------------------------------
34
+ string public constant EMPTY_URI = "";
35
+
36
+ // keccak256(abi.encode(uint256(keccak256("etherisc.storage.Registry")) - 1)) & ~bytes32(uint256(0xff));
37
+ bytes32 internal constant STORAGE_LOCATION_V1 = 0x6548007c3f4340f82f348c576c0ff69f4f529cadd5ad41f96aae61abceeaa300;
38
+
39
+ //--- storage layout -------------------------------------------------------------
40
+
41
+ // @custom:storage-location erc7201:etherisc.storage.Registry
42
+ struct StorageV1 {
43
+ mapping(NftId nftId => ObjectInfo info) info;
44
+ mapping(address object => NftId nftId) nftIdByAddress;
45
+ mapping(ObjectType objectType => bool) isValidType;
46
+ mapping(ObjectType objectType => mapping(ObjectType objectParentType => bool)) isValidParentType;
47
+
48
+ mapping(NftId nftId => string stringValue) name;
49
+ mapping(bytes32 serviceNameHash => mapping(VersionPart majorVersion => address service)) service;
50
+
51
+ NftId nftId;
52
+ IChainNft chainNft;
53
+ ChainNft chainNftInternal;
54
+ address initialOwner;
55
+ /// @dev will own protocol nft and registry nft(s) minted during initialize
56
+ address _protocolOwner;
57
+ }
58
+
59
+ //--- state --------------------------------------------------------------------
60
+
61
+ //--- external/public state changing functions --------------------------------
62
+
63
+ function register(
64
+ address objectAddress
65
+ )
66
+ // TODO add authz (only services may register components etc)
67
+ // we have to check how we do authz for registring services (just restrict to protocol owner/registry owner)
68
+ external
69
+ virtual override
70
+ returns (NftId nftId)
71
+ {
72
+ StorageV1 storage $ = _getStorageV1();
73
+
74
+ require(
75
+ $.nftIdByAddress[objectAddress].eqz(),
76
+ "ERROR:REG-002:ALREADY_REGISTERED"
77
+ );
78
+
79
+ IRegisterable registerable = IRegisterable(objectAddress);
80
+ require(
81
+ registerable.supportsInterface(type(IRegisterable).interfaceId),
82
+ "ERROR:REG-003:NOT_REGISTERABLE"
83
+ );
84
+
85
+ ObjectType objectType = registerable.getType();
86
+ require(
87
+ $.isValidType[objectType],
88
+ "ERROR:REG-004:TYPE_INVALID"
89
+ );
90
+
91
+ NftId parentNftId = registerable.getParentNftId();
92
+ require(
93
+ isRegistered(parentNftId),
94
+ "ERROR:REG-005:PARENT_NOT_REGISTERED"
95
+ );
96
+
97
+ require(
98
+ $.isValidParentType[objectType][$.info[parentNftId].objectType],
99
+ "ERROR:REG-006:PARENT_TYPE_INVALID"
100
+ );
101
+
102
+ // also check that nftId and parentNFtId are on the same chain if applicable
103
+
104
+ // nft minting
105
+ uint256 mintedTokenId = $.chainNft.mint(
106
+ registerable.getOwner(),
107
+ EMPTY_URI
108
+ );
109
+
110
+ nftId = toNftId(mintedTokenId);
111
+
112
+ // special case services
113
+ if(registerable.getType() == SERVICE()) {
114
+ IService service = IService(objectAddress);
115
+ require(
116
+ service.supportsInterface(type(IService).interfaceId),
117
+ "ERROR:REG-007:NOTservice"
118
+ );
119
+
120
+ string memory serviceName = service.getName();
121
+ VersionPart majorVersion = service.getMajorVersion();
122
+ bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
123
+
124
+ // service specific state
125
+ $.name[nftId] = serviceName;
126
+
127
+ require(
128
+ $.service[serviceNameHash][majorVersion] == address(0),
129
+ "ERROR:REG-008:ALREADY_REGISTERED"
130
+ );
131
+ $.service[serviceNameHash][majorVersion] = objectAddress;
132
+ }
133
+
134
+ // create object info and link nft id with it
135
+ _registerObjectInfo(registerable, nftId);
136
+ }
137
+
138
+
139
+ function registerObjectForInstance(
140
+ NftId parentNftId,
141
+ ObjectType objectType,
142
+ address initialOwner,
143
+ bytes memory data
144
+ )
145
+ external
146
+ virtual override
147
+ returns (
148
+ // TODO add onlyRegisteredInstance
149
+ NftId nftId
150
+ )
151
+ {
152
+ StorageV1 storage $ = _getStorageV1();
153
+
154
+ // TODO add more validation
155
+ require(
156
+ objectType == POLICY() || objectType == BUNDLE(),
157
+ "ERROR:REG-010:TYPE_INVALID"
158
+ );
159
+
160
+ uint256 mintedTokenId = $.chainNft.mint(initialOwner, EMPTY_URI);
161
+ nftId = toNftId(mintedTokenId);
162
+
163
+ ObjectInfo memory info = ObjectInfo(
164
+ nftId,
165
+ parentNftId,
166
+ objectType,
167
+ address(0),
168
+ initialOwner,
169
+ data
170
+ );
171
+
172
+ $.info[nftId] = info;
173
+
174
+ // add logging
175
+ }
176
+
177
+ //--- external/public view and pure functions --------------------------------
178
+
179
+ function getObjectCount() external view override returns (uint256) {
180
+ return _getStorageV1().chainNft.totalSupply();
181
+ }
182
+
183
+ function getNftId(
184
+ address object
185
+ ) external view override returns (NftId id) {
186
+ return _getStorageV1().nftIdByAddress[object];
187
+ }
188
+
189
+ function isRegistered(
190
+ NftId nftId
191
+ ) public view override returns (bool) {
192
+ return _getStorageV1().info[nftId].objectType.gtz();
193
+ }
194
+
195
+ function isRegistered(
196
+ address object
197
+ ) external view override returns (bool) {
198
+ return _getStorageV1().nftIdByAddress[object].gtz();
199
+ }
200
+
201
+ function getObjectInfo(
202
+ NftId nftId
203
+ ) external view override returns (ObjectInfo memory info) {
204
+ return _getStorageV1().info[nftId];
205
+ }
206
+
207
+ function getName(
208
+ NftId nftId
209
+ ) external view returns (string memory name) {
210
+ return _getStorageV1().name[nftId];
211
+ }
212
+
213
+ function getOwner(
214
+ NftId nftId
215
+ ) external view override returns (address) {
216
+ return _getStorageV1().chainNft.ownerOf(nftId.toInt());
217
+ }
218
+
219
+ function getChainNft() external view override returns (IChainNft) {
220
+ return _getStorageV1().chainNft;
221
+ }
222
+
223
+ // special case to retrive a gif service
224
+ function getServiceAddress(
225
+ string memory serviceName,
226
+ VersionPart majorVersion
227
+ ) external view override returns (address serviceAddress) {
228
+ bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
229
+ return _getStorageV1().service[serviceNameHash][majorVersion];
230
+ }
231
+
232
+ function getProtocolOwner() external view override returns (address) {
233
+ return _getStorageV1()._protocolOwner;
234
+ }
235
+
236
+ //--- from Registerable --------------------------------------
237
+ // TODO
238
+ // 1) Registerable can not register itself -> otherwise register have to trust owner address provided by registerable
239
+ // registerable owner MUST call register and provide registerable address
240
+ // it will work if component was delegate called ??? NO
241
+ // owner-DELEGATE_CALL->component.register()-CALL->registryService->register()
242
+ // owner-CALL->proxy-DELEGATE_CALL->compoment.register()-CALL->registryService->register()
243
+ // 2) Who is msg.sender here???
244
+ // Registration of Instance or Service (any deployed by GIF contract) msg.sender is done in proxe contructor
245
+ function register() external pure override returns (NftId nftId) {
246
+ return zeroNftId();
247
+ }
248
+
249
+ function getType() external pure override returns (ObjectType objectType) {
250
+ return REGISTRY();
251
+ }
252
+
253
+ function getOwner() public view override returns (address owner) {
254
+ StorageV1 storage $ = _getStorageV1();
255
+ return $.nftId.gtz() ? this.getOwner($.nftId) : $.initialOwner;
256
+ }
257
+
258
+ function getNftId() public view override (IRegisterable, IRegistry) returns (NftId nftId) {
259
+ return _getStorageV1().nftId;
260
+ }
261
+
262
+ function getParentNftId() public view returns (NftId nftId) {
263
+ StorageV1 storage $ = _getStorageV1();
264
+ // we're the global registry
265
+ /*if(block.chainid == 1) {
266
+ return toNftId($.chainNftInternal.PROTOCOL_NFT_ID());
267
+ }
268
+ else {
269
+ return toNftId($.chainNftInternal.GLOBAL_REGISTRY_ID());
270
+ }*/
271
+ nftId = $.info[$.nftId].parentNftId;
272
+ }
273
+
274
+ function getData() public pure returns (bytes memory data) {
275
+ return "";
276
+ }
277
+
278
+ //--- from IRegistryLinked --------------------------------------
279
+
280
+ function getRegistry() external view override returns (IRegistry registry) {
281
+ return this;
282
+ }
283
+
284
+ //--- from Versionable --------------------------------------
285
+
286
+ /// @dev the protocol owner will get ownership of the
287
+ // protocol nft and the global registry nft minted in this
288
+ // initializer function
289
+ function initialize(
290
+ address implementation,
291
+ address activatedBy,
292
+ bytes memory data
293
+ )
294
+ public
295
+ virtual override
296
+ initializer
297
+ {
298
+ _updateVersionHistory(implementation, activatedBy);
299
+ _initializeV01(data);
300
+ }
301
+
302
+ // can not upgrade to the first version
303
+ function upgrade(
304
+ address implementation,
305
+ address activatedBy,
306
+ bytes memory data
307
+ )
308
+ external
309
+ virtual
310
+ {
311
+ revert();
312
+ }
313
+
314
+ function getVersion() public pure virtual override returns (Version) {
315
+ return VersionLib.toVersion(1, 0, 0);
316
+ }
317
+
318
+ //--- IERC165 support -----------------------------------
319
+
320
+ function supportsInterface(bytes4 interfaceId) external pure override returns (bool) {
321
+ return interfaceId == type(IRegistry).interfaceId;
322
+ }
323
+
324
+ //--- all intenal and private functions -----------------------------------
325
+
326
+ function _initializeV01(bytes memory data)
327
+ internal
328
+ onlyInitializing
329
+ {
330
+ StorageV1 storage $ = _getStorageV1();
331
+
332
+ require(
333
+ address($.chainNft) == address(0),
334
+ "ERROR:REG-001:ALREADY_INITIALIZED"
335
+ );
336
+
337
+ address protocolOwner = abi.decode(data, (address));
338
+ $.initialOwner = msg.sender; // TODO here delegate call from proxy constructor, msg.sender is proxy deployer -> Proxy.sol
339
+ $._protocolOwner = protocolOwner;
340
+
341
+ // deploy NFT
342
+ $.chainNftInternal = new ChainNft(address(this));// adds 10kb to deployment size
343
+ $.chainNft = IChainNft($.chainNftInternal);
344
+
345
+ // initial registry setup
346
+ _registerProtocol();
347
+ $.nftId = _registerRegistry();
348
+
349
+ // setup rules for further registrations
350
+ _setupValidTypes();
351
+ _setupValidParentTypes();
352
+ }
353
+
354
+ /// @dev defines which types are allowed to register
355
+ function _setupValidTypes() internal onlyInitializing {
356
+ StorageV1 storage $ = _getStorageV1();
357
+ $.isValidType[REGISTRY()] = true; // only for global registry
358
+ $.isValidType[TOKEN()] = true;
359
+ $.isValidType[SERVICE()] = true;
360
+ $.isValidType[INSTANCE()] = true;
361
+ $.isValidType[STAKE()] = true;
362
+ $.isValidType[PRODUCT()] = true;
363
+ $.isValidType[ORACLE()] = true;
364
+ $.isValidType[POOL()] = true;
365
+ $.isValidType[DISTRIBUTION()] = true;
366
+ $.isValidType[POLICY()] = true;
367
+ $.isValidType[BUNDLE()] = true;
368
+ }
369
+
370
+ /// @dev defines which types - parent type relations are allowed to register
371
+ function _setupValidParentTypes() internal onlyInitializing {
372
+ StorageV1 storage $ = _getStorageV1();
373
+ // registry as parent
374
+ $.isValidParentType[TOKEN()][REGISTRY()] = true;
375
+ $.isValidParentType[SERVICE()][REGISTRY()] = true;
376
+ $.isValidParentType[INSTANCE()][REGISTRY()] = true;
377
+
378
+ // instance as parent
379
+ $.isValidParentType[PRODUCT()][INSTANCE()] = true;
380
+ $.isValidParentType[DISTRIBUTION()][INSTANCE()] = true;
381
+ $.isValidParentType[ORACLE()][INSTANCE()] = true;
382
+ $.isValidParentType[POOL()][INSTANCE()] = true;
383
+
384
+ // product as parent
385
+ $.isValidParentType[POLICY()][PRODUCT()] = true;
386
+
387
+ // pool as parent
388
+ $.isValidParentType[BUNDLE()][POOL()] = true;
389
+ $.isValidParentType[STAKE()][POOL()] = true;
390
+ }
391
+
392
+ /// @dev protocol registration used to anchor the dip ecosystem relations
393
+ function _registerProtocol()
394
+ virtual
395
+ internal
396
+ onlyInitializing
397
+ {
398
+ StorageV1 storage $ = _getStorageV1();
399
+
400
+ uint256 protocolId = $.chainNftInternal.PROTOCOL_NFT_ID();
401
+ $.chainNftInternal.mint($._protocolOwner, protocolId);
402
+
403
+ NftId protocolNftid = toNftId(protocolId);
404
+ ObjectInfo memory protocolInfo = ObjectInfo(
405
+ protocolNftid,
406
+ zeroNftId(), // parent nft id
407
+ PROTOCOL(),
408
+ address(0), // contract address
409
+ $._protocolOwner,
410
+ "" // data
411
+ );
412
+
413
+ $.info[protocolNftid] = protocolInfo;
414
+ }
415
+
416
+ /// @dev registry registration
417
+ /// might also register the global registry when not on mainnet
418
+ function _registerRegistry()
419
+ virtual
420
+ internal
421
+ onlyInitializing
422
+ returns (NftId registryNftId)
423
+ {
424
+ StorageV1 storage $ = _getStorageV1();
425
+
426
+ uint256 registryId = $.chainNftInternal.calculateTokenId(2);
427
+ registryNftId = toNftId(registryId);
428
+
429
+ // we're not the global registry
430
+ if(registryId != $.chainNftInternal.GLOBAL_REGISTRY_ID()) {
431
+ _registerGlobalRegistry();
432
+ }
433
+
434
+ $.chainNftInternal.mint($._protocolOwner, registryId);
435
+
436
+ // TODO error when deploying registry proxy
437
+ // in that case "this" is proxy address, "msg.sender" is proxy deployer, here in delegate call
438
+ // _registerObjectInfo() treats "this" as "IRegisterable"
439
+ // thus registerable.anyFunction() calls proxy...
440
+ /*_registerObjectInfo(this, registryNftId);*/
441
+
442
+ NftId parentNftId;
443
+ // we're the global registry
444
+ if(block.chainid == 1) {
445
+ parentNftId = toNftId($.chainNftInternal.PROTOCOL_NFT_ID());
446
+ }
447
+ else {
448
+ parentNftId = toNftId($.chainNftInternal.GLOBAL_REGISTRY_ID());
449
+ }
450
+ ObjectInfo memory registryInfo = ObjectInfo(
451
+ registryNftId,
452
+ parentNftId, // registerable is proxy address, when in delegate call
453
+ REGISTRY(),
454
+ address(this), // proxy address
455
+ $._protocolOwner, // registry owner is different from proxy owner
456
+ ""
457
+ );
458
+
459
+ $.info[registryNftId] = registryInfo;
460
+ $.nftIdByAddress[address(this)] = registryNftId;
461
+
462
+ // add logging
463
+ }
464
+
465
+
466
+ /// @dev global registry registration for non mainnet registries
467
+ function _registerGlobalRegistry()
468
+ virtual
469
+ internal
470
+ onlyInitializing
471
+ {
472
+ StorageV1 storage $ = _getStorageV1();
473
+
474
+ uint256 globalRegistryId = $.chainNftInternal.GLOBAL_REGISTRY_ID();
475
+ $.chainNftInternal.mint($._protocolOwner, globalRegistryId);
476
+
477
+ NftId globalRegistryNftId = toNftId(globalRegistryId);
478
+ ObjectInfo memory globalRegistryInfo = ObjectInfo(
479
+ globalRegistryNftId,
480
+ toNftId($.chainNftInternal.PROTOCOL_NFT_ID()),
481
+ REGISTRY(),
482
+ address(0), // contract address
483
+ $._protocolOwner,
484
+ "" // data
485
+ );
486
+
487
+ $.info[globalRegistryNftId] = globalRegistryInfo;
488
+ }
489
+
490
+ function _registerObjectInfo(
491
+ IRegisterable registerable,
492
+ NftId nftId
493
+ )
494
+ internal
495
+ virtual
496
+ onlyInitializing
497
+ {
498
+ address objectAddress = address(registerable);
499
+ ObjectInfo memory info = ObjectInfo(
500
+ nftId,
501
+ registerable.getParentNftId(),
502
+ registerable.getType(),
503
+ objectAddress,
504
+ registerable.getOwner(),
505
+ registerable.getData()
506
+ );
507
+
508
+ StorageV1 storage $ = _getStorageV1();
509
+ $.info[nftId] = info;
510
+ $.nftIdByAddress[objectAddress] = nftId;
511
+
512
+ // add logging
513
+ }
514
+
515
+ // TODO: private or internal ?
516
+ // 1) new version have access only to its own storage slot (if previous versions did not expose theirs)
517
+ // - have to chain initializers
518
+ // + simple
519
+ // - slow/costly, initialization gas usage will grow faster then 1)
520
+ // - initialization functions count/code likely will grow with each new version
521
+ // - new functions have access only to a local storage slot
522
+ // 2) each intializer of each version have access to each "registry storage locations" he knows about ->
523
+ // + no initializers chaining
524
+ // + new variables can be added to older versions storage hmmm...redefine storage struct
525
+ function _getStorageV1()
526
+ private
527
+ pure
528
+ returns (StorageV1 storage s)
529
+ {
530
+ // solhint-disable no-inline-assembly
531
+ assembly {
532
+ s.slot := STORAGE_LOCATION_V1
533
+ }
534
+ }
535
+ }
536
+
537
+ /*
538
+ **************** New implementation is set from delegate call ******************
539
+ Implementation controled proxy?
540
+ 1). Proxy allows implV1 to change proxy.implementation variable to a new one (e.g. ImplV2) -> this is called reinitialization
541
+ 2). calls to proxy after reinitialization will point to new implementation -> like switching context -> old implementsations cuts itself from proxy
542
+ 2). Proxy can have:
543
+ a). safe implementation which it uses after construction by default
544
+ safe implementation allows one reinitialization to implementation needed (can be done in one call after initialization)
545
+ b). two impelemtations
546
+ the first for upgrades (have reinitialize function which changes the address the second one)
547
+ the second for appication specific stuff
548
+ */
@@ -0,0 +1,21 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
+
6
+ contract ERC165 is IERC165 {
7
+ mapping(bytes4 => bool) private _isSupported;
8
+
9
+ constructor() {
10
+ // register support for ERC165
11
+ _registerInterface(type(IERC165).interfaceId);
12
+ }
13
+
14
+ function supportsInterface(bytes4 interfaceId) external view override returns (bool) {
15
+ return _isSupported[interfaceId];
16
+ }
17
+
18
+ function _registerInterface(bytes4 interfaceId) internal {
19
+ _isSupported[interfaceId] = true;
20
+ }
21
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ interface IOwnable {
5
+ function getOwner() external view returns (address owner);
6
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
+
6
+ import {IRegistry} from "../registry/IRegistry.sol";
7
+ import {NftId} from "../types/NftId.sol";
8
+ import {ObjectType} from "../types/ObjectType.sol";
9
+
10
+ import {IOwnable} from "./IOwnable.sol";
11
+
12
+ interface IRegisterable is IERC165, IOwnable {
13
+ function getRegistry() external view returns (IRegistry registry);
14
+
15
+ function register() external returns (NftId nftId);
16
+
17
+ function getType() external pure returns (ObjectType objectType);
18
+
19
+ function getNftId() external view returns (NftId nftId);
20
+
21
+ function getParentNftId() external view returns (NftId nftId);
22
+
23
+ function getData() external view returns (bytes memory data);
24
+ }
@@ -0,0 +1,65 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {Blocknumber, blockNumber} from "../types/Blocknumber.sol";
5
+ import {Timestamp, blockTimestamp} from "../types/Timestamp.sol";
6
+ import {Version, VersionPart} from "../types/Version.sol";
7
+
8
+ interface IVersionable {
9
+
10
+ struct VersionInfo {
11
+ Version version;
12
+ address implementation;
13
+ address activatedBy;
14
+ Timestamp activatedAt;
15
+ Blocknumber activatedIn;
16
+ }
17
+
18
+ event LogVersionableInitialized(Version version, address implementation, address activatedBy);
19
+
20
+ // TODO uncomment when all implementations are ready
21
+ /**
22
+ * @dev IMPORTANT this function MUST be implemented by each new version
23
+ * any such implementation MUST be guarded by initializer modifier
24
+ * any such implementation MUST call internal function _activate()
25
+ * any new version MUST inherit from previous version
26
+ */
27
+ function initialize(address implementation, address activatedBy, bytes memory activationData) external;
28
+
29
+ /**
30
+ * @dev IMPORTANT this function MUST be implemented by each new version
31
+ * any such implementation MUST be guarded by reinitializer(version().toUint64()) modifier
32
+ * any such implementation MUST call internal function _activate()
33
+ * any new version MUST inherit from previous version
34
+ * the first verion MUST revert
35
+ */
36
+ function upgrade(address implementation, address activatedBy, bytes memory upgradeData) external;
37
+
38
+ /**
39
+ * @dev returns true if the specified version has been activated for the current contract
40
+ */
41
+ function isInitialized(Version version) external view returns(bool);
42
+
43
+ /**
44
+ * @dev returns currently active version of this contract
45
+ */
46
+ function getVersion() external pure returns(Version);
47
+
48
+ /**
49
+ * @dev returns the number of all deployed versions of this contract
50
+ */
51
+ function getVersionCount() external view returns(uint256 numberOfVersions);
52
+
53
+ /**
54
+ * @dev returns the i-th (index) version of this contract
55
+ */
56
+ function getVersion(uint256 index) external view returns(Version version);
57
+
58
+ /**
59
+ * @dev returns the i-th (index) version info of this contract
60
+ */
61
+ function getVersionInfo(Version version) external view returns(VersionInfo memory versionInfo);
62
+
63
+ function getInitializedVersion() external view returns(uint64);
64
+
65
+ }