Skip to content

Commit

Permalink
Save state, add dai special casing
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongeric committed Sep 27, 2023
1 parent 6fc26bd commit ebe31f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/SwapRouter02ExecutorExecute.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
250340
250378
Original file line number Diff line number Diff line change
@@ -1 +1 @@
111794
111832
18 changes: 14 additions & 4 deletions src/sample-executors/BaseExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit ebe31f9

Please sign in to comment.