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>
5.6 KiB
LibERC7579
Library for handling ERC7579 mode and execution data.
Custom Errors
DecodingError()
error DecodingError()
Cannot decode executionData.
Constants
CALLTYPE_SINGLE
bytes1 internal constant CALLTYPE_SINGLE = 0x00
A single execution.
CALLTYPE_BATCH
bytes1 internal constant CALLTYPE_BATCH = 0x01
A batch of executions.
CALLTYPE_STATICCALL
bytes1 internal constant CALLTYPE_STATICCALL = 0xfe
A single staticcall execution.
CALLTYPE_DELEGATECALL
bytes1 internal constant CALLTYPE_DELEGATECALL = 0xff
A delegatecall execution.
EXECTYPE_DEFAULT
bytes1 internal constant EXECTYPE_DEFAULT = 0x00
Default execution type that reverts on failure.
EXECTYPE_TRY
bytes1 internal constant EXECTYPE_TRY = 0x01
Execution type that does not revert on failure.
Mode Operations
encodeMode(bytes1,bytes1,bytes4,bytes22)
function encodeMode(
bytes1 callType,
bytes1 execType,
bytes4 selector,
bytes22 payload
) internal pure returns (bytes32 result)
Encodes the fields into a mode.
getCallType(bytes32)
function getCallType(bytes32 mode) internal pure returns (bytes1)
Returns the call type of the mode.
getExecType(bytes32)
function getExecType(bytes32 mode) internal pure returns (bytes1)
Returns the call type of the mode.
getSelector(bytes32)
function getSelector(bytes32 mode) internal pure returns (bytes4)
Returns the selector of the mode.
getPayload(bytes32)
function getPayload(bytes32 mode) internal pure returns (bytes22)
Returns the payload stored in the mode.
Execution Data Operations
decodeSingle(bytes)
function decodeSingle(bytes calldata executionData)
internal
pure
returns (address target, uint256 value, bytes calldata data)
Decodes a single call execution.
Reverts if executionData is not correctly encoded.
decodeSingleUnchecked(bytes)
function decodeSingleUnchecked(bytes calldata executionData)
internal
pure
returns (address target, uint256 value, bytes calldata data)
Decodes a single call execution without bounds checks.
decodeDelegate(bytes)
function decodeDelegate(bytes calldata executionData)
internal
pure
returns (address target, bytes calldata data)
Decodes a single delegate execution.
Reverts if executionData is not correctly encoded.
decodeDelegateUnchecked(bytes)
function decodeDelegateUnchecked(bytes calldata executionData)
internal
pure
returns (address target, bytes calldata data)
Decodes a single delegate execution without bounds checks.
decodeBatch(bytes)
function decodeBatch(bytes calldata executionData)
internal
pure
returns (bytes32[] calldata pointers)
Decodes a batch.
Reverts if executionData is not correctly encoded.
decodeBatchUnchecked(bytes)
function decodeBatchUnchecked(bytes calldata executionData)
internal
pure
returns (bytes32[] calldata pointers)
Decodes a batch without bounds checks.
This function can be used in execute, if the validation phase has already
decoded the executionData with checks via decodeBatch.
decodeBatchAndOpData(bytes)
function decodeBatchAndOpData(bytes calldata executionData)
internal
pure
returns (bytes32[] calldata pointers, bytes calldata opData)
Decodes a batch and optional opData.
Reverts if executionData is not correctly encoded.
decodeBatchAndOpDataUnchecked(bytes)
function decodeBatchAndOpDataUnchecked(bytes calldata executionData)
internal
pure
returns (bytes32[] calldata pointers, bytes calldata opData)
Decodes a batch without bounds checks.
This function can be used in execute, if the validation phase has already
decoded the executionData with checks via decodeBatchAndOpData.
hasOpData(bytes)
function hasOpData(bytes calldata executionData)
internal
pure
returns (bool result)
Returns whether the executionData has optional opData.
getExecution(bytes32[],uint256)
function getExecution(bytes32[] calldata pointers, uint256 i)
internal
pure
returns (address target, uint256 value, bytes calldata data)
Returns the ith execution at pointers, without bounds checks.
The bounds check is excluded as this function is intended to be called in a bounded loop.
reencodeBatch(bytes,bytes)
function reencodeBatch(bytes calldata executionData, bytes memory opData)
internal
pure
returns (bytes memory result)
Reencodes executionData such that it has opData added to it.
Like abi.encode(abi.decode(executionData, (Call[])), opData).
Useful for forwarding executionData with extra opData.
This function does not perform any check on the validity of executionData.
reencodeBatchAsExecuteCalldata(bytes32,bytes,bytes)
function reencodeBatchAsExecuteCalldata(
bytes32 mode,
bytes calldata executionData,
bytes memory opData
) internal pure returns (bytes memory result)
abi.encodeWithSignature("execute(bytes32,bytes)", mode, reencodeBatch(executionData, opData)).
Helpers
emptyCalldataBytes()
function emptyCalldataBytes()
internal
pure
returns (bytes calldata result)
Helper function to return empty calldata bytes.