@etherisc/gif-next 0.0.2-e4b632c-016 → 0.0.2-e510b92-393

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. package/README.md +67 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +139 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +149 -15
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +101 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +28 -2
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.json +181 -16
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +157 -56
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  36. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  37. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +0 -13
  38. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  40. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +775 -0
  41. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  42. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +185 -0
  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 +1347 -93
  46. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  47. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +5 -0
  48. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  49. package/artifacts/contracts/instance/Instance.sol/Instance.json +180 -101
  50. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  51. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +34 -47
  52. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +177 -38
  54. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  55. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +249 -34
  56. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  57. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +95 -15
  58. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  59. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  60. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +59 -0
  62. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  63. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  66. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  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/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +18 -18
  76. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +130 -18
  78. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +32 -16
  80. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +167 -0
  84. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +40 -31
  86. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  87. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +1049 -0
  88. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  89. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +464 -0
  90. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  91. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +1147 -0
  92. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  93. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +488 -0
  94. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  95. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +201 -0
  97. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  98. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -19
  99. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  100. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  101. package/artifacts/contracts/registry/Registry.sol/Registry.json +172 -49
  102. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  103. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +61 -29
  104. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  105. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +47 -34
  106. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  107. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
  108. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  109. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  110. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  111. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  112. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  113. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  114. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  116. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  117. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  118. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  119. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  120. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +4 -4
  121. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  122. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  123. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  124. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  125. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  126. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  127. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  128. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  129. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  130. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  131. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  132. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  133. package/artifacts/contracts/test/TestService.sol/TestService.json +11 -11
  134. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  136. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  137. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  139. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  140. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  141. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  146. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  147. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  148. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  149. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  155. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  161. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
  163. package/contracts/components/BaseComponent.sol +57 -11
  164. package/contracts/components/Distribution.sol +15 -18
  165. package/contracts/components/IBaseComponent.sol +7 -0
  166. package/contracts/components/IDistributionComponent.sol +1 -0
  167. package/contracts/components/IPoolComponent.sol +5 -1
  168. package/contracts/components/Pool.sol +36 -28
  169. package/contracts/components/Product.sol +34 -42
  170. package/contracts/instance/AccessManagedSimple.sol +1 -8
  171. package/contracts/instance/BundleManager.sol +129 -0
  172. package/contracts/instance/Cloneable.sol +46 -0
  173. package/contracts/instance/IInstance.sol +30 -7
  174. package/contracts/instance/IInstanceService.sol +3 -1
  175. package/contracts/instance/Instance.sol +27 -15
  176. package/contracts/instance/InstanceAccessManager.sol +1 -1
  177. package/contracts/instance/InstanceReader.sol +26 -1
  178. package/contracts/instance/InstanceService.sol +108 -14
  179. package/contracts/instance/InstanceServiceManager.sol +6 -5
  180. package/contracts/instance/ObjectManager.sol +95 -0
  181. package/contracts/instance/base/ComponentServiceBase.sol +96 -1
  182. package/contracts/instance/module/IBundle.sol +1 -0
  183. package/contracts/instance/module/ISetup.sol +3 -0
  184. package/contracts/instance/service/DistributionService.sol +26 -8
  185. package/contracts/instance/service/DistributionServiceManager.sol +7 -6
  186. package/contracts/instance/service/IPoolService.sol +16 -2
  187. package/contracts/instance/service/IProductService.sol +6 -3
  188. package/contracts/instance/service/PoolService.sol +287 -0
  189. package/contracts/instance/service/PoolServiceManager.sol +54 -0
  190. package/contracts/instance/service/ProductService.sol +570 -0
  191. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  192. package/contracts/registry/IRegistry.sol +25 -2
  193. package/contracts/registry/IRegistryService.sol +27 -12
  194. package/contracts/registry/Registry.sol +60 -35
  195. package/contracts/registry/RegistryService.sol +30 -116
  196. package/contracts/registry/RegistryServiceManager.sol +21 -5
  197. package/contracts/registry/TokenRegistry.sol +111 -0
  198. package/contracts/shared/ERC165.sol +6 -2
  199. package/contracts/shared/NftOwnable.sol +2 -4
  200. package/contracts/shared/Registerable.sol +1 -0
  201. package/contracts/shared/Service.sol +1 -0
  202. package/contracts/types/NftIdSet.sol +26 -24
  203. package/contracts/types/RoleId.sol +8 -0
  204. package/contracts/types/Version.sol +4 -1
  205. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IInstance} from "./IInstance.sol";
