@etherisc/gif-next 0.0.2-e2d8c7d-942 → 0.0.2-e38b7e6-931

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +40 -0
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +42 -100
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +40 -0
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +5 -5
  11. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  12. package/artifacts/contracts/components/Pool.sol/Pool.json +42 -128
  13. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  14. package/artifacts/contracts/components/Product.sol/Product.json +47 -116
  15. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  35. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  36. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  38. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  40. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +90 -13
  41. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  42. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +88 -14
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +56 -616
  46. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  47. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +221 -114
  48. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  49. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +2 -2
  50. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  51. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +2 -2
  52. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +126 -242
  54. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  55. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +26 -126
  56. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  57. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  58. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  59. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +114 -13
  60. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +0 -13
  62. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  63. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +59 -16
  68. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +235 -37
  76. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +20 -24
  78. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +145 -38
  80. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +17 -21
  82. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +64 -13
  84. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +13 -13
  86. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +120 -13
  88. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +13 -13
  90. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +13 -13
  92. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +326 -64
  94. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +51 -23
  96. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +145 -38
  98. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +17 -21
  100. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  101. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +151 -44
  102. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  103. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +17 -13
  104. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  105. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  106. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  107. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +132 -133
  108. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  109. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -65
  110. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  111. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  112. package/artifacts/contracts/registry/Registry.sol/Registry.json +145 -227
  113. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  114. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  115. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  116. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +30 -128
  117. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  118. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +38 -104
  119. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  120. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +530 -0
  121. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +14 -27
  123. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  124. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  125. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IService.sol/IService.json +13 -13
  129. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  132. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  134. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  136. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  137. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  138. package/artifacts/contracts/shared/Service.sol/Service.json +13 -13
  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 +2 -2
  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 +31 -31
  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/NumberId.sol/NumberIdLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  167. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  173. package/contracts/components/BaseComponent.sol +48 -12
  174. package/contracts/components/Distribution.sol +2 -11
  175. package/contracts/components/IBaseComponent.sol +5 -1
  176. package/contracts/components/IProductComponent.sol +2 -2
  177. package/contracts/components/Pool.sol +5 -18
  178. package/contracts/components/Product.sol +19 -16
  179. package/contracts/instance/IInstance.sol +3 -3
  180. package/contracts/instance/IInstanceBase.sol +0 -1
  181. package/contracts/instance/IInstanceService.sol +9 -3
  182. package/contracts/instance/Instance.sol +12 -214
  183. package/contracts/instance/InstanceAccessManager.sol +92 -77
  184. package/contracts/instance/InstanceBase.sol +0 -2
  185. package/contracts/instance/InstanceService.sol +118 -72
  186. package/contracts/instance/InstanceServiceManager.sol +5 -8
  187. package/contracts/instance/base/ComponentServiceBase.sol +78 -12
  188. package/contracts/instance/base/IInstanceBase.sol +0 -2
  189. package/contracts/instance/module/IAccess.sol +27 -17
  190. package/contracts/instance/service/BundleService.sol +39 -5
  191. package/contracts/instance/service/BundleServiceManager.sol +5 -8
  192. package/contracts/instance/service/DistributionService.sol +33 -36
  193. package/contracts/instance/service/DistributionServiceManager.sol +6 -9
  194. package/contracts/instance/service/IBundleService.sol +5 -6
  195. package/contracts/instance/service/IPolicyService.sol +7 -0
  196. package/contracts/instance/service/PolicyService.sol +65 -34
  197. package/contracts/instance/service/PoolService.sol +46 -28
  198. package/contracts/instance/service/PoolServiceManager.sol +5 -8
  199. package/contracts/instance/service/ProductService.sol +66 -30
  200. package/contracts/registry/ChainNft.sol +1 -1
  201. package/contracts/registry/IRegistry.sol +26 -16
  202. package/contracts/registry/IRegistryService.sol +13 -5
  203. package/contracts/registry/Registry.sol +149 -201
  204. package/contracts/registry/RegistryAccessManager.sol +210 -0
  205. package/contracts/registry/RegistryService.sol +50 -88
  206. package/contracts/registry/RegistryServiceManager.sol +18 -36
  207. package/contracts/registry/ReleaseManager.sol +342 -0
  208. package/contracts/registry/TokenRegistry.sol +5 -6
  209. package/contracts/shared/IRegisterable.sol +0 -2
  210. package/contracts/shared/IService.sol +2 -1
  211. package/contracts/shared/ProxyManager.sol +1 -1
  212. package/contracts/shared/Service.sol +10 -7
  213. package/contracts/test/TestService.sol +3 -2
  214. package/contracts/types/RoleId.sol +10 -12
  215. package/package.json +1 -1
  216. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
  217. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
  218. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +0 -4
  219. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +0 -827
  220. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +0 -4
  221. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +0 -466
  222. package/contracts/instance/IAccessManagerSimple.sol +0 -391
  223. package/contracts/instance/service/ComponentOwnerService.sol +0 -317
  224. package/contracts/instance/service/IComponentOwnerService.sol +0 -20
