Skip to content

Commit

Permalink
break out structs into interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz committed Sep 5, 2023
1 parent 9ebc9d5 commit 54a48e5
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 103 deletions.
63 changes: 2 additions & 61 deletions contracts/Routing.sol → contracts/V4Router.sol
Original file line number Diff line number Diff line change
@@ -1,81 +1,22 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "forge-std/console.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol";
import {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";
import {IV4Router} from "./interfaces/IV4Router.sol";

/// @title UniswapV4Routing
/// @notice Abstract contract that contains all internal logic needed for routing through Uniswap V4 pools
abstract contract Routing {
abstract contract V4Router is IV4Router {
using CurrencyLibrary for Currency;

IPoolManager immutable poolManager;

error NotPoolManager();
error InvalidSwapType();
error TooLittleReceived();
error TooMuchRequested();

struct SwapInfo {
SwapType swapType;
address msgSender;
bytes params;
}

struct PathKey {
Currency tradeCurrency;
uint24 fee;
int24 tickSpacing;
IHooks hooks;
}

struct ExactInputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountIn;
uint128 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}

struct ExactInputParams {
Currency currencyIn;
PathKey[] path;
address recipient;
uint128 amountIn;
uint128 amountOutMinimum;
}

struct ExactOutputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountOut;
uint128 amountInMaximum;
uint160 sqrtPriceLimitX96;
}

struct ExactOutputParams {
Currency currencyOut;
PathKey[] path;
address recipient;
uint128 amountOut;
uint128 amountInMaximum;
}

enum SwapType {
ExactInput,
ExactInputSingle,
ExactOutput,
ExactOutputSingle
}

/// @dev Only the pool manager may call this function
modifier poolManagerOnly() {
if (msg.sender != address(poolManager)) revert NotPoolManager();
Expand Down
76 changes: 76 additions & 0 deletions contracts/interfaces/IV4Router.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "forge-std/console.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/contracts/types/Currency.sol";
import {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";

/// @title UniswapV4Routing
/// @notice Abstract contract that contains all internal logic needed for routing through Uniswap V4 pools
interface IV4Router {
error NotPoolManager();
error InvalidSwapType();
error TooLittleReceived();
error TooMuchRequested();

struct SwapInfo {
SwapType swapType;
address msgSender;
bytes params;
}

struct PathKey {
Currency tradeCurrency;
uint24 fee;
int24 tickSpacing;
IHooks hooks;
}

struct ExactInputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountIn;
uint128 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}

struct ExactInputParams {
Currency currencyIn;
PathKey[] path;
address recipient;
uint128 amountIn;
uint128 amountOutMinimum;
}

struct ExactOutputSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 amountOut;
uint128 amountInMaximum;
uint160 sqrtPriceLimitX96;
}

struct ExactOutputParams {
Currency currencyOut;
PathKey[] path;
address recipient;
uint128 amountOut;
uint128 amountInMaximum;
}

enum SwapType {
ExactInput,
ExactInputSingle,
ExactOutput,
ExactOutputSingle
}

function lockAcquired(bytes calldata encodedSwapInfo) external returns (bytes memory);
}
Loading

0 comments on commit 54a48e5

Please sign in to comment.