@etherisc/gif-next 0.0.2-ead1eb0-841 → 0.0.2-eadf4ad-932

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  2. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  3. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +80 -80
  4. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  5. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +97 -58
  6. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  7. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  8. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  9. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  10. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  11. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  12. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  13. package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
  14. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  15. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  16. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.dbg.json +1 -1
  17. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.json +2 -2
  18. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  19. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +2 -2
  20. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  21. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +24 -24
  22. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  23. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +69 -30
  24. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  25. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +2 -2
  26. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  27. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  28. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  29. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  30. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  31. package/artifacts/contracts/instance/base/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  32. package/artifacts/contracts/instance/base/ObjectManager.sol/ObjectManager.json +2 -2
  33. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  34. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  35. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  36. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  37. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  38. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  39. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  40. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  41. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  42. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +44 -44
  43. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  44. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +79 -40
  45. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  46. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  47. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  48. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  49. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  50. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +48 -48
  51. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  52. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +81 -42
  53. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  54. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +4 -4
  55. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  56. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +68 -29
  57. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  58. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +10 -10
  59. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +90 -51
  61. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  62. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  63. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  64. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  65. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  66. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +1 -1
  67. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  68. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +8 -8
  69. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  70. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +90 -51
  71. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  72. package/artifacts/contracts/product/PricingService.sol/PricingService.json +30 -30
  73. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  74. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +77 -38
  75. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  76. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +1 -1
  77. package/artifacts/contracts/product/ProductService.sol/ProductService.json +6 -6
  78. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  79. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +66 -27
  80. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  81. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  82. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +73 -13
  83. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  84. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +153 -51
  85. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  86. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  87. package/artifacts/contracts/registry/Registry.sol/Registry.json +93 -25
  88. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  89. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +48 -95
  90. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  91. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +170 -68
  92. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  93. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +72 -28
  94. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  95. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +363 -76
  96. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  97. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  98. package/artifacts/contracts/shared/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  99. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  100. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  101. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  102. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  103. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  104. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  105. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  106. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  107. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  108. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  109. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  110. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  111. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  112. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  113. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  114. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +43 -14
  115. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  116. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  117. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  118. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  119. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  120. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  121. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  122. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  123. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  124. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  125. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +4 -4
  126. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +4 -0
  127. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +667 -0
  128. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  129. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  130. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  131. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  132. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  133. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  134. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  135. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  136. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  137. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  138. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  139. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  140. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  141. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  142. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.json +2 -2
  143. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  144. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  145. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  146. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +1 -1
  147. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  148. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  149. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  150. package/contracts/distribution/DistributionService.sol +8 -6
  151. package/contracts/distribution/DistributionServiceManager.sol +9 -6
  152. package/contracts/instance/InstanceService.sol +9 -16
  153. package/contracts/instance/InstanceServiceManager.sol +10 -20
  154. package/contracts/pool/BundleService.sol +13 -11
  155. package/contracts/pool/BundleServiceManager.sol +9 -18
  156. package/contracts/pool/PoolService.sol +12 -11
  157. package/contracts/pool/PoolServiceManager.sol +9 -18
  158. package/contracts/product/ApplicationService.sol +6 -5
  159. package/contracts/product/ApplicationServiceManager.sol +9 -6
  160. package/contracts/product/ClaimService.sol +6 -5
  161. package/contracts/product/ClaimServiceManager.sol +9 -6
  162. package/contracts/product/PolicyService.sol +6 -4
  163. package/contracts/product/PolicyServiceManager.sol +9 -21
  164. package/contracts/product/PricingService.sol +6 -5
  165. package/contracts/product/PricingServiceManager.sol +9 -18
  166. package/contracts/product/ProductService.sol +6 -4
  167. package/contracts/product/ProductServiceManager.sol +9 -21
  168. package/contracts/registry/IRegistry.sol +19 -12
  169. package/contracts/registry/IRegistryService.sol +22 -30
  170. package/contracts/registry/Registry.sol +40 -36
  171. package/contracts/registry/RegistryAccessManager.sol +39 -123
  172. package/contracts/registry/RegistryService.sol +22 -76
  173. package/contracts/registry/RegistryServiceManager.sol +21 -9
  174. package/contracts/registry/ReleaseManager.sol +243 -189
  175. package/contracts/shared/ComponentService.sol +0 -9
  176. package/contracts/shared/ProxyManager.sol +26 -0
  177. package/contracts/staking/StakingService.sol +7 -4
  178. package/contracts/staking/{StakeingServiceManager.sol → StakingServiceManager.sol} +8 -5
  179. package/contracts/type/RoleId.sol +10 -3
  180. package/package.json +1 -1
  181. package/artifacts/contracts/staking/StakeingServiceManager.sol/StakingServiceManager.dbg.json +0 -4
  182. package/artifacts/contracts/staking/StakeingServiceManager.sol/StakingServiceManager.json +0 -628
