@etherisc/gif-next 0.0.2-cf68d0c-530 → 0.0.2-d02cb80-460

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. package/README.md +63 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +142 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +164 -62
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +104 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +0 -52
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +28 -2
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +193 -16
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +166 -58
  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/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  38. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  40. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +788 -0
  41. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  42. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  43. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  44. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1373 -93
  46. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  47. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
  48. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  49. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +108 -1
  50. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  51. package/artifacts/contracts/instance/Instance.sol/Instance.json +160 -641
  52. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +291 -143
  54. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  55. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
  56. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  57. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +177 -38
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +333 -67
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +91 -23
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  63. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +285 -0
  64. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +40 -0
  66. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  70. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +54 -22
  73. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  78. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +923 -0
  81. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  82. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +440 -0
  83. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +16 -16
  85. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +69 -26
  87. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +18 -18
  89. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  90. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +669 -0
  91. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  94. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +664 -0
  95. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +9 -71
  97. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +17 -232
  99. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +984 -0
  101. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +464 -0
  103. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  104. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +718 -0
  105. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +428 -0
  107. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  108. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +768 -0
  109. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  110. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +420 -0
  111. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  112. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +2 -110
  114. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  115. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -0
  116. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.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 +35 -146
  119. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  120. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +76 -20
  121. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  122. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +26 -34
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  124. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +12 -12
  125. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  126. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  127. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  137. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  138. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  139. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  140. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  141. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  143. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  145. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  147. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestService.sol/TestService.json +9 -9
  149. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  152. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  153. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  154. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  159. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  162. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  168. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  174. package/contracts/components/BaseComponent.sol +62 -8
  175. package/contracts/components/Distribution.sol +12 -15
  176. package/contracts/components/IBaseComponent.sol +7 -0
  177. package/contracts/components/IDistributionComponent.sol +0 -2
  178. package/contracts/components/IPoolComponent.sol +5 -1
  179. package/contracts/components/Pool.sol +42 -29
  180. package/contracts/components/Product.sol +41 -46
  181. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  182. package/contracts/instance/BundleManager.sol +129 -0
  183. package/contracts/instance/Cloneable.sol +46 -0
  184. package/contracts/instance/IInstance.sol +34 -7
  185. package/contracts/instance/IInstanceBase.sol +26 -0
  186. package/contracts/instance/IInstanceService.sol +15 -3
  187. package/contracts/instance/Instance.sol +57 -224
  188. package/contracts/instance/InstanceAccessManager.sol +95 -78
  189. package/contracts/instance/InstanceBase.sol +41 -0
  190. package/contracts/instance/InstanceReader.sol +26 -1
  191. package/contracts/instance/InstanceService.sol +222 -69
  192. package/contracts/instance/InstanceServiceManager.sol +6 -5
  193. package/contracts/instance/ObjectManager.sol +101 -0
  194. package/contracts/instance/base/ComponentServiceBase.sol +45 -12
  195. package/contracts/instance/module/IAccess.sol +27 -17
  196. package/contracts/instance/module/IBundle.sol +1 -0
  197. package/contracts/instance/module/ISetup.sol +3 -0
  198. package/contracts/instance/service/BundleService.sol +260 -0
  199. package/contracts/instance/service/BundleServiceManager.sol +54 -0
  200. package/contracts/instance/service/DistributionService.sol +43 -21
  201. package/contracts/instance/service/DistributionServiceManager.sol +6 -5
  202. package/contracts/instance/service/IBundleService.sol +45 -0
  203. package/contracts/instance/service/IPolicyService.sol +87 -0
  204. package/contracts/instance/service/IPoolService.sol +6 -23
  205. package/contracts/instance/service/IProductService.sol +6 -73
  206. package/contracts/instance/service/PolicyService.sol +508 -0
  207. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  208. package/contracts/instance/service/PoolService.sol +124 -0
  209. package/contracts/instance/service/PoolServiceManager.sol +54 -0
  210. package/contracts/instance/service/ProductService.sol +173 -0
  211. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  212. package/contracts/registry/IRegistry.sol +5 -18
  213. package/contracts/registry/IRegistryService.sol +28 -11
  214. package/contracts/registry/Registry.sol +4 -45
  215. package/contracts/registry/RegistryService.sol +30 -71
  216. package/contracts/shared/NftOwnable.sol +2 -4
  217. package/contracts/shared/Service.sol +1 -0
  218. package/contracts/types/NftIdSet.sol +26 -24
  219. package/contracts/types/RoleId.sol +7 -2
  220. package/package.json +1 -1
  221. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  222. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  223. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  224. package/contracts/instance/AccessManagedSimple.sol +0 -115
  225. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -3,74 +3,105 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5
