Skip to content

Commit

Permalink
feat: implement delegatecall on executor base
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Feb 25, 2024
1 parent 2ceb1c6 commit 9a03e68
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/modulekit/src/external/ERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ModePayload,
CALLTYPE_SINGLE,
CALLTYPE_BATCH,
CALLTYPE_DELEGATECALL,
EXECTYPE_DEFAULT,
MODE_DEFAULT
} from "erc7579/lib/ModeLib.sol";
Expand Down
31 changes: 31 additions & 0 deletions packages/modulekit/src/modules/ERC7579ExecutorBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,35 @@ abstract contract ERC7579ExecutorBase is IERC7579Executor, ERC7579ModuleBase {
function _execute(Execution[] memory execs) internal returns (bytes[] memory results) {
return _execute(msg.sender, execs);
}

// Note: Not every account will support delegatecalls
function _executeDelegateCall(
address account,
address delegateTarget,
bytes memory callData
)
internal
returns (bytes[] memory results)
{
ModeCode modeCode = ERC7579ModeLib.encode({
callType: CALLTYPE_DELEGATECALL,
execType: EXECTYPE_DEFAULT,
mode: MODE_DEFAULT,
payload: ModePayload.wrap(bytes22(0))
});
results = IERC7579Account(account).executeFromExecutor(
modeCode, abi.encodePacked(delegateTarget, callData)
);
}

// Note: Not every account will support delegatecalls
function _executeDelegateCall(
address delegateTarget,
bytes memory callData
)
internal
returns (bytes[] memory results)
{
return _executeDelegateCall(msg.sender, delegateTarget, callData);
}
}

0 comments on commit 9a03e68

Please sign in to comment.