5
+ import {INSTANCE} from "../types/ObjectType.sol";
6
+ import {InstanceReader} from "./InstanceReader.sol";
7
+ import {IPolicy} from "../instance/module/IPolicy.sol";
8
+ import {IRegistry} from "../registry/IRegistry.sol";
9
+ import {LibNftIdSet} from "../types/NftIdSet.sol";
10
+ import {NftId} from "../types/NftId.sol";
11
+ import {TimestampLib} from "../types/Timestamp.sol";
12
+
13
+ import {ObjectManager} from "./ObjectManager.sol";
14
+
15
+ contract BundleManager is
16
+ ObjectManager
17
+ {
18
+
19
+ event LogBundleManagerPolicyLinked(NftId bundleNftId, NftId policyNftId);
20
+ event LogBundleManagerPolicyUnlinked(NftId bundleNftId, NftId policyNftId);
21
+
22
+ event LogBundleManagerBundleAdded(NftId poolNftId, NftId bundleNftId);
23
+ event LogBundleManagerBundleUnlocked(NftId poolNftId, NftId bundleNftId);
24
+ event LogBundleManagerBundleLocked(NftId poolNftId, NftId bundleNftId);
25
+
26
+ error ErrorBundleManagerErrorPolicyAlreadyActivated(NftId policyNftId);
27
+ error ErrorBundleManagerErrorBundleLocked(NftId bundleNftId, NftId policyNftId);
28
+ error ErrorBundleManagerPolicyWithOpenClaims(NftId policyNftId, uint256 openClaimsCount);
29
+ error ErrorBundleManagerPolicyNotCloseable(NftId policyNftId);
30
+ error ErrorBundleManagerBundleUnknown(NftId bundleNftId);
31
+ error ErrorBundleManagerBundleNotRegistered(NftId bundleNftId);
32
+
33
+ mapping(NftId bundleNftId => LibNftIdSet.Set policies) internal _activePolicies;
34
+
35
+ constructor() ObjectManager() {
36
+ }
37
+
38
+
39
+ /// @dev links a policy with its bundle
40
+ // to link a policy it MUST NOT yet have been activated
41
+ // the bundle MUST be unlocked (active) for linking (underwriting) and registered with this instance
42
+ function linkPolicy(NftId policyNftId) external restricted() {
43
+ NftId bundleNftId = _instanceReader.getPolicyInfo(policyNftId).bundleNftId;
44
+ // decision will likely depend on the decision what to check here and what in the service
45
+ NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
46
+
47
+ // ensure bundle is unlocked (in active set) and registered with this instance
48
+ if (!_isActive(poolNftId, bundleNftId)) {
49
+ revert ErrorBundleManagerErrorBundleLocked(bundleNftId, policyNftId);
50
+ }
51
+
52
+ LibNftIdSet.add(_activePolicies[bundleNftId], policyNftId);
53
+ emit LogBundleManagerPolicyLinked(bundleNftId, policyNftId);
54
+ }
55
+
56
+
57
+ /// @dev unlinks a policy from its bundle
58
+ // to unlink a policy it must closable, ie. meet one of the following criterias
59
+ // - the policy MUST be past its expiry period and it MUST NOT have any open claims
60
+ // - the policy's payoutAmount MUST be equal to its sumInsuredAmount and MUST NOT have any open claims
61
+ function unlinkPolicy(NftId policyNftId) external restricted() {
62
+ IPolicy.PolicyInfo memory policyInfo = _instanceReader.getPolicyInfo(policyNftId);
63
+
64
+ NftId bundleNftId = policyInfo.bundleNftId;
65
+ // decision will likely depend on the decision what to check here and what in the service
66
+ NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
67
+
68
+ // ensure bundle is registered with this instance
69
+ if (!_contains(poolNftId, bundleNftId)) {
70
+ revert ErrorBundleManagerBundleUnknown(bundleNftId);
71
+ }
72
+
73
+ LibNftIdSet.remove(_activePolicies[bundleNftId], policyNftId);
74
+ emit LogBundleManagerPolicyUnlinked(policyInfo.bundleNftId, policyNftId);
75
+ }
76
+
77
+
78
+ /// @dev add a new bundle to a riskpool registerd with this instance
79
+ // the corresponding pool is fetched via instance reader
80
+ function add(NftId bundleNftId) external restricted() {
81
+ NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
82
+
83
+ // ensure pool is registered with instance
84
+ if(poolNftId.eqz()) {
85
+ revert ErrorBundleManagerBundleNotRegistered(bundleNftId);
86
+ }
87
+
88
+ _add(poolNftId, bundleNftId);
89
+ emit LogBundleManagerBundleAdded(poolNftId, bundleNftId);
90
+ }
91
+
92
+ /// @dev unlocked (active) bundles are available to underwrite new policies
93
+ function unlock(NftId bundleNftId) external restricted() {
94
+ NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
95
+ _activate(poolNftId, bundleNftId);
96
+ emit LogBundleManagerBundleUnlocked(poolNftId, bundleNftId);
97
+ }
98
+
99
+ /// @dev locked (deactivated) bundles may not underwrite any new policies
100
+ function lock(NftId bundleNftId) external restricted() {
101
+ NftId poolNftId = _instanceReader.getBundleInfo(bundleNftId).poolNftId;
102
+ _deactivate(poolNftId, bundleNftId);
103
+ emit LogBundleManagerBundleLocked(poolNftId, bundleNftId);
104
+ }
105
+
106
+ function bundles(NftId poolNftId) external view returns(uint256) {
107
+ return _objects(poolNftId);
108
+ }
109
+
110
+ function getBundleNftId(NftId poolNftId, uint256 idx) external view returns(NftId bundleNftId) {
111
+ return _getObject(poolNftId, idx);
112
+ }
113
+
114
+ function activeBundles(NftId poolNftId) external view returns(uint256) {
115
+ return _activeObjs(poolNftId);
116
+ }
117
+
118
+ function getActiveBundleNftId(NftId poolNftId, uint256 idx) external view returns(NftId bundleNftId) {
119
+ return _getActiveObject(poolNftId, idx);
120
+ }
121
+
122
+ function activePolicies(NftId bundleNftId) external view returns(uint256) {
123
+ return LibNftIdSet.size(_activePolicies[bundleNftId]);
124
+ }
125
+
126
+ function getActivePolicy(NftId bundleNftId, uint256 idx) external view returns(NftId policyNftId) {
127
+ return LibNftIdSet.getElementAt(_activePolicies[bundleNftId], idx);
128
+ }
129
+ }
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
5
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
+
7
+ import {IRegistry} from "../registry/IRegistry.sol";
8
+
9
+ abstract contract Cloneable is
10
+ AccessManagedUpgradeable
11
+ {
12
+ event CloneableInitialized(address authority, address registry);
13
+
14
+ error CloneableRegistryInvalid(address registry);
15
+
16
+ IRegistry internal _registry;
17
+
18
+ constructor() {
19
+ _registry = IRegistry(address(0));
20
+ }
21
+
22
+ /// @dev call to initialize MUST be made in the same transaction as cloning of the contract
23
+ function initialize(
24
+ address authority,
25
+ address registry
26
+ )
27
+ public
28
+ initializer
29
+ {
30
+ // check/handle access managed
31
+ __AccessManaged_init(authority);
32
+
33
+ // check/handle registry
34
+ if (registry.code.length == 0) {
35
+ revert CloneableRegistryInvalid(registry);
36
+ }
37
+
38
+ _registry = IRegistry(registry);
39
+
40
+ emit CloneableInitialized(authority, registry);
41
+ }
42
+
43
+ function getRegistry() external view returns (IRegistry) {
44
+ return _registry;
45
+ }
46
+ }
@@ -3,31 +3,54 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
5
 
