@etherisc/gif-next 0.0.2-c83506f-943 → 0.0.2-c8cedfe-604

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. package/README.md +4 -0
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +13 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +75 -15
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +13 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +52 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  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 +29 -13
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +39 -18
  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/Dummy.sol/LifeCycleModule.json +2 -2
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +2 -2
  35. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
  37. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  38. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  39. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
  40. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
  41. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +15 -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 +93 -0
  45. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  46. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +59 -0
  47. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  48. package/artifacts/contracts/instance/Instance.sol/Instance.json +137 -80
  49. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  50. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +34 -34
  51. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +63 -37
  53. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +152 -28
  55. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  56. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +53 -9
  57. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  58. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  59. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  60. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  61. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  62. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  63. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  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 +18 -18
  74. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  75. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +636 -0
  76. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +4 -0
  77. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +428 -0
  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/IProductService.sol/IProductService.dbg.json +1 -1
  82. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  83. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  84. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +309 -0
  85. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  86. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -19
  87. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  88. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  89. package/artifacts/contracts/registry/Registry.sol/Registry.json +258 -24
  90. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  91. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +20 -44
  92. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  93. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +49 -28
  94. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +4 -0
  95. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +410 -0
  96. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  97. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  98. package/artifacts/contracts/shared/ERC165.sol/ERC165.json +2 -2
  99. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  100. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  101. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  102. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  103. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  104. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  105. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  106. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  107. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +4 -4
  109. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  110. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  111. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  112. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  113. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  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/TestRegisterable.sol/TestRegisterable.json +4 -4
  118. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  119. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  120. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestService.sol/TestService.json +11 -11
  122. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  124. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  125. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  126. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  127. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  128. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  129. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  131. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  132. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  133. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  134. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  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/RoleId.sol/RoleIdLib.json +2 -2
  142. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  144. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  147. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  148. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  149. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
  151. package/contracts/components/BaseComponent.sol +8 -3
  152. package/contracts/components/Distribution.sol +13 -13
  153. package/contracts/components/IBaseComponent.sol +1 -0
  154. package/contracts/components/IDistributionComponent.sol +3 -0
  155. package/contracts/components/Pool.sol +1 -2
  156. package/contracts/components/Product.sol +1 -1
  157. package/contracts/instance/AccessManagedSimple.sol +5 -4
  158. package/contracts/instance/AccessManagerSimple.sol +10 -0
  159. package/contracts/instance/IInstance.sol +6 -1
  160. package/contracts/instance/IInstanceService.sol +14 -1
  161. package/contracts/instance/Instance.sol +18 -11
  162. package/contracts/instance/InstanceAccessManager.sol +1 -1
  163. package/contracts/instance/InstanceReader.sol +10 -0
  164. package/contracts/instance/InstanceService.sol +81 -22
  165. package/contracts/instance/base/ComponentServiceBase.sol +1 -11
  166. package/contracts/instance/service/DistributionService.sol +96 -0
  167. package/contracts/instance/service/DistributionServiceManager.sol +53 -0
  168. package/contracts/registry/IRegistry.sol +39 -2
  169. package/contracts/registry/IRegistryService.sol +0 -2
  170. package/contracts/registry/Registry.sol +94 -28
  171. package/contracts/registry/RegistryService.sol +9 -49
  172. package/contracts/registry/RegistryServiceManager.sol +21 -5
  173. package/contracts/registry/TokenRegistry.sol +111 -0
  174. package/contracts/shared/ERC165.sol +6 -2
  175. package/contracts/shared/Registerable.sol +1 -0
  176. package/contracts/types/RoleId.sol +6 -0
  177. package/contracts/types/StateId.sol +4 -0
  178. package/contracts/types/Version.sol +4 -1
  179. package/package.json +1 -1
@@ -11,13 +11,15 @@ import {IInstance} from "../instance/IInstance.sol";
11
11
  import {IInstance} from "../instance/IInstance.sol";
12
12
  import {IComponentOwnerService} from "../instance/service/IComponentOwnerService.sol";
