Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
royalty module adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Spablob committed Feb 17, 2024
1 parent bd0d76e commit 0650769
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/interfaces/modules/royalty/IRoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ interface IRoyaltyModule is IModule {
/// @param amount The amount that is paid
event RoyaltyPaid(address receiverIpId, address payerIpId, address sender, address token, uint256 amount);

/// @notice Event emitted when the license minting fee is paid
/// @param receiverIpId The ipId that receives the royalties
/// @param payerAddress The address that pays the royalties
/// @param token The token that is used to pay the royalties
/// @param amount The amount paid
event LicenseMintingFeePaid(address receiverIpId, address payerAddress, address token, uint256 amount);

/// @notice Returns the licensing module address
function LICENSING_MODULE() external view returns (address);

Expand Down Expand Up @@ -93,4 +100,18 @@ interface IRoyaltyModule is IModule {
/// @param token The token to use to pay the royalties
/// @param amount The amount to pay
function payRoyaltyOnBehalf(address receiverIpId, address payerIpId, address token, uint256 amount) external;

/// @notice Allows to pay the minting fee for a license
/// @param receiverIpId The ipId that receives the royalties
/// @param payerAddress The address that pays the royalties
/// @param licenseRoyaltyPolicy The royalty policy of the license being minted
/// @param token The token to use to pay the royalties
/// @param amount The amount to pay
function payLicenseMintingFee(
address receiverIpId,
address payerAddress,
address licenseRoyaltyPolicy,
address token,
uint256 amount
) external;
}
24 changes: 24 additions & 0 deletions contracts/modules/royalty-module/RoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ contract RoyaltyModule is IRoyaltyModule, Governable, ReentrancyGuard, BaseModul
emit RoyaltyPaid(receiverIpId, payerIpId, msg.sender, token, amount);
}

/// @notice Allows to pay the minting fee for a license
/// @param receiverIpId The ipId that receives the royalties
/// @param payerAddress The address that pays the royalties
/// @param licenseRoyaltyPolicy The royalty policy of the license being minted
/// @param token The token to use to pay the royalties
/// @param amount The amount to pay
function payLicenseMintingFee(
address receiverIpId,
address payerAddress,
address licenseRoyaltyPolicy,
address token,
uint256 amount
) external onlyLicensingModule {
if (!isWhitelistedRoyaltyToken[token]) revert Errors.RoyaltyModule__NotWhitelistedRoyaltyToken();

if (licenseRoyaltyPolicy == address(0)) revert Errors.RoyaltyModule__NoRoyaltyPolicySet();
if (!isWhitelistedRoyaltyPolicy[licenseRoyaltyPolicy])
revert Errors.RoyaltyModule__NotWhitelistedRoyaltyPolicy();

IRoyaltyPolicy(licenseRoyaltyPolicy).onRoyaltyPayment(payerAddress, receiverIpId, token, amount);

emit LicenseMintingFeePaid(receiverIpId, payerAddress, token, amount);
}

/// @notice IERC165 interface support.
function supportsInterface(bytes4 interfaceId) public view virtual override(BaseModule, IERC165) returns (bool) {
return interfaceId == type(IRoyaltyModule).interfaceId || super.supportsInterface(interfaceId);
Expand Down
31 changes: 31 additions & 0 deletions test/foundry/modules/royalty/RoyaltyModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract TestRoyaltyModule is BaseTest {
event RoyaltyTokenWhitelistUpdated(address token, bool allowed);
event RoyaltyPolicySet(address ipId, address royaltyPolicy, bytes data);
event RoyaltyPaid(address receiverIpId, address payerIpId, address sender, address token, uint256 amount);
event LicenseMintingFeePaid(address receiverIpId, address payerAddress, address token, uint256 amount);

address internal ipAccount1 = address(0x111000aaa);
address internal ipAccount2 = address(0x111000bbb);
Expand Down Expand Up @@ -488,4 +489,34 @@ contract TestRoyaltyModule is BaseTest {
assertEq(payerIpIdUSDCBalBefore - payerIpIdUSDCBalAfter, royaltyAmount);
assertEq(splitCloneUSDCBalAfter - splitCloneUSDCBalBefore, royaltyAmount);
}

function test_RoyaltyModule_payLicenseMintingFee() public {
uint256 royaltyAmount = 100 * 10 ** 6;
address receiverIpId = address(7);
address payerAddress = address(3);
address licenseRoyaltyPolicy = address(royaltyPolicyLAP);
address token = address(USDC);

(, address splitClone, , , ) = royaltyPolicyLAP.royaltyData(receiverIpId);

vm.startPrank(payerAddress);
USDC.mint(payerAddress, royaltyAmount);
USDC.approve(address(royaltyPolicyLAP), royaltyAmount);
vm.stopPrank;

uint256 payerAddressUSDCBalBefore = USDC.balanceOf(payerAddress);
uint256 splitCloneUSDCBalBefore = USDC.balanceOf(splitClone);

vm.expectEmit(true, true, true, true, address(royaltyModule));
emit LicenseMintingFeePaid(receiverIpId, payerAddress, address(USDC), royaltyAmount);

vm.startPrank(address(licensingModule));
royaltyModule.payLicenseMintingFee(receiverIpId, payerAddress, licenseRoyaltyPolicy, token, royaltyAmount);

uint256 payerAddressUSDCBalAfter = USDC.balanceOf(payerAddress);
uint256 splitCloneUSDCBalAfter = USDC.balanceOf(splitClone);

assertEq(payerAddressUSDCBalBefore - payerAddressUSDCBalAfter, royaltyAmount);
assertEq(splitCloneUSDCBalAfter - splitCloneUSDCBalBefore, royaltyAmount);
}
}

0 comments on commit 0650769

Please sign in to comment.