Skip to content

Commit

Permalink
Prevent Royalty Over 100 Percent When Minting License Tokens (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will authored Dec 12, 2024
1 parent 4bb66ad commit b4af15c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contracts/LicenseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IDisputeModule public immutable DISPUTE_MODULE;

/// @notice Max Royalty percentage is 100_000_000 means 100%.
uint32 public constant MAX_COMMERCIAL_REVENUE_SHARE = 100_000_000;

/// @notice Emitted for metadata updates, per EIP-4906
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);

Expand Down Expand Up @@ -102,6 +105,14 @@ contract LicenseToken is ILicenseToken, ERC721EnumerableUpgradeable, AccessManag
commercialRevShare: LICENSE_REGISTRY.getRoyaltyPercent(licensorIpId, licenseTemplate, licenseTermsId)
});

if (ltm.commercialRevShare > MAX_COMMERCIAL_REVENUE_SHARE) {
revert Errors.LicenseToken__InvalidRoyaltyPercent(
ltm.commercialRevShare,
licensorIpId,
licenseTemplate,
licenseTermsId
);
}
LicenseTokenStorage storage $ = _getLicenseTokenStorage();
startLicenseTokenId = $.totalMintedTokens;
$.totalMintedTokens += amount;
Expand Down
8 changes: 8 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ library Errors {
address anotherLicenseTemplate
);

/// @notice Royalty percentage is invalid that over 100%.
error LicenseToken__InvalidRoyaltyPercent(
uint32 invalidRoyaltyPercent,
address ipId,
address licenseTemplate,
uint256 licenseTermsId
);

////////////////////////////////////////////////////////////////////////////
// Licensing Module //
////////////////////////////////////////////////////////////////////////////
Expand Down
40 changes: 40 additions & 0 deletions test/foundry/LicenseToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,44 @@ contract LicenseTokenTest is BaseTest {
assertEq(lmt.commercialRevShare, 20_000_000);
assertEq(lmt.transferable, true);
}

function test_LicenseToken_mintLicenseToken_revert_InvalidRoyaltyPercentage() public {
uint256 licenseTermsId = pilTemplate.registerLicenseTerms(
PILFlavors.commercialRemix(0, 100_000_000, address(royaltyPolicyLAP), address(USDC))
);

// attach license terms to the ipAcct
Licensing.LicensingConfig memory licensingConfig = Licensing.LicensingConfig({
isSet: true,
mintingFee: 0,
licensingHook: address(0),
hookData: "",
commercialRevShare: 200_000_000,
disabled: false,
expectMinimumGroupRewardShare: 0,
expectGroupRewardPool: address(0)
});
vm.startPrank(ipOwner[1]);
licensingModule.attachLicenseTerms(ipAcct[1], address(pilTemplate), licenseTermsId);
licensingModule.setLicensingConfig(ipAcct[1], address(pilTemplate), licenseTermsId, licensingConfig);
vm.stopPrank();
vm.prank(address(licensingModule));
vm.expectRevert(
abi.encodeWithSelector(
Errors.LicenseToken__InvalidRoyaltyPercent.selector,
200_000_000,
ipAcct[1],
address(pilTemplate),
licenseTermsId
)
);
uint256 licenseTokenId = licenseToken.mintLicenseTokens({
licensorIpId: ipAcct[1],
licenseTemplate: address(pilTemplate),
licenseTermsId: licenseTermsId,
amount: 1,
minter: ipOwner[1],
receiver: ipOwner[1]
});
}
}

0 comments on commit b4af15c

Please sign in to comment.