@@ -1,224 +1,243 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
5
+ import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
4
6
  import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
5
7
 
6
8
  import {NftId} from "../type/NftId.sol";
7
- import {RoleId} from "../type/RoleId.sol";
9
+ import {RoleId, ADMIN_ROLE, PUBLIC_ROLE} from "../type/RoleId.sol";
8
10
  import {ObjectType, ObjectTypeLib, zeroObjectType, REGISTRY, SERVICE} from "../type/ObjectType.sol";
9
11
  import {Version, VersionLib, VersionPart, VersionPartLib} from "../type/Version.sol";
10
12
  import {Timestamp, TimestampLib} from "../type/Timestamp.sol";
11
13
 
12
14
  import {IService} from "../shared/IService.sol";
15
+ import {AccessManagerUpgradeableInitializeable} from "../shared/AccessManagerUpgradeableInitializeable.sol";
13
16
 
14
17
  import {IRegistry} from "./IRegistry.sol";
15
18
  import {Registry} from "./Registry.sol";
16
19
  import {IRegistryService} from "./IRegistryService.sol";
17
20
  import {RegistryAccessManager} from "./RegistryAccessManager.sol";
18
21
 
22
+ // gif admin is not technical, should sent simple txs
23
+ // foundation creates
24
+ // other guy deployes
25
+ // other guy checks (can precompute addresses and compare with what deployed)
26
+ // foundation activates
27
+ // TODO add function to deactivate releases
28
+ // TODO in next pr add getVersion() to releaseAccessManager only, set in initialize()
29
+ // TODO in next pr make single base for registry access manager, release access manager and instance access manager
19
30
 
20
31
  contract ReleaseManager is AccessManaged
