Skip to content

Commit

Permalink
feat: add backward compatibility to LicenseAttachmentWorkflows (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface authored Dec 20, 2024
1 parent a52404d commit 84db8d6
Show file tree
Hide file tree
Showing 3 changed files with 767 additions and 0 deletions.
64 changes: 64 additions & 0 deletions contracts/interfaces/workflows/ILicenseAttachmentWorkflows.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { PILTerms } from "@storyprotocol/core/interfaces/modules/licensing/IPILicenseTemplate.sol";
import { WorkflowStructs } from "../../lib/WorkflowStructs.sol";

/// @title License Attachment Workflows Interface
Expand Down Expand Up @@ -54,4 +56,66 @@ interface ILicenseAttachmentWorkflows {
WorkflowStructs.LicenseTermsData[] calldata licenseTermsData,
WorkflowStructs.SignatureData calldata sigMetadataAndAttachAndConfig
) external returns (address ipId, uint256[] memory licenseTermsIds);

////////////////////////////////////////////////////////////////////////////
// DEPRECATED //
////////////////////////////////////////////////////////////////////////////

/// @notice Register Programmable IP License Terms (if unregistered) and attach it to IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerPILTermsAndAttach(
address ipId,
PILTerms[] calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (uint256[] memory licenseTermsIds);

/// @notice Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// register Programmable IPLicense
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function mintAndRegisterIpAndAttachPILTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms[] calldata terms
) external returns (address ipId, uint256 tokenId, uint256[] memory licenseTermsIds);

/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms[] calldata terms,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (address ipId, uint256[] memory licenseTermsIds);

/// @notice Register Programmable IP License Terms (if unregistered) and attach it to IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerPILTermsAndAttach(
address ipId,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (uint256 licenseTermsId);

/// Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// register Programmable IPLicense
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function mintAndRegisterIpAndAttachPILTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms calldata terms
) external returns (address ipId, uint256 tokenId, uint256 licenseTermsId);

/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (address ipId, uint256 licenseTermsId);
}
191 changes: 191 additions & 0 deletions contracts/workflows/LicenseAttachmentWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils

import { ICoreMetadataModule } from "@storyprotocol/core/interfaces/modules/metadata/ICoreMetadataModule.sol";
import { ILicensingModule } from "@storyprotocol/core/interfaces/modules/licensing/ILicensingModule.sol";
import { PILTerms } from "@storyprotocol/core/interfaces/modules/licensing/IPILicenseTemplate.sol";

import { BaseWorkflow } from "../BaseWorkflow.sol";
import { Errors } from "../lib/Errors.sol";
Expand Down Expand Up @@ -238,4 +239,194 @@ contract LicenseAttachmentWorkflows is
/// @dev Hook to authorize the upgrade according to UUPSUpgradeable
/// @param newImplementation The address of the new implementation
function _authorizeUpgrade(address newImplementation) internal override restricted {}

////////////////////////////////////////////////////////////////////////////
// DEPRECATED //
////////////////////////////////////////////////////////////////////////////

/// @notice Register Programmable IP License Terms (if unregistered) and attach it to IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerPILTermsAndAttach(
address ipId,
PILTerms[] calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (uint256[] memory licenseTermsIds) {
if (terms.length == 0) revert Errors.LicenseAttachmentWorkflows__NoLicenseTermsData();

PermissionHelper.setPermissionForModule(
ipId,
address(LICENSING_MODULE),
address(ACCESS_CONTROLLER),
ILicensingModule.attachLicenseTerms.selector,
sigAttach
);

licenseTermsIds = _registerMultiplePILTermsAndAttach(ipId, terms);
}

/// @notice Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// register Programmable IP License Terms (if unregistered), and attach it to the registered IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function mintAndRegisterIpAndAttachPILTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms[] calldata terms
)
external
onlyMintAuthorized(spgNftContract)
returns (address ipId, uint256 tokenId, uint256[] memory licenseTermsIds)
{
if (terms.length == 0) revert Errors.LicenseAttachmentWorkflows__NoLicenseTermsData();

tokenId = ISPGNFT(spgNftContract).mintByPeriphery({
to: address(this),
payer: msg.sender,
nftMetadataURI: ipMetadata.nftMetadataURI,
nftMetadataHash: "",
allowDuplicates: true
});
ipId = IP_ASSET_REGISTRY.register(block.chainid, spgNftContract, tokenId);
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);

