Skip to content

Commit

Permalink
feat: remove custom proxy admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Jan 2, 2025
1 parent 6f72233 commit 045c5db
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 201 deletions.
45 changes: 0 additions & 45 deletions src/contracts/transparent-proxy/ProxyAdmin.sol

This file was deleted.

24 changes: 14 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 @@ -15,10 +15,14 @@ import {ProxyAdmin} from './ProxyAdmin.sol';
**/
abstract contract TransparentProxyFactoryBase is ITransparentProxyFactory {
/// @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));

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

Expand All @@ -33,13 +37,13 @@ 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));

emit ProxyDeterministicCreated(proxy, logic, address(admin), salt);
emit ProxyDeterministicCreated(proxy, logic, address(adminOwner), salt);
return proxy;
}

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

Expand Down
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';

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
2 changes: 1 addition & 1 deletion test/PermissionlessRescuable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract PermissionlessRescuableTest is Test {
rescuable = new PermissionlessRescuable(fundsReceiver, address(restrictedMockToken));
}

function test_whoShouldReceiveFunds() public {
function test_whoShouldReceiveFunds() public view {
assertEq(rescuable.whoShouldReceiveFunds(), fundsReceiver);
}

Expand Down
12 changes: 6 additions & 6 deletions test/TransparentProxyFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {Ownable} from 'openzeppelin-contracts/contracts/access/Ownable.sol';
import {ProxyAdmin} from '../src/contracts/transparent-proxy/ProxyAdmin.sol';
import {TransparentUpgradeableProxy} from 'openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import {ProxyAdmin} from 'openzeppelin-contracts/contracts/proxy/transparent/ProxyAdmin.sol';
import {TransparentProxyFactory} from '../src/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {TransparentUpgradeableProxy} from '../src/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {MockImpl} from '../src/mocks/MockImpl.sol';

contract TestTransparentProxyFactory is Test {
Expand All @@ -26,12 +26,12 @@ contract TestTransparentProxyFactory is Test {

address predictedAddress1 = factory.predictCreateDeterministic(
address(mockImpl),
ProxyAdmin(admin),
admin,
data,
salt
);

address proxy1 = factory.createDeterministic(address(mockImpl), ProxyAdmin(admin), data, salt);
address proxy1 = factory.createDeterministic(address(mockImpl), admin, data, salt);

assertEq(predictedAddress1, proxy1);
assertEq(MockImpl(proxy1).getFoo(), FOO);
Expand All @@ -53,14 +53,14 @@ contract TestTransparentProxyFactory is Test {

address predictedAddress1 = factory.predictCreateDeterministic(
address(mockImpl),
ProxyAdmin(deterministicProxyAdmin),
deterministicProxyAdmin,
data,
proxySalt
);

address proxy1 = factory.createDeterministic(
address(mockImpl),
ProxyAdmin(deterministicProxyAdmin),
deterministicProxyAdmin,
data,
proxySalt
);
Expand Down
2 changes: 1 addition & 1 deletion test/UpgradeableOwnableWithGuardian.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract TestOfUpgradableOwnableWithGuardian is Test {
ImplOwnableWithGuardian(address(withGuardian)).initialize(owner, guardian);
}

function test_initializer() external {
function test_initializer() external view {
assertEq(withGuardian.owner(), owner);
assertEq(withGuardian.guardian(), guardian);
}
Expand Down
Loading

0 comments on commit 045c5db

Please sign in to comment.