refactor: rm callback verifier dispatcher

This commit is contained in:
royvardhan
2025-02-14 23:11:01 +05:30
parent 260f9d866f
commit d0027e6cf2
11 changed files with 216 additions and 496 deletions

View File

@@ -3,7 +3,7 @@ pragma solidity ^0.8.26;
import "../lib/IWETH.sol";
import "../lib/bytes/LibPrefixLengthEncodedByteArray.sol";
import "./CallbackVerificationDispatcher.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
@@ -27,7 +27,6 @@ error TychoRouter__MessageValueMismatch(uint256 value, uint256 amount);
contract TychoRouter is
AccessControl,
ExecutionDispatcher,
CallbackVerificationDispatcher,
Pausable,
ReentrancyGuard,
SafeCallback
@@ -58,16 +57,21 @@ contract TychoRouter is
uint256 public fee;
event Withdrawal(
address indexed token, uint256 amount, address indexed receiver
address indexed token,
uint256 amount,
address indexed receiver
);
event FeeReceiverSet(
address indexed oldFeeReceiver, address indexed newFeeReceiver
address indexed oldFeeReceiver,
address indexed newFeeReceiver
);
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
constructor(IPoolManager _poolManager, address _permit2, address weth)
SafeCallback(_poolManager)
{
constructor(
IPoolManager _poolManager,
address _permit2,
address weth
) SafeCallback(_poolManager) {
if (_permit2 == address(0) || weth == address(0)) {
revert TychoRouter__AddressZero();
}
@@ -181,10 +185,11 @@ contract TychoRouter is
*
* @return The total amount of the buy token obtained after all swaps have been executed.
*/
function _swap(uint256 amountIn, uint256 nTokens, bytes calldata swaps_)
internal
returns (uint256)
{
function _swap(
uint256 amountIn,
uint256 nTokens,
bytes calldata swaps_
) internal returns (uint256) {
if (swaps_.length == 0) {
revert TychoRouter__EmptySwaps();
}
@@ -251,10 +256,10 @@ contract TychoRouter is
/**
* @dev Allows granting roles to multiple accounts in a single call.
*/
function batchGrantRole(bytes32 role, address[] memory accounts)
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
function batchGrantRole(
bytes32 role,
address[] memory accounts
) external onlyRole(DEFAULT_ADMIN_ROLE) {
for (uint256 i = 0; i < accounts.length; i++) {
_grantRole(role, accounts[i]);
}
@@ -264,10 +269,9 @@ contract TychoRouter is
* @dev Entrypoint to add or replace an approved executor contract address
* @param targets address of the executor contract
*/
function setExecutors(address[] memory targets)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
function setExecutors(
address[] memory targets
) external onlyRole(EXECUTOR_SETTER_ROLE) {
for (uint256 i = 0; i < targets.length; i++) {
_setExecutor(targets[i]);
}
@@ -277,42 +281,18 @@ contract TychoRouter is
* @dev Entrypoint to remove an approved executor contract address
* @param target address of the executor contract
*/
function removeExecutor(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
function removeExecutor(
address target
) external onlyRole(EXECUTOR_SETTER_ROLE) {
_removeExecutor(target);
}
/**
* @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
onlyRole(EXECUTOR_SETTER_ROLE)
{
_setCallbackVerifier(target);
}
/**
* @dev Entrypoint to remove an approved callback verifier contract address
* @param target address of the callback verifier contract
*/
function removeCallbackVerifier(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
_removeCallbackVerifier(target);
}
/**
* @dev Allows setting the fee receiver.
*/
function setFeeReceiver(address newfeeReceiver)
external
onlyRole(FEE_SETTER_ROLE)
{
function setFeeReceiver(
address newfeeReceiver
) external onlyRole(FEE_SETTER_ROLE) {
if (newfeeReceiver == address(0)) revert TychoRouter__AddressZero();
emit FeeReceiverSet(feeReceiver, newfeeReceiver);
feeReceiver = newfeeReceiver;
@@ -329,10 +309,10 @@ contract TychoRouter is
/**
* @dev Allows withdrawing any ERC20 funds if funds get stuck in case of a bug.
*/
function withdraw(IERC20[] memory tokens, address receiver)
external
onlyRole(FUND_RESCUER_ROLE)
{
function withdraw(
IERC20[] memory tokens,
address receiver
) external onlyRole(FUND_RESCUER_ROLE) {
if (receiver == address(0)) revert TychoRouter__AddressZero();
for (uint256 i = 0; i < tokens.length; i++) {
@@ -349,10 +329,9 @@ contract TychoRouter is
* @dev Allows withdrawing any NATIVE funds if funds get stuck in case of a bug.
* The contract should never hold any NATIVE tokens for security reasons.
*/
function withdrawNative(address receiver)
external
onlyRole(FUND_RESCUER_ROLE)
{
function withdrawNative(
address receiver
) external onlyRole(FUND_RESCUER_ROLE) {
if (receiver == address(0)) revert TychoRouter__AddressZero();
uint256 amount = address(this).balance;
@@ -380,8 +359,9 @@ contract TychoRouter is
* @param amount of WETH to unwrap.
*/
function _unwrapETH(uint256 amount) internal {
uint256 unwrapAmount =
amount == 0 ? _weth.balanceOf(address(this)) : amount;
uint256 unwrapAmount = amount == 0
? _weth.balanceOf(address(this))
: amount;
_weth.withdraw(unwrapAmount);
}
@@ -400,15 +380,14 @@ contract TychoRouter is
bytes calldata msgData
) external {
_handleCallback(
bytes4(0), abi.encodePacked(amount0Delta, amount1Delta, msgData)
bytes4(0),
abi.encodePacked(amount0Delta, amount1Delta, msgData)
);
}
function _unlockCallback(bytes calldata data)
internal
override
returns (bytes memory)
{
function _unlockCallback(
bytes calldata data
) internal override returns (bytes memory) {
require(data.length >= 20, "Invalid data length");
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
address executor = address(uint160(bytes20(data[data.length - 20:])));
@@ -419,7 +398,7 @@ contract TychoRouter is
}
// slither-disable-next-line controlled-delegatecall,low-level-calls
(bool success,) = executor.delegatecall(
(bool success, ) = executor.delegatecall(
abi.encodeWithSelector(selector, protocolData)
);
require(success, "delegatecall to uniswap v4 callback failed");