Skip to content

Commit

Permalink
refactor Governance into AccessManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramarti committed Apr 10, 2024
1 parent 66a6a6a commit fb97fc5
Show file tree
Hide file tree
Showing 32 changed files with 309 additions and 839 deletions.
17 changes: 9 additions & 8 deletions contracts/LicenseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { ERC721EnumerableUpgradeable, ERC721Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol";
import { IERC721Metadata } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
// solhint-disable-next-line max-line-length
import { AccessManagedUpgradeable } from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";

import { ILicenseToken } from "./interfaces/ILicenseToken.sol";
import { ILicensingModule } from "./interfaces/modules/licensing/ILicensingModule.sol";
import { IDisputeModule } from "./interfaces/modules/dispute/IDisputeModule.sol";
import { Errors } from "./lib/Errors.sol";
import { GovernableUpgradeable } from "./governance/GovernableUpgradeable.sol";
import { ILicenseTemplate } from "./interfaces/modules/licensing/ILicenseTemplate.sol";

/// @title LicenseToken aka LNFT
contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, GovernableUpgradeable, UUPSUpgradeable {
contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManagedUpgradeable, UUPSUpgradeable {
using Strings for *;

/// @notice Emitted for metadata updates, per EIP-4906
Expand Down Expand Up @@ -49,17 +50,17 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, GovernableU
}

/// @dev Initializes the LicenseToken contract
function initialize(address governance, string memory imageUrl) public initializer {
function initialize(address accessManager, string memory imageUrl) public initializer {
__ERC721_init("Programmable IP License Token", "PILicenseToken");
__GovernableUpgradeable_init(governance);
__AccessManaged_init(accessManager);
__UUPSUpgradeable_init();
_getLicenseTokenStorage().imageUrl = imageUrl;
}

/// @notice Sets the LicensingModule address.
/// @dev Enforced to be only callable by the protocol admin
/// @param newLicensingModule The address of the LicensingModule
function setLicensingModule(address newLicensingModule) external onlyProtocolAdmin {
function setLicensingModule(address newLicensingModule) external restricted {
if (newLicensingModule == address(0)) {
revert Errors.LicenseToken__ZeroLicensingModule();
}
Expand All @@ -70,7 +71,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, GovernableU
/// @notice Sets the DisputeModule address.
/// @dev Enforced to be only callable by the protocol admin
/// @param newDisputeModule The address of the DisputeModule
function setDisputeModule(address newDisputeModule) external onlyProtocolAdmin {
function setDisputeModule(address newDisputeModule) external restricted {
if (newDisputeModule == address(0)) {
revert Errors.LicenseToken__ZeroDisputeModule();
}
Expand All @@ -81,7 +82,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, GovernableU
/// @dev Sets the Licensing Image URL.
/// @dev Enforced to be only callable by the protocol admin
/// @param url The URL of the Licensing Image
function setLicensingImageUrl(string calldata url) external onlyProtocolAdmin {
function setLicensingImageUrl(string calldata url) external restricted {
LicenseTokenStorage storage $ = _getLicenseTokenStorage();
$.imageUrl = url;
emit BatchMetadataUpdate(1, $.totalMintedTokens);
Expand Down Expand Up @@ -326,5 +327,5 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, GovernableU

/// @dev Hook to authorize the upgrade according to UUPSUpgradeable
/// @param newImplementation The address of the new implementation
function _authorizeUpgrade(address newImplementation) internal override onlyProtocolAdmin {}
function _authorizeUpgrade(address newImplementation) internal override restricted {}
}
33 changes: 15 additions & 18 deletions contracts/access/AccessController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
pragma solidity 0.8.23;

import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
// solhint-disable-next-line max-line-length
import { AccessManagedUpgradeable } from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";

import { IAccessController } from "../interfaces/access/IAccessController.sol";
import { IModuleRegistry } from "../interfaces/registries/IModuleRegistry.sol";
import { IIPAccountRegistry } from "../interfaces/registries/IIPAccountRegistry.sol";
import { IModuleRegistry } from "../interfaces/registries/IModuleRegistry.sol";
import { IPAccountChecker } from "../lib/registries/IPAccountChecker.sol";
import { IIPAccount } from "../interfaces/IIPAccount.sol";
import { GovernableUpgradeable } from "../governance/GovernableUpgradeable.sol";
import { AccessPermission } from "../lib/AccessPermission.sol";
import { Errors } from "../lib/Errors.sol";

Expand All @@ -28,7 +29,7 @@ import { Errors } from "../lib/Errors.sol";
/// - setPermission: Sets the permission for a specific function call.
/// - getPermission: Returns the permission level for a specific function call.
/// - checkPermission: Checks if a specific function call is allowed.
contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgradeable {
contract AccessController is IAccessController, AccessManagedUpgradeable, UUPSUpgradeable {
using IPAccountChecker for IIPAccountRegistry;

/// @dev The storage struct of AccessController.
Expand All @@ -54,16 +55,16 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
}

/// @notice initializer for this implementation contract
/// @param governance The address of the governance contract
function initialize(address governance) external initializer {
__GovernableUpgradeable_init(governance);
/// @param accessManaged The address of the governance contract
function initialize(address accessManaged) external initializer {
__AccessManaged_init(accessManaged);
}

/// @notice Sets the addresses of the IP account registry and the module registry
/// @dev TODO: figure out how to set these addresses in the constructor to make them immutable
/// @param ipAccountRegistry address of the IP account registry
/// @param moduleRegistry address of the module registry
function setAddresses(address ipAccountRegistry, address moduleRegistry) external onlyProtocolAdmin {
function setAddresses(address ipAccountRegistry, address moduleRegistry) external restricted {
AccessControllerStorage storage $ = _getAccessControllerStorage();
$.ipAccountRegistry = ipAccountRegistry;
$.moduleRegistry = moduleRegistry;
Expand All @@ -72,7 +73,8 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
/// @notice Sets a batch of permissions in a single transaction.
/// @dev This function allows setting multiple permissions at once. Pausable.
/// @param permissions An array of `Permission` structs, each representing the permission to be set.
function setBatchPermissions(AccessPermission.Permission[] memory permissions) external whenNotPaused {
function setBatchPermissions(AccessPermission.Permission[] memory permissions) external {
// TODO: removed pause.
for (uint256 i = 0; i < permissions.length; ) {
setPermission(
permissions[i].ipAccount,
Expand All @@ -93,7 +95,7 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
/// @param to The address that can be called by the `signer` (currently only modules can be `to`)
/// @param func The function selector of `to` that can be called by the `signer` on behalf of the `ipAccount`
/// @param permission The new permission level
function setGlobalPermission(address signer, address to, bytes4 func, uint8 permission) external onlyProtocolAdmin {
function setGlobalPermission(address signer, address to, bytes4 func, uint8 permission) external restricted {
if (signer == address(0)) {
revert Errors.AccessController__SignerIsZeroAddress();
}
Expand All @@ -119,13 +121,8 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
/// @param to The address that can be called by the `signer` (currently only modules can be `to`)
/// @param func The function selector of `to` that can be called by the `signer` on behalf of the `ipAccount`
/// @param permission The new permission level
function setPermission(
address ipAccount,
address signer,
address to,
bytes4 func,
uint8 permission
) public whenNotPaused {
function setPermission(address ipAccount, address signer, address to, bytes4 func, uint8 permission) public {
// TODO: Reintroduce pause
// IPAccount and signer does not support wildcard permission
if (ipAccount == address(0)) {
revert Errors.AccessController__IPAccountIsZeroAddress();
Expand Down Expand Up @@ -159,7 +156,7 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
/// @param to The address that can be called by the `signer` (currently only modules can be `to`)
/// @param func The function selector of `to` that can be called by the `signer` on behalf of the `ipAccount`
// solhint-disable code-complexity
function checkPermission(address ipAccount, address signer, address to, bytes4 func) external view whenNotPaused {
function checkPermission(address ipAccount, address signer, address to, bytes4 func) external view {
// The ipAccount is restricted to interact exclusively with registered modules.
// This includes initiating calls to these modules and receiving calls from them.
// Additionally, it can modify Permissions settings.
Expand Down Expand Up @@ -246,7 +243,7 @@ contract AccessController is IAccessController, GovernableUpgradeable, UUPSUpgra
}
}

/// @dev Hook to authorize the upgrade according to UUPSUgradeable
/// @dev Hook to authorize the upgrade according to UUPSUpgradeable
/// @param newImplementation The address of the new implementation
function _authorizeUpgrade(address newImplementation) internal override onlyProtocolAdmin {}
function _authorizeUpgrade(address newImplementation) internal override restricted {}
}
57 changes: 0 additions & 57 deletions contracts/governance/Governable.sol

This file was deleted.

81 changes: 0 additions & 81 deletions contracts/governance/GovernableUpgradeable.sol

This file was deleted.

44 changes: 0 additions & 44 deletions contracts/governance/Governance.sol

This file was deleted.

18 changes: 0 additions & 18 deletions contracts/interfaces/governance/IGovernable.sol

This file was deleted.

Loading

0 comments on commit fb97fc5

Please sign in to comment.