6
+ import {BundleManager} from "./BundleManager.sol";
6
7
  import {InstanceReader} from "./InstanceReader.sol";
7
8
 
8
9
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
9
10
  import {IDistributionService} from "./service/IDistributionService.sol";
10
11
  import {IPoolService} from "./service/IPoolService.sol";
11
12
  import {IProductService} from "./service/IProductService.sol";
13
+ import {IBundle} from "./module/IBundle.sol";
12
14
  import {ISetup} from "./module/ISetup.sol";
13
15
  import {NftId} from "../types/NftId.sol";
14
16
  import {StateId} from "../types/StateId.sol";
17
+ import {RiskId} from "../types/RiskId.sol";
18
+ import {IRisk} from "./module/IRisk.sol";
19
+ import {IPolicy} from "./module/IPolicy.sol";
20
+ import {IKeyValueStore} from "./base/IKeyValueStore.sol";
15
21
 
16
- interface IInstance is IERC165 {
22
+
23
+ interface IInstance is IERC165, IKeyValueStore {
17
24
 
18
25
  function getComponentOwnerService() external view returns (IComponentOwnerService);
19
- // TODO: renable these when we have the services
20
26
  function getDistributionService() external view returns (IDistributionService);
21
- // function getProductService() external view returns (IProductService);
22
- // function getPoolService() external view returns (IPoolService);
23
-
24
- function createProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup) external;
27
+ function getProductService() external view returns (IProductService);
28
+ function getPoolService() external view returns (IPoolService);
25
29
 
26
30
  function createDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup) external;
