Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Simplify registration proccess #51

Merged
merged 7 commits into from
Feb 1, 2024
Merged
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
10 changes: 10 additions & 0 deletions contracts/interfaces/licensing/IPolicyFrameworkManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import { IPolicyVerifier } from "contracts/interfaces/licensing/IPolicyVerifier.
/// @notice Interface to define a policy framework contract, that will
/// register itself into the LicenseRegistry to format policy into the LicenseRegistry
interface IPolicyFrameworkManager is IPolicyVerifier {
Ramarti marked this conversation as resolved.
Show resolved Hide resolved

// TODO: move here the interfaces for verification and sunset IPolicyVerifier

/// @notice Name to be show in LNFT metadata
function name() external view returns(string memory);
/// @notice URL to the off chain legal agreement template text
function licenseTextUrl() external view returns(string memory);
/// @notice address of Story Protocol license registry
function licenseRegistry() external view returns (address);
/// @notice called by the LicenseRegistry uri(uint256) method.
/// Must return ERC1155 OpenSea standard compliant metadata
function policyToJson(bytes memory policyData) external view returns (string memory);
}
8 changes: 2 additions & 6 deletions contracts/interfaces/licensing/IUMLPolicyFrameworkManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ struct UMLPolicy {
/// @title IUMLPolicyFrameworkManager
/// @notice Defines the interface for a Policy Framework Manager compliant with the UML standard
interface IUMLPolicyFrameworkManager is IPolicyFrameworkManager {

/// @notice Emitted when a new policy is added to the registry
event UMLPolicyAdded(uint256 indexed policyId, UMLPolicy policy);

/// @notice Adds a new policy to the registry
/// @notice Registers a new policy to the registry
/// @dev Must encode the policy into bytes to be stored in the LicenseRegistry
/// @param umlPolicy UMLPolicy compliant licensing term values
function addPolicy(UMLPolicy calldata umlPolicy) external returns (uint256 policyId);
function registerPolicy(UMLPolicy calldata umlPolicy) external returns (uint256 policyId);
/// @notice Fetchs a policy from the registry, decoding the raw bytes into a UMLPolicy struct
/// @param policyId The ID of the policy to fetch
/// @return policy The UMLPolicy struct
Expand Down
103 changes: 59 additions & 44 deletions contracts/interfaces/registries/ILicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ import { Licensing } from "contracts/lib/Licensing.sol";
/// - Verifying linking parameters (through the ILinkParamVerifier interface implementation by the policy framework)
/// - Verifying policy parameters (through the IPolicyVerifier interface implementation by the policy framework)
interface ILicenseRegistry {

/// @notice Emitted when a policy framework is created by registering a policy framework manager
/// @param creator The address that created the policy framework
/// @param frameworkId The id of the policy framework
/// @param framework The address of the IPolicyFrameworkManager
/// @param framework The policy framework data
event PolicyFrameworkCreated(
address indexed creator,
uint256 indexed frameworkId,
Licensing.PolicyFramework framework
event PolicyFrameworkRegistered(
address indexed framework,
string name,
string licenseTextUrl
);
/// @notice Emitted when a policy is added to the contract.
/// @param creator The address that created the policy
/// @notice Emitted when a policy is added to the contract
/// @param policyFrameworkManager The address that created the policy
/// @param policyId The id of the policy
/// @param policy The policy data
event PolicyCreated(address indexed creator, uint256 indexed policyId, Licensing.Policy policy);
/// @param policy The encoded policy data
event PolicyRegistered(
address indexed policyFrameworkManager,
uint256 indexed policyId,
bytes policy
);

/// @notice Emitted when a policy is added to an IP
/// @param caller The address that called the function
Expand Down Expand Up @@ -64,23 +66,24 @@ interface ILicenseRegistry {
/// @param parentIpId The id of the parent IP
event IpIdLinkedToParent(address indexed caller, address indexed ipId, address indexed parentIpId);

/// @notice registers a policy framework into the contract
/// @param fw The policy framework data
/// @return frameworkId The id of the policy framework
function addPolicyFramework(Licensing.PolicyFramework calldata fw) external returns (uint256 frameworkId);
/// @notice Registers a policy framework manager into the contract, so it can add policy data for
/// licenses.
/// @param manager the address of the manager. Will be ERC165 checked for IPolicyFrameworkManager
function registerPolicyFrameworkManager(address manager) external;

/// @notice registers a policy into the contract
/// @param pol The policy data
/// @return policyId The id of the policy
function addPolicy(Licensing.Policy memory pol) external returns (uint256 policyId);
/// @notice Registers a policy into the contract. MUST be called by a registered
/// framework or it will revert. The policy data and its integrity must be
/// verified by the policy framework manager.
/// @param data The policy data
function registerPolicy(bytes memory data) external returns (uint256 policyId);

/// @notice adds a policy to an IP policy list
/// @notice Adds a policy to an IP policy list
/// @param ipId The id of the IP
/// @param polId The id of the policy
/// @return indexOnIpId The index of the policy in the IP's policy list
function addPolicyToIp(address ipId, uint256 polId) external returns (uint256 indexOnIpId);

/// @notice mints a license to create derivative IP
/// @notice Mints a license to create derivative IP
/// @param policyId The id of the policy with the licensing parameters
/// @param licensorIpId The id of the licensor IP
/// @param amount The amount of licenses to mint
Expand All @@ -92,7 +95,7 @@ interface ILicenseRegistry {
address receiver
) external returns (uint256 licenseId);

/// @notice links an IP to its parent IP, burning the license NFT and the policy allows it
/// @notice Links an IP to its parent IP, burning the license NFT and the policy allows it
/// @param licenseId The id of the license to burn
/// @param childIpId The id of the child IP
/// @param holder The address that holds the license
Expand All @@ -102,43 +105,55 @@ interface ILicenseRegistry {
/// Getters
///

/// @notice gets total number of policy frameworks in the contract
function totalFrameworks() external view returns (uint256);
/// @notice gets policy framework data by id
function framework(uint256 frameworkId) external view returns (Licensing.PolicyFramework memory);
/// @notice gets policy framework license template URL by id
function frameworkUrl(uint256 frameworkId) external view returns (string memory);
/// @notice gets total number of policies (framework parameter configurations) in the contract
/// @notice True if the framework address is registered in LicenseRegistry
function isFrameworkRegistered(address framework) external view returns (bool);

/// @notice Gets total number of policies (framework parameter configurations) in the contract
function totalPolicies() external view returns (uint256);
/// @notice gets policy data by id

/// @notice Gets policy data by id
function policy(uint256 policyId) external view returns (Licensing.Policy memory pol);
/// @notice true if policy is defined in the contract

/// @notice True if policy is defined in the contract
function isPolicyDefined(uint256 policyId) external view returns (bool);
/// @notice gets the policy ids for an IP

/// @notice Gets the policy ids for an IP
function policyIdsForIp(address ipId) external view returns (uint256[] memory policyIds);
Ramarti marked this conversation as resolved.
Show resolved Hide resolved
/// @notice gets total number of policies for an IP

/// @notice Gets total number of policies for an IP
function totalPoliciesForIp(address ipId) external view returns (uint256);
/// @notice true if policy is part of an IP's policy list

/// @notice True if policy is part of an IP's policy list
function isPolicyIdSetForIp(address ipId, uint256 policyId) external view returns (bool);
/// @notice gets the policy ID for an IP by index on the IP's policy list

/// @notice Gets the policy ID for an IP by index on the IP's policy list
function policyIdForIpAtIndex(address ipId, uint256 index) external view returns (uint256 policyId);
/// @notice gets the policy for an IP by index on the IP's policy list

/// @notice Gets the policy for an IP by index on the IP's policy list
function policyForIpAtIndex(address ipId, uint256 index) external view returns (Licensing.Policy memory);
/// @notice gets the index of a policy in an IP's policy list

/// @notice Gets the index of a policy in an IP's policy list
function indexOfPolicyForIp(address ipId, uint256 policyId) external view returns (uint256 index);
/// @notice true if the license was added to the IP by linking (burning a license)

/// @notice True if the license was added to the IP by linking (burning a license)
function isPolicyInherited(address ipId, uint256 policyId) external view returns (bool);
/// @notice true if holder is the licensee for the license (owner of the license NFT), or derivative IP owner if

/// @notice True if holder is the licensee for the license (owner of the license NFT), or derivative IP owner if
/// the license was added to the IP by linking (burning a license)
function isLicensee(uint256 licenseId, address holder) external view returns (bool);

/// @notice IP ID of the licensor for the license (parent IP)
function licensorIpId(uint256 licenseId) external view returns (address);
/// @notice license data (licensor, policy...) for the license id

/// @notice License data (licensor, policy...) for the license id
function license(uint256 licenseId) external view returns (Licensing.License memory);
/// @notice true if an IP is a derivative of another IP

/// @notice True if an IP is a derivative of another IP
function isParent(address parentIpId, address childIpId) external view returns (bool);
/// @notice returns the parent IP IDs for an IP ID

/// @notice Returns the parent IP IDs for an IP ID
function parentIpIds(address ipId) external view returns (address[] memory);
/// @notice total number of parents for an IP ID

/// @notice Total number of parents for an IP ID
function totalParentsForIpId(address ipId) external view returns (uint256);
}
}
10 changes: 5 additions & 5 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ library Errors {
error LicenseRegistry__PolicyAlreadySetForIpId();
error LicenseRegistry__FrameworkNotFound();
error LicenseRegistry__EmptyLicenseUrl();
error LicenseRegistry__ZeroPolicyFramework();
error LicenseRegistry__InvalidPolicyFramework();
error LicenseRegistry__PolicyAlreadyAdded();
error LicenseRegistry__ParamVerifierLengthMismatch();
error LicenseRegistry__PolicyNotFound();
Expand All @@ -109,15 +109,15 @@ library Errors {
error LicenseRegistryAware__CallerNotLicenseRegistry();

////////////////////////////////////////////////////////////////////////////
// PolicyFramework //
// PolicyFrameworkManager //
////////////////////////////////////////////////////////////////////////////

error PolicyFramework_FrameworkNotYetRegistered();
error PolicyFrameworkManager__GettingPolicyWrongFramework();

////////////////////////////////////////////////////////////////////////////
// LicensorApprovalManager //
// LicensorApprovalChecker //
////////////////////////////////////////////////////////////////////////////
error LicensorApprovalManager__Unauthorized();
error LicensorApprovalChecker__Unauthorized();

////////////////////////////////////////////////////////////////////////////
// Dispute Module //
Expand Down
17 changes: 3 additions & 14 deletions contracts/lib/Licensing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,12 @@ import { Errors } from "./Errors.sol";
/// @title Licensing
/// @notice Types and constants used by the licensing related contracts
library Licensing {
/// @notice Describes a license policy framework, which is a set of licensing terms (parameters)
/// that come into effect in different moments of the licensing life cycle.
/// Must correspond to human (or at least lawyer) readable text describing them in licenseUrl.
/// To be valid in Story Protocol, the policy framework must be registered in the LicenseRegistry.
/// @param policyFramework Address of the contract implementing the policy framework encoding and logic
/// @param licenseUrl URL to the file containing the legal text for the license agreement
struct PolicyFramework {
address policyFramework;
string licenseUrl;
}

/// @notice A particular configuration (flavor) of a Policy Framework, setting values for the licensing
/// terms (parameters) of the framework.
/// @param policyFrameworkId Id of the policy framework this policy is based on
/// @param policyData Encoded data for the policy, specific to the policy framework
/// @param policyFramework address of the IPolicyFrameworkManager this policy is based on
/// @param data Encoded data for the policy, specific to the policy framework
struct Policy {
uint256 policyFrameworkId;
address policyFramework;
bytes data;
}

Expand Down
27 changes: 8 additions & 19 deletions contracts/modules/licensing/BasePolicyFrameworkManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,23 @@ import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol
/// @title BasePolicyFrameworkManager
/// @notice Base contract for policy framework managers.
abstract contract BasePolicyFrameworkManager is IPolicyVerifier, IPolicyFrameworkManager, ERC165, LicenseRegistryAware {
string public licenseUrl;

uint256 public policyFrameworkId;

string public override name;
string public override licenseTextUrl;

/// @notice Initializes the base contract.
/// @param registry The address of the license registry.
/// @param templateUrl The URL for the license template.
constructor(address registry, string memory templateUrl) LicenseRegistryAware(registry) {
licenseUrl = templateUrl;
}

/// @notice Registers this policy framework manager within the license registry, to be able
/// to add policies into the license registry.
/// @dev save the policyFrameworkId in this PolicyFrameworkManager
/// @return The ID of the policy framework.
function register() external returns (uint256) {
Licensing.PolicyFramework memory framework = Licensing.PolicyFramework({
policyFramework: address(this),
licenseUrl: licenseUrl
});
policyFrameworkId = LICENSE_REGISTRY.addPolicyFramework(framework);
return policyFrameworkId;
constructor(address registry, string memory name_, string memory licenseTextUrl_) LicenseRegistryAware(registry) {
name = name_;
licenseTextUrl = licenseTextUrl_;
}

/// @notice ERC165 interface identifier for the policy framework manager.
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(IPolicyFrameworkManager).interfaceId || super.supportsInterface(interfaceId);
}

/// @notice returns the address of the license registry
function licenseRegistry() external view virtual override returns (address) {
return address(LICENSE_REGISTRY);
}
Expand Down
Loading
Loading