@@ -2,21 +2,22 @@
2
2
  pragma solidity ^0.8.20;
3
3
 
4
4
  import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5
- import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
6
5
 
7
- import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.sol";
8
6
  import {Instance} from "./Instance.sol";
7
+ import {IInstance} from "./IInstance.sol";
8
+ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
9
9
  import {IInstanceService} from "./IInstanceService.sol";
10
10
  import {InstanceReader} from "./InstanceReader.sol";
11
11
  import {BundleManager} from "./BundleManager.sol";
12
12
  import {IRegistry} from "../registry/IRegistry.sol";
13
13
  import {RegistryService} from "../registry/RegistryService.sol";
14
+ import {ChainNft} from "../registry/ChainNft.sol";
14
15
  import {Service} from "../../contracts/shared/Service.sol";
15
16
  import {IService} from "../shared/IService.sol";
16
17
  import {NftId} from "../../contracts/types/NftId.sol";
17
18
  import {RoleId} from "../types/RoleId.sol";
18
- import {VersionLib} from "../types/Version.sol";
19
- import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE, PRODUCT_SERVICE_ROLE, POLICY_SERVICE_ROLE, BUNDLE_SERVICE_ROLE} from "../types/RoleId.sol";
19
+ import {ADMIN_ROLE, DISTRIBUTION_OWNER_ROLE, POOL_OWNER_ROLE, PRODUCT_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
+ import {ObjectType, INSTANCE, BUNDLE, POLICY, PRODUCT, DISTRIBUTION, REGISTRY, POOL} from "../types/ObjectType.sol";
20
21
 
21
22
  contract InstanceService is Service, IInstanceService {
22
23
 
@@ -29,10 +30,28 @@ contract InstanceService is Service, IInstanceService {
29
30
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
30
31
  string public constant NAME = "InstanceService";
31
32
 
33
+ modifier onlyInstanceOwner(NftId instanceNftId) {
34
+ IRegistry registry = getRegistry();
35
+ ChainNft chainNft = registry.getChainNft();
36
+
37
+ if( msg.sender != chainNft.ownerOf(instanceNftId.toInt())) {
38
+ revert ErrorInstanceServiceNotInstanceOwner(msg.sender, instanceNftId);
39
+ }
40
+ _;
41
+ }
42
+
43
+ modifier onlyRegisteredService() {
44
+ address caller = msg.sender;
45
+ if (! getRegistry().isRegisteredService(caller)) {
46
+ revert ErrorInstanceServiceRequestUnauhorized(caller);
47
+ }
48
+ _;
49
+ }
50
+
32
51
  function createInstanceClone()
33
52
  external
34
53
  returns (
35
- AccessManagerUpgradeableInitializeable clonedAccessManager,
54
+ InstanceAccessManager clonedAccessManager,
36
55
  Instance clonedInstance,
37
56
  NftId clonedInstanceNftId,
38
57
  InstanceReader clonedInstanceReader,
@@ -43,14 +62,14 @@ contract InstanceService is Service, IInstanceService {
43
62
  IRegistry registry = getRegistry();
44
63
  address registryAddress = address(registry);
45
64
  NftId registryNftId = registry.getNftId(registryAddress);
46
- address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
65
+ address registryServiceAddress = registry.getServiceAddress(REGISTRY(), getMajorVersion());
47
66
  RegistryService registryService = RegistryService(registryServiceAddress);
48
67
 
49
68
  // initially set the authority of the access managar to this (being the instance service).
50
69
  // This will allow the instance service to bootstrap the authorizations of the instance
51
70
  // and then transfer the ownership of the access manager to the instance owner once everything is setup
52
- clonedAccessManager = AccessManagerUpgradeableInitializeable(Clones.clone(_masterInstanceAccessManager));
53
- clonedAccessManager.__AccessManagerUpgradeableInitializeable_init(address(this));
71
+ clonedAccessManager = InstanceAccessManager(Clones.clone(_masterInstanceAccessManager));
72
+ clonedAccessManager.__InstanceAccessManager_initialize(address(this));
54
73
 
55
74
  clonedInstance = Instance(Clones.clone(_masterInstance));
56
75
  clonedInstance.initialize(address(clonedAccessManager), registryAddress, registryNftId, msg.sender);
@@ -71,14 +90,16 @@ contract InstanceService is Service, IInstanceService {
71
90
 
72
91
  // to complete setup switch instance ownership to the instance owner
73
92
  // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
74
- clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
75
- clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
93
+ clonedAccessManager.grantRole(ADMIN_ROLE(), instanceOwner);
94
+ clonedAccessManager.revokeRole(ADMIN_ROLE(), address(this));
76
95
 
77
96
  emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
78
97
  }
79
98
 
80
- function _grantInitialAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
81
- _grantRegistryServiceAuthorizations(clonedAccessManager, clonedInstance);
99
+ function _grantInitialAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
100
+ _createGifRoles(clonedAccessManager);
101
+ _createGifTargets(clonedAccessManager, clonedInstance, clonedBundleManager);
102
+ _grantDistributionServiceAuthorizations(clonedAccessManager, clonedInstance);
82
103
  _grantPoolServiceAuthorizations(clonedAccessManager, clonedInstance);
83
104
  _grantProductServiceAuthorizations(clonedAccessManager, clonedInstance);
84
105
  _grantPolicyServiceAuthorizations(clonedAccessManager, clonedInstance);
@@ -86,37 +107,55 @@ contract InstanceService is Service, IInstanceService {
86
107
  _grantInstanceServiceAuthorizations(clonedAccessManager, clonedInstance);
87
108
  }
88
109
 
89
- function _grantRegistryServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance) internal {
110
+ function _createGifRoles(InstanceAccessManager clonedAccessManager) internal {
111
+ clonedAccessManager.createGifRole(DISTRIBUTION_OWNER_ROLE(), "DistributionOwnerRole");
112
+ clonedAccessManager.createGifRole(POOL_OWNER_ROLE(), "PoolOwnerRole");
113
+ clonedAccessManager.createGifRole(PRODUCT_OWNER_ROLE(), "ProductOwnerRole");
114
+
115
+ clonedAccessManager.createGifRole(DISTRIBUTION_SERVICE_ROLE(), "DistributionServiceRole");
116
+ clonedAccessManager.createGifRole(POOL_SERVICE_ROLE(), "PoolServiceRole");
117
+ clonedAccessManager.createGifRole(PRODUCT_SERVICE_ROLE(), "ProductServiceRole");
118
+ clonedAccessManager.createGifRole(POLICY_SERVICE_ROLE(), "PolicyServiceRole");
119
+ clonedAccessManager.createGifRole(BUNDLE_SERVICE_ROLE(), "BundleServiceRole");
120
+ clonedAccessManager.createGifRole(INSTANCE_SERVICE_ROLE(), "InstanceServiceRole");
121
+ }
122
+
123
+ function _createGifTargets(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
124
+ clonedAccessManager.createGifTarget(address(clonedInstance), "Instance");
125
+ clonedAccessManager.createGifTarget(address(clonedBundleManager), "BundleManager");
126
+ }
127
+
128
+ function _grantDistributionServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
90
129
  // configure authorization for distribution service on instance
91
130
  IRegistry registry = getRegistry();
92
- address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
93
- clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
131
+ address distributionServiceAddress = registry.getServiceAddress(DISTRIBUTION(), getMajorVersion());
132
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE(), distributionServiceAddress);
94
133
  bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
95
134
  instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
96
135
  instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
97
136
  clonedAccessManager.setTargetFunctionRole(
98
- address(clonedInstance),
137
+ "Instance",
99
138
  instanceDistributionServiceSelectors,
100
- DISTRIBUTION_SERVICE_ROLE().toInt());
139
+ DISTRIBUTION_SERVICE_ROLE());
101
140
  }
102
141
 
103
- function _grantPoolServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance) internal {
142
+ function _grantPoolServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
104
143
  // configure authorization for pool service on instance
105
- address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
106
- clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
144
+ address poolServiceAddress = _registry.getServiceAddress(POOL(), getMajorVersion());
145
+ clonedAccessManager.grantRole(POOL_SERVICE_ROLE(), address(poolServiceAddress));
107
146
  bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
108
147
  instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
109
148
  instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
110
149
  clonedAccessManager.setTargetFunctionRole(
111
- address(clonedInstance),
150
+ "Instance",
112
151
  instancePoolServiceSelectors,
113
- POOL_SERVICE_ROLE().toInt());
152
+ POOL_SERVICE_ROLE());
114
153
  }
