@etherisc/gif-next 0.0.2-fb8d07b-779 → 0.0.2-fd275d2-234

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/README.md +43 -0
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +10 -10
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +2 -2
  9. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +16 -11
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +18 -64
  14. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  34. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  35. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  36. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  37. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +809 -0
  38. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  39. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +185 -0
  40. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  41. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +963 -18
  43. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  44. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +5 -0
  45. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  46. package/artifacts/contracts/instance/Instance.sol/Instance.json +150 -81
  47. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  48. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  49. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  50. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +74 -40
  51. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +128 -49
  53. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  54. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +52 -32
  55. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  56. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  57. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  58. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  59. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  62. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  64. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  68. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +16 -16
  72. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +12 -12
  74. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +17 -21
  76. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +108 -0
  80. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +40 -31
  82. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +146 -30
  84. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +23 -23
  86. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  87. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +1147 -0
  88. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  89. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +488 -0
  90. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  91. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +2 -110
  93. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  94. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -0
  95. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  96. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  97. package/artifacts/contracts/registry/Registry.sol/Registry.json +35 -146
  98. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  99. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +76 -20
  100. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  101. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +26 -34
  102. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  103. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +12 -12
  104. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  105. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  106. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  107. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  109. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  110. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  111. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  112. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  113. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  114. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  116. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  117. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  118. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  119. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  120. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  122. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  124. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  125. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  126. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  127. package/artifacts/contracts/test/TestService.sol/TestService.json +9 -9
  128. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  129. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  130. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  131. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  132. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  133. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  136. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  138. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  140. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  141. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  147. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  148. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  149. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  153. package/contracts/components/Distribution.sol +6 -3
  154. package/contracts/components/IPoolComponent.sol +1 -1
  155. package/contracts/components/Pool.sol +13 -9
  156. package/contracts/components/Product.sol +33 -41
  157. package/contracts/instance/BundleManager.sol +152 -0
  158. package/contracts/instance/Cloneable.sol +46 -0
  159. package/contracts/instance/IInstance.sol +21 -4
  160. package/contracts/instance/IInstanceService.sol +3 -1
  161. package/contracts/instance/Instance.sol +15 -4
  162. package/contracts/instance/InstanceReader.sol +9 -0
  163. package/contracts/instance/InstanceService.sol +62 -12
  164. package/contracts/instance/InstanceServiceManager.sol +6 -5
  165. package/contracts/instance/ObjectManager.sol +95 -0
  166. package/contracts/instance/base/ComponentServiceBase.sol +14 -5
  167. package/contracts/instance/module/ISetup.sol +3 -1
  168. package/contracts/instance/service/DistributionService.sol +3 -2
  169. package/contracts/instance/service/DistributionServiceManager.sol +6 -5
  170. package/contracts/instance/service/IPoolService.sol +6 -0
  171. package/contracts/instance/service/IProductService.sol +6 -3
  172. package/contracts/instance/service/PoolService.sol +31 -18
  173. package/contracts/instance/service/PoolServiceManager.sol +6 -5
  174. package/contracts/instance/service/ProductService.sol +561 -0
  175. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  176. package/contracts/registry/IRegistry.sol +5 -18
  177. package/contracts/registry/IRegistryService.sol +28 -11
  178. package/contracts/registry/Registry.sol +4 -45
  179. package/contracts/registry/RegistryService.sol +30 -71
  180. package/contracts/shared/NftOwnable.sol +2 -4
  181. package/contracts/types/NftIdSet.sol +26 -24
  182. package/contracts/types/RoleId.sol +1 -0
  183. package/package.json +1 -1
@@ -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
+ }
@@ -9,6 +9,7 @@ import {NftId, NftIdLib} from "../../types/NftId.sol";
9
9
  import {RoleId, PRODUCT_OWNER_ROLE, POOL_OWNER_ROLE, DISTRIBUTION_OWNER_ROLE, ORACLE_OWNER_ROLE} from "../../types/RoleId.sol";
