@etherisc/gif-next 0.0.2-ce8407f-016 → 0.0.2-d243ae6-520

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/README.md +104 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +4 -0
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +314 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +610 -0
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +26 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +152 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +4 -0
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +249 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +4 -0
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +157 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +774 -0
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  17. package/artifacts/contracts/components/Product.sol/Product.json +754 -0
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.json +66 -0
  20. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.json +24 -0
  22. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.json +42 -0
  24. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  37. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  40. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  41. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  42. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +13 -0
  43. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  44. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +15 -2
  45. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  46. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  47. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +342 -1
  48. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +4 -0
  49. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +480 -0
  50. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  51. package/artifacts/contracts/instance/Instance.sol/Instance.json +489 -493
  52. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +45 -32
  54. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  55. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +438 -33
  56. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  57. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +654 -16
  58. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +4 -0
  59. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +432 -0
  60. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +4 -0
  61. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +481 -0
  62. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  63. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +113 -0
  64. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +0 -77
  66. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +10 -244
  69. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +4 -0
  78. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +827 -0
  79. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +466 -0
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  82. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +446 -0
  83. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +4 -0
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +561 -0
  85. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +4 -0
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +751 -0
  87. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  88. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +47 -2
  89. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  90. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +41 -161
  91. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  92. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +134 -7
  93. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  94. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  95. package/artifacts/contracts/registry/Registry.sol/Registry.json +62 -190
  96. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  97. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +287 -39
  98. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +61 -33
  100. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  101. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  102. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  103. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  104. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +4 -0
  106. package/artifacts/contracts/{instance/base → shared}/IService.sol/IService.json +1 -1
  107. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  109. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  110. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  111. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  112. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  113. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +6 -6
  114. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +4 -0
  115. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.json +442 -0
  116. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +4 -0
  117. package/artifacts/contracts/{instance/base/ServiceBase.sol/ServiceBase.json → shared/Service.sol/Service.json} +2 -2
  118. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  119. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  120. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  121. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  122. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  124. package/artifacts/contracts/test/TestFee.sol/TestFee.json +4 -4
  125. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  126. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +6 -6
  127. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  128. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +111 -5
  129. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  130. package/artifacts/contracts/test/TestService.sol/TestService.json +17 -17
  131. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  132. package/artifacts/contracts/test/TestToken.sol/TestUsdc.json +91 -53
  133. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  134. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  136. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  137. package/artifacts/contracts/test/Usdc.sol/USDC.json +91 -53
  138. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  139. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/Fee.sol/FeeLib.json +4 -4
  144. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  145. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  147. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  148. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  149. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  153. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +4 -0
  156. package/artifacts/contracts/types/UFixed.sol/MathLib.json +10 -0
  157. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +4 -0
  158. package/artifacts/contracts/types/UFixed.sol/{UFixedMathLib.json → UFixedLib.json} +3 -3
  159. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  161. package/contracts/components/BaseComponent.sol +86 -0
  162. package/contracts/components/Distribution.sol +166 -0
  163. package/contracts/components/IBaseComponent.sol +7 -2
  164. package/contracts/components/IDistributionComponent.sol +43 -0
  165. package/contracts/components/IPoolComponent.sol +62 -0
  166. package/contracts/components/IProductComponent.sol +35 -0
  167. package/contracts/components/Pool.sol +259 -0
  168. package/contracts/components/Product.sol +297 -0
  169. package/contracts/experiment/cloning/Cloner.sol +47 -0
  170. package/contracts/instance/AccessManagedSimple.sol +12 -4
  171. package/contracts/instance/AccessManagerSimple.sol +12 -2
  172. package/contracts/instance/IAccessManagerSimple.sol +1 -1
  173. package/contracts/instance/IInstance.sol +23 -1
  174. package/contracts/instance/IInstanceService.sol +30 -0
  175. package/contracts/instance/Instance.sol +59 -9
  176. package/contracts/instance/InstanceAccessManager.sol +2 -2
  177. package/contracts/instance/InstanceReader.sol +63 -8
  178. package/contracts/instance/InstanceService.sol +111 -18
  179. package/contracts/instance/InstanceServiceManager.sol +56 -0
  180. package/contracts/instance/base/ComponentServiceBase.sol +49 -0
  181. package/contracts/instance/base/IInstanceBase.sol +23 -0
  182. package/contracts/instance/base/IKeyValueStore.sol +5 -4
  183. package/contracts/instance/base/KeyValueStore.sol +4 -20
  184. package/contracts/instance/module/IAccess.sol +2 -2
  185. package/contracts/instance/module/ISetup.sol +3 -1
  186. package/contracts/instance/module/ITreasury.sol +1 -1
  187. package/contracts/instance/service/ComponentOwnerService.sol +317 -0
  188. package/contracts/instance/service/IComponentOwnerService.sol +20 -0
  189. package/contracts/instance/service/IDistributionService.sol +12 -0
  190. package/contracts/instance/service/IPoolService.sol +37 -0
  191. package/contracts/instance/service/IProductService.sol +107 -0
  192. package/contracts/registry/ChainNft.sol +40 -25
  193. package/contracts/registry/IRegistry.sol +5 -20
  194. package/contracts/registry/IRegistryService.sol +16 -10
  195. package/contracts/registry/Registry.sol +87 -155
  196. package/contracts/registry/RegistryService.sol +182 -107
  197. package/contracts/registry/RegistryServiceManager.sol +23 -2
  198. package/contracts/shared/ERC165.sol +1 -1
  199. package/contracts/shared/IRegisterable.sol +1 -1
  200. package/contracts/{instance/base → shared}/IService.sol +3 -3
  201. package/contracts/shared/ProxyManager.sol +3 -3
  202. package/contracts/shared/Registerable.sol +2 -2
  203. package/contracts/shared/RegisterableUpgradable.sol +16 -0
  204. package/contracts/shared/Service.sol +54 -0
  205. package/contracts/shared/TokenHandler.sol +2 -2
  206. package/contracts/shared/UpgradableProxyWithAdmin.sol +2 -2
  207. package/contracts/shared/Versionable.sol +1 -1
  208. package/contracts/test/TestFee.sol +2 -2
  209. package/contracts/test/TestRoleId.sol +6 -6
  210. package/contracts/test/TestService.sol +3 -5
  211. package/contracts/types/Fee.sol +3 -3
  212. package/contracts/types/RoleId.sol +11 -4
  213. package/contracts/types/UFixed.sol +128 -12
  214. package/package.json +4 -3
  215. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +0 -4
  216. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +0 -4
  217. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +0 -4
  218. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +0 -457
  219. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +0 -4
  220. package/contracts/instance/base/ServiceBase.sol +0 -44
  221. package/contracts/registry/IChainNft.sol +0 -22
