Skip to content

Commit

Permalink
Fix snaps and MevRouter inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobrunoah committed Dec 20, 2024
1 parent f1284cc commit 4b3a19f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
75 changes: 75 additions & 0 deletions pkg/vault/contracts/MevRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

pragma solidity ^0.8.24;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IPermit2 } from "permit2/src/interfaces/IPermit2.sol";

import { IWETH } from "@balancer-labs/v3-interfaces/contracts/solidity-utils/misc/IWETH.sol";
import { IMevRouter } from "@balancer-labs/v3-interfaces/contracts/vault/IMevRouter.sol";
import { IMevTaxCollector } from "@balancer-labs/v3-interfaces/contracts/vault/IMevTaxCollector.sol";
import { IRouterSwap } from "@balancer-labs/v3-interfaces/contracts/vault/IMevRouter.sol";
import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol";
import { SwapKind } from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";

import { SingletonAuthentication } from "./SingletonAuthentication.sol";
import { RouterSwap } from "./RouterSwap.sol";
Expand Down Expand Up @@ -78,6 +81,78 @@ contract MevRouter is IMevRouter, SingletonAuthentication, RouterSwap {
priorityGasThreshold = newPriorityGasThreshold;
}

/// @inheritdoc IRouterSwap
function swapSingleTokenExactIn(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountIn,
uint256 minAmountOut,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable override(RouterSwap, IRouterSwap) saveSender(msg.sender) returns (uint256) {
chargeMevTax(pool);

return
abi.decode(
_vault.unlock(
abi.encodeCall(
RouterSwap.swapSingleTokenHook,
SwapSingleTokenHookParams({
sender: msg.sender,
kind: SwapKind.EXACT_IN,
pool: pool,
tokenIn: tokenIn,
tokenOut: tokenOut,
amountGiven: exactAmountIn,
limit: minAmountOut,
deadline: deadline,
wethIsEth: wethIsEth,
userData: userData
})
)
),
(uint256)
);
}

/// @inheritdoc IRouterSwap
function swapSingleTokenExactOut(
address pool,
IERC20 tokenIn,
IERC20 tokenOut,
uint256 exactAmountOut,
uint256 maxAmountIn,
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable override(RouterSwap, IRouterSwap) saveSender(msg.sender) returns (uint256) {
chargeMevTax(pool);

return
abi.decode(
_vault.unlock(
abi.encodeCall(
RouterSwap.swapSingleTokenHook,
SwapSingleTokenHookParams({
sender: msg.sender,
kind: SwapKind.EXACT_OUT,
pool: pool,
tokenIn: tokenIn,
tokenOut: tokenOut,
amountGiven: exactAmountOut,
limit: maxAmountIn,
deadline: deadline,
wethIsEth: wethIsEth,
userData: userData
})
)
),
(uint256)
);
}

function chargeMevTax(address pool) internal {
if (_isMevTaxEnabled == false) {
return;
Expand Down
4 changes: 2 additions & 2 deletions pkg/vault/contracts/RouterSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract RouterSwap is IRouterSwap, RouterCommon {
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable saveSender(msg.sender) returns (uint256) {
) external payable virtual saveSender(msg.sender) returns (uint256) {
return
abi.decode(
_vault.unlock(
Expand Down Expand Up @@ -70,7 +70,7 @@ contract RouterSwap is IRouterSwap, RouterCommon {
uint256 deadline,
bool wethIsEth,
bytes calldata userData
) external payable saveSender(msg.sender) returns (uint256) {
) external payable virtual saveSender(msg.sender) returns (uint256) {
return
abi.decode(
_vault.unlock(
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
508.5k
508.4k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
514.1k
514.0k
Original file line number Diff line number Diff line change
@@ -1 +1 @@
559.0k
558.9k

0 comments on commit 4b3a19f

Please sign in to comment.