10
10
 
11
11
  import {BaseComponent} from "../../components/BaseComponent.sol";
12
+ import {Product} from "../../components/Product.sol";
12
13
  import {INftOwnable} from "../../shared/INftOwnable.sol";
13
14
  import {Service} from "../../shared/Service.sol";
14
15
  import {InstanceService} from "../InstanceService.sol";
@@ -35,6 +36,13 @@ abstract contract ComponentServiceBase is Service {
35
36
  _;
36
37
  }
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
+
38
46
  function _initializeService(
39
47
  address registry,
40
48
  address initialOwner
@@ -80,8 +88,10 @@ abstract contract ComponentServiceBase is Service {
80
88
  }
81
89
 
82
90
  componentNftId = objInfo.nftId;
83
- IInstance instance = _getInstanceFromComponentNft(componentNftId);
84
- _finalizeComponentRegistration(componentNftId, initialObjData, instance);
91
+ {
92
+ IInstance instance = _getInstance(objInfo);
93
+ _finalizeComponentRegistration(componentNftId, initialObjData, instance);
94
+ }
85
95
  }
86
96
 
87
97
  function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal virtual;
@@ -91,10 +101,9 @@ abstract contract ComponentServiceBase is Service {
91
101
  return compInitialInfo.objectType;
92
102
  }
93
103
 
94
- function _getInstanceFromComponentNft(NftId componentNftId) internal view returns (IInstance) {
104
+ function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
95
105
  IRegistry registry = getRegistry();
96
- IRegistry.ObjectInfo memory compInfo = registry.getObjectInfo(componentNftId);
97
- IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compInfo.parentNftId);
106
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
98
107
  return IInstance(instanceInfo.objectAddress);
99
108
  }
100
109
 
@@ -5,7 +5,6 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IER
5
5
 
6
6
  import {Fee} from "../../types/Fee.sol";
7
7
  import {NftId} from "../../types/NftId.sol";
8
- import {LibNftIdSet} from "../../types/NftIdSet.sol";
9
8
  import {UFixed} from "../../types/UFixed.sol";
10
9
  import {TokenHandler} from "../../shared/TokenHandler.sol";
11
10
 
@@ -21,6 +20,8 @@ interface ISetup {
21
20
  Fee poolFee; // pool fee on net premium
22
21
  Fee stakingFee; // pool fee on staked capital from investor
23
22
  Fee performanceFee; // pool fee on profits from capital investors
23
+ bool isIntercepting; // intercepts nft transfers (for products)
24
+ address wallet;
24
25
  }
25
26
 
26
27
  struct DistributionSetupInfo {
@@ -39,6 +40,7 @@ interface ISetup {
39
40
  Fee stakingFee; // pool fee on staked capital from investor
40
41
  Fee performanceFee; // pool fee on profits from capital investors
41
42
  bool isIntercepting; // intercepts nft transfers (for bundles)
43
+ bool isConfirmingApplication; // confirms applications before they are underwritten
42
44
  address wallet;
43
45
  }
44
46
  }