115
154
 
116
- function _grantProductServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance) internal {
155
+ function _grantProductServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
117
156
  // configure authorization for product service on instance
118
- address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
119
- clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE().toInt(), address(productServiceAddress), 0);
157
+ address productServiceAddress = _registry.getServiceAddress(PRODUCT(), getMajorVersion());
158
+ clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE(), address(productServiceAddress));
120
159
  bytes4[] memory instanceProductServiceSelectors = new bytes4[](5);
121
160
  instanceProductServiceSelectors[0] = clonedInstance.createProductSetup.selector;
122
161
  instanceProductServiceSelectors[1] = clonedInstance.updateProductSetup.selector;
@@ -124,36 +163,36 @@ contract InstanceService is Service, IInstanceService {
124
163
  instanceProductServiceSelectors[3] = clonedInstance.updateRisk.selector;
125
164
  instanceProductServiceSelectors[4] = clonedInstance.updateRiskState.selector;
126
165
  clonedAccessManager.setTargetFunctionRole(
127
- address(clonedInstance),
166
+ "Instance",
128
167
  instanceProductServiceSelectors,
129
- PRODUCT_SERVICE_ROLE().toInt());
168
+ PRODUCT_SERVICE_ROLE());
130
169
  }
131
170
 
132
- function _grantPolicyServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance) internal {
171
+ function _grantPolicyServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
133
172
  // configure authorization for policy service on instance
134
- address policyServiceAddress = _registry.getServiceAddress("PolicyService", VersionLib.toVersion(3, 0, 0).toMajorPart());
135
- clonedAccessManager.grantRole(POLICY_SERVICE_ROLE().toInt(), address(policyServiceAddress), 0);
173
+ address policyServiceAddress = _registry.getServiceAddress(POLICY(), getMajorVersion());
174
+ clonedAccessManager.grantRole(POLICY_SERVICE_ROLE(), address(policyServiceAddress));
136
175
  bytes4[] memory instancePolicyServiceSelectors = new bytes4[](3);
137
176
  instancePolicyServiceSelectors[0] = clonedInstance.createPolicy.selector;
138
177
  instancePolicyServiceSelectors[1] = clonedInstance.updatePolicy.selector;
139
178
  instancePolicyServiceSelectors[2] = clonedInstance.updatePolicyState.selector;
140
179
  clonedAccessManager.setTargetFunctionRole(
141
- address(clonedInstance),
180
+ "Instance",
142
181
  instancePolicyServiceSelectors,
143
- POLICY_SERVICE_ROLE().toInt());
182
+ POLICY_SERVICE_ROLE());
144
183
  }