27
31
  function updateDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup, StateId newState) external;
28
32
  function updateDistributionSetupState(NftId distributionNftId, StateId newState) external;
29
33
 
30
- function createPoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup) external;
34
+ function createPoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup) external;
35
+ function updatePoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external;
36
+ function updatePoolSetupState(NftId poolNftId, StateId newState) external;
37
+
38
+ function createBundle(NftId bundleNftId, IBundle.BundleInfo memory bundle) external;
39
+ function updateBundle(NftId bundleNftId, IBundle.BundleInfo memory bundle, StateId newState) external;
40
+ function updateBundleState(NftId bundleNftId, StateId newState) external;
41
+
42
+ function createProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup) external;
43
+ function updateProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup, StateId newState) external;
44
+ function updateProductSetupState(NftId productNftId, StateId newState) external;
45
+
46
+ function createRisk(RiskId riskId, IRisk.RiskInfo memory risk) external;
47
+ function updateRisk(RiskId riskId, IRisk.RiskInfo memory risk, StateId newState) external;
48
+ function updateRiskState(RiskId riskId, StateId newState) external;
49
+
50
+ function createPolicy(NftId policyNftId, IPolicy.PolicyInfo memory policy) external;
51
+ function updatePolicy(NftId policyNftId, IPolicy.PolicyInfo memory policy, StateId newState) external;
52
+ function updatePolicyState(NftId policyNftId, StateId newState) external;
31
53
 
32
54
  function getInstanceReader() external view returns (InstanceReader);
55
+ function getBundleManager() external view returns (BundleManager);
33
56
  }
@@ -13,6 +13,7 @@ import {IBaseComponent} from "../components/IBaseComponent.sol";
13
13
  import {AccessManagerSimple} from "./AccessManagerSimple.sol";
14
14
  import {Instance} from "./Instance.sol";
15
15
  import {InstanceReader} from "./InstanceReader.sol";
16
+ import {BundleManager} from "./BundleManager.sol";
16
17
 
17
18
  interface IInstanceService is IService {
18
19
 
@@ -24,7 +25,8 @@ interface IInstanceService is IService {
24
25
  AccessManagerSimple clonedAccessManager,
25
26
  Instance clonedInstance,
26
27
  NftId instanceNftId,
27
- InstanceReader clonedInstanceReader
28
+ InstanceReader clonedInstanceReader,
29
+ BundleManager clonedBundleManager
28
30
  );
29
31
  }
30
32
 
@@ -15,6 +15,7 @@ import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
15
15
  import {KeyValueStore} from "./base/KeyValueStore.sol";
16
16
  import {IInstance} from "./IInstance.sol";
17
17
  import {InstanceReader} from "./InstanceReader.sol";
18
+ import {BundleManager} from "./BundleManager.sol";
18
19
  import {NftId} from "../types/NftId.sol";
19
20
  import {NumberId} from "../types/NumberId.sol";
20
21
  import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
@@ -26,6 +27,8 @@ import {Registerable} from "../shared/Registerable.sol";
26
27
  import {ComponentOwnerService} from "./service/ComponentOwnerService.sol";
27
28
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
28
29
  import {IDistributionService} from "./service/IDistributionService.sol";
30
+ import {IPoolService} from "./service/IPoolService.sol";
31
+ import {IProductService} from "./service/IProductService.sol";
29
32
  import {VersionPart} from "../types/Version.sol";
