Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Add Batch Set Permissions Support to AccessController #70

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion contracts/AccessController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ contract AccessController is IAccessController, Governable {
MODULE_REGISTRY = moduleRegistry;
}

/// @inheritdoc IAccessController
function setBatchPermissions(AccessPermission.Permission[] memory permissions) external whenNotPaused {
for (uint256 i = 0; i < permissions.length; ) {
setPermission(
permissions[i].ipAccount,
permissions[i].signer,
permissions[i].to,
permissions[i].func,
permissions[i].permission
);
unchecked {
i += 1;
}
}
}

/// @notice Sets the permission for all IPAccounts
function setGlobalPermission(
address signer_,
Expand Down Expand Up @@ -80,7 +96,7 @@ contract AccessController is IAccessController, Governable {
address to_,
bytes4 func_,
uint8 permission_
) external whenNotPaused {
) public whenNotPaused {
// IPAccount and signer does not support wildcard permission
if (ipAccount_ == address(0)) {
revert Errors.AccessController__IPAccountIsZeroAddress();
Expand Down
10 changes: 8 additions & 2 deletions contracts/interfaces/IAccessController.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf
pragma solidity ^0.8.23;
import { AccessPermission } from "contracts/lib/AccessPermission.sol";

interface IAccessController {
event PermissionSet(
Expand All @@ -13,15 +14,20 @@ interface IAccessController {

/// @notice Sets the permission for a specific function call
/// @dev Each policy is represented as a mapping from an IP account address to a signer address to a recipient
///// address to a function selector to a permission level.
///// The permission level can be 0 (ABSTAIN), 1 (ALLOW), or 2 (DENY).
/// address to a function selector to a permission level.
/// The permission level can be 0 (ABSTAIN), 1 (ALLOW), or 2 (DENY).
/// @param ipAccount_ The account that owns the IP
/// @param signer_ The account that signs the transaction
/// @param to_ The recipient(modules) of the transaction
/// @param func_ The function selector
/// @param permission_ The permission level
function setPermission(address ipAccount_, address signer_, address to_, bytes4 func_, uint8 permission_) external;

/// @notice Sets a batch of permissions in a single transaction
/// @dev This function allows setting multiple permissions at once.
/// @param permissions An array of `Permission` structs, each representing the permission to be set.
function setBatchPermissions(AccessPermission.Permission[] memory permissions) external;

/// @notice Sets the permission for all IPAccounts
/// @dev Only the protocol admin can set the global permission
/// @param signer_ The account that signs the transaction
Expand Down
14 changes: 14 additions & 0 deletions contracts/lib/AccessPermission.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,18 @@ library AccessPermission {

// DENY means the permission is denied to transaction signer to call the function.
uint8 public constant DENY = 2;

/// @notice This struct is used to represent permissions in batch operations within the AccessController.
/// @param ipAccount The IPAccount address for which the permission is being set.
/// @param signer The address of the signer of the transaction.
/// @param to The address of the recipient of the transaction.
/// @param func The function selector for the transaction.
/// @param permission The permission level for the transaction (0 = ABSTAIN, 1 = ALLOW, 2 = DENY).
struct Permission {
address ipAccount;
address signer;
address to;
bytes4 func;
uint8 permission;
}
}
Loading
Loading