Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize license struct #107

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions contracts/LicenseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
function mintLicenseTokens(
address licensorIpId,
address licenseTemplate,
uint256 licenseTermsId,
uint32 licenseTermsId,
uint256 amount, // mint amount
address minter,
address receiver
Expand All @@ -111,8 +111,8 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
licenseTemplate: licenseTemplate,
licenseTermsId: licenseTermsId,
transferable: ILicenseTemplate(licenseTemplate).isLicenseTransferable(licenseTermsId),
mintedAt: block.timestamp,
expiresAt: ILicenseTemplate(licenseTemplate).getExpireTime(licenseTermsId, block.timestamp)
mintedAt: uint40(block.timestamp),
expiresAt: ILicenseTemplate(licenseTemplate).getExpireTime(licenseTermsId, uint40(block.timestamp))
});

LicenseTokenStorage storage $ = _getLicenseTokenStorage();
Expand Down Expand Up @@ -149,15 +149,11 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
address childIpId,
address childIpOwner,
uint256[] calldata tokenIds
)
external
view
returns (address licenseTemplate, address[] memory licensorIpIds, uint256[] memory licenseTermsIds)
{
) external view returns (address licenseTemplate, address[] memory licensorIpIds, uint32[] memory licenseTermsIds) {
LicenseTokenStorage storage $ = _getLicenseTokenStorage();
licenseTemplate = $.licenseTokenMetadatas[tokenIds[0]].licenseTemplate;
licensorIpIds = new address[](tokenIds.length);
licenseTermsIds = new uint256[](tokenIds.length);
licenseTermsIds = new uint32[](tokenIds.length);

for (uint256 i = 0; i < tokenIds.length; i++) {
LicenseTokenMetadata memory ltm = $.licenseTokenMetadatas[tokenIds[i]];
Expand Down Expand Up @@ -203,7 +199,7 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag

/// @notice Returns the ID of the license terms that are used for the given license ID
/// @param tokenId The ID of the license token
function getLicenseTermsId(uint256 tokenId) external view returns (uint256) {
function getLicenseTermsId(uint256 tokenId) external view returns (uint32) {
return _getLicenseTokenStorage().licenseTokenMetadatas[tokenId].licenseTermsId;
}

Expand Down
19 changes: 10 additions & 9 deletions contracts/interfaces/ILicenseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ import { IERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensio
/// metadata.
interface ILicenseToken is IERC721Metadata, IERC721Enumerable {
/// @notice Metadata struct for License Tokens.
/// @dev Struct layout for 2 storage slots.
/// @param licensorIpId The ID of the licensor IP for which the License Token was minted.
/// @param licenseTemplate The address of the License Template associated with the License Token.
/// @param licenseTermsId The ID of the License Terms associated with the License Token.
/// @param transferable Whether the License Token is transferable, determined by the License Terms.
/// @param licenseTermsId The ID of the License Terms associated with the License Token.
/// @param licenseTemplate The address of the License Template associated with the License Token.
/// @param mintedAt The timestamp at which the License Token was minted.
/// @param expiresAt The timestamp at which the License Token expires.
struct LicenseTokenMetadata {
address licensorIpId;
address licenseTemplate;
uint256 licenseTermsId;
bool transferable;
uint256 mintedAt;
uint256 expiresAt;
uint32 licenseTermsId;
address licenseTemplate;
uint40 mintedAt;
uint40 expiresAt;
}

/// @notice Emitted when a License Token is minted.
Expand All @@ -48,7 +49,7 @@ interface ILicenseToken is IERC721Metadata, IERC721Enumerable {
function mintLicenseTokens(
address licensorIpId,
address licenseTemplate,
uint256 licenseTermsId,
uint32 licenseTermsId,
uint256 amount, // mint amount
address minter,
address receiver
Expand All @@ -71,7 +72,7 @@ interface ILicenseToken is IERC721Metadata, IERC721Enumerable {

/// @notice Returns the ID of the license terms that are used for the given license ID
/// @param tokenId The ID of the license token
function getLicenseTermsId(uint256 tokenId) external view returns (uint256);
function getLicenseTermsId(uint256 tokenId) external view returns (uint32);

/// @notice Returns the address of the license template that is used for the given license ID
/// @param tokenId The ID of the license token
Expand Down Expand Up @@ -107,5 +108,5 @@ interface ILicenseToken is IERC721Metadata, IERC721Enumerable {
address childIpId,
address childIpOwner,
uint256[] calldata tokenIds
) external view returns (address licenseTemplate, address[] memory licensorIpIds, uint256[] memory licenseTermsIds);
) external view returns (address licenseTemplate, address[] memory licensorIpIds, uint32[] memory licenseTermsIds);
}
30 changes: 15 additions & 15 deletions contracts/interfaces/modules/licensing/ILicenseTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ILicenseTemplate is IERC165 {
/// @param licenseTermsId The ID of the license terms.
/// @param licenseTemplate The address of the license template.
/// @param licenseTerms The data of the license.
event LicenseTermsRegistered(uint256 indexed licenseTermsId, address indexed licenseTemplate, bytes licenseTerms);
event LicenseTermsRegistered(uint32 indexed licenseTermsId, address indexed licenseTemplate, bytes licenseTerms);

/// @notice Returns the name of the license template.
/// @return The name of the license template.
Expand All @@ -27,7 +27,7 @@ interface ILicenseTemplate is IERC165 {
/// hence the json format should follow the common NFT metadata standard.
/// @param licenseTermsId The ID of the license terms.
/// @return The JSON string of the license terms.
function toJson(uint256 licenseTermsId) external view returns (string memory);
function toJson(uint32 licenseTermsId) external view returns (string memory);

/// @notice Returns the metadata URI of the license template.
/// @return The metadata URI of the license template.
Expand All @@ -36,33 +36,33 @@ interface ILicenseTemplate is IERC165 {
/// @notice Returns the URI of the license terms.
/// @param licenseTermsId The ID of the license terms.
/// @return The URI of the license terms.
function getLicenseTermsURI(uint256 licenseTermsId) external view returns (string memory);
function getLicenseTermsURI(uint32 licenseTermsId) external view returns (string memory);

/// @notice Returns the total number of registered license terms.
/// @return The total number of registered license terms.
function totalRegisteredLicenseTerms() external view returns (uint256);
function totalRegisteredLicenseTerms() external view returns (uint32);

/// @notice Checks if a license terms exists.
/// @param licenseTermsId The ID of the license terms.
/// @return True if the license terms exists, false otherwise.
function exists(uint256 licenseTermsId) external view returns (bool);
function exists(uint32 licenseTermsId) external view returns (bool);

/// @notice Checks if a license terms is transferable.
/// @param licenseTermsId The ID of the license terms.
/// @return True if the license terms is transferable, false otherwise.
function isLicenseTransferable(uint256 licenseTermsId) external view returns (bool);
function isLicenseTransferable(uint32 licenseTermsId) external view returns (bool);

/// @notice Returns the earliest expiration time among the given license terms.
/// @param start The start time to calculate the expiration time.
/// @param licenseTermsIds The IDs of the license terms.
/// @param start The start time to calculate the expiration time.
/// @return The earliest expiration time.
function getEarlierExpireTime(uint256[] calldata licenseTermsIds, uint256 start) external view returns (uint256);
function getEarlierExpireTime(uint32[] calldata licenseTermsIds, uint40 start) external view returns (uint40);

/// @notice Returns the expiration time of a license terms.
/// @param start The start time.
/// @param licenseTermsId The ID of the license terms.
/// @param start The start time.
/// @return The expiration time.
function getExpireTime(uint256 licenseTermsId, uint256 start) external view returns (uint256);
function getExpireTime(uint32 licenseTermsId, uint40 start) external view returns (uint40);

/// @notice Returns the royalty policy of a license terms.
/// @dev All License Templates should implement this method.
Expand All @@ -76,7 +76,7 @@ interface ILicenseTemplate is IERC165 {
/// @return currencyToken The address of the ERC20 token, used for minting license fee and royalties.
/// the currency token will used for pay for license token minting fee and royalties.
function getRoyaltyPolicy(
uint256 licenseTermsId
uint32 licenseTermsId
)
external
view
Expand All @@ -91,7 +91,7 @@ interface ILicenseTemplate is IERC165 {
/// @param amount The amount of licenses to mint.
/// @return True if the minting is verified, false otherwise.
function verifyMintLicenseToken(
uint256 licenseTermsId,
uint32 licenseTermsId,
address licensee,
address licensorIpId,
uint256 amount
Expand All @@ -109,7 +109,7 @@ interface ILicenseTemplate is IERC165 {
function verifyRegisterDerivative(
address childIpId,
address parentIpId,
uint256 licenseTermsId,
uint32 licenseTermsId,
address licensee
) external returns (bool);

Expand All @@ -119,7 +119,7 @@ interface ILicenseTemplate is IERC165 {
/// It ensures that the licenses of all parent IPs are compatible with each other during the registration process.
/// @param licenseTermsIds The IDs of the license terms.
/// @return True if the licenses are compatible, false otherwise.
function verifyCompatibleLicenses(uint256[] calldata licenseTermsIds) external view returns (bool);
function verifyCompatibleLicenses(uint32[] calldata licenseTermsIds) external view returns (bool);

/// @notice Verifies the registration of a derivative for all parent IPs.
/// @dev This function is called by the LicensingModule to verify licenses for registering a derivative IP
Expand All @@ -134,7 +134,7 @@ interface ILicenseTemplate is IERC165 {
function verifyRegisterDerivativeForAllParents(
address childIpId,
address[] calldata parentIpId,
uint256[] calldata licenseTermsIds,
uint32[] calldata licenseTermsIds,
address childIpOwner
) external returns (bool);
}
12 changes: 6 additions & 6 deletions contracts/interfaces/modules/licensing/ILicensingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ILicensingModule is IModule {
address indexed caller,
address indexed ipId,
address licenseTemplate,
uint256 licenseTermsId
uint32 licenseTermsId
);

/// @notice Emitted when license tokens are minted.
Expand All @@ -34,7 +34,7 @@ interface ILicensingModule is IModule {
address indexed caller,
address indexed licensorIpId,
address licenseTemplate,
uint256 indexed licenseTermsId,
uint32 indexed licenseTermsId,
uint256 amount,
address receiver,
uint256 startLicenseTokenId
Expand All @@ -52,7 +52,7 @@ interface ILicensingModule is IModule {
address indexed childIpId,
uint256[] licenseTokenIds,
address[] parentIpIds,
uint256[] licenseTermsIds,
uint32[] licenseTermsIds,
address licenseTemplate
);

Expand All @@ -61,7 +61,7 @@ interface ILicensingModule is IModule {
/// @param ipId The IP ID.
/// @param licenseTemplate The address of the license template.
/// @param licenseTermsId The ID of the license terms.
function attachLicenseTerms(address ipId, address licenseTemplate, uint256 licenseTermsId) external;
function attachLicenseTerms(address ipId, address licenseTemplate, uint32 licenseTermsId) external;

/// @notice Mints license tokens for the license terms attached to an IP.
/// The license tokens are minted to the receiver.
Expand All @@ -85,7 +85,7 @@ interface ILicensingModule is IModule {
function mintLicenseTokens(
address licensorIpId,
address licenseTemplate,
uint256 licenseTermsId,
uint32 licenseTermsId,
uint256 amount,
address receiver,
bytes calldata royaltyContext
Expand All @@ -104,7 +104,7 @@ interface ILicensingModule is IModule {
function registerDerivative(
address childIpId,
address[] calldata parentIpIds,
uint256[] calldata licenseTermsIds,
uint32[] calldata licenseTermsIds,
address licenseTemplate,
bytes calldata royaltyContext
) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PILTerms {
bool transferable;
address royaltyPolicy;
uint256 mintingFee;
uint256 expiration;
uint40 expiration;
bool commercialUse;
bool commercialAttribution;
address commercializerChecker;
Expand All @@ -53,15 +53,15 @@ interface IPILicenseTemplate is ILicenseTemplate {
/// @notice Registers new license terms.
/// @param terms The PILTerms to register.
/// @return selectedLicenseTermsId The ID of the newly registered license terms.
function registerLicenseTerms(PILTerms calldata terms) external returns (uint256 selectedLicenseTermsId);
function registerLicenseTerms(PILTerms calldata terms) external returns (uint32 selectedLicenseTermsId);

/// @notice Gets the ID of the given license terms.
/// @param terms The PILTerms to get the ID for.
/// @return selectedLicenseTermsId The ID of the given license terms.
function getLicenseTermsId(PILTerms calldata terms) external view returns (uint256 selectedLicenseTermsId);
function getLicenseTermsId(PILTerms calldata terms) external view returns (uint32 selectedLicenseTermsId);

/// @notice Gets license terms of the given ID.
/// @param selectedLicenseTermsId The ID of the license terms.
/// @return terms The PILTerms associate with the given ID.
function getLicenseTerms(uint256 selectedLicenseTermsId) external view returns (PILTerms memory terms);
function getLicenseTerms(uint32 selectedLicenseTermsId) external view returns (PILTerms memory terms);
}
22 changes: 11 additions & 11 deletions contracts/interfaces/registries/ILicenseRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ILicenseRegistry {
event MintingLicenseConfigSetLicense(
address indexed ipId,
address indexed licenseTemplate,
uint256 indexed licenseTermsId
uint32 indexed licenseTermsId
);

/// @notice Emitted when a minting license configuration is set for all licenses of an IP.
Expand All @@ -28,10 +28,10 @@ interface ILicenseRegistry {
/// @notice Sets the default license terms that are attached to all IPs by default.
/// @param newLicenseTemplate The address of the new default license template.
/// @param newLicenseTermsId The ID of the new default license terms.
function setDefaultLicenseTerms(address newLicenseTemplate, uint256 newLicenseTermsId) external;
function setDefaultLicenseTerms(address newLicenseTemplate, uint32 newLicenseTermsId) external;

/// @notice Returns the default license terms.
function getDefaultLicenseTerms() external view returns (address licenseTemplate, uint256 licenseTermsId);
function getDefaultLicenseTerms() external view returns (address licenseTemplate, uint32 licenseTermsId);

/// @notice Registers a new license template in the Story Protocol.
/// @param licenseTemplate The address of the license template to register.
Expand All @@ -51,7 +51,7 @@ interface ILicenseRegistry {
address ipId,
address[] calldata parentIpIds,
address licenseTemplate,
uint256[] calldata licenseTermsIds
uint32[] calldata licenseTermsIds
) external;

/// @notice Checks if an IP is a derivative IP.
Expand All @@ -75,21 +75,21 @@ interface ILicenseRegistry {
function verifyMintLicenseToken(
address licensorIpId,
address licenseTemplate,
uint256 licenseTermsId,
uint32 licenseTermsId,
bool isMintedByIpOwner
) external view returns (Licensing.MintingLicenseConfig memory);

/// @notice Attaches license terms to an IP.
/// @param ipId The address of the IP to which the license terms are attached.
/// @param licenseTemplate The address of the license template.
/// @param licenseTermsId The ID of the license terms.
function attachLicenseTermsToIp(address ipId, address licenseTemplate, uint256 licenseTermsId) external;
function attachLicenseTermsToIp(address ipId, address licenseTemplate, uint32 licenseTermsId) external;

/// @notice Checks if license terms exist.
/// @param licenseTemplate The address of the license template where the license terms are defined.
/// @param licenseTermsId The ID of the license terms.
/// @return Whether the license terms exist.
function exists(address licenseTemplate, uint256 licenseTermsId) external view returns (bool);
function exists(address licenseTemplate, uint32 licenseTermsId) external view returns (bool);

/// @notice Checks if an IP has attached any license terms.
/// @param ipId The address of the IP to check.
Expand All @@ -99,7 +99,7 @@ interface ILicenseRegistry {
function hasIpAttachedLicenseTerms(
address ipId,
address licenseTemplate,
uint256 licenseTermsId
uint32 licenseTermsId
) external view returns (bool);

/// @notice Gets the attached license terms of an IP by its index.
Expand All @@ -110,7 +110,7 @@ interface ILicenseRegistry {
function getAttachedLicenseTerms(
address ipId,
uint256 index
) external view returns (address licenseTemplate, uint256 licenseTermsId);
) external view returns (address licenseTemplate, uint32 licenseTermsId);

/// @notice Gets the count of attached license terms of an IP.
/// @param ipId The address of the IP.
Expand Down Expand Up @@ -154,7 +154,7 @@ interface ILicenseRegistry {
function getMintingLicenseConfig(
address ipId,
address licenseTemplate,
uint256 licenseTermsId
uint32 licenseTermsId
) external view returns (Licensing.MintingLicenseConfig memory);

/// @notice Sets the minting license configuration for a specific license attached to a specific IP.
Expand All @@ -166,7 +166,7 @@ interface ILicenseRegistry {
function setMintingLicenseConfigForLicense(
address ipId,
address licenseTemplate,
uint256 licenseTermsId,
uint32 licenseTermsId,
Licensing.MintingLicenseConfig calldata mintingLicenseConfig
) external;

Expand Down
Loading
Loading