-
Notifications
You must be signed in to change notification settings - Fork 33
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
27 changed files
with
160 additions
and
26 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
File renamed without changes.
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,134 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import { Execution } from "../../common/interfaces/IERC7579Account.sol"; | ||
|
||
/** | ||
* @title Execution | ||
* @dev This contract executes calls in the context of this contract. | ||
* @author zeroknots.eth | rhinestone.wtf | ||
* shoutout to solady (vectorized, ross) for this code | ||
* https://github.com/Vectorized/solady/blob/main/src/accounts/ERC4337.sol | ||
*/ | ||
contract ExecutionHelper { | ||
error ExecutionFailed(); | ||
|
||
event TryExecuteUnsuccessful(uint256 batchExecutionindex, bytes result); | ||
|
||
function _execute(Execution[] calldata executions) internal returns (bytes[] memory result) { | ||
uint256 length = executions.length; | ||
result = new bytes[](length); | ||
|
||
for (uint256 i; i < length; i++) { | ||
Execution calldata _exec = executions[i]; | ||
result[i] = _execute(_exec.target, _exec.value, _exec.callData); | ||
} | ||
} | ||
|
||
function _tryExecute(Execution[] calldata executions) | ||
internal | ||
returns (bytes[] memory result) | ||
{ | ||
uint256 length = executions.length; | ||
result = new bytes[](length); | ||
|
||
for (uint256 i; i < length; i++) { | ||
Execution calldata _exec = executions[i]; | ||
bool success; | ||
(success, result[i]) = _tryExecute(_exec.target, _exec.value, _exec.callData); | ||
if (!success) emit TryExecuteUnsuccessful(i, result[i]); | ||
} | ||
} | ||
|
||
function _execute( | ||
address target, | ||
uint256 value, | ||
bytes calldata callData | ||
) | ||
internal | ||
virtual | ||
returns (bytes memory result) | ||
{ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := mload(0x40) | ||
calldatacopy(result, callData.offset, callData.length) | ||
if iszero(call(gas(), target, value, result, callData.length, codesize(), 0x00)) { | ||
// Bubble up the revert if the call reverts. | ||
returndatacopy(result, 0x00, returndatasize()) | ||
revert(result, returndatasize()) | ||
} | ||
mstore(result, returndatasize()) // Store the length. | ||
let o := add(result, 0x20) | ||
returndatacopy(o, 0x00, returndatasize()) // Copy the returndata. | ||
mstore(0x40, add(o, returndatasize())) // Allocate the memory. | ||
} | ||
} | ||
|
||
function _tryExecute( | ||
address target, | ||
uint256 value, | ||
bytes calldata callData | ||
) | ||
internal | ||
virtual | ||
returns (bool success, bytes memory result) | ||
{ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := mload(0x40) | ||
calldatacopy(result, callData.offset, callData.length) | ||
success := call(gas(), target, value, result, callData.length, codesize(), 0x00) | ||
mstore(result, returndatasize()) // Store the length. | ||
let o := add(result, 0x20) | ||
returndatacopy(o, 0x00, returndatasize()) // Copy the returndata. | ||
mstore(0x40, add(o, returndatasize())) // Allocate the memory. | ||
} | ||
} | ||
|
||
/// @dev Execute a delegatecall with `delegate` on this account. | ||
function _executeDelegatecall( | ||
address delegate, | ||
bytes calldata callData | ||
) | ||
internal | ||
returns (bytes memory result) | ||
{ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := mload(0x40) | ||
calldatacopy(result, callData.offset, callData.length) | ||
// Forwards the `data` to `delegate` via delegatecall. | ||
if iszero(delegatecall(gas(), delegate, result, callData.length, codesize(), 0x00)) { | ||
// Bubble up the revert if the call reverts. | ||
returndatacopy(result, 0x00, returndatasize()) | ||
revert(result, returndatasize()) | ||
} | ||
mstore(result, returndatasize()) // Store the length. | ||
let o := add(result, 0x20) | ||
returndatacopy(o, 0x00, returndatasize()) // Copy the returndata. | ||
mstore(0x40, add(o, returndatasize())) // Allocate the memory. | ||
} | ||
} | ||
|
||
/// @dev Execute a delegatecall with `delegate` on this account and catch reverts. | ||
function _tryExecuteDelegatecall( | ||
address delegate, | ||
bytes calldata callData | ||
) | ||
internal | ||
returns (bool success, bytes memory result) | ||
{ | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
result := mload(0x40) | ||
calldatacopy(result, callData.offset, callData.length) | ||
// Forwards the `data` to `delegate` via delegatecall. | ||
success := delegatecall(gas(), delegate, result, callData.length, codesize(), 0x00) | ||
mstore(result, returndatasize()) // Store the length. | ||
let o := add(result, 0x20) | ||
returndatacopy(o, 0x00, returndatasize()) // Copy the returndata. | ||
mstore(0x40, add(o, returndatasize())) // Allocate the memory. | ||
} | ||
} | ||
} |
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
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
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
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