chore: Rename all SwapExecutor to Executor only for simplicity
--- don't change below this line --- ENG-4033 Took 9 minutes
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
import "@interfaces/ISwapExecutor.sol";
|
||||
import "@interfaces/IExecutor.sol";
|
||||
|
||||
error SwapExecutionDispatcher__UnapprovedExecutor();
|
||||
error SwapExecutionDispatcher__NonContractExecutor();
|
||||
error ExecutionDispatcher__UnapprovedExecutor();
|
||||
error ExecutionDispatcher__NonContractExecutor();
|
||||
|
||||
/**
|
||||
* @title SwapExecutionDispatcher - Dispatch swap execution to external contracts
|
||||
* @title ExecutionDispatcher - Dispatch execution to external contracts
|
||||
* @author PropellerHeads Devs
|
||||
* @dev Provides the ability to delegate execution of swaps to external
|
||||
* contracts. This allows dynamically adding new supported protocols
|
||||
@@ -15,34 +15,34 @@ error SwapExecutionDispatcher__NonContractExecutor();
|
||||
* be called using delegatecall so they can share state with the main
|
||||
* contract if needed.
|
||||
*
|
||||
* Note Executor contracts need to implement the ISwapExecutor interface unless
|
||||
* Note Executor contracts need to implement the IExecutor interface unless
|
||||
* an alternate selector is specified.
|
||||
*/
|
||||
contract SwapExecutionDispatcher {
|
||||
mapping(address => bool) public swapExecutors;
|
||||
contract ExecutionDispatcher {
|
||||
mapping(address => bool) public executors;
|
||||
|
||||
event ExecutorSet(address indexed executor);
|
||||
event ExecutorRemoved(address indexed executor);
|
||||
|
||||
/**
|
||||
* @dev Adds or replaces an approved swap executor contract address if it is a
|
||||
* @dev Adds or replaces an approved executor contract address if it is a
|
||||
* contract.
|
||||
* @param target address of the swap executor contract
|
||||
* @param target address of the executor contract
|
||||
*/
|
||||
function _setSwapExecutor(address target) internal {
|
||||
function _setExecutor(address target) internal {
|
||||
if (target.code.length == 0) {
|
||||
revert SwapExecutionDispatcher__NonContractExecutor();
|
||||
revert ExecutionDispatcher__NonContractExecutor();
|
||||
}
|
||||
swapExecutors[target] = true;
|
||||
executors[target] = true;
|
||||
emit ExecutorSet(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Removes an approved swap executor contract address
|
||||
* @param target address of the swap executor contract
|
||||
* @dev Removes an approved executor contract address
|
||||
* @param target address of the executor contract
|
||||
*/
|
||||
function _removeSwapExecutor(address target) internal {
|
||||
delete swapExecutors[target];
|
||||
function _removeExecutor(address target) internal {
|
||||
delete executors[target];
|
||||
emit ExecutorRemoved(target);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ contract SwapExecutionDispatcher {
|
||||
* protocol-specific data required by the executor.
|
||||
*/
|
||||
// slither-disable-next-line dead-code
|
||||
function _callSwapExecutor(uint256 amount, bytes calldata data)
|
||||
function _callExecutor(uint256 amount, bytes calldata data)
|
||||
internal
|
||||
returns (uint256 calculatedAmount)
|
||||
{
|
||||
@@ -62,12 +62,12 @@ contract SwapExecutionDispatcher {
|
||||
(executor, decodedSelector, protocolData) =
|
||||
_decodeExecutorAndSelector(data);
|
||||
|
||||
if (!swapExecutors[executor]) {
|
||||
revert SwapExecutionDispatcher__UnapprovedExecutor();
|
||||
if (!executors[executor]) {
|
||||
revert ExecutionDispatcher__UnapprovedExecutor();
|
||||
}
|
||||
|
||||
bytes4 selector = decodedSelector == bytes4(0)
|
||||
? ISwapExecutor.swap.selector
|
||||
? IExecutor.swap.selector
|
||||
: decodedSelector;
|
||||
|
||||
// slither-disable-next-line low-level-calls
|
||||
@@ -80,7 +80,7 @@ contract SwapExecutionDispatcher {
|
||||
string(
|
||||
result.length > 0
|
||||
? result
|
||||
: abi.encodePacked("Swap execution failed")
|
||||
: abi.encodePacked("Execution failed")
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import "@openzeppelin/contracts/access/AccessControl.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import "@permit2/src/interfaces/IAllowanceTransfer.sol";
|
||||
import "./SwapExecutionDispatcher.sol";
|
||||
import "./ExecutionDispatcher.sol";
|
||||
import "./CallbackVerificationDispatcher.sol";
|
||||
|
||||
error TychoRouter__WithdrawalFailed();
|
||||
@@ -14,7 +14,7 @@ error TychoRouter__NonContractVerifier();
|
||||
|
||||
contract TychoRouter is
|
||||
AccessControl,
|
||||
SwapExecutionDispatcher,
|
||||
ExecutionDispatcher,
|
||||
CallbackVerificationDispatcher
|
||||
{
|
||||
IAllowanceTransfer public immutable permit2;
|
||||
@@ -92,30 +92,30 @@ contract TychoRouter is
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Entrypoint to add or replace an approved swap executor contract address
|
||||
* @param target address of the swap executor contract
|
||||
* @dev Entrypoint to add or replace an approved executor contract address
|
||||
* @param target address of the executor contract
|
||||
*/
|
||||
function setSwapExecutor(address target)
|
||||
function setExecutor(address target)
|
||||
external
|
||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
||||
{
|
||||
_setSwapExecutor(target);
|
||||
_setExecutor(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Entrypoint to remove an approved swap executor contract address
|
||||
* @param target address of the swap executor contract
|
||||
* @dev Entrypoint to remove an approved executor contract address
|
||||
* @param target address of the executor contract
|
||||
*/
|
||||
function removeSwapExecutor(address target)
|
||||
function removeExecutor(address target)
|
||||
external
|
||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
||||
{
|
||||
_removeSwapExecutor(target);
|
||||
_removeExecutor(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Entrypoint to add or replace an approved swap executor contract address
|
||||
* @param target address of the swap method contract
|
||||
* @dev Entrypoint to add or replace an approved callback verifier contract address
|
||||
* @param target address of the callback verifier contract
|
||||
*/
|
||||
function setCallbackVerifier(address target)
|
||||
external
|
||||
@@ -127,8 +127,8 @@ contract TychoRouter is
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Entrypoint to remove an approved swap executor contract address
|
||||
* @param target address of the swap method contract
|
||||
* @dev Entrypoint to remove an approved callback verifier contract address
|
||||
* @param target address of the callback verifier contract
|
||||
*/
|
||||
function removeCallbackVerifier(address target)
|
||||
external
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
import "@uniswap-v2/contracts/interfaces/IUniswapV2Pair.sol";
|
||||
import "@interfaces/IExecutor.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import {IExecutor} from "../interfaces/IExecutor.sol";
|
||||
import "@uniswap-v2/contracts/interfaces/IUniswapV2Pair.sol";
|
||||
|
||||
error UniswapV2Executor__InvalidDataLength();
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
pragma abicoder v2;
|
||||
|
||||
interface IExecutor {
|
||||
/**
|
||||
* @notice Performs a swap on a liquidity pool.
|
||||
* @dev This method takes the amount of the input token and returns the amount of
|
||||
* the output token which has been swapped.
|
||||
*
|
||||
* Note Part of the informal interface is that the executor supports sending the received
|
||||
* tokens to a receiver address. If the underlying smart contract does not provide this
|
||||
* functionality consider adding an additional transfer in the implementation.
|
||||
*
|
||||
* @param givenAmount The amount of the input token to swap.
|
||||
* @param data Data that holds information necessary to perform the swap.
|
||||
* @return calculatedAmount The amount of the output token swapped, depending on
|
||||
* the givenAmount inputted.
|
||||
*/
|
||||
function swap(uint256 givenAmount, bytes calldata data)
|
||||
external
|
||||
returns (uint256 calculatedAmount);
|
||||
}
|
||||
|
||||
interface IExecutorErrors {
|
||||
error InvalidParameterLength(uint256);
|
||||
error UnknownPoolType(uint8);
|
||||
}
|
||||
Reference in New Issue
Block a user