From ebe31f90952af3a715def9055c7f7356a314c3ff Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Wed, 27 Sep 2023 11:28:46 -0400 Subject: [PATCH] Save state, add dai special casing --- .../SwapRouter02ExecutorExecute.snap | 2 +- ...Router02ExecutorExecuteAlreadyApproved.snap | 2 +- src/sample-executors/BaseExecutor.sol | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.forge-snapshots/SwapRouter02ExecutorExecute.snap b/.forge-snapshots/SwapRouter02ExecutorExecute.snap index f5ceb06b..1af7ba71 100644 --- a/.forge-snapshots/SwapRouter02ExecutorExecute.snap +++ b/.forge-snapshots/SwapRouter02ExecutorExecute.snap @@ -1 +1 @@ -250340 \ No newline at end of file +250378 \ No newline at end of file diff --git a/.forge-snapshots/SwapRouter02ExecutorExecuteAlreadyApproved.snap b/.forge-snapshots/SwapRouter02ExecutorExecuteAlreadyApproved.snap index 5b620388..e3da4550 100644 --- a/.forge-snapshots/SwapRouter02ExecutorExecuteAlreadyApproved.snap +++ b/.forge-snapshots/SwapRouter02ExecutorExecuteAlreadyApproved.snap @@ -1 +1 @@ -111794 \ No newline at end of file +111832 \ No newline at end of file diff --git a/src/sample-executors/BaseExecutor.sol b/src/sample-executors/BaseExecutor.sol index 60833608..f9846c02 100644 --- a/src/sample-executors/BaseExecutor.sol +++ b/src/sample-executors/BaseExecutor.sol @@ -18,6 +18,10 @@ struct PermitData { abstract contract BaseExecutor is IReactorCallback, Multicall, Owned { IReactor public immutable reactor; + address public constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F; + bytes4 internal constant ERC2612_PERMIT_SIGNATURE = 0xd505accf; + bytes4 internal constant DAI_PERMIT_SIGNATURE = 0x8fcbaf0c; + constructor(IReactor _reactor, address _owner) Owned(_owner) { reactor = _reactor; } @@ -33,12 +37,18 @@ abstract contract BaseExecutor is IReactorCallback, Multicall, Owned { reactor.executeBatchWithCallback(orders, callbackData); } - /// @notice execute a signed 2612-style permit + /// @notice execute a signed ERC2612 permit + /// @dev since DAI has a non standard permit, it's special cased /// the transaction will revert if the permit cannot be executed function permit(PermitData memory permitData) public { - (address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) = - abi.decode(permitData.data, (address, address, uint256, uint256, uint8, bytes32, bytes32)); - ERC20(permitData.token).permit(owner, spender, value, deadline, v, r, s); + if(permitData.token == DAI) { + (bool success,) = permitData.token.call(abi.encodeWithSelector(DAI_PERMIT_SIGNATURE, permitData.data)); + require(success, "DAI permit failed"); + } + else { + (bool success,) = permitData.token.call(abi.encodeWithSelector(ERC2612_PERMIT_SIGNATURE, permitData.data); + require(success, "ERC2612 permit failed"); + } } /// @notice execute a batch of signed 2612-style permits