@etherisc/gif-next 0.0.2-d551b5e-892 → 0.0.2-d5522f6-712

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +29 -0
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +33 -102
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +29 -0
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +33 -130
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +33 -113
  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/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  35. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  36. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  37. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +26 -0
  40. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  41. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  42. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +99 -14
  43. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  44. package/artifacts/contracts/instance/Instance.sol/Instance.json +82 -603
  45. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  46. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +221 -114
  47. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  48. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +2 -2
  49. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  50. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +2 -2
  51. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +156 -192
  53. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  54. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +26 -98
  55. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  56. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  57. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  58. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +24 -13
  59. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  62. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  63. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  64. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +59 -16
  66. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  68. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  73. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +1031 -0
  74. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  75. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +436 -0
  76. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +39 -52
  78. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +47 -38
  80. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +13 -21
  82. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  83. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +720 -0
  84. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +13 -13
  86. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +13 -13
  88. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +121 -14
  90. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +12 -241
  92. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +32 -34
  94. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +237 -65
  96. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +51 -23
  98. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +30 -320
  100. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  101. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +13 -41
  102. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  103. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +43 -55
  104. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  105. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +12 -12
  106. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  107. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +132 -133
  110. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  111. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -65
  112. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  114. package/artifacts/contracts/registry/Registry.sol/Registry.json +145 -227
  115. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +4 -0
  116. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +285 -0
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  118. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +30 -128
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  120. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +38 -104
  121. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +4 -0
  122. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +546 -0
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  124. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +14 -27
  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/IService.sol/IService.json +13 -13
  131. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  132. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  133. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  135. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  137. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  138. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  139. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Service.sol/Service.json +13 -13
  141. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  142. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  143. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  145. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  147. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  149. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestService.sol/TestService.json +31 -31
  151. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  152. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  154. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  155. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  156. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  161. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  163. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  169. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  175. package/contracts/components/BaseComponent.sol +35 -8
  176. package/contracts/components/Distribution.sol +2 -1
  177. package/contracts/components/IBaseComponent.sol +3 -0
  178. package/contracts/components/Pool.sol +11 -6
  179. package/contracts/components/Product.sol +10 -1
  180. package/contracts/instance/IInstance.sol +4 -0
  181. package/contracts/instance/IInstanceService.sol +10 -2
  182. package/contracts/instance/Instance.sol +20 -204
  183. package/contracts/instance/InstanceAccessManager.sol +92 -77
  184. package/contracts/instance/InstanceService.sol +208 -115
  185. package/contracts/instance/InstanceServiceManager.sol +5 -8
  186. package/contracts/instance/base/ComponentServiceBase.sol +16 -12
  187. package/contracts/instance/module/IAccess.sol +27 -17
  188. package/contracts/instance/service/BundleService.sol +294 -0
  189. package/contracts/instance/service/BundleServiceManager.sol +51 -0
  190. package/contracts/instance/service/ComponentOwnerService.sol +4 -6
  191. package/contracts/instance/service/DistributionService.sol +21 -19
  192. package/contracts/instance/service/DistributionServiceManager.sol +6 -9
  193. package/contracts/instance/service/IBundleService.sol +44 -0
  194. package/contracts/instance/service/IPolicyService.sol +9 -2
  195. package/contracts/instance/service/IPoolService.sol +2 -33
  196. package/contracts/instance/service/IProductService.sol +2 -2
  197. package/contracts/instance/service/PolicyService.sol +70 -44
  198. package/contracts/instance/service/PoolService.sol +33 -205
  199. package/contracts/instance/service/PoolServiceManager.sol +5 -8
  200. package/contracts/instance/service/ProductService.sol +55 -15
  201. package/contracts/registry/ChainNft.sol +1 -1
  202. package/contracts/registry/IRegistry.sol +26 -16
  203. package/contracts/registry/IRegistryService.sol +13 -5
  204. package/contracts/registry/Registry.sol +149 -201
  205. package/contracts/registry/RegistryAccessManager.sol +210 -0
  206. package/contracts/registry/RegistryService.sol +49 -88
  207. package/contracts/registry/RegistryServiceManager.sol +18 -36
  208. package/contracts/registry/ReleaseManager.sol +348 -0
  209. package/contracts/registry/TokenRegistry.sol +5 -6
  210. package/contracts/shared/IService.sol +2 -1
  211. package/contracts/shared/ProxyManager.sol +1 -1
  212. package/contracts/shared/Service.sol +10 -7
  213. package/contracts/test/TestService.sol +3 -2
  214. package/contracts/types/RoleId.sol +10 -11
  215. package/package.json +1 -1
  216. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +0 -4
  217. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.json +0 -1082
  218. package/contracts/instance/IAccessManagerSimple.sol +0 -391
