@etherisc/gif-next 0.0.2-f2b0fa2-473 → 0.0.2-f5a74cc-201

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) 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/Dummy.sol/LifeCycleModule.json +2 -2
  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/SM.sol/SM.json +2 -2
  35. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  37. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  39. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  40. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  41. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  42. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +775 -0
  43. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  44. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  45. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  46. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  47. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1369 -22
  48. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  49. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
  50. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  51. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +64 -0
  52. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  53. package/artifacts/contracts/instance/Instance.sol/Instance.json +216 -132
  54. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  55. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +57 -34
  56. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  57. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
  58. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  59. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +202 -37
  60. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +321 -41
  62. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  63. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +101 -13
  64. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  65. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  66. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +59 -0
  68. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  70. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  72. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  73. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  74. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  75. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  78. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  79. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  80. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  81. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +18 -18
  84. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  85. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +716 -0
  86. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  87. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +444 -0
  88. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +167 -0
  92. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +40 -31
  94. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +4 -0
  95. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +1049 -0
  96. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +4 -0
  97. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +464 -0
  98. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  99. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +1147 -0
  100. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  101. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +488 -0
  102. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  103. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  104. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +201 -0
  105. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  106. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -19
  107. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  108. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/Registry.sol/Registry.json +172 -49
  110. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +61 -29
  112. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  113. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +47 -34
  114. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  115. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
  116. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  117. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  118. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  119. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  120. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  121. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  122. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  124. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  125. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  126. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  127. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  128. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +4 -4
  129. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  131. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  132. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  133. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  134. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  136. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  137. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  138. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  139. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  140. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  141. package/artifacts/contracts/test/TestService.sol/TestService.json +11 -11
  142. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  143. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  145. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  147. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  148. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  149. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  154. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  156. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  157. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  163. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  165. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  170. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
  172. package/contracts/components/BaseComponent.sol +57 -11
  173. package/contracts/components/Distribution.sol +15 -18
  174. package/contracts/components/IBaseComponent.sol +7 -0
  175. package/contracts/components/IDistributionComponent.sol +1 -0
  176. package/contracts/components/IPoolComponent.sol +5 -1
  177. package/contracts/components/Pool.sol +36 -28
  178. package/contracts/components/Product.sol +34 -42
  179. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  180. package/contracts/instance/BundleManager.sol +129 -0
  181. package/contracts/instance/Cloneable.sol +46 -0
  182. package/contracts/instance/IInstance.sol +35 -7
  183. package/contracts/instance/IInstanceBase.sol +26 -0
  184. package/contracts/instance/IInstanceService.sol +16 -1
  185. package/contracts/instance/Instance.sol +53 -34
  186. package/contracts/instance/InstanceAccessManager.sol +6 -6
  187. package/contracts/instance/InstanceBase.sol +41 -0
  188. package/contracts/instance/InstanceReader.sol +36 -1
  189. package/contracts/instance/InstanceService.sol +164 -27
  190. package/contracts/instance/InstanceServiceManager.sol +6 -5
  191. package/contracts/instance/ObjectManager.sol +95 -0
  192. package/contracts/instance/base/ComponentServiceBase.sol +91 -6
  193. package/contracts/instance/module/IBundle.sol +1 -0
  194. package/contracts/instance/module/ISetup.sol +3 -0
  195. package/contracts/instance/service/DistributionService.sol +88 -0
  196. package/contracts/instance/service/DistributionServiceManager.sol +54 -0
  197. package/contracts/instance/service/IPoolService.sol +16 -2
  198. package/contracts/instance/service/IProductService.sol +6 -3
  199. package/contracts/instance/service/PoolService.sol +287 -0
  200. package/contracts/instance/service/PoolServiceManager.sol +54 -0
  201. package/contracts/instance/service/ProductService.sol +570 -0
  202. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  203. package/contracts/registry/IRegistry.sol +26 -2
  204. package/contracts/registry/IRegistryService.sol +27 -12
  205. package/contracts/registry/Registry.sol +60 -35
  206. package/contracts/registry/RegistryService.sol +37 -118
  207. package/contracts/registry/RegistryServiceManager.sol +21 -5
  208. package/contracts/registry/TokenRegistry.sol +111 -0
  209. package/contracts/shared/ERC165.sol +6 -2
  210. package/contracts/shared/NftOwnable.sol +2 -4
  211. package/contracts/shared/Registerable.sol +1 -0
  212. package/contracts/shared/Service.sol +1 -0
  213. package/contracts/types/NftIdSet.sol +26 -24
  214. package/contracts/types/RoleId.sol +8 -0
  215. package/contracts/types/StateId.sol +4 -0
  216. package/contracts/types/Version.sol +4 -1
  217. package/package.json +1 -1
  218. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  219. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  220. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1119
  221. package/contracts/instance/AccessManagedSimple.sol +0 -114
  222. package/contracts/instance/AccessManagerSimple.sol +0 -682
