The PILicenseTemplate (Programmable IP License Template) is a smart contract that defines and manages license terms for IP assets on Story. It allows IP owners to create customizable license terms that can be attached to their IP assets, enabling them to control how their IP can be used commercially and for derivative works.

State Variables

LICENSE_REGISTRY

ILicenseRegistry public immutable LICENSE_REGISTRY

The address of the License Registry contract that tracks license terms and tokens.

ROYALTY_MODULE

IRoyaltyModule public immutable ROYALTY_MODULE

The address of the Royalty Module contract that handles royalty payments and policies.

licenseTerms

mapping(uint256 licenseTermsId => PILTerms) licenseTerms

Maps license terms IDs to their corresponding PILTerms structures.

hashedLicenseTerms

mapping(bytes32 licenseTermsHash => uint256 licenseTermsId) hashedLicenseTerms

Maps the hash of license terms to their corresponding license terms ID.

licenseTermsCounter

uint256 licenseTermsCounter

Counter for the number of registered license terms.

Functions

initialize

function initialize(address accessManager, string memory name, string memory metadataURI) external initializer

Initializer for this implementation contract.

Parameters:

  • accessManager: The address of the protocol admin roles contract.
  • name: The name of the license template.
  • metadataURI: The URL to the off-chain metadata.

registerLicenseTerms

function registerLicenseTerms(PILTerms calldata terms) external nonReentrant returns (uint256 id)

Registers new license terms and returns the ID of the newly registered license terms. The license terms are hashed and the hash is used to check if the terms are already registered. It will return an existing ID if the terms are already registered.

Parameters:

  • terms: The PILTerms to register.

Returns:

  • id: The ID of the newly registered license terms.

exists

function exists(uint256 licenseTermsId) external view override returns (bool)

Checks if a license terms exists.

Parameters:

  • licenseTermsId: The ID of the license terms.

Returns:

  • Returns true if the license terms exists, false otherwise.

verifyMintLicenseToken

function verifyMintLicenseToken(
    uint256 licenseTermsId,
    address licensee,
    address licensorIpId,
    uint256
) external override nonReentrant returns (bool)

Verifies the minting of a license token. The function will be called by the LicensingModule when minting a license token to verify if the minting is allowed by the license terms.

Parameters:

  • licenseTermsId: The ID of the license terms.
  • licensee: The address of the licensee who will receive the license token.
  • licensorIpId: The IP ID of the licensor who attached the license terms minting the license token.

Returns:

  • Returns true if the minting is verified, false otherwise.

verifyRegisterDerivative

function verifyRegisterDerivative(
    address childIpId,
    address parentIpId,
    uint256 licenseTermsId,
    address licensee
) external override returns (bool)

Verifies the registration of a derivative. This function is invoked by the LicensingModule during the registration of a derivative work to ensure compliance with the parent IP’s licensing terms.

Parameters:

  • childIpId: The IP ID of the derivative.
  • parentIpId: The IP ID of the parent.
  • licenseTermsId: The ID of the license terms.
  • licensee: The address of the licensee.

Returns:

  • Returns true if the registration is verified, false otherwise.

verifyCompatibleLicenses

function verifyCompatibleLicenses(uint256[] calldata licenseTermsIds) external view override returns (bool)

Verifies if the licenses are compatible. This function is called by the LicensingModule to verify license compatibility when registering a derivative IP to multiple parent IPs.

Parameters:

  • licenseTermsIds: The IDs of the license terms.

Returns:

  • Returns true if the licenses are compatible, false otherwise.

verifyRegisterDerivativeForAllParents

function verifyRegisterDerivativeForAllParents(
    address childIpId,
    address[] calldata parentIpIds,
    uint256[] calldata licenseTermsIds,
    address childIpOwner
) external override returns (bool)

Verifies the registration of a derivative for all parent IPs. This function is called by the LicensingModule to verify licenses for registering a derivative IP to multiple parent IPs.

Parameters:

  • childIpId: The IP ID of the derivative.
  • parentIpIds: The IP IDs of the parents.
  • licenseTermsIds: The IDs of the license terms.
  • childIpOwner: The address of the derivative IP owner.

Returns:

  • Returns true if the registration is verified, false otherwise.

getRoyaltyPolicy

function getRoyaltyPolicy(
    uint256 licenseTermsId
) external view returns (address royaltyPolicy, bytes memory royaltyData, uint256 mintingFee, address currency)

Returns the royalty policy of a license terms.

Parameters:

  • licenseTermsId: The ID of the license terms.

Returns:

  • royaltyPolicy: The address of the royalty policy specified for the license terms.
  • royaltyData: The data of the royalty policy.
  • mintingFee: The fee for minting a license.
  • currency: The address of the ERC20 token, used for minting license fee and royalties.

