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

Parameters #31

Merged
merged 30 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0c37b09
added transfer terms, refactored term checking
Jan 23, 2024
b2e3ef0
add param test
Jan 23, 2024
b236822
unused var test
Jan 23, 2024
6c35883
fix policy needs transfer arguments
Jan 23, 2024
62c0f69
fix tests, addPolicy public only allow new policies
Jan 24, 2024
187b98a
licenseData not provided when minting, it is a result
Jan 24, 2024
622a609
added activation
Jan 24, 2024
e9564c2
wip: license activation
Jan 24, 2024
a994cef
rolled back license status
Jan 24, 2024
f435571
removed activation related code
Jan 24, 2024
4c9d6f4
stray activation method
Jan 24, 2024
39d71d5
stray event
Jan 24, 2024
354890a
stray errors
Jan 24, 2024
f79e081
fix comment
Jan 24, 2024
c2f5493
fix comment
Jan 24, 2024
3a82de3
WIP
Jan 25, 2024
05a17e9
comment
Jan 25, 2024
4dc6150
Merge branch 'main' into parameters
Jan 25, 2024
f57adfb
fixes
Jan 25, 2024
15fe95c
WIP
Jan 26, 2024
ca59848
WIP: fix identification of policy set by linking
Jan 26, 2024
8400264
refactor to compile
Jan 26, 2024
92167b8
Merge branch 'main' into parameters
Jan 26, 2024
a1810be
fix except integration
Jan 26, 2024
8def6d8
feat: integration test fix, remove local vars, add reverts on verific…
jdubpark Jan 26, 2024
2b36d27
fix: verifier interfaces, integration test fix, mock verifier fix, re…
jdubpark Jan 26, 2024
48be78d
fix: rename contract, add constructor param for mock verifier, format…
jdubpark Jan 26, 2024
95fff70
fix: rename vars and clean stack
jdubpark Jan 26, 2024
1ffe1d5
feat: flexible MockParamVerifier, modify integration/unit test runs
jdubpark Jan 26, 2024
cfe3ed4
Update contracts/interfaces/licensing/IMintParamVerifier.sol
Ramarti Jan 27, 2024
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
15 changes: 15 additions & 0 deletions contracts/interfaces/licensing/ILinkParamVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.23;

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

interface ILinkParamVerifier is IParamVerifier {
function verifyLink(
uint256 licenseId,
address caller,
address ipId,
address parentIpId,
bytes calldata data
) external returns (bool);
}
16 changes: 16 additions & 0 deletions contracts/interfaces/licensing/IMintParamVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.23;
import { IParamVerifier } from "contracts/interfaces/licensing/IParamVerifier.sol";

interface IMintParamVerifier is IParamVerifier {
function verifyMint(
address caller,
uint256 policyId,
bool policyAddedByLinking,
address licensors,
Ramarti marked this conversation as resolved.
Show resolved Hide resolved
address receiver,
bytes memory data
) external returns (bool);
}

17 changes: 10 additions & 7 deletions contracts/interfaces/licensing/IParamVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.20;
pragma solidity ^0.8.23;

