Skip to content

Commit

Permalink
Creating MEV Router
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobrunoah committed Dec 19, 2024
1 parent 2cb4ac9 commit f1284cc
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 317 deletions.
34 changes: 34 additions & 0 deletions pkg/interfaces/contracts/vault/IMevRouter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.24;

import { IRouterSwap } from "./IRouterSwap.sol";
import { IMevTaxCollector } from "./IMevTaxCollector.sol";

interface IMevRouter is IRouterSwap {
struct MevRouterParams {
IMevTaxCollector mevTaxCollector;
uint256 mevTaxMultiplier;
uint256 priorityGasThreshold;
}

event MevTaxCharged(address pool, uint256 mevTax);

function isMevTaxEnabled() external view returns (bool isMevTaxEnabled);

function enableMevTax() external;

function disableMevTax() external;

function getMevTaxCollector() external view returns (IMevTaxCollector mevTaxCollector);

function setMevTaxCollector(IMevTaxCollector mevTaxCollector) external;

function getMevTaxMultiplier() external view returns (uint256 mevTaxMultiplier);

function setMevTaxMultiplier(uint256 mevTaxMultiplier) external;

function getPriorityGasThreshold() external view returns (uint256 priorityGasThreshold);

function setPriorityGasThreshold(uint256 priorityGasThreshold) external;
}
7 changes: 7 additions & 0 deletions pkg/interfaces/contracts/vault/IMevTaxCollector.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.24;

interface IMevTaxCollector {
function chargeMevTax(address pool) external payable;
}
117 changes: 2 additions & 115 deletions pkg/interfaces/contracts/vault/IRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ pragma solidity ^0.8.24;
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { IRouterSwap } from "./IRouterSwap.sol";
import { AddLiquidityKind, RemoveLiquidityKind, SwapKind } from "./VaultTypes.sol";