licenseTermsIds = _registerMultiplePILTermsAndAttach(ipId, terms);

ISPGNFT(spgNftContract).safeTransferFrom(address(this), recipient, tokenId, "");
}

/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms[] calldata terms,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (address ipId, uint256[] memory licenseTermsIds) {
if (terms.length == 0) revert Errors.LicenseAttachmentWorkflows__NoLicenseTermsData();

ipId = IP_ASSET_REGISTRY.register(block.chainid, nftContract, tokenId);
MetadataHelper.setMetadataWithSig(
ipId,
address(CORE_METADATA_MODULE),
address(ACCESS_CONTROLLER),
ipMetadata,
sigMetadata
);

PermissionHelper.setPermissionForModule(
ipId,
address(LICENSING_MODULE),
address(ACCESS_CONTROLLER),
ILicensingModule.attachLicenseTerms.selector,
sigAttach
);

licenseTermsIds = _registerMultiplePILTermsAndAttach(ipId, terms);
}

/// @notice Register Programmable IP License Terms (if unregistered) and attach it to IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerPILTermsAndAttach(
address ipId,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (uint256 licenseTermsId) {
PermissionHelper.setPermissionForModule(
ipId,
address(LICENSING_MODULE),
address(ACCESS_CONTROLLER),
ILicensingModule.attachLicenseTerms.selector,
sigAttach
);

licenseTermsId = LicensingHelper.registerPILTermsAndAttach(
ipId,
address(PIL_TEMPLATE),
address(LICENSING_MODULE),
terms
);
}

/// @notice Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// register Programmable IP License Terms (if unregistered), and attach it to the registered IP.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function mintAndRegisterIpAndAttachPILTerms(
address spgNftContract,
address recipient,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms calldata terms
) external onlyMintAuthorized(spgNftContract) returns (address ipId, uint256 tokenId, uint256 licenseTermsId) {
tokenId = ISPGNFT(spgNftContract).mintByPeriphery({
to: address(this),
payer: msg.sender,
nftMetadataURI: ipMetadata.nftMetadataURI,
nftMetadataHash: "",
allowDuplicates: true
});
ipId = IP_ASSET_REGISTRY.register(block.chainid, spgNftContract, tokenId);
MetadataHelper.setMetadata(ipId, address(CORE_METADATA_MODULE), ipMetadata);

licenseTermsId = LicensingHelper.registerPILTermsAndAttach(
ipId,
address(PIL_TEMPLATE),
address(LICENSING_MODULE),
terms
);

ISPGNFT(spgNftContract).safeTransferFrom(address(this), recipient, tokenId, "");
}

/// @notice Register a given NFT as an IP and attach Programmable IP License Terms.
/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
WorkflowStructs.IPMetadata calldata ipMetadata,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigAttach
) external returns (address ipId, uint256 licenseTermsId) {
ipId = IP_ASSET_REGISTRY.register(block.chainid, nftContract, tokenId);
MetadataHelper.setMetadataWithSig(
ipId,
address(CORE_METADATA_MODULE),
address(ACCESS_CONTROLLER),
ipMetadata,
sigMetadata
);

PermissionHelper.setPermissionForModule(
ipId,
address(LICENSING_MODULE),
address(ACCESS_CONTROLLER),
ILicensingModule.attachLicenseTerms.selector,
sigAttach
);

licenseTermsId = LicensingHelper.registerPILTermsAndAttach(
ipId,
address(PIL_TEMPLATE),
address(LICENSING_MODULE),
terms
);
}

/// @notice THIS VERSION OF THE FUNCTION IS DEPRECATED, WILL BE REMOVED IN V1.4
function _registerMultiplePILTermsAndAttach(
address ipId,
PILTerms[] calldata terms
) private returns (uint256[] memory licenseTermsIds) {
licenseTermsIds = new uint256[](terms.length);
uint256 length = terms.length;
for (uint256 i; i < length; i++) {
licenseTermsIds[i] = LicensingHelper.registerPILTermsAndAttach(
ipId,
address(PIL_TEMPLATE),
address(LICENSING_MODULE),
terms[i]
);
}
}
}
Loading

0 comments on commit 84db8d6

Please sign in to comment.