@@ -1,19 +1,28 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import {ERC721, ERC721Enumerable} from "@openzeppelin5/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
- import {IERC721} from "@openzeppelin5/contracts/token/ERC721/IERC721.sol";
4
+ import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
+ import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
6
6
 
7
- import {IChainNft} from "./IChainNft.sol";
8
7
  import {ITransferInterceptor} from "./ITransferInterceptor.sol";
9
8
 
10
- contract ChainNft is ERC721Enumerable, IChainNft {
11
- string public constant NAME = "Dezentralized Insurance Protocol Registry";
12
- string public constant SYMBOL = "DIPR";
9
+ contract ChainNft is ERC721Enumerable {
10
+
11
+ // constants
12
+ string public constant NAME = "Dezentralized Insurance Protocol NFT";
13
+ string public constant SYMBOL = "DIPNFT";
13
14
 
14
15
  uint256 public constant PROTOCOL_NFT_ID = 1101;
15
16
  uint256 public constant GLOBAL_REGISTRY_ID = 2101;
16
17
 
18
+ // custom errors
19
+ error CallerNotRegistry(address caller);
20
+ error RegistryAddressZero();
21
+ error NftUriEmpty();
22
+ error NftUriAlreadySet();
23
+
24
+ // contract state
25
+
17
26
  // remember interceptors
18
27
  mapping(uint256 tokenId => address interceptor) private _interceptor;
19
28
 
@@ -31,17 +40,24 @@ contract ChainNft is ERC721Enumerable, IChainNft {
31
40
  uint256 internal _totalMinted;
32
41
 
33
42
  modifier onlyRegistry() {
34
- require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
43
+ if (msg.sender != _registry) { revert CallerNotRegistry(msg.sender); }
35
44
  _;
36
45
  }
37
46
 
38
47
  constructor(address registry) ERC721(NAME, SYMBOL) {
39
- require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
48
+ if (registry == address(0)) { revert RegistryAddressZero(); }
40
49
 
41
50
  _registry = registry;
42
-
43
51
  _chainIdInt = block.chainid;
44
- _chainIdDigits = _countDigits(_chainIdInt);
52
+ _chainIdDigits = 0;
53
+
54
+ // count digis
55
+ uint256 num = _chainIdInt;
56
+ while (num != 0) {
57
+ _chainIdDigits++;
58
+ num /= 10;
59
+ }
60
+
45
61
  _chainIdMultiplier = 10 ** _chainIdDigits;
46
62
  _idNext = 4;
47
63
  }
@@ -77,8 +93,8 @@ contract ChainNft is ERC721Enumerable, IChainNft {
77
93
  _uri[tokenId] = uri;
78
94
  }
79
95
 
80
- _safeMint(to, tokenId);
81
96
  _totalMinted++;
97
+ _safeMint(to, tokenId);
82
98
  }
83
99
 
84
100
 
@@ -95,7 +111,7 @@ contract ChainNft is ERC721Enumerable, IChainNft {
95
111
  }
96
112
 
97
113
 
98
- function burn(uint256 tokenId) external override onlyRegistry {
114
+ function burn(uint256 tokenId) external onlyRegistry {
99
115
  _requireOwned(tokenId);
100
116
  _burn(tokenId);
101
117
  delete _uri[tokenId];
@@ -104,29 +120,36 @@ contract ChainNft is ERC721Enumerable, IChainNft {
104
120
  function setURI(
105
121
  uint256 tokenId,
106
122
  string memory uri
107
- ) external override onlyRegistry {
108
- require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
123
+ ) external onlyRegistry {
124
+ if (bytes(uri).length == 0) { revert NftUriEmpty(); }
125
+ if (bytes(_uri[tokenId]).length > 0) { revert NftUriAlreadySet(); }
109
126
 
110
127
  _requireOwned(tokenId);
111
128
  _uri[tokenId] = uri;
112
129
  }
113
130
 
114
- function exists(uint256 tokenId) external view override returns (bool) {
131
+ function exists(uint256 tokenId) external view returns (bool) {
115
132
  return _ownerOf(tokenId) != address(0);
116
133
  }
117
134
 
118
135
  function tokenURI(
119
136
  uint256 tokenId
120
137
  ) public view override returns (string memory) {
138
+ // gif generally does not revert for view functions
139
+ // this is an exception to keep the openzeppelin nft semantics
121
140
  _requireOwned(tokenId);
122
141
  return _uri[tokenId];
123
142
  }
124
143
 
125
- function getRegistryAddress() external view override returns (address) {
144
+ function getInterceptor(uint256 tokenId) external view returns (address) {
145
+ return _interceptor[tokenId];
146
+ }
147
+
148
+ function getRegistryAddress() external view returns (address) {
126
149
  return _registry;
127
150
  }
128
151
 
129
- function totalMinted() external view override returns (uint256) {
152
+ function totalMinted() external view returns (uint256) {
130
153
  return _totalMinted;
131
154
  }
132
155
 
@@ -176,12 +199,4 @@ contract ChainNft is ERC721Enumerable, IChainNft {
176
199
  id = calculateTokenId(_idNext);
177
200
  _idNext++;
178
201
  }
179
-
180
- function _countDigits(uint256 num) private pure returns (uint256 count) {
181
- count = 0;
182
- while (num != 0) {
183
- count++;
184
- num /= 10;
185
- }
186
- }
187
202
  }
@@ -1,20 +1,19 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import {IERC165} from "@openzeppelin5/contracts/utils/introspection/IERC165.sol";
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
5
 
6
+ import {ChainNft} from "./ChainNft.sol";
6
7
  import {NftId} from "../types/NftId.sol";
7
8
  import {ObjectType} from "../types/ObjectType.sol";
8
9
  import {VersionPart} from "../types/Version.sol";
9
- import {IChainNft} from "./IChainNft.sol";
10
10
 
11
11
  interface IRegistry is IERC165 {
12
12
 
13
- event LogRegistration(NftId indexed nftId, NftId parentNftId, ObjectType objectType, bool isInterceptor, address objectAddress, address initialOwner);
13
+ event LogRegistration(ObjectInfo info);
14
14
 
15
15
  event LogServiceNameRegistration(string serviceName, VersionPart majorVersion);
16
16
 
17
- event LogApproval(NftId indexed nftId, ObjectType objectType);
18
17
 
19
18
  struct ObjectInfo {
20
19
  NftId nftId;
@@ -25,24 +24,10 @@ interface IRegistry is IERC165 {
25
24
  address initialOwner;
26
25
  bytes data;
27
26
  }// TODO delete nftId and initialOwner(if not used) from struct
27
+ // TODO strong disagree, keep nftId there (lets keep get object info return object consistent)
28
28
 
29
29
  function register(ObjectInfo memory info) external returns (NftId nftId);
30
30
 
31
- function registerFrom(
32
- address from,
33
- ObjectInfo memory info
34
- ) external returns (NftId nftId);
35
-
36
- function approve(
37
- NftId registrar,
38
- ObjectType object,
39
- ObjectType parent
40
- ) external;
41
-
42
- function allowance(
43
- NftId registrar,
44
- ObjectType object
45
- ) external view returns (bool);
46
31
 
47
32
  function getObjectCount() external view returns (uint256);
48
33
 
@@ -67,7 +52,7 @@ interface IRegistry is IERC165 {
67
52
  VersionPart majorVersion
68
53
  ) external view returns (address serviceAddress);
69
54
 
70
- function getChainNft() external view returns (IChainNft);
55
+ function getChainNft() external view returns (ChainNft);
71
56
 
72
57
  function getOwner() external view returns (address);
73
58
  }
@@ -1,14 +1,14 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import {NftId} from "../../contracts/types/NftId.sol";
5
- import {ObjectType} from "../../contracts/types/ObjectType.sol";
6
- import {RoleId} from "../../contracts/types/RoleId.sol";
7
- import {IService} from "../../contracts/instance/base/IService.sol";
8
- import {IRegistry} from "../../contracts/registry/IRegistry.sol";
4
+ import {NftId} from "../types/NftId.sol";
5
+ import {ObjectType} from "../types/ObjectType.sol";
6
+ import {RoleId} from "../types/RoleId.sol";
7
+ import {IService} from "../shared/IService.sol";
8
+ import {IRegistry} from "./IRegistry.sol";
9
9
 
10
- import {IRegisterable} from "../../contracts/shared/IRegisterable.sol";
11
- import {IBaseComponent} from "../../contracts/components/IBaseComponent.sol";
10
+ import {IRegisterable} from "../shared/IRegisterable.sol";
11
+ import {IBaseComponent} from "../components/IBaseComponent.sol";
12
12
 
13
13
  interface IRegistryService is IService {
14
14
 
@@ -16,12 +16,18 @@ interface IRegistryService is IService {
16
16
 
17
17
  function registerService(IService service) external returns(IRegistry.ObjectInfo memory info, bytes memory data);
18
18
 
19
- function registerComponent(IBaseComponent component, ObjectType componentType, address owner)
20
- external returns(IRegistry.ObjectInfo memory info, bytes memory data);
21
-
22
19
  function registerInstance(IRegisterable instance)
23
20
  external returns(IRegistry.ObjectInfo memory info, bytes memory data);
24
21
 
22
+ function registerProduct(IBaseComponent product, address owner)
23
+ external returns(IRegistry.ObjectInfo memory info, bytes memory data);
24
+
25
+ function registerPool(IBaseComponent pool, address owner)
26
+ external returns(IRegistry.ObjectInfo memory info, bytes memory data);
27
+
28
+ function registerDistribution(IBaseComponent distribution, address owner)
29
+ external returns(IRegistry.ObjectInfo memory info, bytes memory data);
30
+
25
31
  function registerPolicy(IRegistry.ObjectInfo memory info) external returns(NftId nftId); // -> easy to upgrade
26
32
 
27
33
  function registerBundle(IRegistry.ObjectInfo memory info) external returns(NftId nftId);
@@ -2,9 +2,8 @@
2
2
  pragma solidity ^0.8.20;
3
3
 
4
4
  import {IRegisterable} from "../shared/IRegisterable.sol";
5
- import {IService} from "../instance/base/IService.sol";
5
+ import {IService} from "../shared/IService.sol";
6
6
 
7
- import {IChainNft} from "./IChainNft.sol";
8
7
  import {ChainNft} from "./ChainNft.sol";
9
8
  import {IRegistry} from "./IRegistry.sol";
10
9
  import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
@@ -47,35 +46,26 @@ contract Registry is
47
46
  uint256 public constant REGISTRY_SERVICE_TOKEN_SEQUENCE_ID = 3;
48
47
  string public constant EMPTY_URI = "";
49
48
 
50
- mapping(NftId nftId => ObjectInfo info) _info;
51
- mapping(address object => NftId nftId) _nftIdByAddress;
49
+ mapping(NftId nftId => ObjectInfo info) internal _info;
50
+ mapping(address object => NftId nftId) internal _nftIdByAddress;
52
51
 
53
52
  mapping(NftId registrator => mapping(
54
- ObjectType objectType => bool)) _isApproved;
53
+ ObjectType objectType => bool)) internal _isApproved;
55
54
 
56
55
  mapping(ObjectType objectType => mapping(
57
- ObjectType parentType => bool)) _isValidContractCombination;
56
+ ObjectType parentType => bool)) internal _isValidContractCombination;
58
57
 
59
58
  mapping(ObjectType objectType => mapping(
60
- ObjectType parentType => bool)) _isValidObjectCombination;
59
+ ObjectType parentType => bool)) internal _isValidObjectCombination;
61
60
 
62
- mapping(NftId nftId => string name) _string;
61
+ mapping(NftId nftId => string name) internal _string;
63
62
  mapping(bytes32 serviceNameHash => mapping(
64
- VersionPart majorVersion => address service)) _service;
63
+ VersionPart majorVersion => address service)) internal _service;
65
64
 
66
- NftId _registryNftId;
67
- NftId _serviceNftId; // set in stone upon registry creation
68
- IChainNft _chainNft;
69
- ChainNft _chainNftInternal;
65
+ NftId internal _registryNftId;
66
+ NftId internal _serviceNftId; // set in stone upon registry creation
67
+ ChainNft internal _chainNft;
70
68
 
71
- /*
72
- modifier onlyInitialOwner() {
73
- if(
74
- msg.sender != getOwner() ||
75
- msg.sender != _info[_registryNftId].initialOwner) {
76
- revert NotInitialOwner();
77
- }
78
- }*/
79
69
 
80
70
  modifier onlyOwner() {
81
71
  if(msg.sender != getOwner()) {
@@ -98,8 +88,7 @@ contract Registry is
98
88
  require(majorVersion.toInt() == MAJOR_VERSION_MIN, "Registry: initial major version of registry service is not MAJOR_VERSION_MIN");
99
89
 
100
90
  // deploy NFT
101
- _chainNftInternal = new ChainNft(address(this));// adds 10kb to deployment size
102
- _chainNft = IChainNft(_chainNftInternal);
91
+ _chainNft = new ChainNft(address(this));// adds 10kb to deployment size
103
92
 
104
93
  // initial registry setup
105
94
  _registerProtocol();
@@ -113,8 +102,6 @@ contract Registry is
113
102
  }
114
103
 
115
104
  /// @dev registry protects only against tampering existing records, registering with invalid types pairs and 0 parent address
116
- // IMPORTANT: rare case when parentNftId is not registered and == next nftId -> technincally this is ZeroParentAddress error
117
- // to catch this check parent address before minting !!!!
118
105
  // TODO service registration means its approval for some type?
119
106
  // TODO registration of precompile addresses
120
107
  function register(ObjectInfo memory info)
@@ -139,8 +126,6 @@ contract Registry is
139
126
  address interceptor = _getInterceptor(info.isInterceptor, info.objectAddress, parentInfo.isInterceptor, parentAddress);
140
127
 
141
128
  // TODO does external call
142
- // check for receiver in registry service?
143
- // use unsafe transfer?
144
129
  uint256 mintedTokenId = _chainNft.mint(
145
130
  info.initialOwner,
146
131
  interceptor,
@@ -170,33 +155,8 @@ contract Registry is
170
155
  _nftIdByAddress[contractAddress] = nftId;
171
156
 
172
157
  // special case
173
- if(objectType == SERVICE())
174
- {
175
- (
176
- string memory serviceName,
177
- VersionPart majorVersion
178
- ) = abi.decode(info.data, (string, VersionPart));
179
- bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
180
-
181
- // TODO MUST guarantee consistency of service.getVersion() and majorVersion here
182
- // TODO update _serviceNftId when registryService with new major version is registered? -> it is fixed in current setup
183
- // TODO do not use names -> each object type is registered by corresponding service -> conflicting with approve()
184
- if(
185
- majorVersion.toInt() < MAJOR_VERSION_MIN ||
186
- (majorVersion.toInt() > MAJOR_VERSION_MIN &&
187
- _service[serviceNameHash][VersionLib.toVersionPart(majorVersion.toInt() - 1)] == address(0) )
188
- ) {
189
- revert InvalidServiceVersion(majorVersion);
190
- }
191
-
192
- if(_service[serviceNameHash][majorVersion] != address(0)) {
193
- revert ServiceNameAlreadyRegistered(serviceName, majorVersion);
194
- }
195
-
196
- _string[nftId] = serviceName;
197
- _service[serviceNameHash][majorVersion] = contractAddress;
198
-
199
- emit LogServiceNameRegistration(serviceName, majorVersion);
158
+ if(objectType == SERVICE()) {
159
+ _registerService(info);
200
160
  }
201
161
  }
202
162
  else
@@ -206,67 +166,7 @@ contract Registry is
206
166
  }
207
167
  }
208
168
 
209
- emit LogRegistration(nftId, info.parentNftId, info.objectType, info.isInterceptor, info.objectAddress, info.initialOwner);
210
- }
211
-
212
- function registerFrom(
213
- address from,
214
- ObjectInfo memory info
215
- ) external returns (NftId nftId)
216
- {
217
- revert();
218
- }
219
-
220
-
221
- /// @dev
222
- // msg.sender - registry owner
223
- // CAN approve only registered service contract
224
- // CAN approve any combination specified in _isValidCombination
225
- // CAN NOT approve itself
226
- // TODO in case where exists exactly one registered service per objectType (and major version):
227
- // - registration and approve is a single operation, no need for separate approve() function
228
- // - then approve can be used to adding new valid object-parent combinations???
229
- function approve(
230
- NftId serviceNftId,
231
- ObjectType objectType,
232
- ObjectType parentType
233
- )
234
- public
235
- onlyOwner()
236
- {
237
- address serviceAddress = _info[serviceNftId].objectAddress;
238
-
239
- if(_nftIdByAddress[serviceAddress].eqz()) {
240
- revert NotRegisteredContract(serviceNftId);
241
- }
242
-
243
- if(_info[serviceNftId].objectType != SERVICE()) {
244
- revert NotService(serviceNftId);
245
- }
246
-
247
- if(
248
- _isValidContractCombination[objectType][parentType] == false &&
249
- _isValidObjectCombination[objectType][parentType] == false) {
250
- revert InvalidTypesCombination(objectType, parentType);
251
- }
252
-
253
- _isApproved[serviceNftId][objectType] = true;
254
-
255
- emit LogApproval(serviceNftId, objectType);
256
- }
257
-
258
- /// @dev returns false for registry owner nft
259
- // TODO allowance by address?
260
- // TODO checked by registry service -> but registry owner can upgrade registry service not to check allowance....
261
- function allowance(
262
- NftId nftId,
263
- ObjectType object
264
- )
265
- public
266
- view
267
- returns (bool)
268
- {
269
- return _isApproved[nftId][object];
169
+ emit LogRegistration(info);
270
170
  }
271
171
 
272
172
  // from IRegistry
@@ -319,7 +219,7 @@ contract Registry is
319
219
  return _service[serviceNameHash][majorVersion];
320
220
  }