@@ -20,11 +20,11 @@ import {TokenHandler} from "../../shared/TokenHandler.sol";
20
20
  import {IVersionable} from "../../shared/IVersionable.sol";
21
21
  import {Versionable} from "../../shared/Versionable.sol";
22
22
 
23
- import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
23
+ import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
24
24
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
25
25
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
26
- import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
27
- import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
26
+ import {ObjectType, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
27
+ import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
28
28
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
29
29
  import {Fee, FeeLib} from "../../types/Fee.sol";
30
30
  import {ReferralId} from "../../types/Referral.sol";
@@ -38,17 +38,16 @@ import {Service} from "../../shared/Service.sol";
38
38
  import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
39
39
  import {IPolicyService} from "./IPolicyService.sol";
40
40
  import {InstanceReader} from "../InstanceReader.sol";
41
- import {IPoolService} from "./PoolService.sol";
42
- import {POOL_SERVICE_NAME} from "./PoolService.sol";
41
+ import {IPoolService} from "./IPoolService.sol";
42
+ import {IBundleService} from "./IBundleService.sol";
43
43
 
44
- string constant PRODUCT_SERVICE_NAME = "ProductService";
45
44
 
46
45
  contract PolicyService is ComponentServiceBase, IPolicyService {
47
46
  using NftIdLib for NftId;
48
-
49
- string public constant NAME = "PolicyService";
47
+ using TimestampLib for Timestamp;
50
48
 
51
49
  IPoolService internal _poolService;
50
+ IBundleService internal _bundleService;
52
51
 
53
52
  event LogProductServiceSender(address sender);
54
53
 
@@ -66,14 +65,15 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
66
65
 
67
66
  _initializeService(registryAddress, owner);
68
67
 
69
- _poolService = IPoolService(_registry.getServiceAddress(POOL_SERVICE_NAME, getMajorVersion()));
68
+ _poolService = IPoolService(_registry.getServiceAddress(POOL(), getMajorVersion()));
69
+ _bundleService = IBundleService(_registry.getServiceAddress(BUNDLE(), getMajorVersion()));
70
70
 
71
71
  _registerInterface(type(IPolicyService).interfaceId);
72
72
  }
73
73
 
74
74
 
75
- function getName() public pure override(IService, Service) returns(string memory name) {
76
- return NAME;
75
+ function getDomain() public pure override(IService, Service) returns(ObjectType) {
76
+ return POLICY();
77
77
  }
78
78
 
79
79
 
@@ -82,7 +82,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
82
82
  (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
83
83
  product = Product(productInfo.objectAddress);
84
84
  }
85
- // TODO no access restrictions
85
+ // TODO: no access restrictions
86
86
  function calculatePremium(
87
87
  RiskId riskId,
88
88
  uint256 sumInsuredAmount,
@@ -180,7 +180,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
180
180
  ReferralId referralId
181
181
  ) external override returns (NftId policyNftId) {
182
182
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
183
- // TODO add validations (see create bundle in pool service)
183
+ // TODO: add validations (see create bundle in pool service)
184
184
 
185
185
  policyNftId = getRegistryService().registerPolicy(
186
186
  IRegistry.ObjectInfo(
@@ -225,7 +225,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
225
225
  instance.createPolicy(policyNftId, policyInfo);
226
226
  instance.updatePolicyState(policyNftId, APPLIED());
227
227
 
228
- // TODO add logging
228
+ // TODO: add logging
229
229
  }
230
230
 
231
231
  function _getAndVerifyUnderwritingSetup(
@@ -339,15 +339,6 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
339
339
  productSetupInfo
340
340
  );
341
341
  }
342
-
343
-
344
- // lock bundle collateral
345
- bundleInfo = _lockCollateralInBundle(
346
- instance,
347
- bundleNftId,
348
- bundleInfo,
349
- policyNftId,
350
- collateralAmount);
351
342
 
352
343
  // lock bundle collateral
353
344
  bundleInfo = _lockCollateralInBundle(
@@ -376,7 +367,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
376
367
  policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
377
368
  }
378
369
 
379
- _poolService.underwritePolicy(instance, policyNftId, bundleNftId, collateralAmount, netPremiumAmount);
370
+ _bundleService.underwritePolicy(instance, policyNftId, bundleNftId, collateralAmount, netPremiumAmount);
380
371
  instance.updatePolicy(policyNftId, policyInfo, newPolicyState);
381
372
 
382
373
  // involve pool if necessary
@@ -394,7 +385,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
394
385
  }
395
386
  }
396
387
 
397
- // TODO add logging
388
+ // TODO: add logging
398
389
  }
