@etherisc/gif-next 0.0.2-78bf628-134 → 0.0.2-790d44b-698

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 (231) hide show
  1. package/README.md +38 -7
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +405 -0
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +340 -0
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +131 -0
  10. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +109 -18
  12. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.json +194 -3
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +160 -21
  16. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  28. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  34. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  35. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +609 -416
  36. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
  37. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  38. package/artifacts/contracts/instance/Instance.sol/Instance.json +751 -467
  39. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  40. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +82 -18
  41. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  42. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +32 -0
  43. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/IService.sol/IService.json +59 -18
  47. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  48. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +115 -19
  49. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  50. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +14 -14
  51. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  52. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +4 -4
  53. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +1 -1
  54. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +1 -1
  55. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.json +82 -18
  56. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +55 -54
  61. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
  62. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +56 -55
  64. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +12 -7
  66. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  68. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +12 -7
  69. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.dbg.json +4 -0
  70. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.json +10 -0
  71. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.dbg.json +4 -0
  72. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensation.json → distribution/IDistribution.sol/IDistribution.json} +2 -2
  73. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.dbg.json +4 -0
  74. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensationModule.json → distribution/IDistribution.sol/IDistributionModule.json} +2 -2
  75. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +53 -40
  78. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  79. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +53 -40
  80. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  81. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  82. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -5
  83. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  84. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -5
  85. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +1 -1
  86. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +1 -1
  87. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +104 -1
  88. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +1 -1
  89. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +126 -5
  90. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
  91. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
  92. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +209 -231
  93. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  94. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +2 -2
  95. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
  96. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +209 -231
  97. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +119 -47
  99. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +484 -0
  101. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  102. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +59 -18
  103. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  104. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +366 -0
  105. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  106. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +124 -19
  107. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  108. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +212 -18
  109. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  110. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +170 -34
  111. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  112. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +296 -47
  113. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  114. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  115. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  116. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  117. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  118. package/artifacts/contracts/registry/Registry.sol/Registry.json +266 -14
  119. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  120. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
  121. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  122. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +55 -14
  124. package/artifacts/contracts/shared/Proxy.sol/ProxyDeployer.dbg.json +4 -0
  125. package/artifacts/contracts/shared/Proxy.sol/ProxyDeployer.json +248 -0
  126. package/artifacts/contracts/shared/Proxy.sol/ProxyWithProxyAdminGetter.dbg.json +4 -0
  127. package/artifacts/contracts/shared/Proxy.sol/ProxyWithProxyAdminGetter.json +129 -0
  128. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/Versionable.sol/Versionable.json +78 -14
  131. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.dbg.json +4 -0
  132. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.json +405 -0
  133. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  134. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  135. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
  136. package/artifacts/contracts/test/TestPool.sol/TestPool.json +194 -3
  137. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +209 -27
  139. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  140. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  141. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  143. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestService.sol/TestService.json +95 -31
  145. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  147. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  148. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +89 -25
  150. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  151. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  152. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/Fee.sol/FeeLib.json +50 -11
  156. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  157. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  158. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  160. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  162. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  164. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.dbg.json +4 -0
  165. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.json +99 -0
  166. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  167. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  168. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  170. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/Version.sol/VersionLib.json +40 -2
  175. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  176. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  177. package/contracts/components/BaseComponent.sol +7 -1
  178. package/contracts/components/Distribution.sol +132 -0
  179. package/contracts/components/IDistributionComponent.sol +47 -0
  180. package/contracts/components/IPoolComponent.sol +14 -0
  181. package/contracts/components/IProductComponent.sol +24 -5
  182. package/contracts/components/Pool.sol +64 -3
  183. package/contracts/components/Product.sol +123 -13
  184. package/contracts/instance/IInstance.sol +7 -4
  185. package/contracts/instance/Instance.sol +11 -4
  186. package/contracts/instance/base/IInstanceBase.sol +3 -0
  187. package/contracts/instance/base/InstanceBase.sol +7 -0
  188. package/contracts/instance/base/Lifecycle.sol +10 -2
  189. package/contracts/instance/base/ModuleBase.sol +22 -17
  190. package/contracts/instance/module/access/Access.sol +3 -3
  191. package/contracts/instance/module/bundle/BundleModule.sol +10 -12
  192. package/contracts/instance/module/bundle/IBundle.sol +6 -11
  193. package/contracts/instance/module/component/ComponentModule.sol +15 -20
  194. package/contracts/instance/module/component/IComponent.sol +3 -2
  195. package/contracts/instance/module/distribution/DistributionModule.sol +17 -0
  196. package/contracts/instance/module/distribution/IDistribution.sol +10 -0
  197. package/contracts/instance/module/policy/IPolicy.sol +10 -8
  198. package/contracts/instance/module/policy/PolicyModule.sol +33 -19
  199. package/contracts/instance/module/pool/IPoolModule.sol +0 -1
  200. package/contracts/instance/module/pool/PoolModule.sol +12 -9
  201. package/contracts/instance/module/risk/IRisk.sol +18 -2
  202. package/contracts/instance/module/risk/RiskModule.sol +56 -2
  203. package/contracts/instance/module/treasury/ITreasury.sol +29 -50
  204. package/contracts/instance/module/treasury/TreasuryModule.sol +71 -85
  205. package/contracts/instance/service/ComponentOwnerService.sol +19 -24
  206. package/contracts/instance/service/DistributionService.sol +59 -0
  207. package/contracts/instance/service/IDistributionService.sol +12 -0
  208. package/contracts/instance/service/IPoolService.sol +7 -0
  209. package/contracts/instance/service/IProductService.sol +56 -7
  210. package/contracts/instance/service/PoolService.sol +30 -4
  211. package/contracts/instance/service/ProductService.sol +229 -74
  212. package/contracts/registry/Registry.sol +190 -113
  213. package/contracts/shared/IVersionable.sol +51 -9
  214. package/contracts/shared/Proxy.sol +94 -0
  215. package/contracts/shared/Versionable.sol +90 -38
  216. package/contracts/test/TestDistribution.sol +21 -0
  217. package/contracts/test/TestPool.sol +5 -2
  218. package/contracts/test/TestProduct.sol +35 -7
  219. package/contracts/types/Fee.sol +8 -3
  220. package/contracts/types/ObjectType.sol +17 -5
  221. package/contracts/types/ReferralId.sol +48 -0
  222. package/contracts/types/RiskId.sol +43 -0
  223. package/contracts/types/RoleId.sol +2 -2
  224. package/contracts/types/Version.sol +8 -0
  225. package/package.json +1 -1
  226. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +0 -4
  227. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +0 -10
  228. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +0 -4
  229. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +0 -4
  230. package/contracts/instance/module/compensation/CompensationModule.sol +0 -8
  231. package/contracts/instance/module/compensation/ICompensation.sol +0 -10
