@etherisc/gif-next 0.0.2-cff6256-424 → 0.0.2-d02cb80-460

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. package/README.md +63 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +142 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +164 -62
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +104 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +0 -52
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +28 -2
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +193 -16
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +166 -58
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  37. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  38. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  40. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +788 -0
  41. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  42. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  43. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  44. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1373 -93
  46. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  47. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
  48. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  49. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +108 -1
  50. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  51. package/artifacts/contracts/instance/Instance.sol/Instance.json +160 -641
  52. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +291 -143
  54. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  55. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
  56. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  57. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +177 -38
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +333 -67
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +91 -23
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  63. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +285 -0
  64. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +40 -0
  66. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  70. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +54 -22
  73. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  78. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +923 -0
  81. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  82. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +440 -0
  83. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +16 -16
  85. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +69 -26
  87. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +18 -18
  89. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  90. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +669 -0
  91. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  94. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +664 -0
  95. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +9 -71
  97. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +17 -232
  99. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +984 -0
  101. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +464 -0
  103. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  104. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +718 -0
  105. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +428 -0
  107. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  108. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +768 -0
  109. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  110. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +420 -0
  111. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  112. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +2 -110
  114. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  115. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -0
  116. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  117. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  118. package/artifacts/contracts/registry/Registry.sol/Registry.json +35 -146
  119. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  120. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +76 -20
  121. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  122. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +26 -34
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  124. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +12 -12
  125. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  126. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  127. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  137. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  138. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  139. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  140. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  141. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  143. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  145. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  147. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestService.sol/TestService.json +9 -9
  149. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  152. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  153. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  154. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  159. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  162. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  168. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  174. package/contracts/components/BaseComponent.sol +62 -8
  175. package/contracts/components/Distribution.sol +12 -15
  176. package/contracts/components/IBaseComponent.sol +7 -0
  177. package/contracts/components/IDistributionComponent.sol +0 -2
  178. package/contracts/components/IPoolComponent.sol +5 -1
  179. package/contracts/components/Pool.sol +42 -29
  180. package/contracts/components/Product.sol +41 -46
  181. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  182. package/contracts/instance/BundleManager.sol +129 -0
  183. package/contracts/instance/Cloneable.sol +46 -0
  184. package/contracts/instance/IInstance.sol +34 -7
  185. package/contracts/instance/IInstanceBase.sol +26 -0
  186. package/contracts/instance/IInstanceService.sol +15 -3
  187. package/contracts/instance/Instance.sol +57 -224
  188. package/contracts/instance/InstanceAccessManager.sol +95 -78
  189. package/contracts/instance/InstanceBase.sol +41 -0
  190. package/contracts/instance/InstanceReader.sol +26 -1
  191. package/contracts/instance/InstanceService.sol +222 -69
  192. package/contracts/instance/InstanceServiceManager.sol +6 -5
  193. package/contracts/instance/ObjectManager.sol +101 -0
  194. package/contracts/instance/base/ComponentServiceBase.sol +45 -12
  195. package/contracts/instance/module/IAccess.sol +27 -17
  196. package/contracts/instance/module/IBundle.sol +1 -0
  197. package/contracts/instance/module/ISetup.sol +3 -0
  198. package/contracts/instance/service/BundleService.sol +260 -0
  199. package/contracts/instance/service/BundleServiceManager.sol +54 -0
  200. package/contracts/instance/service/DistributionService.sol +43 -21
  201. package/contracts/instance/service/DistributionServiceManager.sol +6 -5
  202. package/contracts/instance/service/IBundleService.sol +45 -0
  203. package/contracts/instance/service/IPolicyService.sol +87 -0
  204. package/contracts/instance/service/IPoolService.sol +6 -23
  205. package/contracts/instance/service/IProductService.sol +6 -73
  206. package/contracts/instance/service/PolicyService.sol +508 -0
  207. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  208. package/contracts/instance/service/PoolService.sol +124 -0
  209. package/contracts/instance/service/PoolServiceManager.sol +54 -0
  210. package/contracts/instance/service/ProductService.sol +173 -0
  211. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  212. package/contracts/registry/IRegistry.sol +5 -18
  213. package/contracts/registry/IRegistryService.sol +28 -11
  214. package/contracts/registry/Registry.sol +4 -45
  215. package/contracts/registry/RegistryService.sol +30 -71
  216. package/contracts/shared/NftOwnable.sol +2 -4
  217. package/contracts/shared/Service.sol +1 -0
  218. package/contracts/types/NftIdSet.sol +26 -24
  219. package/contracts/types/RoleId.sol +7 -2
  220. package/package.json +1 -1
  221. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  222. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  223. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  224. package/contracts/instance/AccessManagedSimple.sol +0 -115
  225. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -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,58 @@ 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 {IPolicyService} from "./service/IPolicyService.sol";
