Skip to content

Commit

Permalink
fixed comments and added access control to license registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Nov 15, 2023
1 parent a07ce3f commit 30502ec
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 59 deletions.
33 changes: 0 additions & 33 deletions contracts/hooks/licensing/TermsHook.sol

This file was deleted.

2 changes: 2 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ library Errors {
error LicenseRegistry_UnknownLicenseId();
error LicenseRegistry_NotLicenseNFT();
error LicenseRegistry_InvalidIpa();
error LicenseRegistry_ZeroModuleRegistryAddress();
error LicenseRegistry_CallerNotLicensingModule();

////////////////////////////////////////////////////////////////////////////
// RelationshipModule //
Expand Down
5 changes: 5 additions & 0 deletions contracts/modules/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ contract ModuleRegistry is AccessControlled, Multicall {
return _protocolModules[moduleKey];
}

// Returns true if the provided address is a module.
function isModule(string calldata moduleKey, address caller_) external view returns (bool) {
return address(_protocolModules[moduleKey]) == caller_;
}

/// Execution entrypoint, callable by any address on its own behalf.
/// @param ipOrg_ address of the IPOrg, or address(0) for protocol-level stuff
/// @param moduleKey_ short module descriptor
Expand Down
28 changes: 15 additions & 13 deletions contracts/modules/licensing/LicenseCreatorModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TermsRepository } from "./TermsRepository.sol";
import { ShortString, ShortStrings } from "@openzeppelin/contracts/utils/ShortStrings.sol";
import { FixedSet } from "contracts/utils/FixedSet.sol";
import { IPAsset } from "contracts/lib/IPAsset.sol";
import { TermIds, TermData } from "contracts/lib/modules/ProtocolLicensingTerms.sol";
import { TermIds } from "contracts/lib/modules/ProtocolLicensingTerms.sol";

/// @title License Creator module
/// @notice Story Protocol module that:
Expand Down Expand Up @@ -62,7 +62,7 @@ contract LicenseCreatorModule is BaseModule, TermsRepository {
}

