From 9a03e6823108b6ed0ee35c5abc264a5d18c067ed Mon Sep 17 00:00:00 2001 From: kopy-kat Date: Sun, 25 Feb 2024 19:07:29 +0000 Subject: [PATCH] feat: implement delegatecall on executor base --- packages/modulekit/src/external/ERC7579.sol | 1 + .../src/modules/ERC7579ExecutorBase.sol | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/modulekit/src/external/ERC7579.sol b/packages/modulekit/src/external/ERC7579.sol index 47e1cd7d..c5bfe594 100644 --- a/packages/modulekit/src/external/ERC7579.sol +++ b/packages/modulekit/src/external/ERC7579.sol @@ -25,6 +25,7 @@ import { ModePayload, CALLTYPE_SINGLE, CALLTYPE_BATCH, + CALLTYPE_DELEGATECALL, EXECTYPE_DEFAULT, MODE_DEFAULT } from "erc7579/lib/ModeLib.sol"; diff --git a/packages/modulekit/src/modules/ERC7579ExecutorBase.sol b/packages/modulekit/src/modules/ERC7579ExecutorBase.sol index 3d6f160b..cb89d948 100644 --- a/packages/modulekit/src/modules/ERC7579ExecutorBase.sol +++ b/packages/modulekit/src/modules/ERC7579ExecutorBase.sol @@ -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); + } }