14
+ import {IBundleService} from "./service/IBundleService.sol";
15
+ import {IBundle} from "./module/IBundle.sol";
12
16
  import {ISetup} from "./module/ISetup.sol";
13
17
  import {NftId} from "../types/NftId.sol";
14
18
  import {StateId} from "../types/StateId.sol";
19
+ import {RiskId} from "../types/RiskId.sol";
20
+ import {IRisk} from "./module/IRisk.sol";
21
+ import {IPolicy} from "./module/IPolicy.sol";
22
+ import {IKeyValueStore} from "./base/IKeyValueStore.sol";
15
23
 
16
- interface IInstance is IERC165 {
24
+
25
+ interface IInstance is IERC165, IKeyValueStore {
17
26
 
18
27
  function getComponentOwnerService() external view returns (IComponentOwnerService);
19
- // TODO: renable these when we have the services
20
28
  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;
29
+ function getProductService() external view returns (IProductService);
30
+ function getPoolService() external view returns (IPoolService);
31
+ function getPolicyService() external view returns (IPolicyService);
32
+ function getBundleService() external view returns (IBundleService);
25
33
 
26
34
  function createDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup) external;
27
35
  function updateDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup, StateId newState) external;
28
36
  function updateDistributionSetupState(NftId distributionNftId, StateId newState) external;
29
37
 
30
- function createPoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup) external;
38
+ function createPoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup) external;
39
+ function updatePoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external;
40
+ function updatePoolSetupState(NftId poolNftId, StateId newState) external;
41
+
42
+ function createBundle(NftId bundleNftId, IBundle.BundleInfo memory bundle) external;
43
+ function updateBundle(NftId bundleNftId, IBundle.BundleInfo memory bundle, StateId newState) external;
44
+ function updateBundleState(NftId bundleNftId, StateId newState) external;
45
+
46
+ function createProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup) external;
47
+ function updateProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup, StateId newState) external;
48
+ function updateProductSetupState(NftId productNftId, StateId newState) external;
49
+
50
+ function createRisk(RiskId riskId, IRisk.RiskInfo memory risk) external;
51
+ function updateRisk(RiskId riskId, IRisk.RiskInfo memory risk, StateId newState) external;
52
+ function updateRiskState(RiskId riskId, StateId newState) external;
53
+
54
+ function createPolicy(NftId policyNftId, IPolicy.PolicyInfo memory policy) external;
55
+ function updatePolicy(NftId policyNftId, IPolicy.PolicyInfo memory policy, StateId newState) external;
56
+ function updatePolicyState(NftId policyNftId, StateId newState) external;
31
57
 
32
58
  function getInstanceReader() external view returns (InstanceReader);
59
+ function getBundleManager() external view returns (BundleManager);
33
60
  }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
+
6
+ import {BundleManager} from "./BundleManager.sol";
7
+ import {InstanceReader} from "./InstanceReader.sol";
8
+
9
+ import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
10
+ import {IDistributionService} from "./service/IDistributionService.sol";
11
+ import {IPoolService} from "./service/IPoolService.sol";
12
+ import {IProductService} from "./service/IProductService.sol";
13
+ import {IBundle} from "./module/IBundle.sol";
14
+ import {ISetup} from "./module/ISetup.sol";
15
+ import {NftId} from "../types/NftId.sol";
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";
21
+
22
+
23
+ interface IInstanceBase is IERC165, IKeyValueStore {
24
+
25
+
26
+ }
@@ -10,21 +10,33 @@ import {IRegistry} from "../registry/IRegistry.sol";
10
10
  import {IRegisterable} from "../shared/IRegisterable.sol";
11
11
  import {IBaseComponent} from "../components/IBaseComponent.sol";
