@etherisc/gif-next 0.0.2-d64ea51-772 → 0.0.2-d6f24e1-490

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) 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/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 +775 -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 +33 -0
  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 +131 -85
  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 +38 -28
  57. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +99 -60
  59. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +34 -30
  61. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  63. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  66. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
  78. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +2 -2
  80. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +2 -2
  82. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +80 -0
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +151 -28
  89. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +31 -15
  91. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +34 -34
  93. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +18 -18
  95. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  97. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  98. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  99. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  101. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  102. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  103. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  104. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  105. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  106. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  107. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  109. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  110. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  111. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  112. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  113. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  114. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  116. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  117. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  118. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  119. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  120. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  122. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  124. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  125. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  126. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  127. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  128. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  129. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  131. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  132. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  133. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  135. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  136. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  147. package/contracts/components/BaseComponent.sol +49 -8
  148. package/contracts/components/IBaseComponent.sol +6 -0
  149. package/contracts/components/IPoolComponent.sol +5 -1
  150. package/contracts/components/Pool.sol +27 -6
  151. package/contracts/components/Product.sol +1 -0
  152. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  153. package/contracts/instance/BundleManager.sol +129 -0
  154. package/contracts/instance/Cloneable.sol +46 -0
  155. package/contracts/instance/IInstance.sol +2 -0
  156. package/contracts/instance/IInstanceBase.sol +26 -0
  157. package/contracts/instance/IInstanceService.sol +5 -3
  158. package/contracts/instance/Instance.sol +25 -10
  159. package/contracts/instance/InstanceAccessManager.sol +6 -6
  160. package/contracts/instance/InstanceBase.sol +41 -0
  161. package/contracts/instance/InstanceService.sol +49 -14
  162. package/contracts/instance/ObjectManager.sol +95 -0
  163. package/contracts/instance/module/ISetup.sol +2 -1
  164. package/contracts/instance/service/IPoolService.sol +12 -2
  165. package/contracts/instance/service/PoolService.sol +100 -14
  166. package/contracts/instance/service/ProductService.sol +18 -11
  167. package/contracts/types/NftIdSet.sol +26 -24
  168. package/package.json +1 -1
  169. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  170. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  171. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  172. package/contracts/instance/AccessManagedSimple.sol +0 -115
  173. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
5
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
+
7
+ import {IRegistry} from "../registry/IRegistry.sol";
8
+
9
+ abstract contract Cloneable is
10
+ AccessManagedUpgradeable
11
+ {
12
+ event CloneableInitialized(address authority, address registry);
13
+
14
+ error CloneableRegistryInvalid(address registry);
15
+
16
+ IRegistry internal _registry;
17
+
18
+ constructor() {
19
+ _registry = IRegistry(address(0));
20
+ }
21
+
22
+ /// @dev call to initialize MUST be made in the same transaction as cloning of the contract
23
+ function initialize(
24
+ address authority,
25
+ address registry
26
+ )
27
+ public
28
+ initializer
29
+ {
30
+ // check/handle access managed
31
+ __AccessManaged_init(authority);
32
+
33
+ // check/handle registry
34
+ if (registry.code.length == 0) {
35
+ revert CloneableRegistryInvalid(registry);
36
+ }
37
+
38
+ _registry = IRegistry(registry);
39
+
40
+ emit CloneableInitialized(authority, registry);
41
+ }
42
+
43
+ function getRegistry() external view returns (IRegistry) {
44
+ return _registry;
45
+ }
46
+ }
@@ -3,6 +3,7 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
5
 
6
+ import {BundleManager} from "./BundleManager.sol";
6
7
  import {InstanceReader} from "./InstanceReader.sol";
7
8
 
8
9
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
@@ -51,4 +52,5 @@ interface IInstance is IERC165, IKeyValueStore {
51
52
  function updatePolicyState(NftId policyNftId, StateId newState) external;
52
53
 
53
54
  function getInstanceReader() external view returns (InstanceReader);
55
+ function getBundleManager() external view returns (BundleManager);
54
56
  }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