13
13
  import {IBaseComponent} from "./IBaseComponent.sol";
14
- import {NftId} from "../types/NftId.sol";
14
+ import {NftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
15
15
  import {ObjectType} from "../types/ObjectType.sol";
16
16
 
17
17
  abstract contract BaseComponent is
18
18
  Registerable,
19
19
  IBaseComponent
20
20
  {
21
+ using NftIdLib for NftId;
22
+
21
23
  IComponentOwnerService internal _componentOwnerService;
22
24
 
23
25
  address internal _deployer;
@@ -29,7 +31,6 @@ abstract contract BaseComponent is
29
31
  constructor(
30
32
  address registry,
31
33
  NftId instanceNftId,
32
- NftId productNftId,
33
34
  address token,
34
35
  ObjectType componentType,
35
36
  bool isInterceptor,
@@ -49,7 +50,6 @@ abstract contract BaseComponent is
49
50
  _componentOwnerService = _instance.getComponentOwnerService();
50
51
  _wallet = address(this);
51
52
  _token = IERC20Metadata(token);
52
- _productNftId = productNftId;
53
53
 
54
54
  _registerInterface(type(IBaseComponent).interfaceId);
55
55
  }
@@ -80,6 +80,11 @@ abstract contract BaseComponent is
80
80
  return _instance;
81
81
  }
82
82
 
83
+ function setProductNftId(NftId productNftId) public override onlyOwner {
84
+ require(_productNftId.eq(zeroNftId()), "product nft id already set");
85
+ _productNftId = productNftId;
86
+ }
87
+
83
88
  function getProductNftId() public view override returns (NftId productNftId) {
84
89
  return _productNftId;
85
90
  }
@@ -38,20 +38,19 @@ contract Distribution is
38
38
  constructor(
39
39
  address registry,
40
40
  NftId instanceNftId,
41
- NftId productNftId,
42
41
  // TODO refactor into tokenNftId
43
42
  address token,
44
43
  bool verifying,
45
44
  Fee memory distributionFee,
46
45
  address initialOwner
47
46
  )
48
- BaseComponent(registry, instanceNftId, productNftId, token, DISTRIBUTION(), true, initialOwner)
47
+ BaseComponent(registry, instanceNftId, token, DISTRIBUTION(), true, initialOwner)
49
48
  {
50
49
  _isVerifying = verifying;
51
50
  _initialDistributionFee = distributionFee;
52
51
 
52
+ _distributionService = _instance.getDistributionService();
53
53
  // TODO: reactivate when services are available again
54
- // _distributionService = _instance.getDistributionService();
55
54
  // _productService = _instance.getProductService();
56
55
 
57
56
  _registerInterface(type(IDistributionComponent).interfaceId);
@@ -122,20 +121,21 @@ contract Distribution is
122
121
  return false;
123
122
  }
124
123
 
125
- function getSetupInfo() public view returns (ISetup.DistributionSetupInfo memory setupInfo) {
126
- if (getNftId().eq(zeroNftId())) {
127
- return ISetup.DistributionSetupInfo(
128
- _productNftId,
129
- TokenHandler(address(0)),
130
- _initialDistributionFee,
131
- _isVerifying,
132
- address(0)
133
- );
134
- }
124
+ function getInitialSetupInfo() public view returns (ISetup.DistributionSetupInfo memory setupInfo) {
125
+ return ISetup.DistributionSetupInfo(
126
+ _productNftId,
127
+ TokenHandler(address(_token)),
128
+ _initialDistributionFee,
129
+ _isVerifying,
130
+ address(this)
131
+ );
132
+ }
135
133
 
134
+ function getSetupInfo() public view returns (ISetup.DistributionSetupInfo memory setupInfo) {
136
135
  InstanceReader reader = _instance.getInstanceReader();
137
136
  return reader.getDistributionSetupInfo(getNftId());
138
137
  }
138
+
139
139
 
140
140
  /// @dev returns true iff the component needs to be called when selling/renewing policis
141
141
  function isVerifying() external view returns (bool verifying) {
@@ -19,6 +19,7 @@ interface IBaseComponent is IRegisterable {
19
19
 
20
20
  function getInstance() external view returns (IInstance instance);
21
21
 
22
+ function setProductNftId(NftId productNftId) external;
22
23
  function getProductNftId() external view returns (NftId productNftId);
23
24
 
24
25
  }
@@ -4,9 +4,12 @@ pragma solidity ^0.8.19;
4
4
  import {Fee} from "../types/Fee.sol";
5
5
  import {ReferralId} from "../types/Referral.sol";
6
6
  import {NftId} from "../types/NftId.sol";
7
+ import {ISetup} from "../instance/module/ISetup.sol";
7
8
 
8
9
  interface IDistributionComponent {
9
10
 
11
+ function getInitialSetupInfo() external view returns (ISetup.DistributionSetupInfo memory setupInfo);
12
+
10
13
  function setFees(
11
14
  Fee memory distributionFee
12
15
  ) external;
@@ -55,7 +55,6 @@ contract Pool is BaseComponent, IPoolComponent {
55
55
  constructor(
56
56
  address registry,
57
57
  NftId instanceNftId,
58
- NftId productNftId,
59
58
  // TODO refactor into tokenNftId
60
59
  address token,
61
60
  bool isInterceptor,
@@ -66,7 +65,7 @@ contract Pool is BaseComponent, IPoolComponent {
66
65
  Fee memory performanceFee,
67
66
  address initialOwner
68
67
  )
69
- BaseComponent(registry, instanceNftId, productNftId, token, POOL(), isInterceptor, initialOwner)
68
+ BaseComponent(registry, instanceNftId, token, POOL(), isInterceptor, initialOwner)
70
69
  {
71
70
  _isVerifying = verifying;
72
71
  // TODO add validation
@@ -49,7 +49,7 @@ contract Product is BaseComponent, IProductComponent {
49
49
  Fee memory productFee,
50
50
  Fee memory processingFee,
51
51
  address initialOwner
52
- ) BaseComponent(registry, instanceNftid, zeroNftId(), token, PRODUCT(), isInterceptor, initialOwner) {
52
+ ) BaseComponent(registry, instanceNftid, token, PRODUCT(), isInterceptor, initialOwner) {
53
53
  // TODO add validation
54
54
  // TODO: reactivate when services are available again
55
55
  // _productService = _instance.getProductService();
@@ -19,17 +19,18 @@ import {IAccessManagerSimple} from "./IAccessManagerSimple.sol";
19
19
  * functions, and ideally only used in `external` functions. See {restricted}.
20
20
  */
21
21
  abstract contract AccessManagedSimple is Context, IAccessManaged {
22
+ bool private _initialized;
22
23
  address private _authority;
23
24
 
24
25
  bool private _consumingSchedule;
25
26
 
26
- /**
27
- * @dev Initializes the contract connected to an initial authority.
28
- */
29
- constructor(address initialAuthority) {
27
+ function initializeAccessManagedSimple(address initialAuthority) internal {
28
+ require(!_initialized, "AccessManaged: already initialized");
30
29
  _setAuthority(initialAuthority);
30
+ _initialized = true;
31
31
  }
32
32
 
33
+
33
34
  /**
34
35
  * @dev Restricts access to a function as defined by the connected Authority for this contract and the
35
36
  * caller and selector of the function that entered the contract.
@@ -46,6 +46,8 @@ contract AccessManagerSimple is Context, IAccessManagerSimple {
46
46
  uint32 nonce;
47
47
  }
48
48
 
49
+ bool private _initialized;
50
+
49
51
  uint64 public constant ADMIN_ROLE = type(uint64).min; // 0
50
52
  uint64 public constant PUBLIC_ROLE = type(uint64).max; // 2**64-1
51
53
 
@@ -67,14 +69,22 @@ contract AccessManagerSimple is Context, IAccessManagerSimple {
67
69
  }
68
70
 
69
71
  constructor(address initialAdmin) {
72
+ initialize(initialAdmin);
73
+ }
74
+
75
+ function initialize(address initialAdmin) public {
76
+ require(!_initialized, "AccessManager: already initialized");
77
+
70
78
  if (initialAdmin == address(0)) {
71
79
  revert AccessManagerInvalidInitialAdmin(address(0));
72
80
  }
73
81
 
74
82
  // admin is active immediately and without any execution delay.
75
83
  _grantRole(ADMIN_ROLE, initialAdmin, 0, 0);
84
+ _initialized = true;
76
85
  }
77
86
 
87
+
78
88
  // =================================================== GETTERS ====================================================
79
89
  /// @inheritdoc IAccessManagerSimple
80
90
  function canCall(
@@ -11,17 +11,22 @@ import {IPoolService} from "./service/IPoolService.sol";
11
11
  import {IProductService} from "./service/IProductService.sol";
12
12
  import {ISetup} from "./module/ISetup.sol";
13
13
  import {NftId} from "../types/NftId.sol";
14
+ import {StateId} from "../types/StateId.sol";
14
15
 
15
16
  interface IInstance is IERC165 {
16
17
 
17
18
  function getComponentOwnerService() external view returns (IComponentOwnerService);
18
19
  // TODO: renable these when we have the services
19
- // function getDistributionService() external view returns (IDistributionService);
20
+ function getDistributionService() external view returns (IDistributionService);
20
21
  // function getProductService() external view returns (IProductService);
21
22
  // function getPoolService() external view returns (IPoolService);
22
23
 
23
24
  function createProductSetup(NftId productNftId, ISetup.ProductSetupInfo memory setup) external;
25
+
24
26
  function createDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup) external;
27
+ function updateDistributionSetup(NftId distributionNftId, ISetup.DistributionSetupInfo memory setup, StateId newState) external;
28
+ function updateDistributionSetupState(NftId distributionNftId, StateId newState) external;
29
+
25
30
  function createPoolSetup(NftId distributionNftId, ISetup.PoolSetupInfo memory setup) external;
26
31
 
27
32
  function getInstanceReader() external view returns (InstanceReader);
@@ -10,8 +10,21 @@ 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";
14
+ import {Instance} from "./Instance.sol";
15
+ import {InstanceReader} from "./InstanceReader.sol";
16
+
13
17
  interface IInstanceService is IService {
14
18
 
15
-
19
+ event LogInstanceCloned(address clonedAccessManagerAddress, address clonedInstanceAddress, address clonedInstanceReaderAddress, NftId clonedInstanceNftId);
20
+
21
+ function createInstanceClone()
22
+ external
23
+ returns (
24
+ AccessManagerSimple clonedAccessManager,
25
+ Instance clonedInstance,
26
+ NftId instanceNftId,
27
+ InstanceReader clonedInstanceReader
28
+ );
16
29
  }
17
30
 
@@ -25,6 +25,7 @@ import {ERC165} from "../shared/ERC165.sol";
25
25
  import {Registerable} from "../shared/Registerable.sol";
26
26
  import {ComponentOwnerService} from "./service/ComponentOwnerService.sol";
27
27
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
28
+ import {IDistributionService} from "./service/IDistributionService.sol";
28
29
  import {VersionPart} from "../types/Version.sol";
29
30
 
30
31
  contract Instance is
@@ -41,6 +42,8 @@ contract Instance is
41
42
 
42
43
  uint32 public constant EXECUTION_DELAY = 0;
43
44
 
45
+ bool private _initialized;
46
+
44
47
  mapping(ShortString name => RoleId roleId) internal _role;
45
48
  mapping(RoleId roleId => EnumerableSet.AddressSet roleMembers) internal _roleMembers;
46
49
  RoleId [] internal _roles;
@@ -51,16 +54,23 @@ contract Instance is
51
54
  InstanceReader internal _instanceReader;
52
55
 
53
56
  constructor(address accessManagerAddress, address registryAddress, NftId registryNftId)
54
- AccessManagedSimple(accessManagerAddress)
55
57
  {
56
- // TODO move to initializer method and remove constructor - required for the instance to be cloneable
58
+ initialize(accessManagerAddress, registryAddress, registryNftId, msg.sender);
59
+ }
60
+
61
+ function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner) public {
62
+ require(!_initialized, "Contract instance has already been initialized");
63
+
64
+ initializeAccessManagedSimple(accessManagerAddress);
65
+
57
66
  _accessManager = AccessManagerSimple(accessManagerAddress);
58
67
  _createRole(RoleIdLib.toRoleId(ADMIN_ROLE), "AdminRole", false, false);
59
68
  _createRole(RoleIdLib.toRoleId(PUBLIC_ROLE), "PublicRole", false, false);
60
69
 
61
- _initializeRegisterable(registryAddress, registryNftId, INSTANCE(), false, msg.sender, "");
70
+ _initializeRegisterable(registryAddress, registryNftId, INSTANCE(), false, initialOwner, "");
62
71
 
63
- _registerInterface(type(IInstance).interfaceId);
72
+ _registerInterface(type(IInstance).interfaceId);
73
+ _initialized = true;
64
74
  }
65
75
 
66
76
  //--- Role ------------------------------------------------------//
@@ -408,10 +418,9 @@ contract Instance is
408
418
  return ComponentOwnerService(_registry.getServiceAddress("ComponentOwnerService", VersionPart.wrap(3)));
409
419
  }
410
420
 
411
- // TODO reactivate when services are available
412
- // function getDistributionService() external view returns (IDistributionService) {
413
- // return DistributionService(_registry.getServiceAddress("DistributionService", VersionPart.wrap(3)));
414
- // }
421
+ function getDistributionService() external view returns (IDistributionService) {
422
+ return IDistributionService(_registry.getServiceAddress("DistributionService", VersionPart.wrap(3)));
423
+ }
415
424
 
416
425
  // TODO reactivate when services are available
417
426
  // function getProductService() external view returns (IProductService) {
@@ -424,9 +433,7 @@ contract Instance is
424
433
  // }
425
434
 
426
435
  function setInstanceReader(InstanceReader instanceReader) external restricted() {
427
- if (address(_instanceReader) != address(0)) {
428
- revert("InstanceReader is set");
429
- }
436
+ require(address(_instanceReader) == address(0), "InstanceReader is set");
430
437
  _instanceReader = instanceReader;
431
438
  }
432
439
 
@@ -79,9 +79,9 @@ contract InstanceAccessManager is
79
79
  AccessManagerSimple internal _accessManager;
80
80
 
81
81
  constructor(address accessManager)
82
- AccessManagedSimple(accessManager)
83
82
  {
84
83
  _accessManager = AccessManagerSimple(accessManager);
84
+ initializeAccessManagedSimple(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);
@@ -26,6 +26,7 @@ import {TimestampLib} from "../types/Timestamp.sol";
26
26
 
27
27
 
28
28
  contract InstanceReader {
29
+ bool private _initialized;
29
30
 
30
31
  IRegistry internal _registry;
31
32
  NftId internal _instanceNftId;
@@ -37,6 +38,12 @@ contract InstanceReader {
37
38
  NftId instanceNftId
38
39
  )
39
40
  {
41
+ initialize(registry, instanceNftId);
42
+ }
43
+
44
+ function initialize(address registry, NftId instanceNftId) public {
45
+ require(!_initialized, "ERROR:CRD-000:ALREADY_INITIALIZED");
46
+
40
47
  require(
41
48
  address(registry) != address(0),
42
49
  "ERROR:CRD-001:REGISTRY_ZERO");
@@ -55,8 +62,11 @@ contract InstanceReader {
55
62
 
56
63
  _instance = IInstance(instanceInfo.objectAddress);
57
64
  _store = IKeyValueStore(instanceInfo.objectAddress);
65
+
66
+ _initialized = true;
58
67
  }
59
68
 
69
+
60
70
  // module specific functions
61
71
 
62
72
  function getPolicyInfo(NftId policyNftId)
@@ -7,18 +7,23 @@ import {AccessManagerSimple} from "./AccessManagerSimple.sol";
7
7
  import {InstanceAccessManager} from "./InstanceAccessManager.sol";
8
8
  import {Instance} from "./Instance.sol";
9
9
  import {IInstanceService} from "./IInstanceService.sol";
10
- import {Service} from "../shared/Service.sol";
10
+ import {InstanceReader} from "./InstanceReader.sol";
11
11
  import {IRegistry} from "../registry/IRegistry.sol";
12
+ import {Registry} from "../registry/Registry.sol";
13
+ import {RegistryService} from "../registry/RegistryService.sol";
14
+ import {Service} from "../../contracts/shared/Service.sol";
12
15
  import {IService} from "../shared/IService.sol";
13
16
  import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
14
- import {NftId, NftIdLib, zeroNftId} from "../types/NftId.sol";
17
+ import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
18
+ import {VersionLib} from "../types/Version.sol";
19
+ import {ADMIN_ROLE, INSTANCE_SERVICE_ROLE, DISTRIBUTION_SERVICE_ROLE} from "../types/RoleId.sol";
15
20
 
16
21
  contract InstanceService is Service, IInstanceService {
17
22
 
18
23
  address internal _registryAddress;
19
24
  address internal _accessManagerMaster;
20
- address internal _instanceAccessManagerMaster;
21
25
  address internal _instanceMaster;
26
+ address internal _instanceReaderMaster;
22
27
 
23
28
  // TODO update to real hash when instance is stable
24
29
  bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
@@ -27,31 +32,89 @@ contract InstanceService is Service, IInstanceService {
27
32
  function createInstanceClone()
28
33
  external
29
34
  returns (
30
- AccessManagerSimple am,
31
- InstanceAccessManager im,
32
- Instance i
35
+ AccessManagerSimple clonedAccessManager,
36
+ Instance clonedInstance,
37
+ NftId instanceNftId,
38
+ InstanceReader clonedInstanceReader
33
39
  )
34
40
  {
35
- am = AccessManagerSimple(Clones.clone(_accessManagerMaster));
36
- im = InstanceAccessManager(Clones.clone(_instanceAccessManagerMaster));
37
- i = Instance(Clones.clone(_instanceMaster));
41
+ address instanceOwner = msg.sender;
42
+ Registry registry = Registry(_registryAddress);
43
+ NftId registryNftId = registry.getNftId(_registryAddress);
44
+ address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
45
+ RegistryService registryService = RegistryService(registryServiceAddress);
46
+
47
+ // initially set the authority of the access managar to this (being the instance service).
48
+ // This will allow the instance service to bootstrap the authorizations of the instance
49
+ // and then transfer the ownership of the access manager to the instance owner once everything is setup
50
+ clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
51
+ clonedAccessManager.initialize(address(this));
52
+
53
+ clonedInstance = Instance(Clones.clone(_instanceMaster));
54
+ clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
55
+ ( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
56
+ instanceNftId = info.nftId;
57
+
58
+ clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
59
+ clonedInstanceReader.initialize(_registryAddress, instanceNftId);
60
+
61
+ _grantInitialAuthorizations(clonedAccessManager, clonedInstance);
62
+
63
+ clonedInstance.setInstanceReader(clonedInstanceReader);
64
+
65
+ // to complete setup switch instance ownership to the instance owner
66
+ // TODO: use a role less powerful than admin, maybe INSTANCE_ADMIN (does not exist yet)
67
+ clonedAccessManager.grantRole(ADMIN_ROLE().toInt(), instanceOwner, 0);
68
+ clonedAccessManager.revokeRole(ADMIN_ROLE().toInt(), address(this));
69
+
70
+ emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
71
+ }
72
+
73
+ function _grantInitialAuthorizations(AccessManagerSimple clonedAccessManager, Instance clonedInstance) internal {
74
+ address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
75
+
76
+ clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
77
+ bytes4[] memory instanceDistributionServiceSelectors = new bytes4[](2);
78
+ instanceDistributionServiceSelectors[0] = clonedInstance.createDistributionSetup.selector;
79
+ instanceDistributionServiceSelectors[1] = clonedInstance.updateDistributionSetup.selector;
80
+ clonedAccessManager.setTargetFunctionRole(
81
+ address(clonedInstance),
82
+ instanceDistributionServiceSelectors,
83
+ DISTRIBUTION_SERVICE_ROLE().toInt());
84
+ }
85
+
86
+ function setAccessManagerMaster(address accessManagerMaster) external {
87
+ require(
88
+ _accessManagerMaster == address(0),
89
+ "ERROR:CRD-001:ACCESS_MANAGER_MASTER_ALREADY_SET");
90
+ _accessManagerMaster = accessManagerMaster;
91
+ }
92
+
93
+ function setInstanceMaster(address instanceMaster) external {
94
+ require(
95
+ _instanceMaster == address(0),
96
+ "ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
97
+ _instanceMaster = instanceMaster;
38
98
  }
39
99
 
40
- function setAccessManagerMaster(address accessManager) external {
41
- _accessManagerMaster = accessManager;
100
+ function setInstanceReaderMaster(address instanceReaderMaster) external {
101
+ require(
102
+ _instanceReaderMaster == address(0),
103
+ "ERROR:CRD-003:INSTANCE_READER_MASTER_ALREADY_SET");
104
+ _instanceReaderMaster = instanceReaderMaster;
42
105
  }
43
106
 
44
- function setInstanceAccessManagerMaster(address instanceAccessManager) external {
45
- _instanceAccessManagerMaster = instanceAccessManager;
107
+ function getInstanceReaderMaster() external view returns (address) {
108
+ return _instanceReaderMaster;
46
109
  }
47
110
 
48
- function setInstanceMaster(address instance) external {
49
- _instanceMaster = instance;
111
+ function getInstanceMaster() external view returns (address) {
112
+ return _instanceMaster;
50
113
  }
51
114
 
52
- function getAccessManagerMaster() external view returns (address) { return address(_accessManagerMaster); }
53
- function getInstanceAccessManagerMaster() external view returns (address) { return address(_instanceAccessManagerMaster); }
54
- function getInstanceMaster() external view returns (address) { return address(_instanceMaster); }
115
+ function getAccessManagerMaster() external view returns (address) {
116
+ return _accessManagerMaster;
117
+ }
55
118
 
56
119
  // From IService
57
120
  function getName() public pure override(IService, Service) returns(string memory) {
@@ -85,10 +148,6 @@ contract InstanceService is Service, IInstanceService {
85
148
  address initialOwner = address(0);
86
149
  (_registryAddress, initialOwner) = abi.decode(data, (address, address));
87
150
 
88
- // // TODO register instance in registry
89
- IRegistry registry = IRegistry(_registryAddress);
90
- NftId registryNftId = registry.getNftId(_registryAddress);
91
-
92
151
  _initializeService(_registryAddress, initialOwner);
93
152
 
94
153
  _registerInterface(type(IService).interfaceId);
@@ -12,16 +12,6 @@ import {Version, VersionPart, VersionLib} from "../../types/Version.sol";
12
12
 
13
13
  abstract contract ComponentServiceBase is Service {
14
14
 
15
- constructor(
16
- address registry,
17
- NftId registryNftId,
18
- address initialOwner
19
- )
20
- {
21
- _initializeService(registry, initialOwner);
22
- }
23
-
24
-
25
15
  function _getAndVerifyComponentInfoAndInstance(
26
16
  ObjectType objectType
27
17
  )
@@ -32,7 +22,7 @@ abstract contract ComponentServiceBase is Service {
32
22
  IInstance instance
33
23
  )
34
24
  {
35
- NftId componentNftId = getRegistry().getNftId(msg.sender);
25
+ NftId componentNftId = _registry.getNftId(msg.sender);
36
26
  require(componentNftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
37
27
 
38
28
  info = getRegistry().getObjectInfo(componentNftId);
@@ -0,0 +1,96 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IRegistry} from "../../registry/IRegistry.sol";
5
+ import {IRegistryService} from "../../registry/IRegistryService.sol";
6
+ import {IInstance} from "../../instance/IInstance.sol";
7
+ import {InstanceReader} from "../../instance/InstanceReader.sol";
8
+ import {ISetup} from "../../instance/module/ISetup.sol";
9
+ import {ITreasury} from "../../instance/module/ITreasury.sol";
10
+
11
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
12
+ import {Fee} from "../../types/Fee.sol";
13
+ import {KEEP_STATE} from "../../types/StateId.sol";
14
+ import {DISTRIBUTION} from "../../types/ObjectType.sol";
15
+ import {Version, VersionLib} from "../../types/Version.sol";
16
+
17
+ import {IVersionable} from "../../shared/IVersionable.sol";
18
+ import {Versionable} from "../../shared/Versionable.sol";
19
+
20
+ import {IService} from "../../shared/IService.sol";
21
+ import {Service} from "../../shared/Service.sol";
22
+ import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
23
+ import {IDistributionService} from "./IDistributionService.sol";
24
+ import {Distribution} from "../../components/Distribution.sol";
25
+
26
+ string constant DISTRIBUTION_SERVICE_NAME = "DistributionService";
27
+
28
+ contract DistributionService is
29
+ ComponentServiceBase,
30
+ IDistributionService
31
+ {
32
+ using NftIdLib for NftId;
33
+
34
+ string public constant NAME = "DistributionService";
35
+
36
+ address internal _registryAddress;
37
+
38
+ function _initialize(
39
+ address owner,
40
+ bytes memory data
41
+ )
42
+ internal
43
+ initializer
44
+ virtual override
45
+ {
46
+ address initialOwner = address(0);
47
+ (_registryAddress, initialOwner) = abi.decode(data, (address, address));
48
+
49
+ // IRegistry registry = IRegistry(_registryAddress);
50
+
51
+ _initializeService(_registryAddress, initialOwner);
52
+
53
+ _registerInterface(type(IService).interfaceId);
54
+ _registerInterface(type(IDistributionService).interfaceId);
55
+ }
56
+
57
+
58
+ function getName() public pure override(IService, Service) returns(string memory name) {
59
+ return NAME;
60
+ }
61
+
62
+ function register(address distributionComponentAddress)
63
+ external
64
+ returns (NftId distributionNftId)
65
+ {
66
+ address componentOwner = msg.sender;
67
+ // TODO validate permission of componentOwner. check if componentOwner has correct permission on instance via InstanceService - DISTRIBUTION_OWNER
68
+ Distribution distribution = Distribution(distributionComponentAddress);
69
+ IRegistryService registryService = getRegistryService();
70
+ (IRegistry.ObjectInfo memory distributionObjInfo, ) = registryService.registerDistribution(
71
+ distribution,
72
+ componentOwner
73
+ );
74
+ distributionNftId = distributionObjInfo.nftId;
75
+
76
+ ISetup.DistributionSetupInfo memory initialSetup = distribution.getInitialSetupInfo();
77
+ IInstance instance = distribution.getInstance();
78
+ instance.createDistributionSetup(distributionNftId, initialSetup);
79
+ }
80
+
81
+ function setFees(
82
+ Fee memory distributionFee
83
+ )
84
+ external
85
+ override
86
+ {
87
+ (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
88
+ InstanceReader instanceReader = instance.getInstanceReader();
89
+ NftId distributionNftId = info.nftId;
90
+
91
+ ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
92
+ distSetupInfo.distributionFee = distributionFee;
93
+
94
+ instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
95
+ }
96
+ }