@etherisc/gif-next 0.0.2-fb8d07b-779 → 0.0.2-fbe8e04-715

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. package/README.md +63 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +126 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +136 -10
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +88 -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 +168 -11
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +144 -64
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  36. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  37. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  38. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +788 -0
  40. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  41. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  42. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  44. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +981 -10
  45. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  46. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
  47. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  48. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +6 -1
  49. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  50. package/artifacts/contracts/instance/Instance.sol/Instance.json +169 -139
  51. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +55 -32
  53. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  54. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
  55. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  56. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +74 -40
  57. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +223 -75
  59. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +92 -32
  61. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +285 -0
  63. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +0 -19
  65. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  66. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  78. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +923 -0
  79. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +440 -0
  81. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +16 -16
  83. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +16 -48
  85. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +13 -33
  87. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +669 -0
  89. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  92. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +664 -0
  93. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +9 -71
  95. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +17 -232
  97. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  98. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +984 -0
  99. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +464 -0
  101. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  102. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +20 -157
  103. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +13 -45
  105. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +4 -0
  106. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +768 -0
  107. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +4 -0
  108. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +420 -0
  109. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  110. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  111. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +2 -110
  112. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  113. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +94 -0
  114. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  115. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  116. package/artifacts/contracts/registry/Registry.sol/Registry.json +35 -146
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  118. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +76 -20
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  120. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +26 -34
  121. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +12 -12
  123. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  124. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  125. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  131. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  132. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  133. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  134. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  135. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  137. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  138. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  139. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  140. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  141. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +4 -4
  143. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  145. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestService.sol/TestService.json +9 -9
  147. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  150. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  151. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  152. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  157. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  159. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  160. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  166. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  172. package/contracts/components/BaseComponent.sol +49 -8
  173. package/contracts/components/Distribution.sol +6 -3
  174. package/contracts/components/IBaseComponent.sol +6 -0
  175. package/contracts/components/IPoolComponent.sol +5 -1
  176. package/contracts/components/Pool.sol +40 -12
  177. package/contracts/components/Product.sol +41 -46
  178. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  179. package/contracts/instance/BundleManager.sol +129 -0
  180. package/contracts/instance/Cloneable.sol +46 -0
  181. package/contracts/instance/IInstance.sol +25 -4
  182. package/contracts/instance/IInstanceBase.sol +26 -0
  183. package/contracts/instance/IInstanceService.sol +5 -3
  184. package/contracts/instance/Instance.sol +40 -18
  185. package/contracts/instance/InstanceAccessManager.sol +6 -6
  186. package/contracts/instance/InstanceBase.sol +41 -0
  187. package/contracts/instance/InstanceReader.sol +9 -0
  188. package/contracts/instance/InstanceService.sol +116 -37
  189. package/contracts/instance/InstanceServiceManager.sol +6 -5
  190. package/contracts/instance/ObjectManager.sol +101 -0
  191. package/contracts/instance/base/ComponentServiceBase.sol +22 -75
  192. package/contracts/instance/module/ISetup.sol +3 -1
  193. package/contracts/instance/service/BundleService.sol +260 -0
  194. package/contracts/instance/service/BundleServiceManager.sol +54 -0
  195. package/contracts/instance/service/DistributionService.sol +40 -9
  196. package/contracts/instance/service/DistributionServiceManager.sol +6 -5
  197. package/contracts/instance/service/IBundleService.sol +45 -0
  198. package/contracts/instance/service/IPolicyService.sol +87 -0
  199. package/contracts/instance/service/IPoolService.sol +6 -23
  200. package/contracts/instance/service/IProductService.sol +6 -73
  201. package/contracts/instance/service/PolicyService.sol +508 -0
  202. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  203. package/contracts/instance/service/PoolService.sol +44 -113
  204. package/contracts/instance/service/PoolServiceManager.sol +6 -5
  205. package/contracts/instance/service/ProductService.sol +173 -0
  206. package/contracts/instance/service/ProductServiceManager.sol +54 -0
  207. package/contracts/registry/IRegistry.sol +5 -18
  208. package/contracts/registry/IRegistryService.sol +28 -11
  209. package/contracts/registry/Registry.sol +4 -45
  210. package/contracts/registry/RegistryService.sol +30 -71
  211. package/contracts/shared/NftOwnable.sol +2 -4
  212. package/contracts/types/NftIdSet.sol +26 -24
  213. package/contracts/types/RoleId.sol +3 -0
  214. package/package.json +1 -1
  215. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  216. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  217. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  218. package/contracts/instance/AccessManagedSimple.sol +0 -115
  219. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -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";
