-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting rewrite account common as ERC7579
- Loading branch information
Showing
21 changed files
with
813 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {Account} from "./Account.sol"; | ||
import {Address} from "../../utils/Address.sol"; | ||
import {ERC1155Holder} from "../../token/ERC1155/utils/ERC1155Holder.sol"; | ||
import {ERC721Holder} from "../../token/ERC721/utils/ERC721Holder.sol"; | ||
import {ERC7579Utils} from "../utils/ERC7579Utils.sol"; | ||
import {IEntryPoint} from "../../interfaces/IERC4337.sol"; | ||
import {IERC1271} from "../../interfaces/IERC1271.sol"; | ||
import {IERC165, ERC165} from "../../utils/introspection/ERC165.sol"; | ||
import {IERC7579Account, Execution} from "../../interfaces/IERC7579Account.sol"; | ||
|
||
abstract contract ERC7579Account is IERC7579Account, Account, ERC165, ERC721Holder, ERC1155Holder { | ||
using ERC7579Utils for *; | ||
|
||
IEntryPoint private immutable _entryPoint; | ||
|
||
error UnsupportedCallType(bytes1); | ||
|
||
modifier onlyExecutorModule() { | ||
// TODO | ||
_; | ||
} | ||
|
||
constructor(IEntryPoint entryPoint_) { | ||
_entryPoint = entryPoint_; | ||
} | ||
|
||
receive() external payable {} | ||
|
||
function entryPoint() public view virtual override returns (IEntryPoint) { | ||
return _entryPoint; | ||
} | ||
|
||
/// IERC165 | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override(IERC165, ERC165, ERC1155Holder) returns (bool) { | ||
// TODO: more? | ||
return super.supportsInterface(interfaceId); | ||
} | ||
|
||
/// IERC1271 | ||
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4 magicValue) { | ||
(bool valid, , uint48 validAfter, uint48 validUntil) = _processSignature(hash, signature); | ||
return | ||
(valid && validAfter < block.timestamp && (validUntil == 0 || validUntil > block.timestamp)) | ||
? IERC1271.isValidSignature.selector | ||
: bytes4(0); | ||
} | ||
|
||
/// IERC7579Execution | ||
function execute(bytes32 mode, bytes calldata executionCalldata) public virtual onlyEntryPoint { | ||
// TODO: support execType ? | ||
(bytes1 callType, , , ) = mode.parseMode(); | ||
|
||
if (callType == ERC7579Utils.CALLTYPE_SINGLE) { | ||
(address target, uint256 value, bytes calldata callData) = executionCalldata.parseSingle(); | ||
_execute(target, value, callData); | ||
} else if (callType == ERC7579Utils.CALLTYPE_BATCH) { | ||
Execution[] calldata executionBatch = executionCalldata.parseBatch(); | ||
for (uint256 i = 0; i < executionBatch.length; ++i) { | ||
_execute(executionBatch[i].target, executionBatch[i].value, executionBatch[i].callData); | ||
} | ||
} else { | ||
revert UnsupportedCallType(callType); | ||
} | ||
} | ||
|
||
function executeFromExecutor( | ||
bytes32 mode, | ||
bytes calldata executionCalldata | ||
) public virtual onlyExecutorModule returns (bytes[] memory returnData) { | ||
// TODO: support execType ? | ||
(bytes1 callType, , , ) = mode.parseMode(); | ||
|
||
if (callType == ERC7579Utils.CALLTYPE_SINGLE) { | ||
(address target, uint256 value, bytes calldata callData) = executionCalldata.parseSingle(); | ||
returnData = new bytes[](1); | ||
returnData[0] = _execute(target, value, callData); | ||
} else if (callType == ERC7579Utils.CALLTYPE_BATCH) { | ||
Execution[] calldata executionBatch = executionCalldata.parseBatch(); | ||
returnData = new bytes[](executionBatch.length); | ||
for (uint256 i = 0; i < executionBatch.length; ++i) { | ||
returnData[i] = _execute(executionBatch[i].target, executionBatch[i].value, executionBatch[i].callData); | ||
} | ||
} else { | ||
revert UnsupportedCallType(callType); | ||
} | ||
} | ||
|
||
function _execute(address target, uint256 value, bytes memory data) internal returns (bytes memory) { | ||
(bool success, bytes memory returndata) = target.call{value: value}(data); | ||
Address.verifyCallResult(success, returndata); | ||
return returndata; | ||
} | ||
|
||
/// IERC7579AccountConfig | ||
function accountId() external pure returns (/*view*/ string memory /*accountImplementationId*/) { | ||
revert("not-implemented-yet"); | ||
} | ||
|
||
function supportsExecutionMode(bytes32 /*encodedMode*/ /*view*/) external pure returns (bool) { | ||
revert("not-implemented-yet"); | ||
} | ||
|
||
function supportsModule(uint256 /*moduleTypeId*/ /*view*/) external pure returns (bool) { | ||
revert("not-implemented-yet"); | ||
} | ||
|
||
/// IERC7579ModuleConfig | ||
function installModule(uint256 /*moduleTypeId*/, address /*module*/, bytes calldata /*initData*/) external pure { | ||
revert("not-implemented-yet"); | ||
} | ||
|
||
function uninstallModule( | ||
uint256 /*moduleTypeId*/, | ||
address /*module*/, | ||
bytes calldata /*deInitData*/ | ||
) external pure { | ||
revert("not-implemented-yet"); | ||
} | ||
|
||
function isModuleInstalled( | ||
uint256 /*moduleTypeId*/, | ||
address /*module*/, | ||
bytes calldata /*additionalContext*/ /*view*/ | ||
) external pure returns (bool) { | ||
revert("not-implemented-yet"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.