399
390
 
400
391
  function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
@@ -407,28 +398,30 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
407
398
  // check caller is registered product
408
399
  (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
409
400
  InstanceReader instanceReader = instance.getInstanceReader();
401
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
410
402
 
411
- // TODO: check if not paid
412
- // TODO: transfer premium
413
- // TODO: optionally activate
403
+ if (policyInfo.premiumPaidAmount == policyInfo.premiumAmount) {
404
+ revert ErrorIPolicyServicePremiumAlreadyPaid(policyNftId, policyInfo.premiumPaidAmount);
405
+ }
414
406
 
415
- // // perform actual token transfers (this code is probably not complete)
416
- // IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
417
-
418
- // uint256 premiumAmount = policyInfo.premiumAmount;
419
- // _processPremiumByTreasury(instance, productInfo.nftId, policyNftId, premiumAmount);
407
+ uint256 unpaidPremiumAmount = policyInfo.premiumAmount - policyInfo.premiumPaidAmount;
420
408
 
421
- // // policy level book keeping for premium paid
422
- // policyInfo.premiumPaidAmount += premiumAmount;
409
+ uint256 netPremiumAmount = _processPremiumByTreasury(
410
+ instance,
411
+ productInfo.nftId,
412
+ policyNftId,
413
+ unpaidPremiumAmount);
423
414
 
424
- // instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
415
+ policyInfo.premiumPaidAmount += unpaidPremiumAmount;
425
416
 
426
- // // optional activation of policy
427
- // if(activateAt > zeroTimestamp()) {
428
- // activate(policyNftId, activateAt);
429
- // }
417
+ _bundleService.increaseBalance(instance, policyInfo.bundleNftId, netPremiumAmount);
418
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
419
+
420
+ if(activateAt.gtz() && policyInfo.activatedAt.eqz()) {
421
+ activate(policyNftId, activateAt);
422
+ }
430
423
 
431
- // TODO add logging
424
+ // TODO: add logging
432
425
  }
433
426
 
434
427
  function activate(NftId policyNftId, Timestamp activateAt) public override {
@@ -447,14 +440,47 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
447
440
 
448
441
  instance.updatePolicy(policyNftId, policyInfo, ACTIVE());
449
442
 
450
- // TODO add logging
443
+ // TODO: add logging
451
444
  }
452
445
 
453
446
  function close(
454
447
  NftId policyNftId
455
448
  ) external override // solhint-disable-next-line no-empty-blocks
