@etherisc/gif-next 0.0.2-bf75dbb-287 → 0.0.2-c2a8d66-341

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  2. package/artifacts/contracts/components/{IBaseComponent.sol/IBaseComponent.json → Component.sol/Component.json} +300 -12
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +199 -94
  5. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +4 -0
  6. package/artifacts/contracts/components/{BaseComponent.sol/BaseComponent.json → IComponent.sol/IComponent.json} +86 -84
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +496 -0
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +512 -74
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +596 -5
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +180 -205
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +204 -110
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  37. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  38. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +38 -62
  39. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  40. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  41. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +284 -2
  42. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +115 -19
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +117 -601
  46. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  47. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +416 -186
  48. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  49. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +41 -82
  50. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  51. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +253 -226
  52. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +38 -97
  54. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  55. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +8 -32
  56. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +4 -0
  57. package/artifacts/contracts/instance/base/{ComponentServiceBase.sol/ComponentServiceBase.json → ComponentService.sol/ComponentService.json} +124 -61
  58. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  59. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  62. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +65 -44
  64. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  68. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  71. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1102 -0
  72. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  73. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +449 -0
  74. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +149 -93
  76. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +29 -36
  78. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  79. package/artifacts/contracts/instance/service/{IComponentOwnerService.sol/IComponentOwnerService.json → IBundleService.sol/IBundleService.json} +295 -46
  80. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +13 -18
  82. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  83. package/artifacts/contracts/{shared/RegisterableUpgradable.sol/RegisterableUpgradable.json → instance/service/IPolicyService.sol/IPolicyService.json} +372 -48
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +12 -246
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +17 -246
  88. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  89. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +1227 -0
  90. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  91. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +505 -0
  92. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +126 -369
  94. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +29 -56
  96. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +137 -428
  98. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +29 -80
  100. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  103. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +231 -133
  104. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +127 -93
  106. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  107. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  108. package/artifacts/contracts/registry/Registry.sol/Registry.json +243 -234
  109. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  110. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  111. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  112. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +68 -161
  113. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  114. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +51 -104
  115. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  116. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +547 -0
  117. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  118. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +13 -29
  119. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  120. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  121. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  122. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.json +0 -5
  124. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  125. package/artifacts/contracts/shared/IService.sol/IService.json +13 -18
  126. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  128. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +19 -6
  129. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  130. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +19 -6
  131. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +19 -11
  133. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  134. package/artifacts/contracts/shared/Service.sol/Service.json +26 -18
  135. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  136. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  137. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  139. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  140. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +19 -11
  141. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +6 -6
  143. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestService.sol/TestService.json +44 -36
  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/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  148. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  149. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  150. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  155. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  157. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  163. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  169. package/contracts/components/Component.sol +216 -0
  170. package/contracts/components/Distribution.sol +41 -51
  171. package/contracts/components/IComponent.sol +43 -0
  172. package/contracts/components/IDistributionComponent.sol +5 -2
  173. package/contracts/components/IPoolComponent.sol +6 -21
  174. package/contracts/components/IProductComponent.sol +7 -3
  175. package/contracts/components/Pool.sol +50 -109
  176. package/contracts/components/Product.sol +66 -89
  177. package/contracts/instance/BundleManager.sol +7 -11
  178. package/contracts/instance/IInstance.sol +25 -9
  179. package/contracts/instance/IInstanceService.sol +12 -4
  180. package/contracts/instance/Instance.sol +45 -230
  181. package/contracts/instance/InstanceAccessManager.sol +333 -166
  182. package/contracts/instance/InstanceReader.sol +3 -25
  183. package/contracts/instance/InstanceService.sol +352 -143
  184. package/contracts/instance/InstanceServiceManager.sol +5 -8
  185. package/contracts/instance/ObjectManager.sol +7 -24
  186. package/contracts/instance/base/ComponentService.sol +134 -0
  187. package/contracts/instance/module/IAccess.sol +36 -20
  188. package/contracts/instance/service/BundleService.sol +293 -0
  189. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  190. package/contracts/instance/service/DistributionService.sol +43 -25
  191. package/contracts/instance/service/DistributionServiceManager.sol +6 -9
  192. package/contracts/instance/service/IBundleService.sol +44 -0
  193. package/contracts/instance/service/IPolicyService.sol +94 -0
  194. package/contracts/instance/service/IPoolService.sol +2 -33
  195. package/contracts/instance/service/IProductService.sol +2 -72
  196. package/contracts/instance/service/PolicyService.sol +538 -0
  197. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  198. package/contracts/instance/service/PoolService.sol +33 -210
  199. package/contracts/instance/service/PoolServiceManager.sol +5 -8
  200. package/contracts/instance/service/ProductService.sol +122 -459
  201. package/contracts/registry/ChainNft.sol +1 -1
  202. package/contracts/registry/IRegistry.sol +36 -17
  203. package/contracts/registry/IRegistryService.sol +28 -13
  204. package/contracts/registry/Registry.sol +227 -218
  205. package/contracts/registry/RegistryAccessManager.sol +216 -0
  206. package/contracts/registry/RegistryService.sol +61 -157
  207. package/contracts/registry/RegistryServiceManager.sol +18 -36
  208. package/contracts/registry/ReleaseManager.sol +332 -0
  209. package/contracts/registry/TokenRegistry.sol +8 -7
  210. package/contracts/shared/IRegisterable.sol +1 -3
  211. package/contracts/shared/IService.sol +2 -1
  212. package/contracts/shared/NftOwnable.sol +5 -0
  213. package/contracts/shared/ProxyManager.sol +1 -1
  214. package/contracts/shared/Registerable.sol +10 -14
  215. package/contracts/shared/Service.sol +13 -8
  216. package/contracts/test/TestService.sol +3 -2
  217. package/contracts/types/RoleId.sol +18 -15
  218. package/package.json +3 -3
  219. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +0 -4
  220. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +0 -4
  221. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +0 -4
  222. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +0 -1206
  223. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
  224. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
  225. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +0 -4
  226. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +0 -448
  227. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +0 -4
  228. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +0 -763
  229. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +0 -4
  230. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +0 -4
  231. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +0 -113
  232. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +0 -4
  233. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +0 -827
  234. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +0 -4
  235. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +0 -4
  236. package/contracts/components/BaseComponent.sol +0 -132
  237. package/contracts/components/IBaseComponent.sol +0 -31
  238. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +0 -23
  239. package/contracts/instance/IAccessManagerSimple.sol +0 -391
  240. package/contracts/instance/IInstanceBase.sol +0 -26
  241. package/contracts/instance/InstanceBase.sol +0 -41
  242. package/contracts/instance/base/ComponentServiceBase.sol +0 -134
  243. package/contracts/instance/base/IInstanceBase.sol +0 -23
  244. package/contracts/instance/service/ComponentOwnerService.sol +0 -317
  245. package/contracts/instance/service/IComponentOwnerService.sol +0 -20
  246. package/contracts/shared/RegisterableUpgradable.sol +0 -16
