Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
178 lines
4.8 KiB
Markdown
178 lines
4.8 KiB
Markdown
# ERC7821
|
|
|
|
Minimal batch executor mixin.
|
|
|
|
|
|
This contract can be inherited to create fully-fledged smart accounts.
|
|
If you merely want to combine approve-swap transactions into a single transaction
|
|
using [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702), you will need to implement basic
|
|
[ERC-1271](https://eips.ethereum.org/EIPS/eip-1271) `isValidSignature` functionality to
|
|
validate signatures with `ecrecover` against the EOA address. This is necessary because some
|
|
signature checks skip `ecrecover` if the signer has code. For a basic EOA batch executor,
|
|
please refer to [BEBE](https://github.com/vectorized/bebe), which inherits from this class.
|
|
|
|
<b>Inherits:</b>
|
|
|
|
- [`accounts/Receiver.sol`](accounts/receiver.md)
|
|
|
|
|
|
<!-- customintro:start --><!-- customintro:end -->
|
|
|
|
## Structs
|
|
|
|
### Call
|
|
|
|
```solidity
|
|
struct Call {
|
|
address to; // Replaced as `address(this)` if `address(0)`. Renamed to `to` for Ithaca Porto.
|
|
uint256 value; // Amount of native currency (i.e. Ether) to send.
|
|
bytes data; // Calldata to send with the call.
|
|
}
|
|
```
|
|
|
|
Call struct for the `execute` function.
|
|
|
|
## Custom Errors
|
|
|
|
### UnsupportedExecutionMode()
|
|
|
|
```solidity
|
|
error UnsupportedExecutionMode()
|
|
```
|
|
|
|
The execution mode is not supported.
|
|
|
|
### BatchOfBatchesDecodingError()
|
|
|
|
```solidity
|
|
error BatchOfBatchesDecodingError()
|
|
```
|
|
|
|
Cannot decode `executionData` as a batch of batches `abi.encode(bytes[])`.
|
|
|
|
## Execution Operations
|
|
|
|
### execute(bytes32,bytes)
|
|
|
|
```solidity
|
|
function execute(bytes32 mode, bytes calldata executionData)
|
|
public
|
|
payable
|
|
virtual
|
|
```
|
|
|
|
Executes the calls in `executionData`.
|
|
Reverts and bubbles up error if any call fails.
|
|
`executionData` encoding (single batch):
|
|
- 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
|
|
`executionData` encoding (batch of batches):
|
|
- `executionData` is `abi.encode(bytes[])`, where each element in `bytes[]`
|
|
is an `executionData` for a single batch.
|
|
Supported modes:
|
|
- `0x01000000000000000000...`: Single batch. Does not support optional `opData`.
|
|
- `0x01000000000078210001...`: Single batch. Supports optional `opData`.
|
|
- `0x01000000000078210002...`: Batch of batches.
|
|
For the "batch of batches" mode, each batch will be recursively passed into
|
|
`execute` internally with mode `0x01000000000078210001...`.
|
|
Useful for passing in batches signed by different signers.
|
|
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.
|
|
- If `msg.sender` is an authorized entry point, then `execute` MAY accept
|
|
calls from the entry point, and MAY use `opData` for specialized logic.
|
|
`opData` may be used to store additional data for authentication,
|
|
paymaster data, gas limits, etc.
|
|
|
|
### supportsExecutionMode(bytes32)
|
|
|
|
```solidity
|
|
function supportsExecutionMode(bytes32 mode)
|
|
public
|
|
view
|
|
virtual
|
|
returns (bool result)
|
|
```
|
|
|
|
Provided for execution mode support detection.
|
|
|
|
## Internal Helpers
|
|
|
|
### _executionModeId(bytes32)
|
|
|
|
```solidity
|
|
function _executionModeId(bytes32 mode)
|
|
internal
|
|
view
|
|
virtual
|
|
returns (uint256 id)
|
|
```
|
|
|
|
0: invalid mode, 1: no `opData` support, 2: with `opData` support, 3: batch of batches.
|
|
|
|
### _executeBatchOfBatches(bytes32,bytes)
|
|
|
|
```solidity
|
|
function _executeBatchOfBatches(bytes32 mode, bytes calldata executionData)
|
|
internal
|
|
virtual
|
|
```
|
|
|
|
For execution of a batch of batches.
|
|
|
|
### _execute(bytes32,bytes,Call[],bytes)
|
|
|
|
```solidity
|
|
function _execute(
|
|
bytes32 mode,
|
|
bytes calldata executionData,
|
|
Call[] calldata calls,
|
|
bytes calldata opData
|
|
) internal virtual
|
|
```
|
|
|
|
Executes the calls.
|
|
Reverts and bubbles up error if any call fails.
|
|
The `mode` and `executionData` are passed along in case there's a need to use them.
|
|
|
|
### _execute(Call[],bytes32)
|
|
|
|
```solidity
|
|
function _execute(Call[] calldata calls, bytes32 extraData)
|
|
internal
|
|
virtual
|
|
```
|
|
|
|
Executes the calls.
|
|
Reverts and bubbles up error if any call fails.
|
|
`extraData` can be any supplementary data (e.g. a memory pointer, some hash).
|
|
|
|
### _execute(address,uint256,bytes,bytes32)
|
|
|
|
```solidity
|
|
function _execute(
|
|
address to,
|
|
uint256 value,
|
|
bytes calldata data,
|
|
bytes32 extraData
|
|
) internal virtual
|
|
```
|
|
|
|
Executes the call.
|
|
Reverts and bubbles up error if any call fails.
|
|
`extraData` can be any supplementary data (e.g. a memory pointer, some hash).
|
|
|
|
### _get(Call[],uint256)
|
|
|
|
```solidity
|
|
function _get(Call[] calldata calls, uint256 i)
|
|
internal
|
|
view
|
|
virtual
|
|
returns (address to, uint256 value, bytes calldata data)
|
|
```
|
|
|
|
Convenience function for getting `calls[i]`, without bounds checks. |