321
221
 
322
- function getChainNft() external view override returns (IChainNft) {
222
+ function getChainNft() external view override returns (ChainNft) {
323
223
  return _chainNft;
324
224
  }
325
225
 
@@ -327,16 +227,74 @@ contract Registry is
327
227
  return ownerOf(address(this));
328
228
  }
329
229
 
330
- // Internals, called only in constructor
230
+ // Internals
231
+
232
+ function _registerService(ObjectInfo memory info)
233
+ internal
234
+ {
235
+ (
236
+ string memory serviceName,
237
+ VersionPart majorVersion
238
+ ) = abi.decode(info.data, (string, VersionPart));
239
+ bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
240
+
241
+ // TODO MUST guarantee consistency of service.getVersion() and majorVersion here
242
+ // TODO update _serviceNftId when registryService with new major version is registered? -> it is fixed in current setup -> can lock up
243
+ // TODO do not use names -> each object type is registered by corresponding service -> conflicting with approve()
244
+ if(
245
+ majorVersion.toInt() < MAJOR_VERSION_MIN ||
246
+ (majorVersion.toInt() > MAJOR_VERSION_MIN &&
247
+ _service[serviceNameHash][VersionLib.toVersionPart(majorVersion.toInt() - 1)] == address(0) )
248
+ ) {
249
+ revert InvalidServiceVersion(majorVersion);
250
+ }
251
+
252
+ if(_service[serviceNameHash][majorVersion] != address(0)) {
253
+ revert ServiceNameAlreadyRegistered(serviceName, majorVersion);
254
+ }
255
+
256
+ _string[info.nftId] = serviceName;
257
+ _service[serviceNameHash][majorVersion] = info.objectAddress;
258
+
259
+ emit LogServiceNameRegistration(serviceName, majorVersion);
260
+ }
261
+
262
+ /// @dev obtain interceptor address for this nft if applicable, address(0) otherwise
263
+ function _getInterceptor(
264
+ bool isInterceptor,
265
+ address objectAddress,
266
+ bool parentIsInterceptor,
267
+ address parentObjectAddress
268
+ )
269
+ internal
270
+ view
271
+ returns (address interceptor)
272
+ {
273
+ if (objectAddress == address(0)) {
274
+ if (parentIsInterceptor) {
275
+ return parentObjectAddress;
276
+ } else {
277
+ return address(0);
278
+ }
279
+ }
280
+
281
+ if (isInterceptor) {
282
+ return objectAddress;
283
+ }
284
+
285
+ return address(0);
286
+ }
287
+
288
+ // Internals called only in constructor
331
289
 
