Skip to content

Commit

Permalink
refactor: rename "IPlugin" to "IPRBProxyPlugin"
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRBerg committed Feb 12, 2023
1 parent 45fc682 commit c928a6c
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 45 deletions.
12 changes: 6 additions & 6 deletions src/PRBProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity >=0.8.4;

import { IPRBProxy } from "./interfaces/IPRBProxy.sol";
import { IPlugin } from "./interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "./interfaces/IPRBProxyPlugin.sol";

/// @title PRBProxy
/// @author Paul Razvan Berg
Expand All @@ -23,7 +23,7 @@ contract PRBProxy is IPRBProxy {
//////////////////////////////////////////////////////////////////////////*/

/// @dev Maps plugin methods to plugin implementation.
mapping(bytes4 => IPlugin) internal plugins;
mapping(bytes4 => IPRBProxyPlugin) internal plugins;

/// @dev Maps envoys to target contracts to function selectors to boolean flags.
mapping(address => mapping(address => mapping(bytes4 => bool))) internal permissions;
Expand All @@ -46,7 +46,7 @@ contract PRBProxy is IPRBProxy {
// solhint-disable no-complex-fallback
fallback(bytes calldata data) external payable returns (bytes memory response) {
// Check if the function signature exists in the installed plugin methods mapping.
IPlugin plugin = plugins[msg.sig];
IPRBProxyPlugin plugin = plugins[msg.sig];
if (address(plugin) == address(0)) {
revert PRBProxy_NoPluginFound(msg.sender, msg.sig);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ contract PRBProxy is IPRBProxy {
}

/// @inheritdoc IPRBProxy
function getPluginForMethod(bytes4 method) external view override returns (IPlugin plugin) {
function getPluginForMethod(bytes4 method) external view override returns (IPRBProxyPlugin plugin) {
plugin = plugins[method];
}

Expand Down Expand Up @@ -144,7 +144,7 @@ contract PRBProxy is IPRBProxy {
}

/// @inheritdoc IPRBProxy
function installPlugin(IPlugin plugin) external override {
function installPlugin(IPRBProxyPlugin plugin) external override {
// Check that the caller is the owner.
if (owner != msg.sender) {
revert PRBProxy_NotOwner(owner, msg.sender);
Expand Down Expand Up @@ -190,7 +190,7 @@ contract PRBProxy is IPRBProxy {
}

/// @inheritdoc IPRBProxy
function uninstallPlugin(IPlugin plugin) external override {
function uninstallPlugin(IPRBProxyPlugin plugin) external override {
// Check that the caller is the owner.
if (owner != msg.sender) {
revert PRBProxy_NotOwner(owner, msg.sender);
Expand Down
16 changes: 8 additions & 8 deletions src/interfaces/IPRBProxy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import { IPlugin } from "./IPlugin.sol";
import { IPRBProxyPlugin } from "./IPRBProxyPlugin.sol";

/// @title IPRBProxy
/// @author Paul Razvan Berg
Expand All @@ -24,13 +24,13 @@ interface IPRBProxy {
error PRBProxy_NotOwner(address owner, address caller);

/// @notice Emitted when the plugin has no listed methods.
error PRBProxy_NoPluginMethods(IPlugin plugin);
error PRBProxy_NoPluginMethods(IPRBProxyPlugin plugin);

/// @notice Emitted when the owner is changed during the DELEGATECALL.
error PRBProxy_OwnerChanged(address originalOwner, address newOwner);

/// @notice Emitted when a plugin execution reverts with no reason.
error PRBProxy_PluginExecutionReverted(IPlugin plugin);
error PRBProxy_PluginExecutionReverted(IPRBProxyPlugin plugin);

/// @notice Emitted when passing an EOA or an undeployed contract as the target.
error PRBProxy_TargetNotContract(address target);
Expand All @@ -41,11 +41,11 @@ interface IPRBProxy {

event Execute(address indexed target, bytes data, bytes response);

event InstallPlugin(IPlugin indexed plugin);
event InstallPlugin(IPRBProxyPlugin indexed plugin);

event TransferOwnership(address indexed oldOwner, address indexed newOwner);

event UninstallPlugin(IPlugin indexed plugin);
event UninstallPlugin(IPRBProxyPlugin indexed plugin);

/*//////////////////////////////////////////////////////////////////////////
PUBLIC CONSTANT FUNCTIONS
Expand All @@ -58,7 +58,7 @@ interface IPRBProxy {
/// @notice Returns the address of the plugin installed for the the given method.
/// @dev Returns the zero address if no plugin is installed.
/// @param method The signature of the method to make the query for.
function getPluginForMethod(bytes4 method) external view returns (IPlugin plugin);
function getPluginForMethod(bytes4 method) external view returns (IPRBProxyPlugin plugin);

/// @notice The address of the owner account or contract.
function owner() external view returns (address);
Expand Down Expand Up @@ -97,7 +97,7 @@ interface IPRBProxy {
/// - Does not revert if the plugin is already installed.
///
/// @param plugin The address of the plugin to install.
function installPlugin(IPlugin plugin) external;
function installPlugin(IPRBProxyPlugin plugin) external;

/// @notice Gives or takes a permission from an envoy to call the given target contract and function selector
/// on behalf of the owner.
Expand Down Expand Up @@ -132,5 +132,5 @@ interface IPRBProxy {
/// - Does not revert if the plugin is not already installed.
///
/// @param plugin The address of the plugin to uninstall.
function uninstallPlugin(IPlugin plugin) external;
function uninstallPlugin(IPRBProxyPlugin plugin) external;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

/// @title IPlugin
/// @notice Interface for the plugins that can be installed on the proxy.
interface IPlugin {
/// @title IPRBProxyPlugin
/// @notice Interface for the plugins that can be installed on a proxy.
interface IPRBProxyPlugin {
/// @notice Lists the methods that the plugin implements.
/// @dev These methods are installed and uninstalled by the proxy.
///
/// Requirements:
/// - The proxy needs at least one method to be installed.
/// @return methods The methods that the plugin exports.
/// - The plugin needs at least one method to be listed.
///
/// @return methods The methods that the plugin implements.
function methodList() external returns (bytes4[] memory methods);
}
10 changes: 5 additions & 5 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { PRBTest } from "@prb/test/PRBTest.sol";
import { StdCheats } from "forge-std/StdCheats.sol";
import { StdUtils } from "forge-std/StdUtils.sol";

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxy } from "src/interfaces/IPRBProxy.sol";
import { IPRBProxyFactory } from "src/interfaces/IPRBProxyFactory.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";
import { IPRBProxyRegistry } from "src/interfaces/IPRBProxyRegistry.sol";
import { PRBProxy } from "src/PRBProxy.sol";
import { PRBProxyFactory } from "src/PRBProxyFactory.sol";
Expand Down Expand Up @@ -78,13 +78,13 @@ abstract contract Base_Test is PRBTest, StdCheats, StdUtils {
INTERNAL NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @dev Helper function to compare two `IPlugin` addresses.
function assertEq(IPlugin a, IPlugin b) internal {
/// @dev Helper function to compare two `IPRBProxyPlugin` addresses.
function assertEq(IPRBProxyPlugin a, IPRBProxyPlugin b) internal {
assertEq(address(a), address(b));
}

/// @dev Helper function to compare two `IPlugin` addresses.
function assertEq(IPlugin a, IPlugin b, string memory err) internal {
/// @dev Helper function to compare two `IPRBProxyPlugin` addresses.
function assertEq(IPRBProxyPlugin a, IPRBProxyPlugin b, string memory err) internal {
assertEq(address(a), address(b), err);
}

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/plugins/PluginDummy.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

contract PluginDummy is IPlugin {
contract PluginDummy is IPRBProxyPlugin {
function foo() external pure returns (string memory) {
return "foo";
}
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/plugins/PluginEmpty.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

contract PluginEmpty is IPlugin {
contract PluginEmpty is IPRBProxyPlugin {
function methodList() external pure override returns (bytes4[] memory) {
bytes4[] memory methods = new bytes4[](0);
return methods;
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/plugins/PluginRevert.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

contract PluginRevert is IPlugin {
contract PluginRevert is IPRBProxyPlugin {
error PluginError();

function methodList() external pure override returns (bytes4[] memory) {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/targets/TargetPluginRevert.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

contract PluginRevert is IPlugin {
contract PluginRevert is IPRBProxyPlugin {
error PluginError();

function methodList() external pure override returns (bytes4[] memory) {
Expand Down
6 changes: 3 additions & 3 deletions test/prb-proxy/PRBProxy.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";
import { PRBProxy } from "src/PRBProxy.sol";

import { Base_Test } from "../Base.t.sol";
Expand Down Expand Up @@ -43,11 +43,11 @@ contract PRBProxy_Test is Base_Test {

event Execute(address indexed target, bytes data, bytes response);

event InstallPlugin(IPlugin indexed plugin);
event InstallPlugin(IPRBProxyPlugin indexed plugin);

event TransferOwnership(address indexed oldOwner, address indexed newOwner);

event UninstallPlugin(IPlugin indexed plugin);
event UninstallPlugin(IPRBProxyPlugin indexed plugin);

/*//////////////////////////////////////////////////////////////////////////
TESTING VARIABLES
Expand Down
10 changes: 5 additions & 5 deletions test/prb-proxy/install-plugin/installPlugin.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxy } from "src/interfaces/IPRBProxy.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

import { PRBProxy_Test } from "../PRBProxy.t.sol";
import { PluginDummy } from "../../helpers/plugins/PluginDummy.t.sol";
Expand Down Expand Up @@ -45,8 +45,8 @@ contract InstallPlugin_Test is PRBProxy_Test {
// Assert that every plugin method has been installed.
bytes4[] memory pluginMethods = plugins.dummy.methodList();
for (uint256 i = 0; i < pluginMethods.length; ++i) {
IPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPlugin expectedPlugin = plugins.dummy;
IPRBProxyPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPRBProxyPlugin expectedPlugin = plugins.dummy;
assertEq(actualPlugin, expectedPlugin, "Plugin method not installed");
}
}
Expand All @@ -63,8 +63,8 @@ contract InstallPlugin_Test is PRBProxy_Test {
// Assert that every plugin method has been installed.
bytes4[] memory pluginMethods = plugins.dummy.methodList();
for (uint256 i = 0; i < pluginMethods.length; ++i) {
IPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPlugin expectedPlugin = plugins.dummy;
IPRBProxyPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPRBProxyPlugin expectedPlugin = plugins.dummy;
assertEq(actualPlugin, expectedPlugin, "PLugin method not installed");
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/prb-proxy/uninstall-plugin/uninstallPlugin.t.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.4;

import { IPlugin } from "src/interfaces/IPlugin.sol";
import { IPRBProxy } from "src/interfaces/IPRBProxy.sol";
import { IPRBProxyPlugin } from "src/interfaces/IPRBProxyPlugin.sol";

import { PRBProxy_Test } from "../PRBProxy.t.sol";
import { PluginDummy } from "../../helpers/plugins/PluginDummy.t.sol";
Expand Down Expand Up @@ -42,8 +42,8 @@ contract UninstallPlugin_Test is PRBProxy_Test {
// Assert that every plugin method has been uninstalled.
bytes4[] memory pluginMethods = plugins.dummy.methodList();
for (uint256 i = 0; i < pluginMethods.length; ++i) {
IPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPlugin expectedPlugin = IPlugin(address(0));
IPRBProxyPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPRBProxyPlugin expectedPlugin = IPRBProxyPlugin(address(0));
assertEq(actualPlugin, expectedPlugin, "Plugin method installed");
}
}
Expand All @@ -62,8 +62,8 @@ contract UninstallPlugin_Test is PRBProxy_Test {
// Assert that every plugin method has been uninstalled.
bytes4[] memory pluginMethods = plugins.dummy.methodList();
for (uint256 i = 0; i < pluginMethods.length; ++i) {
IPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPlugin expectedPlugin = IPlugin(address(0));
IPRBProxyPlugin actualPlugin = proxy.getPluginForMethod(pluginMethods[i]);
IPRBProxyPlugin expectedPlugin = IPRBProxyPlugin(address(0));
assertEq(actualPlugin, expectedPlugin, "Plugin method installed");
}
}
Expand Down

0 comments on commit c928a6c

Please sign in to comment.