Skip to content

Commit 221b7bb

Browse files
Revert Royalty Transfer to Self's Vault (#414)
1 parent db8159b commit 221b7bb

File tree

5 files changed

+74
-0
lines changed

5 files changed

+74
-0
lines changed

contracts/lib/Errors.sol

+6
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ library Errors {
814814
/// @notice Call failed.
815815
error RoyaltyPolicyLAP__CallFailed();
816816

817+
/// @notice Cannot transfer to the Same IP.
818+
error RoyaltyPolicyLAP__SameIpTransfer();
819+
817820
////////////////////////////////////////////////////////////////////////////
818821
// Royalty Policy LRP //
819822
////////////////////////////////////////////////////////////////////////////
@@ -842,6 +845,9 @@ library Errors {
842845
/// @notice Call failed.
843846
error RoyaltyPolicyLRP__CallFailed();
844847

848+
/// @notice Cannot transfer to the Same IP.
849+
error RoyaltyPolicyLRP__SameIpTransfer();
850+
845851
////////////////////////////////////////////////////////////////////////////
846852
// IP Royalty Vault //
847853
////////////////////////////////////////////////////////////////////////////

contracts/modules/royalty/policies/LAP/RoyaltyPolicyLAP.sol

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ contract RoyaltyPolicyLAP is
130130
address token
131131
) external whenNotPaused returns (uint256) {
132132
RoyaltyPolicyLAPStorage storage $ = _getRoyaltyPolicyLAPStorage();
133+
if (ipId == ancestorIpId) revert Errors.RoyaltyPolicyLAP__SameIpTransfer();
133134

134135
uint32 ancestorPercent = $.ancestorPercentLAP[ipId][ancestorIpId];
135136
if (ancestorPercent == 0) {

contracts/modules/royalty/policies/LRP/RoyaltyPolicyLRP.sol

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ contract RoyaltyPolicyLRP is
157157
address token
158158
) external whenNotPaused returns (uint256) {
159159
RoyaltyPolicyLRPStorage storage $ = _getRoyaltyPolicyLRPStorage();
160+
if (ipId == ancestorIpId) revert Errors.RoyaltyPolicyLRP__SameIpTransfer();
160161

161162
uint32 ancestorPercent = $.ancestorPercentLRP[ipId][ancestorIpId];
162163
if (ancestorPercent == 0) {

test/foundry/modules/royalty/LAP/RoyaltyPolicyLAP.t.sol

+33
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,39 @@ contract TestRoyaltyPolicyLAP is BaseTest {
212212
royaltyPolicyLAP.transferToVault(ipAccount1, address(2000), address(USDC));
213213
}
214214

215+
function test_RoyaltyPolicyLAP_transferToVault_revert_SameIpTransfer() public {
216+
address[] memory parents = new address[](3);
217+
address[] memory licenseRoyaltyPolicies = new address[](3);
218+
uint32[] memory parentRoyalties = new uint32[](3);
219+
parents[0] = address(10);
220+
parents[1] = address(20);
221+
parents[2] = address(30);
222+
licenseRoyaltyPolicies[0] = address(royaltyPolicyLAP);
223+
licenseRoyaltyPolicies[1] = address(royaltyPolicyLAP);
224+
licenseRoyaltyPolicies[2] = address(royaltyPolicyLAP);
225+
parentRoyalties[0] = uint32(10 * 10 ** 6);
226+
parentRoyalties[1] = uint32(15 * 10 ** 6);
227+
parentRoyalties[2] = uint32(20 * 10 ** 6);
228+
ipGraph.addParentIp(ipAccount1, parents);
229+
230+
vm.startPrank(address(licensingModule));
231+
royaltyModule.onLinkToParents(ipAccount1, parents, licenseRoyaltyPolicies, parentRoyalties, "", 100e6);
232+
233+
// make payment to ip 80
234+
uint256 royaltyAmount = 100 * 10 ** 6;
235+
address receiverIpId = ipAccount1;
236+
address payerIpId = address(3);
237+
vm.startPrank(payerIpId);
238+
USDC.mint(payerIpId, royaltyAmount);
239+
USDC.approve(address(royaltyModule), royaltyAmount);
240+
royaltyModule.payRoyaltyOnBehalf(receiverIpId, payerIpId, address(USDC), royaltyAmount);
241+
vm.stopPrank();
242+
243+
// first transfer to vault
244+
vm.expectRevert(Errors.RoyaltyPolicyLAP__SameIpTransfer.selector);
245+
royaltyPolicyLAP.transferToVault(ipAccount1, ipAccount1, address(USDC));
246+
}
247+
215248
function test_RoyaltyPolicyLAP_transferToVault() public {
216249
address[] memory parents = new address[](3);
217250
address[] memory licenseRoyaltyPolicies = new address[](3);

test/foundry/modules/royalty/LRP/RoyaltyPolicyLRP.t.sol

+33
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,39 @@ contract TestRoyaltyPolicyLRP is BaseTest {
222222
royaltyPolicyLRP.transferToVault(ipAccount1, address(2000), address(USDC));
223223
}
224224

225+
function test_RoyaltyPolicyLRP_transferToVault_revert_SameIpTransfer() public {
226+
address[] memory parents = new address[](3);
227+
address[] memory licenseRoyaltyPolicies = new address[](3);
228+
uint32[] memory parentRoyalties = new uint32[](3);
229+
parents[0] = address(10);
230+
parents[1] = address(20);
231+
parents[2] = address(30);
232+
licenseRoyaltyPolicies[0] = address(royaltyPolicyLRP);
233+
licenseRoyaltyPolicies[1] = address(royaltyPolicyLRP);
234+
licenseRoyaltyPolicies[2] = address(royaltyPolicyLRP);
235+
parentRoyalties[0] = uint32(10 * 10 ** 6);
236+
parentRoyalties[1] = uint32(15 * 10 ** 6);
237+
parentRoyalties[2] = uint32(20 * 10 ** 6);
238+
ipGraph.addParentIp(ipAccount1, parents);
239+
240+
vm.startPrank(address(licensingModule));
241+
royaltyModule.onLinkToParents(ipAccount1, parents, licenseRoyaltyPolicies, parentRoyalties, "", 100e6);
242+
243+
// make payment to ip 80
244+
uint256 royaltyAmount = 100 * 10 ** 6;
245+
address receiverIpId = ipAccount1;
246+
address payerIpId = address(3);
247+
vm.startPrank(payerIpId);
248+
USDC.mint(payerIpId, royaltyAmount);
249+
USDC.approve(address(royaltyModule), royaltyAmount);
250+
royaltyModule.payRoyaltyOnBehalf(receiverIpId, payerIpId, address(USDC), royaltyAmount);
251+
vm.stopPrank();
252+
253+
// first transfer to vault
254+
vm.expectRevert(Errors.RoyaltyPolicyLRP__SameIpTransfer.selector);
255+
royaltyPolicyLRP.transferToVault(ipAccount1, ipAccount1, address(USDC));
256+
}
257+
225258
function test_RoyaltyPolicyLRP_transferToVault() public {
226259
address[] memory parents = new address[](3);
227260
address[] memory licenseRoyaltyPolicies = new address[](3);

0 commit comments

Comments
 (0)