interface IParamVerifier {
function verifyMinting(address caller, uint256 amount, bytes memory data) external returns (bool);
function verifyTransfer(address caller, uint256 amount, bytes memory data) external returns (bool);
function verifyLinkParent(address caller, bytes memory data) external returns (bool);
function json() external view returns (string memory);
import { IERC165 } from "@openzeppelin/contracts/interfaces/IERC165.sol";

interface IParamVerifier is IERC165 {

function name() external pure returns (bytes32);
function nameString() external pure returns (string memory);
function json() external pure returns (string memory);
function allowsOtherPolicyOnSameIp(bytes memory data) external view returns (bool);
}
15 changes: 15 additions & 0 deletions contracts/interfaces/licensing/ITransferParamVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.23;

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

interface ITransferParamVerifier is IParamVerifier {
function verifyTransfer(
uint256 licenseId,
address from,
address to,
uint256 amount,
bytes memory data
) external returns (bool);
}
21 changes: 15 additions & 6 deletions contracts/interfaces/registries/ILicenseRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;

import { Licensing } from "contracts/lib/Licensing.sol";
Expand All @@ -12,7 +12,13 @@ interface ILicenseRegistry {

event PolicyCreated(address indexed creator, uint256 indexed policyId, Licensing.Policy policy);

event PolicyAddedToIpId(address indexed caller, address indexed ipId, uint256 indexed policyId, bool setByLinking);
event PolicyAddedToIpId(
address indexed caller,
address indexed ipId,
uint256 indexed policyId,
uint256 index,
bool setByLinking
);

event LicenseMinted(
address indexed creator,
Expand All @@ -39,7 +45,7 @@ interface ILicenseRegistry {

function mintLicense(
uint256 policyId,
address[] calldata licensorIpIds,
address licensorIpId,
uint256 amount,
address receiver
) external returns (uint256 licenseId);
Expand All @@ -52,10 +58,9 @@ interface ILicenseRegistry {

function totalFrameworks() external view returns (uint256);

function frameworkParams(uint256 frameworkId, Licensing.ParamVerifierType pvt) external view returns (Licensing.Parameter[] memory);
function frameworkParam(uint256 frameworkId, string calldata name) external view returns (Licensing.Parameter memory);
function frameworkUrl(uint256 frameworkId) external view returns (string memory);


function totalPolicies() external view returns (uint256);

function policy(uint256 policyId) external view returns (Licensing.Policy memory pol);
Expand All @@ -72,10 +77,14 @@ interface ILicenseRegistry {

function policyForIpAtIndex(address ipId, uint256 index) external view returns (Licensing.Policy memory);

function isPolicyIdAtIndexSetByLinking(address ipId, uint256 index) external view returns (bool);
function indexOfPolicyForIp(address ipId, uint256 policyId) external view returns (uint256 index);

function isPolicySetByLinking(address ipId, uint256 policyId) external view returns (bool);

function isLicensee(uint256 licenseId, address holder) external view returns (bool);

function licensorIpId(uint256 licenseId) external view returns (address);
function license(uint256 licenseId) external view returns (Licensing.License memory);
function isParent(address parentIpId, address childIpId) external view returns (bool);

function parentIpIds(address ipId) external view returns (address[] memory);
Expand Down
13 changes: 12 additions & 1 deletion contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,19 @@ library Errors {
error LicenseRegistry__LicensorDoesntHaveThisPolicy();
error LicenseRegistry__ParamVerifierFailed(uint8 verifierType, address verifier);
error LicenseRegistry__LinkParentParamFailed();
error LicenseRegistry__LicenseMustHaveLicensors();
error LicenseRegistry__InvalidLicensor();
error LicenseRegistry__ParamVerifierAlreadySet();

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

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

////////////////////////////////////////////////////////////////////////////
// Dispute Module //
Expand Down
57 changes: 18 additions & 39 deletions contracts/lib/Licensing.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.20;
import { IParamVerifier } from "../interfaces/licensing/IParamVerifier.sol";
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
Expand All @@ -27,61 +28,39 @@ 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 Framework {
/// @notice Stores the parameters that need to be verified in each moment of the license lifetime
/// ParamVerifierType.Mint --> These parameters need to be verified when minting a license
/// ParamVerifierType.LinkParent --> Verified before the owner of a license links to a parent ipId/policy,
/// burning the license and setting the policy for the ipId.
/// ParamVerifierType.Transfer -> verified when transfering NFT
mapping(ParamVerifierType => Parameter[]) parameters;
/// @notice Stores the parameters that need to be verified in each moment of the licensing lifetime
mapping(bytes32 => Parameter) parameters;
/// @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[] mintingVerifiers;
bytes[] mintingDefaultValues;
IParamVerifier[] linkParentVerifiers;
bytes[] linkParentDefaultValues;
IParamVerifier[] transferVerifiers;
bytes[] transferDefaultValues;
IParamVerifier[] parameters;
bytes[] defaultValues;
string licenseUrl;
}
/// A particular configuration of a Licensing Framework, setting (or not) values fo the licensing

/// A particular configuration of a Licensing Framework, setting (or not) values for the licensing
/// terms (parameters) of the framework.
/// The lengths of the param value arrays must correspond to the Parameter[] 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;
/// Array with values for parameters verifying conditions to mint a license. Empty bytes for index if
/// this policy wants to use the default value for the paremeter.
bytes[] mintingParamValues;
/// Array with values for parameters verifying conditions to link a license to a parent. Empty bytes for index if
/// this policy wants to use the default value for the paremeter.
bytes[] linkParentParamValues;
/// Array with values for parameters verifying conditions to transfer a license. Empty bytes for index if
/// this policy wants to use the default value for the paremeter.
bytes[] transferParamValues;
}

function getValues(Policy memory policy, ParamVerifierType pvt) internal returns(bytes[] memory) {
if (pvt == ParamVerifierType.Mint) {
return policy.mintingParamValues;
} else if (pvt == ParamVerifierType.LinkParent) {
return policy.linkParentParamValues;
} else if (pvt == ParamVerifierType.Transfer) {
return policy.transferParamValues;
} else {
revert Errors.LicenseRegistry__InvalidParamVerifierType();
}
/// 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;
}
Ramarti marked this conversation as resolved.
Show resolved Hide resolved

/// Data that define a License Agreement NFT
struct License {
/// the id for the Policy this License will set to the desired derivative IP after being burned.
uint256 policyId;
/// Ids for the licensors, meaning the Ip Ids of the parents of the derivative to be created
address[] licensorIpIds;
/// Id for the licensor of the Ip Id
address licensorIpId;
}
}
36 changes: 36 additions & 0 deletions contracts/modules/licensing/parameters/BaseParamVerifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: UNLICENSED
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf
pragma solidity ^0.8.23;

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


abstract contract BaseParamVerifier is IParamVerifier {
// /// @notice Gets the protocol-wide module access controller.
// IAccessController public immutable ACCESS_CONTROLLER;

// /// @notice Gets the protocol-wide IP account registry.
// IPAccountRegistry public immutable IP_ACCOUNT_REGISTRY;

// /// @notice Gets the protocol-wide IP record registry.
// IPRecordRegistry public immutable IP_RECORD_REGISTRY;

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

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

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