@@ -49,8 +49,9 @@ contract DistributionService is
49
49
  {
50
50
  address initialOwner = address(0);
51
51
  (_registryAddress, initialOwner) = abi.decode(data, (address, address));
52
-
53
- _initializeService(_registryAddress, initialOwner);
52
+ // TODO while DistributionService is not deployed in DistributionServiceManager constructor
53
+ // owner is DistributionServiceManager deployer
54
+ _initializeService(_registryAddress, owner);
54
55
 
55
56
  _registerInterface(type(IService).interfaceId);
56
57
  _registerInterface(type(IDistributionService).interfaceId);
@@ -29,13 +29,14 @@ contract DistributionServiceManager is ProxyManager {
29
29
  Registry registry = Registry(registryAddress);
30
30
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
31
31
  RegistryService registryService = RegistryService(registryServiceAddress);
32
+ // TODO this must have a role or own nft to register service
33
+ //registryService.registerService(_distributionService);
32
34
 
33
- registryService.registerService(_distributionService);
34
-
35
+ // TODO no nft to link yet
35
36
  // link ownership of instance service manager ot nft owner of instance service
36
- _linkToNftOwnable(
37
- address(registryAddress),
38
- address(_distributionService));
37
+ //_linkToNftOwnable(
38
+ // address(registryAddress),
39
+ // address(_distributionService));
39
40
 
40
41
  // implies that after this constructor call only upgrade functionality is available
41
42
  _isDeployed = true;
@@ -3,9 +3,13 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {NftId} from "../../types/NftId.sol";
5
5
  import {Fee} from "../../types/Fee.sol";
6
+ import {StateId} from "../../types/StateId.sol";
6
7
  import {IService} from "../../shared/IService.sol";
8
+ import {IBundle} from "../module/IBundle.sol";
7
9
 
8
10
  interface IPoolService is IService {
11
+ error ErrorIPoolServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
12
+
9
13
  function setFees(
10
14
  Fee memory poolFee,
11
15
  Fee memory stakingFee,
@@ -25,6 +29,8 @@ interface IPoolService is IService {
25
29
  Fee memory fee
26
30
  ) external;
27
31
 
32
+ function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
33
+
28
34
  // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
29
35
 
30
36
  // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
@@ -13,6 +13,9 @@ import {UFixed} from "../../types/UFixed.sol";
13
13
  import {Fee} from "../../types/Fee.sol";
14
14
 
15
15
  interface IProductService is IService {
16
+
17
+ error ErrorIProductServiceInsufficientAllowance(address customer, address tokenHandlerAddress, uint256 amount);
18
+
16
19
  function setFees(
17
20
  Fee memory productFee,
18
21
  Fee memory processingFee
@@ -24,15 +27,15 @@ interface IProductService is IService {
24
27
  ) external;
25
28
 
26
29
 
27
- function setRiskInfo(
30
+ function updateRisk(
28
31
  RiskId riskId,
29
- IRisk.RiskInfo memory data
32
+ bytes memory data
30
33
  ) external;
31
34
 
32
35
 
33
36
  function updateRiskState(
34
37
  RiskId riskId,
35
- StateId state
38
+ StateId newState
36
39
  ) external;
37
40
 
38
41
 
@@ -17,18 +17,18 @@ import {POOL, BUNDLE} from "../../types/ObjectType.sol";
17
17
  import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
18
18
  import {Fee, FeeLib} from "../../types/Fee.sol";
19
19
  import {Version, VersionLib} from "../../types/Version.sol";
20
- import {KEEP_STATE} from "../../types/StateId.sol";
20
+ import {KEEP_STATE, StateId} from "../../types/StateId.sol";
21
21
  import {zeroTimestamp} from "../../types/Timestamp.sol";
22
22
 
23
23
  import {IService} from "../../shared/IService.sol";
24
24
  import {Service} from "../../shared/Service.sol";
25
+ import {BundleManager} from "../BundleManager.sol";
25
26
  import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
26
27
  import {IPoolService} from "./IPoolService.sol";
27
28
  import {IRegistryService} from "../../registry/IRegistryService.sol";
28
29
  import {InstanceService} from "../InstanceService.sol";
29
30
  import {InstanceReader} from "../InstanceReader.sol";
30
31
 
31
-
32
32
  string constant POOL_SERVICE_NAME = "PoolService";
33
33
 
34
34
  contract PoolService is
@@ -51,8 +51,9 @@ contract PoolService is
51
51
  {
52
52
  address initialOwner = address(0);
53
53
  (_registryAddress, initialOwner) = abi.decode(data, (address, address));
54
-
55
- _initializeService(_registryAddress, initialOwner);
54
+ // TODO while PoolService is not deployed in PoolServiceManager constructor
55
+ // owner is PoolServiceManager deployer
56
+ _initializeService(_registryAddress, owner);
56
57
 
57
58
  _registerInterface(type(IService).interfaceId);
58
59
  _registerInterface(type(IPoolService).interfaceId);
@@ -107,7 +108,7 @@ contract PoolService is
107
108
 
108
109
  IBundle.BundleInfo memory bundleInfo = IBundle.BundleInfo(
109
110
  poolNftId,
110
- FeeLib.zeroFee(),
111
+ fee,
111
112
  filter,
112
113
  stakingAmount,
113
114
  0,
@@ -133,15 +134,14 @@ contract PoolService is
133
134
  // create bundle info in instance
134
135
  instance.createBundle(bundleNftId, bundleInfo);
135
136
 
136
- // TODO add bundle to pool in instance
137
+ BundleManager bundleManager = instance.getBundleManager();
138
+ bundleManager.add(bundleNftId);
137
139
 
138
- // TODO collect capital
139
- // _processStakingByTreasury(
140
- // instanceReader,
141
- // zeroNftId(),
142
- // poolNftId,
143
- // bundleNftId,
144
- // stakingAmount);
140
+ _processStakingByTreasury(
141
+ instanceReader,
142
+ poolNftId,
143
+ bundleNftId,
144
+ stakingAmount);
145
145
 
146
146
  // TODO add logging
147
147
  }
@@ -166,11 +166,17 @@ contract PoolService is
166
166
  instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
167
167
  }
168
168
 
169
-
169
+ function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state)
170
+ external
171
+ onlyService
172
+ {
173
+ IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
174
+ IInstance instance = IInstance(instanceInfo.objectAddress);
175
+ instance.updateBundle(bundleNftId, bundleInfo, state);
176
+ }
170
177
 
171
178
  function _processStakingByTreasury(
172
179
  InstanceReader instanceReader,
173
- NftId productNftId,
174
180
  NftId poolNftId,
175
181
  NftId bundleNftId,
176
182
  uint256 stakingAmount
@@ -179,15 +185,22 @@ contract PoolService is
179
185
  {
180
186
  // process token transfer(s)
181
187
  if(stakingAmount > 0) {
182
- TokenHandler tokenHandler = TokenHandler(instanceReader.getTokenHandler(productNftId));
183
- address bundleOwner = getRegistry().ownerOf(bundleNftId);
184
188
  ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
185
-
189
+ TokenHandler tokenHandler = poolInfo.tokenHandler;
190
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
191
+ Fee memory stakingFee = poolInfo.stakingFee;
192
+
186
193
  tokenHandler.transfer(
187
194
  bundleOwner,
188
195
  poolInfo.wallet,
189
196
  stakingAmount
190
197
  );
198
+
199
+
200
+ if (! FeeLib.feeIsZero(stakingFee)) {
201
+ (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
202
+ // TODO: track staking fees in pool's state (issue #177)
203
+ }
191
204
  }
192
205
  }
193
206
  }
@@ -29,13 +29,14 @@ contract PoolServiceManager is ProxyManager {
29
29
  Registry registry = Registry(registryAddress);
30
30
  address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
31
31
  RegistryService registryService = RegistryService(registryServiceAddress);
32
+ // TODO this must have a role or own nft to register service
33
+ //registryService.registerService(_poolService);
32
34
 
33
- registryService.registerService(_poolService);
34
-
35
+ // TODO no nft to link yet
35
36
  // link ownership of instance service manager ot nft owner of instance service
36
- _linkToNftOwnable(
37
- address(registryAddress),
38
- address(_poolService));
37
+ //_linkToNftOwnable(
38
+ // address(registryAddress),
39
+ // address(_poolService));
39
40
 
40
41
  // implies that after this constructor call only upgrade functionality is available
41
42
  _isDeployed = true;