@@ -2,23 +2,32 @@
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";
5
6
 
6
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
7
+ import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.sol";
7
8
  import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
9
  import {Instance} from "./Instance.sol";
9
10
  import {IInstanceService} from "./IInstanceService.sol";
10
- import {Service} from "../shared/Service.sol";
11
+ import {InstanceReader} from "./InstanceReader.sol";
12
+ import {BundleManager} from "./BundleManager.sol";
11
13
  import {IRegistry} from "../registry/IRegistry.sol";
14
+ import {Registry} from "../registry/Registry.sol";
15
+ import {RegistryService} from "../registry/RegistryService.sol";
16
+ import {Service} from "../../contracts/shared/Service.sol";
12
17
  import {IService} from "../shared/IService.sol";
13
18
  import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
14
- import {NftId, NftIdLib, zeroNftId} from "../types/NftId.sol";
19
+ import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
20
+ import {RoleId} from "../types/RoleId.sol";
21
+ import {VersionLib} from "../types/Version.sol";
22
+ import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE, POOL_SERVICE_ROLE, PRODUCT_SERVICE_ROLE} from "../types/RoleId.sol";
15
23
 
16
24
  contract InstanceService is Service, IInstanceService {
17
25
 
18
26
  address internal _registryAddress;
19
27
  address internal _accessManagerMaster;
20
- address internal _instanceAccessManagerMaster;
21
28
  address internal _instanceMaster;
29
+ address internal _instanceReaderMaster;
30
+ address internal _instanceBundleManagerMaster;
22
31
 
23
32
  // TODO update to real hash when instance is stable
24
33
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
@@ -27,31 +36,154 @@ contract InstanceService is Service, IInstanceService {
27
36
  function createInstanceClone()
28
37
  external
29
38
  returns (
30
- AccessManagerSimple am,
31
- InstanceAccessManager im,
32
- Instance i
39
+ AccessManagerUpgradeableInitializeable clonedAccessManager,
40
+ Instance clonedInstance,
41
+ NftId clonedInstanceNftId,
42
+ InstanceReader clonedInstanceReader,
43
+ BundleManager clonedBundleManager
33
44
  )
34
45
  {
35
- am = AccessManagerSimple(Clones.clone(_accessManagerMaster));
36
- im = InstanceAccessManager(Clones.clone(_instanceAccessManagerMaster));
37
- i = Instance(Clones.clone(_instanceMaster));
46
+ address instanceOwner = msg.sender;
47
+ Registry registry = Registry(_registryAddress);
48
+ NftId registryNftId = registry.getNftId(_registryAddress);
49
+ address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
50
+ RegistryService registryService = RegistryService(registryServiceAddress);
51
+
52
+ // initially set the authority of the access managar to this (being the instance service).
53
+ // This will allow the instance service to bootstrap the authorizations of the instance
54
+ // and then transfer the ownership of the access manager to the instance owner once everything is setup
55
+ clonedAccessManager = AccessManagerUpgradeableInitializeable(Clones.clone(_accessManagerMaster));
56
+ clonedAccessManager.__AccessManagerUpgradeableInitializeable_init(address(this));
57
+
58
+ clonedInstance = Instance(Clones.clone(_instanceMaster));
59
+ clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
60
+ ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
61
+ clonedInstanceNftId = info.nftId;
62
+
63
+ clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
64
+ clonedInstanceReader.initialize(_registryAddress, clonedInstanceNftId);
65
+ clonedInstance.setInstanceReader(clonedInstanceReader);
66
+
67
+ clonedBundleManager = BundleManager(Clones.clone(_instanceBundleManagerMaster));
68
+ clonedBundleManager.initialize(address(clonedAccessManager), _registryAddress, clonedInstanceNftId);
69
+ clonedInstance.setBundleManager(clonedBundleManager);
70
+
71
+ // TODO amend setters with instance specific , policy manager ...
72
+
73
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
74
+
75
+ // to complete setup switch instance ownership to the instance owner
76
+ // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
77
+ clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
78
+ clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
79
+
80
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
81
+ }
82
+
83
+ function _grantInitialAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
84
+ // configure authorization for distribution service on instance
85
+ address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
86
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
87
+ bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
88
+ instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
89
+ instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
90
+ clonedAccessManager.setTargetFunctionRole(
91
+ address(clonedInstance),
92
+ instanceDistributionServiceSelectors,
93
+ DISTRIBUTION_SERVICE_ROLE().toInt());
94
+
95
+ // configure authorization for pool service on instance
96
+ address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
97
+ clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
98
+ bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
99
+ instancePoolServiceSelectors[0] = clonedInstance.createPoolSetup.selector;
100
+ instancePoolServiceSelectors[1] = clonedInstance.updatePoolSetup.selector;
101
+ instancePoolServiceSelectors[2] = clonedInstance.createBundle.selector;
102
+ instancePoolServiceSelectors[3] = clonedInstance.updateBundle.selector;
103
+ clonedAccessManager.setTargetFunctionRole(
104
+ address(clonedInstance),
105
+ instancePoolServiceSelectors,
106
+ POOL_SERVICE_ROLE().toInt());
107
+
108
+ // configure authorization for pool service on bundle manager
109
+ bytes4[] memory bundleManagerPoolServiceSelectors = new bytes4[](5);
110
+ bundleManagerPoolServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
111
+ bundleManagerPoolServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
112
+ bundleManagerPoolServiceSelectors[2] = clonedBundleManager.add.selector;
113
+ bundleManagerPoolServiceSelectors[3] = clonedBundleManager.lock.selector;
114
+ bundleManagerPoolServiceSelectors[4] = clonedBundleManager.unlock.selector;
115
+ clonedAccessManager.setTargetFunctionRole(
116
+ address(clonedBundleManager),
117
+ bundleManagerPoolServiceSelectors,
118
+ POOL_SERVICE_ROLE().toInt());
119
+
120
+ // configure authorization for product service on instance
121
+ address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
122
+ clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE().toInt(), address(productServiceAddress), 0);
123
+ bytes4[] memory instanceProductServiceSelectors = new bytes4[](9);
124
+ instanceProductServiceSelectors[0] = clonedInstance.createProductSetup.selector;
125
+ instanceProductServiceSelectors[1] = clonedInstance.updateProductSetup.selector;
126
+ instanceProductServiceSelectors[2] = clonedInstance.createRisk.selector;
127
+ instanceProductServiceSelectors[3] = clonedInstance.updateRisk.selector;
128
+ instanceProductServiceSelectors[4] = clonedInstance.updateRiskState.selector;
129
+ instanceProductServiceSelectors[5] = clonedInstance.createPolicy.selector;
130
+ instanceProductServiceSelectors[6] = clonedInstance.updatePolicy.selector;
131
+ instanceProductServiceSelectors[7] = clonedInstance.updatePolicyState.selector;
132
+ clonedAccessManager.setTargetFunctionRole(
133
+ address(clonedInstance),
134
+ instanceProductServiceSelectors,
135
+ PRODUCT_SERVICE_ROLE().toInt());
136
+ }
137
+
138
+ function setAccessManagerMaster(address accessManagerMaster) external {
139
+ require(
140
+ _accessManagerMaster == address(0),
141
+ "ERROR:CRD-001:ACCESS_MANAGER_MASTER_ALREADY_SET");
142
+ _accessManagerMaster = accessManagerMaster;
38
143
  }
