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

Dispute effects on royalty #35

Merged
merged 9 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions contracts/interfaces/modules/royalty/IRoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ interface IRoyaltyModule is IModule {
/// @param amount The amount paid
event LicenseMintingFeePaid(address receiverIpId, address payerAddress, address token, uint256 amount);

/// @notice Sets the license registry
/// @dev Enforced to be only callable by the protocol admin
/// @param licensing The address of the license registry
/// @param dispute The address of the dispute module
function setLicensingAndDisputeModules(address licensing, address dispute) external;
jdubpark marked this conversation as resolved.
Show resolved Hide resolved

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

/// @notice Returns the dispute module address
function disputeModule() external view returns (address);

Comment on lines 43 to +48

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two can also be removed, as we don't expect the functions to be called by another contract.

/// @notice Indicates if a royalty policy is whitelisted
/// @param royaltyPolicy The address of the royalty policy
/// @return isWhitelisted True if the royalty policy is whitelisted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ interface IRoyaltyPolicyLAP is IRoyaltyPolicy {
uint32[] targetRoyaltyAmount
);

/// @notice The state data of the LAP royalty policy
/// @param isUnlinkableToParents Indicates if the ipId is unlinkable to new parents
/// @param ipRoyaltyVault The ip royalty vault address
/// @param royaltyStack The royalty stack of a given ipId is the sum of the royalties to be paid to each ancestors
/// @param ancestorsAddresses The ancestors addresses array
/// @param ancestorsRoyalties The ancestors royalties array
jdubpark marked this conversation as resolved.
Show resolved Hide resolved
struct LAPRoyaltyData {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any redundancy of those data with license data?

bool isUnlinkableToParents;
address ipRoyaltyVault;
uint32 royaltyStack;
address[] ancestorsAddresses;
uint32[] ancestorsRoyalties;
}

/// @notice Returns the percentage scale - represents 100% of royalty tokens for an ip
function TOTAL_RT_SUPPLY() external view returns (uint32);