isLicenseTransferable

function isLicenseTransferable(uint256 licenseTermsId) external view override returns (bool)

Checks if a license terms is transferable.

Parameters:

  • licenseTermsId: The ID of the license terms.

Returns:

  • Returns true if the license terms is transferable, false otherwise.

getEarlierExpireTime

function getEarlierExpireTime(
    uint256[] calldata licenseTermsIds,
    uint256 start
) external view override returns (uint256)

Returns the earliest expiration time among the given license terms.

Parameters:

  • licenseTermsIds: The IDs of the license terms.
  • start: The start time.

Returns:

  • Returns the earliest expiration time.

getExpireTime

function getExpireTime(uint256 licenseTermsId, uint256 start) external view returns (uint256)

Returns the expiration time of a license terms.

Parameters:

  • licenseTermsId: The ID of the license terms.
  • start: The start time.

Returns:

  • Returns the expiration time.

getLicenseTermsId

function getLicenseTermsId(PILTerms calldata terms) external view returns (uint256 selectedLicenseTermsId)

Gets the ID of the given license terms.

Parameters:

  • terms: The PILTerms to get the ID for.

Returns:

  • selectedLicenseTermsId: The ID of the given license terms.

getLicenseTerms

function getLicenseTerms(uint256 selectedLicenseTermsId) external view returns (PILTerms memory terms)

Gets license terms of the given ID.

Parameters:

  • selectedLicenseTermsId: The ID of the license terms.

Returns:

  • terms: The PILTerms associated with the given ID.

getLicenseTermsURI

function getLicenseTermsURI(uint256 licenseTermsId) external view returns (string memory)

Returns the URI of the license terms.

Parameters:

  • licenseTermsId: The ID of the license terms.

Returns:

  • Returns the URI of the license terms.

totalRegisteredLicenseTerms

function totalRegisteredLicenseTerms() external view returns (uint256)

Returns the total number of registered license terms.

Returns:

  • Returns the total number of registered license terms.

supportsInterface

function supportsInterface(
    bytes4 interfaceId
) public view virtual override(BaseLicenseTemplateUpgradeable, IERC165) returns (bool)

Checks whether the contract supports the given interface.

Parameters:

  • interfaceId: The interface identifier.

Returns:

  • Returns true if the contract supports the interface, false otherwise.

toJson

function toJson(uint256 licenseTermsId) public view returns (string memory)

Converts the license terms to a JSON string which will be part of the metadata of the license token.

Parameters:

  • licenseTermsId: The ID of the license terms.

Returns:

  • Returns the JSON string of the license terms, following the OpenSea metadata standard.

PILTerms Structure

The PILTerms structure defines the terms for a Programmable IP License (PIL):

struct PILTerms {
    bool transferable;
    address royaltyPolicy;
    uint256 mintingFee;
    uint256 expiration;
    bool commercialUse;
    bool commercialAttribution;
    address commercializerChecker;
    bytes commercializerCheckerData;
    uint32 commercialRevShare;
    uint256 commercialRevCelling;
    bool derivativesAllowed;
    bool derivativesAttribution;
    bool derivativesApproval;
    bool derivativesReciprocal;
    uint256 derivativeRevCelling;
    address currency;
    string uri;
}

Parameters:

  • transferable: Indicates whether the license is transferable or not.
  • royaltyPolicy: The address of the royalty policy contract which is required by StoryProtocol in advance.
  • mintingFee: The fee to be paid when minting a license.
  • expiration: The expiration period of the license.
  • commercialUse: Indicates whether the work can be used commercially or not.
  • commercialAttribution: Whether attribution is required when reproducing the work commercially or not.
  • commercializerChecker: Commercializers that are allowed to commercially exploit the work. If zero address, then no restrictions are enforced.
  • commercializerCheckerData: The data to be passed to the commercializer checker contract.
  • commercialRevShare: Percentage of revenue that must be shared with the licensor.
  • commercialRevCelling: The maximum revenue that can be generated from the commercial use of the work.
  • derivativesAllowed: Indicates whether the licensee can create derivatives of their work or not.
  • derivativesAttribution: Indicates whether attribution is required for derivatives of the work or not.
  • derivativesApproval: Indicates whether the licensor must approve derivatives of the work before they can be linked to the licensor IP ID or not.
  • derivativesReciprocal: Indicates whether the licensee must license derivatives of the work under the same terms or not.
  • derivativeRevCelling: The maximum revenue that can be generated from the derivative use of the work.
  • currency: The ERC20 token to be used to pay the minting fee. The token must be registered in Story Protocol.
  • uri: The URI of the license terms, which can be used to fetch the off-chain license terms.