30
33
 
31
34
  contract Instance is
@@ -52,9 +55,9 @@ contract Instance is
52
55
 
53
56
  AccessManagerSimple internal _accessManager;
54
57
  InstanceReader internal _instanceReader;
58
+ BundleManager internal _bundleManager;
55
59
 
56
60
  constructor(address accessManagerAddress, address registryAddress, NftId registryNftId)
57
- AccessManagedSimple(accessManagerAddress)
58
61
  {
59
62
  initialize(accessManagerAddress, registryAddress, registryNftId, msg.sender);
60
63
  }
@@ -62,6 +65,8 @@ contract Instance is
62
65
  function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner) public {
63
66
  require(!_initialized, "Contract instance has already been initialized");
64
67
 
68
+ initializeAccessManagedSimple(accessManagerAddress);
69
+
65
70
  _accessManager = AccessManagerSimple(accessManagerAddress);
66
71
  _createRole(RoleIdLib.toRoleId(ADMIN_ROLE), "AdminRole", false, false);
67
72
  _createRole(RoleIdLib.toRoleId(PUBLIC_ROLE), "PublicRole", false, false);
@@ -219,16 +224,16 @@ contract Instance is
219
224
  }
220
225
 
221
226
  //--- PoolSetup ------------------------------------------------------//
222
- function createPoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup) external restricted() {
223
- create(_toNftKey32(distributionNftId, POOL()), abi.encode(setup));
227
+ function createPoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup) external restricted() {
228
+ create(_toNftKey32(poolNftId, POOL()), abi.encode(setup));
224
229
  }
225
230
 