/// @notice User-friendly interface to basic Vault operations: swap, add/remove liquidity, and associated queries.
interface IRouter {
interface IRouter is IRouterSwap {
/***************************************************************************
Pool Initialization
***************************************************************************/
Expand Down Expand Up @@ -235,82 +236,6 @@ interface IRouter {
uint256[] memory minAmountsOut
) external payable returns (uint256[] memory amountsOut);

/***************************************************************************
Swaps
***************************************************************************/

/**
* @notice Data for the swap hook.
* @param sender Account initiating the swap operation
* @param kind Type of swap (exact in or exact out)
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param amountGiven Amount given based on kind of the swap (e.g., tokenIn for exact in)
* @param limit Maximum or minimum amount based on the kind of swap (e.g., maxAmountIn for exact out)
* @param deadline Deadline for the swap, after which it will revert
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data sent with the swap request
*/
struct SwapSingleTokenHookParams {
address sender;
SwapKind kind;
address pool;
IERC20 tokenIn;
IERC20 tokenOut;
uint256 amountGiven;
uint256 limit;
uint256 deadline;
bool wethIsEth;
bytes userData;
}

/**
* @notice Executes a swap operation specifying an exact input token amount.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountIn Exact amounts of input tokens to send
* @param minAmountOut Minimum amount of tokens to be received
* @param deadline Deadline for the swap, after which it will revert
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data sent with the swap request
* @return amountOut Calculated amount of output tokens to be received in exchange for the given input tokens
*/
function swapSingleTokenExactIn(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountIn,
uint256 minAmountOut,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable returns (uint256 amountOut);

/**
* @notice Executes a swap operation specifying an exact output token amount.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountOut Exact amounts of input tokens to receive
* @param maxAmountIn Maximum amount of tokens to be sent
* @param deadline Deadline for the swap, after which it will revert
* @param userData Additional (optional) data sent with the swap request
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @return amountIn Calculated amount of input tokens to be sent in exchange for the requested output tokens
*/
function swapSingleTokenExactOut(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountOut,
uint256 maxAmountIn,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable returns (uint256 amountIn);

/***************************************************************************
Queries
***************************************************************************/
Expand Down Expand Up @@ -459,42 +384,4 @@ interface IRouter {
address pool,
uint256 exactBptAmountIn
) external returns (uint256[] memory amountsOut);

/**
* @notice Queries a swap operation specifying an exact input token amount without actually executing it.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountIn Exact amounts of input tokens to send
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data sent with the query request
* @return amountOut Calculated amount of output tokens to be received in exchange for the given input tokens
*/
function querySwapSingleTokenExactIn(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountIn,
address sender,
bytes calldata userData
) external returns (uint256 amountOut);

/**
* @notice Queries a swap operation specifying an exact output token amount without actually executing it.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountOut Exact amounts of input tokens to receive
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data sent with the query request
* @return amountIn Calculated amount of input tokens to be sent in exchange for the requested output tokens
*/
function querySwapSingleTokenExactOut(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountOut,
address sender,
bytes calldata userData
) external returns (uint256 amountIn);
}
127 changes: 127 additions & 0 deletions pkg/interfaces/contracts/vault/IRouterSwap.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.24;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { SwapKind } from "./VaultTypes.sol";

interface IRouterSwap {
/***************************************************************************
Swaps
***************************************************************************/

/**
* @notice Data for the swap hook.
* @param sender Account initiating the swap operation
* @param kind Type of swap (exact in or exact out)
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param amountGiven Amount given based on kind of the swap (e.g., tokenIn for exact in)
* @param limit Maximum or minimum amount based on the kind of swap (e.g., maxAmountIn for exact out)
* @param deadline Deadline for the swap, after which it will revert
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data sent with the swap request
*/
struct SwapSingleTokenHookParams {
address sender;
SwapKind kind;
address pool;
IERC20 tokenIn;
IERC20 tokenOut;
uint256 amountGiven;
uint256 limit;
uint256 deadline;
bool wethIsEth;
bytes userData;
}

/**
* @notice Executes a swap operation specifying an exact input token amount.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountIn Exact amounts of input tokens to send
* @param minAmountOut Minimum amount of tokens to be received
* @param deadline Deadline for the swap, after which it will revert
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @param userData Additional (optional) data sent with the swap request
* @return amountOut Calculated amount of output tokens to be received in exchange for the given input tokens
*/
function swapSingleTokenExactIn(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountIn,
uint256 minAmountOut,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable returns (uint256 amountOut);

/**
* @notice Executes a swap operation specifying an exact output token amount.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountOut Exact amounts of input tokens to receive
* @param maxAmountIn Maximum amount of tokens to be sent
* @param deadline Deadline for the swap, after which it will revert
* @param userData Additional (optional) data sent with the swap request
* @param wethIsEth If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
* @return amountIn Calculated amount of input tokens to be sent in exchange for the requested output tokens
*/
function swapSingleTokenExactOut(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountOut,
uint256 maxAmountIn,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable returns (uint256 amountIn);

/***************************************************************************
Queries
***************************************************************************/

/**
* @notice Queries a swap operation specifying an exact input token amount without actually executing it.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountIn Exact amounts of input tokens to send
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data sent with the query request
* @return amountOut Calculated amount of output tokens to be received in exchange for the given input tokens
*/
function querySwapSingleTokenExactIn(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountIn,
address sender,
bytes calldata userData
) external returns (uint256 amountOut);

/**
* @notice Queries a swap operation specifying an exact output token amount without actually executing it.
* @param pool Address of the liquidity pool
* @param tokenIn Token to be swapped from
* @param tokenOut Token to be swapped to
* @param exactAmountOut Exact amounts of input tokens to receive
* @param sender The sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
* @param userData Additional (optional) data sent with the query request
* @return amountIn Calculated amount of input tokens to be sent in exchange for the requested output tokens
*/
function querySwapSingleTokenExactOut(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountOut,
address sender,
bytes calldata userData
) external returns (uint256 amountIn);
}
Loading

0 comments on commit f1284cc

Please sign in to comment.