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

Commit

Permalink
refactored licensing from param based to fw based
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Jan 29, 2024
1 parent 0b4c31b commit 1046bf5
Show file tree
Hide file tree
Showing 22 changed files with 727 additions and 576 deletions.
11 changes: 11 additions & 0 deletions contracts/interfaces/licensing/ILicensingFramework.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.23;

import { Licensing } from "contracts/lib/Licensing.sol";
import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";

interface ILicensingFramework is IParamVerifier {
function licenseRegistry() external view returns (address);
function policyToJson(bytes memory policyData) external view returns (string memory);
}
2 changes: 1 addition & 1 deletion contracts/interfaces/licensing/ILinkParamVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ interface ILinkParamVerifier is IParamVerifier {
address caller,
address ipId,
address parentIpId,
bytes calldata data
bytes calldata policyData
) external returns (bool);
}
8 changes: 3 additions & 5 deletions contracts/interfaces/licensing/IMintParamVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.so
interface IMintParamVerifier is IParamVerifier {
function verifyMint(
address caller,
uint256 policyId,
bool policyAddedByLinking,
address licensor,
address licensors,
address receiver,
uint256 mintAmount,
bytes memory data
bytes memory policyData
) external returns (bool);
}

}
8 changes: 1 addition & 7 deletions contracts/interfaces/licensing/IParamVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,5 @@ pragma solidity ^0.8.23;
import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol";

