Skip to content

Commit

Permalink
Merge pull request #20 from rabbitholegg/art/chore/add_support_interf…
Browse files Browse the repository at this point in the history
…aces

feat(evm): add helpers to determine the component interface
  • Loading branch information
Quazia authored Jul 3, 2024
2 parents 3e101ab + 1ee31d3 commit f75e6a6
Show file tree
Hide file tree
Showing 23 changed files with 420 additions and 335 deletions.
8 changes: 5 additions & 3 deletions packages/evm/contracts/actions/Action.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ abstract contract Action is Cloneable {
/// @dev The `data` field should contain the return data from the action, if any.
event ActionExecuted(address indexed executor, address caller, bool success, bytes data);

/// @notice Thrown when the `execute` function is not implemented
error ExecuteNotImplemented();

/// @notice Emitted when the action is validated
/// @dev The `data` field should contain implementation-specific context, if applicable.
event ActionValidated(address indexed user, bool isValidated, bytes data);
Expand All @@ -36,4 +33,9 @@ abstract contract Action is Cloneable {
function supportsInterface(bytes4 interfaceId) public view virtual override(Cloneable) returns (bool) {
return interfaceId == type(Action).interfaceId || super.supportsInterface(interfaceId);
}

function getComponentInterface() public pure virtual returns (bytes4) {
return type(Action).interfaceId;
}

}
8 changes: 6 additions & 2 deletions packages/evm/contracts/actions/ERC721MintAction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.24;

import {ERC721} from "@solady/tokens/ERC721.sol";

import {BoostError} from "contracts/shared/BoostError.sol";
import {Action} from "contracts/actions/Action.sol";
import {Cloneable} from "contracts/shared/Cloneable.sol";
import {ContractAction} from "contracts/actions/ContractAction.sol";
Expand Down Expand Up @@ -37,7 +37,7 @@ contract ERC721MintAction is ContractAction, Validator {
/// @return returnData The return data from the call
function execute(bytes calldata data_) external payable override returns (bool success, bytes memory returnData) {
(data_, success, returnData);
revert ExecuteNotImplemented();
revert BoostError.NotImplemented();
}

/// @notice Prepare the action for execution and return the expected payload
Expand Down Expand Up @@ -71,6 +71,10 @@ contract ERC721MintAction is ContractAction, Validator {
return super.supportsInterface(interfaceId);
}

function getComponentInterface() public pure override(Action, Validator) returns (bytes4) {
return type(Validator).interfaceId;
}

function _initialize(InitPayload memory init_) internal override onlyInitializing {
super._initialize(init_);
_initializeOwner(msg.sender);
Expand Down
21 changes: 20 additions & 1 deletion packages/evm/contracts/allowlists/AllowList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract contract AllowList is Ownable, Cloneable {
constructor() {
_initializeOwner(msg.sender);
}

/// @notice Check if a user is authorized
/// @param user_ The address of the user
/// @param data_ The data payload for the authorization check, if applicable
Expand All @@ -24,4 +24,23 @@ abstract contract AllowList is Ownable, Cloneable {
function supportsInterface(bytes4 interfaceId) public view virtual override(Cloneable) returns (bool) {
return interfaceId == type(AllowList).interfaceId || super.supportsInterface(interfaceId);
}

/// @notice Set the allowed status of a user
/// @param users_ The list of users to update
/// @param allowed_ The allowed status of each user
/// @dev The length of the `users_` and `allowed_` arrays must be the same
/// @dev This function can only be called by the owner
function setAllowed(address[] calldata users_, bool[] calldata allowed_) external virtual;


/// @notice Set the denied status of a user
/// @param users_ The list of users to update
/// @param denied_ The denied status of each user
/// @dev The length of the `users_` and `denied_` arrays must be the same
/// @dev This function can only be called by the owner
function setDenied(address[] calldata users_, bool[] calldata denied_) external virtual;

function getComponentInterface() public pure virtual returns (bytes4) {
return type(AllowList).interfaceId;
}
}
14 changes: 8 additions & 6 deletions packages/evm/contracts/allowlists/SimpleAllowList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ contract SimpleAllowList is AllowList, OwnableRoles {
return _allowed[user_];
}

/// @notice Set the allowed status of a user
/// @param users_ The list of users to update
/// @param allowed_ The allowed status of each user
/// @dev The length of the `users_` and `allowed_` arrays must be the same
/// @dev This function can only be called by the owner
function setAllowed(address[] calldata users_, bool[] calldata allowed_) external onlyRoles(LIST_MANAGER_ROLE) {
/// @inheritdoc AllowList
function setAllowed(address[] calldata users_, bool[] calldata allowed_) external override onlyRoles(LIST_MANAGER_ROLE) {
if (users_.length != allowed_.length) revert BoostError.LengthMismatch();

for (uint256 i = 0; i < users_.length; i++) {
_allowed[users_[i]] = allowed_[i];
}
}

/// @inheritdoc AllowList
/// @notice This function is not implemented in this contract
function setDenied(address[] calldata users_, bool[] calldata denied_) external override onlyOwner {
revert BoostError.NotImplemented();
}
}
7 changes: 6 additions & 1 deletion packages/evm/contracts/allowlists/SimpleDenyList.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ contract SimpleDenyList is AllowList {
return !_denied[user_];
}

/// @inheritdoc AllowList
function setAllowed(address[] calldata users_, bool[] calldata allowed_) external override onlyOwner {
revert BoostError.NotImplemented();
}

/// @notice Set the denied status of a user
/// @param users_ The list of users to update
/// @param denied_ The denied status of each user
/// @dev The length of the `users_` and `denied_` arrays must be the same
/// @dev This function can only be called by the owner
function setDenied(address[] calldata users_, bool[] calldata denied_) external onlyOwner {
function setDenied(address[] calldata users_, bool[] calldata denied_) external override onlyOwner {
if (users_.length != denied_.length) revert BoostError.LengthMismatch();

for (uint256 i = 0; i < users_.length; i++) {
Expand Down
Loading

0 comments on commit f75e6a6

Please sign in to comment.