21
32
  {
22
33
  using ObjectTypeLib for ObjectType;
23
34
 
24
- event LogReleaseCreation(VersionPart version);
35
+ event LogReleaseCreation(VersionPart version, bytes32 salt, AccessManagerUpgradeableInitializeable accessManager);
25
36
  event LogReleaseActivation(VersionPart version);
26
37
 
27
- // createNextRelease
28
- error NotRegistryService();
29
- error UnexpectedServiceAuthority(address expected, address found);
30
38
 
39
+ // prepareRelease
40
+ error ErrorReleaseManagerReleaseEmpty();
41
+ error ErrorReleaseManagerReleaseAlreadyCreated(VersionPart version);
42
+
31
43
  // registerService
32
- error NotService();
44
+ error ErrorReleaseManagerNotService(IService service);
45
+ error ErrorReleaseManagerServiceAddressInvalid(IService given, address expected);
33
46
 
34
47
  // activateNextRelease
35
- error ReleaseNotCreated();
36
- error ReleaseRegistrationNotFinished();
37
-
38
- // _getAndVerifyContractInfo
39
- error UnexpectedRegisterableType(ObjectType expected, ObjectType found);
40
- error NotRegisterableOwner(address notOwner);
41
- error SelfRegistration();
42
- error RegisterableOwnerIsRegistered();
48
+ error ErrorReleaseManagerReleaseNotCreated(VersionPart releaseVersion);
49
+ error ErrorReleaseManagerReleaseRegistrationNotFinished(VersionPart releaseVersion, uint awaitingRegistration);
50
+ error ErrorReleaseManagerReleaseAlreadyActivated(VersionPart releaseVersion);
43
51
 
44
52
  // _verifyService
45
- error UnexpectedServiceVersion(VersionPart expected, VersionPart found);
46
- error UnexpectedServiceDomain(ObjectType expected, ObjectType found);
47
-
48
- // _verifyAndStoreConfig
49
- error ConfigMissing();
50
- error ConfigServiceDomainInvalid(uint configArrayIndex, ObjectType domain);
51
- error ConfigSelectorZero(uint configArrayIndex);
52
- error SelectorAlreadyExists(VersionPart releaseVersion, ObjectType serviceDomain);
53
-
53
+ error ErrorReleaseManagerServiceReleaseAuthorityMismatch(IService service, address serviceAuthority, address releaseAuthority);
54
+ error ErrorReleaseManagerServiceReleaseVersionMismatch(IService service, VersionPart serviceVersion, VersionPart releaseVersion);
54
55
 
55
- RegistryAccessManager private immutable _accessManager;
56
- IRegistry private immutable _registry;
56
+ // _verifyServiceInfo
57
+ error ErrorReleaseManagerServiceInfoAddressInvalid(IService service, address expected);
58
+ error ErrorReleaseManagerServiceInfoInterceptorInvalid(IService service, bool isInterceptor);
59
+ error ErrorReleaseManagerServiceInfoTypeInvalid(IService service, ObjectType expected, ObjectType found);
60
+ error ErrorReleaseManagerServiceInfoOwnerInvalid(IService service, address expected, address found);
61
+ error ErrorReleaseManagerServiceSelfRegistration(IService service);
62
+ error ErrorReleaseManagerServiceOwnerRegistered(IService service, address owner);
57
63
 
58
- VersionPart immutable _initial;// first active major version
59
- VersionPart _latest;// latest active major version
60
- VersionPart _next;// major version to create and activate
64
+ // _verifyServiceAuthorizations
65
+ error ErrorReleaseManagerServiceRoleInvalid(address service, RoleId role);
61
66
 
62
- mapping(VersionPart majorVersion => IRegistry.ReleaseInfo info) _release;
67
+ RegistryAccessManager public immutable _accessManager;
68
+ IRegistry public immutable _registry;
63
69
 
64
- // registry service function selector assigned to domain
65
- mapping(VersionPart majorVersion => mapping(ObjectType serviceDomain => bytes4[])) _selectors;
70
+ mapping(VersionPart version => AccessManagerUpgradeableInitializeable accessManager) internal _releaseAccessManager;
71
+ mapping(VersionPart version => IRegistry.ReleaseInfo info) internal _releaseInfo;
72
+ mapping(address registryService => bool isActive) internal _active;// have access to registry
66
73
 
67
- uint _awaitingRegistration; // "services left to register" counter
74
+ VersionPart immutable internal _initial;// first active version
75
+ VersionPart internal _latest;// latest active version
76
+ VersionPart internal _next;// version to create and activate
68
77
 
69
- mapping(address registryService => bool isActive) _active;
70
-
71
- mapping(VersionPart majorVersion => bool isValid) _valid; // TODO refactor to use _active only
78
+ uint internal _awaitingRegistration; // "services left to register" counter
72
79
 
73
80
  constructor(
74
81
  RegistryAccessManager accessManager,
75
82
  VersionPart initialVersion)
76
83
  AccessManaged(accessManager.authority())
77
84
  {
78
- require(initialVersion.toInt() > 0, "ReleaseManager: initial version is 0");
79
-
80
85
  _accessManager = accessManager;
81
-
82
86
  _initial = initialVersion;
83
- _next = initialVersion;
84
-
87
+ _next = VersionPartLib.toVersionPart(initialVersion.toInt() - 1);
85
88
  _registry = new Registry();
86
89
  }
87
90
 
88
- /// @dev skips previous release if was not activated
89
- function createNextRelease()
91
+ /// @dev skips previous release if it was not activated
92
+ function createNextRelease()
90
93
  external
91
94
  restricted // GIF_ADMIN_ROLE
95
+ returns(VersionPart version)
92
96
  {
93
- // allow to register new registry service for next version
94
- // TODO check/test: assignment to _next likely missing ...
95
- VersionPartLib.toVersionPart(_next.toInt() + 1);
96
-
97
- // disallow registration of regular services for next version while registry service is not registered
97
+ _next = VersionPartLib.toVersionPart(_next.toInt() + 1);
98
98
  _awaitingRegistration = 0;
99
-
100
- emit LogReleaseCreation(_next);
101
99
  }
102
100
 
103
- function activateNextRelease()
104
- external
105
- restricted // GIF_ADMIN_ROLE
101
+ function prepareNextRelease(
102
+ address[] memory addresses,
103
+ RoleId[][] memory serviceRoles,
104
+ RoleId[][] memory functionRoles,
105
+ bytes4[][][] memory selectors,
106
+ bytes32 salt
107
+ )
108
+ external
109
+ restricted // GIF_MANAGER_ROLE
110
+ returns(address releaseAccessManagerAddress, VersionPart version, bytes32 releaseSalt)
106
111
  {
107
- VersionPart version = _next;
108
- address service = _registry.getServiceAddress(REGISTRY(), version);
109
-
110
- // release was created
111
- if(service == address(0)) {
112
- revert ReleaseNotCreated();
112
+ if(addresses.length == 0) {
113
+ revert ErrorReleaseManagerReleaseEmpty();
113
114
  }
114
115
 
115
- // release fully deployed
116
116
  if(_awaitingRegistration > 0) {
117
- revert ReleaseRegistrationNotFinished();
117
+ revert ErrorReleaseManagerReleaseAlreadyCreated(version);
118
118
  }
119
119
 
120
- //setTargetClosed(service, false);
120
+ _verifyReleaseAuthorizations(addresses, serviceRoles, functionRoles, selectors);
121
121
 
122
- _latest = version;
122
+ version = getNextVersion();
123
123
 
124
- _active[service] = true;
125
- _valid[version] = true;
124
+ _releaseInfo[version].version = version;
125
+ _releaseInfo[version].addresses = addresses;
126
+ _releaseInfo[version].serviceRoles = serviceRoles;
127
+ _releaseInfo[version].functionRoles = functionRoles;
128
+ _releaseInfo[version].selectors = selectors;
129
+ _awaitingRegistration = addresses.length;
126
130
 
127
- emit LogReleaseActivation(version);
131
+ version = getNextVersion();
132
+ // ensures unique salt
133
+ releaseSalt = keccak256(
134
+ bytes.concat(
135
+ bytes32(version.toInt()),
136
+ salt));
137
+
138
+ releaseAccessManagerAddress = Clones.cloneDeterministic(_accessManager.authority(), releaseSalt);
139
+ AccessManagerUpgradeableInitializeable releaseAccessManager = AccessManagerUpgradeableInitializeable(releaseAccessManagerAddress);
140
+
141
+ _releaseAccessManager[version] = releaseAccessManager;
142
+
143
+ releaseAccessManager.initialize(address(this));
144
+
145
+ emit LogReleaseCreation(version, releaseSalt, releaseAccessManager);
128
146
  }
129
147
 
130
- // TODO implement reliable way this function can only be called directly after createNextRelease()
131
- // IMPORTANT: MUST never be possible to create with access/release manager, token registry
132
- // callable once per release after release creation
133
- // can not register regular services
134
- function registerRegistryService(IRegistryService service)
148
+ function registerService(IService service)
135
149
  external
136
150
  restricted // GIF_MANAGER_ROLE
137
151
  returns(NftId nftId)
138
152
  {
139
- if(!service.supportsInterface(type(IRegistryService).interfaceId)) {
140
- revert NotRegistryService();
141
- }
153
+ (
154
+ IRegistry.ObjectInfo memory info,
155
+ ObjectType domain,
156
+ VersionPart version
157
+ ) = _verifyService(service);
158
+
159
+ uint serviceIdx = _awaitingRegistration - 1;
160
+ address serviceAddress = _releaseInfo[version].addresses[serviceIdx];
161
+ // TODO temp, while typescript addresses computation is not implemented
162
+ /*if(address(service) != serviceAddress) {
163
+ revert ErrorReleaseManagerServiceAddressInvalid(service, serviceAddress);
164
+ }*/
165
+
166
+ _setServiceAuthorizations(
167
+ _releaseAccessManager[version],
168
+ // TODO temp, while typescript addresses computation is not implemented
169
+ address(service),//serviceAddress,
170
+ _releaseInfo[version].serviceRoles[serviceIdx],
171
+ _releaseInfo[version].functionRoles[serviceIdx],
172
+ _releaseInfo[version].selectors[serviceIdx]);
173
+
174
+ _awaitingRegistration = serviceIdx;
175
+ // checked in registry
176
+ _releaseInfo[version].domains.push(domain);
177
+
178
+ nftId = _registry.registerService(info, version, domain);
142
179
 
143
- // TODO unreliable! MUST guarantee the same authority -> how?
144
- address serviceAuthority = service.authority();
145
- if(serviceAuthority != authority()) {
146
- revert UnexpectedServiceAuthority(
147
- authority(),
148
- serviceAuthority);
149
- }
150
-
151
- IRegistry.ObjectInfo memory info = _getAndVerifyContractInfo(service, SERVICE(), msg.sender);
152
-
153
- VersionPart majorVersion = _next;
154
- ObjectType domain = REGISTRY();
155
- _verifyService(service, majorVersion, domain);
156
- _createRelease(service.getFunctionConfigs());
157
-
158
- nftId = _registry.registerService(info, majorVersion, domain);
159
-
160
- // external call
161
180
  service.linkToRegisteredNftId();
162
181
  }
163
182
 
164
- // TODO adding service to release -> synchronized with proxy upgrades or simple addServiceToRelease(service, version, selector)?
165
- // TODO removing service from release? -> set _active to false forever, but keep all other records?
166
- function registerService(IService service)
167
- external
168
- restricted // GIF_MANAGER_ROLE
169
- returns(NftId nftId)
183
+ function activateNextRelease()
184
+ external
185
+ restricted // GIF_ADMIN_ROLE
170
186
  {
171
- if(!service.supportsInterface(type(IService).interfaceId)) {
172
- revert NotService();
187
+ VersionPart version = _next;
188
+ address service = _registry.getServiceAddress(REGISTRY(), version);
189
+
190
+ // release exists, registry service is a MUST
191
+ //if(_releaseAccessManager[version] == address(0)) {
192
+ if(service == address(0)) {
193
+ revert ErrorReleaseManagerReleaseNotCreated(version);
194
+ }
195
+
196
+ // release fully deployed
197
+ if(_awaitingRegistration > 0) {
198
+ revert ErrorReleaseManagerReleaseRegistrationNotFinished(version, _awaitingRegistration);
173
199
  }
174
200
 
175
- IRegistry.ObjectInfo memory info = _getAndVerifyContractInfo(service, SERVICE(), msg.sender);
176
- VersionPart majorVersion = getNextVersion();
177
- ObjectType domain = _release[majorVersion].domains[_awaitingRegistration];// reversed registration order of services specified in RegistryService config
178
- _verifyService(service, majorVersion, domain);
179
-
180
- // setup and grant unique role if service does registrations
181
- bytes4[] memory selectors = _selectors[majorVersion][domain];
182
- address registryService = _registry.getServiceAddress(REGISTRY(), majorVersion);
183
- if(selectors.length > 0) {
184
- _accessManager.setAndGrantUniqueRole(
185
- address(service),
186
- registryService,
187
- selectors);
201
+ // release is not activated
202
+ if(_releaseInfo[version].activatedAt.gtz()) {
203
+ revert ErrorReleaseManagerReleaseAlreadyActivated(version);
188
204
  }
189
-
190
- _awaitingRegistration--;
191
205
 
192
- nftId = _registry.registerService(info, majorVersion, domain);
206
+ _latest = version;
193
207
 
194
- // external call
195
- service.linkToRegisteredNftId();
208
+ _active[service] = true;
209
+ _releaseInfo[version].activatedAt = TimestampLib.blockTimestamp();
210
+
211
+ emit LogReleaseActivation(version);
196
212
  }
197
213
 
198
214
  //--- view functions ----------------------------------------------------//
199
215
 
200
- function isActiveRegistryService(address service) external view returns(bool)
201
- {
216
+ function predictDeterministicAddress(
217
+ address implementation,
218
+ bytes32 salt,
219
+ address deployer
220
+ ) external pure returns (address predicted) {
221
+ return Clones.predictDeterministicAddress(implementation, salt, deployer);
222
+ }
223
+
224
+ function isActiveRegistryService(address service) external view returns(bool) {
202
225
  return _active[service];
203
226
  }
204
227
 
205
- function isValidRelease(VersionPart version) external view returns(bool)
206
- {
207
- return _valid[version];
228
+ function isValidRelease(VersionPart version) external view returns(bool) {
229
+ return _releaseInfo[version].activatedAt.gtz();
208
230
  }
209
231
 
210
- function getRegistry() external view returns(address)
211
- {
232
+ function getRegistry() external view returns(address) {
212
233
  return (address(_registry));
213
234
  }
214
235
 
215
- function getReleaseInfo(VersionPart version) external view returns(IRegistry.ReleaseInfo memory)
216
- {
217
- return _release[version];
236
+ function getReleaseInfo(VersionPart version) external view returns(IRegistry.ReleaseInfo memory) {
237
+ return _releaseInfo[version];
218
238
  }
219
239
 
220
- function getNextVersion() public view returns(VersionPart)
221
- {
240
+ function getNextVersion() public view returns(VersionPart) {
222
241
  return _next;
223
242
  }
224
243
 
@@ -230,99 +249,134 @@ contract ReleaseManager is AccessManaged
230
249
  return _initial;
231
250
  }
232
251
 
252
+ function getReleaseAccessManager(VersionPart version) external view returns(AccessManagerUpgradeableInitializeable) {
253
+ return _releaseAccessManager[version];
254
+ }
255
+
233
256
  //--- private functions ----------------------------------------------------//
234
257
 
235
- function _getAndVerifyContractInfo(
258
+ function _verifyService(IService service)
259
+ internal
260
+ returns(
261
+ IRegistry.ObjectInfo memory serviceInfo,
262
+ ObjectType serviceDomain,
263
+ VersionPart serviceVersion
264
+ )
265
+ {
266
+ if(!service.supportsInterface(type(IService).interfaceId)) {
267
+ revert ErrorReleaseManagerNotService(service);
268
+ }
269
+
270
+ address owner = msg.sender;
271
+ address serviceAuthority = service.authority();
272
+ serviceVersion = service.getVersion().toMajorPart();
273
+ serviceDomain = service.getDomain();// checked in registry
274
+ serviceInfo = service.getInitialInfo();
275
+
276
+ _verifyServiceInfo(service, serviceInfo, owner);
277
+
278
+ VersionPart releaseVersion = getNextVersion(); // never 0
279
+ address releaseAuthority = address(_releaseAccessManager[releaseVersion]); // can be zero if registering service when release is not created
280
+
281
+ // IMPORTANT: can not guarantee service access is actually controlled by authority
282
+ if(serviceAuthority != releaseAuthority) {
283
+ revert ErrorReleaseManagerServiceReleaseAuthorityMismatch(
284
+ service,
285
+ serviceAuthority,
286
+ releaseAuthority);
287
+ }
288
+
289
+ if(serviceVersion != releaseVersion) {
290
+ revert ErrorReleaseManagerServiceReleaseVersionMismatch(
291
+ service,
292
+ serviceVersion,
293
+ releaseVersion);
294
+ }
295
+ }
296
+
297
+ function _verifyServiceInfo(
236
298
  IService service,
237
- ObjectType expectedType,
299
+ IRegistry.ObjectInfo memory info,
238
300
  address expectedOwner // assume always valid, can not be 0
239
301
  )
240
302
  internal
241
- // view
242
- returns(
243
- IRegistry.ObjectInfo memory info
244
- )
303
+ view
245
304
  {
246
- info = service.getInitialInfo();
247
- info.objectAddress = address(service);
248
- info.isInterceptor = false; // service is never interceptor, at least now
305
+ if(info.objectAddress != address(service)) {
306
+ revert ErrorReleaseManagerServiceInfoAddressInvalid(service, address(service));
307
+ }
308
+
309
+ if(info.isInterceptor != false) { // service is never interceptor
310
+ revert ErrorReleaseManagerServiceInfoInterceptorInvalid(service, info.isInterceptor);
311
+ }
249
312
 
250
- if(info.objectType != expectedType) {// type is checked in registry anyway...but service logic may depend on expected value
251
- revert UnexpectedRegisterableType(expectedType, info.objectType);
313
+ if(info.objectType != SERVICE()) {// type is checked in registry anyway...but service logic may depend on expected value
314
+ revert ErrorReleaseManagerServiceInfoTypeInvalid(service, SERVICE(), info.objectType);
252
315
  }
253
316
 
254
317
  address owner = info.initialOwner;
255
318
 
256
319
  if(owner != expectedOwner) { // registerable owner protection
257
- revert NotRegisterableOwner(expectedOwner);
320
+ revert ErrorReleaseManagerServiceInfoOwnerInvalid(service, expectedOwner, owner);
258
321
  }
259
322
 
260
323
  if(owner == address(service)) {
261
- revert SelfRegistration();
324
+ revert ErrorReleaseManagerServiceSelfRegistration(service);
262
325
  }
263
326
 
264
327
  if(_registry.isRegistered(owner)) {
265
- revert RegisterableOwnerIsRegistered();
328
+ revert ErrorReleaseManagerServiceOwnerRegistered(service, owner);
266
329
  }
267
330
  }
268
331
 
269
- function _verifyService(
270
- IService service,
271
- VersionPart expectedVersion,
272
- ObjectType expectedDomain
332
+ function _verifyReleaseAuthorizations(
333
+ address[] memory serviceAddress,
334
+ RoleId[][] memory serviceRoles,
335
+ RoleId[][] memory functionRoles,
336
+ bytes4[][][] memory selectors
273
337
  )
274
338
  internal
275
339
  view
276
- returns(ObjectType)
277
340
  {
278
- Version version = service.getVersion();
279
- VersionPart majorVersion = version.toMajorPart();
280
- if(majorVersion != expectedVersion) {
281
- revert UnexpectedServiceVersion(expectedVersion, majorVersion);
282
- }
283
-
284
- if(service.getDomain() != expectedDomain) {
285
- revert UnexpectedServiceDomain(expectedDomain, service.getDomain());
341
+ for(uint serviceIdx = 0; serviceIdx < serviceAddress.length; serviceIdx++)
342
+ {
343
+ for(uint roleIdx = 0; roleIdx < serviceRoles[serviceIdx].length; roleIdx++)
344
+ {
345
+ RoleId role = serviceRoles[serviceIdx][roleIdx];
346
+ if(role == ADMIN_ROLE()) {
347
+ revert ErrorReleaseManagerServiceRoleInvalid(serviceAddress[serviceIdx], role);
348
+ }
349
+ }
286
350
  }
287
-
288
- return expectedDomain;
351
+ // TODO no duplicate service "domain" role per release
352
+ // TODO no duplicate service roles per service
353
+ // TODO no duplicate service function roles per service
354
+ // TODO no duplicate service function selectors per service
289
355
  }
290
356
 
291
- // TODO check if registry supports types specified in the config array
292
- function _createRelease(IRegistryService.FunctionConfig[] memory config)
357
+ function _setServiceAuthorizations(
358
+ IAccessManager accessManager,
359
+ address serviceAddress,
360
+ RoleId[] memory serviceRoles,
361
+ RoleId[] memory functionRoles,
362
+ bytes4[][] memory selectors
363
+ )
293
364
  internal
294
365
  {
295
- VersionPart version = getNextVersion();
296
-
297
- if(config.length == 0) {
298
- revert ConfigMissing();
299
- }
300
- // always in release
301
- _release[version].domains.push(REGISTRY());
302
- for(uint idx = 0; idx < config.length; idx++)
366
+ for(uint idx = 0; idx < functionRoles.length; idx++)
303
367
  {
304
- ObjectType domain = config[idx].serviceDomain;
305
- // not "registry service" / zero domain
306
- if(
307
- domain == REGISTRY() ||
308
- domain.eqz()
309
- ) { revert ConfigServiceDomainInvalid(idx, domain); }
310
-
311
- bytes4[] memory selectors = config[idx].selectors;
312
-
313
- // TODO can be zero -> e.g. duplicate domain, first with zero selector, second with non zero selector -> need to check _release[version].domains.contains(domain) instead
314
- // no overwrite
315
- if(_selectors[version][domain].length > 0) {
316
- revert SelectorAlreadyExists(version, domain);
317
- }
318
-
319
- _selectors[version][domain] = selectors;
320
- _release[version].domains.push(domain);
368
+ accessManager.setTargetFunctionRole(
369
+ serviceAddress,
370
+ selectors[idx],
371
+ functionRoles[idx].toInt());
321
372
  }
322
- // TODO set when activated?
323
- _release[version].createdAt = TimestampLib.blockTimestamp();
324
- //_release[version].updatedAt = TimestampLib.blockTimestamp();
325
373
 
326
- _awaitingRegistration = config.length;
374
+ for(uint idx = 0; idx < serviceRoles.length; idx++)
375
+ {
376
+ accessManager.grantRole(
377
+ serviceRoles[idx].toInt(),
378
+ serviceAddress,
379
+ 0);
380
+ }
327
381
  }
328
382
  }
@@ -26,15 +26,6 @@ abstract contract ComponentService is
26
26
  error ErrorComponentServiceSenderNotService(address sender);
27
27
  error ErrorComponentServiceComponentTypeInvalid(address component, ObjectType expectedType, ObjectType foundType);
28
28
 
29
- /// @dev modifier to check if caller is a registered service
30
- modifier onlyService() {
31
- address caller = msg.sender;
32
- if(!getRegistry().isRegisteredService(caller)) {
33
- revert ErrorComponentServiceSenderNotService(caller);
34
- }
35
- _;
36
- }
37
-
38
29
  // view functions
39
30
 
40
31
  function getRegistryService() public view virtual returns (IRegistryService) {
@@ -2,6 +2,7 @@
2
2
  pragma solidity ^0.8.20;
3
3
 
4
4
  import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
5
+ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
5
6
 
6
7
  import {Blocknumber, blockNumber} from "../type/Blocknumber.sol";
7
8
  import {IVersionable} from "./IVersionable.sol";
@@ -79,6 +80,31 @@ contract ProxyManager is
79
80
  emit LogProxyManagerVersionableDeployed(address(_proxy), initialImplementation);
80
81
  }
81
82
 
83
+ function deployDetermenistic(address initialImplementation, bytes memory initializationData, bytes32 salt)
84
+ public
85
+ virtual
86
+ onlyOwner()
87
+ returns (IVersionable versionable)
88
+ {
89
+ if (_versions.length > 0) {
90
+ revert ErrorProxyManagerAlreadyDeployed();
91
+ }
92
+
93
+ address currentProxyOwner = getOwner();
94
+ address initialProxyAdminOwner = address(this);
95
+
96
+ _proxy = new UpgradableProxyWithAdmin{salt: salt}(
97
+ initialImplementation,
98
+ initialProxyAdminOwner,
99
+ getDeployData(currentProxyOwner, initializationData)
100
+ );
101
+
102
+ versionable = IVersionable(address(_proxy));
103
+ _updateVersionHistory(versionable.getVersion(), initialImplementation, currentProxyOwner);
104
+
105
+ emit LogProxyManagerVersionableDeployed(address(_proxy), initialImplementation);
106
+ }
107
+
82
108
  /// @dev upgrade existing contract
83
109
  function upgrade(address newImplementation, bytes memory upgradeData)
84
110
  public
@@ -143,14 +143,17 @@ contract StakingService is
143
143
  virtual override
144
144
  initializer()
145
145
  {
146
- // TODO check this, might no longer be the way, refactor if necessary
147
- address registryAddress;
148
- (registryAddress,) = abi.decode(data, (address, address));
146
+ (
147
+ address registryAddress,,
148
+ //address managerAddress
149
+ address authority
150
+ ) = abi.decode(data, (address, address, address));
151
+
152
+ initializeService(registryAddress, authority, owner);
149
153
 
150
154
  StakingServiceStorage storage $ = _getStakingServiceStorage();
151
155
  $._poolService = IPoolService(_getServiceAddress(POOL()));
152
156
 
153
- initializeService(registryAddress, address(0), owner);
154
157
  registerInterface(type(IStakingService).interfaceId);
155
158
  }
156
159
 
@@ -13,15 +13,18 @@ contract StakingServiceManager is
13
13
 
14
14
  /// @dev initializes proxy manager with service implementation
15
15
  constructor(
16
- address registryAddress
16
+ address authority,
17
+ address registryAddress,
18
+ bytes32 salt
17
19
  )
18
20
  ProxyManager(registryAddress)
19
21
  {
20
- StakingService svc = new StakingService();
21
- bytes memory data = abi.encode(registryAddress, address(this));
22
- IVersionable versionable = deploy(
22
+ StakingService svc = new StakingService{salt: salt}();
23
+ bytes memory data = abi.encode(registryAddress, address(this), authority);
24
+ IVersionable versionable = deployDetermenistic(
23
25
  address(svc),
24
- data);
26
+ data,
27
+ salt);
25
28
 
26
29
  _stakingService = StakingService(address(versionable));
27
30
  }