+
6
+ import {BundleManager} from "./BundleManager.sol";
7
+ import {InstanceReader} from "./InstanceReader.sol";
8
+
9
+ import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
10
+ import {IDistributionService} from "./service/IDistributionService.sol";
11
+ import {IPoolService} from "./service/IPoolService.sol";
12
+ import {IProductService} from "./service/IProductService.sol";
13
+ import {IBundle} from "./module/IBundle.sol";
14
+ import {ISetup} from "./module/ISetup.sol";
15
+ import {NftId} from "../types/NftId.sol";
16
+ import {StateId} from "../types/StateId.sol";
17
+ import {RiskId} from "../types/RiskId.sol";
18
+ import {IRisk} from "./module/IRisk.sol";
19
+ import {IPolicy} from "./module/IPolicy.sol";
20
+ import {IKeyValueStore} from "./base/IKeyValueStore.sol";
21
+
22
+
23
+ interface IInstanceBase is IERC165, IKeyValueStore {
24
+
25
+
26
+ }
@@ -10,9 +10,10 @@ import {IRegistry} from "../registry/IRegistry.sol";
10
10
  import {IRegisterable} from "../shared/IRegisterable.sol";
11
11
  import {IBaseComponent} from "../components/IBaseComponent.sol";
12
12
 
13
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
13
+ import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.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
 
@@ -21,10 +22,11 @@ interface IInstanceService is IService {
21
22
  function createInstanceClone()
22
23
  external
23
24
  returns (
24
- AccessManagerSimple clonedAccessManager,
25
+ AccessManagerUpgradeableInitializeable clonedAccessManager,
25
26
  Instance clonedInstance,
26
27
  NftId instanceNftId,
27
- InstanceReader clonedInstanceReader
28
+ InstanceReader clonedInstanceReader,
29
+ BundleManager clonedBundleManager
28
30
  );
29
31
  }
30
32
 
@@ -3,9 +3,10 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
5
5
  import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
+ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
7
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
8
+ import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
6
9
 
7
- import {AccessManagedSimple} from "./AccessManagedSimple.sol";
8
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
9
10
  import {IAccess} from "./module/IAccess.sol";
10
11
  import {IBundle} from "./module/IBundle.sol";
11
12
  import {IPolicy} from "./module/IPolicy.sol";
@@ -15,6 +16,7 @@ import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
15
16
  import {KeyValueStore} from "./base/KeyValueStore.sol";
16
17
  import {IInstance} from "./IInstance.sol";
17
18
  import {InstanceReader} from "./InstanceReader.sol";
19
+ import {BundleManager} from "./BundleManager.sol";
18
20
  import {NftId} from "../types/NftId.sol";
19
21
  import {NumberId} from "../types/NumberId.sol";
20
22
  import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
@@ -29,13 +31,13 @@ import {IDistributionService} from "./service/IDistributionService.sol";
29
31
  import {IPoolService} from "./service/IPoolService.sol";
30
32
  import {IProductService} from "./service/IProductService.sol";
31
33
  import {VersionPart} from "../types/Version.sol";
34
+ import {InstanceBase} from "./InstanceBase.sol";
32
35
 
33
36
  contract Instance is
34
- AccessManagedSimple,
35
- KeyValueStore,
37
+ AccessManagedUpgradeable,
36
38
  IInstance,
