feat: Set swap executors and verifiers

- Moved the deployment method into a test template for organization
- Created skeletons of dispatcher contracts
- Added all possible test cases for thoroughness
This commit is contained in:
TAMARA LIPOWSKI
2025-01-22 12:21:13 -05:00
parent 68d29f1970
commit 4cb3286c94
6 changed files with 262 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
/**
* @title Dispatch callback verification to external contracts
* @author PropellerHeads Devs
* @dev Provides the ability to delegate callback verification 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 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__InvalidReceiver();
error TychoRouter__NonContractExecutor();
error TychoRouter__NonContractVerifier();
contract TychoRouter is AccessControl {
contract TychoRouter is
AccessControl,
SwapExecutionDispatcher,
CallbackVerificationDispatcher
{
IAllowanceTransfer public immutable permit2;
using SafeERC20 for IERC20;
@@ -68,7 +76,55 @@ 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;
}
/**
* @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;
}
/**
* @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];
}
/**