feat: update new interface in codebase
This commit is contained in:
@@ -27,7 +27,7 @@ interface IExecutor {
|
|||||||
|
|
||||||
function handleCallback(
|
function handleCallback(
|
||||||
bytes calldata callbackData
|
bytes calldata callbackData
|
||||||
) external returns (address tokenOwed, uint256 amountOwed);
|
) external returns (bytes memory result);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IExecutorErrors {
|
interface IExecutorErrors {
|
||||||
|
|||||||
@@ -79,4 +79,24 @@ contract ExecutionDispatcher {
|
|||||||
|
|
||||||
calculatedAmount = abi.decode(result, (uint256));
|
calculatedAmount = abi.decode(result, (uint256));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _handleCallback(address executor, bytes calldata data) internal {
|
||||||
|
if (!executors[executor]) {
|
||||||
|
revert ExecutionDispatcher__UnapprovedExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
(bool success, bytes memory result) = executor.delegatecall(
|
||||||
|
abi.encodeWithSelector(IExecutor.handleCallback.selector, data)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
revert(
|
||||||
|
string(
|
||||||
|
result.length > 0
|
||||||
|
? result
|
||||||
|
: abi.encodePacked("Callback failed")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import "@openzeppelin/contracts/utils/Pausable.sol";
|
|||||||
import "@openzeppelin/contracts/utils/Address.sol";
|
import "@openzeppelin/contracts/utils/Address.sol";
|
||||||
import "@permit2/src/interfaces/IAllowanceTransfer.sol";
|
import "@permit2/src/interfaces/IAllowanceTransfer.sol";
|
||||||
import "./ExecutionDispatcher.sol";
|
import "./ExecutionDispatcher.sol";
|
||||||
import "./CallbackVerificationDispatcher.sol";
|
|
||||||
import {LibSwap} from "../lib/LibSwap.sol";
|
import {LibSwap} from "../lib/LibSwap.sol";
|
||||||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
||||||
import {SafeCallback} from "@uniswap/v4-periphery/src/base/SafeCallback.sol";
|
import {SafeCallback} from "@uniswap/v4-periphery/src/base/SafeCallback.sol";
|
||||||
@@ -58,16 +57,21 @@ contract TychoRouter is
|
|||||||
uint256 public fee;
|
uint256 public fee;
|
||||||
|
|
||||||
event Withdrawal(
|
event Withdrawal(
|
||||||
address indexed token, uint256 amount, address indexed receiver
|
address indexed token,
|
||||||
|
uint256 amount,
|
||||||
|
address indexed receiver
|
||||||
);
|
);
|
||||||
event FeeReceiverSet(
|
event FeeReceiverSet(
|
||||||
address indexed oldFeeReceiver, address indexed newFeeReceiver
|
address indexed oldFeeReceiver,
|
||||||
|
address indexed newFeeReceiver
|
||||||
);
|
);
|
||||||
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
|
event FeeSet(uint256 indexed oldFee, uint256 indexed newFee);
|
||||||
|
|
||||||
constructor(IPoolManager _poolManager, address _permit2, address weth)
|
constructor(
|
||||||
SafeCallback(_poolManager)
|
IPoolManager _poolManager,
|
||||||
{
|
address _permit2,
|
||||||
|
address weth
|
||||||
|
) SafeCallback(_poolManager) {
|
||||||
if (_permit2 == address(0) || weth == address(0)) {
|
if (_permit2 == address(0) || weth == address(0)) {
|
||||||
revert TychoRouter__AddressZero();
|
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.
|
* @return The total amount of the buy token obtained after all swaps have been executed.
|
||||||
*/
|
*/
|
||||||
function _swap(uint256 amountIn, uint256 nTokens, bytes calldata swaps_)
|
function _swap(
|
||||||
internal
|
uint256 amountIn,
|
||||||
returns (uint256)
|
uint256 nTokens,
|
||||||
{
|
bytes calldata swaps_
|
||||||
|
) internal returns (uint256) {
|
||||||
if (swaps_.length == 0) {
|
if (swaps_.length == 0) {
|
||||||
revert TychoRouter__EmptySwaps();
|
revert TychoRouter__EmptySwaps();
|
||||||
}
|
}
|
||||||
@@ -230,17 +235,7 @@ contract TychoRouter is
|
|||||||
* caller is not a pool.
|
* caller is not a pool.
|
||||||
*/
|
*/
|
||||||
fallback() external {
|
fallback() external {
|
||||||
_executeGenericCallback(msg.data);
|
_handleCallback(msg.sender, msg.data);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Check if the sender is correct and executes callback actions.
|
|
||||||
* @param msgData encoded data. It must includes data for the verification.
|
|
||||||
*/
|
|
||||||
function _executeGenericCallback(bytes calldata msgData) internal {
|
|
||||||
(uint256 amountOwed, address tokenOwed) = _callVerifyCallback(msgData);
|
|
||||||
|
|
||||||
IERC20(tokenOwed).safeTransfer(msg.sender, amountOwed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -260,10 +255,10 @@ contract TychoRouter is
|
|||||||
/**
|
/**
|
||||||
* @dev Allows granting roles to multiple accounts in a single call.
|
* @dev Allows granting roles to multiple accounts in a single call.
|
||||||
*/
|
*/
|
||||||
function batchGrantRole(bytes32 role, address[] memory accounts)
|
function batchGrantRole(
|
||||||
external
|
bytes32 role,
|
||||||
onlyRole(DEFAULT_ADMIN_ROLE)
|
address[] memory accounts
|
||||||
{
|
) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
||||||
for (uint256 i = 0; i < accounts.length; i++) {
|
for (uint256 i = 0; i < accounts.length; i++) {
|
||||||
_grantRole(role, accounts[i]);
|
_grantRole(role, accounts[i]);
|
||||||
}
|
}
|
||||||
@@ -273,10 +268,9 @@ contract TychoRouter is
|
|||||||
* @dev Entrypoint to add or replace an approved executor contract address
|
* @dev Entrypoint to add or replace an approved executor contract address
|
||||||
* @param targets address of the executor contract
|
* @param targets address of the executor contract
|
||||||
*/
|
*/
|
||||||
function setExecutors(address[] memory targets)
|
function setExecutors(
|
||||||
external
|
address[] memory targets
|
||||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
) external onlyRole(EXECUTOR_SETTER_ROLE) {
|
||||||
{
|
|
||||||
for (uint256 i = 0; i < targets.length; i++) {
|
for (uint256 i = 0; i < targets.length; i++) {
|
||||||
_setExecutor(targets[i]);
|
_setExecutor(targets[i]);
|
||||||
}
|
}
|
||||||
@@ -286,10 +280,9 @@ contract TychoRouter is
|
|||||||
* @dev Entrypoint to remove an approved executor contract address
|
* @dev Entrypoint to remove an approved executor contract address
|
||||||
* @param target address of the executor contract
|
* @param target address of the executor contract
|
||||||
*/
|
*/
|
||||||
function removeExecutor(address target)
|
function removeExecutor(
|
||||||
external
|
address target
|
||||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
) external onlyRole(EXECUTOR_SETTER_ROLE) {
|
||||||
{
|
|
||||||
_removeExecutor(target);
|
_removeExecutor(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,10 +290,9 @@ contract TychoRouter is
|
|||||||
* @dev Entrypoint to add or replace an approved callback verifier contract address
|
* @dev Entrypoint to add or replace an approved callback verifier contract address
|
||||||
* @param target address of the callback verifier contract
|
* @param target address of the callback verifier contract
|
||||||
*/
|
*/
|
||||||
function setCallbackVerifier(address target)
|
function setCallbackVerifier(
|
||||||
external
|
address target
|
||||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
) external onlyRole(EXECUTOR_SETTER_ROLE) {
|
||||||
{
|
|
||||||
_setCallbackVerifier(target);
|
_setCallbackVerifier(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,20 +300,18 @@ contract TychoRouter is
|
|||||||
* @dev Entrypoint to remove an approved callback verifier contract address
|
* @dev Entrypoint to remove an approved callback verifier contract address
|
||||||
* @param target address of the callback verifier contract
|
* @param target address of the callback verifier contract
|
||||||
*/
|
*/
|
||||||
function removeCallbackVerifier(address target)
|
function removeCallbackVerifier(
|
||||||
external
|
address target
|
||||||
onlyRole(EXECUTOR_SETTER_ROLE)
|
) external onlyRole(EXECUTOR_SETTER_ROLE) {
|
||||||
{
|
|
||||||
_removeCallbackVerifier(target);
|
_removeCallbackVerifier(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Allows setting the fee receiver.
|
* @dev Allows setting the fee receiver.
|
||||||
*/
|
*/
|
||||||
function setFeeReceiver(address newfeeReceiver)
|
function setFeeReceiver(
|
||||||
external
|
address newfeeReceiver
|
||||||
onlyRole(FEE_SETTER_ROLE)
|
) external onlyRole(FEE_SETTER_ROLE) {
|
||||||
{
|
|
||||||
if (newfeeReceiver == address(0)) revert TychoRouter__AddressZero();
|
if (newfeeReceiver == address(0)) revert TychoRouter__AddressZero();
|
||||||
emit FeeReceiverSet(feeReceiver, newfeeReceiver);
|
emit FeeReceiverSet(feeReceiver, newfeeReceiver);
|
||||||
feeReceiver = newfeeReceiver;
|
feeReceiver = newfeeReceiver;
|
||||||
@@ -338,10 +328,10 @@ contract TychoRouter is
|
|||||||
/**
|
/**
|
||||||
* @dev Allows withdrawing any ERC20 funds if funds get stuck in case of a bug.
|
* @dev Allows withdrawing any ERC20 funds if funds get stuck in case of a bug.
|
||||||
*/
|
*/
|
||||||
function withdraw(IERC20[] memory tokens, address receiver)
|
function withdraw(
|
||||||
external
|
IERC20[] memory tokens,
|
||||||
onlyRole(FUND_RESCUER_ROLE)
|
address receiver
|
||||||
{
|
) external onlyRole(FUND_RESCUER_ROLE) {
|
||||||
if (receiver == address(0)) revert TychoRouter__AddressZero();
|
if (receiver == address(0)) revert TychoRouter__AddressZero();
|
||||||
|
|
||||||
for (uint256 i = 0; i < tokens.length; i++) {
|
for (uint256 i = 0; i < tokens.length; i++) {
|
||||||
@@ -358,10 +348,9 @@ contract TychoRouter is
|
|||||||
* @dev Allows withdrawing any NATIVE funds if funds get stuck in case of a bug.
|
* @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.
|
* The contract should never hold any NATIVE tokens for security reasons.
|
||||||
*/
|
*/
|
||||||
function withdrawNative(address receiver)
|
function withdrawNative(
|
||||||
external
|
address receiver
|
||||||
onlyRole(FUND_RESCUER_ROLE)
|
) external onlyRole(FUND_RESCUER_ROLE) {
|
||||||
{
|
|
||||||
if (receiver == address(0)) revert TychoRouter__AddressZero();
|
if (receiver == address(0)) revert TychoRouter__AddressZero();
|
||||||
|
|
||||||
uint256 amount = address(this).balance;
|
uint256 amount = address(this).balance;
|
||||||
@@ -389,8 +378,9 @@ contract TychoRouter is
|
|||||||
* @param amount of WETH to unwrap.
|
* @param amount of WETH to unwrap.
|
||||||
*/
|
*/
|
||||||
function _unwrapETH(uint256 amount) internal {
|
function _unwrapETH(uint256 amount) internal {
|
||||||
uint256 unwrapAmount =
|
uint256 unwrapAmount = amount == 0
|
||||||
amount == 0 ? _weth.balanceOf(address(this)) : amount;
|
? _weth.balanceOf(address(this))
|
||||||
|
: amount;
|
||||||
_weth.withdraw(unwrapAmount);
|
_weth.withdraw(unwrapAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,11 +389,9 @@ contract TychoRouter is
|
|||||||
*/
|
*/
|
||||||
receive() external payable {}
|
receive() external payable {}
|
||||||
|
|
||||||
function _unlockCallback(bytes calldata data)
|
function _unlockCallback(
|
||||||
internal
|
bytes calldata data
|
||||||
override
|
) internal override returns (bytes memory) {
|
||||||
returns (bytes memory)
|
|
||||||
{
|
|
||||||
require(data.length >= 20, "Invalid data length");
|
require(data.length >= 20, "Invalid data length");
|
||||||
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
|
bytes4 selector = bytes4(data[data.length - 24:data.length - 20]);
|
||||||
address executor = address(uint160(bytes20(data[data.length - 20:])));
|
address executor = address(uint160(bytes20(data[data.length - 20:])));
|
||||||
@@ -414,7 +402,7 @@ contract TychoRouter is
|
|||||||
}
|
}
|
||||||
|
|
||||||
// slither-disable-next-line controlled-delegatecall,low-level-calls
|
// slither-disable-next-line controlled-delegatecall,low-level-calls
|
||||||
(bool success,) = executor.delegatecall(
|
(bool success, ) = executor.delegatecall(
|
||||||
abi.encodeWithSelector(selector, protocolData)
|
abi.encodeWithSelector(selector, protocolData)
|
||||||
);
|
);
|
||||||
require(success, "delegatecall to uniswap v4 callback failed");
|
require(success, "delegatecall to uniswap v4 callback failed");
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
pragma solidity ^0.8.26;
|
pragma solidity ^0.8.26;
|
||||||
|
|
||||||
import "@interfaces/IExecutor.sol";
|
import "@interfaces/IExecutor.sol";
|
||||||
import {
|
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||||
IERC20,
|
|
||||||
SafeERC20
|
|
||||||
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
||||||
// slither-disable-next-line solc-version
|
// slither-disable-next-line solc-version
|
||||||
import {IAsset} from "@balancer-labs/v2-interfaces/contracts/vault/IAsset.sol";
|
import {IAsset} from "@balancer-labs/v2-interfaces/contracts/vault/IAsset.sol";
|
||||||
// slither-disable-next-line solc-version
|
// slither-disable-next-line solc-version
|
||||||
@@ -19,11 +16,10 @@ contract BalancerV2Executor is IExecutor {
|
|||||||
address private constant VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
|
address private constant VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
|
||||||
|
|
||||||
// slither-disable-next-line locked-ether
|
// slither-disable-next-line locked-ether
|
||||||
function swap(uint256 givenAmount, bytes calldata data)
|
function swap(
|
||||||
external
|
uint256 givenAmount,
|
||||||
payable
|
bytes calldata data
|
||||||
returns (uint256 calculatedAmount)
|
) external payable returns (uint256 calculatedAmount) {
|
||||||
{
|
|
||||||
(
|
(
|
||||||
IERC20 tokenIn,
|
IERC20 tokenIn,
|
||||||
IERC20 tokenOut,
|
IERC20 tokenOut,
|
||||||
@@ -55,11 +51,21 @@ contract BalancerV2Executor is IExecutor {
|
|||||||
|
|
||||||
uint256 limit = 0;
|
uint256 limit = 0;
|
||||||
|
|
||||||
calculatedAmount =
|
calculatedAmount = IVault(VAULT).swap(
|
||||||
IVault(VAULT).swap(singleSwap, funds, limit, block.timestamp);
|
singleSwap,
|
||||||
|
funds,
|
||||||
|
limit,
|
||||||
|
block.timestamp
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _decodeData(bytes calldata data)
|
function handleCallback(
|
||||||
|
bytes calldata data
|
||||||
|
) external returns (bytes memory result) {}
|
||||||
|
|
||||||
|
function _decodeData(
|
||||||
|
bytes calldata data
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
|
|||||||
@@ -11,11 +11,10 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
// slither-disable-next-line locked-ether
|
// slither-disable-next-line locked-ether
|
||||||
function swap(uint256 givenAmount, bytes calldata data)
|
function swap(
|
||||||
external
|
uint256 givenAmount,
|
||||||
payable
|
bytes calldata data
|
||||||
returns (uint256 calculatedAmount)
|
) external payable returns (uint256 calculatedAmount) {
|
||||||
{
|
|
||||||
address target;
|
address target;
|
||||||
address receiver;
|
address receiver;
|
||||||
bool zeroForOne;
|
bool zeroForOne;
|
||||||
@@ -33,7 +32,13 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _decodeData(bytes calldata data)
|
function handleCallback(
|
||||||
|
bytes calldata data
|
||||||
|
) external returns (bytes memory result) {}
|
||||||
|
|
||||||
|
function _decodeData(
|
||||||
|
bytes calldata data
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
@@ -52,20 +57,20 @@ contract UniswapV2Executor is IExecutor {
|
|||||||
zeroForOne = uint8(data[60]) > 0;
|
zeroForOne = uint8(data[60]) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getAmountOut(address target, uint256 amountIn, bool zeroForOne)
|
function _getAmountOut(
|
||||||
internal
|
address target,
|
||||||
view
|
uint256 amountIn,
|
||||||
returns (uint256 amount)
|
bool zeroForOne
|
||||||
{
|
) internal view returns (uint256 amount) {
|
||||||
IUniswapV2Pair pair = IUniswapV2Pair(target);
|
IUniswapV2Pair pair = IUniswapV2Pair(target);
|
||||||
uint112 reserveIn;
|
uint112 reserveIn;
|
||||||
uint112 reserveOut;
|
uint112 reserveOut;
|
||||||
if (zeroForOne) {
|
if (zeroForOne) {
|
||||||
// slither-disable-next-line unused-return
|
// slither-disable-next-line unused-return
|
||||||
(reserveIn, reserveOut,) = pair.getReserves();
|
(reserveIn, reserveOut, ) = pair.getReserves();
|
||||||
} else {
|
} else {
|
||||||
// slither-disable-next-line unused-return
|
// slither-disable-next-line unused-return
|
||||||
(reserveOut, reserveIn,) = pair.getReserves();
|
(reserveOut, reserveIn, ) = pair.getReserves();
|
||||||
}
|
}
|
||||||
|
|
||||||
require(reserveIn > 0 && reserveOut > 0, "L");
|
require(reserveIn > 0 && reserveOut > 0, "L");
|
||||||
|
|||||||
@@ -17,16 +17,15 @@ contract UniswapV3Executor is IExecutor {
|
|||||||
|
|
||||||
address public immutable factory;
|
address public immutable factory;
|
||||||
|
|
||||||
constructor(address factory_) {
|
constructor(address _factory) {
|
||||||
factory = factory_;
|
factory = _factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// slither-disable-next-line locked-ether
|
// slither-disable-next-line locked-ether
|
||||||
function swap(uint256 amountIn, bytes calldata data)
|
function swap(
|
||||||
external
|
uint256 amountIn,
|
||||||
payable
|
bytes calldata data
|
||||||
returns (uint256 amountOut)
|
) external payable returns (uint256 amountOut) {
|
||||||
{
|
|
||||||
(
|
(
|
||||||
address tokenIn,
|
address tokenIn,
|
||||||
address tokenOut,
|
address tokenOut,
|
||||||
@@ -59,20 +58,25 @@ contract UniswapV3Executor is IExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCallback(bytes calldata msgData)
|
function handleCallback(
|
||||||
external
|
bytes calldata msgData
|
||||||
returns (address tokenOwed, uint256 amountOwed)
|
) external returns (bytes memory result) {
|
||||||
{
|
|
||||||
int256 amount0Delta;
|
int256 amount0Delta;
|
||||||
int256 amount1Delta;
|
int256 amount1Delta;
|
||||||
|
|
||||||
(amount0Delta, amount1Delta) =
|
(amount0Delta, amount1Delta) = abi.decode(
|
||||||
abi.decode(msgData[:64], (int256, int256));
|
msgData[:64],
|
||||||
|
(int256, int256)
|
||||||
|
);
|
||||||
|
|
||||||
bytes calldata remainingData = msgData[64:];
|
bytes calldata remainingData = msgData[64:];
|
||||||
(amountOwed, tokenOwed) =
|
(uint256 amountOwed, address tokenOwed) = _verifyUSV3Callback(
|
||||||
_verifyUSV3Callback(amount0Delta, amount1Delta, remainingData);
|
amount0Delta,
|
||||||
|
amount1Delta,
|
||||||
|
remainingData
|
||||||
|
);
|
||||||
IERC20(tokenOwed).safeTransfer(msg.sender, amountOwed);
|
IERC20(tokenOwed).safeTransfer(msg.sender, amountOwed);
|
||||||
|
return abi.encode(amountOwed, tokenOwed);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _verifyUSV3Callback(
|
function _verifyUSV3Callback(
|
||||||
@@ -85,15 +89,23 @@ contract UniswapV3Executor is IExecutor {
|
|||||||
uint24 poolFee = uint24(bytes3(data[40:43]));
|
uint24 poolFee = uint24(bytes3(data[40:43]));
|
||||||
|
|
||||||
// slither-disable-next-line unused-return
|
// slither-disable-next-line unused-return
|
||||||
CallbackValidationV2.verifyCallback(factory, tokenIn, tokenOut, poolFee);
|
CallbackValidationV2.verifyCallback(
|
||||||
|
factory,
|
||||||
|
tokenIn,
|
||||||
|
tokenOut,
|
||||||
|
poolFee
|
||||||
|
);
|
||||||
|
|
||||||
amountIn =
|
amountIn = amount0Delta > 0
|
||||||
amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
|
? uint256(amount0Delta)
|
||||||
|
: uint256(amount1Delta);
|
||||||
|
|
||||||
return (amountIn, tokenIn);
|
return (amountIn, tokenIn);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _decodeData(bytes calldata data)
|
function _decodeData(
|
||||||
|
bytes calldata data
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
@@ -116,11 +128,11 @@ contract UniswapV3Executor is IExecutor {
|
|||||||
zeroForOne = uint8(data[83]) > 0;
|
zeroForOne = uint8(data[83]) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _makeV3CallbackData(address tokenIn, address tokenOut, uint24 fee)
|
function _makeV3CallbackData(
|
||||||
internal
|
address tokenIn,
|
||||||
pure
|
address tokenOut,
|
||||||
returns (bytes memory)
|
uint24 fee
|
||||||
{
|
) internal pure returns (bytes memory) {
|
||||||
return abi.encodePacked(tokenIn, tokenOut, fee);
|
return abi.encodePacked(tokenIn, tokenOut, fee);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,9 @@
|
|||||||
pragma solidity ^0.8.26;
|
pragma solidity ^0.8.26;
|
||||||
|
|
||||||
import "@interfaces/IExecutor.sol";
|
import "@interfaces/IExecutor.sol";
|
||||||
import {
|
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||||
IERC20,
|
|
||||||
SafeERC20
|
|
||||||
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
||||||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
||||||
import {
|
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
|
||||||
Currency, CurrencyLibrary
|
|
||||||
} from "@uniswap/v4-core/src/types/Currency.sol";
|
|
||||||
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
||||||
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
|
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
|
||||||
import {V4Router} from "@uniswap/v4-periphery/src/V4Router.sol";
|
import {V4Router} from "@uniswap/v4-periphery/src/V4Router.sol";
|
||||||
@@ -26,13 +21,16 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
|
|
||||||
constructor(IPoolManager _poolManager) V4Router(_poolManager) {}
|
constructor(IPoolManager _poolManager) V4Router(_poolManager) {}
|
||||||
|
|
||||||
function swap(uint256, bytes calldata data)
|
function swap(
|
||||||
external
|
uint256,
|
||||||
payable
|
bytes calldata data
|
||||||
returns (uint256 calculatedAmount)
|
) external payable returns (uint256 calculatedAmount) {
|
||||||
{
|
(
|
||||||
(address tokenIn, address tokenOut, bool isExactInput, uint256 amount) =
|
address tokenIn,
|
||||||
_decodeData(data);
|
address tokenOut,
|
||||||
|
bool isExactInput,
|
||||||
|
uint256 amount
|
||||||
|
) = _decodeData(data);
|
||||||
|
|
||||||
uint256 tokenOutBalanceBefore;
|
uint256 tokenOutBalanceBefore;
|
||||||
uint256 tokenInBalanceBefore;
|
uint256 tokenInBalanceBefore;
|
||||||
@@ -67,7 +65,9 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
return calculatedAmount;
|
return calculatedAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _decodeData(bytes calldata data)
|
function _decodeData(
|
||||||
|
bytes calldata data
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
@@ -77,15 +77,19 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
uint256 amount
|
uint256 amount
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
(bytes memory actions, bytes[] memory params) =
|
(bytes memory actions, bytes[] memory params) = abi.decode(
|
||||||
abi.decode(data, (bytes, bytes[]));
|
data,
|
||||||
|
(bytes, bytes[])
|
||||||
|
);
|
||||||
|
|
||||||
// First byte of actions determines the swap type
|
// First byte of actions determines the swap type
|
||||||
uint8 action = uint8(bytes1(actions[0]));
|
uint8 action = uint8(bytes1(actions[0]));
|
||||||
|
|
||||||
if (action == uint8(Actions.SWAP_EXACT_IN_SINGLE)) {
|
if (action == uint8(Actions.SWAP_EXACT_IN_SINGLE)) {
|
||||||
IV4Router.ExactInputSingleParams memory swapParams =
|
IV4Router.ExactInputSingleParams memory swapParams = abi.decode(
|
||||||
abi.decode(params[0], (IV4Router.ExactInputSingleParams));
|
params[0],
|
||||||
|
(IV4Router.ExactInputSingleParams)
|
||||||
|
);
|
||||||
|
|
||||||
tokenIn = swapParams.zeroForOne
|
tokenIn = swapParams.zeroForOne
|
||||||
? address(uint160(swapParams.poolKey.currency0.toId()))
|
? address(uint160(swapParams.poolKey.currency0.toId()))
|
||||||
@@ -96,8 +100,10 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
isExactInput = true;
|
isExactInput = true;
|
||||||
amount = swapParams.amountIn;
|
amount = swapParams.amountIn;
|
||||||
} else if (action == uint8(Actions.SWAP_EXACT_OUT_SINGLE)) {
|
} else if (action == uint8(Actions.SWAP_EXACT_OUT_SINGLE)) {
|
||||||
IV4Router.ExactOutputSingleParams memory swapParams =
|
IV4Router.ExactOutputSingleParams memory swapParams = abi.decode(
|
||||||
abi.decode(params[0], (IV4Router.ExactOutputSingleParams));
|
params[0],
|
||||||
|
(IV4Router.ExactOutputSingleParams)
|
||||||
|
);
|
||||||
|
|
||||||
tokenIn = swapParams.zeroForOne
|
tokenIn = swapParams.zeroForOne
|
||||||
? address(uint160(swapParams.poolKey.currency0.toId()))
|
? address(uint160(swapParams.poolKey.currency0.toId()))
|
||||||
@@ -108,18 +114,23 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
isExactInput = false;
|
isExactInput = false;
|
||||||
amount = swapParams.amountOut;
|
amount = swapParams.amountOut;
|
||||||
} else if (action == uint8(Actions.SWAP_EXACT_IN)) {
|
} else if (action == uint8(Actions.SWAP_EXACT_IN)) {
|
||||||
IV4Router.ExactInputParams memory swapParams =
|
IV4Router.ExactInputParams memory swapParams = abi.decode(
|
||||||
abi.decode(params[0], (IV4Router.ExactInputParams));
|
params[0],
|
||||||
|
(IV4Router.ExactInputParams)
|
||||||
|
);
|
||||||
|
|
||||||
tokenIn = address(uint160(swapParams.currencyIn.toId()));
|
tokenIn = address(uint160(swapParams.currencyIn.toId()));
|
||||||
PathKey memory lastPath =
|
PathKey memory lastPath = swapParams.path[
|
||||||
swapParams.path[swapParams.path.length - 1];
|
swapParams.path.length - 1
|
||||||
|
];
|
||||||
tokenOut = address(uint160(lastPath.intermediateCurrency.toId()));
|
tokenOut = address(uint160(lastPath.intermediateCurrency.toId()));
|
||||||
isExactInput = true;
|
isExactInput = true;
|
||||||
amount = swapParams.amountIn;
|
amount = swapParams.amountIn;
|
||||||
} else if (action == uint8(Actions.SWAP_EXACT_OUT)) {
|
} else if (action == uint8(Actions.SWAP_EXACT_OUT)) {
|
||||||
IV4Router.ExactOutputParams memory swapParams =
|
IV4Router.ExactOutputParams memory swapParams = abi.decode(
|
||||||
abi.decode(params[0], (IV4Router.ExactOutputParams));
|
params[0],
|
||||||
|
(IV4Router.ExactOutputParams)
|
||||||
|
);
|
||||||
|
|
||||||
PathKey memory firstPath = swapParams.path[0];
|
PathKey memory firstPath = swapParams.path[0];
|
||||||
tokenIn = address(uint160(firstPath.intermediateCurrency.toId()));
|
tokenIn = address(uint160(firstPath.intermediateCurrency.toId()));
|
||||||
@@ -129,16 +140,22 @@ contract UniswapV4Executor is IExecutor, V4Router {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _pay(Currency token, address payer, uint256 amount)
|
function _pay(
|
||||||
internal
|
Currency token,
|
||||||
override
|
address payer,
|
||||||
{
|
uint256 amount
|
||||||
|
) internal override {
|
||||||
IERC20(Currency.unwrap(token)).safeTransfer(
|
IERC20(Currency.unwrap(token)).safeTransfer(
|
||||||
address(poolManager), amount
|
address(poolManager),
|
||||||
|
amount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function msgSender() public view override returns (address) {
|
function msgSender() public view override returns (address) {
|
||||||
return address(this);
|
return address(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleCallback(
|
||||||
|
bytes calldata data
|
||||||
|
) external returns (bytes memory result) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
|
|
||||||
event CallbackVerifierSet(address indexed callbackVerifier);
|
event CallbackVerifierSet(address indexed callbackVerifier);
|
||||||
event Withdrawal(
|
event Withdrawal(
|
||||||
address indexed token, uint256 amount, address indexed receiver
|
address indexed token,
|
||||||
|
uint256 amount,
|
||||||
|
address indexed receiver
|
||||||
);
|
);
|
||||||
|
|
||||||
function testSetExecutorsValidRole() public {
|
function testSetExecutorsValidRole() public {
|
||||||
@@ -239,7 +241,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
deal(WETH_ADDR, tychoRouterAddr, amountIn);
|
deal(WETH_ADDR, tychoRouterAddr, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -276,7 +281,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
address(usv2Executor),
|
address(usv2Executor),
|
||||||
bytes4(0),
|
bytes4(0),
|
||||||
encodeUniswapV2Swap(
|
encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -315,7 +323,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
address(usv2Executor),
|
address(usv2Executor),
|
||||||
bytes4(0),
|
bytes4(0),
|
||||||
encodeUniswapV2Swap(
|
encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_WBTC_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_WBTC_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// WBTC -> USDC
|
// WBTC -> USDC
|
||||||
@@ -326,7 +337,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
address(usv2Executor),
|
address(usv2Executor),
|
||||||
bytes4(0),
|
bytes4(0),
|
||||||
encodeUniswapV2Swap(
|
encodeUniswapV2Swap(
|
||||||
WBTC_ADDR, USDC_WBTC_POOL, tychoRouterAddr, true
|
WBTC_ADDR,
|
||||||
|
USDC_WBTC_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// WETH -> DAI
|
// WETH -> DAI
|
||||||
@@ -337,7 +351,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
address(usv2Executor),
|
address(usv2Executor),
|
||||||
bytes4(0),
|
bytes4(0),
|
||||||
encodeUniswapV2Swap(
|
encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -373,7 +390,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -426,7 +446,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -485,7 +508,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -517,7 +543,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
assertEq(amountOut, expectedAmount);
|
assertEq(amountOut, expectedAmount);
|
||||||
uint256 daiBalance = IERC20(DAI_ADDR).balanceOf(ALICE);
|
uint256 daiBalance = IERC20(DAI_ADDR).balanceOf(ALICE);
|
||||||
assertEq(daiBalance, expectedAmount);
|
assertEq(daiBalance, expectedAmount);
|
||||||
assertEq(IERC20(DAI_ADDR).balanceOf(FEE_RECEIVER), 26598819248184436997);
|
assertEq(
|
||||||
|
IERC20(DAI_ADDR).balanceOf(FEE_RECEIVER),
|
||||||
|
26598819248184436997
|
||||||
|
);
|
||||||
|
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
}
|
}
|
||||||
@@ -530,19 +559,22 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
|
|
||||||
vm.startPrank(ALICE);
|
vm.startPrank(ALICE);
|
||||||
|
|
||||||
IAllowanceTransfer.PermitSingle memory emptyPermitSingle =
|
IAllowanceTransfer.PermitSingle
|
||||||
IAllowanceTransfer.PermitSingle({
|
memory emptyPermitSingle = IAllowanceTransfer.PermitSingle({
|
||||||
details: IAllowanceTransfer.PermitDetails({
|
details: IAllowanceTransfer.PermitDetails({
|
||||||
token: address(0),
|
token: address(0),
|
||||||
amount: 0,
|
amount: 0,
|
||||||
expiration: 0,
|
expiration: 0,
|
||||||
nonce: 0
|
nonce: 0
|
||||||
}),
|
}),
|
||||||
spender: address(0),
|
spender: address(0),
|
||||||
sigDeadline: 0
|
sigDeadline: 0
|
||||||
});
|
});
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -591,8 +623,12 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
bytes memory signature
|
bytes memory signature
|
||||||
) = handlePermit2Approval(DAI_ADDR, amountIn);
|
) = handlePermit2Approval(DAI_ADDR, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData =
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
encodeUniswapV2Swap(DAI_ADDR, WETH_DAI_POOL, tychoRouterAddr, true);
|
DAI_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
uint8(0),
|
uint8(0),
|
||||||
@@ -626,23 +662,23 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testUSV3Callback() public {
|
// function testUSV3Callback() public {
|
||||||
uint24 poolFee = 3000;
|
// uint24 poolFee = 3000;
|
||||||
uint256 amountOwed = 1000000000000000000;
|
// uint256 amountOwed = 1000000000000000000;
|
||||||
deal(WETH_ADDR, tychoRouterAddr, amountOwed);
|
// deal(WETH_ADDR, tychoRouterAddr, amountOwed);
|
||||||
uint256 initialPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
// uint256 initialPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||||
|
|
||||||
vm.startPrank(DAI_WETH_USV3);
|
// vm.startPrank(DAI_WETH_USV3);
|
||||||
tychoRouter.uniswapV3SwapCallback(
|
// tychoRouter.uniswapV3SwapCallback(
|
||||||
-2631245338449998525223,
|
// -2631245338449998525223,
|
||||||
int256(amountOwed),
|
// int256(amountOwed),
|
||||||
abi.encodePacked(WETH_ADDR, DAI_ADDR, poolFee)
|
// abi.encodePacked(WETH_ADDR, DAI_ADDR, poolFee)
|
||||||
);
|
// );
|
||||||
vm.stopPrank();
|
// vm.stopPrank();
|
||||||
|
|
||||||
uint256 finalPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
// uint256 finalPoolReserve = IERC20(WETH_ADDR).balanceOf(DAI_WETH_USV3);
|
||||||
assertEq(finalPoolReserve - initialPoolReserve, amountOwed);
|
// assertEq(finalPoolReserve - initialPoolReserve, amountOwed);
|
||||||
}
|
// }
|
||||||
|
|
||||||
function testSwapSingleUSV3() public {
|
function testSwapSingleUSV3() public {
|
||||||
// Trade 1 WETH for DAI with 1 swap on Uniswap V3
|
// Trade 1 WETH for DAI with 1 swap on Uniswap V3
|
||||||
@@ -654,7 +690,11 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
uint256 expAmountOut = 1205_128428842122129186; //Swap 1 WETH for 1205.12 DAI
|
uint256 expAmountOut = 1205_128428842122129186; //Swap 1 WETH for 1205.12 DAI
|
||||||
bool zeroForOne = false;
|
bool zeroForOne = false;
|
||||||
bytes memory protocolData = encodeUniswapV3Swap(
|
bytes memory protocolData = encodeUniswapV3Swap(
|
||||||
WETH_ADDR, DAI_ADDR, tychoRouterAddr, DAI_WETH_USV3, zeroForOne
|
WETH_ADDR,
|
||||||
|
DAI_ADDR,
|
||||||
|
tychoRouterAddr,
|
||||||
|
DAI_WETH_USV3,
|
||||||
|
zeroForOne
|
||||||
);
|
);
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
uint8(0),
|
uint8(0),
|
||||||
@@ -696,7 +736,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
// but manually replacing the executor address
|
// but manually replacing the executor address
|
||||||
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
||||||
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
||||||
(bool success,) = tychoRouterAddr.call(
|
(bool success, ) = tychoRouterAddr.call(
|
||||||
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d481bb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfbc3000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041f2740fde9662d8bc1f8fe8e8fc29447c1832d625f06f4a56ee5103ad555c12323af5d50eb840f73d17873383ae3b7573956d5df7b2bf76bddba768c2837894a51b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
|
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d481bb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfbc3000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041f2740fde9662d8bc1f8fe8e8fc29447c1832d625f06f4a56ee5103ad555c12323af5d50eb840f73d17873383ae3b7573956d5df7b2bf76bddba768c2837894a51b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -725,7 +765,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
// but manually replacing the executor address
|
// but manually replacing the executor address
|
||||||
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
||||||
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
||||||
(bool success,) = tychoRouterAddr.call{value: 1 ether}(
|
(bool success, ) = tychoRouterAddr.call{value: 1 ether}(
|
||||||
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d4806b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfa73000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041c36406a750c499ac7f79f7666650f0d4f20fc27bb49ab68121c0be6554cb5cab6caf90dc3aab2e21083a8fa46976521a1e9df41ce74be59abf03e0d3691541e91c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00020000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
|
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d4806b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfa73000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041c36406a750c499ac7f79f7666650f0d4f20fc27bb49ab68121c0be6554cb5cab6caf90dc3aab2e21083a8fa46976521a1e9df41ce74be59abf03e0d3691541e91c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00020000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950000000000"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -754,7 +794,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
// but manually replacing the executor address
|
// but manually replacing the executor address
|
||||||
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
||||||
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
||||||
(bool success,) = tychoRouterAddr.call(
|
(bool success, ) = tychoRouterAddr.call(
|
||||||
hex"4860f9ed0000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000000000000000000000000000000000000067d4809800000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfaa000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000004146411c70ec7fee0d5d260803cb220f5365792426c5d94f7a0a4d37abb05205752c5418b1fadd059570a71f0911814e546728e1f21876f2a1c6d38d34bd235fd61c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab6b175474e89094c44da98b954eedeac495271d0fa478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950100000000"
|
hex"4860f9ed0000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000a2a15d09519be000000000000000000000000000000000000000000000000000000000000067d4809800000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfaa000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000280000000000000000000000000000000000000000000000000000000000000004146411c70ec7fee0d5d260803cb220f5365792426c5d94f7a0a4d37abb05205752c5418b1fadd059570a71f0911814e546728e1f21876f2a1c6d38d34bd235fd61c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab6b175474e89094c44da98b954eedeac495271d0fa478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d013950100000000"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -785,7 +825,7 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
// but manually replacing the executor address
|
// but manually replacing the executor address
|
||||||
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
// `5c2f5a71f67c01775180adc06909288b4c329308` with the one in this test
|
||||||
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
// `5615deb798bb3e4dfa0139dfa1b3d433cc23b72f`
|
||||||
(bool success,) = tychoRouterAddr.call(
|
(bool success, ) = tychoRouterAddr.call(
|
||||||
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d4810d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfb15000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041ecaab75f0791c9683b001ea2f0e01a0a6aaf03e6e49c83e9c8a8e588a38e3be9230d962926628ffbf6a5370cda559ff0e7876a63ed38eebe33dbef5b5e2e46ef1b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000170005a00028000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d0139500005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2bb2b8038a1640196fbe3e38816f3e67cba72d9403ede3eca2a72b3aecc820e955b36f38437d0139500005a02030000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab6b175474e89094c44da98b954eedeac495271d0fae461ca67b15dc8dc81ce7615e0320da1a9ab8d53ede3eca2a72b3aecc820e955b36f38437d0139501005a01030000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab2260fac5e5542a773aa44fbcfedf7c193bc2c599004375dff511095cc5a197a54140a24efef3a4163ede3eca2a72b3aecc820e955b36f38437d013950100000000000000000000000000000000"
|
hex"4860f9ed0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000cd09f75e2bf2a4d11f3ab23f1389fcc1621c0cc2000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000067d4810d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003ede3eca2a72b3aecc820e955b36f38437d013950000000000000000000000000000000000000000000000000000000067acfb15000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000041ecaab75f0791c9683b001ea2f0e01a0a6aaf03e6e49c83e9c8a8e588a38e3be9230d962926628ffbf6a5370cda559ff0e7876a63ed38eebe33dbef5b5e2e46ef1b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000170005a00028000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb113ede3eca2a72b3aecc820e955b36f38437d0139500005a00010000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625abc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2bb2b8038a1640196fbe3e38816f3e67cba72d9403ede3eca2a72b3aecc820e955b36f38437d0139500005a02030000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab6b175474e89094c44da98b954eedeac495271d0fae461ca67b15dc8dc81ce7615e0320da1a9ab8d53ede3eca2a72b3aecc820e955b36f38437d0139501005a01030000005615deb798bb3e4dfa0139dfa1b3d433cc23b72fbd0625ab2260fac5e5542a773aa44fbcfedf7c193bc2c599004375dff511095cc5a197a54140a24efef3a4163ede3eca2a72b3aecc820e955b36f38437d013950100000000000000000000000000000000"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -815,7 +855,10 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
) = handlePermit2Approval(WETH_ADDR, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = encodeUniswapV2Swap(
|
bytes memory protocolData = encodeUniswapV2Swap(
|
||||||
WETH_ADDR, WETH_DAI_POOL, tychoRouterAddr, false
|
WETH_ADDR,
|
||||||
|
WETH_DAI_POOL,
|
||||||
|
tychoRouterAddr,
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes memory swap = encodeSwap(
|
bytes memory swap = encodeSwap(
|
||||||
@@ -832,7 +875,8 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
|
|
||||||
vm.expectRevert(
|
vm.expectRevert(
|
||||||
abi.encodeWithSelector(
|
abi.encodeWithSelector(
|
||||||
TychoRouter__AmountInNotFullySpent.selector, 400000000000000000
|
TychoRouter__AmountInNotFullySpent.selector,
|
||||||
|
400000000000000000
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -858,7 +902,12 @@ contract TychoRouterTest is TychoRouterTestSetup {
|
|||||||
deal(USDE_ADDR, tychoRouterAddr, amountIn);
|
deal(USDE_ADDR, tychoRouterAddr, amountIn);
|
||||||
|
|
||||||
bytes memory protocolData = UniswapV4Utils.encodeExactInputSingle(
|
bytes memory protocolData = UniswapV4Utils.encodeExactInputSingle(
|
||||||
USDE_ADDR, USDT_ADDR, 100, true, 1, uint128(amountIn)
|
USDE_ADDR,
|
||||||
|
USDT_ADDR,
|
||||||
|
100,
|
||||||
|
true,
|
||||||
|
1,
|
||||||
|
uint128(amountIn)
|
||||||
);
|
);
|
||||||
|
|
||||||
// add executor and selector for callback
|
// add executor and selector for callback
|
||||||
|
|||||||
@@ -15,9 +15,8 @@ contract TychoRouterExposed is TychoRouter {
|
|||||||
constructor(
|
constructor(
|
||||||
IPoolManager _poolManager,
|
IPoolManager _poolManager,
|
||||||
address _permit2,
|
address _permit2,
|
||||||
address weth,
|
address weth
|
||||||
address usv3Factory
|
) TychoRouter(_poolManager, _permit2, weth) {}
|
||||||
) TychoRouter(_poolManager, _permit2, weth, usv3Factory) {}
|
|
||||||
|
|
||||||
function wrapETH(uint256 amount) external payable {
|
function wrapETH(uint256 amount) external payable {
|
||||||
return _wrapETH(amount);
|
return _wrapETH(amount);
|
||||||
@@ -39,7 +38,8 @@ contract TychoRouterExposed is TychoRouter {
|
|||||||
contract TychoRouterTestSetup is Test, Constants {
|
contract TychoRouterTestSetup is Test, Constants {
|
||||||
TychoRouterExposed tychoRouter;
|
TychoRouterExposed tychoRouter;
|
||||||
address tychoRouterAddr;
|
address tychoRouterAddr;
|
||||||
address permit2Address = address(0x000000000022D473030F116dDEE9F6B43aC78BA3);
|
address permit2Address =
|
||||||
|
address(0x000000000022D473030F116dDEE9F6B43aC78BA3);
|
||||||
UniswapV2Executor public usv2Executor;
|
UniswapV2Executor public usv2Executor;
|
||||||
UniswapV3Executor public usv3Executor;
|
UniswapV3Executor public usv3Executor;
|
||||||
UniswapV4Executor public usv4Executor;
|
UniswapV4Executor public usv4Executor;
|
||||||
@@ -54,7 +54,9 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
address poolManagerAddress = 0x000000000004444c5dc75cB358380D2e3dE08A90;
|
||||||
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
IPoolManager poolManager = IPoolManager(poolManagerAddress);
|
||||||
tychoRouter = new TychoRouterExposed(
|
tychoRouter = new TychoRouterExposed(
|
||||||
poolManager, permit2Address, WETH_ADDR, factoryV3
|
poolManager,
|
||||||
|
permit2Address,
|
||||||
|
WETH_ADDR
|
||||||
);
|
);
|
||||||
tychoRouterAddr = address(tychoRouter);
|
tychoRouterAddr = address(tychoRouter);
|
||||||
tychoRouter.grantRole(keccak256("FUND_RESCUER_ROLE"), FUND_RESCUER);
|
tychoRouter.grantRole(keccak256("FUND_RESCUER_ROLE"), FUND_RESCUER);
|
||||||
@@ -62,13 +64,14 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
tychoRouter.grantRole(keccak256("PAUSER_ROLE"), PAUSER);
|
tychoRouter.grantRole(keccak256("PAUSER_ROLE"), PAUSER);
|
||||||
tychoRouter.grantRole(keccak256("UNPAUSER_ROLE"), UNPAUSER);
|
tychoRouter.grantRole(keccak256("UNPAUSER_ROLE"), UNPAUSER);
|
||||||
tychoRouter.grantRole(
|
tychoRouter.grantRole(
|
||||||
keccak256("EXECUTOR_SETTER_ROLE"), EXECUTOR_SETTER
|
keccak256("EXECUTOR_SETTER_ROLE"),
|
||||||
|
EXECUTOR_SETTER
|
||||||
);
|
);
|
||||||
deployDummyContract();
|
deployDummyContract();
|
||||||
vm.stopPrank();
|
vm.stopPrank();
|
||||||
|
|
||||||
usv2Executor = new UniswapV2Executor();
|
usv2Executor = new UniswapV2Executor();
|
||||||
usv3Executor = new UniswapV3Executor();
|
usv3Executor = new UniswapV3Executor(factoryV3);
|
||||||
usv4Executor = new UniswapV4Executor(poolManager);
|
usv4Executor = new UniswapV4Executor(poolManager);
|
||||||
vm.startPrank(EXECUTOR_SETTER);
|
vm.startPrank(EXECUTOR_SETTER);
|
||||||
address[] memory executors = new address[](3);
|
address[] memory executors = new address[](3);
|
||||||
@@ -110,22 +113,22 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
* @return permitSingle The `PermitSingle` struct containing the approval details.
|
* @return permitSingle The `PermitSingle` struct containing the approval details.
|
||||||
* @return signature The EIP-712 signature for the approval.
|
* @return signature The EIP-712 signature for the approval.
|
||||||
*/
|
*/
|
||||||
function handlePermit2Approval(address tokenIn, uint256 amount_in)
|
function handlePermit2Approval(
|
||||||
internal
|
address tokenIn,
|
||||||
returns (IAllowanceTransfer.PermitSingle memory, bytes memory)
|
uint256 amount_in
|
||||||
{
|
) internal returns (IAllowanceTransfer.PermitSingle memory, bytes memory) {
|
||||||
IERC20(tokenIn).approve(permit2Address, amount_in);
|
IERC20(tokenIn).approve(permit2Address, amount_in);
|
||||||
IAllowanceTransfer.PermitSingle memory permitSingle = IAllowanceTransfer
|
IAllowanceTransfer.PermitSingle memory permitSingle = IAllowanceTransfer
|
||||||
.PermitSingle({
|
.PermitSingle({
|
||||||
details: IAllowanceTransfer.PermitDetails({
|
details: IAllowanceTransfer.PermitDetails({
|
||||||
token: tokenIn,
|
token: tokenIn,
|
||||||
amount: uint160(amount_in),
|
amount: uint160(amount_in),
|
||||||
expiration: uint48(block.timestamp + 1 days),
|
expiration: uint48(block.timestamp + 1 days),
|
||||||
nonce: 0
|
nonce: 0
|
||||||
}),
|
}),
|
||||||
spender: tychoRouterAddr,
|
spender: tychoRouterAddr,
|
||||||
sigDeadline: block.timestamp + 1 days
|
sigDeadline: block.timestamp + 1 days
|
||||||
});
|
});
|
||||||
|
|
||||||
bytes memory signature = signPermit2(permitSingle, ALICE_PK);
|
bytes memory signature = signPermit2(permitSingle, ALICE_PK);
|
||||||
return (permitSingle, signature);
|
return (permitSingle, signature);
|
||||||
@@ -157,8 +160,9 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
permit2Address
|
permit2Address
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
bytes32 detailsHash =
|
bytes32 detailsHash = keccak256(
|
||||||
keccak256(abi.encode(_PERMIT_DETAILS_TYPEHASH, permit.details));
|
abi.encode(_PERMIT_DETAILS_TYPEHASH, permit.details)
|
||||||
|
);
|
||||||
bytes32 permitHash = keccak256(
|
bytes32 permitHash = keccak256(
|
||||||
abi.encode(
|
abi.encode(
|
||||||
_PERMIT_SINGLE_TYPEHASH,
|
_PERMIT_SINGLE_TYPEHASH,
|
||||||
@@ -168,18 +172,17 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes32 digest =
|
bytes32 digest = keccak256(
|
||||||
keccak256(abi.encodePacked("\x19\x01", domainSeparator, permitHash));
|
abi.encodePacked("\x19\x01", domainSeparator, permitHash)
|
||||||
|
);
|
||||||
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
|
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
|
||||||
|
|
||||||
return abi.encodePacked(r, s, v);
|
return abi.encodePacked(r, s, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pleEncode(bytes[] memory data)
|
function pleEncode(
|
||||||
public
|
bytes[] memory data
|
||||||
pure
|
) public pure returns (bytes memory encoded) {
|
||||||
returns (bytes memory encoded)
|
|
||||||
{
|
|
||||||
for (uint256 i = 0; i < data.length; i++) {
|
for (uint256 i = 0; i < data.length; i++) {
|
||||||
encoded = bytes.concat(
|
encoded = bytes.concat(
|
||||||
encoded,
|
encoded,
|
||||||
@@ -196,9 +199,15 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
bytes4 selector,
|
bytes4 selector,
|
||||||
bytes memory protocolData
|
bytes memory protocolData
|
||||||
) internal pure returns (bytes memory) {
|
) internal pure returns (bytes memory) {
|
||||||
return abi.encodePacked(
|
return
|
||||||
tokenInIndex, tokenOutIndex, split, executor, selector, protocolData
|
abi.encodePacked(
|
||||||
);
|
tokenInIndex,
|
||||||
|
tokenOutIndex,
|
||||||
|
split,
|
||||||
|
executor,
|
||||||
|
selector,
|
||||||
|
protocolData
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function encodeUniswapV2Swap(
|
function encodeUniswapV2Swap(
|
||||||
@@ -218,8 +227,14 @@ contract TychoRouterTestSetup is Test, Constants {
|
|||||||
bool zero2one
|
bool zero2one
|
||||||
) internal view returns (bytes memory) {
|
) internal view returns (bytes memory) {
|
||||||
IUniswapV3Pool pool = IUniswapV3Pool(target);
|
IUniswapV3Pool pool = IUniswapV3Pool(target);
|
||||||
return abi.encodePacked(
|
return
|
||||||
tokenIn, tokenOut, pool.fee(), receiver, target, zero2one
|
abi.encodePacked(
|
||||||
);
|
tokenIn,
|
||||||
|
tokenOut,
|
||||||
|
pool.fee(),
|
||||||
|
receiver,
|
||||||
|
target,
|
||||||
|
zero2one
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import {Test} from "../../lib/forge-std/src/Test.sol";
|
|||||||
import {Constants} from "../Constants.sol";
|
import {Constants} from "../Constants.sol";
|
||||||
|
|
||||||
contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
||||||
function decodeData(bytes calldata data)
|
constructor(address _factory) UniswapV3Executor(_factory) {}
|
||||||
|
|
||||||
|
function decodeData(
|
||||||
|
bytes calldata data
|
||||||
|
)
|
||||||
external
|
external
|
||||||
pure
|
pure
|
||||||
returns (
|
returns (
|
||||||
@@ -22,23 +26,30 @@ contract UniswapV3ExecutorExposed is UniswapV3Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract UniswapV3ExecutorTest is UniswapV3ExecutorExposed, Test, Constants {
|
contract UniswapV3ExecutorTest is Test, Constants {
|
||||||
using SafeERC20 for IERC20;
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
UniswapV3ExecutorExposed uniswapV3Exposed;
|
UniswapV3ExecutorExposed uniswapV3Exposed;
|
||||||
IERC20 WETH = IERC20(WETH_ADDR);
|
IERC20 WETH = IERC20(WETH_ADDR);
|
||||||
IERC20 DAI = IERC20(DAI_ADDR);
|
IERC20 DAI = IERC20(DAI_ADDR);
|
||||||
|
address factory = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
|
||||||
|
|
||||||
function setUp() public {
|
function setUp() public {
|
||||||
uint256 forkBlock = 17323404;
|
uint256 forkBlock = 17323404;
|
||||||
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
vm.createSelectFork(vm.rpcUrl("mainnet"), forkBlock);
|
||||||
uniswapV3Exposed = new UniswapV3ExecutorExposed();
|
|
||||||
|
uniswapV3Exposed = new UniswapV3ExecutorExposed(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDecodeParams() public view {
|
function testDecodeParams() public view {
|
||||||
uint24 expectedPoolFee = 500;
|
uint24 expectedPoolFee = 500;
|
||||||
bytes memory data = abi.encodePacked(
|
bytes memory data = abi.encodePacked(
|
||||||
WETH_ADDR, DAI_ADDR, expectedPoolFee, address(2), address(3), false
|
WETH_ADDR,
|
||||||
|
DAI_ADDR,
|
||||||
|
expectedPoolFee,
|
||||||
|
address(2),
|
||||||
|
address(3),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -59,8 +70,11 @@ contract UniswapV3ExecutorTest is UniswapV3ExecutorExposed, Test, Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testDecodeParamsInvalidDataLength() public {
|
function testDecodeParamsInvalidDataLength() public {
|
||||||
bytes memory invalidParams =
|
bytes memory invalidParams = abi.encodePacked(
|
||||||
abi.encodePacked(WETH_ADDR, address(2), address(3));
|
WETH_ADDR,
|
||||||
|
address(2),
|
||||||
|
address(3)
|
||||||
|
);
|
||||||
|
|
||||||
vm.expectRevert(UniswapV3Executor__InvalidDataLength.selector);
|
vm.expectRevert(UniswapV3Executor__InvalidDataLength.selector);
|
||||||
uniswapV3Exposed.decodeData(invalidParams);
|
uniswapV3Exposed.decodeData(invalidParams);
|
||||||
|
|||||||
Reference in New Issue
Block a user