39
144
 
40
- function setAccessManagerMaster(address accessManager) external {
41
- _accessManagerMaster = accessManager;
145
+ function setInstanceMaster(address instanceMaster) external {
146
+ // TODO: ensure instance has correct access manager
147
+ require(
148
+ _instanceMaster == address(0),
149
+ "ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
150
+ _instanceMaster = instanceMaster;
42
151
  }
43
152
 
44
- function setInstanceAccessManagerMaster(address instanceAccessManager) external {
45
- _instanceAccessManagerMaster = instanceAccessManager;
153
+ function setInstanceReaderMaster(address instanceReaderMaster) external onlyOwner {
154
+ // TODO: ensure instance reader points to master instance
155
+ // TODO: add a test for this
156
+ _instanceReaderMaster = instanceReaderMaster;
46
157
  }
47
158
 
48
- function setInstanceMaster(address instance) external {
49
- _instanceMaster = instance;
159
+ function upgradeInstanceReader(NftId instanceNftId) external {
160
+ // TODO: ensure this is done by instance owner
161
+ // TODO: upgrade instance reader of this instance to latest (set above here)
50
162
  }
51
163
 
52
- function getAccessManagerMaster() external view returns (address) { return address(_accessManagerMaster); }
53
- function getInstanceAccessManagerMaster() external view returns (address) { return address(_instanceAccessManagerMaster); }
54
- function getInstanceMaster() external view returns (address) { return address(_instanceMaster); }
164
+ function setBundleManagerMaster(address bundleManagerMaster) external {
165
+ // TODO: ensure bundle manager points to master instance
166
+ require(
167
+ _instanceBundleManagerMaster == address(0),
168
+ "ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
169
+ _instanceBundleManagerMaster = bundleManagerMaster;
170
+ }
171
+
172
+ function getInstanceReaderMaster() external view returns (address) {
173
+ return _instanceReaderMaster;
174
+ }
175
+
176
+ function getInstanceMaster() external view returns (address) {
177
+ return _instanceMaster;
178
+ }
179
+
180
+ function getAccessManagerMaster() external view returns (address) {
181
+ return _accessManagerMaster;
182
+ }
183
+
184
+ function getBundleManagerMaster() external view returns (address) {
185
+ return _instanceBundleManagerMaster;
186
+ }
55
187
 
56
188
  // From IService
57
189
  function getName() public pure override(IService, Service) returns(string memory) {
@@ -84,19 +216,24 @@ contract InstanceService is Service, IInstanceService {
84
216
 
85
217
  address initialOwner = address(0);
86
218
  (_registryAddress, initialOwner) = abi.decode(data, (address, address));
87
-
88
- // // TODO register instance in registry
89
- IRegistry registry = IRegistry(_registryAddress);
90
- NftId registryNftId = registry.getNftId(_registryAddress);
91
-
92
- _initializeService(_registryAddress, initialOwner);
219
+ // TODO while InstanceService is not deployed in InstanceServiceManager constructor
220
+ // owner is InstanceServiceManager deployer
221
+ _initializeService(_registryAddress, owner);
93
222
 
94
223
  _registerInterface(type(IService).interfaceId);
95
224
  _registerInterface(type(IInstanceService).interfaceId);
96
225
  }
97
226
 
98
- function getInstance() external view returns (Instance) {
99
- return Instance(address(this));
227
+ function hasRole(address account, RoleId role, NftId instanceNftId) external view returns (bool) {
228
+ IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
229
+ address instanceAddress = instanceObjectInfo.objectAddress;
230
+ Instance instance = Instance(instanceAddress);
231
+ AccessManagerUpgradeable accessManager = AccessManagerUpgradeable(instance.authority());
232
+ (bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
233
+ if (executionDelay > 0) {
234
+ return false;
235
+ }
236
+ return isMember;
100
237
  }
101
238
  }
102
239
 
@@ -31,14 +31,15 @@ contract InstanceServiceManager is ProxyManager {
31
31
  Registry registry = Registry(registryAddress);
32
32
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
33
33
  RegistryService registryService = RegistryService(registryServiceAddress);
34
-
35
- registryService.registerService(_instanceService);
34
+ // TODO this must have a role or own nft to register service
35
+ //registryService.registerService(_instanceService);
36
36
  // RegistryService registryService = _instanceService.getRegistryService();
37
37
 
38
+ // TODO no nft to link yet
38
39
  // link ownership of instance service manager ot nft owner of instance service
39
- _linkToNftOwnable(
40
- address(registryAddress),
41
- address(_instanceService));
40
+ //_linkToNftOwnable(
41
+ // address(registryAddress),
42
+ // address(_instanceService));
42
43
 
43
44
  // implies that after this constructor call only upgrade functionality is available
44
45
  _isDeployed = true;
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {Cloneable} from "./Cloneable.sol";
5
+
6
+ import {IInstance} from "./IInstance.sol";
7
+ import {INSTANCE} from "../types/ObjectType.sol";
8
+ import {InstanceReader} from "./InstanceReader.sol";
9
+ import {IRegistry} from "../registry/IRegistry.sol";
10
+ import {LibNftIdSet} from "../types/NftIdSet.sol";
11
+ import {NftId} from "../types/NftId.sol";
12
+
13
+ contract ObjectManager is
14
+ Cloneable
15
+ {
16
+
17
+ event LogObjectManagerInitialized(NftId instanceNftId, address instanceReader);
18
+
19
+ error ErrorObjectManagerNftIdInvalid(NftId instanceNftId);
20
+ error ErrorObjectManagerAlreadyAdded(NftId componentNftId, NftId objectNftId);
21
+
22
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _activeObjects;
23
+ mapping(NftId compnentNftId => LibNftIdSet.Set objects) internal _allObjects;
24
+ InstanceReader internal _instanceReader;
25
+
26
+ constructor() Cloneable() {
27
+ _instanceReader = InstanceReader(address(0));
28
+ }
29
+
30
+ /// @dev call to initialize MUST be made in the same transaction as cloning of the contract
31
+ function initialize(
32
+ address authority,
33
+ address registry,
34
+ NftId instanceNftId
35
+ )
36
+ external
37
+ {
38
+ initialize(authority, registry);
39
+
40
+ // check/handle instance nft id/instance reader
41
+ IRegistry.ObjectInfo memory instanceInfo = _registry.getObjectInfo(instanceNftId);
42
+ if (instanceInfo.objectType != INSTANCE()) {
43
+ revert ErrorObjectManagerNftIdInvalid(instanceNftId);
44
+ }
45
+
46
+ IInstance instance = IInstance(instanceInfo.objectAddress);
47
+ _instanceReader = instance.getInstanceReader();
48
+
49
+ emit LogObjectManagerInitialized(instanceNftId, address(_instanceReader));
50
+ }
51
+
52
+ function getInstanceReader() external view returns (InstanceReader) {
53
+ return _instanceReader;
54
+ }
55
+
56
+ function _add(NftId componentNftId, NftId objectNftId) internal {
57
+ LibNftIdSet.Set storage allSet = _allObjects[componentNftId];
58
+ LibNftIdSet.Set storage activeSet = _activeObjects[componentNftId];
59
+
60
+ LibNftIdSet.add(allSet, objectNftId);
61
+ LibNftIdSet.add(activeSet, objectNftId);
62
+ }
63
+
64
+ function _activate(NftId componentNftId, NftId objectNftId) internal {
65
+ LibNftIdSet.add(_activeObjects[componentNftId], objectNftId);
66
+ }
67
+
68
+ function _deactivate(NftId componentNftId, NftId objectNftId) internal {
69
+ LibNftIdSet.remove(_activeObjects[componentNftId], objectNftId);
70
+ }
71
+
72
+ function _objects(NftId componentNftId) internal view returns (uint256) {
73
+ return LibNftIdSet.size(_allObjects[componentNftId]);
74
+ }
75
+
76
+ function _contains(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
77
+ return LibNftIdSet.contains(_allObjects[componentNftId], objectNftId);
78
+ }
79
+
80
+ function _getObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
81
+ return LibNftIdSet.getElementAt(_allObjects[componentNftId], idx);
82
+ }
83
+
84
+ function _activeObjs(NftId componentNftId) internal view returns (uint256) {
85
+ return LibNftIdSet.size(_activeObjects[componentNftId]);
86
+ }
87
+
88
+ function _isActive(NftId componentNftId, NftId objectNftId) internal view returns (bool) {
89
+ return LibNftIdSet.contains(_activeObjects[componentNftId], objectNftId);
90
+ }
91
+
92
+ function _getActiveObject(NftId componentNftId, uint256 idx) internal view returns (NftId) {
93
+ return LibNftIdSet.getElementAt(_activeObjects[componentNftId], idx);
94
+ }
95
+ }
@@ -4,23 +4,108 @@ pragma solidity ^0.8.19;
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
5
  import {IRegistryService} from "../../registry/IRegistryService.sol";
6
6
  import {IInstance} from "../../instance/IInstance.sol";
7
- import {ObjectType, INSTANCE, PRODUCT, POOL} from "../../types/ObjectType.sol";
7
+ import {ObjectType, INSTANCE, PRODUCT, POOL, DISTRIBUTION, ORACLE} from "../../types/ObjectType.sol";
8
8
  import {NftId, NftIdLib} from "../../types/NftId.sol";
9
+ import {RoleId, PRODUCT_OWNER_ROLE, POOL_OWNER_ROLE, DISTRIBUTION_OWNER_ROLE, ORACLE_OWNER_ROLE} from "../../types/RoleId.sol";
9
10
 
11
+ import {BaseComponent} from "../../components/BaseComponent.sol";
12
+ import {Product} from "../../components/Product.sol";
13
+ import {INftOwnable} from "../../shared/INftOwnable.sol";
10
14
  import {Service} from "../../shared/Service.sol";
15
+ import {InstanceService} from "../InstanceService.sol";
11
16
  import {Version, VersionPart, VersionLib} from "../../types/Version.sol";
12
17
 
13
18
  abstract contract ComponentServiceBase is Service {
14
19
 
15
- constructor(
16
- address registry,
17
- NftId registryNftId,
20
+ error ExpectedRoleMissing(RoleId expected, address caller);
21
+ error ComponentTypeInvalid(ObjectType componentType);
22
+
23
+ mapping (ObjectType => RoleId) internal _objectTypeToExpectedRole;
24
+
25
+ /// @dev modifier to check if caller has a role on the instance the component is registered in
26
+ modifier onlyComponentOwnerRole(address componentAddress) {
27
+ BaseComponent component = BaseComponent(componentAddress);
28
+ ObjectType objectType = _getObjectType(component);
29
+ RoleId expectedRole = _objectTypeToExpectedRole[objectType];
30
+
31
+ address componentOwner = msg.sender;
32
+ INftOwnable nftOwnable = INftOwnable(address(component.getInstance()));
33
+ if(! getInstanceService().hasRole(componentOwner, expectedRole, nftOwnable.getNftId())) {
34
+ revert ExpectedRoleMissing(expectedRole, componentOwner);
35
+ }
36
+ _;
37
+ }
38
+
39
+ /// @dev modifier to check if caller is a registered service
40
+ modifier onlyService() {
41
+ address caller = msg.sender;
42
+ require(getRegistry().isRegisteredService(caller), "ERROR_NOT_SERVICE");
43
+ _;
44
+ }
45
+
46
+ function _initializeService(
47
+ address registry,
18
48
  address initialOwner
19
49
  )
50
+ internal
51
+ override
20
52
  {
21
- _initializeService(registry, initialOwner);
53
+ super._initializeService(registry, initialOwner);
54
+ _objectTypeToExpectedRole[PRODUCT()] = PRODUCT_OWNER_ROLE();
55
+ _objectTypeToExpectedRole[POOL()] = POOL_OWNER_ROLE();
56
+ _objectTypeToExpectedRole[DISTRIBUTION()] = DISTRIBUTION_OWNER_ROLE();
57
+ _objectTypeToExpectedRole[ORACLE()] = ORACLE_OWNER_ROLE();
58
+ }
59
+
60
+ function getInstanceService() public view returns (InstanceService) {
61
+ return InstanceService(getRegistry().getServiceAddress("InstanceService", getMajorVersion()));
22
62
  }
23
63
 
64
+ function register(address componentAddress)
65
+ external
66
+ onlyComponentOwnerRole(componentAddress)
67
+ returns (NftId componentNftId)
68
+ {
69
+ address componentOwner = msg.sender;
70
+ BaseComponent component = BaseComponent(componentAddress);
71
+ ObjectType objectType = _getObjectType(component);
72
+ IRegistryService registryService = getRegistryService();
73
+
74
+ IRegistry.ObjectInfo memory objInfo;
75
+ bytes memory initialObjData;
76
+
77
+ if (objectType == DISTRIBUTION()) {
78
+ (objInfo, initialObjData) = registryService.registerDistribution(component, componentOwner);
79
+ } else if (objectType == PRODUCT()) {
80
+ (objInfo, initialObjData) = registryService.registerProduct(component, componentOwner);
81
+ } else if (objectType == POOL()) {
82
+ (objInfo, initialObjData) = registryService.registerPool(component, componentOwner);
83
+ // TODO: implement this for oracle - currently missing in registry
84
+ // } else if (objectType == ORACLE()) {
85
+ // (objInfo, initialObjData) = registryService.registerOracle(component, componentOwner);
86
+ } else {
87
+ revert ComponentTypeInvalid(objectType);
88
+ }
89
+
90
+ componentNftId = objInfo.nftId;
91
+ {
92
+ IInstance instance = _getInstance(objInfo);
93
+ _finalizeComponentRegistration(componentNftId, initialObjData, instance);
94
+ }
95
+ }
96
+
97
+ function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal virtual;
98
+
99
+ function _getObjectType(BaseComponent component) internal view returns (ObjectType) {
100
+ (IRegistry.ObjectInfo memory compInitialInfo, ) = component.getInitialInfo();
101
+ return compInitialInfo.objectType;
102
+ }
103
+
104
+ function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
105
+ IRegistry registry = getRegistry();
106
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
107
+ return IInstance(instanceInfo.objectAddress);
108
+ }
24
109
 
25
110
  function _getAndVerifyComponentInfoAndInstance(
26
111
  ObjectType objectType
@@ -32,7 +117,7 @@ abstract contract ComponentServiceBase is Service {
32
117
  IInstance instance
33
118
  )
34
119
  {
35
- NftId componentNftId = getRegistry().getNftId(msg.sender);
120
+ NftId componentNftId = _registry.getNftId(msg.sender);
36
121
  require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
37
122
 
38
123
  info = getRegistry().getObjectInfo(componentNftId);
@@ -13,6 +13,7 @@ interface IBundle {
13
13
  uint256 capitalAmount; // net investment capital + net premiums - payouts
14
14
  uint256 lockedAmount; // capital amount linked to collateralizaion of non-closed policies (<= balance)
15
15
  uint256 balanceAmount; // total amount of funds: capitalAmount + fees (balance >= captial)
16
+ uint256 lifetime;
16
17
  Timestamp expiredAt; // no new policies
17
18
  Timestamp closedAt; // no open policies, locked amount = 0
18
19
  }
@@ -20,6 +20,8 @@ interface ISetup {
20
20
  Fee poolFee; // pool fee on net premium
21
21
  Fee stakingFee; // pool fee on staked capital from investor
22
22
  Fee performanceFee; // pool fee on profits from capital investors
23
+ bool isIntercepting; // intercepts nft transfers (for products)
24
+ address wallet;
23
25
  }
24
26
 
25
27
  struct DistributionSetupInfo {
@@ -38,6 +40,7 @@ interface ISetup {
38
40
  Fee stakingFee; // pool fee on staked capital from investor
39
41
  Fee performanceFee; // pool fee on profits from capital investors
40
42
  bool isIntercepting; // intercepts nft transfers (for bundles)
43
+ bool isConfirmingApplication; // confirms applications before they are underwritten
41
44
  address wallet;
42
45
  }
43
46
  }
@@ -0,0 +1,88 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IRegistryService} from "../../registry/IRegistryService.sol";
6
+ import {IInstance} from "../../instance/IInstance.sol";
7
+ import {InstanceReader} from "../../instance/InstanceReader.sol";
8
+ import {ISetup} from "../../instance/module/ISetup.sol";
9
+ import {ITreasury} from "../../instance/module/ITreasury.sol";
10
+
11
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
12
+ import {Fee} from "../../types/Fee.sol";
13
+ import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
14
+ import {KEEP_STATE} from "../../types/StateId.sol";
15
+ import {DISTRIBUTION} from "../../types/ObjectType.sol";
16
+ import {Version, VersionLib} from "../../types/Version.sol";
17
+
18
+ import {IVersionable} from "../../shared/IVersionable.sol";
19
+ import {Versionable} from "../../shared/Versionable.sol";
20
+
21
+ import {IService} from "../../shared/IService.sol";
22
+ import {Service} from "../../shared/Service.sol";
23
+ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
24
+ import {IDistributionService} from "./IDistributionService.sol";
25
+ import {Distribution} from "../../components/Distribution.sol";
26
+ import {InstanceService} from "../InstanceService.sol";
27
+ import {Instance} from "../Instance.sol";
28
+ import {INftOwnable} from "../../shared/INftOwnable.sol";
29
+
30
+ string constant DISTRIBUTION_SERVICE_NAME = "DistributionService";
31
+
32
+ contract DistributionService is
33
+ ComponentServiceBase,
34
+ IDistributionService
35
+ {
36
+ using NftIdLib for NftId;
37
+
38
+ string public constant NAME = "DistributionService";
39
+
40
+ address internal _registryAddress;
41
+
42
+ function _initialize(
43
+ address owner,
44
+ bytes memory data
45
+ )
46
+ internal
47
+ initializer
48
+ virtual override
49
+ {
50
+ address initialOwner = address(0);
51
+ (_registryAddress, initialOwner) = abi.decode(data, (address, address));
52
+ // TODO while DistributionService is not deployed in DistributionServiceManager constructor
53
+ // owner is DistributionServiceManager deployer
54
+ _initializeService(_registryAddress, owner);
55
+
56
+ _registerInterface(type(IService).interfaceId);
57
+ _registerInterface(type(IDistributionService).interfaceId);
58
+ }
59
+
60
+
61
+ function getName() public pure override(IService, Service) returns(string memory name) {
62
+ return NAME;
63
+ }
64
+
65
+ function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
66
+ ISetup.DistributionSetupInfo memory initialSetup = abi.decode(
67
+ initialObjData,
68
+ (ISetup.DistributionSetupInfo)
69
+ );
70
+ instance.createDistributionSetup(componentNftId, initialSetup);
71
+ }
72
+
73
+ function setFees(
74
+ Fee memory distributionFee
75
+ )
76
+ external
77
+ override
78
+ {
79
+ (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
80
+ InstanceReader instanceReader = instance.getInstanceReader();
81
+ NftId distributionNftId = info.nftId;
82
+
83
+ ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
84
+ distSetupInfo.distributionFee = distributionFee;
85
+
86
+ instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
87
+ }
88
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IVersionable} from "../../shared/IVersionable.sol";
5
+ import {ProxyManager} from "../../shared/ProxyManager.sol";
6
+ import {DistributionService} from "./DistributionService.sol";
7
+ import {Registry} from "../../registry/Registry.sol";
8
+ import {RegistryService} from "../../registry/RegistryService.sol";
9
+ import {VersionLib} from "../../types/Version.sol";
10
+
11
+ contract DistributionServiceManager is ProxyManager {
12
+
13
+ DistributionService private _distributionService;
14
+
15
+ /// @dev initializes proxy manager with distribution service implementation and deploys instance
16
+ constructor(
17
+ address registryAddress
18
+ )
19
+ ProxyManager()
20
+ {
21
+ DistributionService distSrv = new DistributionService();
22
+ bytes memory data = abi.encode(registryAddress, address(this));
23
+ IVersionable versionable = deploy(
24
+ address(distSrv),
25
+ data);
26
+
27
+ _distributionService = DistributionService(address(versionable));
28
+
29
+ Registry registry = Registry(registryAddress);
30
+ address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
31
+ RegistryService registryService = RegistryService(registryServiceAddress);
32
+ // TODO this must have a role or own nft to register service
33
+ //registryService.registerService(_distributionService);
34
+
35
+ // TODO no nft to link yet
36
+ // link ownership of instance service manager ot nft owner of instance service
37
+ //_linkToNftOwnable(
38
+ // address(registryAddress),
39
+ // address(_distributionService));
40
+
41
+ // implies that after this constructor call only upgrade functionality is available
42
+ _isDeployed = true;
43
+ }
44
+
45
+ //--- view functions ----------------------------------------------------//
46
+ function getDistributionService()
47
+ external
48
+ view
49
+ returns (DistributionService distributionService)
50
+ {
51
+ return _distributionService;
52
+ }
53
+
54
+ }