Skip to content

Commit

Permalink
remove plugin base
Browse files Browse the repository at this point in the history
  • Loading branch information
1kresh committed May 24, 2024
1 parent 2be6c07 commit f8a7a4f
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 148 deletions.
27 changes: 0 additions & 27 deletions src/contracts/base/Plugin.sol

This file was deleted.

20 changes: 15 additions & 5 deletions src/contracts/plugins/MetadataPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Plugin} from "src/contracts/base/Plugin.sol";

import {IMetadataPlugin} from "src/interfaces/plugins/IMetadataPlugin.sol";
import {IRegistry} from "src/interfaces/base/IRegistry.sol";

import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

contract MetadataPlugin is Plugin, IMetadataPlugin {
contract MetadataPlugin is IMetadataPlugin {
using Strings for string;

/**
* @inheritdoc IMetadataPlugin
*/
address public immutable REGISTRY;

/**
* @inheritdoc IMetadataPlugin
*/
mapping(address entity => string value) public metadataURL;

constructor(address registry) Plugin(registry) {}
constructor(address registry) {
REGISTRY = registry;
}

/**
* @inheritdoc IMetadataPlugin
*/
function setMetadataURL(string calldata metadataURL_) external onlyEntity {
function setMetadataURL(string calldata metadataURL_) external {
if (!IRegistry(REGISTRY).isEntity(msg.sender)) {
revert NotEntity();
}

if (metadataURL[msg.sender].equal(metadataURL_)) {
revert AlreadySet();
}
Expand Down
20 changes: 15 additions & 5 deletions src/contracts/plugins/MiddlewarePlugin.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Plugin} from "src/contracts/base/Plugin.sol";

import {IMiddlewarePlugin} from "src/interfaces/plugins/IMiddlewarePlugin.sol";
import {IRegistry} from "src/interfaces/base/IRegistry.sol";

contract MiddlewarePlugin is IMiddlewarePlugin {
/**
* @inheritdoc IMiddlewarePlugin
*/
address public immutable REGISTRY;

contract MiddlewarePlugin is Plugin, IMiddlewarePlugin {
/**
* @inheritdoc IMiddlewarePlugin
*/
mapping(address entity => address value) public middleware;

constructor(address registry) Plugin(registry) {}
constructor(address registry) {
REGISTRY = registry;
}

/**
* @inheritdoc IMiddlewarePlugin
*/
function setMiddleware(address middleware_) external onlyEntity {
function setMiddleware(address middleware_) external {
if (!IRegistry(REGISTRY).isEntity(msg.sender)) {
revert NotEntity();
}

if (middleware[msg.sender] == middleware_) {
revert AlreadySet();
}
Expand Down
18 changes: 13 additions & 5 deletions src/contracts/plugins/NetworkOptInPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Plugin} from "src/contracts/base/Plugin.sol";

import {INetworkOptInPlugin} from "src/interfaces/plugins/INetworkOptInPlugin.sol";
import {IRegistry} from "src/interfaces/base/IRegistry.sol";

import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";

contract NetworkOptInPlugin is Plugin, INetworkOptInPlugin {
contract NetworkOptInPlugin is INetworkOptInPlugin {
/**
* @inheritdoc INetworkOptInPlugin
*/
address public immutable NETWORK_REGISTRY;

/**
* @inheritdoc INetworkOptInPlugin
*/
Expand All @@ -25,7 +28,8 @@ contract NetworkOptInPlugin is Plugin, INetworkOptInPlugin {
mapping(address network => mapping(address resolver => mapping(address where => uint48 timestamp))) public
lastOptOut;

constructor(address networkRegistry, address whereRegistry) Plugin(networkRegistry) {
constructor(address networkRegistry, address whereRegistry) {
NETWORK_REGISTRY = networkRegistry;
WHERE_REGISTRY = whereRegistry;
}

Expand All @@ -44,7 +48,11 @@ contract NetworkOptInPlugin is Plugin, INetworkOptInPlugin {
/**
* @inheritdoc INetworkOptInPlugin
*/
function optIn(address resolver, address where) external onlyEntity {
function optIn(address resolver, address where) external {
if (!IRegistry(NETWORK_REGISTRY).isEntity(msg.sender)) {
revert NotNetwork();
}

if (!IRegistry(WHERE_REGISTRY).isEntity(where)) {
revert NotWhereEntity();
}
Expand Down
18 changes: 13 additions & 5 deletions src/contracts/plugins/OperatorOptInPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {Plugin} from "src/contracts/base/Plugin.sol";

import {IOperatorOptInPlugin} from "src/interfaces/plugins/IOperatorOptInPlugin.sol";
import {IRegistry} from "src/interfaces/base/IRegistry.sol";

import {Time} from "@openzeppelin/contracts/utils/types/Time.sol";

contract OperatorOptInPlugin is Plugin, IOperatorOptInPlugin {
contract OperatorOptInPlugin is IOperatorOptInPlugin {
/**
* @inheritdoc IOperatorOptInPlugin
*/
address public immutable OPERATOR_REGISTRY;

/**
* @inheritdoc IOperatorOptInPlugin
*/
Expand All @@ -24,7 +27,8 @@ contract OperatorOptInPlugin is Plugin, IOperatorOptInPlugin {
*/
mapping(address operator => mapping(address where => uint48 timestamp)) public lastOptOut;

constructor(address operatorRegistry, address whereRegistry) Plugin(operatorRegistry) {
constructor(address operatorRegistry, address whereRegistry) {
OPERATOR_REGISTRY = operatorRegistry;
WHERE_REGISTRY = whereRegistry;
}

Expand All @@ -38,7 +42,11 @@ contract OperatorOptInPlugin is Plugin, IOperatorOptInPlugin {
/**
* @inheritdoc IOperatorOptInPlugin
*/
function optIn(address where) external onlyEntity {
function optIn(address where) external {
if (!IRegistry(OPERATOR_REGISTRY).isEntity(msg.sender)) {
revert NotOperator();
}

if (!IRegistry(WHERE_REGISTRY).isEntity(where)) {
revert NotWhereEntity();
}
Expand Down
12 changes: 0 additions & 12 deletions src/interfaces/base/IPlugin.sol

This file was deleted.

11 changes: 8 additions & 3 deletions src/interfaces/plugins/IMetadataPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

interface IMetadataPlugin is IPlugin {
interface IMetadataPlugin {
error AlreadySet();
error NotEntity();

/**
* @notice Emitted when a metadata URL is set for an entity.
Expand All @@ -13,6 +12,12 @@ interface IMetadataPlugin is IPlugin {
*/
event SetMetadataURL(address indexed entity, string metadataURL);

/**
* @notice Get the registry address.
* @return address of the registry
*/
function REGISTRY() external view returns (address);

/**
* @notice Get a URL with an entity's metadata.
* The metadata should contain a name, description, external_url, and image.
Expand Down
11 changes: 8 additions & 3 deletions src/interfaces/plugins/IMiddlewarePlugin.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

interface IMiddlewarePlugin is IPlugin {
interface IMiddlewarePlugin {
error AlreadySet();
error NotEntity();

/**
* @notice Emitted when a middleware is set for an entity.
Expand All @@ -13,6 +12,12 @@ interface IMiddlewarePlugin is IPlugin {
*/
event SetMiddleware(address indexed entity, address middleware);

/**
* @notice Get the registry address.
* @return address of the registry
*/
function REGISTRY() external view returns (address);

/**
* @notice Get an entity's middleware.
* @param entity address of the entity
Expand Down
11 changes: 8 additions & 3 deletions src/interfaces/plugins/INetworkOptInPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

interface INetworkOptInPlugin is IPlugin {
interface INetworkOptInPlugin {
error AlreadyOptedIn();
error NotOptedIn();
error NotWhereEntity();
error NotNetwork();

/**
* @notice Emitted when a network opts-in to a "where" entity.
Expand All @@ -24,6 +23,12 @@ interface INetworkOptInPlugin is IPlugin {
*/
event OptOut(address indexed network, address indexed resolver, address indexed where);

/**
* @notice Get the network registry's address.
* @return address of the network registry
*/
function NETWORK_REGISTRY() external view returns (address);

/**
* @notice Get the address of the registry where to opt-in.
* @return address of the "where" registry
Expand Down
11 changes: 8 additions & 3 deletions src/interfaces/plugins/IOperatorOptInPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

interface IOperatorOptInPlugin is IPlugin {
interface IOperatorOptInPlugin {
error AlreadyOptedIn();
error NotOptedIn();
error NotWhereEntity();
error NotOperator();

/**
* @notice Emitted when an operator opts-in to a "where" entity.
Expand All @@ -22,6 +21,12 @@ interface IOperatorOptInPlugin is IPlugin {
*/
event OptOut(address indexed operator, address indexed where);

/**
* @notice Get the operator registry's address.
* @return address of the operator registry
*/
function OPERATOR_REGISTRY() external view returns (address);

/**
* @notice Get the address of the registry where to opt-in.
* @return address of the "where" registry
Expand Down
55 changes: 0 additions & 55 deletions test/base/Plugin.t.sol

This file was deleted.

14 changes: 0 additions & 14 deletions test/mocks/SimplePlugin.sol

This file was deleted.

Loading

0 comments on commit f8a7a4f

Please sign in to comment.