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

feat: remove custom proxy admin #54

Merged
merged 8 commits into from
Jan 24, 2025
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
branch = release-v5.0
branch = release-v5.1
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable
45 changes: 0 additions & 45 deletions src/contracts/transparent-proxy/ProxyAdmin.sol

This file was deleted.

59 changes: 49 additions & 10 deletions src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import {TransparentUpgradeableProxy} from 'openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {ProxyAdmin} from 'openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol';
import {ITransparentProxyFactory} from './interfaces/ITransparentProxyFactory.sol';
import {TransparentUpgradeableProxy} from './TransparentUpgradeableProxy.sol';
import {ProxyAdmin} from './ProxyAdmin.sol';

/**
* @title TransparentProxyFactory
Expand All @@ -14,11 +14,23 @@ import {ProxyAdmin} from './ProxyAdmin.sol';
* @dev Highly recommended to pass as `admin` on creation an OZ ProxyAdmin instance
**/
abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
mapping(address proxy => address admin) internal _proxyToAdmin;

function getProxyAdmin(address proxy) external view returns (address) {
return _proxyToAdmin[proxy];
}

/// @inheritdoc ITransparentProxyFactory
function create(address logic, ProxyAdmin admin, bytes calldata data) external returns (address) {
address proxy = address(new TransparentUpgradeableProxy(logic, admin, data));
function create(
address logic,
address adminOwner,
bytes calldata data
) external returns (address) {
address proxy = address(new TransparentUpgradeableProxy(logic, adminOwner, data));
_storeProxyInRegistry(proxy);

emit ProxyCreated(proxy, logic, address(adminOwner));
sakulstra marked this conversation as resolved.
Show resolved Hide resolved

emit ProxyCreated(proxy, logic, address(admin));
return proxy;
}

Expand All @@ -33,13 +45,14 @@ abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
/// @inheritdoc ITransparentProxyFactory
function createDeterministic(
address logic,
ProxyAdmin admin,
address adminOwner,
bytes calldata data,
bytes32 salt
) external returns (address) {
address proxy = address(new TransparentUpgradeableProxy{salt: salt}(logic, admin, data));
address proxy = address(new TransparentUpgradeableProxy{salt: salt}(logic, adminOwner, data));
_storeProxyInRegistry(proxy);

emit ProxyDeterministicCreated(proxy, logic, address(admin), salt);
emit ProxyDeterministicCreated(proxy, logic, address(adminOwner), salt);
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
return proxy;
}

Expand All @@ -57,7 +70,7 @@ abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
/// @inheritdoc ITransparentProxyFactory
function predictCreateDeterministic(
address logic,
ProxyAdmin admin,
address admin,
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
bytes calldata data,
bytes32 salt
) public view returns (address) {
Expand All @@ -66,7 +79,7 @@ abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
address(this),
salt,
type(TransparentUpgradeableProxy).creationCode,
abi.encode(logic, address(admin), data)
abi.encode(logic, admin, data)
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand All @@ -90,4 +103,30 @@ abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
bytes memory creationCode,
bytes memory constructorArgs
) internal pure virtual returns (address);

function _storeProxyInRegistry(address proxy) internal {
_proxyToAdmin[proxy] = _predictCreate1Address(proxy);
}

/**
* @dev the prediction only depends on the address of the proxy.
* The admin is always the first and only contract deployed by the proxy.
*/
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
function _predictCreate1Address(address proxy) internal virtual returns (address) {
return
address(
uint160(
uint256(
keccak256(
abi.encodePacked(
bytes1(0xd6), // RLP prefix for a list with total length 22
bytes1(0x94), // RLP prefix for an address (20 bytes)
proxy, // 20-byte address
uint8(1) // 1-byte nonce
)
)
)
)
);
}
}
125 changes: 0 additions & 125 deletions src/contracts/transparent-proxy/TransparentUpgradeableProxy.sol

This file was deleted.

15 changes: 15 additions & 0 deletions src/contracts/transparent-proxy/interfaces/IProxyAdminOzV4.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

/**
* The package relies on OZ-v5, some legacy contracts rely on the oz v4 versions of `TransparentUpgradeableProxy` and `ProxyAdmin`.
* While we no longer recommend deploying new instances of these, we expose the interface to allow interacting with existing contracts.
*/

interface IProxyAdminOzV4 {
function changeProxyAdmin(address proxy, address newAdmin) external;

function upgrade(address proxy, address implementation) external;

function upgradeAndCall(address proxy, address implementation, bytes memory data) external;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import {ProxyAdmin} from '../ProxyAdmin.sol';
import {ProxyAdmin} from 'openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol';
Copy link

Choose a reason for hiding this comment

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

I think it is possible to delete this import

sakulstra marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
import {ProxyAdmin} from 'openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol';


interface ITransparentProxyFactory {
event ProxyCreated(address proxy, address indexed logic, address indexed proxyAdmin);
Expand All @@ -28,7 +28,7 @@ interface ITransparentProxyFactory {
* for an `initialize` function being `function initialize(uint256 foo) external initializer;`
* @return address The address of the proxy deployed
**/
function create(address logic, ProxyAdmin admin, bytes memory data) external returns (address);
function create(address logic, address admin, bytes memory data) external returns (address);

/**
* @notice Creates a proxyAdmin instance, and transfers ownership to provided owner
Expand All @@ -51,7 +51,7 @@ interface ITransparentProxyFactory {
**/
function createDeterministic(
address logic,
ProxyAdmin admin,
address admin,
bytes memory data,
bytes32 salt
) external returns (address);
Expand Down Expand Up @@ -80,7 +80,7 @@ interface ITransparentProxyFactory {
**/
function predictCreateDeterministic(
address logic,
ProxyAdmin admin,
address admin,
bytes calldata data,
bytes32 salt
) external view returns (address);
Expand Down
Loading
Loading