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

(groups): upgradeableRenounceableProxy for group policies #78

Merged
merged 16 commits into from
Nov 18, 2024
Merged
Changes from 4 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
63 changes: 63 additions & 0 deletions src/groups/UpgradeableRenounceableProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.24;

import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

benjaminbollen marked this conversation as resolved.
Show resolved Hide resolved
interface IUpgradeableRenounceableProxy {
function implementation() external view returns (address);
function upgradeToAndCall(address _newImplementation, bytes memory _data) external;
function renounceUpgradeability() external;
}

contract UpgradeableRenounceableProxy is ERC1967Proxy {
// Errors

error BlockReceive();

// Constants

/// @dev Initial proxy admin.
address internal immutable ADMIN_INIT;

// Constructor

constructor(address _implementation, bytes memory _data) ERC1967Proxy(_implementation, _data) {
// set the admin to the deployer
ERC1967Utils.changeAdmin(msg.sender);
// set the admin as immutable
ADMIN_INIT = msg.sender;
}

function implementation() external view returns (address) {
return _implementation();
}

/// @dev Dispatch if caller is admin.
function _fallback() internal virtual override {
if (msg.sender == ADMIN_INIT && msg.sender == ERC1967Utils.getAdmin()) {
_dispatchAdmin();
} else {
super._fallback();
}
}
benjaminbollen marked this conversation as resolved.
Show resolved Hide resolved

/// @dev Upgrades to new implementation, renounces the ability to upgrade or moves to regular flow based on admin request.
function _dispatchAdmin() private {
if (msg.sig == IUpgradeableRenounceableProxy.upgradeToAndCall.selector) {
// upgrades to new implementation
(address newImplementation, bytes memory data) = abi.decode(msg.data[4:], (address, bytes));
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} else if (msg.sig == IUpgradeableRenounceableProxy.renounceUpgradeability.selector) {
// renounces the ability to upgrade the contract, by setting the admin to 0x01.
ERC1967Utils.changeAdmin(address(0x01));
} else {
_delegate(_implementation());
}
}

// Fallback function

receive() external payable {
revert BlockReceive();
}
}
Loading