Skip to content

Commit

Permalink
feat(spg): add group IPA features
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface committed Aug 28, 2024
1 parent 31233dd commit 087f63e
Show file tree
Hide file tree
Showing 8 changed files with 785 additions and 107 deletions.
252 changes: 203 additions & 49 deletions contracts/StoryProtocolGateway.sol

Large diffs are not rendered by default.

110 changes: 83 additions & 27 deletions contracts/interfaces/IStoryProtocolGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ interface IStoryProtocolGateway {
address owner
) external returns (address nftContract);

/// @notice Mint an NFT from a collection and register it with metadata as an IP.
/// @notice Mint an NFT from a SPGNFT collection and register it with metadata as an IP.
/// @dev Caller must have the minter role for the provided SPG NFT.
/// @param nftContract The address of the NFT collection.
/// @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.
/// @return ipId The ID of the registered IP.
/// @return tokenId The ID of the minted NFT.
/// @return tokenId The ID of the newly minted NFT.
function mintAndRegisterIp(
address nftContract,
address spgNftContract,
address recipient,
IPMetadata calldata ipMetadata
) external returns (address ipId, uint256 tokenId);
Expand All @@ -78,7 +78,7 @@ interface IStoryProtocolGateway {
/// @param tokenId The ID of the NFT.
/// @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.
/// @return ipId The ID of the registered IP.
/// @return ipId The ID of the newly registered IP.
function registerIp(
address nftContract,
uint256 tokenId,
Expand All @@ -89,21 +89,22 @@ interface IStoryProtocolGateway {
/// @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.
/// @return licenseTermsId The ID of the registered PIL terms.
/// @return licenseTermsId The ID of the newly registered PIL terms.
function registerPILTermsAndAttach(address ipId, PILTerms calldata terms) external returns (uint256 licenseTermsId);

/// @notice Mint an NFT from a collection, register it with metadata as an IP, register Programmable IP License
/// @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 Caller must have the minter role for the provided SPG NFT.
/// @param nftContract The address of the NFT collection.
/// @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.
/// @return ipId The ID of the registered IP.
/// @return tokenId The ID of the minted NFT.
/// @return licenseTermsId The ID of the registered PIL terms.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
/// @return licenseTermsId The ID of the newly registered PIL terms.
function mintAndRegisterIpAndAttachPILTerms(
address nftContract,
address spgNftContract,
address recipient,
IPMetadata calldata ipMetadata,
PILTerms calldata terms
Expand All @@ -118,8 +119,8 @@ interface IStoryProtocolGateway {
/// @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 sigAttach Signature data for attachLicenseTerms to the IP via the Licensing Module.
/// @return ipId The ID of the registered IP.
/// @return licenseTermsId The ID of the registered PIL terms.
/// @return ipId The ID of the newly registered IP.
/// @return licenseTermsId The ID of the newly registered PIL terms.
function registerIpAndAttachPILTerms(
address nftContract,
uint256 tokenId,
Expand All @@ -129,29 +130,29 @@ interface IStoryProtocolGateway {
SignatureData calldata sigAttach
) external returns (address ipId, uint256 licenseTermsId);

/// @notice Mint an NFT from a collection and register it as a derivative IP without license tokens.
/// @notice Mint an NFT from a SPGNFT collection and register it as a derivative IP without license tokens.
/// @dev Caller must have the minter role for the provided SPG NFT.
/// @param nftContract The address of the NFT collection.
/// @param spgNftContract The address of the SPGNFT collection.
/// @param derivData The derivative data to be used for registerDerivative.
/// @param ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param recipient The address to receive the minted NFT.
/// @return ipId The ID of the registered IP.
/// @return tokenId The ID of the minted NFT.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
function mintAndRegisterIpAndMakeDerivative(
address nftContract,
address spgNftContract,
MakeDerivative calldata derivData,
IPMetadata calldata ipMetadata,
address recipient
) external returns (address ipId, uint256 tokenId);

/// @notice Register the given NFT as a derivative IP with metadata without using license tokens.
/// @notice Register the given NFT as a derivative IP with metadata without license tokens.
/// @param nftContract The address of the NFT collection.
/// @param tokenId The ID of the NFT.
/// @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 sigRegister Signature data for registerDerivative for the IP via the Licensing Module.
/// @return ipId The ID of the registered IP.
/// @return ipId The ID of the newly registered IP.
function registerIpAndMakeDerivative(
address nftContract,
uint256 tokenId,
Expand All @@ -161,17 +162,17 @@ interface IStoryProtocolGateway {
SignatureData calldata sigRegister
) external returns (address ipId);

/// @notice Mint an NFT from a collection and register it as a derivative IP using license tokens.
/// @notice Mint an NFT from a SPGNFT collection and register it as a derivative IP using license tokens.
/// @dev Caller must have the minter role for the provided SPG NFT.
/// @param nftContract The address of the NFT collection.
/// @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 ipMetadata OPTIONAL. The desired metadata for the newly minted NFT and registered IP.
/// @param recipient The address to receive the minted NFT.
/// @return ipId The ID of the registered IP.
/// @return tokenId The ID of the minted NFT.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
function mintAndRegisterIpAndMakeDerivativeWithLicenseTokens(
address nftContract,
address spgNftContract,
uint256[] calldata licenseTokenIds,
bytes calldata royaltyContext,
IPMetadata calldata ipMetadata,
Expand All @@ -186,7 +187,7 @@ interface IStoryProtocolGateway {
/// @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.
/// @return ipId The ID of the registered IP.
/// @return ipId The ID of the newly registered IP.
function registerIpAndMakeDerivativeWithLicenseTokens(
address nftContract,
uint256 tokenId,
Expand All @@ -196,4 +197,59 @@ interface IStoryProtocolGateway {
SignatureData calldata sigMetadata,
SignatureData calldata sigRegister
) external returns (address ipId);

/// @notice Mint an NFT from a SPGNFT collection, register it with metadata as an IP,
/// attach Programmable IP License Terms to the registered IP, and add it to a group IP.
/// @dev Caller must have the minter role for the provided SPG NFT.
/// @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 licenseTermsId The ID of the registered PIL terms that will be attached to the newly registered 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.
/// @return ipId The ID of the newly registered IP.
/// @return tokenId The ID of the newly minted NFT.
function mintAndRegisterIpAndAttachPILTermsAndAddToGroup(
address spgNftContract,
address groupId,
address recipient,
uint256 licenseTermsId,
IPMetadata calldata ipMetadata,
SignatureData calldata sigAddToGroup
) external returns (address ipId, uint256 tokenId);

/// @notice Register an NFT as IP with metadata, attach Programmable IP License Terms to the registered IP,
/// and add it to a group IP.
/// @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 licenseTermsId The ID of the registered PIL terms that will be attached to the newly registered 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 sigAddToGroup Signature data for addIp to the group IP via the Grouping Module.
/// @return ipId The ID of the newly registered IP.
function registerIpAndAttachPILTermsAndAddToGroup(
address nftContract,
uint256 tokenId,
address groupId,
uint256 licenseTermsId,
IPMetadata calldata ipMetadata,
SignatureData calldata sigMetadataAndAttach,
SignatureData calldata sigAddToGroup
) external returns (address ipId);

/// @notice Register a group IP with a group reward pool, register Programmable IP License Terms,
/// attach it to the group IP, and add individual IPs to the group IP.
/// @dev ipIds must be have the same PIL 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 groupIpTerms The PIL terms to be registered and attached to the newly registered group IP.
/// @return groupId The ID of the newly registered group IP.
/// @return groupLicenseTermsId The ID of the newly registered PIL terms.
function registerGroupAndAttachPILTermsAndAddIps(
address groupPool,
address[] calldata ipIds,
PILTerms calldata groupIpTerms
) external returns (address groupId, uint256 groupLicenseTermsId);
}
8 changes: 4 additions & 4 deletions script/Main.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ pragma solidity ^0.8.23;

import { console2 } from "forge-std/console2.sol";
import { Script } from "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { ICreate3Deployer } from "@create3-deployer/contracts/Create3Deployer.sol";

import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import { IPAssetRegistry } from "@storyprotocol/core/registries/IPAssetRegistry.sol";

import { StoryProtocolGateway } from "../contracts/StoryProtocolGateway.sol";
import { SPGNFT } from "../contracts/SPGNFT.sol";
Expand Down Expand Up @@ -61,7 +59,9 @@ contract Main is Script, StoryProtocolCoreAddressManager, BroadcastManager, Json
royaltyModuleAddr,
coreMetadataModuleAddr,
pilTemplateAddr,
licenseTokenAddr
licenseTokenAddr,
groupingModuleAddr,
groupNFTAddr
)
);
spg = StoryProtocolGateway(
Expand Down Expand Up @@ -103,7 +103,7 @@ contract Main is Script, StoryProtocolCoreAddressManager, BroadcastManager, Json
console2.log(string.concat(contractKey, " deployed to:"), newAddress);
}

function _getSalt(string memory name) private view returns (bytes32 salt) {
function _getSalt(string memory name) private pure returns (bytes32 salt) {
salt = keccak256(abi.encode(name, create3SaltSeed));
}
}
4 changes: 3 additions & 1 deletion script/UpgradeSPG.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ contract UpgradeSPG is
royaltyModuleAddr,
coreMetadataModuleAddr,
pilTemplateAddr,
licenseTokenAddr
licenseTokenAddr,
groupingModuleAddr,
groupNFTAddr
)
);
console2.log("New SPG Implementation", newSpgImpl);
Expand Down
4 changes: 4 additions & 0 deletions script/utils/StoryProtocolCoreAddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ contract StoryProtocolCoreAddressManager is Script {
address internal accessControllerAddr;
address internal pilTemplateAddr;
address internal licenseTokenAddr;
address internal groupingModuleAddr;
address internal groupNFTAddr;

function _readStoryProtocolCoreAddresses() internal {
string memory root = vm.projectRoot();
Expand All @@ -39,5 +41,7 @@ contract StoryProtocolCoreAddressManager is Script {
accessControllerAddr = json.readAddress(".main.AccessController");
pilTemplateAddr = json.readAddress(".main.PILicenseTemplate");
licenseTokenAddr = json.readAddress(".main.LicenseToken");
groupingModuleAddr = json.readAddress(".main.GroupingModule");
groupNFTAddr = json.readAddress(".main.GroupNFT");
}
}
Loading

0 comments on commit 087f63e

Please sign in to comment.