145
184
 
146
- function _grantBundleServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
185
+ function _grantBundleServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
147
186
  // configure authorization for bundle service on instance
148
- address bundleServiceAddress = _registry.getServiceAddress("BundleService", VersionLib.toVersion(3, 0, 0).toMajorPart());
149
- clonedAccessManager.grantRole(BUNDLE_SERVICE_ROLE().toInt(), address(bundleServiceAddress), 0);
187
+ address bundleServiceAddress = _registry.getServiceAddress(BUNDLE(), getMajorVersion());
188
+ clonedAccessManager.grantRole(BUNDLE_SERVICE_ROLE(), address(bundleServiceAddress));
150
189
  bytes4[] memory instanceBundleServiceSelectors = new bytes4[](2);
151
190
  instanceBundleServiceSelectors[0] = clonedInstance.createBundle.selector;
152
191
  instanceBundleServiceSelectors[1] = clonedInstance.updateBundle.selector;
153
192
  clonedAccessManager.setTargetFunctionRole(
154
- address(clonedInstance),
193
+ "Instance",
155
194
  instanceBundleServiceSelectors,
156
- BUNDLE_SERVICE_ROLE().toInt());
195
+ BUNDLE_SERVICE_ROLE());
157
196
 
158
197
  // configure authorization for bundle service on bundle manager