interface IParamVerifier is IERC165 {
function name() external view returns (bytes32);

function nameString() external view returns (string memory);

function json() external view returns (string memory);

function allowsOtherPolicyOnSameIp(bytes memory data) external view returns (bool);
}
}
15 changes: 4 additions & 11 deletions contracts/interfaces/registries/ILicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ILicenseRegistry {
event LicenseFrameworkCreated(
address indexed creator,
uint256 indexed frameworkId,
Licensing.FrameworkCreationParams frameworkCreationParams
Licensing.Framework framework
);

event PolicyCreated(address indexed creator, uint256 indexed policyId, Licensing.Policy policy);
Expand All @@ -30,14 +30,7 @@ interface ILicenseRegistry {

event IpIdLinkedToParent(address indexed caller, address indexed ipId, address indexed parentIpId);

function addLicenseFramework(
Licensing.FrameworkCreationParams calldata fwCreation
) external returns (uint256 frameworkId);

function addPolicyToIp(
address ipId,
Licensing.Policy memory pol
) external returns (uint256 policyId, bool isNew, uint256 indexOnIpId);
function addLicenseFramework(Licensing.Framework calldata fw) external returns (uint256 frameworkId);

function addPolicyToIp(address ipId, uint256 polId) external returns (uint256 indexOnIpId);

Expand All @@ -58,7 +51,7 @@ interface ILicenseRegistry {

function totalFrameworks() external view returns (uint256);

function frameworkParam(uint256 frameworkId, string calldata name) external view returns (Licensing.Parameter memory);
function framework(uint256 frameworkId) external view returns (Licensing.Framework memory);
function frameworkUrl(uint256 frameworkId) external view returns (string memory);

function totalPolicies() external view returns (uint256);
Expand Down Expand Up @@ -90,4 +83,4 @@ interface ILicenseRegistry {
function parentIpIds(address ipId) external view returns (address[] memory);

function totalParentsForIpId(address ipId) external view returns (uint256);
}
}
32 changes: 25 additions & 7 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,46 @@ library Errors {
error LicenseRegistry__PolicyAlreadySetForIpId();
error LicenseRegistry__FrameworkNotFound();
error LicenseRegistry__EmptyLicenseUrl();
error LicenseRegistry__ZeroLicensingFramework();
error LicenseRegistry__PolicyAlreadyAdded();
error LicenseRegistry__ParamVerifierLengthMismatch();
error LicenseRegistry__InvalidParamVerifierType();
error LicenseRegistry__PolicyNotFound();
error LicenseRegistry__NotLicensee();
error LicenseRegistry__ParentIdEqualThanChild();
error LicenseRegistry__LicensorDoesntHaveThisPolicy();
error LicenseRegistry__ParamVerifierFailed(uint8 verifierType, address verifier);
error LicenseRegistry__MintLicenseParamFailed();
error LicenseRegistry__LinkParentParamFailed();
error LicenseRegistry__TransferParamFailed();
error LicenseRegistry__InvalidLicensor();
error LicenseRegistry__ParamVerifierAlreadySet();
error LicenseRegistry__CommercialTermInNonCommercialPolicy();
error LicenseRegistry__EmptyParamName();
error LicenseRegistry__UnregisteredFrameworkAddingPolicy();

////////////////////////////////////////////////////////////////////////////
// BaseParamVerifier //
// LicenseRegistryAware //
////////////////////////////////////////////////////////////////////////////
error BaseParamVerifier__Unauthorized();

error LicenseRegistryAware__CallerNotLicenseRegistry();

////////////////////////////////////////////////////////////////////////////
// LicensingFrameworkUML //
////////////////////////////////////////////////////////////////////////////

error LicensingFrameworkUML_CommecialDisabled_CantAddAttribution();
error LicensingFrameworkUML_CommecialDisabled_CantAddCommercializers();
error LicensingFrameworkUML_CommecialDisabled_CantAddRevShare();
error LicensingFrameworkUML_CommecialDisabled_CantAddDerivRevShare();
error LicensingFrameworkUML_DerivativesDisabled_CantAddAttribution();
error LicensingFrameworkUML_DerivativesDisabled_CantAddApproval();
error LicensingFrameworkUML_DerivativesDisabled_CantAddReciprocal();
error LicensingFrameworkUML_DerivativesDisabled_CantAddRevShare();
error LicensingFrameworkUML_FrameworkNotYetRegistered();

////////////////////////////////////////////////////////////////////////////
// DerivativesParamVerifier //
// LicensorApprovalManager //
////////////////////////////////////////////////////////////////////////////
error DerivativesParamVerifier__InvalidDerivativesConfig();
error DerivativesParamVerifier__ZeroShare();
error LicensorApprovalManager__Unauthorized();

////////////////////////////////////////////////////////////////////////////
// Dispute Module //
Expand Down
37 changes: 3 additions & 34 deletions contracts/lib/Licensing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,23 @@ import { Errors } from "./Errors.sol";

library Licensing {


/// Identifies a license parameter (term) from a license framework
struct Parameter {
/// Contract that must check if the condition of the paremeter is set
IParamVerifier verifier;
/// Default value for the parameter, as defined in the license framework text
bytes defaultValue;
}

/// Moment of the license lifetime where a Parameter will be verified
enum ParamVerifierType {
Mint,
LinkParent,
Transfer
}

/// Describes a licensing 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 parameters described in the text must express default values
/// corresponding to those of each Parameter struct
struct Framework {
/// @notice Stores the parameters that need to be verified in each moment of the licensing lifetime
mapping(bytes32 => Parameter) parameters;
address licensingFramework;
/// @notice URL to the file containing the legal text for the license agreement
string licenseUrl;
}

// Needed because Solidity doesn't support passing nested struct arrays to storage
struct FrameworkCreationParams {
IParamVerifier[] parameters;
bytes[] defaultValues;
string licenseUrl;
}

/// A particular configuration of a Licensing Framework, setting (or not) values for the licensing
/// terms (parameters) of the framework.
struct Policy {
/// True if the policy accepts commercial terms
bool commercialUse;
/// True if the policy accepts derivative-related terms
bool derivatives;
/// Id of a Licensing Framework
uint256 frameworkId;
/// Names of the parameters of the framework. Must be the same that IParamVerifier.name() returns
bytes32[] paramNames;
/// Values for the parameters of the framework. Index must correspond to paramNames[]
bytes[] paramValues;
bytes data;
}

/// Data that define a License Agreement NFT
Expand All @@ -63,4 +32,4 @@ library Licensing {
/// Id for the licensor of the Ip Id
address licensorIpId;
}
}
}
45 changes: 45 additions & 0 deletions contracts/modules/licensing/BaseLicensingFramework.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: UNLICENSED
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf
pragma solidity ^0.8.23;

// contracts
import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";
import { ILicensingFramework } from "contracts/interfaces/licensing/ILicensingFramework.sol";
import { LicenseRegistry } from "contracts/registries/LicenseRegistry.sol";
import { Licensing } from "contracts/lib/Licensing.sol";
import { Errors } from "contracts/lib/Errors.sol";
import { LicenseRegistryAware } from "contracts/modules/licensing/LicenseRegistryAware.sol";

// external
import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

abstract contract BaseLicensingFramework is IParamVerifier, ILicensingFramework, ERC165, LicenseRegistryAware {

string public licenseUrl;

uint256 public frameworkId;

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

function register() external returns(uint256) {
Licensing.Framework memory framework = Licensing.Framework({
licensingFramework: address(this),
licenseUrl: licenseUrl
});
frameworkId = LICENSE_REGISTRY.addLicenseFramework(framework);
return frameworkId;
}

function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == type(ILicensingFramework).interfaceId || super.supportsInterface(interfaceId);
}

function licenseRegistry() virtual override external view returns (address) {
return address(LICENSE_REGISTRY);
}
}
28 changes: 28 additions & 0 deletions contracts/modules/licensing/LicenseRegistryAware.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: UNLICENSED
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf
pragma solidity ^0.8.23;

// contracts
import { LicenseRegistry } from "contracts/registries/LicenseRegistry.sol";
import { Errors } from "contracts/lib/Errors.sol";

abstract contract LicenseRegistryAware {

/// @notice Gets the protocol-wide license registry.
LicenseRegistry public immutable LICENSE_REGISTRY;

/// @notice Initializes the base module contract.
/// @param licenseRegistry The address of the license registry.
constructor(address licenseRegistry) {
LICENSE_REGISTRY = LicenseRegistry(licenseRegistry);
}

/// @notice Modifier for authorizing the calling entity.
modifier onlyLicenseRegistry() {
if (msg.sender != address(LICENSE_REGISTRY)) {
revert Errors.LicenseRegistryAware__CallerNotLicenseRegistry();
}
_;
}

}
Loading

0 comments on commit 1046bf5

Please sign in to comment.