@@ -1,5 +1,5 @@
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
5
  import {IService} from "../instance/base/IService.sol";
@@ -8,11 +8,14 @@ import {IChainNft} from "./IChainNft.sol";
8
8
  import {ChainNft} from "./ChainNft.sol";
9
9
  import {IRegistry} from "./IRegistry.sol";
10
10
  import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
11
- import {VersionPart} from "../types/Version.sol";
12
- import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, COMPENSATION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
11
+ import {Version, VersionPart, VersionLib} from "../types/Version.sol";
12
+ import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, DISTRIBUTION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
13
+
14
+ import {Versionable} from "../shared/Versionable.sol";
15
+
13
16
 
14
- // TODO make registry upgradable
15
17
  contract Registry is
18
+ Versionable,
16
19
  IRegisterable,
17
20
  IRegistry
18
21
  {
@@ -20,62 +23,84 @@ contract Registry is
20
23
 
21
24
  string public constant EMPTY_URI = "";
22
25
 
23
- mapping(NftId nftId => ObjectInfo info) private _info;
24
- mapping(NftId nftId => address owner) private _owner;
25
- mapping(address object => NftId nftId) private _nftIdByAddress;
26
- mapping(ObjectType objectType => bool) private _isValidType;
27
- mapping(ObjectType objectType => mapping(ObjectType objectParentType => bool)) private _isValidParentType;
26
+ // IMPORTANT Every new version with storage changes must implement its own struct
27
+ // copy paste previous version and add changes
28
+ // @custom:storage-location erc7201:gif-next.contracts.registry.Registry.sol
29
+ struct StorageV1 {
30
+
31
+ mapping(NftId nftId => ObjectInfo info) _info;
32
+ mapping(address object => NftId nftId) _nftIdByAddress;
33
+ mapping(ObjectType objectType => bool) _isValidType;
34
+ mapping(ObjectType objectType => mapping(ObjectType objectParentType => bool)) _isValidParentType;
28
35
 
29
- mapping(NftId nftId => string stringValue) private _string;
30
- mapping(bytes32 serviceNameHash => mapping(VersionPart majorVersion => address service)) _service;
36
+ mapping(NftId nftId => string stringValue) _string;
37
+ mapping(bytes32 serviceNameHash => mapping(VersionPart majorVersion => address service)) _service;
31
38
 
32
- NftId private _nftId;
33
- IChainNft private _chainNft;
34
- ChainNft private _chainNftInternal;
35
- address private _initialOwner;
39
+ NftId _nftId;
40
+ IChainNft _chainNft;
41
+ ChainNft _chainNftInternal;
42
+ address _initialOwner;
36
43
 
37
- // @dev will own protocol nft and registry nft(s) minted during initialize
38
- address private _protocolOwner;
44
+ /// @dev will own protocol nft and registry nft(s) minted during initialize
45
+ address _protocolOwner;
46
+ // if struct goes here
47
+ // then you cannot add new vars here
48
+ }
39
49
 
40
- // TODO refactor once registry becomes upgradable
41
- // @Dev the protocol owner will get ownership of the
50
+ // TODO do not use gif-next in namespace id
51
+ // TODO ask openzeppelin about public location
52
+ // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.registry.Registry.sol")) - 1)) & ~bytes32(uint256(0xff));
53
+ bytes32 public constant LOCATION_V1 = 0x6548007c3f4340f82f348c576c0ff69f4f529cadd5ad41f96aae61abceeaa300;
54
+
55
+ // TODO check how usage of "$.data" influences gas costs
56
+ // IMPORTANT Every new version must implement this function
57
+ // keep it private -> if unreachable from the next version then not included in its byte code
58
+ // each version MUST use the same locationV1, just change return type
59
+ function _getStorage() private pure returns (StorageV1 storage $) {
60
+ assembly {
61
+ $.slot := LOCATION_V1
62
+ }
63
+ }
64
+
65
+ /// @dev the protocol owner will get ownership of the
42
66
  // protocol nft and the global registry nft minted in this
43
67
  // initializer function
44
- function initialize(
45
- address chainNft,
46
- address protocolOwner
47
- )
48
- public
68
+ function _initialize(bytes memory data)
69
+ internal
70
+ onlyInitializing
71
+ virtual override
49
72
  {
50
- require(
51
- address(_chainNft) == address(0),
52
- "ERROR:REG-001:ALREADY_INITIALIZED"
53
- );
54
-
55
- _initialOwner = msg.sender;
56
- _protocolOwner = protocolOwner;
57
-
58
- _chainNft = IChainNft(chainNft);
59
- _chainNftInternal = ChainNft(chainNft);
60
-
73
+ address protocolOwner = abi.decode(data, (address));
74
+ StorageV1 storage $ = _getStorage();
75
+
76
+ // TODO here delegate call from proxy constructor, msg.sender is proxy deployer -> Proxy.sol
77
+ $._initialOwner = msg.sender;
78
+ $._protocolOwner = protocolOwner;
79
+
80
+ // TODO deployment size is to big, call another contract which keeps and deploys ChainNft byte code
81
+ // deploy NFT
82
+ $._chainNftInternal = new ChainNft(address(this));// adds 10kb to deployment size
83
+ $._chainNft = IChainNft($._chainNftInternal);
84
+
61
85
  // initial registry setup
62
86
  _registerProtocol();
63
- _nftId = _registerRegistry();
87
+ $._nftId = _registerRegistry();
64
88
 
65
89
  // setup rules for further registrations
66
90
  _setupValidTypes();
67
91
  _setupValidParentTypes();
68
92
  }
69
93
 
70
-
71
94
  function register(
72
95
  address objectAddress
73
96
  )
74
97
  // TODO add authz (only services may register components etc)
75
98
  // we have to check how we do authz for registring services (just restrict to protocol owner/registry owner)
76
99
  external override returns (NftId nftId) {
100
+ StorageV1 storage $ = _getStorage();
101
+
77
102
  require(
78
- _nftIdByAddress[objectAddress].eqz(),
103
+ $._nftIdByAddress[objectAddress].eqz(),
79
104
  "ERROR:REG-002:ALREADY_REGISTERED"
80
105
  );
81
106
 
@@ -87,7 +112,7 @@ contract Registry is
87
112
 
88
113
  ObjectType objectType = registerable.getType();
89
114
  require(
90
- _isValidType[objectType],
115
+ $._isValidType[objectType],
91
116
  "ERROR:REG-004:TYPE_INVALID"
92
117
  );
93
118
 
@@ -98,14 +123,14 @@ contract Registry is
98
123
  );
99
124
 
100
125
  require(
101
- _isValidParentType[objectType][_info[parentNftId].objectType],
126
+ $._isValidParentType[objectType][$._info[parentNftId].objectType],
102
127
  "ERROR:REG-006:PARENT_TYPE_INVALID"
103
128
  );
104
129
 
105
130
  // also check that nftId and parentNFtId are on the same chain if applicable
106
131
 
107
132
  // nft minting
108
- uint256 mintedTokenId = _chainNft.mint(
133
+ uint256 mintedTokenId = $._chainNft.mint(
109
134
  registerable.getOwner(),
110
135
  EMPTY_URI
111
136
  );
@@ -125,13 +150,13 @@ contract Registry is
125
150
  bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
126
151
 
127
152
  // service specific state
128
- _string[nftId] = serviceName;
153
+ $._string[nftId] = serviceName;
129
154
 
130
155
  require(
131
- _service[serviceNameHash][majorVersion] == address(0),
156
+ $._service[serviceNameHash][majorVersion] == address(0),
132
157
  "ERROR:REG-008:ALREADY_REGISTERED"
133
158
  );
134
- _service[serviceNameHash][majorVersion] = objectAddress;
159
+ $._service[serviceNameHash][majorVersion] = objectAddress;
135
160
  }
136
161
 
137
162
  // create object info and link nft id with it
@@ -152,13 +177,15 @@ contract Registry is
152
177
  NftId nftId
153
178
  )
