Skip to content

Commit

Permalink
determenistic release
Browse files Browse the repository at this point in the history
  • Loading branch information
rapidddenis committed Apr 13, 2024
1 parent 8e4a894 commit a9dbe12
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 117 deletions.
15 changes: 9 additions & 6 deletions contracts/distribution/DistributionServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ contract DistributionServiceManager is ProxyManager {

/// @dev initializes proxy manager with distribution service implementation and deploys instance
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
DistributionService distSrv = new DistributionService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
DistributionService distSrv = new DistributionService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(distSrv),
data);
data,
salt);

_distributionService = DistributionService(address(versionable));

Expand Down
15 changes: 9 additions & 6 deletions contracts/instance/InstanceServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ contract InstanceServiceManager is ProxyManager {

/// @dev initializes proxy manager with instance service implementation and deploys instance
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
InstanceService instSrv = new InstanceService();
InstanceService instSrv = new InstanceService{salt: salt}();
// bytes memory initCode = type(InstanceService).creationCode;
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(instSrv),
data);
data,
salt);

_instanceService = InstanceService(address(versionable));

Expand Down
15 changes: 9 additions & 6 deletions contracts/pool/BundleServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ contract BundleServiceManager is ProxyManager {

/// @dev initializes proxy manager with pool service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
BundleService bundleSrv = new BundleService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
BundleService bundleSrv = new BundleService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(bundleSrv),
data);
data,
salt);

_bundleService = BundleService(address(versionable));

Expand Down
15 changes: 9 additions & 6 deletions contracts/pool/PoolServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ contract PoolServiceManager is ProxyManager {

/// @dev initializes proxy manager with pool service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
PoolService poolSrv = new PoolService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
PoolService poolSrv = new PoolService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(poolSrv),
data);
data,
salt);

_poolService = PoolService(address(versionable));

Expand Down
15 changes: 9 additions & 6 deletions contracts/product/ApplicationServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ contract ApplicationServiceManager is ProxyManager {

/// @dev initializes proxy manager with service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
ApplicationService svc = new ApplicationService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
ApplicationService svc = new ApplicationService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(svc),
data);
data,
salt);

_applicationService = ApplicationService(address(versionable));
}
Expand Down
15 changes: 9 additions & 6 deletions contracts/product/ClaimServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ contract ClaimServiceManager is ProxyManager {

/// @dev initializes proxy manager with service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
ClaimService svc = new ClaimService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
ClaimService svc = new ClaimService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(svc),
data);
data,
salt);

_claimService = ClaimService(address(versionable));
}
Expand Down
15 changes: 9 additions & 6 deletions contracts/product/PolicyServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ contract PolicyServiceManager is ProxyManager {

/// @dev initializes proxy manager with product service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
PolicyService svc = new PolicyService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
PolicyService svc = new PolicyService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(svc),
data);
data,
salt);

_policyService = PolicyService(address(versionable));

Expand Down
27 changes: 9 additions & 18 deletions contracts/product/PricingServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,22 @@ contract PricingServiceManager is ProxyManager {

PricingService private _pricingService;

/// @dev initializes proxy manager with distribution service implementation and deploys instance
/// @dev initializes proxy manager with pricing service implementation and deploys instance
constructor(
address registryAddress
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
PricingService pricingSrv = new PricingService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
PricingService pricingSrv = new PricingService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(pricingSrv),
data);
data,
salt);

_pricingService = PricingService(address(versionable));

// TODO `thi` must have a role or own nft to register service
//Registry registry = Registry(registryAddress);
//address registryServiceAddress = registry.getServiceAddress(REGISTRY(), _distributionService.getMajorVersion());
//RegistryService registryService = RegistryService(registryServiceAddress);
//registryService.registerService(_distributionService);

// TODO no nft to link yet
// link ownership of instance service manager ot nft owner of instance service
//_linkToNftOwnable(
// address(registryAddress),
// address(_distributionService));
}