226
- function updatePoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external restricted() {
227
- update(_toNftKey32(distributionNftId, POOL()), abi.encode(setup), newState);
231
+ function updatePoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external restricted() {
232
+ update(_toNftKey32(poolNftId, POOL()), abi.encode(setup), newState);
228
233
  }
229
234
 
230
- function updatePoolSetupState(NftId distributionNftId, StateId newState) external restricted() {
231
- updateState(_toNftKey32(distributionNftId, POOL()), newState);
235
+ function updatePoolSetupState(NftId poolNftId, StateId newState) external restricted() {
236
+ updateState(_toNftKey32(poolNftId, POOL()), newState);
232
237
  }
233
238
 
234
239
  //--- DistributorType ---------------------------------------------------//
@@ -421,15 +426,13 @@ contract Instance is
421
426
  return IDistributionService(_registry.getServiceAddress("DistributionService", VersionPart.wrap(3)));
422
427
  }
423
428
 
424
- // TODO reactivate when services are available
425
- // function getProductService() external view returns (IProductService) {
426
- // return ProductService(_registry.getServiceAddress("ProductService", VersionPart.wrap(3)));
427
- // }
429
+ function getProductService() external view returns (IProductService) {
430
+ return IProductService(_registry.getServiceAddress("ProductService", VersionPart.wrap(3)));
431
+ }
428
432
 
429
- // TODO reactivate when services are available
430
- // function getPoolService() external view returns (IPoolService) {
431
- // return PoolService(_registry.getServiceAddress("PoolService", VersionPart.wrap(3)));
432
- // }
433
+ function getPoolService() external view returns (IPoolService) {
434
+ return IPoolService(_registry.getServiceAddress("PoolService", VersionPart.wrap(3)));
435
+ }
433
436
 
434
437
  function setInstanceReader(InstanceReader instanceReader) external restricted() {
435
438
  require(address(_instanceReader) == address(0), "InstanceReader is set");
@@ -439,4 +442,13 @@ contract Instance is
439
442
  function getInstanceReader() external view returns (InstanceReader) {
440
443
  return _instanceReader;
441
444
  }
445
+
446
+ function setBundleManager(BundleManager bundleManager) external restricted() {
447
+ require(address(_bundleManager) == address(0), "BundleManager is set");
448
+ _bundleManager = bundleManager;
449
+ }
450
+
451
+ function getBundleManager() external view returns (BundleManager) {
452
+ return _bundleManager;
453
+ }
442
454
  }
@@ -79,9 +79,9 @@ contract InstanceAccessManager is
79
79
  AccessManagerSimple internal _accessManager;
80
80
 
81
81
  constructor(address accessManager)
82
- AccessManagedSimple(accessManager)
83
82
  {
84
83
  _accessManager = AccessManagerSimple(accessManager);
84
+ initializeAccessManagedSimple(accessManager);
85
85
 
86
86
  _createRole(RoleIdLib.toRoleId(_accessManager.ADMIN_ROLE()), ADMIN_ROLE_NAME, false, false);
87
87
  _createRole(RoleIdLib.toRoleId(_accessManager.PUBLIC_ROLE()), PUBLIC_ROLE_NAME, false, false);
@@ -7,14 +7,16 @@ import {DistributorType} from "../types/DistributorType.sol";
7
7
  import {Fee, FeeLib} from "../types/Fee.sol";
8
8
  import {Key32} from "../types/Key32.sol";
9
9
  import {NftId} from "../types/NftId.sol";
10
- import {ObjectType, DISTRIBUTOR, DISTRIBUTION, INSTANCE, PRODUCT, POLICY, POOL, TREASURY} from "../types/ObjectType.sol";
10
+ import {ObjectType, DISTRIBUTOR, DISTRIBUTION, INSTANCE, PRODUCT, POLICY, POOL, TREASURY, BUNDLE} from "../types/ObjectType.sol";
11
11
  import {ReferralId, ReferralStatus, ReferralLib, REFERRAL_OK, REFERRAL_ERROR_UNKNOWN, REFERRAL_ERROR_EXPIRED, REFERRAL_ERROR_EXHAUSTED} from "../types/Referral.sol";
12
12
  import {Registerable} from "../shared/Registerable.sol";
13
13
  import {RiskId} from "../types/RiskId.sol";
14
14
  import {UFixed, MathLib, UFixedLib} from "../types/UFixed.sol";
15
15
  import {Version} from "../types/Version.sol";
16
+ import {StateId} from "../types/StateId.sol";
16
17
 
17
18
  import {IRegistry} from "../registry/IRegistry.sol";
19
+ import {IBundle} from "../instance/module/IBundle.sol";
18
20
  import {IDistribution} from "../instance/module/IDistribution.sol";
19
21
  import {IInstance} from "./IInstance.sol";
20
22
  import {IKeyValueStore} from "../instance/base/IKeyValueStore.sol";
@@ -80,6 +82,14 @@ contract InstanceReader {
80
82
  }
81
83
  }
82
84
 
85
+ function getPolicyState(NftId policyNftId)
86
+ public
87
+ view
88
+ returns (StateId state)
89
+ {
90
+ return _instance.getState(toPolicyKey(policyNftId));
91
+ }
92
+
83
93
  function getRiskInfo(RiskId riskId)
84
94
  public
85
95
  view
@@ -114,6 +124,17 @@ contract InstanceReader {
114
124
  return abi.decode(data, (ITreasury.TreasuryInfo));
115
125
  }
116
126
  }
127
+
128
+ function getBundleInfo(NftId bundleNftId)
129
+ public
130
+ view
131
+ returns (IBundle.BundleInfo memory info)
132
+ {
133
+ bytes memory data = _store.getData(toBundleKey(bundleNftId));
134
+ if (data.length > 0) {
135
+ return abi.decode(data, (IBundle.BundleInfo));
136
+ }
137
+ }
117
138
 
118
139
  function getDistributorTypeInfo(DistributorType distributorType)
119
140
  public
@@ -259,6 +280,10 @@ contract InstanceReader {
259
280
  return distributionNftId.toKey32(DISTRIBUTION());
260
281
  }
261
282
 
283
+ function toBundleKey(NftId poolNftId) public pure returns (Key32) {
284
+ return poolNftId.toKey32(BUNDLE());
285
+ }
286
+
262
287
  function toPoolKey(NftId poolNftId) public pure returns (Key32) {
263
288
  return poolNftId.toKey32(POOL());
264
289
  }
@@ -8,6 +8,7 @@ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
8
  import {Instance} from "./Instance.sol";
9
9
  import {IInstanceService} from "./IInstanceService.sol";
10
10
  import {InstanceReader} from "./InstanceReader.sol";
11
+ import {BundleManager} from "./BundleManager.sol";
11
12
  import {IRegistry} from "../registry/IRegistry.sol";
12
13
  import {Registry} from "../registry/Registry.sol";