/// Get the number of terms configured for an ipOrg
/// @param commercial true for commercial terms, false for non-commercial terms
/// @param commercial_ true for commercial terms, false for non-commercial terms
/// @param ipOrg_ the ipOrg address
/// @return the number of terms configured for the ipOrg
function getTotalIpOrgTerms(bool commercial_, address ipOrg_) public view returns (uint256) {
Expand All @@ -74,32 +74,33 @@ contract LicenseCreatorModule is BaseModule, TermsRepository {
}

/// Check if an ipOrg has a term configured
/// @param commercial true for commercial terms, false for non-commercial terms
/// @param commercial_ true for commercial terms, false for non-commercial terms
/// @param ipOrg_ the ipOrg address
/// @param true if the term is configured, false otherwise
function ipOrgTermsContains(bool commercial_, address ipOrg_, ShortString termId) public view returns (bool) {
/// @param termId_ the term id
/// @return true if the term is configured, false otherwise
function ipOrgTermsContains(bool commercial_, address ipOrg_, ShortString termId_) public view returns (bool) {
if (commercial_) {
return _comIpOrgTermIds[ipOrg_].contains(termId);
return _comIpOrgTermIds[ipOrg_].contains(termId_);
} else {
return _nonComIpOrgTermIds[ipOrg_].contains(termId);
return _nonComIpOrgTermIds[ipOrg_].contains(termId_);
}
}

/// Get the data for a term configured for an ipOrg
/// @dev method will revert if the term is not configured
/// @param commercial true for commercial terms, false for non-commercial terms
/// @param commercial_ true for commercial terms, false for non-commercial terms
/// @param ipOrg_ the ipOrg address
/// @param termId the term id
/// @param termId_ the term id
/// @return the term data
function ipOrgTermData(bool commercial_, address ipOrg_, ShortString termId) public view returns (bytes memory) {
function ipOrgTermData(bool commercial_, address ipOrg_, ShortString termId_) public view returns (bytes memory) {
if (commercial_) {
uint256 index = _comIpOrgTermIds[ipOrg_].indexOf(termId);
uint256 index = _comIpOrgTermIds[ipOrg_].indexOf(termId_);
if (index == type(uint256).max) {
revert Errors.LicensingModule_ipOrgTermNotFound();
}
return _comIpOrgTermData[ipOrg_][index];
} else {
uint256 index = _nonComIpOrgTermIds[ipOrg_].indexOf(termId);
uint256 index = _nonComIpOrgTermIds[ipOrg_].indexOf(termId_);
if (index == type(uint256).max) {
revert Errors.LicensingModule_ipOrgTermNotFound();
}
Expand All @@ -111,7 +112,8 @@ contract LicenseCreatorModule is BaseModule, TermsRepository {
/// @param commercial_ true for commercial terms, false for non-commercial terms
/// @param ipOrg_ the ipOrg address
/// @param index_ the index
/// @return the term id and data
/// @return termId term Id
/// @return data the term data
function ipOrgTermsAt(bool commercial_, address ipOrg_, uint index_) public view returns (ShortString termId, bytes memory data) {
if (commercial_) {
return (_comIpOrgTermIds[ipOrg_].at(index_), _comIpOrgTermData[ipOrg_][index_]);
Expand Down
28 changes: 21 additions & 7 deletions contracts/modules/licensing/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { Licensing } from "contracts/lib/modules/Licensing.sol";
import { IPAssetRegistry } from "contracts/IPAssetRegistry.sol";
import { Errors } from "contracts/lib/Errors.sol";
import { ERC721 } from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import { ModuleRegistry } from "contracts/modules/ModuleRegistry.sol";
import { ModuleRegistryKeys } from "contracts/lib/modules/ModuleRegistryKeys.sol";

/// @title LicenseRegistry
/// @notice This contract is the source of truth for all licenses that are registered in the protocol.
Expand All @@ -27,14 +29,27 @@ contract LicenseRegistry is ERC721 {
uint256 private _licenseCount;

IPAssetRegistry public immutable IPA_REGISTRY;
ModuleRegistry public immutable MODULE_REGISTRY;

modifier onlyLicensingModule() {
if (!MODULE_REGISTRY.isModule(ModuleRegistryKeys.LICENSING_MODULE, msg.sender)) {
revert Errors.LicenseRegistry_CallerNotLicensingModule();
}
_;
}

constructor(
address ipaRegistry
address ipaRegistry_,
address moduleRegistry_
) ERC721("Story Protocol License NFT", "LNFT") {
if (ipaRegistry == address(0)) {
if (ipaRegistry_ == address(0)) {
revert Errors.LicenseRegistry_ZeroIpaRegistryAddress();
}
IPA_REGISTRY = IPAssetRegistry(ipaRegistry);
IPA_REGISTRY = IPAssetRegistry(ipaRegistry_);
if (moduleRegistry_ == address(0)) {
revert Errors.LicenseRegistry_ZeroModuleRegistryAddress();
}
MODULE_REGISTRY = ModuleRegistry(moduleRegistry_);
}

/// Creates a License bound to a certain IPA
Expand All @@ -44,7 +59,7 @@ contract LicenseRegistry is ERC721 {
function addBoundToIpaLicense(
Licensing.RegistryAddition memory params_,
uint256 ipaId_
) external returns (uint256) {
) external onlyLicensingModule returns (uint256) {
// TODO statuses
if (IPA_REGISTRY.ipAssetStatus(ipaId_) == 0) {
revert Errors.LicenseRegistry_InvalidIpa();
Expand Down Expand Up @@ -73,7 +88,7 @@ contract LicenseRegistry is ERC721 {
function addTradeableLicense(
Licensing.RegistryAddition memory params_,
address licensee_
) external returns (uint256) {
) external onlyLicensingModule returns (uint256) {
_addLicense(
Licensing.License({
isCommercial: params_.isCommercial,
Expand Down Expand Up @@ -128,8 +143,7 @@ contract LicenseRegistry is ERC721 {
/// Burns a license NFT and binds the license to an IPA
/// @param licenseId_ id of the license NFT
/// @param ipaId_ id of the IPA
function boundLnftToIpa(uint256 licenseId_, uint256 ipaId_) external {
// TODO add Authorization
function boundLnftToIpa(uint256 licenseId_, uint256 ipaId_) external onlyLicensingModule {
Licensing.License memory license_ = _licenses[licenseId_];
if (license_.licenseeType != Licensing.LicenseeType.LNFTHolder) {
revert Errors.LicenseRegistry_NotLicenseNFT();
Expand Down
3 changes: 1 addition & 2 deletions contracts/modules/licensing/ProtocolTermsHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
pragma solidity ^0.8.19;

import { Licensing } from "contracts/lib/modules/Licensing.sol";
import { TermsHook } from "contracts/hooks/licensing/TermsHook.sol";
import { IHook } from "contracts/interfaces/hooks/base/IHook.sol";

library ProtocolTermsHelper {

function _getExcludedCategoriesTerm(
Licensing.CommercialStatus comStatus_,
TermsHook hook
IHook hook
) internal pure returns (Licensing.LicensingTerm memory) {
return Licensing.LicensingTerm({
comStatus: comStatus_,
Expand Down
5 changes: 1 addition & 4 deletions test/foundry/utils/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ShortString, ShortStrings } from "@openzeppelin/contracts/utils/ShortSt
import { ShortStringOps } from "contracts/utils/ShortStringOps.sol";
import { AccessControl } from "contracts/lib/AccessControl.sol";
import { ModuleRegistryKeys } from "contracts/lib/modules/ModuleRegistryKeys.sol";
import { TermsHook } from "contracts/hooks/licensing/TermsHook.sol";
// On active refactor

// import { Licensing } from "contracts/lib/modules/Licensing.sol";
Expand All @@ -41,7 +40,6 @@ contract BaseTest is BaseTestUtils, ProxyHelper, AccessControlHelper {
StoryProtocol public spg;
LicenseCreatorModule public licensingModule;
LicenseRegistry public licenseRegistry;
TermsHook public termsHook;

address public defaultCollectNftImpl;
address public collectModuleImpl;
Expand Down Expand Up @@ -80,7 +78,7 @@ contract BaseTest is BaseTestUtils, ProxyHelper, AccessControlHelper {
_grantRole(vm, AccessControl.MODULE_REGISTRAR_ROLE, address(this));

// Create Licensing contracts
licenseRegistry = new LicenseRegistry(address(registry));
licenseRegistry = new LicenseRegistry(address(registry), address(moduleRegistry));
licensingModule = new LicenseCreatorModule(
BaseModule.ModuleConstruction({
ipaRegistry: registry,
Expand All @@ -89,7 +87,6 @@ contract BaseTest is BaseTestUtils, ProxyHelper, AccessControlHelper {
})
);
moduleRegistry.registerProtocolModule(ModuleRegistryKeys.LICENSING_MODULE, licensingModule);
termsHook = new TermsHook(address(accessControl));

// Create Relationship Module
relationshipModule = new RelationshipModule(
Expand Down

0 comments on commit 30502ec

Please sign in to comment.