456
449
  {
450
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
451
+ InstanceReader instanceReader = instance.getInstanceReader();
452
+
453
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
454
+
455
+ if (policyInfo.activatedAt.eqz()) {
456
+ revert ErrorIPolicyServicePolicyNotActivated(policyNftId);
457
+ }
458
+
459
+ StateId state = instanceReader.getPolicyState(policyNftId);
460
+ if (state != ACTIVE()) {
461
+ revert ErrorIPolicyServicePolicyNotActive(policyNftId, state);
462
+ }
463
+
464
+ if (policyInfo.closedAt.gtz()) {
465
+ revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
466
+ }
467
+
468
+ if (policyInfo.premiumAmount != policyInfo.premiumPaidAmount) {
469
+ revert ErrorIPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
470
+ }
471
+
472
+ if (policyInfo.openClaimsCount > 0) {
473
+ revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
474
+ }
475
+
476
+ if (TimestampLib.blockTimestamp().lte(policyInfo.expiredAt) && (policyInfo.payoutAmount < policyInfo.sumInsuredAmount)) {
477
+ revert ErrorIPolicyServicePolicyHasNotExpired(policyNftId, policyInfo.expiredAt);
478
+ }
479
+
480
+ policyInfo.closedAt = TimestampLib.blockTimestamp();
457
481
 
482
+ _bundleService.closePolicy(instance, policyNftId, policyInfo.bundleNftId, policyInfo.sumInsuredAmount);
483
+ instance.updatePolicy(policyNftId, policyInfo, CLOSED());
458
484
  }
459
485
 
460
486
  function _getPoolNftId(
@@ -500,7 +526,7 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
500
526
  (uint256 productFeeAmount, uint256 netAmount) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
501
527
  address productWallet = productSetupInfo.wallet;
502
528
  if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premiumAmount) {
503
- revert ErrorIProductServiceInsufficientAllowance(policyOwner, address(tokenHandler), premiumAmount);
529
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premiumAmount);
504
530
  }
505
531
  tokenHandler.transfer(policyOwner, productWallet, productFeeAmount);
506
532
  tokenHandler.transfer(policyOwner, poolWallet, netAmount);
@@ -508,6 +534,6 @@ contract PolicyService is ComponentServiceBase, IPolicyService {
508
534
  }
509
535
  }
510
536
 
511
- // TODO add logging
537
+ // TODO: add logging
512
538
  }
513
539
  }
@@ -14,7 +14,7 @@ import {Versionable} from "../../shared/Versionable.sol";
14
14
  import {INftOwnable} from "../../shared/INftOwnable.sol";
15
15
 
16
16
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
17
- import {POOL, BUNDLE} from "../../types/ObjectType.sol";
17
+ import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
18
18
  import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
19
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
20
20
  import {Version, VersionLib} from "../../types/Version.sol";