12
12
 
13
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
13
+ import {InstanceAccessManager} from "./InstanceAccessManager.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
 
20
+ error ErrorInstanceServiceRequestUnauhorized(address caller);
21
+ error ErrorInstanceServiceNotInstanceOwner(address caller, NftId instanceNftId);
22
+
19
23
  event LogInstanceCloned(address clonedAccessManagerAddress, address clonedInstanceAddress, address clonedInstanceReaderAddress, NftId clonedInstanceNftId);
20
24
 
21
25
  function createInstanceClone()
22
26
  external
23
27
  returns (
24
- AccessManagerSimple clonedAccessManager,
28
+ InstanceAccessManager clonedAccessManager,
25
29
  Instance clonedInstance,
26
30
  NftId instanceNftId,
27
- InstanceReader clonedInstanceReader
31
+ InstanceReader clonedInstanceReader,
32
+ BundleManager clonedBundleManager
28
33
  );
34
+
35
+ function createRole(RoleId role, string memory name, NftId instanceNftId) external;
36
+
37
+ function grantRole(RoleId role, address member, NftId instanceNftId) external;
38
+
39
+ function hasRole(address account, RoleId role, address instanceAddress) external returns (bool);
40
+
29
41
  }
30
42
 
@@ -3,9 +3,9 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
5
5
  import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
+ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
7
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
6
8
 
7
- import {AccessManagedSimple} from "./AccessManagedSimple.sol";
8
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
9
9
  import {IAccess} from "./module/IAccess.sol";
10
10
  import {IBundle} from "./module/IBundle.sol";
11
11
  import {IPolicy} from "./module/IPolicy.sol";
@@ -15,25 +15,32 @@ 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 {InstanceAccessManager} from "./InstanceAccessManager.sol";
19
+ import {BundleManager} from "./BundleManager.sol";
18
20
  import {NftId} from "../types/NftId.sol";
19
21
  import {NumberId} from "../types/NumberId.sol";
20
22
  import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
21
23
  import {RiskId, RiskIdLib} from "../types/RiskId.sol";
22
24
  import {RoleId, RoleIdLib} from "../types/RoleId.sol";
23
25
  import {StateId, ACTIVE} from "../types/StateId.sol";
26
+ import {TimestampLib} from "../types/Timestamp.sol";
24
27
  import {ERC165} from "../shared/ERC165.sol";
25
28
  import {Registerable} from "../shared/Registerable.sol";
26
29
  import {ComponentOwnerService} from "./service/ComponentOwnerService.sol";
27
30
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
28
31
  import {IDistributionService} from "./service/IDistributionService.sol";
32
+ import {IPoolService} from "./service/IPoolService.sol";
33
+ import {IProductService} from "./service/IProductService.sol";
34
+ import {IPolicyService} from "./service/IPolicyService.sol";
35
+ import {IBundleService} from "./service/IBundleService.sol";
29
36
  import {VersionPart} from "../types/Version.sol";
37
+ import {InstanceBase} from "./InstanceBase.sol";
30
38
 
31
39
  contract Instance is
32
- AccessManagedSimple,
33
- KeyValueStore,
40
+ AccessManagedUpgradeable,
34
41
  IInstance,
35
- ERC165,
36
- Registerable
42
+ // Initializable,
43
+ InstanceBase
37
44
  {
38
45
 
39
46
  uint64 public constant ADMIN_ROLE = type(uint64).min;
@@ -44,155 +51,26 @@ contract Instance is
44
51
 
45
52
  bool private _initialized;
46
53
 
47
- mapping(ShortString name => RoleId roleId) internal _role;
48
- mapping(RoleId roleId => EnumerableSet.AddressSet roleMembers) internal _roleMembers;
49
- RoleId [] internal _roles;
50
-
51
- mapping(ShortString name => address target) internal _target;
52
-
53
- AccessManagerSimple internal _accessManager;
54
+ InstanceAccessManager internal _accessManager;
54
55
  InstanceReader internal _instanceReader;
56
+ BundleManager internal _bundleManager;
55
57
 
56
- constructor(address accessManagerAddress, address registryAddress, NftId registryNftId)
58
+ function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner)
59
+ public
60
+ initializer
57
61
  {
58
- initialize(accessManagerAddress, registryAddress, registryNftId, msg.sender);
59
- }
60
-
61
- function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner) public {
62
62
  require(!_initialized, "Contract instance has already been initialized");
63
63
 
64
- initializeAccessManagedSimple(accessManagerAddress);
65
-
66
- _accessManager = AccessManagerSimple(accessManagerAddress);
67
- _createRole(RoleIdLib.toRoleId(ADMIN_ROLE), "AdminRole", false, false);
68
- _createRole(RoleIdLib.toRoleId(PUBLIC_ROLE), "PublicRole", false, false);
69
-
64
+ __AccessManaged_init(accessManagerAddress);
65
+
66
+ _accessManager = InstanceAccessManager(accessManagerAddress);
67
+
70
68
  _initializeRegisterable(registryAddress, registryNftId, INSTANCE(), false, initialOwner, "");
71
69
 
72
70
  _registerInterface(type(IInstance).interfaceId);
73
71
  _initialized = true;
74
72
  }