5
 
6
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
7
- import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
6
  import {Instance} from "./Instance.sol";
7
+ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
9
8
  import {IInstanceService} from "./IInstanceService.sol";
10
9
  import {InstanceReader} from "./InstanceReader.sol";
10
+ import {BundleManager} from "./BundleManager.sol";
11
11
  import {IRegistry} from "../registry/IRegistry.sol";
12
- import {Registry} from "../registry/Registry.sol";
13
12
  import {RegistryService} from "../registry/RegistryService.sol";
13
+ import {ChainNft} from "../registry/ChainNft.sol";
14
14
  import {Service} from "../../contracts/shared/Service.sol";
15
15
  import {IService} from "../shared/IService.sol";
16
- import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
17
- import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
16
+ import {NftId} from "../../contracts/types/NftId.sol";
17
+ import {RoleId} from "../types/RoleId.sol";
18
18
  import {VersionLib} from "../types/Version.sol";
19
- import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE} from "../types/RoleId.sol";
19
+ import {ADMIN_ROLE, INSTANCE_OWNER_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE, PRODUCT_SERVICE_ROLE, POLICY_SERVICE_ROLE, BUNDLE_SERVICE_ROLE} from "../types/RoleId.sol";
20
20
 
21
21
  contract InstanceService is Service, IInstanceService {
22
22
 
23
- address internal _registryAddress;
24
- address internal _accessManagerMaster;
25
- address internal _instanceMaster;
26
- address internal _instanceReaderMaster;
23
+ address internal _masterInstanceAccessManager;
24
+ address internal _masterInstance;
25
+ address internal _masterInstanceReader;
26
+ address internal _masterInstanceBundleManager;
27
27
 
28
28
  // TODO update to real hash when instance is stable
29
29
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
30
30
  string public constant NAME = "InstanceService";
31
31
 
32
+ modifier onlyInstanceOwner(NftId instanceNftId) {
33
+ IRegistry registry = getRegistry();
34
+ ChainNft chainNft = registry.getChainNft();
35
+
36
+ if( msg.sender != chainNft.ownerOf(instanceNftId.toInt())) {
37
+ revert ErrorInstanceServiceNotInstanceOwner(msg.sender, instanceNftId);
38
+ }
39
+ _;
40
+ }
41
+
32
42
  function createInstanceClone()
33
43
  external
34
44
  returns (
35
- AccessManagerSimple clonedAccessManager,
45
+ InstanceAccessManager clonedAccessManager,
36
46
  Instance clonedInstance,
37
- NftId instanceNftId,
38
- InstanceReader clonedInstanceReader
47
+ NftId clonedInstanceNftId,
48
+ InstanceReader clonedInstanceReader,
49
+ BundleManager clonedBundleManager
39
50
  )
40
51
  {
41
52
  address instanceOwner = msg.sender;
42
- Registry registry = Registry(_registryAddress);
43
- NftId registryNftId = registry.getNftId(_registryAddress);
53
+ IRegistry registry = getRegistry();
54
+ address registryAddress = address(registry);
55
+ NftId registryNftId = registry.getNftId(registryAddress);
44
56
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
45
57
  RegistryService registryService = RegistryService(registryServiceAddress);
46
58
 
47
- clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
48
- // initial as this
49
- clonedAccessManager.initialize(address(this));
59
+ // initially set the authority of the access managar to this (being the instance service).
60
+ // This will allow the instance service to bootstrap the authorizations of the instance
61
+ // and then transfer the ownership of the access manager to the instance owner once everything is setup
62
+ clonedAccessManager = InstanceAccessManager(Clones.clone(_masterInstanceAccessManager));
63
+ clonedAccessManager.__InstanceAccessManager_initialize(address(this));
50
64
 
51
- clonedInstance = Instance(Clones.clone(_instanceMaster));
52
- clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
65
+ clonedInstance = Instance(Clones.clone(_masterInstance));
66
+ clonedInstance.initialize(address(clonedAccessManager), registryAddress, registryNftId, msg.sender);
53
67
  ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
54
- instanceNftId = info.nftId;
68
+ clonedInstanceNftId = info.nftId;
55
69
 
56
- clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
57
- clonedInstanceReader.initialize(_registryAddress, instanceNftId);
70
+ clonedInstanceReader = InstanceReader(Clones.clone(address(_masterInstanceReader)));
71
+ clonedInstanceReader.initialize(registryAddress, clonedInstanceNftId);
72
+ clonedInstance.setInstanceReader(clonedInstanceReader);
58
73
 
59
- _grantInitialAuthorizations(clonedAccessManager, clonedInstance);
74
+ clonedBundleManager = BundleManager(Clones.clone(_masterInstanceBundleManager));
75
+ clonedBundleManager.initialize(address(clonedAccessManager), registryAddress, clonedInstanceNftId);
76
+ clonedInstance.setBundleManager(clonedBundleManager);
60
77
 
61
- clonedInstance.setInstanceReader(clonedInstanceReader);
78
+ // TODO amend setters with instance specific , policy manager ...
62
79
 
63
- // switch instance ownership to instance owner
64
- clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
65
- clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
80
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
66
81
 
67
- emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
82
+ // to complete setup switch instance ownership to the instance owner
83
+ // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
84
+ clonedAccessManager.grantRole(INSTANCE_OWNER_ROLE(), instanceOwner);
85
+ clonedAccessManager.grantRole(ADMIN_ROLE(), instanceOwner);
86
+ clonedAccessManager.revokeRole(ADMIN_ROLE(), address(this));
87
+
88
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
89
+ }
90
+
91
+ function _grantInitialAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
92
+ _grantRegistryServiceAuthorizations(clonedAccessManager, clonedInstance);
93
+ _grantPoolServiceAuthorizations(clonedAccessManager, clonedInstance);
94
+ _grantProductServiceAuthorizations(clonedAccessManager, clonedInstance);
95
+ _grantPolicyServiceAuthorizations(clonedAccessManager, clonedInstance);
96
+ _grantBundleServiceAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
97
+ _grantInstanceServiceAuthorizations(clonedAccessManager, clonedInstance);
68
98
  }
