Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectInfo struct: move out intialOwner and data, add objectRelease #691

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions contracts/accounting/AccountingService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ contract AccountingService is
)
internal
virtual override
initializer()
onlyInitializing()
{
(
address authority,
address registry
) = abi.decode(data, (address, address));
address authority
) = abi.decode(data, (address));

__Service_init(authority, registry, owner);
__Service_init(authority, owner);
_registerInterface(type(IAccountingService).interfaceId);
}

Expand Down Expand Up @@ -256,7 +255,7 @@ contract AccountingService is
internal
virtual
{
emit LogComponentServiceUpdateFee(
emit LogAccountingServiceUpdateFee(
productNftId,
name,
feeBefore.fractionalFee,
Expand Down
10 changes: 4 additions & 6 deletions contracts/accounting/AccountingServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {AccountingService} from "./AccountingService.sol";
import {IVersionable} from "../upgradeability/IVersionable.sol";
import {IUpgradeable} from "../upgradeability/IUpgradeable.sol";
import {ProxyManager} from "../upgradeability/ProxyManager.sol";

contract AccountingServiceManager is ProxyManager {
Expand All @@ -10,21 +10,19 @@
AccountingService private _accountingService;

/// @dev initializes proxy manager with service implementation
constructor(

Check warning on line 13 in contracts/accounting/AccountingServiceManager.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Explicitly mark visibility in function (Set ignoreConstructors to true if using solidity >=0.7.0)
address authority,
address registry,
bytes32 salt
)
{
AccountingService svc = new AccountingService();
bytes memory data = abi.encode(authority, registry);
IVersionable versionable = initialize(
registry,
bytes memory data = abi.encode(authority);
IUpgradeable upgradeable = initialize(
address(svc),
data,
salt);

_accountingService = AccountingService(address(versionable));
_accountingService = AccountingService(address(upgradeable));
}

//--- view functions ----------------------------------------------------//
Expand Down
2 changes: 1 addition & 1 deletion contracts/accounting/IAccountingService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {UFixed} from "../type/UFixed.sol";
interface IAccountingService is
IService
{
event LogComponentServiceUpdateFee(
event LogAccountingServiceUpdateFee(
NftId nftId,
string feeName,
UFixed previousFractionalFee,
Expand Down
41 changes: 22 additions & 19 deletions contracts/authorization/AccessAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
import {IAccess} from "./IAccess.sol";
import {IAccessAdmin} from "./IAccessAdmin.sol";
import {IAuthorization} from "./IAuthorization.sol";
import {IRegistry} from "../registry/IRegistry.sol";
import {IServiceAuthorization} from "./IServiceAuthorization.sol";

import {AccessAdminLib} from "./AccessAdminLib.sol";
import {AccessManagerCloneable} from "./AccessManagerCloneable.sol";
import {Blocknumber, BlocknumberLib} from "../type/Blocknumber.sol";
import {ContractLib} from "../shared/ContractLib.sol";
import {NftId, NftIdLib} from "../type/NftId.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType} from "../type/ObjectType.sol";

Check warning on line 17 in contracts/authorization/AccessAdmin.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

imported name ObjectType is not used
import {RoleId, RoleIdLib, ADMIN_ROLE, PUBLIC_ROLE} from "../type/RoleId.sol";
import {RegistryLinked} from "../shared/RegistryLinked.sol";
import {Selector, SelectorSetLib} from "../type/Selector.sol";
import {Str, StrLib} from "../type/String.sol";
import {TimestampLib} from "../type/Timestamp.sol";
import {VersionPart} from "../type/Version.sol";
import {VersionPartLib, VersionPart} from "../type/Version.sol";


/**
Expand All @@ -30,6 +30,7 @@
*/
contract AccessAdmin is
AccessManagedUpgradeable,
RegistryLinked,
IAccessAdmin
{
using EnumerableSet for EnumerableSet.AddressSet;
Expand Down Expand Up @@ -91,12 +92,16 @@
/// Internally initializes access manager with this admin and creates basic role setup.
function initialize(
address authority,
string memory adminName
string memory adminName,
VersionPart release
)
public
initializer()
{
__AccessAdmin_init(authority, adminName);
if(_getInitializedVersion() != 0) {
revert InvalidInitialization();
}

__AccessAdmin_init(authority, adminName, release);
}


Expand All @@ -104,32 +109,34 @@
/// IMPORTANT
/// - cloning of an access admin and initialization MUST be done in the same tx.
/// - this function as well as any completeSetup functions MUST be called in the same tx.
function __AccessAdmin_init(

Check warning on line 112 in contracts/authorization/AccessAdmin.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Function name must be in mixedCase
address authority,
string memory adminName
string memory adminName,
VersionPart release
)
internal
onlyInitializing()
reinitializer(release.toInt())
{
AccessAdminLib.checkInitParameters(authority, adminName);

_authority = AccessManagerCloneable(authority);
_authority.initialize(address(this));
_authority.initialize(address(this), release);

// delayed additional check for authority after its initialization
if (!ContractLib.isAuthority(authority)) {
revert ErrorAccessAdminAccessManagerNotAccessManager(authority);
}

// effects
// set and initialize this access manager contract as
// set and initialize this contract as
// the admin (ADMIN_ROLE) of the provided authority
__AccessManaged_init(authority);

// set name for logging
_adminName = adminName;

// set initial linked NFT ID to zero
_linkedNftId = NftIdLib.zero();
//_linkedNftId = NftIdLib.zero();

// setup admin role
_createRoleUnchecked(
Expand All @@ -149,12 +156,7 @@
//--- view functions for access admin ---------------------------------------//

function getRelease() public view virtual returns (VersionPart release) {
return _authority.getRelease();
}


function getRegistry() public view returns (IRegistry registry) {
return _authority.getRegistry();
return VersionPartLib.toVersionPart(uint8(_getInitializedVersion()));
}


Expand Down Expand Up @@ -298,11 +300,12 @@
//--- internal/private functions -------------------------------------------------//

function _linkToNftOwnable(address registerable) internal {
if (!getRegistry().isRegistered(registerable)) {
NftId nftId = _getRegistry().getNftIdForAddress(registerable);
if (nftId.eqz()) {
revert ErrorAccessAdminNotRegistered(registerable);
}

_linkedNftId = getRegistry().getNftIdForAddress(registerable);
_linkedNftId = nftId;
}


Expand Down
21 changes: 12 additions & 9 deletions contracts/authorization/AccessAdminLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
uint64 public constant CUSTOM_ROLE_MIN = 1000000;


function ADMIN_ROLE_NAME() public pure returns (string memory) {

Check warning on line 46 in contracts/authorization/AccessAdminLib.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Function name must be in mixedCase
return "AdminRole";
}

Expand All @@ -53,7 +53,7 @@
}


function PUBLIC_ROLE_NAME() public pure returns (string memory) {

Check warning on line 56 in contracts/authorization/AccessAdminLib.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Function name must be in mixedCase
return "PublicRole";
}

Expand Down Expand Up @@ -336,9 +336,9 @@
view
returns (IAuthorization componentAuthorization)
{
checkIsRegistered(address(accessAdmin.getRegistry()), componentAddress, expectedType);

VersionPart expecteRelease = accessAdmin.getRelease();
checkIsRegistered(componentAddress, expectedType, expecteRelease);

IAuthorizedComponent component = IAuthorizedComponent(componentAddress);
componentAuthorization = component.getAuthorization();

Expand Down Expand Up @@ -436,22 +436,25 @@


function checkIsRegistered(
address registry,
address target,
ObjectType expectedType
ObjectType expectedType,
VersionPart expectedRelease
)
public
view
{
checkRegistry(registry);
IRegistry.ObjectInfo memory info = ContractLib.getRegistry().getObjectInfo(target);

ObjectType tagetType = IRegistry(registry).getObjectInfo(target).objectType;
if (tagetType.eqz()) {
if (info.objectType.eqz()) {
revert IAccessAdmin.ErrorAccessAdminNotRegistered(target);
}

if (tagetType != expectedType) {
revert IAccessAdmin.ErrorAccessAdminTargetTypeMismatch(target, expectedType, tagetType);
if (info.objectType != expectedType) {
revert IAccessAdmin.ErrorAccessAdminTargetTypeMismatch(target, expectedType, info.objectType);
}

if (info.release != expectedRelease) {
revert IAccessAdmin.ErrorAccessAdminTargetReleaseMismatch(target, expectedRelease, info.release);
}
}

Expand Down
72 changes: 24 additions & 48 deletions contracts/authorization/AccessManagerCloneable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
import {IAccessManager} from "@openzeppelin/contracts/access/manager/IAccessManager.sol";

import {IAccessAdmin} from "./IAccessAdmin.sol";

Check warning on line 7 in contracts/authorization/AccessManagerCloneable.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

imported name IAccessAdmin is not used
import {InitializableERC165} from "../shared/InitializableERC165.sol";
import {RegistryLinked} from "../shared/RegistryLinked.sol";
import {VersionPart} from "../type/Version.sol";
import {VersionPartLib, VersionPart} from "../type/Version.sol";


/// @dev An AccessManager based on OpenZeppelin that is cloneable and has a central lock property.
/// The lock property allows to lock all services of a release in a central place.
/// Cloned by upon release preparation and instance cloning.
contract AccessManagerCloneable is
AccessManagerUpgradeable,
InitializableERC165,
RegistryLinked
InitializableERC165
{
error ErrorAccessManagerCallerNotAdmin(address caller);
error ErrorAccessManagerRegistryAlreadySet(address registry);
Expand All @@ -24,7 +23,6 @@
error ErrorAccessManagerTargetAdminLocked(address target);
error ErrorAccessManagerCallerAdminLocked(address caller);

VersionPart private _release;
bool private _isLocked;


Expand All @@ -36,34 +34,36 @@
_;
}


function initialize(address admin)
function initialize(address adminAddress, VersionPart release)
public
initializer()

{
__ERC165_init();
__AccessManager_init(admin);
if(_getInitializedVersion() != 0) {
revert InvalidInitialization();
}

_registerInterface(type(IAccessManager).interfaceId);
AccessManagerCloneable_init(adminAddress, release);
}


/// @dev Completes the setup of the access manager.
/// Links the access manager to the registry and sets the release version.
function completeSetup(
address registry,
function AccessManagerCloneable_init(

Check warning on line 48 in contracts/authorization/AccessManagerCloneable.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Function name must be in mixedCase
address admin,
VersionPart release
)
external
onlyAdminRole
reinitializer(uint64(release.toInt()))
internal
reinitializer(release.toInt())
{
_checkAndSetRegistry(registry);
_checkAndSetRelease(release);
if (!release.isValidRelease()) {
revert ErrorAccessManagerInvalidRelease(release);
}

__ERC165_init();
__AccessManager_init(admin);

_registerInterface(type(IAccessManager).interfaceId);
}

/// @dev Returns true if the caller is authorized to call the target with the given selector and the manager lock is not set to locked.
/// Feturn values as in OpenZeppelin AccessManager.
/// Return values as in OpenZeppelin AccessManager.
/// For a locked manager the function reverts with ErrorAccessManagerTargetAdminLocked.
function canCall(
address caller,
Expand Down Expand Up @@ -101,10 +101,10 @@
/// For the registry admin release 3 is returned.
/// For the release admin and the instance admin the actual release version is returned.
function getRelease() external view returns (VersionPart release) {
return _release;
return VersionPartLib.toVersionPart(
uint8(_getInitializedVersion()));
}


/// @dev Returns true iff all contracts of this access manager are locked.
function isLocked()
public
Expand All @@ -113,28 +113,4 @@
{
return _isLocked;
}


function _checkAndSetRelease(VersionPart release)
internal
{
if (!release.isValidRelease()) {
revert ErrorAccessManagerInvalidRelease(release);
}

_release = release;
}


function _checkAndSetRegistry(address registry)
internal
{
// checks
if(address(getRegistry()) != address(0)) {
revert ErrorAccessManagerRegistryAlreadySet(address(getRegistry()) );
}

// effects
__RegistryLinked_init(registry);
}
}
4 changes: 2 additions & 2 deletions contracts/authorization/Authorization.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {RoleId, RoleIdLib} from "../type/RoleId.sol";
import {ServiceAuthorization} from "../authorization/ServiceAuthorization.sol";
import {Str, StrLib} from "../type/String.sol";

import {VersionPart} from "../type/Version.sol";

contract Authorization is
ServiceAuthorization,
Expand All @@ -27,10 +27,10 @@
Str internal _tokenHandlerTarget;


constructor(

Check warning on line 30 in contracts/authorization/Authorization.sol

View workflow job for this annotation

GitHub Actions / Build and test (Hardhat)

Explicitly mark visibility in function (Set ignoreConstructors to true if using solidity >=0.7.0)
string memory mainTargetName,
ObjectType domain,
uint8 release,
VersionPart release,
string memory commitHash,
IAccess.TargetType targetType,
bool includeTokenHandler
Expand Down
Loading