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

feat(royalty): Add dispute royalty distribution handling #388

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
58 changes: 58 additions & 0 deletions contracts/modules/royalty/RoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -726,4 +726,62 @@ contract RoyaltyModule is IRoyaltyModule, VaultController, ReentrancyGuardUpgrad
/// @dev Hook to authorize the upgrade according to UUPSUpgradeable
/// @param newImplementation The address of the new implementation
function _authorizeUpgrade(address newImplementation) internal override restricted {}

/// @notice Handles royalty distribution when a dispute is resolved for unattributed derivative
/// @param originalIpId The ID of the original IP that was copied
/// @param derivativeIpId The ID of the derivative work that was disputed
/// @param royaltyAmount The amount of royalties to distribute
/// @param token The token in which royalties are paid
function handleDisputeRoyaltyDistribution(
address originalIpId,
address derivativeIpId,
uint256 royaltyAmount,
address token
) external nonReentrant {
RoyaltyModuleStorage storage $ = _getRoyaltyModuleStorage();

// Verify caller is dispute module
if (msg.sender != address(DISPUTE_MODULE)) revert Errors.RoyaltyModule__NotAllowedCaller();

// Check if token is whitelisted
if (!$.isWhitelistedRoyaltyToken[token]) revert Errors.RoyaltyModule__NotWhitelistedRoyaltyToken();

// Get or deploy vault for original IP
address originalVault = $.ipRoyaltyVaults[originalIpId];
if (originalVault == address(0)) {
address receiver = originalIpId;
if (IP_ASSET_REGISTRY.isRegisteredGroup(originalIpId)) {
receiver = IP_ASSET_REGISTRY.getGroupRewardPool(originalIpId);
if (!IP_ASSET_REGISTRY.isWhitelistedGroupRewardPool(receiver)) {
revert Errors.RoyaltyModule__GroupRewardPoolNotWhitelisted(originalIpId, receiver);
}
}
originalVault = _deployIpRoyaltyVault(originalIpId, receiver);
}

// In case of dispute, original IP owner gets 100% of royalties
IERC20(token).safeTransfer(originalVault, royaltyAmount);

emit DisputeRoyaltyDistributed(
originalIpId,
derivativeIpId,
royaltyAmount,
token,
originalVault
);
}

/// @notice Emitted when dispute royalties are distributed
/// @param originalIpId The ID of the original IP
/// @param derivativeIpId The ID of the derivative work
/// @param amount The amount of royalties distributed
/// @param token The token in which royalties were paid
/// @param recipientVault The vault that received the royalties
event DisputeRoyaltyDistributed(
address indexed originalIpId,
address indexed derivativeIpId,
uint256 amount,
address token,
address recipientVault
);
}