13
14
  import {RegistryService} from "../registry/RegistryService.sol";
@@ -15,7 +16,9 @@ import {Service} from "../../contracts/shared/Service.sol";
15
16
  import {IService} from "../shared/IService.sol";
16
17
  import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
17
18
  import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
19
+ import {RoleId} from "../types/RoleId.sol";
18
20
  import {VersionLib} from "../types/Version.sol";
21
+ import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE, PRODUCT_SERVICE_ROLE} from "../types/RoleId.sol";
19
22
 
20
23
  contract InstanceService is Service, IInstanceService {
21
24
 
@@ -23,6 +26,7 @@ contract InstanceService is Service, IInstanceService {
23
26
  address internal _accessManagerMaster;
24
27
  address internal _instanceMaster;
25
28
  address internal _instanceReaderMaster;
29
+ address internal _instanceBundleManagerMaster;
26
30
 
27
31
  // TODO update to real hash when instance is stable
28
32
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
@@ -33,27 +37,101 @@ contract InstanceService is Service, IInstanceService {
33
37
  returns (
34
38
  AccessManagerSimple clonedAccessManager,
35
39
  Instance clonedInstance,
36
- NftId instanceNftId,
37
- InstanceReader clonedInstanceReader
40
+ NftId clonedInstanceNftId,
41
+ InstanceReader clonedInstanceReader,
42
+ BundleManager clonedBundleManager
38
43
  )
39
44
  {
45
+ address instanceOwner = msg.sender;
40
46
  Registry registry = Registry(_registryAddress);
41
47
  NftId registryNftId = registry.getNftId(_registryAddress);
42
48
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
43
49
  RegistryService registryService = RegistryService(registryServiceAddress);
44
50
 
51
+ // initially set the authority of the access managar to this (being the instance service).
52
+ // This will allow the instance service to bootstrap the authorizations of the instance
53
+ // and then transfer the ownership of the access manager to the instance owner once everything is setup
45
54
  clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
46
- clonedAccessManager.initialize(msg.sender);
55
+ clonedAccessManager.initialize(address(this));
47
56
 
48
57
  clonedInstance = Instance(Clones.clone(_instanceMaster));
49
58
  clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
50
59
  ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
51
- instanceNftId = info.nftId;
60
+ clonedInstanceNftId = info.nftId;
52
61
 
53
62
  clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
54
- clonedInstanceReader.initialize(_registryAddress, instanceNftId);
63
+ clonedInstanceReader.initialize(_registryAddress, clonedInstanceNftId);
64
+ clonedInstance.setInstanceReader(clonedInstanceReader);
55
65
 
56
- emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
66
+ clonedBundleManager = BundleManager(Clones.clone(_instanceBundleManagerMaster));
67
+ clonedBundleManager.initialize(address(clonedAccessManager), _registryAddress, clonedInstanceNftId);
68
+ clonedInstance.setBundleManager(clonedBundleManager);
69
+
70
+ // TODO amend setters with instance specific , policy manager ...
71
+
72
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
73
+
74
+ // to complete setup switch instance ownership to the instance owner
75
+ // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
76
+ clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
77
+ clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
78
+
79
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
80
+ }
81
+
82
+ function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
83
+ // configure authorization for distribution service on instance
84
+ address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
85
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
86
+ bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
87
+ instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
88
+ instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
89
+ clonedAccessManager.setTargetFunctionRole(
90
+ address(clonedInstance),
91
+ instanceDistributionServiceSelectors,
92
+ DISTRIBUTION_SERVICE_ROLE().toInt());
93
+
94
+ // configure authorization for pool service on instance
95
+ address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
96
+ clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
97
+ bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
98
+ instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
99
+ instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
100
+ instancePoolServiceSelectors[2] = clonedInstance.createBundle.selector;
101
+ instancePoolServiceSelectors[3] = clonedInstance.updateBundle.selector;
102
+ clonedAccessManager.setTargetFunctionRole(
103
+ address(clonedInstance),
104
+ instancePoolServiceSelectors,
105
+ POOL_SERVICE_ROLE().toInt());
106
+
107
+ // configure authorization for pool service on bundle manager
108
+ bytes4[] memory bundleManagerPoolServiceSelectors = new bytes4[](5);
109
+ bundleManagerPoolServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
110
+ bundleManagerPoolServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
111
+ bundleManagerPoolServiceSelectors[2] = clonedBundleManager.add.selector;
112
+ bundleManagerPoolServiceSelectors[3] = clonedBundleManager.lock.selector;
113
+ bundleManagerPoolServiceSelectors[4] = clonedBundleManager.unlock.selector;
114
+ clonedAccessManager.setTargetFunctionRole(
115
+ address(clonedBundleManager),
116
+ bundleManagerPoolServiceSelectors,
117
+ POOL_SERVICE_ROLE().toInt());
118
+
119
+ // configure authorization for product service on instance
120
+ address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
121
+ clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE().toInt(), address(productServiceAddress), 0);
122
+ bytes4[] memory instanceProductServiceSelectors = new bytes4[](9);
123
+ instanceProductServiceSelectors[0] = clonedInstance.createProductSetup.selector;
124
+ instanceProductServiceSelectors[1] = clonedInstance.updateProductSetup.selector;
125
+ instanceProductServiceSelectors[2] = clonedInstance.createRisk.selector;
126
+ instanceProductServiceSelectors[3] = clonedInstance.updateRisk.selector;
127
+ instanceProductServiceSelectors[4] = clonedInstance.updateRiskState.selector;
128
+ instanceProductServiceSelectors[5] = clonedInstance.createPolicy.selector;
129
+ instanceProductServiceSelectors[6] = clonedInstance.updatePolicy.selector;
130
+ instanceProductServiceSelectors[7] = clonedInstance.updatePolicyState.selector;
131
+ clonedAccessManager.setTargetFunctionRole(
132
+ address(clonedInstance),
133
+ instanceProductServiceSelectors,
134
+ PRODUCT_SERVICE_ROLE().toInt());
57
135
  }
58
136
 
59
137
  function setAccessManagerMaster(address accessManagerMaster) external {
@@ -77,6 +155,13 @@ contract InstanceService is Service, IInstanceService {
77
155
  _instanceReaderMaster = instanceReaderMaster;
78
156
  }
79
157
 
158
+ function setBundleManagerMaster(address bundleManagerMaster) external {
159
+ require(
160
+ _instanceBundleManagerMaster == address(0),
161
+ "ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
162
+ _instanceBundleManagerMaster = bundleManagerMaster;
163
+ }
164
+
80
165
  function getInstanceReaderMaster() external view returns (address) {
81
166
  return _instanceReaderMaster;
82
167
  }
@@ -89,6 +174,10 @@ contract InstanceService is Service, IInstanceService {
89
174
  return _accessManagerMaster;
90
175
  }
91
176
 
177
+ function getBundleManagerMaster() external view returns (address) {
178
+ return _instanceBundleManagerMaster;
179
+ }
180
+
92
181
  // From IService
93
182
  function getName() public pure override(IService, Service) returns(string memory) {
94
183
  return NAME;
@@ -120,19 +209,24 @@ contract InstanceService is Service, IInstanceService {
120
209
 
121
210
  address initialOwner = address(0);
122
211
  (_registryAddress, initialOwner) = abi.decode(data, (address, address));
123
-
124
- // // TODO register instance in registry
125
- IRegistry registry = IRegistry(_registryAddress);
126
- NftId registryNftId = registry.getNftId(_registryAddress);
127
-
128
- _initializeService(_registryAddress, initialOwner);
212
+ // TODO while InstanceService is not deployed in InstanceServiceManager constructor
213
+ // owner is InstanceServiceManager deployer
214
+ _initializeService(_registryAddress, owner);
129
215
 
130
216
  _registerInterface(type(IService).interfaceId);
131
217
  _registerInterface(type(IInstanceService).interfaceId);
132
218
  }
133
219
 
134
- function getInstance() external view returns (Instance) {
135
- return Instance(address(this));
220
+ function hasRole(address account, RoleId role, NftId instanceNftId) external view returns (bool) {
221
+ IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
222
+ address instanceAddress = instanceObjectInfo.objectAddress;
223
+ Instance instance = Instance(instanceAddress);
224
+ AccessManagerSimple accessManager = AccessManagerSimple(instance.authority());
225
+ (bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
226
+ if (executionDelay > 0) {
227
+ return false;
228
+ }
229
+ return isMember;
136
230
  }
137
231
  }
138
232
 
@@ -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;