37
- ERC165,
38
- Registerable
39
+ // Initializable,
40
+ InstanceBase
39
41
  {
40
42
 
41
43
  uint64 public constant ADMIN_ROLE = type(uint64).min;
@@ -52,20 +54,24 @@ contract Instance is
52
54
 
53
55
  mapping(ShortString name => address target) internal _target;
54
56
 
55
- AccessManagerSimple internal _accessManager;
57
+ AccessManagerUpgradeable internal _accessManager;
56
58
  InstanceReader internal _instanceReader;
59
+ BundleManager internal _bundleManager;
57
60
 
58
61
  constructor(address accessManagerAddress, address registryAddress, NftId registryNftId)
59
62
  {
60
63
  initialize(accessManagerAddress, registryAddress, registryNftId, msg.sender);
61
64
  }
62
65
 
63
- function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner) public {
66
+ function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner)
67
+ public
68
+ initializer
69
+ {
64
70
  require(!_initialized, "Contract instance has already been initialized");
65
71
 
66
- initializeAccessManagedSimple(accessManagerAddress);
72
+ __AccessManaged_init(accessManagerAddress);
67
73
 
68
- _accessManager = AccessManagerSimple(accessManagerAddress);
74
+ _accessManager = AccessManagerUpgradeable(accessManagerAddress);
69
75
  _createRole(RoleIdLib.toRoleId(ADMIN_ROLE), "AdminRole", false, false);
70
76
  _createRole(RoleIdLib.toRoleId(PUBLIC_ROLE), "PublicRole", false, false);
71
77
 
@@ -440,4 +446,13 @@ contract Instance is
440
446
  function getInstanceReader() external view returns (InstanceReader) {
441
447
  return _instanceReader;
442
448
  }
449
+
450
+ function setBundleManager(BundleManager bundleManager) external restricted() {
451
+ require(address(_bundleManager) == address(0), "BundleManager is set");
452
+ _bundleManager = bundleManager;
453
+ }
454
+
455
+ function getBundleManager() external view returns (BundleManager) {
456
+ return _bundleManager;
457
+ }
443
458
  }
@@ -3,9 +3,9 @@ pragma solidity ^0.8.20;
3
3
 
4
4
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
5
5
  import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
+ import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
7
+ import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
6
8
 
7
- import {AccessManagedSimple} from "./AccessManagedSimple.sol";
8
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
9
9
  import {IBundle} from "./module/IBundle.sol";
10
10
  import {IPolicy} from "./module/IPolicy.sol";
11
11
  import {IRisk} from "./module/IRisk.sol";
@@ -21,7 +21,7 @@ import {StateId, ACTIVE} from "../types/StateId.sol";
21
21
  import {Timestamp, TimestampLib} from "../types/Timestamp.sol";
22
22
 
23
23
  contract InstanceAccessManager is
