feat: Refactor callback to use transient storage

With this, we don't need the univ3 specific method in the router contract. This should be flexible enough for most protocols that integrate

TODO: is this safe enough??

--- don't change below this line ---
ENG-4411 Took 1 hour 52 minutes

Took 4 minutes

Took 5 minutes
This commit is contained in:
Diana Carvalho
2025-03-31 18:07:59 +01:00
parent 62754b195e
commit af449562b0
10 changed files with 45 additions and 102 deletions

View File

@@ -52,7 +52,7 @@ contract Dispatcher {
* @dev Calls an executor, assumes swap.protocolData contains
* protocol-specific data required by the executor.
*/
// slither-disable-next-line delegatecall-loop
// slither-disable-next-line delegatecall-loop,assembly
function _callExecutor(
address executor,
uint256 amount,
@@ -62,6 +62,10 @@ contract Dispatcher {
revert Dispatcher__UnapprovedExecutor();
}
assembly {
tstore(0, executor)
}
// slither-disable-next-line controlled-delegatecall,low-level-calls
(bool success, bytes memory result) = executor.delegatecall(
abi.encodeWithSelector(IExecutor.swap.selector, amount, data)
@@ -80,8 +84,12 @@ contract Dispatcher {
calculatedAmount = abi.decode(result, (uint256));
}
// slither-disable-next-line assembly
function _handleCallback(bytes calldata data) internal {
address executor = address(uint160(bytes20(data[data.length - 20:])));
address executor;
assembly {
executor := tload(0)
}
if (!executors[executor]) {
revert Dispatcher__UnapprovedExecutor();