From a186a40275b084d29f5c75a1f208fc6ffe0b376b Mon Sep 17 00:00:00 2001 From: Kingster Date: Tue, 19 Nov 2024 21:54:15 -0800 Subject: [PATCH 1/2] LicenseConfig can only increase Royalty Percentage --- .../modules/licensing/PILicenseTemplate.sol | 2 +- .../modules/licensing/LicensingModule.t.sol | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/contracts/modules/licensing/PILicenseTemplate.sol b/contracts/modules/licensing/PILicenseTemplate.sol index 508294ae..74d070e9 100644 --- a/contracts/modules/licensing/PILicenseTemplate.sol +++ b/contracts/modules/licensing/PILicenseTemplate.sol @@ -302,7 +302,7 @@ contract PILicenseTemplate is function canOverrideRoyaltyPercent(uint256 licenseTermsId, uint32 newRoyaltyPercent) external view returns (bool) { if (licenseTermsId == 0 || newRoyaltyPercent == 0) return false; PILTerms memory terms = _getPILicenseTemplateStorage().licenseTerms[licenseTermsId]; - return terms.commercialUse; + return terms.commercialUse && newRoyaltyPercent >= terms.commercialRevShare; } /// @notice checks the contract whether supports the given interface. diff --git a/test/foundry/modules/licensing/LicensingModule.t.sol b/test/foundry/modules/licensing/LicensingModule.t.sol index 2d31cf9a..2a60370d 100644 --- a/test/foundry/modules/licensing/LicensingModule.t.sol +++ b/test/foundry/modules/licensing/LicensingModule.t.sol @@ -1936,6 +1936,39 @@ contract LicensingModuleTest is BaseTest { licensingModule.setLicensingConfig(ipId1, address(pilTemplate), socialRemixTermsId, licensingConfig); } + function test_LicensingModule_setLicensingConfig_revert_newRoyaltyPercentLessThanLicenseTerms() public { + uint256 commRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.commercialRemix( + { + mintingFee: 0, + commercialRevShare: 20_000_000, + royaltyPolicy: address(royaltyPolicyLRP), + currencyToken: address(erc20) + } + )); + MockLicensingHook licensingHook = new MockLicensingHook(); + vm.prank(admin); + moduleRegistry.registerModule("MockLicensingHook", address(licensingHook)); + Licensing.LicensingConfig memory licensingConfig = Licensing.LicensingConfig({ + isSet: true, + mintingFee: 100, + licensingHook: address(licensingHook), + hookData: abi.encode(address(0x123)), + commercialRevShare: 10_000_000, + disabled: false + }); + + vm.expectRevert( + abi.encodeWithSelector( + Errors.LicensingModule__CurrentLicenseNotAllowOverrideRoyaltyPercent.selector, + address(pilTemplate), + commRemixTermsId, + 10_000_000 + ) + ); + vm.prank(ipOwner1); + licensingModule.setLicensingConfig(ipId1, address(pilTemplate), commRemixTermsId, licensingConfig); + } + function test_LicensingModule_setLicensingConfig_revert_invalidLicensingHook() public { uint256 socialRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.nonCommercialSocialRemixing()); // unregistered the licensing hook From 8ef1be767a08ae18499c59ebc6df987724b8ac83 Mon Sep 17 00:00:00 2001 From: Kingster Date: Tue, 19 Nov 2024 22:01:05 -0800 Subject: [PATCH 2/2] fix lint --- test/foundry/modules/licensing/LicensingModule.t.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/foundry/modules/licensing/LicensingModule.t.sol b/test/foundry/modules/licensing/LicensingModule.t.sol index 2a60370d..c3e3332a 100644 --- a/test/foundry/modules/licensing/LicensingModule.t.sol +++ b/test/foundry/modules/licensing/LicensingModule.t.sol @@ -1937,14 +1937,14 @@ contract LicensingModuleTest is BaseTest { } function test_LicensingModule_setLicensingConfig_revert_newRoyaltyPercentLessThanLicenseTerms() public { - uint256 commRemixTermsId = pilTemplate.registerLicenseTerms(PILFlavors.commercialRemix( - { + uint256 commRemixTermsId = pilTemplate.registerLicenseTerms( + PILFlavors.commercialRemix({ mintingFee: 0, commercialRevShare: 20_000_000, royaltyPolicy: address(royaltyPolicyLRP), currencyToken: address(erc20) - } - )); + }) + ); MockLicensingHook licensingHook = new MockLicensingHook(); vm.prank(admin); moduleRegistry.registerModule("MockLicensingHook", address(licensingHook));