69
99
 
70
- function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance) internal {
100
+ function _grantRegistryServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
101
+ // configure authorization for distribution service on instance
102
+ IRegistry registry = getRegistry();
71
103
  address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
72
-
73
- clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
104
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE(), address(distributionServiceAddress));
74
105
  bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
75
106
  instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
76
107
  instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
@@ -80,37 +111,150 @@ contract InstanceService is Service, IInstanceService {
80
111
  DISTRIBUTION_SERVICE_ROLE().toInt());
81
112
  }
82
113
 
83
- function setAccessManagerMaster(address accessManagerMaster) external {
84
- require(
85
- _accessManagerMaster == address(0),
86
- "ERROR:CRD-001:ACCESS_MANAGER_MASTER_ALREADY_SET");
87
- _accessManagerMaster = accessManagerMaster;
114
+ function _grantPoolServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
115
+ // configure authorization for pool service on instance
116
+ address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
117
+ clonedAccessManager.grantRole(POOL_SERVICE_ROLE(), address(poolServiceAddress));
118
+ bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
119
+ instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
120
+ instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
121
+ clonedAccessManager.setTargetFunctionRole(
122
+ address(clonedInstance),
123
+ instancePoolServiceSelectors,
124
+ POOL_SERVICE_ROLE().toInt());
88
125
  }
89
126
 
90
- function setInstanceMaster(address instanceMaster) external {
91
- require(
92
- _instanceMaster == address(0),
93
- "ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
94
- _instanceMaster = instanceMaster;
127
+ function _grantProductServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
128
+ // configure authorization for product service on instance
129
+ address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
130
+ clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE(), address(productServiceAddress));
131
+ bytes4[] memory instanceProductServiceSelectors = new bytes4[](5);
132
+ instanceProductServiceSelectors[0] = clonedInstance.createProductSetup.selector;
133
+ instanceProductServiceSelectors[1] = clonedInstance.updateProductSetup.selector;
134
+ instanceProductServiceSelectors[2] = clonedInstance.createRisk.selector;
135
+ instanceProductServiceSelectors[3] = clonedInstance.updateRisk.selector;
136
+ instanceProductServiceSelectors[4] = clonedInstance.updateRiskState.selector;
137
+ clonedAccessManager.setTargetFunctionRole(
138
+ address(clonedInstance),
139
+ instanceProductServiceSelectors,
140
+ PRODUCT_SERVICE_ROLE().toInt());
95
141
  }
96
142
 
