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

Commit

Permalink
refactor naming to policy framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul committed Jan 29, 2024
1 parent 4fca0d7 commit 305abc5
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ pragma solidity ^0.8.23;
import { Licensing } from "contracts/lib/Licensing.sol";
import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";

interface ILicensingFramework is IParamVerifier {
/// @title IPolicyFrameworkManager
/// @notice Interface to define a licensing framework contract, that will
/// register itself into the LicenseRegistry to format policy into the LicenseRegistry
interface IPolicyFrameworkManager is IParamVerifier {
function licenseRegistry() external view returns (address);
function policyToJson(bytes memory policyData) external view returns (string memory);
}
22 changes: 11 additions & 11 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ library Errors {
error LicenseRegistry__PolicyAlreadySetForIpId();
error LicenseRegistry__FrameworkNotFound();
error LicenseRegistry__EmptyLicenseUrl();
error LicenseRegistry__ZeroLicensingFramework();
error LicenseRegistry__ZeroPolicyFramework();
error LicenseRegistry__PolicyAlreadyAdded();
error LicenseRegistry__ParamVerifierLengthMismatch();
error LicenseRegistry__PolicyNotFound();
Expand All @@ -97,18 +97,18 @@ library Errors {
error LicenseRegistryAware__CallerNotLicenseRegistry();

////////////////////////////////////////////////////////////////////////////
// LicensingFrameworkUML //
// UMLPolicyFrameworkManager //
////////////////////////////////////////////////////////////////////////////

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();
error UMLPolicyFrameworkManager_CommecialDisabled_CantAddAttribution();
error UMLPolicyFrameworkManager_CommecialDisabled_CantAddCommercializers();
error UMLPolicyFrameworkManager_CommecialDisabled_CantAddRevShare();
error UMLPolicyFrameworkManager_CommecialDisabled_CantAddDerivRevShare();
error UMLPolicyFrameworkManager_DerivativesDisabled_CantAddAttribution();
error UMLPolicyFrameworkManager_DerivativesDisabled_CantAddApproval();
error UMLPolicyFrameworkManager_DerivativesDisabled_CantAddReciprocal();
error UMLPolicyFrameworkManager_DerivativesDisabled_CantAddRevShare();
error UMLPolicyFrameworkManager_FrameworkNotYetRegistered();

////////////////////////////////////////////////////////////////////////////
// LicensorApprovalManager //
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/Licensing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ library Licensing {
/// To be valid in Story Protocol, the parameters described in the text must express default values
/// corresponding to those of each Parameter struct
struct PolicyFramework {
address licensingFramework;
address policyFramework;
/// @notice URL to the file containing the legal text for the license agreement
string licenseUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.23;

// contracts
import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";
import { ILicensingFramework } from "contracts/interfaces/licensing/ILicensingFramework.sol";
import { IPolicyFrameworkManager } from "contracts/interfaces/licensing/IPolicyFrameworkManager.sol";
import { LicenseRegistry } from "contracts/registries/LicenseRegistry.sol";
import { Licensing } from "contracts/lib/Licensing.sol";
import { Errors } from "contracts/lib/Errors.sol";
Expand All @@ -14,7 +14,7 @@ import { LicenseRegistryAware } from "contracts/modules/licensing/LicenseRegistr
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 {
abstract contract BasePolicyFrameworkManager is IParamVerifier, IPolicyFrameworkManager, ERC165, LicenseRegistryAware {
string public licenseUrl;

uint256 public frameworkId;
Expand All @@ -27,15 +27,15 @@ abstract contract BaseLicensingFramework is IParamVerifier, ILicensingFramework,

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

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

function licenseRegistry() external view virtual override returns (address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Errors } from "contracts/lib/Errors.sol";
import { ILinkParamVerifier } from "contracts/interfaces/licensing/ILinkParamVerifier.sol";
import { IMintParamVerifier } from "contracts/interfaces/licensing/IMintParamVerifier.sol";
import { ITransferParamVerifier } from "contracts/interfaces/licensing/ITransferParamVerifier.sol";
import { BaseLicensingFramework } from "contracts/modules/licensing/BaseLicensingFramework.sol";
import { BasePolicyFrameworkManager } from "contracts/modules/licensing/BasePolicyFrameworkManager.sol";
import { LicensorApprovalManager } from "contracts/modules/licensing/parameter-helpers/LicensorApprovalManager.sol";

// external
Expand All @@ -33,24 +33,24 @@ struct UMLv1Policy {
string[] distributionChannels;
}

contract LicensingFrameworkUML is
BaseLicensingFramework,
contract UMLPolicyFrameworkManager is
BasePolicyFrameworkManager,
ILinkParamVerifier,
IMintParamVerifier,
ITransferParamVerifier,
LicensorApprovalManager
{
event UMLv1PolicyAdded(uint256 indexed policyId, UMLv1Policy policy);

constructor(address licRegistry, string memory licenseUrl) BaseLicensingFramework(licRegistry, licenseUrl) {}
constructor(address licRegistry, string memory licenseUrl) BasePolicyFrameworkManager(licRegistry, licenseUrl) {}

function licenseRegistry() external view override returns (address) {
return address(LICENSE_REGISTRY);
}

function addPolicy(UMLv1Policy calldata umlPolicy) external returns (uint256 policyId) {
if (frameworkId == 0) {
revert Errors.LicensingFrameworkUML_FrameworkNotYetRegistered();
revert Errors.UMLPolicyFrameworkManager_FrameworkNotYetRegistered();
}
_verifyComercialUse(umlPolicy);
_verifyDerivatives(umlPolicy);
Expand All @@ -76,7 +76,7 @@ contract LicensingFrameworkUML is

function supportsInterface(
bytes4 interfaceId
) public view virtual override(BaseLicensingFramework, IERC165) returns (bool) {
) public view virtual override(BasePolicyFrameworkManager, IERC165) returns (bool) {
return
super.supportsInterface(interfaceId) ||
interfaceId == type(ILinkParamVerifier).interfaceId ||
Expand Down Expand Up @@ -139,33 +139,33 @@ contract LicensingFrameworkUML is
function _verifyComercialUse(UMLv1Policy calldata policy) internal view {
if (!policy.commercialUse) {
if (policy.commercialAttribution) {
revert Errors.LicensingFrameworkUML_CommecialDisabled_CantAddAttribution();
revert Errors.UMLPolicyFrameworkManager_CommecialDisabled_CantAddAttribution();
}
if (policy.commercializers.length > 0) {
revert Errors.LicensingFrameworkUML_CommecialDisabled_CantAddCommercializers();
revert Errors.UMLPolicyFrameworkManager_CommecialDisabled_CantAddCommercializers();
}
if (policy.commercialRevShare > 0) {
revert Errors.LicensingFrameworkUML_CommecialDisabled_CantAddRevShare();
revert Errors.UMLPolicyFrameworkManager_CommecialDisabled_CantAddRevShare();
}
if (policy.derivativesRevShare > 0) {
revert Errors.LicensingFrameworkUML_CommecialDisabled_CantAddDerivRevShare();
revert Errors.UMLPolicyFrameworkManager_CommecialDisabled_CantAddDerivRevShare();
}
}
}

function _verifyDerivatives(UMLv1Policy calldata policy) internal pure {
if (!policy.derivativesAllowed) {
if (policy.derivativesAttribution) {
revert Errors.LicensingFrameworkUML_DerivativesDisabled_CantAddAttribution();
revert Errors.UMLPolicyFrameworkManager_DerivativesDisabled_CantAddAttribution();
}
if (policy.derivativesApproval) {
revert Errors.LicensingFrameworkUML_DerivativesDisabled_CantAddApproval();
revert Errors.UMLPolicyFrameworkManager_DerivativesDisabled_CantAddApproval();
}
if (policy.derivativesReciprocal) {
revert Errors.LicensingFrameworkUML_DerivativesDisabled_CantAddReciprocal();
revert Errors.UMLPolicyFrameworkManager_DerivativesDisabled_CantAddReciprocal();
}
if (policy.derivativesRevShare > 0) {
revert Errors.LicensingFrameworkUML_DerivativesDisabled_CantAddRevShare();
revert Errors.UMLPolicyFrameworkManager_DerivativesDisabled_CantAddRevShare();
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions contracts/registries/LicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ITransferParamVerifier } from "contracts/interfaces/licensing/ITransfer
import { ILicenseRegistry } from "contracts/interfaces/registries/ILicenseRegistry.sol";
import { Errors } from "contracts/lib/Errors.sol";
import { Licensing } from "contracts/lib/Licensing.sol";
import { ILicensingFramework } from "contracts/interfaces/licensing/ILicensingFramework.sol";
import { IPolicyFrameworkManager } from "contracts/interfaces/licensing/IPolicyFrameworkManager.sol";


// TODO: consider disabling operators/approvals on creation
Expand Down Expand Up @@ -77,8 +77,8 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
if (bytes(fwCreation.licenseUrl).length == 0 || fwCreation.licenseUrl.equal("")) {
revert Errors.LicenseRegistry__EmptyLicenseUrl();
}
if (fwCreation.licensingFramework == address(0)) {
revert Errors.LicenseRegistry__ZeroLicensingFramework();
if (fwCreation.policyFramework == address(0)) {
revert Errors.LicenseRegistry__ZeroPolicyFramework();
}
// Todo: check duplications

Expand All @@ -96,7 +96,7 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {

function _framework(uint256 frameworkId) internal view returns (Licensing.PolicyFramework storage fw) {
fw = _frameworks[frameworkId];
if (fw.licensingFramework == address(0)) {
if (fw.policyFramework == address(0)) {
revert Errors.LicenseRegistry__FrameworkNotFound();
}
return fw;
Expand Down Expand Up @@ -150,13 +150,13 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
}

/// Adds a particular configuration of license terms to the protocol.
/// Must be called by a LicensingFramework, which is responsible for verifying the parameters
/// Must be called by a PolicyFramework, which is responsible for verifying the parameters
/// are valid and the configuration makes sense.
/// @param pol policy data
/// @return policyId if policy data was in the contract, policyId is reused, if it's new, id will be new.
function addPolicy(Licensing.Policy memory pol) public returns (uint256 policyId) {
address licensingFramework = _framework(pol.frameworkId).licensingFramework;
if (msg.sender != licensingFramework) {
address policyFramework = _framework(pol.frameworkId).policyFramework;
if (msg.sender != policyFramework) {
revert Errors.LicenseRegistry__UnregisteredFrameworkAddingPolicy();
}
(uint256 polId, bool newPol) = _addIdOrGetExisting(abi.encode(pol), _hashedPolicies, _totalPolicies);
Expand Down Expand Up @@ -279,8 +279,8 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
Licensing.PolicyFramework storage fw = _framework(pol.frameworkId);
bool inheritedPolicy = _policySetups[licensorIp][policyId].inheritedPolicy;

if (ERC165Checker.supportsInterface(fw.licensingFramework, type(IMintParamVerifier).interfaceId)) {
if(!IMintParamVerifier(fw.licensingFramework).verifyMint(
if (ERC165Checker.supportsInterface(fw.policyFramework, type(IMintParamVerifier).interfaceId)) {
if(!IMintParamVerifier(fw.policyFramework).verifyMint(
msg.sender,
inheritedPolicy,
licensorIp,
Expand Down Expand Up @@ -343,8 +343,8 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
Licensing.Policy memory pol = policy(licenseData.policyId);
Licensing.PolicyFramework storage fw = _framework(pol.frameworkId);

if (ERC165Checker.supportsInterface(fw.licensingFramework, type(ILinkParamVerifier).interfaceId)) {
if(!ILinkParamVerifier(fw.licensingFramework).verifyLink(
if (ERC165Checker.supportsInterface(fw.policyFramework, type(ILinkParamVerifier).interfaceId)) {
if(!ILinkParamVerifier(fw.policyFramework).verifyLink(
licenseId,
msg.sender,
childIpId,
Expand Down Expand Up @@ -401,11 +401,11 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {

if (
ERC165Checker.supportsInterface(
fw.licensingFramework,
fw.policyFramework,
type(ITransferParamVerifier).interfaceId
)
) {
if(!ITransferParamVerifier(fw.licensingFramework).verifyTransfer(
if(!ITransferParamVerifier(fw.policyFramework).verifyTransfer(
ids[i],
from,
to,
Expand All @@ -424,6 +424,6 @@ contract LicenseRegistry is ERC1155, ILicenseRegistry {
Licensing.License memory licenseData = _licenses[id];
Licensing.Policy memory pol = policy(licenseData.policyId);
Licensing.PolicyFramework storage fw = _framework(pol.frameworkId);
return ILicensingFramework(fw.licensingFramework).policyToJson(pol.data);
return IPolicyFrameworkManager(fw.policyFramework).policyToJson(pol.data);
}
}
6 changes: 3 additions & 3 deletions script/foundry/deployment/Main.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { RoyaltyModule } from "contracts/modules/royalty-module/RoyaltyModule.so
import { DisputeModule } from "contracts/modules/dispute-module/DisputeModule.sol";
import { IPResolver } from "contracts/resolvers/IPResolver.sol";
import { Governance } from "contracts/governance/Governance.sol";
import { LicensingFrameworkUML, UMLv1Policy } from "contracts/modules/licensing/LicensingFrameworkUML.sol";
import { UMLPolicyFrameworkManager, UMLv1Policy } from "contracts/modules/licensing/UMLPolicyFrameworkManager.sol";

// test
import { MockERC721 } from "test/foundry/mocks/MockERC721.sol";
Expand Down Expand Up @@ -248,11 +248,11 @@ contract Main is Script, BroadcastManager, JsonDeploymentHandler {
CREATE LICENSE FRAMEWORKS
////////////////////////////////////////////////////////////////*/

LicensingFrameworkUML umlAllTrue = new LicensingFrameworkUML(
UMLPolicyFrameworkManager umlAllTrue = new UMLPolicyFrameworkManager(
address(licenseRegistry),
"https://very-nice-verifier-license.com/{id}.json"
);
LicensingFrameworkUML umlMintPayment = new LicensingFrameworkUML(
UMLPolicyFrameworkManager umlMintPayment = new UMLPolicyFrameworkManager(
address(licenseRegistry),
"https://expensive-minting-license.com/{id}.json"
);
Expand Down
14 changes: 7 additions & 7 deletions test/foundry/integration/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import { RoyaltyModule } from "contracts/modules/royalty-module/RoyaltyModule.so
import { RoyaltyPolicyLS } from "contracts/modules/royalty-module/policies/RoyaltyPolicyLS.sol";
import { IPAccountRegistry } from "contracts/registries/IPAccountRegistry.sol";
import { LicenseRegistry } from "contracts/registries/LicenseRegistry.sol";
import { LicensingFrameworkUML, UMLv1Policy } from "contracts/modules/licensing/LicensingFrameworkUML.sol";
import { UMLPolicyFrameworkManager, UMLv1Policy } from "contracts/modules/licensing/UMLPolicyFrameworkManager.sol";

import { MockAccessController } from "test/foundry/mocks/MockAccessController.sol";
import { MockERC20 } from "test/foundry/mocks/MockERC20.sol";
import { MockERC721 } from "test/foundry/mocks/MockERC721.sol";
import { MockModule } from "test/foundry/mocks/MockModule.sol";
import { MockLicensingFramework, MockLicensingFrameworkConfig, MockPolicy } from "test/foundry/mocks/licensing/MockLicensingFramework.sol";
import { MintPaymentLicensingFramework, MintPaymentPolicy } from "test/foundry/mocks/licensing/MintPaymentLicensingFramework.sol";
import { MockPolicyFrameworkManager, MockPolicyFrameworkConfig, MockPolicy } from "test/foundry/mocks/licensing/MockPolicyFrameworkManager.sol";
import { MintPaymentPolicyFrameworkManager, MintPaymentPolicy } from "test/foundry/mocks/licensing/MintPaymentPolicyFrameworkManager.sol";
import { Users, UsersLib } from "test/foundry/utils/Users.sol";

struct MockERC721s {
Expand Down Expand Up @@ -218,17 +218,17 @@ contract IntegrationTest is Test {
CREATE LICENSE FRAMEWORKS
////////////////////////////////////////////////////////////////*/

MockLicensingFramework mock_lf_AllTrue = new MockLicensingFramework(
MockLicensingFrameworkConfig({
MockPolicyFrameworkManager mock_lf_AllTrue = new MockPolicyFrameworkManager(
MockPolicyFrameworkConfig({
licenseRegistry: address(licenseRegistry),
licenseUrl: "https://MockLicensingFramework.com/{id}.json",
licenseUrl: "https://MockPolicyFrameworkManager.com/{id}.json",
supportVerifyLink: true,
supportVerifyMint: true,
supportVerifyTransfer: true
})
);

MintPaymentLicensingFramework mock_lf_MintPayment = new MintPaymentLicensingFramework(
MintPaymentPolicyFrameworkManager mock_lf_MintPayment = new MintPaymentPolicyFrameworkManager(
address(licenseRegistry),
"https://expensive-minting-license.com/{id}.json",
address(mockToken),
Expand Down
Loading

0 comments on commit 305abc5

Please sign in to comment.