75
73
 
76
- //--- Role ------------------------------------------------------//
77
- function createStandardRole(RoleId roleId, string memory name) external restricted() {
78
- _createRole(roleId, name, false, true);
79
- }
80
-
81
- function createCustomRole(RoleId roleId, string memory name) external restricted() {
82
- _createRole(roleId, name, true, true);
83
- }
84
-
85
- function updateRole(RoleId roleId, string memory name, StateId newState) external restricted() {
86
- (bool isCustom,) = _validateRoleParameters(roleId, name, false);
87
- IAccess.RoleInfo memory role = _toRole(roleId, name, isCustom);
88
- update(toRoleKey32(roleId), abi.encode(role), newState);
89
- }
90
-
91
- function updateRoleState(RoleId roleId, StateId newState) external restricted() {
92
- updateState(toRoleKey32(roleId), newState);
93
- }
94
-
95
- function grantRole(RoleId roleId, address member) external restricted() returns (bool granted) {
96
- Key32 roleKey = toRoleKey32(roleId);
97
-
98
- if (!exists(roleKey)) {
99
- revert IAccess.ErrorGrantNonexstentRole(roleId);
100
- }
101
-
102
- if (getState(roleKey) != ACTIVE()) {
103
- revert IAccess.ErrorRoleIdNotActive(roleId);
104
- }
105
-
106
- if (!EnumerableSet.contains(_roleMembers[roleId], member)) {
107
- _accessManager.grantRole(roleId.toInt(), member, EXECUTION_DELAY);
108
- EnumerableSet.add(_roleMembers[roleId], member);
109
- return true;
110
- }
111
-
112
- return false;
113
- }
114
-
115
- function revokeRole(RoleId roleId, address member) external restricted() returns (bool revoked) {
116
- Key32 roleKey = toRoleKey32(roleId);
117
-
118
- if (!exists(roleKey)) {
119
- revert IAccess.ErrorRevokeNonexstentRole(roleId);
120
- }
121
-
122
- if (EnumerableSet.contains(_roleMembers[roleId], member)) {
123
- _accessManager.revokeRole(roleId.toInt(), member);
124
- EnumerableSet.remove(_roleMembers[roleId], member);
125
- return true;
126
- }
127
-
128
- return false;
129
- }
130
-
131
- /// @dev not restricted function by intention
132
- /// the restriction to role members is already enforced by the call to the access manger
133
- function renounceRole(RoleId roleId) external returns (bool revoked) {
134
- address member = msg.sender;
135
- Key32 roleKey = toRoleKey32(roleId);
136
-
137
- if (!exists(roleKey)) {
138
- revert IAccess.ErrorRenounceNonexstentRole(roleId);
139
- }
140
-
141
- if (EnumerableSet.contains(_roleMembers[roleId], member)) {
142
- _accessManager.renounceRole(roleId.toInt(), member);
143
- EnumerableSet.remove(_roleMembers[roleId], member);
144
- return true;
145
- }
146
-
147
- return false;
148
- }
149
-
150
- function roles() external view returns (uint256 numberOfRoles) {
151
- return _roles.length;
152
- }
153
-
154
- function getRoleId(uint256 idx) external view returns (RoleId roleId) {
155
- return _roles[idx];
156
- }
157
-
158
- function getRole(RoleId roleId) external view returns (IAccess.RoleInfo memory role) {
159
- return abi.decode(getData(roleId.toKey32()), (IAccess.RoleInfo));
160
- }
161
-
162
- function roleMembers(RoleId roleId) external view returns (uint256 numberOfMembers) {
163
- return EnumerableSet.length(_roleMembers[roleId]);
164
- }
165
-
166
- function getRoleMember(RoleId roleId, uint256 idx) external view returns (address roleMember) {
167
- return EnumerableSet.at(_roleMembers[roleId], idx);
168
- }
169
-
170
- function _createRole(RoleId roleId, string memory name, bool isCustom, bool validateParameters) internal {
171
- if (validateParameters) {
172
- _validateRoleParameters(roleId, name, isCustom);
173
- }
174
-
175
- IAccess.RoleInfo memory role = _toRole(roleId, name, isCustom);
176
- _role[role.name] = roleId;
177
- _roles.push(roleId);
178
-
179
- create(toRoleKey32(roleId), abi.encode(role));
180
- }
181
-
182
- //--- Target ------------------------------------------------------//
183
- function createTarget(address target, IAccess.TargetInfo memory targetInfo) external restricted() {
184
- _validateTargetParameters(target, targetInfo);
185
- create(toTargetKey32(target), abi.encode(targetInfo));
186
- }
187
-
188
- function setTargetClosed(address target, bool closed) external restricted() {
189
- if (!exists(toTargetKey32(target))) {
190
- revert IAccess.ErrorTargetDoesNotExist(target);
191
- }
192
-
193
- _accessManager.setTargetClosed(target, closed);
194
- }
195
-
196
74
  //--- ProductSetup ------------------------------------------------------//