@@ -39,8 +39,6 @@ contract PoolService is
39
39
  {
40
40
  using NftIdLib for NftId;
41
41
 
42
- string public constant NAME = "PoolService";
43
-
44
42
  address internal _registryAddress;
45
43
 
46
44
  function _initialize(
@@ -61,8 +59,8 @@ contract PoolService is
61
59
  _registerInterface(type(IPoolService).interfaceId);
62
60
  }
63
61
 
64
- function getName() public pure override(Service, IService) returns(string memory name) {
65
- return NAME;
62
+ function getDomain() public pure override(Service, IService) returns(ObjectType) {
63
+ return POOL();
66
64
  }
67
65
 
68
66
  function register(address poolAddress)
@@ -76,8 +74,8 @@ contract PoolService is
76
74
  bytes memory data;
77
75
  (info, data) = getRegistryService().registerPool(pool, poolOwner);
78
76
 
79
- IInstance instance = _getInstance(info);
80
- // check role here
77
+ NftId instanceNftId = info.parentNftId;
78
+ IInstance instance = _getInstance(instanceNftId);
81
79
  bool hasRole = getInstanceService().hasRole(
82
80
  poolOwner,
83
81
  POOL_OWNER_ROLE(),
@@ -88,18 +86,41 @@ contract PoolService is
88
86
  }
89
87
 
90
88
  poolNftId = info.nftId;
91
- ISetup.PoolSetupInfo memory initialSetup = _decodeAndVerifyPoolSetup(data);
89
+ string memory poolName;
90
+ ISetup.PoolSetupInfo memory initialSetup;
91
+ (poolName, initialSetup) = _decodeAndVerifyPoolData(data);
92
92
  instance.createPoolSetup(poolNftId, initialSetup);
93
+
94
+ getInstanceService().createTarget(instanceNftId, poolAddress, poolName);
95
+
96
+ pool.linkToRegisteredNftId();
93
97
  }
94
98
 
95
- function _decodeAndVerifyPoolSetup(bytes memory data) internal returns(ISetup.PoolSetupInfo memory setup)
99
+ function _decodeAndVerifyPoolData(bytes memory data)
100
+ internal
101
+ returns(string memory name, ISetup.PoolSetupInfo memory setup)
96
102
  {
97
- setup = abi.decode(
103
+ (name, setup) = abi.decode(
98
104
  data,
99
- (ISetup.PoolSetupInfo)
105
+ (string, ISetup.PoolSetupInfo)
100
106
  );
101
107
 
102
- // TODO add checks if applicable
108
+ // TODO add checks
109
+ /*IRegistry _registry = getRegistry();
110
+
111
+ if(wallet == address(0)) {
112
+ revert WalletIsZero();
113
+ }
114
+
115
+ ObjectType tokenType = _registry.getObjectInfo(address(token)).objectType;
116
+
117
+ if(tokenType != TOKEN()) {
118
+ revert InvalidToken();
119
+ }
120
+
121
+ if(UFixedLib.eqz(info.collateralizationLevel)) {
122
+ revert CollateralizationLevelIsZero();
123
+ }*/
103
124
  }
104
125
 
105
126
  function setFees(
@@ -121,197 +142,4 @@ contract PoolService is
121
142
 
122
143
  instance.updatePoolSetup(poolNftId, poolSetupInfo, KEEP_STATE());
123
144
  }
124
-
125
- function createBundle(
126
- address owner,
127
- Fee memory fee,
128
- uint256 stakingAmount,
129
- uint256 lifetime,
130
- bytes calldata filter
131
- )
132
- external
133
- override
134
- returns(NftId bundleNftId)
135
- {
136
- (IRegistry.ObjectInfo memory info, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
137
- InstanceReader instanceReader = instance.getInstanceReader();
138
- NftId poolNftId = info.nftId;
139
-
140
- IBundle.BundleInfo memory bundleInfo = IBundle.BundleInfo(
141
- poolNftId,
142
- fee,
143
- filter,
144
- stakingAmount,
145
- 0,
146
- stakingAmount,
147
- lifetime,
148
- zeroTimestamp(),
149
- zeroTimestamp()
150
- );
151
-
152
- // register bundle with registry
153
- bundleNftId = getRegistryService().registerBundle(
154
- IRegistry.ObjectInfo(
155
- zeroNftId(),
156
- poolNftId,
157
- BUNDLE(),
158
- false, // intercepting property for bundles is defined on pool
159
- address(0),
160
- owner,
161
- abi.encode(bundleInfo)
162
- )
163
- );
164
-
165
- // create bundle info in instance
166
- instance.createBundle(bundleNftId, bundleInfo);
167
-
168
- BundleManager bundleManager = instance.getBundleManager();
169
- bundleManager.add(bundleNftId);
170
-
171
- _processStakingByTreasury(
172
- instanceReader,
173
- poolNftId,
174
- bundleNftId,
175
- stakingAmount);
176
-
177
- // TODO add logging
178
- }
179
-
180
- function setBundleFee(
181
- NftId bundleNftId,
182
- Fee memory fee
183
- )
184
- external
185
- override
186
- {
187
- (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
188
- InstanceReader instanceReader = instance.getInstanceReader();
189
- NftId poolNftId = info.nftId;
190
-
191
- IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
192
- require(bundleInfo.poolNftId.gtz(), "ERROR:PLS-010:BUNDLE_UNKNOWN");
193
- require(poolNftId == bundleInfo.poolNftId, "ERROR:PLS-011:BUNDLE_POOL_MISMATCH");
194
-
195
- bundleInfo.fee = fee;
196
-
197
- instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
198
- }
199
-
200
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state)
201
- external
202
- onlyService
203
- {
204
- IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
205
- IInstance instance = IInstance(instanceInfo.objectAddress);
206
- instance.updateBundle(bundleNftId, bundleInfo, state);
207
- }
208
-
209
- function lockBundle(NftId bundleNftId)
210
- external
211
- {
212
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
213
- BundleManager bundleManager = instance.getBundleManager();
214
- bundleManager.lock(bundleNftId);
215
- }
216
-
217
- function unlockBundle(NftId bundleNftId)
218
- external
219
- {
220
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
221
- BundleManager bundleManager = instance.getBundleManager();
222
- bundleManager.unlock(bundleNftId);
223
- }
224
-
225
- function underwritePolicy(IInstance instance,
226
- NftId policyNftId,
227
- NftId bundleNftId,
228
- uint256 collateralAmount,
229
- uint256 netPremiumAmount
230
- )
231
- external
232
- onlyService
233
- {
234
- InstanceReader instanceReader = instance.getInstanceReader();
235
- IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
236
-
237
- // lock collateral
238
- bundleInfo.lockedAmount += collateralAmount;
239
- bundleInfo.balanceAmount += netPremiumAmount;
240
-
241
- instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
242
-
243
- linkPolicy(instance, policyNftId);
244
- }
245
-
246
- /// @dev links policy to bundle
247
- function linkPolicy(IInstance instance, NftId policyNftId)
248
- internal
249
- onlyService
250
- {
251
- InstanceReader instanceReader = instance.getInstanceReader();
252
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
253
-
254
- // ensure policy has not yet been activated
255
- if (policyInfo.activatedAt.gtz()) {
256
- revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
257
- }
258
-
259
- BundleManager bundleManager = instance.getBundleManager();
260
- bundleManager.linkPolicy(policyNftId);
261
- }
262
-
263
- /// @dev unlinks policy from bundle
264
- function unlinkPolicy(IInstance instance, NftId policyNftId)
265
- internal
266
- onlyService
267
- {
268
- InstanceReader instanceReader = instance.getInstanceReader();
269
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
270
-
271
- // ensure policy has no open claims
272
- if (policyInfo.openClaimsCount > 0) {
273
- revert BundleManager.ErrorBundleManagerPolicyWithOpenClaims(
274
- policyNftId,
275
- policyInfo.openClaimsCount);
276
- }
277
-
278
- // ensure policy is closeable
279
- if (policyInfo.expiredAt < TimestampLib.blockTimestamp()
280
- || policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
281
- {
282
- revert BundleManager.ErrorBundleManagerPolicyNotCloseable(policyNftId);
283
- }
284
-
285
- BundleManager bundleManager = instance.getBundleManager();
286
- bundleManager.unlinkPolicy(policyNftId);
287
- }
288
-
289
- function _processStakingByTreasury(
290
- InstanceReader instanceReader,
291
- NftId poolNftId,
292
- NftId bundleNftId,
293
- uint256 stakingAmount
294
- )
295
- internal
296
- {
297
- // process token transfer(s)
298
- if(stakingAmount > 0) {
299
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
300
- TokenHandler tokenHandler = poolInfo.tokenHandler;
301
- address bundleOwner = getRegistry().ownerOf(bundleNftId);
302
- Fee memory stakingFee = poolInfo.stakingFee;
303
-
304
- tokenHandler.transfer(
305
- bundleOwner,
306
- poolInfo.wallet,
307
- stakingAmount
308
- );
309
-
310
-
311
- if (! FeeLib.feeIsZero(stakingFee)) {
312
- (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
313
- // TODO: track staking fees in pool's state (issue #177)
314
- }
315
- }
316
- }
317
145
  }
@@ -6,7 +6,7 @@ import {ProxyManager} from "../../shared/ProxyManager.sol";
6
6
  import {PoolService} from "./PoolService.sol";
7
7
  import {Registry} from "../../registry/Registry.sol";
8
8
  import {RegistryService} from "../../registry/RegistryService.sol";
9
- import {VersionLib} from "../../types/Version.sol";
9
+ import {REGISTRY} from "../../types/ObjectType.sol";
10
10
 
11
11
  contract PoolServiceManager is ProxyManager {
12
12
 
@@ -26,10 +26,10 @@ contract PoolServiceManager is ProxyManager {
26
26
 
27
27
  _poolService = PoolService(address(versionable));
28
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
29
+ // TODO `this` must have a role or own nft to register service
30
+ //Registry registry = Registry(registryAddress);
31
+ //address registryServiceAddress = registry.getServiceAddress(REGISTRY(), _poolService.getMajorVersion());
32
+ //RegistryService registryService = RegistryService(registryServiceAddress);
33
33
  //registryService.registerService(_poolService);
34
34
 
35
35
  // TODO no nft to link yet
@@ -37,9 +37,6 @@ contract PoolServiceManager is ProxyManager {
37
37
  //_linkToNftOwnable(
38
38
  // address(registryAddress),
39
39
  // address(_poolService));
40
-
41
- // implies that after this constructor call only upgrade functionality is available
42
- _isDeployed = true;
43
40
  }
44
41
 
45
42
  //--- view functions ----------------------------------------------------//
@@ -23,7 +23,7 @@ import {Versionable} from "../../shared/Versionable.sol";
23
23
  import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
24
24
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
25
25
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
26
- import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
26
+ import {ObjectType, PRODUCT, POOL, POLICY} from "../../types/ObjectType.sol";
27
27
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
28
28
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
29
29
  import {Fee, FeeLib} from "../../types/Fee.sol";
@@ -39,16 +39,11 @@ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
39
39
  import {IProductService} from "./IProductService.sol";
40
40
  import {InstanceReader} from "../InstanceReader.sol";
41
41
  import {IPoolService} from "./PoolService.sol";
42
- import {POOL_SERVICE_NAME} from "./PoolService.sol";
43
-
44
- string constant PRODUCT_SERVICE_NAME = "ProductService";
45
42
 
46
43
  // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
47
44
  contract ProductService is ComponentServiceBase, IProductService {
48
45
  using NftIdLib for NftId;
49
46
 
50
- string public constant NAME = "ProductService";
51
-
52
47
  IPoolService internal _poolService;
53
48
 
54
49
  event LogProductServiceSender(address sender);
@@ -67,14 +62,14 @@ contract ProductService is ComponentServiceBase, IProductService {
67
62
 
68
63
  _initializeService(registryAddress, owner);
69
64
 
70
- _poolService = IPoolService(_registry.getServiceAddress(POOL_SERVICE_NAME, getMajorVersion()));
65
+ _poolService = IPoolService(_registry.getServiceAddress(POOL(), getMajorVersion()));
71
66
 
72
67
  _registerInterface(type(IProductService).interfaceId);
73
68
  }
74
69
 
75
70
 
76
- function getName() public pure override(IService, Service) returns(string memory name) {
77
- return NAME;
71
+ function getDomain() public pure override(IService, Service) returns(ObjectType) {
72
+ return PRODUCT();
78
73
  }
79
74
 
80
75
  function register(address productAddress)
@@ -88,7 +83,8 @@ contract ProductService is ComponentServiceBase, IProductService {
88
83
  bytes memory data;
89
84
  (info, data) = getRegistryService().registerProduct(product, productOwner);
90
85
 
91
- IInstance instance = _getInstance(info);
86
+ NftId instanceNftId = info.parentNftId;
87
+ IInstance instance = _getInstance(instanceNftId);
92
88
  bool hasRole = getInstanceService().hasRole(
93
89
  productOwner,
94
90
  PRODUCT_OWNER_ROLE(),
@@ -99,18 +95,62 @@ contract ProductService is ComponentServiceBase, IProductService {
99
95
  }
100
96
 
101
97
  productNftId = info.nftId;
102
- ISetup.ProductSetupInfo memory initialSetup = _decodeAndVerifyProductSetup(data);
98
+ string memory productName;
99
+ ISetup.ProductSetupInfo memory initialSetup;
100
+ (productName, initialSetup) = _decodeAndVerifyProductData(data);
101
+
103
102
  instance.createProductSetup(productNftId, initialSetup);
103
+
104
+ getInstanceService().createTarget(instanceNftId, productAddress, productName);
105
+
106
+ product.linkToRegisteredNftId();
104
107
  }
105
108
 
106
- function _decodeAndVerifyProductSetup(bytes memory data) internal returns(ISetup.ProductSetupInfo memory setup)
109
+ function _decodeAndVerifyProductData(bytes memory data)
110
+ internal
111
+ returns(string memory name, ISetup.ProductSetupInfo memory setup)
107
112
  {
108
- setup = abi.decode(
113
+ (name, setup) = abi.decode(
109
114
  data,
110
- (ISetup.ProductSetupInfo)
115
+ (string, ISetup.ProductSetupInfo)
111
116
  );
112
117
 
113
- // TODO add checks if applicable
118
+ // TODO add checks
119
+ // if(wallet == address(0)) {
120
+ // revert WalletIsZero();
121
+ // }
122
+
123
+ // IRegistry.ObjectInfo memory tokenInfo = _registry.getObjectInfo(address(info.token));
124
+
125
+ // if(tokenInfo.objectType != TOKEN()) {
126
+ // revert InvalidToken();
127
+ // }
128
+
129
+ // IRegistry.ObjectInfo memory poolInfo = _registry.getObjectInfo(info.poolNftId);
130
+
131
+ // if(poolInfo.objectType != POOL()) {
132
+ // revert InvalidPool();
133
+ // }
134
+
135
+ // if(poolInfo.parentNftId != instanceNftId) {
136
+ // revert InvalidPoolsInstance();
137
+ // }
138
+ // // TODO pool have the same token
139
+ // //ITreasury.PoolSetup memory poolSetup = instance.getPoolSetup(info.poolNftId);
140
+ // //require(tokenInfo.objectAddress == address(poolSetup.token), "ERROR:COS-018:PRODUCT_POOL_TOKEN_MISMATCH");
141
+ // // TODO pool is not linked
142
+
143
+ // IRegistry.ObjectInfo memory distributionInfo = _registry.getObjectInfo(info.distributionNftId);
144
+
145
+ // if(distributionInfo.objectType != DISTRIBUTION()) {
146
+ // revert InvalidDistribution();
147
+ // }
148
+
149
+ // if(distributionInfo.parentNftId != instanceNftId) {
150
+ // revert InvalidDistributionsInstance();
151
+ // }
152
+ // // TODO distribution have the same token
153
+ // // TODO distribution is not linked
114
154
  }
115
155
 
116
156
  function setFees(
@@ -59,7 +59,7 @@ contract ChainNft is ERC721Enumerable {
59
59
  }
60
60
 
61
61
  _chainIdMultiplier = 10 ** _chainIdDigits;
62
- _idNext = 4;
62
+ _idNext = 3;
63
63
  }
64
64
 
65
65
  /**