154
179
  {
180
+ StorageV1 storage $ = _getStorage();
181
+
155
182
  // TODO add more validation
156
183
  require(
157
184
  objectType == POLICY() || objectType == BUNDLE(),
158
185
  "ERROR:REG-010:TYPE_INVALID"
159
186
  );
160
187
 
161
- uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
188
+ uint256 mintedTokenId = $._chainNft.mint(initialOwner, EMPTY_URI);
162
189
  nftId = toNftId(mintedTokenId);
163
190
 
164
191
  ObjectInfo memory info = ObjectInfo(
@@ -170,57 +197,57 @@ contract Registry is
170
197
  data
171
198
  );
172
199
 
173
- _info[nftId] = info;
200
+ $._info[nftId] = info;
174
201
 
175
202
  // add logging
176
203
  }
177
204
 
178
205
  function getObjectCount() external view override returns (uint256) {
179
- return _chainNft.totalSupply();
206
+ return _getStorage()._chainNft.totalSupply();
180
207
  }
181
208
 
182
209
  function getNftId(
183
210
  address object
184
211
  ) external view override returns (NftId id) {
185
- return _nftIdByAddress[object];
212
+ return _getStorage()._nftIdByAddress[object];
186
213
  }
187
214
 
188
215
  function isRegistered(
189
216
  NftId nftId
190
217
  ) public view override returns (bool) {
191
- return _info[nftId].objectType.gtz();
218
+ return _getStorage()._info[nftId].objectType.gtz();
192
219
  }