332
290
  /// @dev protocol registration used to anchor the dip ecosystem relations
333
291
  function _registerProtocol()
334
292
  internal
335
293
  {
336
- uint256 protocolId = _chainNftInternal.PROTOCOL_NFT_ID();
294
+ uint256 protocolId = _chainNft.PROTOCOL_NFT_ID();
337
295
  NftId protocolNftId = toNftId(protocolId);
338
296
 
339
- _chainNftInternal.mint(NFT_LOCK_ADDRESS, protocolId);
297
+ _chainNft.mint(NFT_LOCK_ADDRESS, protocolId);
340
298
 
341
299
  _info[protocolNftId] = ObjectInfo(
342
300
  protocolNftId,
@@ -354,22 +312,22 @@ contract Registry is
354
312
  function _registerRegistry(address registryOwner)
355
313
  internal
356
314
  {
357
- uint256 registryId = _chainNftInternal.calculateTokenId(2);
315
+ uint256 registryId = _chainNft.calculateTokenId(2);
358
316
  NftId registryNftId = toNftId(registryId);
359
317
 
360
318
  NftId parentNftId;
361
319
 
362
- if(registryId != _chainNftInternal.GLOBAL_REGISTRY_ID())
320
+ if(registryId != _chainNft.GLOBAL_REGISTRY_ID())
363
321
  {// we're not the global registry
364
322
  _registerGlobalRegistry();
365
- parentNftId = toNftId(_chainNftInternal.GLOBAL_REGISTRY_ID());
323
+ parentNftId = toNftId(_chainNft.GLOBAL_REGISTRY_ID());
366
324
  }
367
325
  else
368
326
  {// we are global registry
369
- parentNftId = toNftId(_chainNftInternal.PROTOCOL_NFT_ID());
327
+ parentNftId = toNftId(_chainNft.PROTOCOL_NFT_ID());
370
328
  }
371
329
 
372
- _chainNftInternal.mint(registryOwner, registryId);
330
+ _chainNft.mint(registryOwner, registryId);
373
331
 
374
332
  _info[registryNftId] = ObjectInfo(
375
333
  registryNftId,
@@ -389,15 +347,15 @@ contract Registry is
389
347
  function _registerGlobalRegistry()
390
348
  internal
391
349
  {
392
- uint256 globalRegistryId = _chainNftInternal.GLOBAL_REGISTRY_ID();
350
+ uint256 globalRegistryId = _chainNft.GLOBAL_REGISTRY_ID();
393
351
 
394
- _chainNftInternal.mint(NFT_LOCK_ADDRESS, globalRegistryId);
352
+ _chainNft.mint(NFT_LOCK_ADDRESS, globalRegistryId);
395
353
 
396
354
  NftId globalRegistryNftId = toNftId(globalRegistryId);
397
355
 
398
356
  _info[globalRegistryNftId] = ObjectInfo(
399
357
  globalRegistryNftId,
400
- toNftId(_chainNftInternal.PROTOCOL_NFT_ID()), // parent
358
+ toNftId(_chainNft.PROTOCOL_NFT_ID()), // parent
401
359
  REGISTRY(),
402
360
  false, // isInterceptor
403
361
  address(0), // objectAddress
@@ -409,10 +367,10 @@ contract Registry is
409
367
  function _registerRegistryService(address registryOwner)
410
368
  internal
411
369
  {
412
- uint256 serviceId = _chainNftInternal.calculateTokenId(REGISTRY_SERVICE_TOKEN_SEQUENCE_ID);
370
+ uint256 serviceId = _chainNft.calculateTokenId(REGISTRY_SERVICE_TOKEN_SEQUENCE_ID);
413
371
  NftId serviceNftId = toNftId(serviceId);
414
372
 
415
- _chainNftInternal.mint(registryOwner, serviceId);
373
+ _chainNft.mint(registryOwner, serviceId);
416
374
 
417
375
  _info[serviceNftId] = ObjectInfo(
418
376
  serviceNftId,
@@ -433,32 +391,6 @@ contract Registry is
433
391
  _serviceNftId = serviceNftId;
434
392
  }
435
393
 
436
- /// @dev obtain interceptor address for this nft if applicable, address(0) otherwise
437
- function _getInterceptor(
438
- bool isInterceptor,
439
- address objectAddress,
440
- bool parentIsInterceptor,
441
- address parentObjectAddress
442
- )
443
- internal
444
- view
445
- returns (address interceptor)
446
- {
447
- if (objectAddress == address(0)) {
448
- if (parentIsInterceptor) {
449
- return parentObjectAddress;
450
- } else {
451
- return address(0);
452
- }
453
- }
454
-
455
- if (isInterceptor) {
456
- return objectAddress;
457
- }
458
-
459
- return address(0);
460
- }
461
-
462
394
  /// @dev defines which object - parent types relations are allowed to register
463
395
  // IMPORTANT:
464
396
  // 1) EACH object type MUST have only one parent type across ALL mappings