Skip to content

Commit

Permalink
refactor(permission): enable direct function calls via `executeWithSi…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface authored Nov 20, 2024
1 parent 3fc7b22 commit a6fbf2c
Show file tree
Hide file tree
Showing 21 changed files with 1,302 additions and 874 deletions.
2 changes: 2 additions & 0 deletions contracts/interfaces/workflows/IDerivativeWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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 @@ -37,6 +38,7 @@ 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 Down
7 changes: 4 additions & 3 deletions contracts/interfaces/workflows/IGroupingWorkflows.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ interface IGroupingWorkflows {
/// @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 sigMetadataAndAttach Signature data for setAll (metadata) and attachLicenseTerms to the IP
/// via the Core Metadata Module and Licensing Module.
/// @param sigMetadata OPTIONAL. Signature data for setAll (metadata).
/// @param sigAttach Signature data for attachLicenseTerms to the IP via the 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(
Expand All @@ -49,7 +49,8 @@ interface IGroupingWorkflows {
address licenseTemplate,
uint256 licenseTermsId,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigMetadataAndAttach,
WorkflowStructs.SignatureData calldata sigMetadata,
WorkflowStructs.SignatureData calldata sigAttach,
WorkflowStructs.SignatureData calldata sigAddToGroup
) external returns (address ipId);

Expand Down
67 changes: 61 additions & 6 deletions contracts/lib/LicensingHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,39 @@
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 licenseTermsId The ID of the registered PIL terms.
function registerPILTermsAndAttach(
address ipId,
address pilTemplate,
address licensingModule,
address licenseRegistry,
PILTerms calldata terms
) internal returns (uint256 licenseTermsId) {
licenseTermsId = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms);

attachLicenseTerms(ipId, licensingModule, licenseRegistry, pilTemplate, licenseTermsId);
attachLicenseTerms(ipId, licensingModule, 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 @@ -51,4 +49,61 @@ library LicensingHelper {
}
}
}

/// @dev Registers PIL License Terms and attaches them 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 pilTemplate The address of the PIL License Template.
/// @param licensingModule The address of the Licensing Module.
/// @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 registered PIL terms.
function registerPILTermsAndAttachWithSig(
address ipId,
address pilTemplate,
address licensingModule,
PILTerms calldata terms,
WorkflowStructs.SignatureData calldata sigAttach
) internal returns (uint256 licenseTermsId) {
licenseTermsId = IPILicenseTemplate(pilTemplate).registerLicenseTerms(terms);
attachLicenseTermsWithSig(ipId, licensingModule, pilTemplate, licenseTermsId, sigAttach);
}

/// @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 calldata 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))
}
}
}
}
}
30 changes: 19 additions & 11 deletions contracts/lib/MetadataHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity 0.8.26;

import { ICoreMetadataModule } from "@storyprotocol/core/interfaces/modules/metadata/ICoreMetadataModule.sol";
import { IIPAccount } from "@storyprotocol/core/interfaces/IIPAccount.sol";

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

/// @title Periphery Metadata Helper Library
/// @notice Library for all metadata related helper functions for Periphery contracts.
Expand All @@ -13,26 +13,34 @@ library MetadataHelper {
/// metadata is non-empty and sets the metadata via signature.
/// @param ipId The ID of the IP.
/// @param coreMetadataModule The address of the Core Metadata Module.
/// @param accessController The address of the Access Controller.
/// @param ipMetadata The metadata to set.
/// @param sigData Signature data for setAll for this IP by SPG via the Core Metadata Module.
function setMetadataWithSig(
address ipId,
address coreMetadataModule,
address accessController,
WorkflowStructs.IPMetadata calldata ipMetadata,
WorkflowStructs.SignatureData calldata sigData
) internal {
if (sigData.signer != address(0) && sigData.deadline != 0 && sigData.signature.length != 0) {
PermissionHelper.setPermissionForModule({
ipId: ipId,
module: coreMetadataModule,
accessController: accessController,
selector: ICoreMetadataModule.setAll.selector,
sigData: sigData
if (
keccak256(abi.encodePacked(ipMetadata.ipMetadataURI)) != keccak256("") ||
ipMetadata.ipMetadataHash != bytes32(0) ||
ipMetadata.nftMetadataHash != bytes32(0)
) {
IIPAccount(payable(ipId)).executeWithSig({
to: coreMetadataModule,
value: 0,
data: abi.encodeWithSelector(
ICoreMetadataModule.setAll.selector,
ipId,
ipMetadata.ipMetadataURI,
ipMetadata.ipMetadataHash,
ipMetadata.nftMetadataHash
),
signer: sigData.signer,
deadline: sigData.deadline,
signature: sigData.signature
});
}
setMetadata(ipId, coreMetadataModule, ipMetadata);
}

/// @dev Sets the metadata for the given IP if metadata is non-empty.
Expand Down
79 changes: 0 additions & 79 deletions contracts/lib/PermissionHelper.sol

This file was deleted.

Loading

0 comments on commit a6fbf2c

Please sign in to comment.