97
- function setInstanceReaderMaster(address instanceReaderMaster) external {
98
- require(
99
- _instanceReaderMaster == address(0),
100
- "ERROR:CRD-003:INSTANCE_READER_MASTER_ALREADY_SET");
101
- _instanceReaderMaster = instanceReaderMaster;
143
+ function _grantPolicyServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
144
+ // configure authorization for policy service on instance
145
+ address policyServiceAddress = _registry.getServiceAddress("PolicyService", VersionLib.toVersion(3, 0, 0).toMajorPart());
146
+ clonedAccessManager.grantRole(POLICY_SERVICE_ROLE(), address(policyServiceAddress));
147
+ bytes4[] memory instancePolicyServiceSelectors = new bytes4[](3);
148
+ instancePolicyServiceSelectors[0] = clonedInstance.createPolicy.selector;
149
+ instancePolicyServiceSelectors[1] = clonedInstance.updatePolicy.selector;
150
+ instancePolicyServiceSelectors[2] = clonedInstance.updatePolicyState.selector;
151
+ clonedAccessManager.setTargetFunctionRole(
152
+ address(clonedInstance),
153
+ instancePolicyServiceSelectors,
154
+ POLICY_SERVICE_ROLE().toInt());
102
155
  }
103
156
 
104
- function getInstanceReaderMaster() external view returns (address) {
105
- return _instanceReaderMaster;
157
+ function _grantBundleServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
158
+ // configure authorization for bundle service on instance
159
+ address bundleServiceAddress = _registry.getServiceAddress("BundleService", VersionLib.toVersion(3, 0, 0).toMajorPart());
160
+ clonedAccessManager.grantRole(BUNDLE_SERVICE_ROLE(), address(bundleServiceAddress));
161
+ bytes4[] memory instanceBundleServiceSelectors = new bytes4[](2);
162
+ instanceBundleServiceSelectors[0] = clonedInstance.createBundle.selector;
163
+ instanceBundleServiceSelectors[1] = clonedInstance.updateBundle.selector;
164
+ clonedAccessManager.setTargetFunctionRole(
165
+ address(clonedInstance),
166
+ instanceBundleServiceSelectors,
167
+ BUNDLE_SERVICE_ROLE().toInt());
168
+
169
+ // configure authorization for bundle service on bundle manager
170
+ bytes4[] memory bundleManagerBundleServiceSelectors = new bytes4[](5);
171
+ bundleManagerBundleServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
172
+ bundleManagerBundleServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
173
+ bundleManagerBundleServiceSelectors[2] = clonedBundleManager.add.selector;
174
+ bundleManagerBundleServiceSelectors[3] = clonedBundleManager.lock.selector;
175
+ bundleManagerBundleServiceSelectors[4] = clonedBundleManager.unlock.selector;
176
+ clonedAccessManager.setTargetFunctionRole(
177
+ address(clonedBundleManager),
178
+ bundleManagerBundleServiceSelectors,
179
+ BUNDLE_SERVICE_ROLE().toInt());
106
180
  }
107
181
 
108
- function getInstanceMaster() external view returns (address) {
109
- return _instanceMaster;
182
+ function _grantInstanceServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
183
+ // configure authorization for instance service on instance
184
+ address instanceServiceAddress = _registry.getServiceAddress("InstanceService", VersionLib.toVersion(3, 0, 0).toMajorPart());
185
+ clonedAccessManager.grantRole(INSTANCE_SERVICE_ROLE(), instanceServiceAddress);
186
+ bytes4[] memory instanceInstanceServiceSelectors = new bytes4[](1);
187
+ instanceInstanceServiceSelectors[0] = clonedInstance.setInstanceReader.selector;
188
+ clonedAccessManager.setTargetFunctionRole(
189
+ address(clonedInstance),
190
+ instanceInstanceServiceSelectors,
191
+ INSTANCE_SERVICE_ROLE().toInt());
110
192
  }
111
193
 