159
198
  bytes4[] memory bundleManagerBundleServiceSelectors = new bytes4[](5);
@@ -163,21 +202,21 @@ contract InstanceService is Service, IInstanceService {
163
202
  bundleManagerBundleServiceSelectors[3] = clonedBundleManager.lock.selector;
164
203
  bundleManagerBundleServiceSelectors[4] = clonedBundleManager.unlock.selector;
165
204
  clonedAccessManager.setTargetFunctionRole(
166
- address(clonedBundleManager),
205
+ "BundleManager",
167
206
  bundleManagerBundleServiceSelectors,
168
- BUNDLE_SERVICE_ROLE().toInt());
207
+ BUNDLE_SERVICE_ROLE());
169
208
  }
170
209
 
171
- function _grantInstanceServiceAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance) internal {
210
+ function _grantInstanceServiceAuthorizations(InstanceAccessManager clonedAccessManager, Instance clonedInstance) internal {
172
211
  // configure authorization for instance service on instance
173
- address instanceServiceAddress = _registry.getServiceAddress("InstanceService", VersionLib.toVersion(3, 0, 0).toMajorPart());
174
- clonedAccessManager.grantRole(INSTANCE_SERVICE_ROLE().toInt(), instanceServiceAddress, 0);
212
+ address instanceServiceAddress = _registry.getServiceAddress(INSTANCE(), getMajorVersion());
213
+ clonedAccessManager.grantRole(INSTANCE_SERVICE_ROLE(), instanceServiceAddress);
175
214
  bytes4[] memory instanceInstanceServiceSelectors = new bytes4[](1);
176
215
  instanceInstanceServiceSelectors[0] = clonedInstance.setInstanceReader.selector;
177
216
  clonedAccessManager.setTargetFunctionRole(
178
- address(clonedInstance),
217
+ "Instance",
179
218
  instanceInstanceServiceSelectors,
180
- INSTANCE_SERVICE_ROLE().toInt());
219
+ INSTANCE_SERVICE_ROLE());
181
220
  }
182
221
 