//--- view functions ----------------------------------------------------//
Expand Down
15 changes: 9 additions & 6 deletions contracts/product/ProductServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ contract ProductServiceManager is ProxyManager {

/// @dev initializes proxy manager with product service implementation
constructor(
address registryAddress
)
address authority,
address registryAddress,
bytes32 salt
)
ProxyManager(registryAddress)
{
ProductService svc = new ProductService();
bytes memory data = abi.encode(registryAddress, address(this));
IVersionable versionable = deploy(
ProductService svc = new ProductService{salt: salt}();
bytes memory data = abi.encode(registryAddress, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(svc),
data);
data,
salt);

_productService = ProductService(address(versionable));

Expand Down
24 changes: 15 additions & 9 deletions contracts/registry/RegistryServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.20;

import {AccessManager} from "@openzeppelin/contracts/access/manager/AccessManager.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

import {Registry} from "./Registry.sol";
import {IVersionable} from "../shared/IVersionable.sol";
Expand All @@ -18,20 +19,25 @@ contract RegistryServiceManager is
RegistryService private immutable _registryService;

/// @dev initializes proxy manager with registry service implementation and deploys registry
//registryServiceManager = new RegistryServiceManager{salt: config.CONFIG_SALT()}(releaseAccessManager, registryAddress, config.CONFIG_SALT());
constructor(
address initialAuthority, // used by implementation
address registryAddress) // used by implementation
ProxyManager(registryAddress)
address authority, // used by implementation
address registry, // used by implementation
bytes32 salt
)
ProxyManager(registry)
{
require(initialAuthority > address(0), "RegistryServiceManager: initial authority is 0");
require(registryAddress > address(0), "RegistryServiceManager: registry is 0");
require(authority > address(0), "RegistryServiceManager: initial authority is 0");
require(registry > address(0), "RegistryServiceManager: registry is 0");

// implementation's initializer func `data` argument
RegistryService srv = new RegistryService();
bytes memory data = abi.encode(registryAddress, initialAuthority);
IVersionable versionable = deploy(
//RegistryService srv = new RegistryService{salt: salt}();
RegistryService srv = new RegistryService{ salt: salt }();
bytes memory data = abi.encode(registry, address(this), authority);
IVersionable versionable = deployDetermenistic(
address(srv),
data);
data,
salt);

_registryService = RegistryService(address(versionable));

Expand Down
26 changes: 26 additions & 0 deletions contracts/shared/ProxyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.20;

import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";

import {Blocknumber, blockNumber} from "../type/Blocknumber.sol";
import {IVersionable} from "./IVersionable.sol";
Expand Down Expand Up @@ -79,6 +80,31 @@ contract ProxyManager is
emit LogProxyManagerVersionableDeployed(address(_proxy), initialImplementation);
}

function deployDetermenistic(address initialImplementation, bytes memory initializationData, bytes32 salt)
public
virtual
onlyOwner()
returns (IVersionable versionable)
{
if (_versions.length > 0) {
revert ErrorProxyManagerAlreadyDeployed();
}

address currentProxyOwner = getOwner();
address initialProxyAdminOwner = address(this);

_proxy = new UpgradableProxyWithAdmin{salt: salt}(
initialImplementation,
initialProxyAdminOwner,
getDeployData(currentProxyOwner, initializationData)
);

versionable = IVersionable(address(_proxy));
_updateVersionHistory(versionable.getVersion(), initialImplementation, currentProxyOwner);

emit LogProxyManagerVersionableDeployed(address(_proxy), initialImplementation);
}

/// @dev upgrade existing contract
function upgrade(address newImplementation, bytes memory upgradeData)
public
Expand Down
5 changes: 3 additions & 2 deletions contracts/type/RoleId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ function POLICY_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId
function CLAIM_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(2420); }
function BUNDLE_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(2500); }
function INSTANCE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(2600); }
function REGISTRY_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(2700); }
function PRICING_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(2800); }

function GIF_ADMIN_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(1500); }
function GIF_MANAGER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(1600); }
function RELEASE_MANAGER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(1700); }
function GIF_MANAGER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(1600); }

// @dev Returns true iff role ids a and b are identical
function eqRoleId(RoleId a, RoleId b) pure returns (bool isSame) {
Expand Down
Loading

0 comments on commit a9dbe12

Please sign in to comment.