112
- function getAccessManagerMaster() external view returns (address) {
113
- return _accessManagerMaster;
194
+ function setMasterInstance(address accessManagerAddress, address instanceAddress, address instanceReaderAddress, address bundleManagerAddress) external onlyOwner {
195
+ require(_masterInstanceAccessManager == address(0), "ERROR:CRD-001:ACCESS_MANAGER_MASTER_ALREADY_SET");
196
+ require(_masterInstance == address(0), "ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
197
+ require(_masterInstanceBundleManager == address(0), "ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
198
+
199
+ require (accessManagerAddress != address(0), "ERROR:CRD-005:ACCESS_MANAGER_ZERO");
200
+ require (instanceAddress != address(0), "ERROR:CRD-006:INSTANCE_ZERO");
201
+ require (instanceReaderAddress != address(0), "ERROR:CRD-007:INSTANCE_READER_ZERO");
202
+ require (bundleManagerAddress != address(0), "ERROR:CRD-008:BUNDLE_MANAGER_ZERO");
203
+
204
+ Instance instance = Instance(instanceAddress);
205
+ InstanceReader instanceReader = InstanceReader(instanceReaderAddress);
206
+ BundleManager bundleManager = BundleManager(bundleManagerAddress);
207
+
208
+ require(instance.authority() == accessManagerAddress, "ERROR:CRD-009:INSTANCE_AUTHORITY_MISMATCH");
209
+ require(instanceReader.getInstanceNftId() == instance.getNftId(), "ERROR:CRD-010:INSTANCE_READER_INSTANCE_MISMATCH");
210
+ require(bundleManager.getInstanceNftId() == instance.getNftId(), "ERROR:CRD-011:BUNDLE_MANAGER_INSTANCE_MISMATCH");
211
+
212
+ _masterInstanceAccessManager = accessManagerAddress;
213
+ _masterInstance = instanceAddress;
214
+ _masterInstanceReader = instanceReaderAddress;
215
+ _masterInstanceBundleManager = bundleManagerAddress;
216
+ }
217
+
218
+ function setMasterInstanceReader(address instanceReaderAddress) external onlyOwner {
219
+ require(_masterInstanceReader != address(0), "ERROR:CRD-003:INSTANCE_READER_MASTER_NOT_SET");
220
+ require (instanceReaderAddress != address(0), "ERROR:CRD-012:INSTANCE_READER_ZERO");
221
+ require(instanceReaderAddress != _masterInstanceReader, "ERROR:CRD-014:INSTANCE_READER_MASTER_SAME_AS_NEW");
222
+
223
+ InstanceReader instanceReader = InstanceReader(instanceReaderAddress);
224
+ require(instanceReader.getInstanceNftId() == Instance(_masterInstance).getNftId(), "ERROR:CRD-015:INSTANCE_READER_INSTANCE_MISMATCH");
225
+
226
+ _masterInstanceReader = instanceReaderAddress;
227
+ }
228
+
229
+ function upgradeInstanceReader(NftId instanceNftId) external {
230
+ IRegistry registry = getRegistry();
231
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
232
+ Instance instance = Instance(instanceInfo.objectAddress);
233
+ address owner = instance.getOwner();
234
+
235
+ if (msg.sender != owner) {
236
+ revert ErrorInstanceServiceRequestUnauhorized(msg.sender);
237
+ }
238
+
239
+ InstanceReader upgradedInstanceReaderClone = InstanceReader(Clones.clone(address(_masterInstanceReader)));
240
+ upgradedInstanceReaderClone.initialize(address(registry), instanceNftId);
241
+ instance.setInstanceReader(upgradedInstanceReaderClone);
242
+ }
243
+
244
+ function getMasterInstanceReader() external view returns (address) {
245
+ return _masterInstanceReader;
246
+ }
247
+
248
+ function getMasterInstance() external view returns (address) {
249
+ return _masterInstance;
250
+ }
251
+
252
+ function getMasterInstanceAccessManager() external view returns (address) {
253
+ return _masterInstanceAccessManager;
254
+ }
255
+
256
+ function getMasterInstanceBundleManager() external view returns (address) {
257
+ return _masterInstanceBundleManager;
114
258
  }
115
259
 
116
260
  // From IService
@@ -131,28 +275,37 @@ contract InstanceService is Service, IInstanceService {
131
275
  initializer
132
276
  virtual override
133
277
  {
134
- // bytes memory encodedConstructorArguments = abi.encode(
135
- // _registryAddress);
136
-
137
- // bytes memory instanceCreationCode = ContractDeployerLib.getCreationCode(
138
- // instanceByteCodeWithInitCode,
139
- // encodedConstructorArguments);
140
-
141
- // address instanceAddress = ContractDeployerLib.deploy(
142
- // instanceCreationCode,
143
- // INSTANCE_CREATION_CODE_HASH);
144
-
145
278
  address initialOwner = address(0);
146
- (_registryAddress, initialOwner) = abi.decode(data, (address, address));
147
-
148
- _initializeService(_registryAddress, initialOwner);
279
+ address registryAddress = address(0);
280
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
281
+ // TODO while InstanceService is not deployed in InstanceServiceManager constructor
282
+ // owner is InstanceServiceManager deployer
283
+ _initializeService(registryAddress, owner);
149
284
 
150
285
  _registerInterface(type(IService).interfaceId);
151
286
  _registerInterface(type(IInstanceService).interfaceId);
152
287
  }
153
288
 
154
- function getInstance() external view returns (Instance) {
155
- return Instance(address(this));
289
+ function createRole(RoleId role, string memory name, NftId instanceNftId) external override onlyInstanceOwner(instanceNftId) {
290
+ IRegistry registry = getRegistry();
291
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
292
+ Instance instance = Instance(instanceInfo.objectAddress);
293
+ InstanceAccessManager accessManager = instance.getInstanceAccessManager();
294
+ accessManager.createRole(role, name);
295
+ }
296
+
297
+ function grantRole(RoleId role, address member, NftId instanceNftId) external override onlyInstanceOwner(instanceNftId) {
298
+ IRegistry registry = getRegistry();
299
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
300
+ Instance instance = Instance(instanceInfo.objectAddress);
301
+ InstanceAccessManager accessManager = instance.getInstanceAccessManager();
302
+ accessManager.grantRole(role, member);
303
+ }
304
+
305
+ function hasRole(address account, RoleId role, address instanceAddress) public view returns (bool) {
306
+ Instance instance = Instance(instanceAddress);
307
+ InstanceAccessManager accessManager = instance.getInstanceAccessManager();
308
+ return accessManager.hasRole(role, account);
156
309
  }
157
310
  }
158
311
 
@@ -31,14 +31,15 @@ contract InstanceServiceManager is ProxyManager {
31
31
  Registry registry = Registry(registryAddress);
32
32
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
33
33
  RegistryService registryService = RegistryService(registryServiceAddress);
34
-
35
- registryService.registerService(_instanceService);
34
+ // TODO this must have a role or own nft to register service
35
+ //registryService.registerService(_instanceService);
36
36
  // RegistryService registryService = _instanceService.getRegistryService();
37
37
 
38
+ // TODO no nft to link yet
38
39
  // link ownership of instance service manager ot nft owner of instance service
39
- _linkToNftOwnable(
40
- address(registryAddress),
41
- address(_instanceService));
40
+ //_linkToNftOwnable(
41
+ // address(registryAddress),
42
+ // address(_instanceService));
42
43
 
43
44
  // implies that after this constructor call only upgrade functionality is available
44
45
  _isDeployed = true;
@@ -0,0 +1,101 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Cloneable} from "./Cloneable.sol";
5
+
6
+ import {IInstance} from "./IInstance.sol";
7
+ import {INSTANCE} from "../types/ObjectType.sol";
8
+ import {InstanceReader} from "./InstanceReader.sol";
9
+ import {IRegistry} from "../registry/IRegistry.sol";
10
+ import {LibNftIdSet} from "../types/NftIdSet.sol";
11
+ import {NftId} from "../types/NftId.sol";
12
+
13
+ contract ObjectManager is
14
+ Cloneable
15
+ {
16
+
17
+ event LogObjectManagerInitialized(NftId instanceNftId, address instanceReader);
18
+
19
+ error ErrorObjectManagerNftIdInvalid(NftId instanceNftId);
20
+ error ErrorObjectManagerAlreadyAdded(NftId componentNftId, NftId objectNftId);
21
+
22
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _activeObjects;
23
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _allObjects;
24
+ NftId internal _instanceNftId;
25
+ InstanceReader internal _instanceReader;
26
+
27
+ constructor() Cloneable() {
28
+ _instanceReader = InstanceReader(address(0));
29
+ }
30
+
31
+ /// @dev call to initialize MUST be made in the same transaction as cloning of the contract
32
+ function initialize(
33
+ address authority,
34
+ address registry,
35
+ NftId instanceNftId
36
+ )
37
+ external
38
+ {
39
+ initialize(authority, registry);
40
+
41
+ // check/handle instance nft id/instance reader
42
+ IRegistry.ObjectInfo memory instanceInfo = _registry.getObjectInfo(instanceNftId);
43
+ if (instanceInfo.objectType != INSTANCE()) {
44
+ revert ErrorObjectManagerNftIdInvalid(instanceNftId);
45
+ }
46
+
47
+ IInstance instance = IInstance(instanceInfo.objectAddress);
48
+ _instanceReader = instance.getInstanceReader();
49
+ _instanceNftId = instanceNftId;
50
+
51
+ emit LogObjectManagerInitialized(instanceNftId, address(_instanceReader));
52
+ }
53
+
54
+ function getInstanceReader() external view returns (InstanceReader) {
55
+ return _instanceReader;
56
+ }
57
+
58
+ function getInstanceNftId() external view returns (NftId) {
59
+ return _instanceNftId;
60
+ }
61
+
62
+ function _add(NftId componentNftId, NftId objectNftId) internal {
63
+ LibNftIdSet.Set storage allSet = _allObjects[componentNftId];
64
+ LibNftIdSet.Set storage activeSet = _activeObjects[componentNftId];
65
+
66
+ LibNftIdSet.add(allSet, objectNftId);
67
+ LibNftIdSet.add(activeSet, objectNftId);
68
+ }
69
+
70
+ function _activate(NftId componentNftId, NftId objectNftId) internal {
71
+ LibNftIdSet.add(_activeObjects[componentNftId], objectNftId);
72
+ }
73
+
74
+ function _deactivate(NftId componentNftId, NftId objectNftId) internal {
75
+ LibNftIdSet.remove(_activeObjects[componentNftId], objectNftId);
76
+ }
77
+
78
+ function _objects(NftId componentNftId) internal view returns (uint256) {
79
+ return LibNftIdSet.size(_allObjects[componentNftId]);
80
+ }
81
+
82
+ function _contains(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
83
+ return LibNftIdSet.contains(_allObjects[componentNftId], objectNftId);
84
+ }
85
+
86
+ function _getObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
87
+ return LibNftIdSet.getElementAt(_allObjects[componentNftId], idx);
88
+ }
89
+
90
+ function _activeObjs(NftId componentNftId) internal view returns (uint256) {
91
+ return LibNftIdSet.size(_activeObjects[componentNftId]);
92
+ }
93
+
94
+ function _isActive(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
95
+ return LibNftIdSet.contains(_activeObjects[componentNftId], objectNftId);
96
+ }
97
+
98
+ function _getActiveObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
99
+ return LibNftIdSet.getElementAt(_activeObjects[componentNftId], idx);
100
+ }
101
+ }
@@ -4,16 +4,52 @@ pragma solidity ^0.8.19;
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
5
  import {IRegistryService} from "../../registry/IRegistryService.sol";
6
6
  import {IInstance} from "../../instance/IInstance.sol";
7
- import {ObjectType, INSTANCE, PRODUCT, POOL} from "../../types/ObjectType.sol";
7
+ import {ObjectType, INSTANCE, PRODUCT, POOL, DISTRIBUTION, ORACLE} from "../../types/ObjectType.sol";
8
8
  import {NftId, NftIdLib} from "../../types/NftId.sol";
9
+ import {RoleId, PRODUCT_OWNER_ROLE, POOL_OWNER_ROLE, DISTRIBUTION_OWNER_ROLE, ORACLE_OWNER_ROLE} from "../../types/RoleId.sol";
9
10
 
11
+ import {BaseComponent} from "../../components/BaseComponent.sol";
12
+ import {Product} from "../../components/Product.sol";
13
+ import {INftOwnable} from "../../shared/INftOwnable.sol";
10
14
  import {Service} from "../../shared/Service.sol";
15
+ import {InstanceService} from "../InstanceService.sol";
11
16
  import {Version, VersionPart, VersionLib} from "../../types/Version.sol";
12
17
 
13
18
  abstract contract ComponentServiceBase is Service {
14
19
 
20
+ error ExpectedRoleMissing(RoleId expected, address caller);
21
+ error ComponentTypeInvalid(ObjectType componentType);
22
+
23
+
24
+ /// @dev modifier to check if caller is a registered service
25
+ modifier onlyService() {
26
+ address caller = msg.sender;
27
+ require(getRegistry().isRegisteredService(caller), "ERROR_NOT_SERVICE");
28
+ _;
29
+ }
30
+
31
+ // view functions
32
+
33
+ function getRegistryService() public view virtual returns (IRegistryService) {
34
+ address service = getRegistry().getServiceAddress("RegistryService", getMajorVersion());
35
+ return IRegistryService(service);
36
+ }
37
+
38
+ function getInstanceService() public view returns (InstanceService) {
39
+ return InstanceService(getRegistry().getServiceAddress("InstanceService", getMajorVersion()));
40
+ }
41
+
42
+ // internal view functions
43
+
44
+ function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
45
+ IRegistry registry = getRegistry();
46
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
47
+ return IInstance(instanceInfo.objectAddress);
48
+ }
49
+
15
50
  function _getAndVerifyComponentInfoAndInstance(
16
- ObjectType objectType
51
+ //address component,
52
+ ObjectType expectedType
17
53
  )
18
54
  internal
19
55
  view
@@ -22,18 +58,15 @@ abstract contract ComponentServiceBase is Service {
22
58
  IInstance instance
23
59
  )
24
60
  {
25
- NftId componentNftId = _registry.getNftId(msg.sender);
26
- require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
61
+ IRegistry registry = getRegistry();
62
+ //TODO redundant check -> just check type
63
+ //NftId componentNftId = registry.getNftId(component);
64
+ //require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
27
65
 
28
- info = getRegistry().getObjectInfo(componentNftId);
29
- require(info.objectType == objectType, "OBJECT_TYPE_INVALID");
66
+ info = registry.getObjectInfo(msg.sender);
67
+ require(info.objectType == expectedType, "OBJECT_TYPE_INVALID");
30
68
 
31
- address instanceAddress = getRegistry().getObjectInfo(info.parentNftId).objectAddress;
69
+ address instanceAddress = registry.getObjectInfo(info.parentNftId).objectAddress;
32
70
  instance = IInstance(instanceAddress);
33
71
  }
34
-
35
- function getRegistryService() public view virtual returns (IRegistryService) {
36
- address service = getRegistry().getServiceAddress("RegistryService", getMajorVersion());
37
- return IRegistryService(service);
38
- }
39
72
  }
@@ -5,34 +5,44 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
5
5
  import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
6
 
7
7
  import {RoleId} from "../../types/RoleId.sol";
8
+ import {Timestamp} from "../../types/Timestamp.sol";
8
9
 
9
10
  interface IAccess {
11
+
10
12
  struct RoleInfo {
11
13
  ShortString name;
12
14
  bool isCustom;
15
+ bool isLocked;
16
+ Timestamp createdAt;
17
+ Timestamp updatedAt;
13
18
  }
14
19
 
15
20
  struct TargetInfo {
16
21
  ShortString name;
17
22
  bool isCustom;
23
+ bool isLocked;
24
+ Timestamp createdAt;
25
+ Timestamp updatedAt;
18
26
  }
19
27
 
20
- error ErrorTargetAddressZero();
21
- error ErrorTargetAlreadyExists(address target, ShortString name);
22
- error ErrorTargetDoesNotExist(address target);
23
- error ErrorTargetNameEmpty(address target);
24
- error ErrorTargetNameExists(address target, address existingTarget, ShortString name);
25
-
26
- error ErrorRoleIdInvalid(RoleId roleId);
27
- error ErrorRoleIdTooBig(RoleId roleId);
28
- error ErrorRoleIdTooSmall(RoleId roleId);
29
- error ErrorRoleIdAlreadyExists(RoleId roleId, ShortString name);
30
- error ErrorRoleIdNotActive(RoleId roleId);
31
- error ErrorRoleNameEmpty(RoleId roleId);
32
- error ErrorRoleNameNotUnique(RoleId roleId, ShortString name);
33
- error ErrorRoleInvalidUpdate(RoleId roleId, bool isCustom);
34
- error ErrorGrantNonexstentRole(RoleId roleId);
35
- error ErrorRevokeNonexstentRole(RoleId roleId);
36
- error ErrorRenounceNonexstentRole(RoleId roleId);
28
+ error ErrorIAccessRoleIdInvalid(RoleId roleId);
29
+ error ErrorIAccessRoleIdTooBig(RoleId roleId);
30
+ error ErrorIAccessRoleIdTooSmall(RoleId roleId);
31
+ error ErrorIAccessRoleIdAlreadyExists(RoleId roleId, ShortString name);
32
+ error ErrorIAccessRoleIdNotActive(RoleId roleId);
33
+ error ErrorIAccessRoleNameEmpty(RoleId roleId);
34
+ error ErrorIAccessRoleNameNotUnique(RoleId roleId, ShortString name);
35
+ error ErrorIAccessRoleInvalidUpdate(RoleId roleId, bool isCustom);
36
+ error ErrorIAccessRoleIsCustomIsImmutable(RoleId roleId, bool isCustom, bool isCustomExisting);
37
+ error ErrorIAccessSetLockedForNonexstentRole(RoleId roleId);
38
+ error ErrorIAccessGrantNonexstentRole(RoleId roleId);
39
+ error ErrorIAccessRevokeNonexstentRole(RoleId roleId);
40
+ error ErrorIAccessRenounceNonexstentRole(RoleId roleId);
41
+
42
+ error ErrorIAccessTargetAddressZero();
43
+ error ErrorIAccessTargetAlreadyExists(address target, ShortString name);
44
+ error ErrorIAccessTargetNameEmpty(address target);
45
+ error ErrorIAccessTargetNameExists(address target, address existingTarget, ShortString name);
46
+ error ErrorIAccessSetLockedForNonexstentTarget(address target);
37
47
 
38
48
  }
@@ -13,6 +13,7 @@ interface IBundle {
13
13
  uint256 capitalAmount; // net investment capital + net premiums - payouts
14
14
  uint256 lockedAmount; // capital amount linked to collateralizaion of non-closed policies (<= balance)
15
15
  uint256 balanceAmount; // total amount of funds: capitalAmount + fees (balance >= captial)
16
+ uint256 lifetime;
16
17
  Timestamp expiredAt; // no new policies
17
18
  Timestamp closedAt; // no open policies, locked amount = 0
18
19
  }