Skip to content

Commit

Permalink
Enforce maxMintingFee Across Multiple Parent IPs in LicensingModule (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
sebsadface authored and irfand29 committed Feb 8, 2025
1 parent 8edba1d commit 926736b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ library Errors {
address licenseTemplate,
uint256 licenseTermsId,
uint32 revenueShare,
uint32 maxRevenueShare
uint32 maxRevenueShareRemaining
);

////////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 6 additions & 2 deletions contracts/modules/licensing/LicensingModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -495,21 +495,25 @@ contract LicensingModule is
maxMintingFee
);

uint32 remainingRevenueShareAllowance = maxRevenueShare;
for (uint256 i = 0; i < parentIpIds.length; i++) {
royaltyPercents[i] = LICENSE_REGISTRY.getRoyaltyPercent(
parentIpIds[i],
licenseTemplate,
licenseTermsIds[i]
);
if (maxRevenueShare != 0 && royaltyPercents[i] > maxRevenueShare) {
if (remainingRevenueShareAllowance != 0 && royaltyPercents[i] > remainingRevenueShareAllowance) {
revert Errors.LicensingModule__ExceedMaxRevenueShare(
parentIpIds[i],
licenseTemplate,
licenseTermsIds[i],
royaltyPercents[i],
maxRevenueShare
remainingRevenueShareAllowance
);
}
remainingRevenueShareAllowance = remainingRevenueShareAllowance > royaltyPercents[i]
? remainingRevenueShareAllowance - royaltyPercents[i]
: 0;
}

if (royaltyPolicies.length == 0 || royaltyPolicies[0] == address(0)) return;
Expand Down
100 changes: 100 additions & 0 deletions test/foundry/modules/licensing/LicensingModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,106 @@ contract LicensingModuleTest is BaseTest {
});
}

function test_LicensingModule_revert_registerDerivative_singleParent_ExceedMaxRevenueShare() public {
uint256 commRemixTermsId = pilTemplate.registerLicenseTerms(
PILFlavors.commercialRemix({
mintingFee: 500,
commercialRevShare: 10_000_000,
currencyToken: address(erc20),
royaltyPolicy: address(royaltyPolicyLAP)
})
);

vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), commRemixTermsId);

address[] memory parentIpIds = new address[](1);
uint256[] memory licenseTermsIds = new uint256[](1);
parentIpIds[0] = ipId1;
licenseTermsIds[0] = commRemixTermsId;

vm.startPrank(ipOwner5);
erc20.mint(ipOwner5, 500);
erc20.approve(address(royaltyModule), 500);

vm.expectRevert(
abi.encodeWithSelector(
Errors.LicensingModule__ExceedMaxRevenueShare.selector,
ipId1,
address(pilTemplate),
commRemixTermsId,
10_000_000,
5_000_000
)
);
licensingModule.registerDerivative({
childIpId: ipId5,
parentIpIds: parentIpIds,
licenseTermsIds: licenseTermsIds,
licenseTemplate: address(pilTemplate),
royaltyContext: "",
maxMintingFee: 500,
maxRts: 100e6,
maxRevenueShare: 5_000_000
});
vm.stopPrank();
}

function test_LicensingModule_revert_registerDerivative_multipleParent_ExceedMaxRevenueShare() public {
uint256 commRemixTermsId = pilTemplate.registerLicenseTerms(
PILFlavors.commercialRemix({
mintingFee: 200,
commercialRevShare: 10_000_000,
currencyToken: address(erc20),
royaltyPolicy: address(royaltyPolicyLAP)
})
);

vm.prank(ipOwner1);
licensingModule.attachLicenseTerms(ipId1, address(pilTemplate), commRemixTermsId);

vm.prank(ipOwner2);
licensingModule.attachLicenseTerms(ipId2, address(pilTemplate), commRemixTermsId);

vm.prank(ipOwner3);
licensingModule.attachLicenseTerms(ipId3, address(pilTemplate), commRemixTermsId);

address[] memory parentIpIds = new address[](3);
uint256[] memory licenseTermsIds = new uint256[](3);
parentIpIds[0] = ipId1;
parentIpIds[1] = ipId2;
parentIpIds[2] = ipId3;
licenseTermsIds[0] = commRemixTermsId;
licenseTermsIds[1] = commRemixTermsId;
licenseTermsIds[2] = commRemixTermsId;

vm.startPrank(ipOwner5);
erc20.mint(ipOwner5, 600);
erc20.approve(address(royaltyModule), 600);

vm.expectRevert(
abi.encodeWithSelector(
Errors.LicensingModule__ExceedMaxRevenueShare.selector,
ipId3,
address(pilTemplate),
commRemixTermsId,
10_000_000,
25_000_000 - 10_000_000 - 10_000_000
)
);
licensingModule.registerDerivative({
childIpId: ipId5,
parentIpIds: parentIpIds,
licenseTermsIds: licenseTermsIds,
licenseTemplate: address(pilTemplate),
royaltyContext: "",
maxMintingFee: 600,
maxRts: 100e6,
maxRevenueShare: 25_000_000
});
vm.stopPrank();
}

function test_LicensingModule_mintLicenseTokens_mintMultipleTimes() public {
uint256 termsId = pilTemplate.registerLicenseTerms(PILFlavors.defaultValuesLicenseTerms());
vm.prank(ipOwner1);
Expand Down

0 comments on commit 926736b

Please sign in to comment.