Skip to content

Commit

Permalink
Revert "refactor(permission): enable direct function calls via `execu…
Browse files Browse the repository at this point in the history
…teWithSig` (#121)" (#133)

* Revert "refactor(permission): enable direct function calls via `executeWithSig` (#121)"

This reverts commit a6fbf2c.

Revert "feat(licensing): support custom license templates and decouple terms registration from attachment (#123)"

This reverts commit 68f4a4a.

Revert "feat(licensing): enable multi-license attachment (#128)"

This reverts commit 027eed9.

* test(derivative): fix stack too deep
  • Loading branch information
sebsadface authored Nov 29, 2024
1 parent 027eed9 commit 6016acb
Show file tree
Hide file tree
Showing 33 changed files with 1,655 additions and 2,173 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ function mintAndRegisterIpAndAttachPILTerms(
address nftContract,
address recipient,
IPMetadata calldata ipMetadata,
PILTerms calldata terms,
bool allowDuplicates
PILTerms calldata terms
) external onlyCallerWithMinterRole(nftContract) returns (address ipId, uint256 tokenId, uint256 licenseTermsId)
```

Expand Down
6 changes: 4 additions & 2 deletions contracts/interfaces/workflows/IDerivativeWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface IDerivativeWorkflows {
/// @param derivData The derivative data to be used for registerDerivative.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata) for the IP via the Core Metadata Module.
/// @param sigMintingFee OPTIONAL. Signature data for approving license minting fee for the IP via the currency token.
/// @param sigRegister Signature data for registerDerivative for the IP via the Licensing Module.
/// @return ipId The ID of the newly registered IP.
function registerIpAndMakeDerivative(
Expand All @@ -38,7 +37,6 @@ interface IDerivativeWorkflows {
WorkflowStructs.MakeDerivative calldata derivData,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigMintingFee,
WorkflowStructs.SignatureData calldata sigRegister
) external returns (address ipId);

Expand All @@ -48,6 +46,7 @@ interface IDerivativeWorkflows {
/// @param spgNftContract The address of the SPGNFT collection.
/// @param licenseTokenIds The IDs of the license tokens to be burned for linking the IP to parent IPs.
/// @param royaltyContext The context for royalty module, should be empty for Royalty Policy LAP.
/// @param maxRts The maximum number of royalty tokens that can be distributed to the external royalty policies.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param recipient The address to receive the minted NFT.
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
Expand All @@ -57,6 +56,7 @@ interface IDerivativeWorkflows {
address spgNftContract,
uint256[] calldata licenseTokenIds,
bytes calldata royaltyContext,
uint32 maxRts,
WorkflowStructs.IPMetadata calldata ipMetadata,
address recipient,
bool allowDuplicates
Expand All @@ -68,6 +68,7 @@ interface IDerivativeWorkflows {
/// @param tokenId The ID of the NFT.
/// @param licenseTokenIds The IDs of the license tokens to be burned for linking the IP to parent IPs.
/// @param royaltyContext The context for royalty module, should be empty for Royalty Policy LAP.
/// @param maxRts The maximum number of royalty tokens that can be distributed to the external royalty policies.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata) for the IP via the Core Metadata Module.
/// @param sigRegister Signature data for registerDerivativeWithLicenseTokens for the IP via the Licensing Module.
Expand All @@ -77,6 +78,7 @@ interface IDerivativeWorkflows {
uint256 tokenId,
uint256[] calldata licenseTokenIds,
bytes calldata royaltyContext,
uint32 maxRts,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigRegister
Expand Down
33 changes: 19 additions & 14 deletions contracts/interfaces/workflows/IGroupingWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ interface IGroupingWorkflows {
/// @param spgNftContract The address of the SPGNFT collection.
/// @param groupId The ID of the group IP to add the newly registered IP.
/// @param recipient The address of the recipient of the minted NFT.
/// @param licenseInfo The information of the license terms that will be attached to the new IP.
/// @param licenseTemplate The address of the license template to be attached to the new IP.
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new IP.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
Expand All @@ -22,7 +23,8 @@ interface IGroupingWorkflows {
address spgNftContract,
address groupId,
address recipient,
WorkflowStructs.LicenseInfo[] calldata licenseInfo,
address licenseTemplate,
uint256 licenseTermsId,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigAddToGroup,
bool allowDuplicates
Expand All @@ -33,45 +35,48 @@ interface IGroupingWorkflows {
/// @param nftContract The address of the NFT collection.
/// @param tokenId The ID of the NFT.
/// @param groupId The ID of the group IP to add the newly registered IP.
/// @param licenseInfo The information of the license terms that will be attached to the new IP.
/// @param licenseTemplate The address of the license template to be attached to the new IP.
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new IP.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata).
/// @param sigsAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
/// The i th signature data is for attaching the i th license terms registered
/// in the i th license template to the IP.
/// @param sigMetadataAndAttach Signature data for setAll (metadata) and attachLicenseTerms to the IP
/// via the Core Metadata Module and Licensing Module.
/// @param sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
/// @return ipId The ID of the newly registered IP.
function registerIpAndAttachLicenseAndAddToGroup(
address nftContract,
uint256 tokenId,
address groupId,
WorkflowStructs.LicenseInfo[] calldata licenseInfo,
address licenseTemplate,
uint256 licenseTermsId,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData[] calldata sigsAttach,
WorkflowStructs.SignatureData calldata sigMetadataAndAttach,
WorkflowStructs.SignatureData calldata sigAddToGroup
) external returns (address ipId);

/// @notice Register a group IP with a group reward pool and attach license terms to the group IP
/// @param groupPool The address of the group reward pool.
/// @param licenseInfo The information of the license terms that will be attached to the new group IP.
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
/// @return groupId The ID of the newly registered group IP.
function registerGroupAndAttachLicense(
address groupPool,
WorkflowStructs.LicenseInfo calldata licenseInfo
address licenseTemplate,
uint256 licenseTermsId
) external returns (address groupId);

/// @notice Register a group IP with a group reward pool, attach license terms to the group IP,
/// and add individual IPs to the group IP.
/// @dev ipIds must be have the same license terms as the group IP.
/// @param groupPool The address of the group reward pool.
/// @param ipIds The IDs of the IPs to add to the newly registered group IP.
/// @param licenseInfo The information of the license terms that will be attached to the new group IP.
/// @param licenseTemplate The address of the license template to be attached to the new group IP.
/// @param licenseTermsId The ID of the registered license terms that will be attached to the new group IP.
/// @return groupId The ID of the newly registered group IP.
function registerGroupAndAttachLicenseAndAddIps(
address groupPool,
address[] calldata ipIds,
WorkflowStructs.LicenseInfo calldata licenseInfo
address licenseTemplate,
uint256 licenseTermsId
) external returns (address groupId);

/// @notice Collect royalties for the entire group and distribute the rewards to each member IP's royalty vault
Expand Down
70 changes: 28 additions & 42 deletions contracts/interfaces/workflows/ILicenseAttachmentWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,54 @@ import { WorkflowStructs } from "../../lib/WorkflowStructs.sol";
/// @title License Attachment Workflows Interface
/// @notice Interface for IP license attachment workflows.
interface ILicenseAttachmentWorkflows {
/// @notice Mint an NFT from a SPGNFT collection, register it as an IP, attach provided IP metadata,
/// register Programmable IPLicense Terms (if unregistered), and attach it to the newly registered IP.
/// @notice Register Programmable IP License Terms (if unregistered) and attach it to IP.
/// @param ipId The ID of the IP.
/// @param terms The PIL terms to be registered.
/// @param sigAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
/// @return licenseTermsId The ID of the newly registered PIL terms.
function registerPILTermsAndAttach(
address ipId,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (uint256 licenseTermsId);

/// @notice Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// register Programmable IPLicense
/// Terms (if unregistered), and attach it to the registered IP.
/// @dev Requires caller to have the minter role or the SPG NFT to allow public minting.
/// @param spgNftContract The address of the SPGNFT collection.
/// @param recipient The address of the recipient of the minted NFT.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param terms The PIL terms to be registered and attached to the newly registered IP.
/// @param terms The PIL terms to be registered.
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
/// @return licenseTermsIds The IDs of the newly registered PIL terms.
/// @return licenseTermsId The ID of the newly registered PIL terms.
function mintAndRegisterIpAndAttachPILTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms[] calldata terms,
bool allowDuplicates
) external returns (address ipId, uint256 tokenId, uint256[] memory licenseTermsIds);

/// @notice Mint an NFT from a SPGNFT collection, register as an IP, attach provided IP metadata,
/// and attach the provided license terms to the newly registered IP.
/// @dev Requires caller to have the minter role or the SPG NFT to allow public minting.
/// @param spgNftContract The address of the SPGNFT collection.
/// @param recipient The address of the recipient of the newly minted NFT.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param licenseTemplates The addresses of the license templates used of the license terms to be attached.
/// @param licenseTermsIds The IDs of the license terms to attach. The i th license terms ID must be a valid license
/// terms that was registered in the i th license template.
/// @param allowDuplicates Set to true to allow minting an NFT with a duplicate metadata hash.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
function mintAndRegisterIpAndAttachLicenseTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
address[] calldata licenseTemplates,
uint256[] calldata licenseTermsIds,
PILTerms calldata terms,
bool allowDuplicates
) external returns (address ipId, uint256 tokenId);
) external returns (address ipId, uint256 tokenId, uint256 licenseTermsId);

/// @notice Register a given NFT as an IP, attach provided IP metadata, and attach the provided license terms to the
/// newly registered IP.
/// @dev Since IP Account is created in this function, we need signatures to allow this contract to set metadata
/// and attach PIL Terms to the newly created IP Account on behalf of the owner.
/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.
/// @dev Because IP Account is created in this function, we need to set the permission via signature to allow this
/// contract to attach PIL Terms to the newly created IP Account in the same function.
/// @param nftContract The address of the NFT collection.
/// @param tokenId The ID of the NFT.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly registered IP.
/// @param licenseTemplates The addresses of the license templates used of the license terms to be attached.
/// @param licenseTermsIds The IDs of the license terms to attach. The i th license terms ID must be a valid license
/// terms that was registered in the i th license template.
/// @param terms The PIL terms to be registered.
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata) for the IP via the Core Metadata Module.
/// @param sigsAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
/// The i th signature data is for attaching the i th license terms registered in the i th license template
/// to the IP.
/// @param sigAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
/// @return ipId The ID of the newly registered IP.
function registerIpAndAttachLicenseTerms(
/// @return licenseTermsId The ID of the newly registered PIL terms.
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
WorkflowStructs.IPMetadata calldata ipMetadata,
address[] calldata licenseTemplates,
uint256[] calldata licenseTermsIds,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData[] calldata sigsAttach
) external returns (address ipId);
WorkflowStructs.SignatureData calldata sigAttach
) external returns (address ipId, uint256 licenseTermsId);
}
60 changes: 10 additions & 50 deletions contracts/lib/LicensingHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,41 @@
pragma solidity 0.8.26;

import { Errors as CoreErrors } from "@storyprotocol/core/lib/Errors.sol";
import { IIPAccount } from "@storyprotocol/core/interfaces/IIPAccount.sol";
import { ILicensingModule } from "@storyprotocol/core/interfaces/modules/licensing/ILicensingModule.sol";
import { IPILicenseTemplate, PILTerms } from "@storyprotocol/core/interfaces/modules/licensing/IPILicenseTemplate.sol";

import { WorkflowStructs } from "../lib/WorkflowStructs.sol";

/// @title Periphery Licensing Helper Library
/// @notice Library for all licensing related helper functions for Periphery contracts.
library LicensingHelper {
/// @dev Registers PIL License Terms and attaches them to the given IP.
/// @param ipId The ID of the IP.
/// @param pilTemplate The address of the PIL License Template.
/// @param licensingModule The address of the Licensing Module.
/// @param licenseRegistry The address of the License Registry.
/// @param terms The PIL terms to be registered.
/// @return licenseTermsIds The IDs of the registered PIL terms.
/// @return licenseTermsId The ID of the registered PIL terms.
function registerPILTermsAndAttach(
address ipId,
address pilTemplate,
address licensingModule,
PILTerms[] memory terms
) internal returns (uint256[] memory licenseTermsIds) {
licenseTermsIds = new uint256[](terms.length);
for (uint256 i = 0; i < terms.length; i++) {
licenseTermsIds[i] = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms[i]);
attachLicenseTerms(ipId, licensingModule, pilTemplate, licenseTermsIds[i]);
}
address licenseRegistry,
PILTerms calldata terms
) internal returns (uint256 licenseTermsId) {
licenseTermsId = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms);

attachLicenseTerms(ipId, licensingModule, licenseRegistry, pilTemplate, licenseTermsId);
}

/// @dev Attaches license terms to the given IP.
/// @param ipId The ID of the IP.
/// @param licensingModule The address of the Licensing Module.
/// @param licenseRegistry The address of the License Registry.
/// @param licenseTemplate The address of the license template.
/// @param licenseTermsId The ID of the license terms to be attached.
function attachLicenseTerms(
address ipId,
address licensingModule,
address licenseRegistry,
address licenseTemplate,
uint256 licenseTermsId
) internal {
Expand All @@ -52,43 +51,4 @@ library LicensingHelper {
}
}
}

/// @dev Attaches license terms to the given IP on behalf of the owner with a signature.
/// @param ipId The ID of the IP to which the license terms will be attached.
/// @param licensingModule The address of the Licensing Module.
/// @param licenseTemplate The address of the license template.
/// @param licenseTermsId The ID of the license terms to be attached.
/// @param sigAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
function attachLicenseTermsWithSig(
address ipId,
address licensingModule,
address licenseTemplate,
uint256 licenseTermsId,
WorkflowStructs.SignatureData memory sigAttach
) internal {
try
IIPAccount(payable(ipId)).executeWithSig({
to: address(licensingModule),
value: 0,
data: abi.encodeWithSelector(
ILicensingModule.attachLicenseTerms.selector,
ipId,
licenseTemplate,
licenseTermsId
),
signer: sigAttach.signer,
deadline: sigAttach.deadline,
signature: sigAttach.signature
})
{
return; // license terms are attached successfully
} catch (bytes memory reason) {
// if the error is not that the license terms are already attached, revert with the original error
if (CoreErrors.LicenseRegistry__LicenseTermsAlreadyAttached.selector != bytes4(reason)) {
assembly {
revert(add(reason, 32), mload(reason))
}
}
}
}
}
Loading

0 comments on commit 6016acb

Please sign in to comment.