193
220
 
194
221
  function isRegistered(
195
222
  address object
196
223
  ) external view override returns (bool) {
197
- return _nftIdByAddress[object].gtz();
224
+ return _getStorage()._nftIdByAddress[object].gtz();
198
225
  }
199
226
 
200
227
  function getObjectInfo(
201
228
  NftId nftId
202
229
  ) external view override returns (ObjectInfo memory info) {
203
- return _info[nftId];
230
+ return _getStorage()._info[nftId];
204
231
  }
205
232
 
206
233
  function getName(
207
234
  NftId nftId
208
235
  ) external view returns (string memory name) {
209
- return _string[nftId];
236
+ return _getStorage()._string[nftId];
210
237
  }
211
238
 
212
239
  function getOwner(NftId nftId) external view override returns (address) {
213
- return _chainNft.ownerOf(nftId.toInt());
240
+ return _getStorage()._chainNft.ownerOf(nftId.toInt());
214
241
  }
215
242
 
216
243
  function getChainNft() external view override returns (IChainNft) {
217
- return _chainNft;
244
+ return _getStorage()._chainNft;
218
245
  }
219
246
 
220
247
  // special case to retrive a gif service
221
248
  function getServiceAddress(string memory serviceName, VersionPart majorVersion) external view override returns (address serviceAddress) {
222
249
  bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
223
- return _service[serviceNameHash][majorVersion];
250
+ return _getStorage()._service[serviceNameHash][majorVersion];
224
251
  }