24
- AccessManagedSimple
24
+ AccessManagedUpgradeable
25
25
  {
26
26
  string public constant ADMIN_ROLE_NAME = "AdminRole";
27
27
  string public constant PUBLIC_ROLE_NAME = "PublicRole";
@@ -76,12 +76,12 @@ contract InstanceAccessManager is
76
76
  mapping(ShortString name => address target) internal _targetForName;
77
77
  address [] internal _targets;
78
78
 
79
- AccessManagerSimple internal _accessManager;
79
+ AccessManagerUpgradeable internal _accessManager;
80
80
 
81
81
  constructor(address accessManager)
82
82
  {
83
- _accessManager = AccessManagerSimple(accessManager);
84
- initializeAccessManagedSimple(accessManager);
83
+ _accessManager = AccessManagerUpgradeable(accessManager);
84
+ __AccessManaged_init(accessManager);
85
85
 
86
86
  _createRole(RoleIdLib.toRoleId(_accessManager.ADMIN_ROLE()), ADMIN_ROLE_NAME, false, false);
87
87
  _createRole(RoleIdLib.toRoleId(_accessManager.PUBLIC_ROLE()), PUBLIC_ROLE_NAME, false, false);
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.20;
3
+
4
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
5
+ import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
6
+
7
+ import {IAccess} from "./module/IAccess.sol";
8
+ import {IBundle} from "./module/IBundle.sol";
9
+ import {IPolicy} from "./module/IPolicy.sol";
10
+ import {IRisk} from "./module/IRisk.sol";
11
+ import {ISetup} from "./module/ISetup.sol";
12
+ import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
13
+ import {KeyValueStore} from "./base/KeyValueStore.sol";
14
+ import {IInstance} from "./IInstance.sol";
15
+ import {InstanceReader} from "./InstanceReader.sol";
16
+ import {BundleManager} from "./BundleManager.sol";
17
+ import {NftId} from "../types/NftId.sol";
18
+ import {NumberId} from "../types/NumberId.sol";
19
+ import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
20
+ import {RiskId, RiskIdLib} from "../types/RiskId.sol";
21
+ import {RoleId, RoleIdLib} from "../types/RoleId.sol";
22
+ import {StateId, ACTIVE} from "../types/StateId.sol";
23
+ import {ERC165} from "../shared/ERC165.sol";
24
+ import {Registerable} from "../shared/Registerable.sol";
25
+ import {ComponentOwnerService} from "./service/ComponentOwnerService.sol";
26
+ import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
27
+ import {IDistributionService} from "./service/IDistributionService.sol";
28
+ import {IPoolService} from "./service/IPoolService.sol";
29
+ import {IProductService} from "./service/IProductService.sol";
30
+ import {VersionPart} from "../types/Version.sol";
31
+ import {IInstanceBase} from "./IInstanceBase.sol";
32
+
33
+ contract InstanceBase is
34
+ IInstanceBase,
35
+ KeyValueStore,
36
+ ERC165,
37
+ Registerable
38
+ {
39
+
40
+
41
+ }
@@ -2,12 +2,14 @@
2
2
  pragma solidity ^0.8.20;
3
3
 
4
4
  import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5
+ import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
5
6
 
6
- import {AccessManagerSimple} from "./AccessManagerSimple.sol";
7
+ import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.sol";
7
8
  import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
9
  import {Instance} from "./Instance.sol";
9
10
  import {IInstanceService} from "./IInstanceService.sol";
10
11
  import {InstanceReader} from "./InstanceReader.sol";
12
+ import {BundleManager} from "./BundleManager.sol";
11
13
  import {IRegistry} from "../registry/IRegistry.sol";
12
14
  import {Registry} from "../registry/Registry.sol";
13
15
  import {RegistryService} from "../registry/RegistryService.sol";
@@ -25,6 +27,7 @@ contract InstanceService is Service, IInstanceService {
25
27
  address internal _accessManagerMaster;
26
28
  address internal _instanceMaster;
27
29
  address internal _instanceReaderMaster;
30
+ address internal _instanceBundleManagerMaster;
28
31
 
29
32
  // TODO update to real hash when instance is stable
30
33
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
@@ -33,10 +36,11 @@ contract InstanceService is Service, IInstanceService {
33
36
  function createInstanceClone()
34
37
  external
35
38
  returns (
36
- AccessManagerSimple clonedAccessManager,
39
+ AccessManagerUpgradeableInitializeable clonedAccessManager,
37
40
  Instance clonedInstance,
38
- NftId instanceNftId,
39
- InstanceReader clonedInstanceReader
41
+ NftId clonedInstanceNftId,
42
+ InstanceReader clonedInstanceReader,
43
+ BundleManager clonedBundleManager
40
44
  )
41
45
  {
42
46
  address instanceOwner = msg.sender;
@@ -48,30 +52,36 @@ contract InstanceService is Service, IInstanceService {
48
52
  // initially set the authority of the access managar to this (being the instance service).
49
53
  // This will allow the instance service to bootstrap the authorizations of the instance
50
54
  // and then transfer the ownership of the access manager to the instance owner once everything is setup
51
- clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
52
- clonedAccessManager.initialize(address(this));
55
+ clonedAccessManager = AccessManagerUpgradeableInitializeable(Clones.clone(_accessManagerMaster));
56
+ clonedAccessManager.__AccessManagerUpgradeableInitializeable_init(address(this));
53
57
 
54
58
  clonedInstance = Instance(Clones.clone(_instanceMaster));
55
59
  clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
56
60
  ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
57
- instanceNftId = info.nftId;
61
+ clonedInstanceNftId = info.nftId;
58
62
 
59
63
  clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
60
- clonedInstanceReader.initialize(_registryAddress, instanceNftId);
64
+ clonedInstanceReader.initialize(_registryAddress, clonedInstanceNftId);
65
+ clonedInstance.setInstanceReader(clonedInstanceReader);
61
66
 
62
- _grantInitialAuthorizations(clonedAccessManager, clonedInstance);
67
+ clonedBundleManager = BundleManager(Clones.clone(_instanceBundleManagerMaster));
68
+ clonedBundleManager.initialize(address(clonedAccessManager), _registryAddress, clonedInstanceNftId);
69
+ clonedInstance.setBundleManager(clonedBundleManager);
70
+
71
+ // TODO amend setters with instance specific , policy manager ...
72
+
73
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance, clonedBundleManager);
63
74
 
64
- clonedInstance.setInstanceReader(clonedInstanceReader);
65
-
66
75
  // to complete setup switch instance ownership to the instance owner
67
76
  // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
68
77
  clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
69
78
  clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
70
79
 
71
- emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
80
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
72
81
  }
73
82
 
74
- function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance) internal {
83
+ function _grantInitialAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
84
+ // configure authorization for distribution service on instance
75
85
  address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
76
86
  clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
77
87
  bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
@@ -82,6 +92,7 @@ contract InstanceService is Service, IInstanceService {
82
92
  instanceDistributionServiceSelectors,
83
93
  DISTRIBUTION_SERVICE_ROLE().toInt());
84
94
 
95
+ // configure authorization for pool service on instance
85
96
  address poolServiceAddress = _registry.getServiceAddress("PoolService", VersionLib.toVersion(3, 0, 0).toMajorPart());
86
97
  clonedAccessManager.grantRole(POOL_SERVICE_ROLE().toInt(), address(poolServiceAddress), 0);
87
98
  bytes4[] memory instancePoolServiceSelectors = new bytes4[](4);
@@ -93,7 +104,20 @@ contract InstanceService is Service, IInstanceService {
93
104
  address(clonedInstance),
94
105
  instancePoolServiceSelectors,
95
106
  POOL_SERVICE_ROLE().toInt());
107
+
108
+ // configure authorization for pool service on bundle manager
109
+ bytes4[] memory bundleManagerPoolServiceSelectors = new bytes4[](5);
110
+ bundleManagerPoolServiceSelectors[0] = clonedBundleManager.linkPolicy.selector;
111
+ bundleManagerPoolServiceSelectors[1] = clonedBundleManager.unlinkPolicy.selector;
112
+ bundleManagerPoolServiceSelectors[2] = clonedBundleManager.add.selector;
113
+ bundleManagerPoolServiceSelectors[3] = clonedBundleManager.lock.selector;
114
+ bundleManagerPoolServiceSelectors[4] = clonedBundleManager.unlock.selector;
115
+ clonedAccessManager.setTargetFunctionRole(
116
+ address(clonedBundleManager),
117
+ bundleManagerPoolServiceSelectors,
118
+ POOL_SERVICE_ROLE().toInt());
96
119
 
120
+ // configure authorization for product service on instance
97
121
  address productServiceAddress = _registry.getServiceAddress("ProductService", VersionLib.toVersion(3, 0, 0).toMajorPart());
98
122
  clonedAccessManager.grantRole(PRODUCT_SERVICE_ROLE().toInt(), address(productServiceAddress), 0);
99
123
  bytes4[] memory instanceProductServiceSelectors = new bytes4[](9);
@@ -132,6 +156,13 @@ contract InstanceService is Service, IInstanceService {
132
156
  _instanceReaderMaster = instanceReaderMaster;
133
157
  }
134
158
 
159
+ function setBundleManagerMaster(address bundleManagerMaster) external {
160
+ require(
161
+ _instanceBundleManagerMaster == address(0),
162
+ "ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
163
+ _instanceBundleManagerMaster = bundleManagerMaster;
164
+ }
165
+
135
166
  function getInstanceReaderMaster() external view returns (address) {
136
167
  return _instanceReaderMaster;
137
168
  }
@@ -144,6 +175,10 @@ contract InstanceService is Service, IInstanceService {
144
175
  return _accessManagerMaster;
145
176
  }
146
177
 
178
+ function getBundleManagerMaster() external view returns (address) {
179
+ return _instanceBundleManagerMaster;
180
+ }
181
+
147
182
  // From IService
148
183
  function getName() public pure override(IService, Service) returns(string memory) {
149
184
  return NAME;
@@ -187,7 +222,7 @@ contract InstanceService is Service, IInstanceService {
187
222
  IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
188
223
  address instanceAddress = instanceObjectInfo.objectAddress;
189
224
  Instance instance = Instance(instanceAddress);
190
- AccessManagerSimple accessManager = AccessManagerSimple(instance.authority());
225
+ AccessManagerUpgradeable accessManager = AccessManagerUpgradeable(instance.authority());
191
226
  (bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
192
227
  if (executionDelay > 0) {
193
228
  return false;
@@ -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
  }