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

Commit

Permalink
refactor: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jdubpark committed Feb 17, 2024
1 parent b8e4760 commit bf73fb4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
10 changes: 5 additions & 5 deletions contracts/AccessController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ contract AccessController is IAccessController, Governable {
address public IP_ACCOUNT_REGISTRY;
address public MODULE_REGISTRY;

/// @dev Tracks the permission granted to an encoded callpath, where the
/// encoded callpath = keccak256(abi.encodePacked(ipAccount, signer, to, func))
/// @dev Tracks the permission granted to an encoded permission path, where the
/// encoded permission path = keccak256(abi.encodePacked(ipAccount, signer, to, func))
mapping(bytes32 => uint8) internal encodedPermissions;

constructor(address governance) Governable(governance) {}
Expand Down Expand Up @@ -84,8 +84,8 @@ contract AccessController is IAccessController, Governable {
if (permission > 2) {
revert Errors.AccessController__PermissionIsNotValid();
}
_setPermission(address(0), signer_, to_, func_, permission_);
emit PermissionSet(address(0), signer_, to_, func_, permission_);
_setPermission(address(0), signer, to, func, permission);
emit PermissionSet(address(0), address(0), signer, to, func, permission);
}

/// @notice Sets the permission for a specific function call
Expand Down Expand Up @@ -128,7 +128,7 @@ contract AccessController is IAccessController, Governable {
}
_setPermission(ipAccount, signer, to, func, permission);

emit PermissionSet(ipAccount_, signer_, to_, func_, permission_);
emit PermissionSet(IIPAccount(payable(ipAccount)).owner(), ipAccount, signer, to, func, permission);
}

/// @notice Checks the permission level for a specific function call. Reverts if permission is not granted.
Expand Down
35 changes: 17 additions & 18 deletions contracts/IPAccountImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { Errors } from "./lib/Errors.sol";
/// @title IPAccountImpl
/// @notice The Story Protocol's implementation of the IPAccount.
contract IPAccountImpl is IERC165, IIPAccount {
/// @notice Returns the address of the protocol-wide access controller.
address public ACCESS_CONTROLLER;
address public immutable accessController;

/// @notice Returns the IPAccount's internal nonce for transaction ordering.
uint256 public state;
Expand All @@ -30,19 +29,21 @@ contract IPAccountImpl is IERC165, IIPAccount {
/// in the implementation code's storage.
/// This means that each cloned IPAccount will inherently use the same AccessController
/// without the need for individual configuration.
/// @param accessController The address of the AccessController contract to be used for permission checks
constructor(address accessController) {
if (accessController == address(0)) revert Errors.IPAccount__InvalidAccessController();
ACCESS_CONTROLLER = accessController;
/// @param accessController_ The address of the AccessController contract to be used for permission checks
constructor(address accessController_) {
if (accessController_ == address(0)) revert Errors.IPAccount__InvalidAccessController();
accessController = accessController_;
}

/// @notice IERC165 interface support.
function supportsInterface(bytes4 interfaceId_) external pure returns (bool) {
return (interfaceId_ == type(IIPAccount).interfaceId ||
interfaceId_ == type(IERC6551Account).interfaceId ||
interfaceId_ == type(IERC1155Receiver).interfaceId ||
interfaceId_ == type(IERC721Receiver).interfaceId ||
interfaceId_ == type(IERC165).interfaceId);
/// @notice Checks if the contract supports a specific interface
/// @param interfaceId The interface identifier, as specified in ERC-165
/// @return bool is true if the contract supports the interface, false otherwise
function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
return (interfaceId == type(IIPAccount).interfaceId ||
interfaceId == type(IERC6551Account).interfaceId ||
interfaceId == type(IERC1155Receiver).interfaceId ||
interfaceId == type(IERC721Receiver).interfaceId ||
interfaceId == type(IERC165).interfaceId);
}

/// @notice Returns the identifier of the non-fungible token which owns the account
Expand Down Expand Up @@ -80,7 +81,7 @@ contract IPAccountImpl is IERC165, IIPAccount {
}

/// @notice Returns the owner of the IP Account.
/// @return owner The address of the owner.
/// @return The address of the owner.
function owner() public view returns (address) {
(uint256 chainId, address contractAddress, uint256 tokenId) = token();
if (chainId != block.chainid) return address(0);
Expand All @@ -91,18 +92,17 @@ contract IPAccountImpl is IERC165, IIPAccount {
/// @param signer The signer to check
/// @param to The recipient of the transaction
/// @param data The calldata to check against
/// @return isValid True if the signer is valid, false otherwise
/// @return bool is true if the signer is valid, false otherwise
function _isValidSigner(address signer, address to, bytes calldata data) internal view returns (bool) {
if (data.length > 0 && data.length < 4) {
revert Errors.IPAccount__InvalidCalldata();
}
require(data.length == 0 || data.length >= 4, "Invalid calldata");
bytes4 selector = bytes4(0);
if (data.length >= 4) {
selector = bytes4(data[:4]);
}
// the check will revert if permission is denied
IAccessController(ACCESS_CONTROLLER).checkPermission(address(this), signer, to, selector);
IAccessController(accessController).checkPermission(address(this), signer, to, selector);
return true;
}

Expand All @@ -113,7 +113,6 @@ contract IPAccountImpl is IERC165, IIPAccount {
/// @param signer The signer of the transaction.
/// @param deadline The deadline of the transaction signature.
/// @param signature The signature of the transaction, EIP-712 encoded.
/// @return result The return data from the transaction.
function executeWithSig(
address to,
uint256 value,
Expand Down
3 changes: 0 additions & 3 deletions contracts/interfaces/IIPAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ interface IIPAccount is IERC6551Account, IERC721Receiver, IERC1155Receiver {
bytes signature
);

/// @notice Returns the address of the protocol-wide access controller.
function ACCESS_CONTROLLER() external view returns (address);

/// @notice Returns the IPAccount's internal nonce for transaction ordering.
function state() external view returns (uint256);

Expand Down
3 changes: 0 additions & 3 deletions contracts/interfaces/registries/IIPAccountRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ interface IIPAccountRegistry {
/// @notice Returns the public ERC6551 registry address
function ERC6551_PUBLIC_REGISTRY() external view returns (address);

/// @notice Returns the access controller address
function ACCESS_CONTROLLER() external view returns (address);

/// @notice Deploys an IPAccount contract with the IPAccount implementation and returns the address of the new IP
/// @dev The IPAccount deployment deltegates to public ERC6551 Registry
/// @param chainId The chain ID where the IP Account will be created
Expand Down

0 comments on commit bf73fb4

Please sign in to comment.