225
252
 
226
253
  // from IERC165
@@ -233,7 +260,16 @@ contract Registry is
233
260
  return this;
234
261
  }
235
262
 
263
+ // from IVersionable
264
+ function getVersion() public pure virtual override returns (Version) {
265
+ return VersionLib.toVersion(1, 0, 0);
266
+ }
267
+
236
268
  // from IRegisterable
269
+ // TODO
270
+ // 1) Registerable can not register itself -> otherwise register have to trust owner address provided by registerable
271
+ // registerable owner MUST call register and provide registerable address
272
+ // 2) Who is msg.sender here???
237
273
  function register() external pure override returns (NftId nftId) {
238
274
  return zeroNftId();
239
275
  }
@@ -242,73 +278,77 @@ contract Registry is
242
278
  return REGISTRY();
243
279
  }
244
280
 
245
-
246
281
  function getOwner() public view override returns (address owner) {
247
- return _nftId.gtz() ? this.getOwner(_nftId) : _initialOwner;
282
+ StorageV1 storage $ = _getStorage();
283
+ return $._nftId.gtz() ? this.getOwner($._nftId) : $._initialOwner;
248
284
  }
249
285
 
250
- function getNftId() external view override (IRegisterable, IRegistry) returns (NftId nftId) {
251
- return _nftId;
286
+ function getNftId() public view override (IRegisterable, IRegistry) returns (NftId nftId) {
287
+ return _getStorage()._nftId;
252
288
  }
253
289
 
254
- function getParentNftId() external view returns (NftId nftId) {
255
- // we're the global registry
256
- if(block.chainid == 1) {
257
- return toNftId(_chainNftInternal.PROTOCOL_NFT_ID());
258
- }
259
- else {
260
- return toNftId(_chainNftInternal.GLOBAL_REGISTRY_ID());
261
- }
290
+ function getParentNftId() public view returns (NftId nftId) {
291
+ StorageV1 storage $ = _getStorage();
292
+ nftId = $._info[$._nftId].parentNftId;
262
293
  }
263
294
 
264
- function getData() external pure returns (bytes memory data) {
295
+ function getData() public pure returns (bytes memory data) {
265
296
  return "";
266
297
  }
267
298
 
268
299
  // registry specific functions
269
300
  function getProtocolOwner() external view override returns (address) {
270
- return _protocolOwner;
301
+ return _getStorage()._protocolOwner;
271
302
  }
272
303
 
273
304
  /// @dev defines which types are allowed to register
274
- function _setupValidTypes() internal {
275
- _isValidType[REGISTRY()] = true; // only for global registry
276
- _isValidType[TOKEN()] = true;
277
- _isValidType[SERVICE()] = true;
278
- _isValidType[INSTANCE()] = true;
279
- _isValidType[STAKE()] = true;
280
- _isValidType[PRODUCT()] = true;
281
- _isValidType[ORACLE()] = true;
282
- _isValidType[POOL()] = true;
283
- _isValidType[POLICY()] = true;
284
- _isValidType[BUNDLE()] = true;
305
+ function _setupValidTypes() internal onlyInitializing {
306
+ StorageV1 storage $ = _getStorage();
307
+ $._isValidType[REGISTRY()] = true; // only for global registry
308
+ $._isValidType[TOKEN()] = true;
309
+ $._isValidType[SERVICE()] = true;
310
+ $._isValidType[INSTANCE()] = true;
311
+ $._isValidType[STAKE()] = true;
312
+ $._isValidType[PRODUCT()] = true;
313
+ $._isValidType[ORACLE()] = true;
314
+ $._isValidType[POOL()] = true;
315
+ $._isValidType[DISTRIBUTION()] = true;
316
+ $._isValidType[POLICY()] = true;
317
+ $._isValidType[BUNDLE()] = true;
285
318
  }
286
319
 
287
320
  /// @dev defines which types - parent type relations are allowed to register
288
- function _setupValidParentTypes() internal {
321
+ function _setupValidParentTypes() internal onlyInitializing {
322
+ StorageV1 storage $ = _getStorage();
289
323
  // registry as parent
290
- _isValidParentType[TOKEN()][REGISTRY()] = true;
291
- _isValidParentType[SERVICE()][REGISTRY()] = true;
292
- _isValidParentType[INSTANCE()][REGISTRY()] = true;
324
+ $._isValidParentType[TOKEN()][REGISTRY()] = true;
325
+ $._isValidParentType[SERVICE()][REGISTRY()] = true;
326
+ $._isValidParentType[INSTANCE()][REGISTRY()] = true;
293
327
 
294
328
  // instance as parent
295
- _isValidParentType[PRODUCT()][INSTANCE()] = true;
296
- _isValidParentType[COMPENSATION()][INSTANCE()] = true;
297
- _isValidParentType[ORACLE()][INSTANCE()] = true;
298
- _isValidParentType[POOL()][INSTANCE()] = true;
329
+ $._isValidParentType[PRODUCT()][INSTANCE()] = true;
330
+ $._isValidParentType[DISTRIBUTION()][INSTANCE()] = true;
331
+ $._isValidParentType[ORACLE()][INSTANCE()] = true;
332
+ $._isValidParentType[POOL()][INSTANCE()] = true;
299
333
 
300
334
  // product as parent
301
- _isValidParentType[POLICY()][PRODUCT()] = true;
335
+ $._isValidParentType[POLICY()][PRODUCT()] = true;
302
336
 
303
337
  // pool as parent
304
- _isValidParentType[BUNDLE()][POOL()] = true;
305
- _isValidParentType[STAKE()][POOL()] = true;
338
+ $._isValidParentType[BUNDLE()][POOL()] = true;
339
+ $._isValidParentType[STAKE()][POOL()] = true;
306
340
  }
307
341
 
308
342
  /// @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);
343
+ function _registerProtocol()
344
+ virtual
345
+ internal
346
+ onlyInitializing
347
+ {
348
+ StorageV1 storage $ = _getStorage();
349
+
350
+ uint256 protocolId = $._chainNftInternal.PROTOCOL_NFT_ID();
351
+ $._chainNftInternal.mint($._protocolOwner, protocolId);
312
352
 
313
353
  NftId protocolNftid = toNftId(protocolId);
314
354
  ObjectInfo memory protocolInfo = ObjectInfo(
@@ -316,66 +356,103 @@ contract Registry is
316
356
  zeroNftId(), // parent nft id
317
357
  PROTOCOL(),
318
358
  address(0), // contract address
319
- _protocolOwner,
359
+ $._protocolOwner,
320
360
  "" // data
321
361
  );
322
362
 
323
- _info[protocolNftid] = protocolInfo;
363
+ $._info[protocolNftid] = protocolInfo;
324
364
  }
325
365
 
326
366
  /// @dev registry registration
327
367
  /// might also register the global registry when not on mainnet
328
- function _registerRegistry() virtual internal returns (NftId registryNftId) {
329
- uint256 registryId = _chainNftInternal.calculateTokenId(2);
368
+ function _registerRegistry()
369
+ virtual
370
+ internal
371
+ onlyInitializing
372
+ returns (NftId registryNftId)
373
+ {
374
+ StorageV1 storage $ = _getStorage();
375
+
376
+ uint256 registryId = $._chainNftInternal.calculateTokenId(2);
330
377
  registryNftId = toNftId(registryId);
331
378
 
332
379
  // we're not the global registry
333
- if(registryId != _chainNftInternal.GLOBAL_REGISTRY_ID()) {
380
+ if(registryId != $._chainNftInternal.GLOBAL_REGISTRY_ID()) {
334
381
  _registerGlobalRegistry();
335
382
  }
336
383
 
337
- _chainNftInternal.mint(_protocolOwner, registryId);
338
- _registerObjectInfo(this, registryNftId);
384
+ $._chainNftInternal.mint($._protocolOwner, registryId);
385
+
386
+ NftId parentNftId;
387
+ // we're the global registry
388
+ if(block.chainid == 1) {
389
+ parentNftId = toNftId($._chainNftInternal.PROTOCOL_NFT_ID());
390
+ }
391
+ else {
392
+ parentNftId = toNftId($._chainNftInternal.GLOBAL_REGISTRY_ID());
393
+ }
394
+ ObjectInfo memory registryInfo = ObjectInfo(
395
+ registryNftId,
396
+ parentNftId,
397
+ REGISTRY(),
398
+ address(this), // proxy address
399
+ $._protocolOwner, // registry owner is different from proxy owner
400
+ ""
401
+ );
402
+
403
+ $._info[registryNftId] = registryInfo;
404
+ $._nftIdByAddress[address(this)] = registryNftId;
405
+
406
+ // add logging
339
407
  }
340
408
 
341
409
 
342
410
  /// @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);
411
+ function _registerGlobalRegistry()
412
+ virtual
413
+ internal
414
+ onlyInitializing
415
+ {
416
+ StorageV1 storage $ = _getStorage();
417
+
418
+ uint256 globalRegistryId = $._chainNftInternal.GLOBAL_REGISTRY_ID();
419
+ $._chainNftInternal.mint($._protocolOwner, globalRegistryId);
346
420
 
347
421
  NftId globalRegistryNftId = toNftId(globalRegistryId);
348
422
  ObjectInfo memory globalRegistryInfo = ObjectInfo(
349
423
  globalRegistryNftId,
350
- toNftId(_chainNftInternal.PROTOCOL_NFT_ID()),
424
+ toNftId($._chainNftInternal.PROTOCOL_NFT_ID()),
351
425
  REGISTRY(),
352
426
  address(0), // contract address
353
- _protocolOwner,
427
+ $._protocolOwner,
354
428
  "" // data
355
429
  );
356
430
 
357
- _info[globalRegistryNftId] = globalRegistryInfo;
431
+ $._info[globalRegistryNftId] = globalRegistryInfo;
358
432
  }
359
433
 
360
-
361
434
  function _registerObjectInfo(
362
435
  IRegisterable registerable,
363
436
  NftId nftId
364
- ) internal virtual {
437
+ )
438
+ internal
439
+ virtual
440
+ {
365
441
  address objectAddress = address(registerable);
366
442
  ObjectInfo memory info = ObjectInfo(
367
443
  nftId,
368
- registerable.getParentNftId(),
444
+ registerable.getParentNftId(),
369
445
  registerable.getType(),
370
446
  objectAddress,
371
447
  registerable.getOwner(),
372
448
  registerable.getData()
373
449
  );
374
450
 
375
- _info[nftId] = info;
376
- _nftIdByAddress[objectAddress] = nftId;
451
+ StorageV1 storage $ = _getStorage();
452
+ $._info[nftId] = info;
453
+ $._nftIdByAddress[objectAddress] = nftId;
377
454
 
378
455
  // add logging
379
456
  }
380
457
 
381
- }
458
+ }
@@ -1,9 +1,37 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
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";
4
+ import {Blocknumber} from "../types/Blocknumber.sol";
5
+ import {Timestamp} from "../types/Timestamp.sol";
6
+ import {Version} from "../types/Version.sol";
7
+
8
+
9
+ /// IMPORTANT
10
+ // Upgradeable contract MUST:
11
+ // 1) inherit from Versionable
12
+ // 2) implement version() function
13
+ // 3) implement internal _initialize() function with onlyInitializing modifier
14
+ // 4) implement internal _upgrade() function with onlyInitializing modifier (1st version MUST revert)
15
+ // 5) have onlyInitialising modifier for each function callable inside _initialize()/_upgrade() (MUST use different functions for initialization/upgrade and normal operations)
16
+ // 6) use default empty constructor -> _disableInitializer() called from Versionable contructor
17
+ // 7) use namespace storage
18
+ //
19
+ // IMPORTANT
20
+ // Each version MUST:
21
+ // 1) ALWAYS define namespace storage struct (even if no changes were introduced)
22
+ // - DO NOT use structs inside, except
23
+ // - CAN use structs ONLY inside mappings
24
+ // 2) ALWAYS define private getter (even if no changes were introduced)
25
+ // - MUST use default implementation, CAN change ONLY return type
26
+ // - MUST use the same "LOCATION_V1"
27
+ // Optional:
28
+ // 4) implement public initialize()
29
+ // - MUST use intializer modifier
30
+ // - MUST call Versionable._updateVersionHistory()
31
+ // 5) implement public upgrade()
32
+ // - 1st version MUST revert
33
+ // - MUST use reinitializer(VersionLib.toUint64(getVersion())) modifier
34
+ // - MUST call Versionable._updateVersionHistory()
7
35
 
8
36
  interface IVersionable {
9
37
 
@@ -15,19 +43,30 @@ interface IVersionable {
15
43
  Blocknumber activatedIn;
16
44
  }
17
45
 
18
- event LogVersionableActivated(Version version, address implementation, address activatedBy);
46
+ event LogVersionableInitialized(Version version, address implementation, address activatedBy);
47
+
48
+ // TODO uncomment when all implementations are ready
49
+ /**
50
+ * @dev IMPORTANT
51
+ * implementation MUST be guarded by initializer modifier
52
+ * implementation MUST call internal function Versionable._updateVersionHistory
53
+ * new version MUST inherit from previous version
54
+ */
55
+ function initialize(address implementation, address activatedBy, bytes memory activationData) external;
19
56
 
20
57
  /**
21
- * @dev IMPORTANT this function needs to be implemented by each new version
22
- * any such activate implementation needs to call internal function call _activate()
23
- * any new version needs to inherit from previous version
58
+ * @dev
59
+ * implementation MUST be guarded by reinitializer(version().toUint64()) modifier
60
+ * implementation MUST call internal function Versionable._updateVersionHistory
61
+ * new version MUST inherit from previous version
62
+ * the first verion MUST revert
24
63
  */
25
- function activate(address implementation, address activatedBy) external;
64
+ function upgrade(address implementation, address activatedBy, bytes memory upgradeData) external;
26
65
 
27
66
  /**
28
67
  * @dev returns true if the specified version has been activated for the current contract
29
68
  */
30
- function isActivated(Version version) external view returns(bool);
69
+ function isInitialized(Version version) external view returns(bool);
31
70
 
32
71
  /**
33
72
  * @dev returns currently active version of this contract
@@ -49,4 +88,7 @@ interface IVersionable {
49
88
  */
50
89
  function getVersionInfo(Version version) external view returns(VersionInfo memory versionInfo);
51
90
 
91
+ // TODO make sure it is needed here
92
+ function getInitializedVersion() external view returns(uint64);
93
+
52
94
  }