Merge branch 'main' into router/hr/ENG-4050-fee-methods

This commit is contained in:
Harsh Vardhan Roy
2025-01-23 15:04:11 +05:30
committed by GitHub
9 changed files with 285 additions and 12 deletions

View File

@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/**
* @title Dispatch callback verification to external contracts
* @author PropellerHeads Devs
* @dev Provides the ability call external contracts to perform callback
* verification. This allows dynamically adding new supported protocols
* without needing to upgrade any contracts.
*
* Note Verifier contracts need to implement the ICallbackVerifier interface
*/
contract CallbackVerificationDispatcher {
mapping(address => bool) public callbackVerifiers;
}

View File

@@ -0,0 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
/**
* @title SwapExecutionDispatcher - Dispatch swap 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
* without needing to upgrade any contracts. External contracts will
* be called using delegatecall so they can share state with the main
* contract if needed.
*
* Note Executor contracts need to implement the ISwapExecutor interface
*/
contract SwapExecutionDispatcher {
mapping(address => bool) public swapExecutors;
}

View File

@@ -2,14 +2,22 @@
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@permit2/src/interfaces/IAllowanceTransfer.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 "./CallbackVerificationDispatcher.sol";
error TychoRouter__WithdrawalFailed();
error TychoRouter__AddressZero();
error TychoRouter__NonContractExecutor();
error TychoRouter__NonContractVerifier();
contract TychoRouter is AccessControl {
contract TychoRouter is
AccessControl,
SwapExecutionDispatcher,
CallbackVerificationDispatcher
{
IAllowanceTransfer public immutable permit2;
using SafeERC20 for IERC20;
@@ -37,6 +45,8 @@ contract TychoRouter is AccessControl {
address indexed oldFeeReceiver, address indexed newFeeReceiver
);
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
event ExecutorSet(address indexed executor);
event CallbackVerifierSet(address indexed callbackVerifier);
constructor(address _permit2) {
permit2 = IAllowanceTransfer(_permit2);
@@ -78,7 +88,57 @@ contract TychoRouter is AccessControl {
external
onlyRole(DEFAULT_ADMIN_ROLE)
{
// TODO
for (uint256 i = 0; i < accounts.length; i++) {
_grantRole(role, accounts[i]);
}
}
/**
* @dev Entrypoint to add or replace an approved swap executor contract address
* @param target address of the swap method contract
*/
function setSwapExecutor(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
if (target.code.length == 0) revert TychoRouter__NonContractExecutor();
swapExecutors[target] = true;
emit ExecutorSet(target);
}
/**
* @dev Entrypoint to remove an approved swap executor contract address
* @param target address of the swap method contract
*/
function removeSwapExecutor(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
delete swapExecutors[target];
}
/**
* @dev Entrypoint to add or replace an approved swap executor contract address
* @param target address of the swap method contract
*/
function setCallbackVerifier(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
if (target.code.length == 0) revert TychoRouter__NonContractVerifier();
callbackVerifiers[target] = true;
emit CallbackVerifierSet(target);
}
/**
* @dev Entrypoint to remove an approved swap executor contract address
* @param target address of the swap method contract
*/
function removeCallbackVerifier(address target)
external
onlyRole(EXECUTOR_SETTER_ROLE)
{
delete callbackVerifiers[target];
}
/**