@etherisc/gif-next 0.0.2-d64ea51-772 → 0.0.2-d81820a-051

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) 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 +139 -8
  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/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  37. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  38. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +775 -0
  40. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  41. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +185 -0
  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 +33 -0
  45. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  46. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +5 -0
  47. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  48. package/artifacts/contracts/instance/Instance.sol/Instance.json +120 -74
  49. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  50. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  51. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +38 -28
  53. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +98 -59
  55. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  56. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +34 -30
  57. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  58. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  59. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  62. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  63. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  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/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
  74. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +2 -2
  76. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +2 -2
  78. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  80. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +80 -0
  82. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +151 -28
  85. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +31 -15
  87. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +34 -34
  89. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +18 -18
  91. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  93. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  94. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  95. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  96. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  97. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  98. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  100. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  101. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  102. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  103. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  104. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  106. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  107. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  109. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  110. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  111. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  112. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  113. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  114. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  115. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  116. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  117. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  118. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  119. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  120. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  122. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  123. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  124. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  125. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  126. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  127. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  128. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  129. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  131. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  132. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  133. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  136. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  143. package/contracts/components/BaseComponent.sol +46 -8
  144. package/contracts/components/IBaseComponent.sol +6 -0
  145. package/contracts/components/IPoolComponent.sol +5 -1
  146. package/contracts/components/Pool.sol +27 -6
  147. package/contracts/components/Product.sol +1 -0
  148. package/contracts/instance/BundleManager.sol +129 -0
  149. package/contracts/instance/Cloneable.sol +46 -0
  150. package/contracts/instance/IInstance.sol +2 -0
  151. package/contracts/instance/IInstanceService.sol +3 -1
  152. package/contracts/instance/Instance.sol +11 -0
  153. package/contracts/instance/InstanceService.sol +43 -9
  154. package/contracts/instance/ObjectManager.sol +95 -0
  155. package/contracts/instance/module/ISetup.sol +2 -1
  156. package/contracts/instance/service/IPoolService.sol +12 -2
  157. package/contracts/instance/service/PoolService.sol +100 -14
  158. package/contracts/instance/service/ProductService.sol +18 -11
  159. package/contracts/types/NftIdSet.sol +26 -24
  160. package/package.json +1 -1
@@ -13,6 +13,7 @@ import {IBaseComponent} from "../components/IBaseComponent.sol";
13
13
  import {AccessManagerSimple} from "./AccessManagerSimple.sol";
14
14
  import {Instance} from "./Instance.sol";
15
15
  import {InstanceReader} from "./InstanceReader.sol";
16
+ import {BundleManager} from "./BundleManager.sol";
16
17
 
17
18
  interface IInstanceService is IService {
18
19
 
@@ -24,7 +25,8 @@ interface IInstanceService is IService {
24
25
  AccessManagerSimple clonedAccessManager,
25
26
  Instance clonedInstance,
26
27
  NftId instanceNftId,
27
- InstanceReader clonedInstanceReader
28
+ InstanceReader clonedInstanceReader,
29
+ BundleManager clonedBundleManager
28
30
  );
29
31
  }
30
32
 
@@ -15,6 +15,7 @@ import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
15
15
  import {KeyValueStore} from "./base/KeyValueStore.sol";
16
16
  import {IInstance} from "./IInstance.sol";
17
17
  import {InstanceReader} from "./InstanceReader.sol";
18
+ import {BundleManager} from "./BundleManager.sol";
18
19
  import {NftId} from "../types/NftId.sol";
19
20
  import {NumberId} from "../types/NumberId.sol";
20
21
  import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
@@ -54,6 +55,7 @@ contract Instance is
54
55
 
55
56
  AccessManagerSimple internal _accessManager;
56
57
  InstanceReader internal _instanceReader;
58
+ BundleManager internal _bundleManager;
57
59
 
58
60
  constructor(address accessManagerAddress, address registryAddress, NftId registryNftId)