@@ -19,87 +20,36 @@ abstract contract ComponentServiceBase is Service {
19
20
  error ExpectedRoleMissing(RoleId expected, address caller);
20
21
  error ComponentTypeInvalid(ObjectType componentType);
21
22
 
22
- mapping (ObjectType => RoleId) internal _objectTypeToExpectedRole;
23
23
 
24
- /// @dev modifier to check if caller has a role on the instance the component is registered in
25
- modifier onlyComponentOwnerRole(address componentAddress) {
26
- BaseComponent component = BaseComponent(componentAddress);
27
- ObjectType objectType = _getObjectType(component);
28
- RoleId expectedRole = _objectTypeToExpectedRole[objectType];
29
-
30
- address componentOwner = msg.sender;
31
- INftOwnable nftOwnable = INftOwnable(address(component.getInstance()));
32
- if(! getInstanceService().hasRole(componentOwner, expectedRole, nftOwnable.getNftId())) {
33
- revert ExpectedRoleMissing(expectedRole, componentOwner);
34
- }
24
+ /// @dev modifier to check if caller is a registered service
25
+ modifier onlyService() {
26
+ address caller = msg.sender;
27
+ require(getRegistry().isRegisteredService(caller), "ERROR_NOT_SERVICE");
35
28
  _;
36
29
  }
37
30
 
38
- function _initializeService(
39
- address registry,
40
- address initialOwner
41
- )
42
- internal
43
- override
44
- {
45
- super._initializeService(registry, initialOwner);
46
- _objectTypeToExpectedRole[PRODUCT()] = PRODUCT_OWNER_ROLE();
47
- _objectTypeToExpectedRole[POOL()] = POOL_OWNER_ROLE();
48
- _objectTypeToExpectedRole[DISTRIBUTION()] = DISTRIBUTION_OWNER_ROLE();
49
- _objectTypeToExpectedRole[ORACLE()] = ORACLE_OWNER_ROLE();
31
+ // view functions
32
+
33
+ function getRegistryService() public view virtual returns (IRegistryService) {
34
+ address service = getRegistry().getServiceAddress("RegistryService", getMajorVersion());
35
+ return IRegistryService(service);
50
36
  }
51
37
 
52
38
  function getInstanceService() public view returns (InstanceService) {
53
39
  return InstanceService(getRegistry().getServiceAddress("InstanceService", getMajorVersion()));
54
40
  }
55
41
 
56
- function register(address componentAddress)
57
- external
58
- onlyComponentOwnerRole(componentAddress)
59
- returns (NftId componentNftId)
60
- {
61
- address componentOwner = msg.sender;
62
- BaseComponent component = BaseComponent(componentAddress);
63
- ObjectType objectType = _getObjectType(component);
64
- IRegistryService registryService = getRegistryService();
65
-
66
- IRegistry.ObjectInfo memory objInfo;
67
- bytes memory initialObjData;
68
-
69
- if (objectType == DISTRIBUTION()) {
70
- (objInfo, initialObjData) = registryService.registerDistribution(component, componentOwner);
71
- } else if (objectType == PRODUCT()) {
72
- (objInfo, initialObjData) = registryService.registerProduct(component, componentOwner);
73
- } else if (objectType == POOL()) {
74
- (objInfo, initialObjData) = registryService.registerPool(component, componentOwner);
75
- // TODO: implement this for oracle - currently missing in registry
76
- // } else if (objectType == ORACLE()) {
77
- // (objInfo, initialObjData) = registryService.registerOracle(component, componentOwner);
78
- } else {
79
- revert ComponentTypeInvalid(objectType);
80
- }
42
+ // internal view functions
81
43
 
82
- componentNftId = objInfo.nftId;
83
- IInstance instance = _getInstanceFromComponentNft(componentNftId);
84
- _finalizeComponentRegistration(componentNftId, initialObjData, instance);
85
- }
86
-
87
- function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal virtual;
88
-
89
- function _getObjectType(BaseComponent component) internal view returns (ObjectType) {
90
- (IRegistry.ObjectInfo memory compInitialInfo, ) = component.getInitialInfo();
91
- return compInitialInfo.objectType;
92
- }
93
-
94
- function _getInstanceFromComponentNft(NftId componentNftId) internal view returns (IInstance) {
44
+ function _getInstance(IRegistry.ObjectInfo memory compObjInfo) internal view returns (IInstance) {
95
45
  IRegistry registry = getRegistry();
96
- IRegistry.ObjectInfo memory compInfo = registry.getObjectInfo(componentNftId);
97
- IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compInfo.parentNftId);
46
+ IRegistry.ObjectInfo memory instanceInfo = registry.getObjectInfo(compObjInfo.parentNftId);
98
47
  return IInstance(instanceInfo.objectAddress);
99
48
  }
100
49
 
101
50
  function _getAndVerifyComponentInfoAndInstance(
102
- ObjectType objectType
51
+ //address component,
52
+ ObjectType expectedType
103
53
  )
104
54
  internal
105
55
  view
@@ -108,18 +58,15 @@ abstract contract ComponentServiceBase is Service {
108
58
  IInstance instance
109
59
  )
110
60
  {
111
- NftId componentNftId = _registry.getNftId(msg.sender);
112
- require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
61
+ IRegistry registry = getRegistry();
62
+ //TODO redundant check -> just check type
63
+ //NftId componentNftId = registry.getNftId(component);
64
+ //require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
113
65
 
114
- info = getRegistry().getObjectInfo(componentNftId);
115
- require(info.objectType == objectType, "OBJECT_TYPE_INVALID");
66
+ info = registry.getObjectInfo(msg.sender);
67
+ require(info.objectType == expectedType, "OBJECT_TYPE_INVALID");
116
68
 
117
- address instanceAddress = getRegistry().getObjectInfo(info.parentNftId).objectAddress;
69
+ address instanceAddress = registry.getObjectInfo(info.parentNftId).objectAddress;
118
70
  instance = IInstance(instanceAddress);
119
71
  }
120
-
121
- function getRegistryService() public view virtual returns (IRegistryService) {
122
- address service = getRegistry().getServiceAddress("RegistryService", getMajorVersion());
123
- return IRegistryService(service);
124
- }
125
72
  }
@@ -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
  }
@@ -0,0 +1,260 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {Pool} from "../../components/Pool.sol";
5
+ import {IRegistry} from "../../registry/IRegistry.sol";
6
+ import {IInstance} from "../../instance/IInstance.sol";
7
+ import {IBundle} from "../../instance/module/IBundle.sol";
8
+ import {TokenHandler} from "../../instance/module/ITreasury.sol";
9
+ import {ISetup} from "../module/ISetup.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
11
+
12
+ import {IVersionable} from "../../shared/IVersionable.sol";
13
+ import {Versionable} from "../../shared/Versionable.sol";
14
+ import {INftOwnable} from "../../shared/INftOwnable.sol";
15
+
16
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
17
+ import {POOL, BUNDLE} from "../../types/ObjectType.sol";
18
+ import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
19
+ import {Fee, FeeLib} from "../../types/Fee.sol";
20
+ import {Version, VersionLib} from "../../types/Version.sol";
21
+ import {KEEP_STATE, StateId} from "../../types/StateId.sol";
22
+ import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
23
+
24
+ import {IService} from "../../shared/IService.sol";
25
+ import {Service} from "../../shared/Service.sol";
26
+ import {BundleManager} from "../BundleManager.sol";
27
+ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
28
+ import {IBundleService} from "./IBundleService.sol";
29
+ import {IRegistryService} from "../../registry/IRegistryService.sol";
30
+ import {InstanceService} from "../InstanceService.sol";
31
+ import {InstanceReader} from "../InstanceReader.sol";
32
+ import {IBaseComponent} from "../../components/IBaseComponent.sol";
33
+
34
+ string constant BUNDLE_SERVICE_NAME = "BundleService";
35
+
36
+ contract BundleService is
37
+ ComponentServiceBase,
38
+ IBundleService
39
+ {
40
+ using NftIdLib for NftId;
41
+
42
+ string public constant NAME = "BundleService";
43
+
44
+ address internal _registryAddress;
45
+
46
+ function _initialize(
47
+ address owner,
48
+ bytes memory data
49
+ )
50
+ internal
51
+ initializer
52
+ virtual override
53
+ {
54
+ address registryAddress;
55
+ address initialOwner;
56
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
57
+ // TODO while PoolService is not deployed in PoolServiceManager constructor
58
+ // owner is PoolServiceManager deployer
59
+ _initializeService(registryAddress, owner);
60
+
61
+ _registerInterface(type(IBundleService).interfaceId);
62
+ }
63
+
64
+ function getName() public pure override(Service, IService) returns(string memory name) {
65
+ return NAME;
66
+ }
67
+
68
+ function createBundle(
69
+ address owner,
70
+ Fee memory fee,
71
+ uint256 stakingAmount,
72
+ uint256 lifetime,
73
+ bytes calldata filter
74
+ )
75
+ external
76
+ override
77
+ returns(NftId bundleNftId)
78
+ {
79
+ (IRegistry.ObjectInfo memory info, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
80
+ InstanceReader instanceReader = instance.getInstanceReader();
81
+ NftId poolNftId = info.nftId;
82
+
83
+ IBundle.BundleInfo memory bundleInfo = IBundle.BundleInfo(
84
+ poolNftId,
85
+ fee,
86
+ filter,
87
+ stakingAmount,
88
+ 0,
89
+ stakingAmount,
90
+ lifetime,
91
+ zeroTimestamp(),
92
+ zeroTimestamp()
93
+ );
94
+
95
+ // register bundle with registry
96
+ bundleNftId = getRegistryService().registerBundle(
97
+ IRegistry.ObjectInfo(
98
+ zeroNftId(),
99
+ poolNftId,
100
+ BUNDLE(),
101
+ false, // intercepting property for bundles is defined on pool
102
+ address(0),
103
+ owner,
104
+ abi.encode(bundleInfo)
105
+ )
106
+ );
107
+
108
+ // create bundle info in instance
109
+ instance.createBundle(bundleNftId, bundleInfo);
110
+
111
+ BundleManager bundleManager = instance.getBundleManager();
112
+ bundleManager.add(bundleNftId);
113
+
114
+ _processStakingByTreasury(
115
+ instanceReader,
116
+ poolNftId,
117
+ bundleNftId,
118
+ stakingAmount);
119
+
120
+ // TODO add logging
121
+ }
122
+
123
+ function setBundleFee(
124
+ NftId bundleNftId,
125
+ Fee memory fee
126
+ )
127
+ external
128
+ override
129
+ {
130
+ (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
131
+ InstanceReader instanceReader = instance.getInstanceReader();
132
+ NftId poolNftId = info.nftId;
133
+
134
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
135
+ require(bundleInfo.poolNftId.gtz(), "ERROR:PLS-010:BUNDLE_UNKNOWN");
136
+ require(poolNftId == bundleInfo.poolNftId, "ERROR:PLS-011:BUNDLE_POOL_MISMATCH");
137
+
138
+ bundleInfo.fee = fee;
139
+
140
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
141
+ }
142
+
143
+ function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state)
144
+ external
145
+ onlyService
146
+ {
147
+ IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
148
+ IInstance instance = IInstance(instanceInfo.objectAddress);
149
+ instance.updateBundle(bundleNftId, bundleInfo, state);
150
+ }
151
+
152
+ function lockBundle(NftId bundleNftId)
153
+ external
154
+ {
155
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
156
+ BundleManager bundleManager = instance.getBundleManager();
157
+ bundleManager.lock(bundleNftId);
158
+ }
159
+
160
+ function unlockBundle(NftId bundleNftId)
161
+ external
162
+ {
163
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
164
+ BundleManager bundleManager = instance.getBundleManager();
165
+ bundleManager.unlock(bundleNftId);
166
+ }
167
+
168
+ function underwritePolicy(IInstance instance,
169
+ NftId policyNftId,
170
+ NftId bundleNftId,
171
+ uint256 collateralAmount,
172
+ uint256 netPremiumAmount
173
+ )
174
+ external
175
+ onlyService
176
+ {
177
+ InstanceReader instanceReader = instance.getInstanceReader();
178
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
179
+
180
+ // lock collateral
181
+ bundleInfo.lockedAmount += collateralAmount;
182
+ bundleInfo.balanceAmount += netPremiumAmount;
183
+
184
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
185
+
186
+ linkPolicy(instance, policyNftId);
187
+ }
188
+
189
+ /// @dev links policy to bundle
190
+ function linkPolicy(IInstance instance, NftId policyNftId)
191
+ internal
192
+ onlyService
193
+ {
194
+ InstanceReader instanceReader = instance.getInstanceReader();
195
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
196
+
197
+ // ensure policy has not yet been activated
198
+ if (policyInfo.activatedAt.gtz()) {
199
+ revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
200
+ }
201
+
202
+ BundleManager bundleManager = instance.getBundleManager();
203
+ bundleManager.linkPolicy(policyNftId);
204
+ }
205
+
206
+ /// @dev unlinks policy from bundle
207
+ function unlinkPolicy(IInstance instance, NftId policyNftId)
208
+ internal
209
+ onlyService
210
+ {
211
+ InstanceReader instanceReader = instance.getInstanceReader();
212
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
213
+
214
+ // ensure policy has no open claims
215
+ if (policyInfo.openClaimsCount > 0) {
216
+ revert BundleManager.ErrorBundleManagerPolicyWithOpenClaims(
217
+ policyNftId,
218
+ policyInfo.openClaimsCount);
219
+ }
220
+
221
+ // ensure policy is closeable
222
+ if (policyInfo.expiredAt < TimestampLib.blockTimestamp()
223
+ || policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
224
+ {
225
+ revert BundleManager.ErrorBundleManagerPolicyNotCloseable(policyNftId);
226
+ }
227
+
228
+ BundleManager bundleManager = instance.getBundleManager();
229
+ bundleManager.unlinkPolicy(policyNftId);
230
+ }
231
+
232
+ function _processStakingByTreasury(
233
+ InstanceReader instanceReader,
234
+ NftId poolNftId,
235
+ NftId bundleNftId,
236
+ uint256 stakingAmount
237
+ )
238
+ internal
239
+ {
240
+ // process token transfer(s)
241
+ if(stakingAmount > 0) {
242
+ ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
243
+ TokenHandler tokenHandler = poolInfo.tokenHandler;
244
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
245
+ Fee memory stakingFee = poolInfo.stakingFee;
246
+
247
+ tokenHandler.transfer(
248
+ bundleOwner,
249
+ poolInfo.wallet,
250
+ stakingAmount
251
+ );
252
+
253
+
254
+ if (! FeeLib.feeIsZero(stakingFee)) {
255
+ (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
256
+ // TODO: track staking fees in pool's state (issue #177)
257
+ }
258
+ }
259
+ }
260
+ }
@@ -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 {BundleService} from "./BundleService.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 BundleServiceManager is ProxyManager {
12
+
13
+ BundleService private _bundleService;
14
+
15
+ /// @dev initializes proxy manager with pool service implementation
16
+ constructor(
17
+ address registryAddress
18
+ )
19
+ ProxyManager()
20
+ {
21
+ BundleService bundleSrv = new BundleService();
22
+ bytes memory data = abi.encode(registryAddress, address(this));
23
+ IVersionable versionable = deploy(
24
+ address(bundleSrv),
25
+ data);
26
+
27
+ _bundleService = BundleService(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(_poolService);
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(_poolService));
40
+
41
+ // implies that after this constructor call only upgrade functionality is available
42
+ _isDeployed = true;
43
+ }
44
+
45
+ //--- view functions ----------------------------------------------------//
46
+ function getBundleService()
47
+ external
48
+ view
49
+ returns (BundleService)
50
+ {
51
+ return _bundleService;
52
+ }
53
+
54
+ }
@@ -26,6 +26,7 @@ import {Distribution} from "../../components/Distribution.sol";
26
26
  import {InstanceService} from "../InstanceService.sol";
27
27
  import {Instance} from "../Instance.sol";
28
28
  import {INftOwnable} from "../../shared/INftOwnable.sol";
29
+ import {IBaseComponent} from "../../components/IBaseComponent.sol";
29
30
 
30
31
  string constant DISTRIBUTION_SERVICE_NAME = "DistributionService";
31
32
 
@@ -47,12 +48,13 @@ contract DistributionService is
47
48
  initializer
48
49
  virtual override
49
50
  {
50
- address initialOwner = address(0);
51
- (_registryAddress, initialOwner) = abi.decode(data, (address, address));
51
+ address initialOwner;
52
+ address registryAddress;
53
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
54
+ // TODO while DistributionService is not deployed in DistributionServiceManager constructor
55
+ // owner is DistributionServiceManager deployer
56
+ _initializeService(registryAddress, owner);
52
57
 
53
- _initializeService(_registryAddress, initialOwner);
54
-
55
- _registerInterface(type(IService).interfaceId);
56
58
  _registerInterface(type(IDistributionService).interfaceId);
57
59
  }
58
60
 
@@ -61,12 +63,41 @@ contract DistributionService is
61
63
  return NAME;
62
64
  }
63
65
 
64
- function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
65
- ISetup.DistributionSetupInfo memory initialSetup = abi.decode(
66
- initialObjData,
66
+ function register(address distributionAddress)
67
+ external
68
+ returns(NftId distributionNftId)
69
+ {
70
+ address distributionOwner = msg.sender;
71
+ IBaseComponent distribution = IBaseComponent(distributionAddress);
72
+
73
+ IRegistry.ObjectInfo memory info;
74
+ bytes memory data;
75
+ (info, data) = getRegistryService().registerDistribution(distribution, distributionOwner);
76
+
77
+ IInstance instance = _getInstance(info);
78
+
79
+ bool hasRole = getInstanceService().hasRole(
80
+ distributionOwner,
81
+ DISTRIBUTION_OWNER_ROLE(),
82
+ address(instance));
83
+
84
+ if(!hasRole) {
85
+ revert ExpectedRoleMissing(DISTRIBUTION_OWNER_ROLE(), distributionOwner);
86
+ }
87
+
88
+ distributionNftId = info.nftId;
89
+ ISetup.DistributionSetupInfo memory initialSetup = _decodeAndVerifyDistributionSetup(data);
90
+ instance.createDistributionSetup(distributionNftId, initialSetup);
91
+ }
92
+
93
+ function _decodeAndVerifyDistributionSetup(bytes memory data) internal returns(ISetup.DistributionSetupInfo memory setup)
94
+ {
95
+ setup = abi.decode(
96
+ data,
67
97
  (ISetup.DistributionSetupInfo)
68
98
  );
69
- instance.createDistributionSetup(componentNftId, initialSetup);
99
+
100
+ // TODO add checks if applicable
70
101
  }
71
102
 
72
103
  function setFees(
@@ -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;
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {NftId} from "../../types/NftId.sol";
5
+ import {Fee} from "../../types/Fee.sol";
6
+ import {StateId} from "../../types/StateId.sol";
7
+ import {IService} from "../../shared/IService.sol";
8
+ import {IBundle} from "../module/IBundle.sol";
9
+ import {IInstance} from "../../instance/IInstance.sol";
10
+
11
+ interface IBundleService is IService {
12
+ error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
13
+
14
+ function createBundle(
15
+ address owner,
16
+ Fee memory fee,
17
+ uint256 amount,
18
+ uint256 lifetime,
19
+ bytes calldata filter
20
+ ) external returns(NftId bundleNftId);
21
+
22
+ function setBundleFee(
23
+ NftId bundleNftId,
24
+ Fee memory fee
25
+ ) external;
26
+
27
+ function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
28
+
29
+ function underwritePolicy(IInstance instanceNftId,
30
+ NftId policyNftId,
31
+ NftId bundleNftId,
32
+ uint256 collateralAmount,
33
+ uint256 netPremium
34
+ ) external;
35
+
36
+ // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
37
+
38
+ // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
39
+
40
+ function lockBundle(NftId bundleNftId) external;
41
+
42
+ function unlockBundle(NftId bundleNftId) external;
43
+
44
+ // function closeBundle(NftId bundleNftId) external;
45
+ }