Expand Down
4 changes: 4 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ library Errors {
error RoyaltyModule__ZeroLicensingModule();
error RoyaltyModule__CanOnlyMintSelectedPolicy();
error RoyaltyModule__NoParentsOnLinking();
error RoyaltyModule__ZeroDisputeModule();
error RoyaltyModule__IpIsTagged();
jdubpark marked this conversation as resolved.
Show resolved Hide resolved

error RoyaltyPolicyLAP__ZeroRoyaltyModule();
error RoyaltyPolicyLAP__ZeroLiquidSplitFactory();
Expand All @@ -246,6 +248,8 @@ library Errors {
error IpRoyaltyVault__SnapshotIntervalTooShort();
error IpRoyaltyVault__AlreadyClaimed();
error IpRoyaltyVault__ClaimerNotAnAncestor();
error IpRoyaltyVault__IpTagged();
jdubpark marked this conversation as resolved.
Show resolved Hide resolved
error IpRoyaltyVault__ZeroDisputeModule();

////////////////////////////////////////////////////////////////////////////
// ModuleRegistry //
Expand Down
16 changes: 8 additions & 8 deletions contracts/modules/dispute/DisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ contract DisputeModule is
IIPAssetRegistry public immutable IP_ASSET_REGISTRY;

/// Constructor
/// @param _controller The address of the access controller
/// @param _assetRegistry The address of the asset registry
/// @param controller The address of the access controller
/// @param assetRegistry The address of the asset registry
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address _controller, address _assetRegistry) AccessControlled(_controller, _assetRegistry) {
IP_ASSET_REGISTRY = IIPAssetRegistry(_assetRegistry);
constructor(address controller, address assetRegistry) AccessControlled(controller, assetRegistry) {
IP_ASSET_REGISTRY = IIPAssetRegistry(assetRegistry);
_disableInitializers();
}

Expand Down Expand Up @@ -169,9 +169,9 @@ contract DisputeModule is
address arbitrationPolicy = $.arbitrationPolicies[targetIpId];
if (!$.isWhitelistedArbitrationPolicy[arbitrationPolicy]) arbitrationPolicy = $.baseArbitrationPolicy;

uint256 disputeId_ = ++$.disputeCounter;
uint256 disputeId = ++$.disputeCounter;

$.disputes[disputeId_] = Dispute({
$.disputes[disputeId] = Dispute({
targetIpId: targetIpId,
disputeInitiator: msg.sender,
arbitrationPolicy: arbitrationPolicy,
Expand All @@ -183,7 +183,7 @@ contract DisputeModule is
IArbitrationPolicy(arbitrationPolicy).onRaiseDispute(msg.sender, data);

emit DisputeRaised(
disputeId_,
disputeId,
targetIpId,
msg.sender,
arbitrationPolicy,
Expand All @@ -192,7 +192,7 @@ contract DisputeModule is
data
);

return disputeId_;
return disputeId;
}

/// @notice Sets the dispute judgement on a given dispute. Only whitelisted arbitration relayers can call to judge.
Expand Down
20 changes: 18 additions & 2 deletions contracts/modules/royalty/RoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BaseModule } from "../BaseModule.sol";
import { GovernableUpgradeable } from "../../governance/GovernableUpgradeable.sol";
import { IRoyaltyModule } from "../../interfaces/modules/royalty/IRoyaltyModule.sol";
import { IRoyaltyPolicy } from "../../interfaces/modules/royalty/policies/IRoyaltyPolicy.sol";
import { IDisputeModule } from "../../interfaces/modules/dispute/IDisputeModule.sol";
import { Errors } from "../../lib/Errors.sol";
import { ROYALTY_MODULE_KEY } from "../../lib/modules/Module.sol";
import { BaseModule } from "../BaseModule.sol";
Expand All @@ -27,12 +28,14 @@ contract RoyaltyModule is
using ERC165Checker for address;

/// @dev Storage structure for the RoyaltyModule
/// @param disputeModule The address of the dispute module
/// @param licensingModule The address of the licensing module
/// @param isWhitelistedRoyaltyPolicy Indicates if a royalty policy is whitelisted
/// @param isWhitelistedRoyaltyToken Indicates if a royalty token is whitelisted
/// @param royaltyPolicies Indicates the royalty policy for a given IP asset
/// @custom:storage-location erc7201:story-protocol.RoyaltyModule
struct RoyaltyModuleStorage {
address disputeModule;
address licensingModule;
mapping(address royaltyPolicy => bool isWhitelisted) isWhitelistedRoyaltyPolicy;
mapping(address token => bool) isWhitelistedRoyaltyToken;
Expand Down Expand Up @@ -69,9 +72,13 @@ contract RoyaltyModule is
/// @notice Sets the license registry
/// @dev Enforced to be only callable by the protocol admin
/// @param licensing The address of the license registry
function setLicensingModule(address licensing) external onlyProtocolAdmin {
/// @param dispute The address of the dispute module
function setLicensingAndDisputeModules(address licensing, address dispute) external onlyProtocolAdmin {
if (licensing == address(0)) revert Errors.RoyaltyModule__ZeroLicensingModule();
if (dispute == address(0)) revert Errors.RoyaltyModule__ZeroDisputeModule();

_getRoyaltyModuleStorage().licensingModule = licensing;
_getRoyaltyModuleStorage().disputeModule = dispute;
}

/// @notice Whitelist a royalty policy
Expand Down Expand Up @@ -175,6 +182,10 @@ contract RoyaltyModule is
RoyaltyModuleStorage storage $ = _getRoyaltyModuleStorage();
if (!$.isWhitelistedRoyaltyToken[token]) revert Errors.RoyaltyModule__NotWhitelistedRoyaltyToken();

IDisputeModule dispute = IDisputeModule($.disputeModule);
if (dispute.isIpTagged(receiverIpId)) revert Errors.RoyaltyModule__IpIsTagged();
if (dispute.isIpTagged(payerIpId)) revert Errors.RoyaltyModule__IpIsTagged();
jdubpark marked this conversation as resolved.
Show resolved Hide resolved

address payerRoyaltyPolicy = $.royaltyPolicies[payerIpId];
// if the payer does not have a royalty policy set, then the payer is not a derivative ip and does not pay
// royalties while the receiver ip can have a zero royalty policy since that could mean it is an ip a root
Expand Down Expand Up @@ -202,7 +213,7 @@ contract RoyaltyModule is
) external onlyLicensingModule {
RoyaltyModuleStorage storage $ = _getRoyaltyModuleStorage();
if (!$.isWhitelistedRoyaltyToken[token]) revert Errors.RoyaltyModule__NotWhitelistedRoyaltyToken();

if (IDisputeModule($.disputeModule).isIpTagged(receiverIpId)) revert Errors.RoyaltyModule__IpIsTagged();
if (licenseRoyaltyPolicy == address(0)) revert Errors.RoyaltyModule__NoRoyaltyPolicySet();
if (!$.isWhitelistedRoyaltyPolicy[licenseRoyaltyPolicy])
revert Errors.RoyaltyModule__NotWhitelistedRoyaltyPolicy();
Expand All @@ -217,6 +228,11 @@ contract RoyaltyModule is
return _getRoyaltyModuleStorage().licensingModule;
}

/// @notice Returns the dispute module address
function disputeModule() external view returns (address) {
return _getRoyaltyModuleStorage().disputeModule;
}

/// @notice Indicates if a royalty policy is whitelisted
/// @param royaltyPolicy The address of the royalty policy
/// @return isWhitelisted True if the royalty policy is whitelisted
Expand Down
15 changes: 14 additions & 1 deletion contracts/modules/royalty/policies/IpRoyaltyVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SafeERC20Upgradeable } from "@openzeppelin/contracts-upgradeable-v4/tok
import { IERC20Upgradeable } from "@openzeppelin/contracts-upgradeable-v4/token/ERC20/IERC20Upgradeable.sol";

import { IRoyaltyPolicyLAP } from "../../../interfaces/modules/royalty/policies/IRoyaltyPolicyLAP.sol";
import { IDisputeModule } from "../../../interfaces/modules/dispute/IDisputeModule.sol";
import { IIpRoyaltyVault } from "../../../interfaces/modules/royalty/policies/IIpRoyaltyVault.sol";
import { ArrayUtils } from "../../../lib/ArrayUtils.sol";
import { Errors } from "../../../lib/Errors.sol";
Expand All @@ -25,6 +26,9 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20SnapshotUpgradeable, Reentrancy
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IRoyaltyPolicyLAP public immutable ROYALTY_POLICY_LAP;

/// @notice Dispute module address
IDisputeModule public immutable DISPUTE_MODULE;

/// @notice Ip id to whom this royalty vault belongs to
address public ipId;

Expand Down Expand Up @@ -58,10 +62,15 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20SnapshotUpgradeable, Reentrancy

/// @notice Constructor
/// @param royaltyPolicyLAP The address of the royalty policy LAP
/// @param disputeModule The address of the dispute module
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address royaltyPolicyLAP) {
constructor(address royaltyPolicyLAP, address disputeModule) {
if (royaltyPolicyLAP == address(0)) revert Errors.IpRoyaltyVault__ZeroRoyaltyPolicyLAP();
if (disputeModule == address(0)) revert Errors.IpRoyaltyVault__ZeroDisputeModule();

ROYALTY_POLICY_LAP = IRoyaltyPolicyLAP(royaltyPolicyLAP);
DISPUTE_MODULE = IDisputeModule(disputeModule);

_disableInitializers();
}

Expand Down Expand Up @@ -186,6 +195,7 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20SnapshotUpgradeable, Reentrancy
ipId
);

if (DISPUTE_MODULE.isIpTagged(ipId)) revert Errors.IpRoyaltyVault__IpTagged();
if (isClaimedByAncestor[ancestorIpId]) revert Errors.IpRoyaltyVault__AlreadyClaimed();

// check if the address being claimed to is an ancestor
Expand Down Expand Up @@ -216,6 +226,9 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20SnapshotUpgradeable, Reentrancy
/// @param token The revenue token to claim
/// @return The amount of revenue token claimable
function _claimableRevenue(address account, uint256 snapshotId, address token) internal view returns (uint256) {
// if the ip is tagged, then the unclaimed royalties are lost
if (DISPUTE_MODULE.isIpTagged(ipId)) return 0;
jdubpark marked this conversation as resolved.
Show resolved Hide resolved

uint256 balance = balanceOfAt(account, snapshotId);
uint256 totalSupply = totalSupplyAt(snapshotId) - unclaimedAtSnapshot[snapshotId];
uint256 claimableToken = claimableAtSnapshot[snapshotId][token];
Expand Down
18 changes: 2 additions & 16 deletions contracts/modules/royalty/policies/RoyaltyPolicyLAP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ import { Errors } from "../../../lib/Errors.sol";
contract RoyaltyPolicyLAP is IRoyaltyPolicyLAP, GovernableUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;

/// @notice The state data of the LAP royalty policy
/// @param isUnlinkableToParents Indicates if the ipId is unlinkable to new parents
/// @param ipRoyaltyVault The ip royalty vault address
/// @param royaltyStack The royalty stack of a given ipId is the sum of the royalties to be paid to each ancestors
/// @param ancestorsAddresses The ancestors addresses array
/// @param ancestorsRoyalties The ancestors royalties array
struct LAPRoyaltyData {
bool isUnlinkableToParents;
address ipRoyaltyVault;
uint32 royaltyStack;
address[] ancestorsAddresses;
uint32[] ancestorsRoyalties;
}

/// @dev Storage structure for the RoyaltyPolicyLAP
/// @param ipRoyaltyVaultBeacon The ip royalty vault beacon address
/// @param snapshotInterval The minimum timestamp interval between snapshots
Expand Down Expand Up @@ -118,7 +104,7 @@ contract RoyaltyPolicyLAP is IRoyaltyPolicyLAP, GovernableUpgradeable, Reentranc
address ipId,
bytes calldata licenseData,
bytes calldata externalData
) external onlyRoyaltyModule {
) external onlyRoyaltyModule nonReentrant {
uint32 newLicenseRoyalty = abi.decode(licenseData, (uint32));
RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage();

Expand Down Expand Up @@ -153,7 +139,7 @@ contract RoyaltyPolicyLAP is IRoyaltyPolicyLAP, GovernableUpgradeable, Reentranc
address[] calldata parentIpIds,
bytes[] memory licenseData,
bytes calldata externalData
) external onlyRoyaltyModule {
) external onlyRoyaltyModule nonReentrant {
RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage();
if ($.royaltyData[ipId].isUnlinkableToParents) revert Errors.RoyaltyPolicyLAP__UnlinkableToParents();

Expand Down
2 changes: 1 addition & 1 deletion script/foundry/deployment/Main.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ contract Main is Script, BroadcastManager, JsonDeploymentHandler, StorageLayoutC
}

function _configureRoyaltyRelated() private {
royaltyModule.setLicensingModule(address(licensingModule));
royaltyModule.setLicensingAndDisputeModules(address(licensingModule), address(disputeModule));
// whitelist
royaltyModule.whitelistRoyaltyPolicy(address(royaltyPolicyLAP), true);
royaltyModule.whitelistRoyaltyToken(address(erc20), true);
Expand Down
9 changes: 8 additions & 1 deletion test/foundry/mocks/module/MockRoyaltyModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ contract MockRoyaltyModule is BaseModule, IRoyaltyModule {

address public LICENSING_MODULE;

address public DISPUTE_MODULE;

mapping(address royaltyPolicy => bool allowed) public isWhitelistedRoyaltyPolicy;

mapping(address token => bool) public isWhitelistedRoyaltyToken;
Expand All @@ -19,14 +21,19 @@ contract MockRoyaltyModule is BaseModule, IRoyaltyModule {

constructor() {}

function setLicensingModule(address _licensingModule) external {
function setLicensingAndDisputeModules(address _licensingModule, address _disputeModule) external {
LICENSING_MODULE = _licensingModule;
DISPUTE_MODULE = _disputeModule;
}

function licensingModule() external view override returns (address) {
return LICENSING_MODULE;
}

function disputeModule() external view override returns (address) {
return DISPUTE_MODULE;
}

function whitelistRoyaltyPolicy(address _royaltyPolicy, bool _allowed) external {
isWhitelistedRoyaltyPolicy[_royaltyPolicy] = _allowed;
}
Expand Down
Loading
Loading