@@ -1,288 +1,455 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {AccessManager} from "@openzeppelin/contracts/access/manager/AccessManager.sol";
5
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
4
6
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
5
7
  import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
- import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
7
- import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
8
-
9
- import {IBundle} from "./module/IBundle.sol";
10
- import {IPolicy} from "./module/IPolicy.sol";
11
- import {IRisk} from "./module/IRisk.sol";
12
- import {ISetup} from "./module/ISetup.sol";
13
- import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
14
- import {KeyValueStore} from "./base/KeyValueStore.sol";
8
+
9
+ import {RoleId, RoleIdLib, ADMIN_ROLE, PUBLIC_ROLE, INSTANCE_SERVICE_ROLE, INSTANCE_OWNER_ROLE} from "../types/RoleId.sol";
10
+ import {TimestampLib} from "../types/Timestamp.sol";
15
11
  import {NftId} from "../types/NftId.sol";
16
- import {NumberId} from "../types/NumberId.sol";
17
- import {ObjectType, BUNDLE, DISTRIBUTION, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
18
- import {RiskId, RiskIdLib} from "../types/RiskId.sol";
19
- import {RoleId, RoleIdLib} from "../types/RoleId.sol";
20
- import {StateId, ACTIVE} from "../types/StateId.sol";
21
- import {Timestamp, TimestampLib} from "../types/Timestamp.sol";
12
+
13
+ import {IAccess} from "./module/IAccess.sol";
14
+ import {IRegistry} from "../registry/IRegistry.sol";
22
15
 
23
16
  contract InstanceAccessManager is
24
17
  AccessManagedUpgradeable
25
18
  {
19
+ using RoleIdLib for RoleId;
20
+
26
21
  string public constant ADMIN_ROLE_NAME = "AdminRole";
27
22
  string public constant PUBLIC_ROLE_NAME = "PublicRole";
28
23
 
29
24
  uint64 public constant CUSTOM_ROLE_ID_MIN = 10000;
30
25
  uint32 public constant EXECUTION_DELAY = 0;
31
26
 
32
- struct RoleInfo {
33
- ShortString name;
34
- bool isCustom;
35
- bool isLocked;
36
- Timestamp createdAt;
37
- Timestamp updatedAt;
38
- }
39
-
40
- struct TargetInfo {
41
- ShortString name;
42
- bool isCustom;
43
- bool isLocked;
44
- Timestamp createdAt;
45
- Timestamp updatedAt;
46
- }
47
-
48
- error ErrorRoleIdInvalid(RoleId roleId);
49
- error ErrorRoleIdTooBig(RoleId roleId);
50
- error ErrorRoleIdTooSmall(RoleId roleId);
51
- error ErrorRoleIdAlreadyExists(RoleId roleId, ShortString name);
52
- error ErrorRoleIdNotActive(RoleId roleId);
53
- error ErrorRoleNameEmpty(RoleId roleId);
54
- error ErrorRoleNameNotUnique(RoleId roleId, ShortString name);
55
- error ErrorRoleInvalidUpdate(RoleId roleId, bool isCustom);
56
- error ErrorRoleIsCustomIsImmutable(RoleId roleId, bool isCustom, bool isCustomExisting);
57
- error ErrorSetLockedForNonexstentRole(RoleId roleId);
58
- error ErrorGrantNonexstentRole(RoleId roleId);
59
- error ErrorRevokeNonexstentRole(RoleId roleId);
60
- error ErrorRenounceNonexstentRole(RoleId roleId);
61
-
62
- error ErrorTargetAddressZero();
63
- error ErrorTargetAlreadyExists(address target, ShortString name);
64
- error ErrorTargetNameEmpty(address target);
65
- error ErrorTargetNameExists(address target, address existingTarget, ShortString name);
66
- error ErrorSetLockedForNonexstentTarget(address target);
67
-
68
27
  // role specific state
69
- mapping(RoleId roleId => RoleInfo info) internal _role;
28
+ mapping(RoleId roleId => IAccess.RoleInfo info) internal _roleInfo;
70
29
  mapping(RoleId roleId => EnumerableSet.AddressSet roleMembers) internal _roleMembers;
71
- mapping(ShortString name => RoleId roleId) internal _roleForName;
72
- RoleId [] internal _roles;
30
+ mapping(ShortString name => RoleId roleId) internal _roleIdForName;
31
+ RoleId [] internal _roleIds;
32
+ uint64 _idNext;
73
33
 
74
34
  // target specific state
75
- mapping(address target => TargetInfo info) internal _target;
76
- mapping(ShortString name => address target) internal _targetForName;
35
+ mapping(address target => IAccess.TargetInfo info) internal _targetInfo;
36
+ mapping(ShortString name => address target) internal _targetAddressForName;
77
37
  address [] internal _targets;
78
38
 
79
- AccessManagerUpgradeable internal _accessManager;
39
+ AccessManager internal _accessManager;
40
+ IRegistry internal _registry;
80
41
 
81
- constructor(address accessManager)
42
+ modifier restrictedToRoleAdmin(RoleId roleId) {
43
+ RoleId admin = getRoleAdmin(roleId);
44
+ (bool inRole, uint32 executionDelay) = _accessManager.hasRole(admin.toInt(), _msgSender());
45
+ assert(executionDelay == 0); // to be sure no delayed execution functionality is used
46
+ if (!inRole) {
47
+ revert IAccess.ErrorIAccessCallerIsNotRoleAdmin(_msgSender(), roleId);
48
+ }
49
+ _;
50
+ }
51
+
52
+ function initialize(address initialAdmin, address registry) external initializer
82
53
  {
83
- _accessManager = AccessManagerUpgradeable(accessManager);
84
- __AccessManaged_init(accessManager);
54
+ require(initialAdmin != address(0));
55
+ require(registry != address(0));
85
56
 
86
- _createRole(RoleIdLib.toRoleId(_accessManager.ADMIN_ROLE()), ADMIN_ROLE_NAME, false, false);
87
- _createRole(RoleIdLib.toRoleId(_accessManager.PUBLIC_ROLE()), PUBLIC_ROLE_NAME, false, false);
88
- }
57
+ // if size of the contract gets too large, this can be externalized which will reduce the contract size considerably
58
+ _accessManager = new AccessManager(address(this));
89
59
 
90
- //--- Role ------------------------------------------------------//
60
+ __AccessManaged_init(address(_accessManager));
91
61
 
92
- function createDefaultRole(RoleId roleId, string memory name) external restricted() {
93
- _createRole(roleId, name, false, true);
94
- }
62
+ _registry = IRegistry(registry);
63
+ _idNext = CUSTOM_ROLE_ID_MIN;
95
64
 
96
- function createRole(RoleId roleId, string memory name) external restricted() {
97
- _createRole(roleId, name, true, true);
98
- }
65
+ _createRole(ADMIN_ROLE(), ADMIN_ROLE_NAME, IAccess.Type.Core);
66
+ _createRole(PUBLIC_ROLE(), PUBLIC_ROLE_NAME, IAccess.Type.Core);
99
67
 
100
- function setRoleLocked(RoleId roleId, bool locked) external restricted() {
101
- if (!roleExists(roleId)) {
102
- revert ErrorSetLockedForNonexstentRole(roleId);
103
- }
68
+ // assume initialAdmin is instance service which requires admin rights to access manager during instance cloning
69
+ _accessManager.grantRole(ADMIN_ROLE().toInt(), initialAdmin, 0);
104
70
 
105
- _role[roleId].isLocked = locked;
106
- _role[roleId].updatedAt = TimestampLib.blockTimestamp();
71
+ EnumerableSet.add(_roleMembers[ADMIN_ROLE()], address(this));
72
+ EnumerableSet.add(_roleMembers[ADMIN_ROLE()], initialAdmin);
107
73
  }
108
74
 
109
- function roleExists(RoleId roleId) public view returns (bool exists) {
110
- return _role[roleId].createdAt.gtz();
75
+ //--- Role ------------------------------------------------------//
76
+ // INSTANCE_SERVICE_ROLE
77
+ // assume core roles are never revoked or renounced -> core roles admin is never active after intialization
78
+ function createCoreRole(RoleId roleId, string memory name, RoleId admin)
79
+ external
80
+ restricted()
81
+ {
82
+ _validateRoleParameters(roleId, name, IAccess.Type.Core);// TODO put inside _createRole
83
+ _createRole(roleId, name, IAccess.Type.Core);
84
+ setRoleAdmin(roleId, admin);
85
+ }
86
+ // INSTANCE_SERVICE_ROLE
87
+ // assume gif roles can be revoked or renounced
88
+ function createGifRole(RoleId roleId, string memory name, RoleId admin)
89
+ external
90
+ restricted()
91
+ {
92
+ _validateRoleParameters(roleId, name, IAccess.Type.Gif);
93
+ _createRole(roleId, name, IAccess.Type.Gif);
94
+ setRoleAdmin(roleId, admin);
111
95
  }
112
96
 
113
- function grantRole(RoleId roleId, address member) external restricted() returns (bool granted) {
114
- if (!roleExists(roleId)) {
115
- revert ErrorGrantNonexstentRole(roleId);
116
- }
97
+ // INSTANCE_OWNER_ROLE
98
+ // creates custom roles only
99
+ // TODO INSTANCE_OWNER_ROLE as default admin
100
+ function createCustomRole(string memory name, RoleId admin)
101
+ external
102
+ restricted()
103
+ returns(RoleId roleId)
104
+ {
105
+ RoleId roleId = _getNextCustomRoleId();
106
+ _validateRoleParameters(roleId, name, IAccess.Type.Custom);
107
+ _createRole(roleId, name, IAccess.Type.Custom);
108
+ setRoleAdmin(roleId, admin);
109
+ }
117
110
 
118
- if (_role[roleId].isLocked) {
119
- revert ErrorRoleIdNotActive(roleId);
111
+ // TODO MUST always be restricted to ADMIN_ROLE? -> use onlyAdminRole or use similar _getAdminRestrictions()
112
+ function setRoleAdmin(RoleId roleId, RoleId admin)
113
+ public
114
+ restricted()
115
+ {
116
+ if (!roleExists(roleId)) {
117
+ revert IAccess.ErrorIAccessRoleIdInvalid(roleId);
120
118
  }
121
119
 
122
- if (!EnumerableSet.contains(_roleMembers[roleId], member)) {
123
- _accessManager.grantRole(roleId.toInt(), member, EXECUTION_DELAY);
124
- EnumerableSet.add(_roleMembers[roleId], member);
125
- return true;
126
- }
120
+ if (!roleExists(admin)) {
121
+ revert IAccess.ErrorIAccessRoleIdInvalid(admin);
122
+ }
127
123
 
128
- return false;
124
+ _roleInfo[roleId].admin = admin;
129
125
  }
130
126
 
131
- function revokeRole(RoleId roleId, address member) external restricted() returns (bool revoked) {
127
+ // TODO notify member?
128
+ // TODO granting/revoking can be `attached` to nft transfer?
129
+ function grantRole(RoleId roleId, address member)
130
+ external
131
+ restrictedToRoleAdmin(roleId)
132
+ returns (bool granted)
133
+ {
132
134
  if (!roleExists(roleId)) {
133
- revert ErrorRevokeNonexstentRole(roleId);
135
+ revert IAccess.ErrorIAccessRoleIdInvalid(roleId);
134
136
  }
135
137
 
136
- if (EnumerableSet.contains(_roleMembers[roleId], member)) {
137
- _accessManager.revokeRole(roleId.toInt(), member);
138
- EnumerableSet.remove(_roleMembers[roleId], member);
139
- return true;
140
- }
138
+ granted = EnumerableSet.add(_roleMembers[roleId], member);
139
+ if(granted) {
140
+ _accessManager.grantRole(roleId.toInt(), member, EXECUTION_DELAY);
141
+ }
142
+ }
141
143
 
142
- return false;
144
+ function revokeRole(RoleId roleId, address member)
145
+ external
146
+ restrictedToRoleAdmin(roleId)
147
+ returns (bool)
148
+ {
149
+ return _revokeRole(roleId, member);
143
150
  }
144
151
 
145
152
  /// @dev not restricted function by intention
146
- /// the restriction to role members is already enforced by the call to the access manger
147
- function renounceRole(RoleId roleId) external returns (bool revoked) {
153
+ /// the restriction to role members is already enforced by the call to the access manager
154
+ function renounceRole(RoleId roleId)
155
+ external
156
+ returns (bool)
157
+ {
148
158
  address member = msg.sender;
159
+ // cannot use accessManger.renounce as it directly checks against msg.sender
160
+ return _revokeRole(roleId, member);
161
+ }
149
162
 
150
- if (!roleExists(roleId)) {
151
- revert ErrorRenounceNonexstentRole(roleId);
152
- }
163
+ function roleExists(RoleId roleId) public view returns (bool exists) {
164
+ return _roleInfo[roleId].createdAt.gtz();
165
+ }
153
166
 
154
- if (EnumerableSet.contains(_roleMembers[roleId], member)) {
155
- // cannot use accessManger.renounce as it directly checks against msg.sender
156
- _accessManager.revokeRole(roleId.toInt(), member);
157
- EnumerableSet.remove(_roleMembers[roleId], member);
158
- return true;
159
- }
167
+ function getRoleAdmin(RoleId roleId) public view returns(RoleId admin) {
168
+ return _roleInfo[roleId].admin;
169
+ }
160
170
 
161
- return false;
171
+ function getRoleInfo(RoleId roleId) external view returns (IAccess.RoleInfo memory role) {
172
+ return _roleInfo[roleId];
162
173
  }
163
174
 
164
- function roles() external view returns (uint256 numberOfRoles) {
165
- return _roles.length;
175
+ function roleMembers(RoleId roleId) external view returns (uint256 numberOfMembers) {
176
+ return EnumerableSet.length(_roleMembers[roleId]);
166
177
  }
167
178
 
168
179
  function getRoleId(uint256 idx) external view returns (RoleId roleId) {
169
- return _roles[idx];
180
+ return _roleIds[idx];
170
181
  }
171
182
 
172
183
  function getRoleIdForName(string memory name) external view returns (RoleId roleId) {
173
- return _roleForName[ShortStrings.toShortString(name)];
184
+ return _roleIdForName[ShortStrings.toShortString(name)];
174
185
  }
175
186
 
176
- function getRole(RoleId roleId) external view returns (RoleInfo memory role) {
177
- return _role[roleId];
187
+ function roleMember(RoleId roleId, uint256 idx) external view returns (address roleMember) {
188
+ return EnumerableSet.at(_roleMembers[roleId], idx);
178
189
  }
179
190
 
180
191
  function hasRole(RoleId roleId, address account) external view returns (bool accountHasRole) {
181
192
  (accountHasRole, ) = _accessManager.hasRole(roleId.toInt(), account);
182
193
  }
183
194
 
184
- function roleMembers(RoleId roleId) external view returns (uint256 numberOfMembers) {
185
- return EnumerableSet.length(_roleMembers[roleId]);
186
- }
187
-
188
- function getRoleMember(RoleId roleId, uint256 idx) external view returns (address roleMember) {
189
- return EnumerableSet.at(_roleMembers[roleId], idx);
195
+ function roles() external view returns (uint256 numberOfRoles) {
196
+ return _roleIds.length;
190
197
  }
191
198
 
192
199
  //--- Target ------------------------------------------------------//
193
- function createTarget(address target, string memory name) external restricted() {
194
- _createTarget(target, name, true, true);
200
+ // INSTANCE_SERVICE_ROLE
201
+ function createCoreTarget(address target, string memory name) external restricted() {
202
+ _createTarget(target, name, IAccess.Type.Core);
195
203
  }
204
+ // INSTANCE_SERVICE_ROLE
205
+ function createGifTarget(address target, string memory name) external restricted() {
206
+ _createTarget(target, name, IAccess.Type.Gif);
207
+ }
208
+ // INSTANCE_OWNER_ROLE
209
+ function createCustomTarget(address target, string memory name)
210
+ external
211
+ restricted()
212
+ {
213
+ // TODO custom targets can not be registered before this function, but possibly can after...
214
+ if(_registry.isRegistered(target)) {
215
+ revert IAccess.ErrorIAccessTargetIsRegistered(target);
216
+ }
196
217
 
197
- function setTargetLocked(address target, bool locked) external restricted() {
198
- if (!targetExists(target)) {
199
- revert ErrorSetLockedForNonexstentTarget(target);
218
+ _createTarget(target, name, IAccess.Type.Custom);
219
+ }
220
+ // INSTANCE_SERVICE_ROLE
221
+ function setTargetLocked(string memory targetName, bool locked)
222
+ external
223
+ restricted()
224
+ {
225
+ ShortString nameShort = ShortStrings.toShortString(targetName);
226
+ address target = _targetAddressForName[nameShort];
227
+
228
+ if (target == address(0)) {
229
+ revert IAccess.ErrorIAccessTargetDoesNotExist(nameShort);
200
230
  }
201
231
 
202
- _target[target].isLocked = locked;
232
+ if(_targetInfo[target].ttype == IAccess.Type.Core) {
233
+ revert IAccess.ErrorIAccessTargetTypeInvalid(nameShort, _targetInfo[target].ttype);
234
+ }
235
+ // TODO isLocked is redundant but makes getTargetInfo() faster
236
+ _targetInfo[target].isLocked = locked;
203
237
  _accessManager.setTargetClosed(target, locked);
204
238
  }
205
239
 
206
- function targetExists(address target) public view returns (bool exists) {
207
- return _target[target].createdAt.gtz();
240
+ // allowed combinations of roles and targets:
241
+ //1) set core role for core target
242
+ //2) set gif role for gif target
243
+ //3) set custom role for gif target
244
+ //4) set custom role for custom target
245
+
246
+ // ADMIN_ROLE if used only during initialization, works with:
247
+ // any roles for any targets
248
+ // INSTANCE_SERVICE_ROLE if used not only during initilization, works with:
249
+ // core roles for core targets
250
+ // gif roles for gif targets
251
+ // TODO taget admin example:
252
+ // 1) INSTANCE_OWNER_ROLE is admin role for component target
253
+ // 2) ADMIN_ROLE is admin role for core targets
254
+ function setTargetFunctionRole(
255
+ string memory targetName,
256
+ bytes4[] calldata selectors,
257
+ RoleId roleId
258
+ )
259
+ public
260
+ virtual
261
+ restricted()
262
+ {
263
+ ShortString nameShort = ShortStrings.toShortString(targetName);
264
+ address target = _targetAddressForName[nameShort];
265
+
266
+ // not custom target
267
+ if(_targetInfo[target].ttype == IAccess.Type.Custom) {
268
+ revert IAccess.ErrorIAccessTargetTypeInvalid(nameShort, _targetInfo[target].ttype);
269
+ }
270
+
271
+ // not custom role
272
+ if(_roleInfo[roleId].rtype == IAccess.Type.Custom) {
273
+ revert IAccess.ErrorIAccessRoleTypeInvalid(roleId, _roleInfo[roleId].rtype);
274
+ }
275
+
276
+ _setTargetFunctionRole(target, nameShort, selectors, roleId);
208
277
  }
209
278
 
210
- //--- internal view/pure functions --------------------------------------//
279
+ // INSTANCE_OWNER_ROLE
280
+ // custom role for gif target -> instance owner can mess with gif target (component) -> e.g. set custom role for function intendent to work with gif role
281
+ // custom role for custom target
282
+ function setTargetFunctionCustomRole(
283
+ string memory targetName,
284
+ bytes4[] calldata selectors,
285
+ RoleId roleId
286
+ )
287
+ public
288
+ virtual
289
+ restricted()
290
+ {
291
+ ShortString nameShort = ShortStrings.toShortString(targetName);
292
+ address target = _targetAddressForName[nameShort];
293
+
294
+ // not core target
295
+ if(_targetInfo[target].ttype == IAccess.Type.Core) {
296
+ revert IAccess.ErrorIAccessTargetTypeInvalid(nameShort, _targetInfo[target].ttype);
297
+ }
211
298
 
212
- function _createRole(RoleId roleId, string memory name, bool isCustom, bool validateParameters) internal {
213
- if (validateParameters) {
214
- _validateRoleParameters(roleId, name, isCustom);
299
+ // target belongs to instance owned by caller
300
+ // TODO parent may be !instance
301
+ NftId instanceNftId = _registry.getObjectInfo(target).parentNftId;
302
+ address instanceAddress = _registry.getObjectInfo(instanceNftId).objectAddress;
303
+ if(_registry.ownerOf(instanceAddress) != msg.sender) {
304
+ revert IAccess.ErrorIAccessTargetInstanceMismatch(nameShort, instanceNftId);
215
305
  }
216
306
 
217
- RoleInfo memory role = RoleInfo(
307
+ // not core role
308
+ if(_roleInfo[roleId].rtype == IAccess.Type.Core) {
309
+ revert IAccess.ErrorIAccessRoleTypeInvalid(roleId, _roleInfo[roleId].rtype);
310
+ }
311
+
312
+ _setTargetFunctionRole(target, nameShort, selectors, roleId);
313
+ }
314
+
315
+ function isTargetLocked(address target) public view returns (bool locked) {
316
+ return _accessManager.isTargetClosed(target);
317
+ }
318
+
319
+ function targetExists(address target) public view returns (bool exists) {
320
+ return _targetInfo[target].createdAt.gtz();
321
+ }
322
+
323
+ function getTargetInfo(address target) public view returns (IAccess.TargetInfo memory) {
324
+ return _targetInfo[target];
325
+ }
326
+
327
+ //--- internal view/pure functions --------------------------------------//
328
+
329
+ function _createRole(RoleId roleId, string memory name, IAccess.Type rtype)
330
+ internal
331
+ {
332
+ IAccess.RoleInfo memory role = IAccess.RoleInfo(
218
333
  ShortStrings.toShortString(name),
219
- isCustom,
220
- false, // role un-locked,
334
+ rtype,
335
+ ADMIN_ROLE(),
221
336
  TimestampLib.blockTimestamp(),
222
337
  TimestampLib.blockTimestamp());
223
338
 
224
- _role[roleId] = role;
225
- _roleForName[role.name] = roleId;
226
- _roles.push(roleId);
339
+ _roleInfo[roleId] = role;
340
+ _roleIdForName[role.name] = roleId;
341
+ _roleIds.push(roleId);
227
342
  }
228
343
 
229
344
  function _validateRoleParameters(
230
345
  RoleId roleId,
231
346
  string memory name,
232
- bool isCustom
347
+ IAccess.Type rtype
233
348
  )
234
349
  internal
235
350
  view
236
- returns (RoleInfo memory existingRole)
351
+ returns (IAccess.RoleInfo memory existingRole)
237
352
  {
238
- // check role id
239
- uint64 roleIdInt = RoleId.unwrap(roleId);
240
- if(roleIdInt == _accessManager.ADMIN_ROLE() || roleIdInt == _accessManager.PUBLIC_ROLE()) {
241
- revert ErrorRoleIdInvalid(roleId);
353
+ if(roleExists(roleId)) {
354
+ revert IAccess.ErrorIAccessRoleIdAlreadyExists(roleId);
242
355
  }
243
356
 
244
- // prevent changing isCustom for existing roles
245
- existingRole = _role[roleId];
246
-
247
- if (existingRole.createdAt.gtz() && isCustom != existingRole.isCustom) {
248
- revert ErrorRoleIsCustomIsImmutable(roleId, isCustom, existingRole.isCustom);
357
+ uint roleIdInt = roleId.toInt();
358
+ if(rtype == IAccess.Type.Custom && roleIdInt < CUSTOM_ROLE_ID_MIN) {
359
+ revert IAccess.ErrorIAccessRoleIdTooSmall(roleId);
249
360
  }
250
361
 
251
- if (isCustom && roleIdInt < CUSTOM_ROLE_ID_MIN) {
252
- revert ErrorRoleIdTooSmall(roleId);
253
- } else if (!isCustom && roleIdInt >= CUSTOM_ROLE_ID_MIN) {
254
- revert ErrorRoleIdTooBig(roleId);
362
+ if(rtype != IAccess.Type.Custom && roleIdInt >= CUSTOM_ROLE_ID_MIN) {
363
+ revert IAccess.ErrorIAccessRoleIdTooBig(roleId);
255
364
  }
256
365
 
257
366
  // role name checks
258
367
  ShortString nameShort = ShortStrings.toShortString(name);
259
368
  if (ShortStrings.byteLength(nameShort) == 0) {
260
- revert ErrorRoleNameEmpty(roleId);
369
+ revert IAccess.ErrorIAccessRoleNameEmpty(roleId);
261
370
  }
262
371
 
263
- if (_roleForName[nameShort] != RoleIdLib.zero() && _roleForName[nameShort] != roleId) {
264
- revert ErrorRoleNameNotUnique(_roleForName[nameShort], nameShort);
372
+ if (_roleIdForName[nameShort].gtz()) {
373
+ revert IAccess.ErrorIAccessRoleNameNotUnique(_roleIdForName[nameShort], nameShort);
265
374
  }
266
375
  }
267
376
 
268
- function _createTarget(address target, string memory name, bool isCustom, bool validateParameters) internal {
269
- if (validateParameters) {
270
- _validateTargetParameters(target, name, isCustom);
377
+ function _revokeRole(RoleId roleId, address member)
378
+ internal
379
+ returns(bool revoked)
380
+ {
381
+ if (!roleExists(roleId)) {
382
+ revert IAccess.ErrorIAccessRoleIdInvalid(roleId);
271
383
  }
272
384
 
273
- TargetInfo memory info = TargetInfo(
385
+ revoked = EnumerableSet.remove(_roleMembers[roleId], member);
386
+ if(revoked) {
387
+ _accessManager.revokeRole(roleId.toInt(), member);
388
+ }
389
+ }
390
+
391
+ function _getNextCustomRoleId() internal returns(RoleId) {
392
+ return RoleIdLib.toRoleId(_idNext++);
393
+ }
394
+
395
+ function _createTarget(address target, string memory name, IAccess.Type ttype) internal {
396
+ _validateTargetParameters(target, name);
397
+
398
+ IAccess.TargetInfo memory info = IAccess.TargetInfo(
274
399
  ShortStrings.toShortString(name),
275
- isCustom,
400
+ ttype,
276
401
  _accessManager.isTargetClosed(target), // sync with state in access manager
277
402
  TimestampLib.blockTimestamp(),
278
403
  TimestampLib.blockTimestamp());
279
404
 
280
- _target[target] = info;
281
- _targetForName[info.name] = target;
405
+ _targetInfo[target] = info;
406
+ _targetAddressForName[info.name] = target;
282
407
  _targets.push(target);
283
408
  }
284
409
 
285
- function _validateTargetParameters(address target, string memory name, bool isCustom) internal view {
410
+ function _validateTargetParameters(address target, string memory name) internal view {
411
+ if (_targetInfo[target].createdAt.gtz()) {
412
+ revert IAccess.ErrorIAccessTargetAlreadyExists(target, _targetInfo[target].name);
413
+ }
414
+
415
+ ShortString nameShort = ShortStrings.toShortString(name);
416
+ if (ShortStrings.byteLength(nameShort) == 0) {
417
+ revert IAccess.ErrorIAccessTargetNameEmpty(target);
418
+ }
419
+
420
+ if (_targetAddressForName[nameShort] != address(0)) {
421
+ revert IAccess.ErrorIAccessTargetNameExists(
422
+ target,
423
+ _targetAddressForName[nameShort],
424
+ nameShort);
425
+ }
426
+ }
427
+
428
+ function _setTargetFunctionRole(
429
+ address target,
430
+ ShortString name,
431
+ bytes4[] calldata selectors,
432
+ RoleId roleId
433
+ )
434
+ internal
435
+ {
436
+ if (target == address(0)) {
437
+ revert IAccess.ErrorIAccessTargetDoesNotExist(name);
438
+ }
439
+
440
+ if (!roleExists(roleId)) {
441
+ revert IAccess.ErrorIAccessRoleIdInvalid(roleId);
442
+ }
443
+
444
+ uint64 roleIdInt = RoleId.unwrap(roleId);
445
+ _accessManager.setTargetFunctionRole(target, selectors, roleIdInt);
446
+ }
286
447
 
448
+ function canCall(
449
+ address caller,
450
+ address target,
451
+ bytes4 selector
452
+ ) public view virtual returns (bool immediate, uint32 delay) {
453
+ return _accessManager.canCall(caller, target, selector);
287
454
  }
288
455
  }
@@ -31,39 +31,21 @@ contract InstanceReader {
31
31
  bool private _initialized;
32
32
 
33
33
  IRegistry internal _registry;
34
- NftId internal _instanceNftId;
35
34
  IInstance internal _instance;
36
35
  IKeyValueStore internal _store;
37
36
 
38
- constructor(
39
- address registry,
40
- NftId instanceNftId
41
- )
42
- {
43
- initialize(registry, instanceNftId);
44
- }
45
-
46
- function initialize(address registry, NftId instanceNftId) public {
37
+ function initialize(address registry, address instance) public {
47
38
  require(!_initialized, "ERROR:CRD-000:ALREADY_INITIALIZED");
48
39
 
49
40
  require(
50
41
  address(registry) != address(0),
51
42
  "ERROR:CRD-001:REGISTRY_ZERO");
52
43
 
53
- require(
54
- instanceNftId.gtz(),
55
- "ERROR:CRD-002:NFT_ID_ZERO");
56
44
 
57
45
  _registry = IRegistry(registry);
58
- _instanceNftId = instanceNftId;
59
- IRegistry.ObjectInfo memory instanceInfo = _registry.getObjectInfo(_instanceNftId);
60
46
 
61
- require(
62
- instanceInfo.objectType == INSTANCE(),
63
- "ERROR:CRD-003:PARENT_NOT_INSTANCE");
64
-
65
- _instance = IInstance(instanceInfo.objectAddress);
66
- _store = IKeyValueStore(instanceInfo.objectAddress);
47
+ _instance = IInstance(instance);
48
+ _store = IKeyValueStore(instance);
67
49
 
68
50
  _initialized = true;
69
51
  }
@@ -301,10 +283,6 @@ contract InstanceReader {
301
283
  return _store;
302
284
  }
303
285
 
304
- function getInstanceNftId() external view returns (NftId nftId) {
305
- return _instanceNftId;
306
- }
307
-
308
286
  function toUFixed(uint256 value, int8 exp) public pure returns (UFixed) {
309
287
  return UFixedLib.toUFixed(value, exp);
310
288
  }