feat: update solc and add V4Router into UniswapV4Executor
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -16,3 +16,6 @@
|
||||
[submodule "foundry/lib/v4-core"]
|
||||
path = foundry/lib/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
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
src = 'src'
|
||||
out = 'out'
|
||||
libs = ['lib']
|
||||
solc = "0.8.28"
|
||||
auto_detect_sol = true
|
||||
evm_version = 'cancun'
|
||||
optimizer = true
|
||||
optimizer_runs = 1000
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
interface ICallbackVerifier {
|
||||
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.
|
||||
*/
|
||||
function verifyCallback(address sender, bytes calldata data)
|
||||
external
|
||||
returns (
|
||||
uint256 amountOwed,
|
||||
address tokenOwed
|
||||
);
|
||||
function verifyCallback(
|
||||
address sender,
|
||||
bytes calldata data
|
||||
) external returns (uint256 amountOwed, address tokenOwed);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
@@ -20,10 +20,10 @@ interface IExecutor {
|
||||
* @return calculatedAmount The amount of the output token swapped, depending on
|
||||
* the givenAmount inputted.
|
||||
*/
|
||||
function swap(uint256 givenAmount, bytes calldata data)
|
||||
external
|
||||
payable
|
||||
returns (uint256 calculatedAmount);
|
||||
function swap(
|
||||
uint256 givenAmount,
|
||||
bytes calldata data
|
||||
) external payable returns (uint256 calculatedAmount);
|
||||
}
|
||||
|
||||
interface IExecutorErrors {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
|
||||
|
||||
@@ -1,58 +1,44 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
library LibSwap {
|
||||
/// Returns the InToken index into an array of tokens
|
||||
function tokenInIndex(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint8 res)
|
||||
{
|
||||
function tokenInIndex(
|
||||
bytes calldata swap
|
||||
) internal pure returns (uint8 res) {
|
||||
res = uint8(swap[0]);
|
||||
}
|
||||
|
||||
/// The OutToken index into an array of tokens
|
||||
function tokenOutIndex(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint8 res)
|
||||
{
|
||||
function tokenOutIndex(
|
||||
bytes calldata swap
|
||||
) internal pure returns (uint8 res) {
|
||||
res = uint8(swap[1]);
|
||||
}
|
||||
|
||||
/// The relative amount of token quantity routed into this swap
|
||||
function splitPercentage(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (uint24 res)
|
||||
{
|
||||
function splitPercentage(
|
||||
bytes calldata swap
|
||||
) internal pure returns (uint24 res) {
|
||||
res = uint24(bytes3(swap[2:5]));
|
||||
}
|
||||
|
||||
/// The address of the executor contract
|
||||
function executor(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (address res)
|
||||
{
|
||||
function executor(bytes calldata swap) internal pure returns (address res) {
|
||||
res = address(uint160(bytes20(swap[5:25])));
|
||||
}
|
||||
|
||||
/// The selector to be used of the executor contract
|
||||
function executorSelector(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (bytes4 res)
|
||||
{
|
||||
function executorSelector(
|
||||
bytes calldata swap
|
||||
) internal pure returns (bytes4 res) {
|
||||
res = bytes4(swap[25:29]);
|
||||
}
|
||||
|
||||
/// Remaining bytes are interpreted as protocol data
|
||||
function protocolData(bytes calldata swap)
|
||||
internal
|
||||
pure
|
||||
returns (bytes calldata res)
|
||||
{
|
||||
function protocolData(
|
||||
bytes calldata swap
|
||||
) internal pure returns (bytes calldata res) {
|
||||
res = swap[29:];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
function next(bytes calldata encoded)
|
||||
internal
|
||||
pure
|
||||
returns (bytes calldata elem, bytes calldata res)
|
||||
{
|
||||
function next(
|
||||
bytes calldata encoded
|
||||
) internal pure returns (bytes calldata elem, bytes calldata res) {
|
||||
assembly {
|
||||
switch iszero(encoded.length)
|
||||
case 1 {
|
||||
@@ -46,7 +44,11 @@ library LibPrefixLengthEncodedByteArray {
|
||||
assembly {
|
||||
let offset := encoded.offset
|
||||
let end := add(encoded.offset, encoded.length)
|
||||
for {} lt(offset, end) {} {
|
||||
for {
|
||||
|
||||
} lt(offset, end) {
|
||||
|
||||
} {
|
||||
offset := add(offset, add(shr(240, calldataload(offset)), 2))
|
||||
s := add(s, 1)
|
||||
}
|
||||
@@ -56,11 +58,9 @@ library LibPrefixLengthEncodedByteArray {
|
||||
/**
|
||||
* @dev Cast an encoded array into a Solidity array.
|
||||
*/
|
||||
function toArray(bytes calldata encoded)
|
||||
internal
|
||||
pure
|
||||
returns (bytes[] memory arr)
|
||||
{
|
||||
function toArray(
|
||||
bytes calldata encoded
|
||||
) internal pure returns (bytes[] memory arr) {
|
||||
bytes calldata elem;
|
||||
uint256 idx = 0;
|
||||
arr = new bytes[](LibPrefixLengthEncodedByteArray.size(encoded));
|
||||
|
||||
1
foundry/lib/v4-periphery
Submodule
1
foundry/lib/v4-periphery
Submodule
Submodule foundry/lib/v4-periphery added at cf451c4f55
@@ -6,4 +6,5 @@
|
||||
@balancer-labs/v2-interfaces=lib/balancer-v2-monorepo/pkg/interfaces
|
||||
@uniswap/v3-updated/=lib/v3-updated/
|
||||
@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/
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/ICallbackVerifier.sol";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/IExecutor.sol";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "../lib/IWETH.sol";
|
||||
import "../lib/bytes/LibPrefixLengthEncodedByteArray.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/IExecutor.sol";
|
||||
import {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/IExecutor.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/IExecutor.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@interfaces/IExecutor.sol";
|
||||
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import {IPoolManager} from "@uniswap/v4-core/interfaces/IPoolManager.sol";
|
||||
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/types/Currency.sol";
|
||||
import {PoolKey} from "@uniswap/v4-core/types/PoolKey.sol";
|
||||
import {BalanceDelta} from "@uniswap/v4-core/types/BalanceDelta.sol";
|
||||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
|
||||
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
|
||||
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
|
||||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
|
||||
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
|
||||
import {IHooks} from "@uniswap/v4-core/interfaces/IHooks.sol";
|
||||
import {IUnlockCallback} from "@uniswap/v4-core/interfaces/callback/IUnlockCallback.sol";
|
||||
import {TransientStateLibrary} from "@uniswap/v4-core/libraries/TransientStateLibrary.sol";
|
||||
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
|
||||
import {IUnlockCallback} from "@uniswap/v4-core/src/interfaces/callback/IUnlockCallback.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__SwapFailed();
|
||||
error UniswapV4Executor__InsufficientOutput();
|
||||
error UniswapV4Executor__ManagerMismatch();
|
||||
|
||||
contract UniswapV4Executor is IExecutor {
|
||||
contract UniswapV4Executor is IExecutor, V4Router {
|
||||
using SafeERC20 for IERC20;
|
||||
using CurrencyLibrary for Currency;
|
||||
using SafeCast for int128;
|
||||
@@ -36,6 +37,8 @@ contract UniswapV4Executor is IExecutor {
|
||||
address receiver;
|
||||
}
|
||||
|
||||
constructor(IPoolManager _poolManager) V4Router(_poolManager) {}
|
||||
|
||||
function swap(
|
||||
uint256 amountIn,
|
||||
bytes calldata data
|
||||
@@ -111,4 +114,14 @@ contract UniswapV4Executor is IExecutor {
|
||||
target = address(bytes20(data[63:83]));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@src/CallbackVerificationDispatcher.sol";
|
||||
import "./TychoRouterTestSetup.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@src/ExecutionDispatcher.sol";
|
||||
import "./TychoRouterTestSetup.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import {Test} from "forge-std/Test.sol";
|
||||
import {LibPrefixLengthEncodedByteArray} from
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "forge-std/Test.sol";
|
||||
import "../lib/LibSwap.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import {TychoRouter} from "@src/TychoRouter.sol";
|
||||
import "./TychoRouterTestSetup.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.13;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "../src/executors/UniswapV2Executor.sol";
|
||||
import "./Constants.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@src/executors/BalancerV2Executor.sol";
|
||||
import {Test} from "../../lib/forge-std/src/Test.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@src/executors/UniswapV2Executor.sol";
|
||||
import {Test} from "../../lib/forge-std/src/Test.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import "@src/executors/UniswapV3Executor.sol";
|
||||
import {Test} from "../../lib/forge-std/src/Test.sol";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: Unlicense
|
||||
pragma solidity ^0.8.28;
|
||||
pragma solidity ^0.8.26;
|
||||
|
||||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user