197
75
  function createProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup) external restricted() {
198
76
  create(_toNftKey32(productNftId, PRODUCT()), abi.encode(setup));
@@ -220,16 +98,16 @@ contract Instance is
220
98
  }
221
99
 
222
100
  //--- PoolSetup ------------------------------------------------------//
223
- function createPoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup) external restricted() {
224
- create(_toNftKey32(distributionNftId, POOL()), abi.encode(setup));
101
+ function createPoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup) external restricted() {
102
+ create(_toNftKey32(poolNftId, POOL()), abi.encode(setup));
225
103
  }
226
104
 
227
- function updatePoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external restricted() {
228
- update(_toNftKey32(distributionNftId, POOL()), abi.encode(setup), newState);
105
+ function updatePoolSetup(NftId poolNftId, ISetup.PoolSetupInfo memory setup, StateId newState) external restricted() {
106
+ update(_toNftKey32(poolNftId, POOL()), abi.encode(setup), newState);
229
107
  }
230
108
 
231
- function updatePoolSetupState(NftId distributionNftId, StateId newState) external restricted() {
232
- updateState(_toNftKey32(distributionNftId, POOL()), newState);
109
+ function updatePoolSetupState(NftId poolNftId, StateId newState) external restricted() {
110
+ updateState(_toNftKey32(poolNftId, POOL()), newState);
233
111
  }
234
112
 
235
113
  //--- DistributorType ---------------------------------------------------//
@@ -337,71 +215,6 @@ contract Instance is
337
215
  }
338
216
 
339
217
  //--- internal view/pure functions --------------------------------------//
340
- function _toRole(RoleId roleId, string memory name, bool isCustom)
341
- internal
342
- pure
343
- returns (IAccess.RoleInfo memory role)
344
- {
345
- return IAccess.RoleInfo(
346
- ShortStrings.toShortString(name),
347
- isCustom);
348
- }
349
-
350
- function _validateRoleParameters(
351
- RoleId roleId,
352
- string memory name,
353
- bool isCustom
354
- )
355
- internal
356
- view
357
- returns (
358
- bool roleExists,
359
- bool roleIsCustom
360
- )
361
- {
362
- Key32 roleKey = toRoleKey32(roleId);
363
- roleExists = exists(roleKey);
364
- if (roleExists) {
365
- roleIsCustom = abi.decode(getData(roleKey), (IAccess.RoleInfo)).isCustom;
366
- } else {
367
- roleIsCustom = isCustom;
368
- }
369
-
370
- // check role id
371
- uint64 roleIdInt = RoleId.unwrap(roleId);
372
- if(roleIdInt == ADMIN_ROLE || roleIdInt == PUBLIC_ROLE) {
373
- revert IAccess.ErrorRoleIdInvalid(roleId);
374
- }
375
-
376
- if (roleIsCustom && roleIdInt < CUSTOM_ROLE_ID_MIN) {
377
- revert IAccess.ErrorRoleIdTooSmall(roleId);
378
- } else if (roleIsCustom && roleIdInt >= CUSTOM_ROLE_ID_MIN) {
379
- revert IAccess.ErrorRoleIdTooBig(roleId);
380
- }
381
-
382
- // role name checks
383
- ShortString nameShort = ShortStrings.toShortString(name);
384
- if (ShortStrings.byteLength(nameShort) == 0) {
385
- revert IAccess.ErrorRoleNameEmpty(roleId);
386
- }
387
-
388
- if (_role[nameShort] != RoleIdLib.zero() && _role[nameShort] != roleId) {
389
- revert IAccess.ErrorRoleNameNotUnique(_role[nameShort], nameShort);
390
- }
391
- }
392
-
393
- function _validateTargetParameters(address target, IAccess.TargetInfo memory targetInfo) internal view {
394
-
395
- }
396
-
397
- function toRoleKey32(RoleId roleId) public pure returns (Key32) {
398
- return roleId.toKey32();
399
- }
400
-
401
- function toTargetKey32(address target) public pure returns (Key32) {
402
- return Key32Lib.toKey32(TARGET(), KeyId.wrap(bytes20(target)));
403
- }
404
-
405
218
  function _toNftKey32(NftId nftId, ObjectType objectType) internal pure returns (Key32) {
406
219
  return nftId.toKey32(objectType);
407
220
  }
@@ -422,22 +235,42 @@ contract Instance is
422
235
  return IDistributionService(_registry.getServiceAddress("DistributionService", VersionPart.wrap(3)));
423
236
  }
