feat: update solc and add V4Router into UniswapV4Executor

This commit is contained in:
royvardhan
2025-02-10 20:21:59 +05:30
parent 24d4e762a2
commit bdd3daffba
27 changed files with 86 additions and 84 deletions

3
.gitmodules vendored
View File

@@ -16,3 +16,6 @@
[submodule "foundry/lib/v4-core"] [submodule "foundry/lib/v4-core"]
path = foundry/lib/v4-core path = foundry/lib/v4-core
url = https://github.com/Uniswap/v4-core url = https://github.com/Uniswap/v4-core
[submodule "foundry/lib/universal-router"]
path = foundry/lib/universal-router
url = https://github.com/uniswap/universal-router

View File

@@ -2,7 +2,7 @@
src = 'src' src = 'src'
out = 'out' out = 'out'
libs = ['lib'] libs = ['lib']
solc = "0.8.28" auto_detect_sol = true
evm_version = 'cancun' evm_version = 'cancun'
optimizer = true optimizer = true
optimizer_runs = 1000 optimizer_runs = 1000

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
interface ICallbackVerifier { interface ICallbackVerifier {
error UnauthorizedCaller(string exchange, address sender); error UnauthorizedCaller(string exchange, address sender);
@@ -7,10 +7,8 @@ interface ICallbackVerifier {
/** /**
* @dev This method should revert if the sender is not a verified sender of the exchange. * @dev This method should revert if the sender is not a verified sender of the exchange.
*/ */
function verifyCallback(address sender, bytes calldata data) function verifyCallback(
external address sender,
returns ( bytes calldata data
uint256 amountOwed, ) external returns (uint256 amountOwed, address tokenOwed);
address tokenOwed
);
} }

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
@@ -20,10 +20,10 @@ interface IExecutor {
* @return calculatedAmount The amount of the output token swapped, depending on * @return calculatedAmount The amount of the output token swapped, depending on
* the givenAmount inputted. * the givenAmount inputted.
*/ */
function swap(uint256 givenAmount, bytes calldata data) function swap(
external uint256 givenAmount,
payable bytes calldata data
returns (uint256 calculatedAmount); ) external payable returns (uint256 calculatedAmount);
} }
interface IExecutorErrors { interface IExecutorErrors {

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

View File

@@ -1,58 +1,44 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
library LibSwap { library LibSwap {
/// Returns the InToken index into an array of tokens /// Returns the InToken index into an array of tokens
function tokenInIndex(bytes calldata swap) function tokenInIndex(
internal bytes calldata swap
pure ) internal pure returns (uint8 res) {
returns (uint8 res)
{
res = uint8(swap[0]); res = uint8(swap[0]);
} }
/// The OutToken index into an array of tokens /// The OutToken index into an array of tokens
function tokenOutIndex(bytes calldata swap) function tokenOutIndex(
internal bytes calldata swap
pure ) internal pure returns (uint8 res) {
returns (uint8 res)
{
res = uint8(swap[1]); res = uint8(swap[1]);
} }
/// The relative amount of token quantity routed into this swap /// The relative amount of token quantity routed into this swap
function splitPercentage(bytes calldata swap) function splitPercentage(
internal bytes calldata swap
pure ) internal pure returns (uint24 res) {
returns (uint24 res)
{
res = uint24(bytes3(swap[2:5])); res = uint24(bytes3(swap[2:5]));
} }
/// The address of the executor contract /// The address of the executor contract
function executor(bytes calldata swap) function executor(bytes calldata swap) internal pure returns (address res) {
internal
pure
returns (address res)
{
res = address(uint160(bytes20(swap[5:25]))); res = address(uint160(bytes20(swap[5:25])));
} }
/// The selector to be used of the executor contract /// The selector to be used of the executor contract
function executorSelector(bytes calldata swap) function executorSelector(
internal bytes calldata swap
pure ) internal pure returns (bytes4 res) {
returns (bytes4 res)
{
res = bytes4(swap[25:29]); res = bytes4(swap[25:29]);
} }
/// Remaining bytes are interpreted as protocol data /// Remaining bytes are interpreted as protocol data
function protocolData(bytes calldata swap) function protocolData(
internal bytes calldata swap
pure ) internal pure returns (bytes calldata res) {
returns (bytes calldata res)
{
res = swap[29:]; res = swap[29:];
} }
} }

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
/** /**
* @title Propellerheads PrefixLengthEncoded Byte Array Library * @title Propellerheads PrefixLengthEncoded Byte Array Library
@@ -16,11 +16,9 @@ library LibPrefixLengthEncodedByteArray {
/** /**
* @dev Pop the first element of an array and returns it with the remaining data. * @dev Pop the first element of an array and returns it with the remaining data.
*/ */
function next(bytes calldata encoded) function next(
internal bytes calldata encoded
pure ) internal pure returns (bytes calldata elem, bytes calldata res) {
returns (bytes calldata elem, bytes calldata res)
{
assembly { assembly {
switch iszero(encoded.length) switch iszero(encoded.length)
case 1 { case 1 {
@@ -46,7 +44,11 @@ library LibPrefixLengthEncodedByteArray {
assembly { assembly {
let offset := encoded.offset let offset := encoded.offset
let end := add(encoded.offset, encoded.length) let end := add(encoded.offset, encoded.length)
for {} lt(offset, end) {} { for {
} lt(offset, end) {
} {
offset := add(offset, add(shr(240, calldataload(offset)), 2)) offset := add(offset, add(shr(240, calldataload(offset)), 2))
s := add(s, 1) s := add(s, 1)
} }
@@ -56,11 +58,9 @@ library LibPrefixLengthEncodedByteArray {
/** /**
* @dev Cast an encoded array into a Solidity array. * @dev Cast an encoded array into a Solidity array.
*/ */
function toArray(bytes calldata encoded) function toArray(
internal bytes calldata encoded
pure ) internal pure returns (bytes[] memory arr) {
returns (bytes[] memory arr)
{
bytes calldata elem; bytes calldata elem;
uint256 idx = 0; uint256 idx = 0;
arr = new bytes[](LibPrefixLengthEncodedByteArray.size(encoded)); arr = new bytes[](LibPrefixLengthEncodedByteArray.size(encoded));

Submodule foundry/lib/v4-periphery added at cf451c4f55

View File

@@ -6,4 +6,5 @@
@balancer-labs/v2-interfaces=lib/balancer-v2-monorepo/pkg/interfaces @balancer-labs/v2-interfaces=lib/balancer-v2-monorepo/pkg/interfaces
@uniswap/v3-updated/=lib/v3-updated/ @uniswap/v3-updated/=lib/v3-updated/
@uniswap/v3-core/=lib/v3-core/ @uniswap/v3-core/=lib/v3-core/
@uniswap/v4-core/=lib/v4-core/src/ @uniswap/v4-core/=lib/v4-core/
@uniswap/v4-periphery/=lib/v4-periphery/

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/ICallbackVerifier.sol"; import "@interfaces/ICallbackVerifier.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol"; import "@interfaces/IExecutor.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "../lib/IWETH.sol"; import "../lib/IWETH.sol";
import "../lib/bytes/LibPrefixLengthEncodedByteArray.sol"; import "../lib/bytes/LibPrefixLengthEncodedByteArray.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol"; import "@interfaces/IExecutor.sol";
import { import {

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol"; import "@interfaces/IExecutor.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol"; import "@interfaces/IExecutor.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

View File

@@ -1,23 +1,24 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol"; import "@interfaces/IExecutor.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IPoolManager} from "@uniswap/v4-core/interfaces/IPoolManager.sol"; import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/types/Currency.sol"; import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-core/types/PoolKey.sol"; import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {BalanceDelta} from "@uniswap/v4-core/types/BalanceDelta.sol"; import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {IHooks} from "@uniswap/v4-core/interfaces/IHooks.sol"; import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {IUnlockCallback} from "@uniswap/v4-core/interfaces/callback/IUnlockCallback.sol"; import {IUnlockCallback} from "@uniswap/v4-core/src/interfaces/callback/IUnlockCallback.sol";
import {TransientStateLibrary} from "@uniswap/v4-core/libraries/TransientStateLibrary.sol"; import {TransientStateLibrary} from "@uniswap/v4-core/src/libraries/TransientStateLibrary.sol";
import {V4Router} from "@uniswap/v4-periphery/src/V4Router.sol";
error UniswapV4Executor__InvalidDataLength(); error UniswapV4Executor__InvalidDataLength();
error UniswapV4Executor__SwapFailed(); error UniswapV4Executor__SwapFailed();
error UniswapV4Executor__InsufficientOutput(); error UniswapV4Executor__InsufficientOutput();
error UniswapV4Executor__ManagerMismatch(); error UniswapV4Executor__ManagerMismatch();
contract UniswapV4Executor is IExecutor { contract UniswapV4Executor is IExecutor, V4Router {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
using CurrencyLibrary for Currency; using CurrencyLibrary for Currency;
using SafeCast for int128; using SafeCast for int128;
@@ -36,6 +37,8 @@ contract UniswapV4Executor is IExecutor {
address receiver; address receiver;
} }
constructor(IPoolManager _poolManager) V4Router(_poolManager) {}
function swap( function swap(
uint256 amountIn, uint256 amountIn,
bytes calldata data bytes calldata data
@@ -111,4 +114,14 @@ contract UniswapV4Executor is IExecutor {
target = address(bytes20(data[63:83])); target = address(bytes20(data[63:83]));
zeroForOne = uint8(data[83]) > 0; zeroForOne = uint8(data[83]) > 0;
} }
function _pay(
Currency token,
address payer,
uint256 amount
) internal override {}
function msgSender() public view override returns (address) {
return msg.sender;
}
} }

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@src/CallbackVerificationDispatcher.sol"; import "@src/CallbackVerificationDispatcher.sol";
import "./TychoRouterTestSetup.sol"; import "./TychoRouterTestSetup.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "forge-std/Test.sol"; import "forge-std/Test.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@src/ExecutionDispatcher.sol"; import "@src/ExecutionDispatcher.sol";
import "./TychoRouterTestSetup.sol"; import "./TychoRouterTestSetup.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.26;
import {Test} from "forge-std/Test.sol"; import {Test} from "forge-std/Test.sol";
import {LibPrefixLengthEncodedByteArray} from import {LibPrefixLengthEncodedByteArray} from

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "forge-std/Test.sol"; import "forge-std/Test.sol";
import "../lib/LibSwap.sol"; import "../lib/LibSwap.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import {TychoRouter} from "@src/TychoRouter.sol"; import {TychoRouter} from "@src/TychoRouter.sol";
import "./TychoRouterTestSetup.sol"; import "./TychoRouterTestSetup.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13; pragma solidity ^0.8.26;
import "../src/executors/UniswapV2Executor.sol"; import "../src/executors/UniswapV2Executor.sol";
import "./Constants.sol"; import "./Constants.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@src/executors/BalancerV2Executor.sol"; import "@src/executors/BalancerV2Executor.sol";
import {Test} from "../../lib/forge-std/src/Test.sol"; import {Test} from "../../lib/forge-std/src/Test.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@src/executors/UniswapV2Executor.sol"; import "@src/executors/UniswapV2Executor.sol";
import {Test} from "../../lib/forge-std/src/Test.sol"; import {Test} from "../../lib/forge-std/src/Test.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import "@src/executors/UniswapV3Executor.sol"; import "@src/executors/UniswapV3Executor.sol";
import {Test} from "../../lib/forge-std/src/Test.sol"; import {Test} from "../../lib/forge-std/src/Test.sol";

View File

@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Unlicense // SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.28; pragma solidity ^0.8.26;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";