183
222
  function setMasterInstance(address accessManagerAddress, address instanceAddress, address instanceReaderAddress, address bundleManagerAddress) external onlyOwner {
@@ -247,15 +286,11 @@ contract InstanceService is Service, IInstanceService {
247
286
  }
248
287
 
249
288
  // From IService
250
- function getName() public pure override(IService, Service) returns(string memory) {
251
- return NAME;
289
+ function getDomain() public pure override(Service, IService) returns(ObjectType) {
290
+ return INSTANCE();
252
291
  }
253
292
 
254
293
  /// @dev top level initializer
255
- // 1) registry is non upgradeable -> don't need a proxy and uses constructor !
256
- // 2) deploy registry service first -> from its initialization func it is easier to deploy registry then vice versa
257
- // 3) deploy registry -> pass registry service address as constructor argument
258
- // registry is getting instantiated and locked to registry service address forever
259
294
  function _initialize(
260
295
  address owner,
261
296
  bytes memory data
@@ -264,36 +299,47 @@ contract InstanceService is Service, IInstanceService {
264
299
  initializer
265
300
  virtual override
266
301
  {
267
- address initialOwner = address(0);
268
- address registryAddress = address(0);
302
+ address initialOwner;
303
+ address registryAddress;
269
304
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
270
305
  // TODO while InstanceService is not deployed in InstanceServiceManager constructor
271
306
  // owner is InstanceServiceManager deployer
272
307
  _initializeService(registryAddress, owner);
273
308
 
274
- _registerInterface(type(IService).interfaceId);
275
309
  _registerInterface(type(IInstanceService).interfaceId);
276
310
  }
277
- // TODO use instanceAddress instead of nft
278
- /*function hasRole(address account, RoleId role, NftId instanceNftId) external view returns (bool) {
279
- IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
280
- address instanceAddress = instanceObjectInfo.objectAddress;
281
- Instance instance = Instance(instanceAddress);
282
- AccessManagerUpgradeable accessManager = AccessManagerUpgradeable(instance.authority());
283
- (bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
284
- if (executionDelay > 0) {
285
- return false;
286
- }
287
- return isMember;
288
- }*/
289
- function hasRole(address account, RoleId role, address instanceAddress) external view returns (bool) {
311
+
312
+ function hasRole(address account, RoleId role, address instanceAddress) public view returns (bool) {
290
313
  Instance instance = Instance(instanceAddress);
291
- AccessManagerUpgradeable accessManager = AccessManagerUpgradeable(instance.authority());
292
- (bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
293
- if (executionDelay > 0) {
294
- return false;
295
- }
296
- return isMember;
314
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
315
+ return accessManager.hasRole(role, account);
297
316
  }
317
+
318
+ function createTarget(NftId instanceNftId, address targetAddress, string memory targetName) external onlyRegisteredService {
319
+ IRegistry registry = getRegistry();
320
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(instanceNftId);
321
+ Instance instance = Instance(instanceInfo.objectAddress);
322
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
323
+ accessManager.createTarget(targetAddress, targetName);
324
+ }
325
+
326
+ function setTargetLocked(string memory targetName, bool locked) external {
327
+ address componentAddress = msg.sender;
328
+ IRegistry registry = getRegistry();
329
+ IRegistry.ObjectInfo memory componentInfo = registry.getObjectInfo(componentAddress);
330
+ if (componentInfo.nftId.eqz()) {
331
+ revert ErrorInstanceServiceComponentNotRegistered(componentAddress);
332
+ }
333
+
334
+ // TODO validate component type
335
+
336
+
337
+ address instanceAddress = registry.getObjectInfo(componentInfo.parentNftId).objectAddress;
338
+ IInstance instance = IInstance(instanceAddress);
339
+
340
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
341
+ accessManager.setTargetClosed(targetName, locked);
342
+ }
343
+
298
344
  }
299
345
 
@@ -7,7 +7,7 @@ import {ProxyManager} from "../shared/ProxyManager.sol";
7
7
  import {InstanceService} from "./InstanceService.sol";
8
8
  import {Registry} from "../registry/Registry.sol";
9
9
  import {RegistryService} from "../registry/RegistryService.sol";
10
- import {VersionLib} from "../types/Version.sol";
10
+ import {REGISTRY} from "../types/ObjectType.sol";
11
11
 
12
12
  contract InstanceServiceManager is ProxyManager {
13
13
 
@@ -28,10 +28,10 @@ contract InstanceServiceManager is ProxyManager {
28
28
 
29
29
  _instanceService = InstanceService(address(versionable));
30
30
 
31
- Registry registry = Registry(registryAddress);
32
- address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
33
- RegistryService registryService = RegistryService(registryServiceAddress);
34
- // TODO this must have a role or own nft to register service
31
+ // TODO `this` must have a role or own nft to register service
32
+ //Registry registry = Registry(registryAddress);
33
+ //address registryServiceAddress = registry.getServiceAddress(REGISTRY(), _instanceService.getMajorVersion());
34
+ //RegistryService registryService = RegistryService(registryServiceAddress);
35
35
  //registryService.registerService(_instanceService);
36
36
  // RegistryService registryService = _instanceService.getRegistryService();
37
37
 
@@ -40,9 +40,6 @@ contract InstanceServiceManager is ProxyManager {
40
40
  //_linkToNftOwnable(
41
41
  // address(registryAddress),
42
42
  // address(_instanceService));
43
-
44
- // implies that after this constructor call only upgrade functionality is available
45
- _isDeployed = true;
46
43
  }
47
44
 
48
45
  //--- view functions ----------------------------------------------------//
@@ -1,22 +1,29 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IBaseComponent} from "../../components/IBaseComponent.sol";
4
5
  import {IRegistry} from "../../registry/IRegistry.sol";
5
6
  import {IRegistryService} from "../../registry/IRegistryService.sol";
6
7
  import {IInstance} from "../../instance/IInstance.sol";
7
- import {ObjectType, INSTANCE, PRODUCT, POOL, DISTRIBUTION, ORACLE} from "../../types/ObjectType.sol";
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";
8
+ import {IAccess} from "../module/IAccess.sol";
9
+ import {ObjectType, INSTANCE, REGISTRY} from "../../types/ObjectType.sol";
10
+ import {NftId} from "../../types/NftId.sol";
11
+ import {RoleId} from "../../types/RoleId.sol";
10
12
 
11
- import {BaseComponent} from "../../components/BaseComponent.sol";
12
- import {Product} from "../../components/Product.sol";
13
- import {INftOwnable} from "../../shared/INftOwnable.sol";
14
13
  import {Service} from "../../shared/Service.sol";
15
14
  import {InstanceService} from "../InstanceService.sol";
16
- import {Version, VersionPart, VersionLib} from "../../types/Version.sol";
15
+ import {InstanceAccessManager} from "../InstanceAccessManager.sol";
17
16
 
18
17
  abstract contract ComponentServiceBase is Service {
19
18
 
19
+
20
+ error ErrorComponentServiceAlreadyRegistered(address component, NftId nftId);
21
+ error ErrorComponentServiceNotComponent(address component);
22
+ error ErrorComponentServiceInvalidType(address component, ObjectType requiredType, ObjectType componentType);
23
+ error ErrorComponentServiceSenderNotOwner(address component, address initialOwner, address sender);
24
+ error ErrorComponentServiceExpectedRoleMissing(NftId instanceNftId, RoleId requiredRole, address sender);
25
+
26
+ error ErrorComponentServiceBaseComponentLocked(address componentAddress);
20
27
  error ExpectedRoleMissing(RoleId expected, address caller);
21
28
  error ComponentTypeInvalid(ObjectType componentType);
22
29
 
@@ -31,19 +38,73 @@ abstract contract ComponentServiceBase is Service {
31
38
  // view functions
32
39
 
33
40
  function getRegistryService() public view virtual returns (IRegistryService) {
34
- address service = getRegistry().getServiceAddress("RegistryService", getMajorVersion());
41
+ address service = getRegistry().getServiceAddress(REGISTRY(), getMajorVersion());
35
42
  return IRegistryService(service);
36
43
  }
37
44
 
38
45
  function getInstanceService() public view returns (InstanceService) {
39
- return InstanceService(getRegistry().getServiceAddress("InstanceService", getMajorVersion()));
46
+ address service = getRegistry().getServiceAddress(INSTANCE(), getMajorVersion());
47
+ return InstanceService(service);
48
+ }
49
+
50
+ // internal functions
51
+ function _checkComponentForRegistration(
52
+ address componentAddress,
53
+ ObjectType requiredType,
54
+ RoleId requiredRole
55
+ )
56
+ internal
57
+ returns (
58
+ IBaseComponent component,
59
+ address owner,
60
+ IInstance instance,
61
+ NftId instanceNftId
62
+ )
63
+ {
64
+ // component may only be registerd by initial owner of component
65
+ owner = msg.sender;
66
+
67
+ // check component has not already been registerd
68
+ NftId compoentNftId = _registry.getNftId(componentAddress);
69
+ if(compoentNftId.gtz()) {
70
+ revert ErrorComponentServiceAlreadyRegistered(componentAddress, compoentNftId);
71
+ }
72
+
73
+ // check this is a component
74
+ component = IBaseComponent(componentAddress);
75
+ if(!component.supportsInterface(type(IBaseComponent).interfaceId)) {
76
+ revert ErrorComponentServiceNotComponent(componentAddress);
77
+ }
78
+
79
+ // check component is of required type
80
+ (IRegistry.ObjectInfo memory componentInfo, ) = component.getInitialInfo();
81
+ if(componentInfo.objectType != requiredType) {
82
+ revert ErrorComponentServiceInvalidType(componentAddress, requiredType, componentInfo.objectType);
83
+ }
84
+
85
+ // check msg.sender is component owner
86
+ address initialOwner = componentInfo.initialOwner;
87
+ if(owner != initialOwner) {
88
+ revert ErrorComponentServiceSenderNotOwner(componentAddress, componentInfo.initialOwner, owner);
89
+ }
90
+
91
+ // check instance has assigned required role to owner
92
+ instanceNftId = componentInfo.parentNftId;
93
+ instance = _getInstance(instanceNftId);
94
+ bool hasRole = getInstanceService().hasRole(
95
+ owner,
96
+ requiredRole,
97
+ address(instance));
98
+
99
+ if(!hasRole) {
100
+ revert ErrorComponentServiceExpectedRoleMissing(instanceNftId, requiredRole, owner);
101
+ }
40
102
  }
41
103
 
42
104
  // internal view functions
43
105
 
44
- function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
45
- IRegistry registry = getRegistry();
46
- IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
106
+ function _getInstance(NftId instanceNftId) internal view returns (IInstance) {
107
+ IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
47
108
  return IInstance(instanceInfo.objectAddress);
48
109
  }
49
110
 
@@ -68,5 +129,10 @@ abstract contract ComponentServiceBase is Service {
68
129
 
69
130
  address instanceAddress = registry.getObjectInfo(info.parentNftId).objectAddress;
70
131
  instance = IInstance(instanceAddress);
132
+
133
+ InstanceAccessManager accessManager = InstanceAccessManager(instance.authority());
134
+ if (accessManager.isTargetLocked(info.objectAddress)) {
135
+ revert IAccess.ErrorIAccessTargetLocked(info.objectAddress);
136
+ }
71
137
  }
72
138
  }
@@ -6,7 +6,6 @@ import {StateId} from "../../types/StateId.sol";
6
6
 
7
7
  import {IKeyValueStore} from "./IKeyValueStore.sol";
8
8
 
9
- import {IComponentOwnerService} from "../service/IComponentOwnerService.sol";
10
9
  import {IDistributionService} from "../service/IDistributionService.sol";
11
10
  import {IProductService} from "../service/IProductService.sol";
12
11
  import {IPoolService} from "../service/IPoolService.sol";
@@ -16,7 +15,6 @@ interface IInstanceBase {
16
15
  function updateState(Key32 key, StateId state) external;
17
16
  function getState(Key32 key) external view returns (StateId state);
18
17
 
19
- function getComponentOwnerService() external view returns(IComponentOwnerService);
20
18
  function getDistributionService() external view returns(IDistributionService);
21
19
  function getProductService() external view returns(IProductService service);
22
20
  function getPoolService() external view returns(IPoolService service);
@@ -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);
37
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);
47
+ error ErrorIAccessTargetLocked(address target);
38
48
  }
@@ -14,7 +14,7 @@ import {Versionable} from "../../shared/Versionable.sol";
14
14
  import {INftOwnable} from "../../shared/INftOwnable.sol";
15
15
 
16
16
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
17
- import {POOL, BUNDLE} from "../../types/ObjectType.sol";
17
+ import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
18
18
  import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
19
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
20
20
  import {Version, VersionLib} from "../../types/Version.sol";
@@ -61,8 +61,8 @@ contract BundleService is
61
61
  _registerInterface(type(IBundleService).interfaceId);
62
62
  }
63
63
 
64
- function getName() public pure override(Service, IService) returns(string memory name) {
65
- return NAME;
64
+ function getDomain() public pure override(Service, IService) returns(ObjectType) {
65
+ return BUNDLE();
66
66
  }
67
67
 
68
68
  function createBundle(
@@ -186,6 +186,40 @@ contract BundleService is
186
186
  linkPolicy(instance, policyNftId);
187
187
  }
188
188
 
189
+ function increaseBalance(IInstance instance,
190
+ NftId bundleNftId,
191
+ uint256 amount
192
+ )
193
+ external
194
+ onlyService
195
+ {
196
+ InstanceReader instanceReader = instance.getInstanceReader();
197
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
198
+
199
+ bundleInfo.balanceAmount += amount;
200
+
201
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
202
+ }
203
+
204
+ function closePolicy(IInstance instance,
205
+ NftId policyNftId,
206
+ NftId bundleNftId,
207
+ uint256 collateralAmount
208
+ )
209
+ external
210
+ onlyService
211
+ {
212
+ InstanceReader instanceReader = instance.getInstanceReader();
213
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
214
+
215
+ // lock collateral
216
+ bundleInfo.lockedAmount -= collateralAmount;
217
+
218
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
219
+
220
+ unlinkPolicy(instance, policyNftId);
221
+ }
222
+
189
223
  /// @dev links policy to bundle
190
224
  function linkPolicy(IInstance instance, NftId policyNftId)
191
225
  internal
@@ -219,8 +253,8 @@ contract BundleService is
219
253
  }
220
254
 
221
255
  // ensure policy is closeable
222
- if (policyInfo.expiredAt < TimestampLib.blockTimestamp()
223
- || policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
256
+ if ( TimestampLib.blockTimestamp() < policyInfo.expiredAt
257
+ && policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
224
258
  {
225
259
  revert BundleManager.ErrorBundleManagerPolicyNotCloseable(policyNftId);
226
260
  }