59
61
  {
@@ -440,4 +442,13 @@ contract Instance is
440
442
  function getInstanceReader() external view returns (InstanceReader) {
441
443
  return _instanceReader;
442
444
  }
445
+
446
+ function setBundleManager(BundleManager bundleManager) external restricted() {
447
+ require(address(_bundleManager) == address(0), "BundleManager is set");
448
+ _bundleManager = bundleManager;
449
+ }
450
+
451
+ function getBundleManager() external view returns (BundleManager) {
452
+ return _bundleManager;
453
+ }
443
454
  }
@@ -8,6 +8,7 @@ import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
8
  import {Instance} from "./Instance.sol";
9
9
  import {IInstanceService} from "./IInstanceService.sol";
10
10
  import {InstanceReader} from "./InstanceReader.sol";
11
+ import {BundleManager} from "./BundleManager.sol";
11
12
  import {IRegistry} from "../registry/IRegistry.sol";
12
13
  import {Registry} from "../registry/Registry.sol";
13
14
  import {RegistryService} from "../registry/RegistryService.sol";
@@ -25,6 +26,7 @@ contract InstanceService is Service, IInstanceService {
25
26
  address internal _accessManagerMaster;
26
27
  address internal _instanceMaster;
27
28
  address internal _instanceReaderMaster;
29
+ address internal _instanceBundleManagerMaster;
28
30
 
29
31
  // TODO update to real hash when instance is stable
30
32
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
@@ -35,8 +37,9 @@ contract InstanceService is Service, IInstanceService {
35
37
  returns (
36
38
  AccessManagerSimple clonedAccessManager,
37
39
  Instance clonedInstance,
38
- NftId instanceNftId,
39
- InstanceReader clonedInstanceReader
40
+ NftId clonedInstanceNftId,
41
+ InstanceReader clonedInstanceReader,
42
+ BundleManager clonedBundleManager
40
43
  )
41
44
  {
42
45
  address instanceOwner = msg.sender;
@@ -54,24 +57,30 @@ contract InstanceService is Service, IInstanceService {
54
57
  clonedInstance = Instance(Clones.clone(_instanceMaster));
55
58
  clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
56
59
  ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
57
- instanceNftId = info.nftId;
60
+ clonedInstanceNftId = info.nftId;
58
61
 
59
62
  clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
60
- clonedInstanceReader.initialize(_registryAddress, instanceNftId);
63
+ clonedInstanceReader.initialize(_registryAddress, clonedInstanceNftId);
64
+ clonedInstance.setInstanceReader(clonedInstanceReader);
61
65
 
62
- _grantInitialAuthorizations(clonedAccessManager, clonedInstance);
66
+ clonedBundleManager = BundleManager(Clones.clone(_instanceBundleManagerMaster));
67
+ clonedBundleManager.initialize(address(clonedAccessManager), _registryAddress, clonedInstanceNftId);
68
+ clonedInstance.setBundleManager(clonedBundleManager);
69
+
70
+ // TODO amend setters with instance specific , policy manager ...
71
+
72
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
63
73
 
64
- clonedInstance.setInstanceReader(clonedInstanceReader);
65
-
66
74
  // to complete setup switch instance ownership to the instance owner
67
75
  // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
68
76
  clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
69
77
  clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
70
78
 
71
- emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
79
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
72
80
  }
73
81
 
74
- function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance) internal {
82
+ function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
83
+ // configure authorization for distribution service on instance
75
84
  address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
76
85
  clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
77
86
  bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
@@ -82,6 +91,7 @@ contract InstanceService is Service, IInstanceService {
82
91
  instanceDistributionServiceSelectors,
83
92
  DISTRIBUTION_SERVICE_ROLE().toInt());
84
93
 
94
+ // configure authorization for pool service on instance
85
95
  address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
86
96
  clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
87
97
  bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
@@ -93,7 +103,20 @@ contract InstanceService is Service, IInstanceService {
93
103
  address(clonedInstance),
94
104
  instancePoolServiceSelectors,
95
105
  POOL_SERVICE_ROLE().toInt());
106
+
107
+ // configure authorization for pool service on bundle manager
108
+ bytes4[] memory bundleManagerPoolServiceSelectors = new bytes4[](5);
109
+ bundleManagerPoolServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
110
+ bundleManagerPoolServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
111
+ bundleManagerPoolServiceSelectors[2] = clonedBundleManager.add.selector;
112
+ bundleManagerPoolServiceSelectors[3] = clonedBundleManager.lock.selector;
113
+ bundleManagerPoolServiceSelectors[4] = clonedBundleManager.unlock.selector;
114
+ clonedAccessManager.setTargetFunctionRole(
115
+ address(clonedBundleManager),
116
+ bundleManagerPoolServiceSelectors,
117
+ POOL_SERVICE_ROLE().toInt());
96
118
 
119
+ // configure authorization for product service on instance
97
120
  address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
98
121
  clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE().toInt(), address(productServiceAddress), 0);
99
122
  bytes4[] memory instanceProductServiceSelectors = new bytes4[](9);
@@ -132,6 +155,13 @@ contract InstanceService is Service, IInstanceService {
132
155
  _instanceReaderMaster = instanceReaderMaster;
133
156
  }
134
157
 
158
+ function setBundleManagerMaster(address bundleManagerMaster) external {
159
+ require(
160
+ _instanceBundleManagerMaster == address(0),
161
+ "ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
162
+ _instanceBundleManagerMaster = bundleManagerMaster;
163
+ }
164
+
135
165
  function getInstanceReaderMaster() external view returns (address) {
136
166
  return _instanceReaderMaster;
137
167
  }
@@ -144,6 +174,10 @@ contract InstanceService is Service, IInstanceService {
144
174
  return _accessManagerMaster;
145
175
  }
146
176
 
177
+ function getBundleManagerMaster() external view returns (address) {
178
+ return _instanceBundleManagerMaster;
179
+ }
180
+
147
181
  // From IService
148
182
  function getName() public pure override(IService, Service) returns(string memory) {
149
183
  return NAME;
@@ -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
+ }
@@ -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,7 @@ 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
24
  address wallet;
25
25
  }
26
26
 
@@ -40,6 +40,7 @@ interface ISetup {
40
40
  Fee stakingFee; // pool fee on staked capital from investor
41
41
  Fee performanceFee; // pool fee on profits from capital investors
42
42
  bool isIntercepting; // intercepts nft transfers (for bundles)
43
+ bool isConfirmingApplication; // confirms applications before they are underwritten
43
44
  address wallet;
44
45
  }
45
46
  }
@@ -6,8 +6,11 @@ import {Fee} from "../../types/Fee.sol";
6
6
  import {StateId} from "../../types/StateId.sol";
7
7
  import {IService} from "../../shared/IService.sol";
8
8
  import {IBundle} from "../module/IBundle.sol";
9
+ import {IInstance} from "../../instance/IInstance.sol";
9
10
 
10
11
  interface IPoolService is IService {
12
+ error ErrorIPoolServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
13
+
11
14
  function setFees(
12
15
  Fee memory poolFee,
13
16
  Fee memory stakingFee,
@@ -29,13 +32,20 @@ interface IPoolService is IService {
29
32
 
30
33
  function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
31
34
 
35
+ function underwritePolicy(IInstance instanceNftId,
36
+ NftId policyNftId,
37
+ NftId bundleNftId,
38
+ uint256 collateralAmount,
39
+ uint256 netPremium
40
+ ) external;
41
+
32
42
  // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
33
43
 
34
44
  // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
35
45
 
36
- // function lockBundle(NftId bundleNftId) external;
46
+ function lockBundle(NftId bundleNftId) external;
37
47
 
38
- // function unlockBundle(NftId bundleNftId) external;
48
+ function unlockBundle(NftId bundleNftId) external;
39
49
 
40
50
  // function closeBundle(NftId bundleNftId) external;
41
51
  }
@@ -7,6 +7,7 @@ import {IInstance} from "../../instance/IInstance.sol";
7
7
  import {IBundle} from "../../instance/module/IBundle.sol";
8
8
  import {TokenHandler} from "../../instance/module/ITreasury.sol";
9
9
  import {ISetup} from "../module/ISetup.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
10
11
 
11
12
  import {IVersionable} from "../../shared/IVersionable.sol";
12
13
  import {Versionable} from "../../shared/Versionable.sol";
@@ -18,17 +19,17 @@ import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
18
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
19
20
  import {Version, VersionLib} from "../../types/Version.sol";
20
21
  import {KEEP_STATE, StateId} from "../../types/StateId.sol";
21
- import {zeroTimestamp} from "../../types/Timestamp.sol";
22
+ import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
22
23
 
23
24
  import {IService} from "../../shared/IService.sol";
24
25
  import {Service} from "../../shared/Service.sol";
26
+ import {BundleManager} from "../BundleManager.sol";
25
27
  import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
26
28
  import {IPoolService} from "./IPoolService.sol";
27
29
  import {IRegistryService} from "../../registry/IRegistryService.sol";
28
30
  import {InstanceService} from "../InstanceService.sol";
29
31
  import {InstanceReader} from "../InstanceReader.sol";
30
32
 
31
-
32
33
  string constant POOL_SERVICE_NAME = "PoolService";
33
34
 
34
35
  contract PoolService is
@@ -134,15 +135,14 @@ contract PoolService is
134
135
  // create bundle info in instance
135
136
  instance.createBundle(bundleNftId, bundleInfo);
136
137
 
137
- // TODO add bundle to pool in instance
138
+ BundleManager bundleManager = instance.getBundleManager();
139
+ bundleManager.add(bundleNftId);
138
140
 
139
- // TODO collect capital
140
- // _processStakingByTreasury(
141
- // instanceReader,
142
- // zeroNftId(),
143
- // poolNftId,
144
- // bundleNftId,
145
- // stakingAmount);
141
+ _processStakingByTreasury(
142
+ instanceReader,
143
+ poolNftId,
144
+ bundleNftId,
145
+ stakingAmount);
146
146
 
147
147
  // TODO add logging
148
148
  }
@@ -176,9 +176,88 @@ contract PoolService is
176
176
  instance.updateBundle(bundleNftId, bundleInfo, state);
177
177
  }
178
178
 
179
+ function lockBundle(NftId bundleNftId)
180
+ external
181
+ {
182
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
183
+ BundleManager bundleManager = instance.getBundleManager();
184
+ bundleManager.lock(bundleNftId);
185
+ }
186
+
187
+ function unlockBundle(NftId bundleNftId)
188
+ external
189
+ {
190
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
191
+ BundleManager bundleManager = instance.getBundleManager();
192
+ bundleManager.unlock(bundleNftId);
193
+ }
194
+
195
+ function underwritePolicy(IInstance instance,
196
+ NftId policyNftId,
197
+ NftId bundleNftId,
198
+ uint256 collateralAmount,
199
+ uint256 netPremiumAmount
200
+ )
201
+ external
202
+ onlyService
203
+ {
204
+ InstanceReader instanceReader = instance.getInstanceReader();
205
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
206
+
207
+ // lock collateral
208
+ bundleInfo.lockedAmount += collateralAmount;
209
+ bundleInfo.balanceAmount += netPremiumAmount;
210
+
211
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
212
+
213
+ linkPolicy(instance, policyNftId);
214
+ }
215
+
216
+ /// @dev links policy to bundle
217
+ function linkPolicy(IInstance instance, NftId policyNftId)
218
+ internal
219
+ onlyService
220
+ {
221
+ InstanceReader instanceReader = instance.getInstanceReader();
222
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
223
+
224
+ // ensure policy has not yet been activated
225
+ if (policyInfo.activatedAt.gtz()) {
226
+ revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
227
+ }
228
+
229
+ BundleManager bundleManager = instance.getBundleManager();
230
+ bundleManager.linkPolicy(policyNftId);
231
+ }
232
+
233
+ /// @dev unlinks policy from bundle
234
+ function unlinkPolicy(IInstance instance, NftId policyNftId)
235
+ internal
236
+ onlyService
237
+ {
238
+ InstanceReader instanceReader = instance.getInstanceReader();
239
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
240
+
241
+ // ensure policy has no open claims
242
+ if (policyInfo.openClaimsCount > 0) {
243
+ revert BundleManager.ErrorBundleManagerPolicyWithOpenClaims(
244
+ policyNftId,
245
+ policyInfo.openClaimsCount);
246
+ }
247
+
248
+ // ensure policy is closeable
249
+ if (policyInfo.expiredAt < TimestampLib.blockTimestamp()
250
+ || policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
251
+ {
252
+ revert BundleManager.ErrorBundleManagerPolicyNotCloseable(policyNftId);
253
+ }
254
+
255
+ BundleManager bundleManager = instance.getBundleManager();
256
+ bundleManager.unlinkPolicy(policyNftId);
257
+ }
258
+
179
259
  function _processStakingByTreasury(
180
260
  InstanceReader instanceReader,
181
- NftId productNftId,
182
261
  NftId poolNftId,
183
262
  NftId bundleNftId,
184
263
  uint256 stakingAmount
@@ -187,15 +266,22 @@ contract PoolService is
187
266
  {
188
267
  // process token transfer(s)
189
268
  if(stakingAmount > 0) {
190
- TokenHandler tokenHandler = TokenHandler(instanceReader.getTokenHandler(productNftId));
191
- address bundleOwner = getRegistry().ownerOf(bundleNftId);
192
269
  ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
193
-
270
+ TokenHandler tokenHandler = poolInfo.tokenHandler;
271
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
272
+ Fee memory stakingFee = poolInfo.stakingFee;
273
+
194
274
  tokenHandler.transfer(
195
275
  bundleOwner,
196
276
  poolInfo.wallet,
197
277
  stakingAmount
198
278
  );
279
+
280
+
281
+ if (! FeeLib.feeIsZero(stakingFee)) {
282
+ (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
283
+ // TODO: track staking fees in pool's state (issue #177)
284
+ }
199
285
  }
200
286
  }
201
287
  }
@@ -323,8 +323,7 @@ contract ProductService is ComponentServiceBase, IProductService {
323
323
  returns (IBundle.BundleInfo memory)
324
324
  {
325
325
  bundleInfo.lockedAmount += collateralAmount;
326
- // FIXME: this
327
- // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
326
+ // TODO: track policy associated to bundle in bundlemanager (tbd) and how much is locked for it
328
327
  return bundleInfo;
329
328
  }
330
329
 
@@ -381,9 +380,11 @@ contract ProductService is ComponentServiceBase, IProductService {
381
380
  NftId bundleNftId;
382
381
  IBundle.BundleInfo memory bundleInfo;
383
382
  uint256 collateralAmount;
383
+ uint256 netPremiumAmount = 0; // > 0 if immediate premium payment
384
384
  {
385
385
  ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
386
-
386
+ IBundle.BundleInfo memory bundleInfo;
387
+
387
388
  (
388
389
  bundleNftId,
389
390
  bundleInfo,
@@ -396,6 +397,15 @@ contract ProductService is ComponentServiceBase, IProductService {
396
397
  );
397
398
  }
398
399
 
400
+
401
+ // lock bundle collateral
402
+ bundleInfo = _lockCollateralInBundle(
403
+ instance,
404
+ bundleNftId,
405
+ bundleInfo,
406
+ policyNftId,
407
+ collateralAmount);
408
+
399
409
  // lock bundle collateral
400
410
  bundleInfo = _lockCollateralInBundle(
401
411
  instance,
@@ -414,28 +424,25 @@ contract ProductService is ComponentServiceBase, IProductService {
414
424
 
415
425
  // optional collection of premium
416
426
  if(requirePremiumPayment) {
417
- uint256 netPremiumAmount = _processPremiumByTreasury(
427
+ netPremiumAmount = _processPremiumByTreasury(
418
428
  instance,
419
429
  productInfo.nftId,
420
430
  policyNftId,
421
431
  policyInfo.premiumAmount);
422
432
 
423
433
  policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
424
- bundleInfo.balanceAmount += netPremiumAmount;
425
434
  }
426
435
 
436
+ _poolService.underwritePolicy(instance, policyNftId, bundleNftId, collateralAmount, netPremiumAmount);
427
437
  instance.updatePolicy(policyNftId, policyInfo, newPolicyState);
428
- _poolService.updateBundle(productInfo.parentNftId, bundleNftId, bundleInfo, KEEP_STATE());
429
438
 
430
439
  // involve pool if necessary
431
440
  {
432
- NftId poolNftId = bundleInfo.poolNftId;
433
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
441
+ ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(bundleInfo.poolNftId);
434
442
 
435
- // FIXME: use poolInfo.isVerifying ???
436
- if(poolInfo.isIntercepting) {
443
+ if(poolInfo.isConfirmingApplication) {
437
444
  _underwriteByPool(
438
- poolNftId,
445
+ bundleInfo.poolNftId,
439
446
  policyNftId,
440
447
  policyInfo,
441
448
  bundleInfo.filter,
@@ -11,35 +11,37 @@ library LibNftIdSet {
11
11
  mapping(NftId nftid => uint256 index) at;
12
12
  }
13
13
 
14
- function add(Set storage set, NftId nftId) external returns(bool added) {
15
- if (set.at[nftId] == 0) {
16
- set.ids.push(nftId);
17
- set.at[nftId] = set.ids.length;
18
- return true;
19
- } else {
20
- return false;
14
+ error ErrorNftIdSetAlreadyAdded(NftId nftId);
15
+ error ErrorNftIdSetNotInSet(NftId nftId);
16
+
17
+
18
+ function add(Set storage set, NftId nftId) external {
19
+ if (set.at[nftId] > 0) {
20
+ revert ErrorNftIdSetAlreadyAdded(nftId);
21
21
  }
22
+
23
+ set.ids.push(nftId);
24
+ set.at[nftId] = set.ids.length;
22
25
  }
23
26
 
24
- function remove(Set storage set, NftId nftId) external returns(bool removed) {
27
+ function remove(Set storage set, NftId nftId) external {
25
28
  uint256 nftIdIndex = set.at[nftId];
26
29
 
27
- if (nftIdIndex > 0) {
28
- uint256 toDeleteIndex = nftIdIndex - 1;
29
- uint256 lastIndex = set.ids.length - 1;
30
-
31
- if (lastIndex != toDeleteIndex) {
32
- NftId lastId = set.ids[lastIndex];
33
- set.ids[toDeleteIndex] = lastId;
34
- set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
35
- }
36
-
37
- set.ids.pop();
38
- delete set.at[nftId];
39
- return true;
40
- } else {
41
- return false;
30
+ if (nftIdIndex == 0) {
31
+ revert ErrorNftIdSetNotInSet(nftId);
42
32
  }
33
+
34
+ uint256 toDeleteIndex = nftIdIndex - 1;
35
+ uint256 lastIndex = set.ids.length - 1;
36
+
37
+ if (lastIndex != toDeleteIndex) {
38
+ NftId lastId = set.ids[lastIndex];
39
+ set.ids[toDeleteIndex] = lastId;
40
+ set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
41
+ }
42
+
43
+ set.ids.pop();
44
+ delete set.at[nftId];
43
45
  }
44
46
 
45
47
  function isEmpty(Set storage set) external view returns(bool empty) {
@@ -50,7 +52,7 @@ library LibNftIdSet {
50
52
  return set.at[nftId] > 0;
51
53
  }
52
54
 
53
- function getLength(Set storage set) external view returns(uint256 length) {
55
+ function size(Set storage set) external view returns(uint256 length) {
54
56
  return set.ids.length;
55
57
  }
56
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-d64ea51-772",
3
+ "version": "0.0.2-d81820a-051",
4
4
  "description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
5
5
  "main": "index.js",
6
6
  "scripts": {