424
237
 
425
- // TODO reactivate when services are available
426
- // function getProductService() external view returns (IProductService) {
427
- // return ProductService(_registry.getServiceAddress("ProductService", VersionPart.wrap(3)));
428
- // }
238
+ function getProductService() external view returns (IProductService) {
239
+ return IProductService(_registry.getServiceAddress("ProductService", VersionPart.wrap(3)));
240
+ }
241
+
242
+ function getPoolService() external view returns (IPoolService) {
243
+ return IPoolService(_registry.getServiceAddress("PoolService", VersionPart.wrap(3)));
244
+ }
429
245
 
430
- // TODO reactivate when services are available
431
- // function getPoolService() external view returns (IPoolService) {
432
- // return PoolService(_registry.getServiceAddress("PoolService", VersionPart.wrap(3)));
433
- // }
246
+ function getPolicyService() external view returns (IPolicyService) {
247
+ return IPolicyService(_registry.getServiceAddress("PolicyService", VersionPart.wrap(3)));
248
+ }
249
+
250
+ function getBundleService() external view returns (IBundleService) {
251
+ return IBundleService(_registry.getServiceAddress("BundleService", VersionPart.wrap(3)));
252
+ }
253
+
254
+ function getInstanceAccessManager() external view returns (InstanceAccessManager) {
255
+ return _accessManager;
256
+ }
434
257
 
435
258
  function setInstanceReader(InstanceReader instanceReader) external restricted() {
436
- require(address(_instanceReader) == address(0), "InstanceReader is set");
259
+ require(instanceReader.getInstanceNftId() == getNftId(), "NFT ID of InstanceReader does not match");
437
260
  _instanceReader = instanceReader;
438
261
  }
439
262
 
440
263
  function getInstanceReader() external view returns (InstanceReader) {
441
264
  return _instanceReader;
442
265
  }
266
+
267
+ function setBundleManager(BundleManager bundleManager) external restricted() {
268
+ require(address(_bundleManager) == address(0), "BundleManager is set");
269
+ require(bundleManager.getInstanceNftId() == getNftId(), "NFT ID of BundleManager does not match");
270
+ _bundleManager = bundleManager;
271
+ }
272
+
273
+ function getBundleManager() external view returns (BundleManager) {
274
+ return _bundleManager;
275
+ }
443
276
  }