-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
35 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {ERC7579Utils, Mode, CallType, ExecType, ModeSelector} from "@openzeppelin/contracts/account/utils/draft-ERC7579Utils.sol"; | ||
import {IERC7821} from "../../interfaces/IERC7821.sol"; | ||
import {AccountCore} from "../AccountCore.sol"; | ||
|
||
/** | ||
* @dev Minimal batch executor following ERC7821. Only supports basic mode (no optional "opData"). | ||
*/ | ||
abstract contract AccountERC7821 is AccountCore, IERC7821 { | ||
using ERC7579Utils for *; | ||
|
||
ModeSelector internal constant MODE_BASIC = ModeSelector.wrap(0x00000000); | ||
ModeSelector internal constant MODE_OPDATA = ModeSelector.wrap(0x78210001); // Not supported yet | ||
|
||
error UnsupportedExecutionMode(); | ||
|
||
/// @inheritdoc IERC7821 | ||
function execute(bytes32 mode, bytes calldata executionData) public payable virtual onlyEntryPointOrSelf { | ||
require(supportsExecutionMode(mode), UnsupportedExecutionMode()); | ||
executionData.execBatch(ERC7579Utils.EXECTYPE_DEFAULT); | ||
} | ||
|
||
/// @inheritdoc IERC7821 | ||
function supportsExecutionMode(bytes32 mode) public view virtual returns (bool result) { | ||
(CallType callType, ExecType execType, ModeSelector modeSelector, ) = Mode.wrap(mode).decodeMode(); | ||
return | ||
callType == ERC7579Utils.CALLTYPE_BATCH && | ||
execType == ERC7579Utils.EXECTYPE_DEFAULT && | ||
modeSelector == MODE_BASIC; | ||
} | ||
} |
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,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev Interface for minimal batch executor. | ||
*/ | ||
interface IERC7821 { | ||
/** | ||
* @dev Executes the calls in `executionData`. | ||
* Reverts and bubbles up error if any call fails. | ||
* | ||
* `executionData` encoding: | ||
* - If `opData` is empty, `executionData` is simply `abi.encode(calls)`. | ||
* - Else, `executionData` is `abi.encode(calls, opData)`. | ||
* See: https://eips.ethereum.org/EIPS/eip-7579 | ||
* | ||
* Supported modes: | ||
* - `bytes32(0x01000000000000000000...)`: does not support optional `opData`. | ||
* - `bytes32(0x01000000000078210001...)`: supports optional `opData`. | ||
* | ||
* Authorization checks: | ||
* - If `opData` is empty, the implementation SHOULD require that | ||
* `msg.sender == address(this)`. | ||
* - If `opData` is not empty, the implementation SHOULD use the signature | ||
* encoded in `opData` to determine if the caller can perform the execution. | ||
* | ||
* `opData` may be used to store additional data for authentication, | ||
* paymaster data, gas limits, etc. | ||
*/ | ||
function execute(bytes32 mode, bytes calldata executionData) external payable; | ||
|
||
/** | ||
* @dev This function is provided for frontends to detect support. | ||
* Only returns true for: | ||
* - `bytes32(0x01000000000000000000...)`: does not support optional `opData`. | ||
* - `bytes32(0x01000000000078210001...)`: supports optional `opData`. | ||
*/ | ||
function supportsExecutionMode(bytes32 mode) external view returns (bool); | ||
} |
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