Skip to content

Commit

Permalink
chore: gas optimizations in ExecutionHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 21, 2024
1 parent 1f1a30a commit 8d63189
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
43 changes: 37 additions & 6 deletions accounts/safe7579/src/core/ExecutionHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import "../interfaces/ISafe.sol";
abstract contract ExecutionHelper {
error ExecutionFailed();

/**
* Execute call on Safe
* @dev This function will revert if the call fails
* @param safe address of the safe
* @param target address of the contract to call
* @param value value of the transaction
* @param callData data of the transaction
*/
function _execute(
address safe,
address target,
Expand All @@ -25,6 +33,15 @@ abstract contract ExecutionHelper {
if (!success) revert ExecutionFailed();
}

/**
* Execute call on Safe, get return value from call
* @dev This function will revert if the call fails
* @param safe address of the safe
* @param target address of the contract to call
* @param value value of the transaction
* @param callData data of the transaction
* @return returnData data returned from the call
*/
function _executeReturnData(
address safe,
address target,
Expand All @@ -40,26 +57,40 @@ abstract contract ExecutionHelper {
if (!success) revert ExecutionFailed();
}

/**
* Execute call on Safe
* @dev This function will revert if the call fails
* @param safe address of the safe
* @param executions ERC-7579 struct for batched executions
*/
function _execute(address safe, Execution[] calldata executions) internal {
uint256 length = executions.length;
for (uint256 i; i < length; i++) {
_execute(safe, executions[i].target, executions[i].value, executions[i].callData);
Execution calldata execution = executions[i];
_execute(safe, execution.target, execution.value, execution.callData);
}
}

/**
* Execute call on Safe
* @dev This function will revert if the call fails
* @param safe address of the safe
* @param executions ERC-7579 struct for batched executions
* @return returnDatas array returned datas from the batched calls
*/
function _executeReturnData(
address safe,
Execution[] calldata executions
)
internal
returns (bytes[] memory retData)
returns (bytes[] memory returnDatas)
{
uint256 length = executions.length;
retData = new bytes[](length);
returnDatas = new bytes[](length);
for (uint256 i; i < length; i++) {
retData[i] = _executeReturnData(
safe, executions[i].target, executions[i].value, executions[i].callData
);
Execution calldata execution = executions[i];
returnDatas[i] =
_executeReturnData(safe, execution.target, execution.value, execution.callData);
}
}
}
3 changes: 3 additions & 0 deletions accounts/safe7579/src/core/HookManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ abstract contract HookManager is ModuleManager {
address hook = $hookManager[msg.sender];
bool isHookEnabled = hook != address(0);
bytes memory hookPreContext;

// pre hook
if (isHookEnabled) hookPreContext = _doPreHook(hook);

_; // <-- hooked Function Bytecode here

// post hook
if (isHookEnabled) _doPostHook(hook, hookPreContext);
}

Expand Down

0 comments on commit 8d63189

Please sign in to comment.