Skip to content

Commit

Permalink
Fix on license minting restriction (storyprotocol#314)
Browse files Browse the repository at this point in the history
* on-mint restriction fix

* lint fix
  • Loading branch information
Spablob authored Nov 25, 2024
1 parent 2ce76ce commit 6f538db
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions contracts/lib/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ library Errors {
/// @notice Zero address provided for Royalty Module.
error RoyaltyPolicyLRP__ZeroRoyaltyModule();

/// @notice Zero address provided for Royalty Policy LAP.
error RoyaltyPolicyLRP__ZeroRoyaltyPolicyLAP();

/// @notice Zero address provided for Access Manager in initializer.
error RoyaltyPolicyLRP__ZeroAccessManager();

Expand Down
12 changes: 9 additions & 3 deletions contracts/modules/royalty/policies/LRP/RoyaltyPolicyLRP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ contract RoyaltyPolicyLRP is
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IRoyaltyModule public immutable ROYALTY_MODULE;

/// @notice Returns the RoyaltyPolicyLAP address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IGraphAwareRoyaltyPolicy public immutable ROYALTY_POLICY_LAP;

/// @notice IPGraphACL address
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
IPGraphACL public immutable IP_GRAPH_ACL;
Expand All @@ -78,13 +82,16 @@ contract RoyaltyPolicyLRP is

/// @notice Constructor
/// @param royaltyModule The RoyaltyModule address
/// @param royaltyPolicyLAP The RoyaltyPolicyLAP address
/// @param ipGraphAcl The IPGraphACL address
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address royaltyModule, address ipGraphAcl) {
constructor(address royaltyModule, address royaltyPolicyLAP, address ipGraphAcl) {
if (royaltyModule == address(0)) revert Errors.RoyaltyPolicyLRP__ZeroRoyaltyModule();
if (royaltyPolicyLAP == address(0)) revert Errors.RoyaltyPolicyLRP__ZeroRoyaltyPolicyLAP();
if (ipGraphAcl == address(0)) revert Errors.RoyaltyPolicyLRP__ZeroIPGraphACL();

ROYALTY_MODULE = IRoyaltyModule(royaltyModule);
ROYALTY_POLICY_LAP = IGraphAwareRoyaltyPolicy(royaltyPolicyLAP);
IP_GRAPH_ACL = IPGraphACL(ipGraphAcl);

_disableInitializers();
Expand All @@ -108,8 +115,7 @@ contract RoyaltyPolicyLRP is
uint32 licensePercent,
bytes calldata
) external onlyRoyaltyModule nonReentrant {
IRoyaltyModule royaltyModule = ROYALTY_MODULE;
if (royaltyModule.globalRoyaltyStack(ipId) + licensePercent > royaltyModule.maxPercent())
if (ROYALTY_POLICY_LAP.getPolicyRoyaltyStack(ipId) + licensePercent > ROYALTY_MODULE.maxPercent())
revert Errors.RoyaltyPolicyLRP__AboveMaxPercent();
}

Expand Down
1 change: 1 addition & 0 deletions script/foundry/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
_predeploy("RoyaltyPolicyLRP");
impl = address(new RoyaltyPolicyLRP(
address(royaltyModule),
address(royaltyPolicyLAP),
newDeployedIpGraphACL ? _getDeployedAddress(type(IPGraphACL).name) : address(ipGraphACL)
));
royaltyPolicyLRP = RoyaltyPolicyLRP(
Expand Down
19 changes: 15 additions & 4 deletions test/foundry/modules/royalty/LRP/RoyaltyPolicyLRP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,32 @@ contract TestRoyaltyPolicyLRP is BaseTest {

function test_RoyaltyPolicyLRP_constructor_revert_ZeroRoyaltyModule() public {
vm.expectRevert(Errors.RoyaltyPolicyLRP__ZeroRoyaltyModule.selector);
new RoyaltyPolicyLRP(address(0), address(ipGraphACL));
new RoyaltyPolicyLRP(address(0), address(royaltyPolicyLAP), address(ipGraphACL));
}

function test_RoyaltyPolicyLRP_constructor_revert_ZeroRoyaltyPolicyLAP() public {
vm.expectRevert(Errors.RoyaltyPolicyLRP__ZeroRoyaltyPolicyLAP.selector);
new RoyaltyPolicyLRP(address(royaltyModule), address(0), address(ipGraphACL));
}

function test_RoyaltyPolicyLRP_constructor_revert_ZeroIPGraphACL() public {
vm.expectRevert(Errors.RoyaltyPolicyLRP__ZeroIPGraphACL.selector);
new RoyaltyPolicyLRP(address(royaltyModule), address(0));
new RoyaltyPolicyLRP(address(royaltyModule), address(royaltyPolicyLAP), address(0));
}

function test_RoyaltyPolicyLRP_constructor() public {
testRoyaltyPolicyLRP = new RoyaltyPolicyLRP(address(royaltyModule), address(ipGraphACL));
testRoyaltyPolicyLRP = new RoyaltyPolicyLRP(
address(royaltyModule),
address(royaltyPolicyLAP),
address(ipGraphACL)
);
assertEq(address(testRoyaltyPolicyLRP.ROYALTY_MODULE()), address(royaltyModule));
}

function test_RoyaltyPolicyLRP_initialize_revert_ZeroAccessManager() public {
address impl = address(new RoyaltyPolicyLRP(address(royaltyModule), address(ipGraphACL)));
address impl = address(
new RoyaltyPolicyLRP(address(royaltyModule), address(royaltyPolicyLAP), address(ipGraphACL))
);
vm.expectRevert(Errors.RoyaltyPolicyLRP__ZeroAccessManager.selector);
RoyaltyPolicyLRP(
TestProxyHelper.deployUUPSProxy(impl, abi.encodeCall(RoyaltyPolicyLRP.initialize, (address(0))))
Expand Down

0 comments on commit 6f538db

Please sign in to comment.