forked from storyprotocol/protocol-core
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade beacon through RoyaltyPolicyLAP (#88)
* upgrade beacon via RoyaltyPolicyLAP * lint
- Loading branch information
Showing
5 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { IpRoyaltyVault } from "contracts/modules/royalty/policies/IpRoyaltyVault.sol"; | ||
|
||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.23; | ||
|
||
contract MockIpRoyaltyVaultV2 is IpRoyaltyVault { | ||
/// @dev Storage structure for the MockIPRoyaltyVaultV2 | ||
/// @custom:storage-location erc7201:story-protocol.MockIPRoyaltyVaultV2 | ||
struct MockIPRoyaltyVaultV2Storage { | ||
string newState; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("story-protocol.MockIPRoyaltyVaultV2")) - 1)) & ~bytes32(uint256(0xff)); | ||
bytes32 private constant MockIPRoyaltyVaultV2StorageLocation = | ||
0x2942176f94974e015a9b06f79a3a2280d18f1872591c134ba237fa184e378300; | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor(address royaltyPolicyLAP, address disputeModule) IpRoyaltyVault(royaltyPolicyLAP, disputeModule) { | ||
_disableInitializers(); | ||
} | ||
|
||
function set(string calldata value) external { | ||
_getMockIPRoyaltyVaultV2Storage().newState = value; | ||
} | ||
|
||
function get() external view returns (string memory) { | ||
return _getMockIPRoyaltyVaultV2Storage().newState; | ||
} | ||
|
||
/// @dev Returns the storage struct of MockIPRoyaltyVaultV2. | ||
function _getMockIPRoyaltyVaultV2Storage() private pure returns (MockIPRoyaltyVaultV2Storage storage $) { | ||
assembly { | ||
$.slot := MockIPRoyaltyVaultV2StorageLocation | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.23; | ||
|
||
import { ProtocolAdmin } from "contracts/lib/ProtocolAdmin.sol"; | ||
import { RoyaltyPolicyLAP } from "contracts/modules/royalty/policies/RoyaltyPolicyLAP.sol"; | ||
|
||
import { BaseTest } from "../utils/BaseTest.t.sol"; | ||
|
||
import { MockIpRoyaltyVaultV2 } from "../mocks/module/MockIpRoyaltyVaultV2.sol"; | ||
|
||
contract IPRoyaltyVaults is BaseTest { | ||
function setUp() public override { | ||
super.setUp(); | ||
vm.prank(u.admin); | ||
protocolAccessManager.grantRole(ProtocolAdmin.UPGRADER_ROLE, u.alice, upgraderExecDelay); | ||
} | ||
|
||
function test_upgradeVaults() public { | ||
address newVault = address(new MockIpRoyaltyVaultV2(address(royaltyPolicyLAP), address(disputeModule))); | ||
(bool immediate, uint32 delay) = protocolAccessManager.canCall( | ||
u.alice, | ||
address(royaltyPolicyLAP), | ||
RoyaltyPolicyLAP.upgradeVaults.selector | ||
); | ||
assertFalse(immediate); | ||
assertEq(delay, 600); | ||
vm.prank(u.alice); | ||
(bytes32 operationId, uint32 nonce) = protocolAccessManager.schedule( | ||
address(royaltyPolicyLAP), | ||
abi.encodeCall(RoyaltyPolicyLAP.upgradeVaults, (newVault)), | ||
0 // earliest time possible, upgraderExecDelay | ||
); | ||
vm.warp(upgraderExecDelay + 1); | ||
|
||
vm.prank(u.alice); | ||
royaltyPolicyLAP.upgradeVaults(newVault); | ||
|
||
assertEq(ipRoyaltyVaultBeacon.implementation(), newVault); | ||
} | ||
} |