Skip to content
Verified contractExactMIT

FeeWrapper

Address0x8042f94de684957f7ddc1f54bb0d6ab3cec23aee
Balance

0 ETH

 

Transactions

490

 

Compiler

solc 0.8.34

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.34+commit.80d5c536
Language
solidity
Optimization
Yes, 200 runs
EVM version
osaka
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,814,825
Creation transaction
0x75e96a2b67…b29d44c125

Ace/feeWrapper2.1.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC20 {
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function approve(address spender, uint256 value) external returns (bool);
}

interface IUniswapV2Router {
    function swapExactETHForTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable returns (uint[] memory amounts);

    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;

    function swapExactTokensForETH(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}


interface IUniswapV3Router {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    function exactInputSingle(ExactInputSingleParams calldata params)
        external
        payable
        returns (uint256 amountOut);
}

interface IUniswapV3Factory {
    function getPool(address tokenA, address tokenB, uint24 fee) external view returns (address);
}


interface IWrappedNative {
    function withdraw(uint256) external;
}

contract FeeWrapper {
    address public owner;
    address public overheadVault;

    address public v2Router;
    address public v3Router;
    address public v3Factory;
    address public wrappedNative;

    uint256 public overheadBps;
    uint256 public minOverheadNative;

    bool private locked;

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    modifier nonReentrant() {
        require(!locked, "REENTRANT");
        locked = true;
        _;
        locked = false;
    }

    constructor(
        address _owner,
        address _overheadVault,
        address _v2Router,
        address _v3Router,
        address _v3Factory,
        address _wrappedNative,
        uint256 _overheadBps,
        uint256 _minOverheadNative
    ) {
        require(_owner != address(0), "Bad owner");
        require(_overheadVault != address(0), "Bad vault");
        require(_v2Router != address(0), "Bad v2");
        require(_v3Router != address(0), "Bad v3");
        require(_v3Factory != address(0), "Bad factory");
        require(_wrappedNative != address(0), "Bad wrapped");
        require(_overheadBps <= 10_000, "Bad bps");

        owner = _owner;
        overheadVault = _overheadVault;
        v2Router = _v2Router;
        v3Router = _v3Router;
        v3Factory = _v3Factory;
        wrappedNative = _wrappedNative;
        overheadBps = _overheadBps;
        minOverheadNative = _minOverheadNative;
    }

    receive() external payable {}

    function setConfig(
        address _overheadVault,
        address _v2Router,
        address _v3Router,
        address _v3Factory,
        address _wrappedNative,
        uint256 _overheadBps,
        uint256 _minOverheadNative
    ) external onlyOwner {
        require(_overheadVault != address(0), "Bad vault");
        require(_v2Router != address(0), "Bad v2");
        require(_v3Router != address(0), "Bad v3");
        require(_v3Factory != address(0), "Bad factory");
        require(_wrappedNative != address(0), "Bad wrapped");
        require(_overheadBps <= 10_000, "Bad bps");

        overheadVault = _overheadVault;
        v2Router = _v2Router;
        v3Router = _v3Router;
        v3Factory = _v3Factory;
        wrappedNative = _wrappedNative;
        overheadBps = _overheadBps;
        minOverheadNative = _minOverheadNative;
    }

    function quoteOverhead(uint256 amountNative) public view returns (uint256) {
        uint256 pct = (amountNative * overheadBps) / 10_000;
        return pct + minOverheadNative;
    }

    function _payOverhead(uint256 overhead) internal {
        (bool ok,) = payable(overheadVault).call{value: overhead}("");
        require(ok, "Overhead transfer failed");
    }

    function _requireV3Pool(address a, address b, uint24 feeTier) internal view {
        require(
            IUniswapV3Factory(v3Factory).getPool(a, b, feeTier) != address(0),
            "No V3 pool"
        );
    }

    function _payNative(address to, uint256 amount) internal {
        (bool ok,) = payable(to).call{value: amount}("");
        require(ok, "Native transfer failed");
    }

    
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable nonReentrant {
        require(to != address(0), "Bad to");
        require(path.length >= 2, "Bad path");

        uint256 totalIn = msg.value;
        uint256 overhead = quoteOverhead(totalIn);
        require(totalIn > overhead, "Too small");

        uint256 swapIn = totalIn - overhead;
        _payOverhead(overhead);

        IUniswapV2Router(v2Router).swapExactETHForTokensSupportingFeeOnTransferTokens{value: swapIn}(
            amountOutMin,
            path,
            to,
            deadline
        );
    }

    function buyV3(
        uint256 amountOutMin,
        address tokenOut,
        uint24 feeTier,
        address user
    ) external payable nonReentrant returns (uint256 amountOut) {
        require(user != address(0), "Bad user");
        require(tokenOut != address(0), "Bad tokenOut");

        uint256 totalIn = msg.value;
        uint256 overhead = quoteOverhead(totalIn);
        require(totalIn > overhead, "Too small");

        uint256 swapIn = totalIn - overhead;
        _requireV3Pool(wrappedNative, tokenOut, feeTier);
        _payOverhead(overhead);

        IUniswapV3Router.ExactInputSingleParams memory p =
            IUniswapV3Router.ExactInputSingleParams({
                tokenIn: wrappedNative,
                tokenOut: tokenOut,
                fee: feeTier,
                recipient: user,
                amountIn: swapIn,
                amountOutMinimum: amountOutMin,
                sqrtPriceLimitX96: 0
            });

        amountOut = IUniswapV3Router(v3Router).exactInputSingle{value: swapIn}(p);
        return amountOut;
    }

    
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external nonReentrant {
        require(to != address(0), "Bad to");
        require(path.length >= 2, "Bad path");
        require(amountIn > 0, "Zero amount");

        address tokenIn = path[0];
        bool ok = IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
        require(ok, "Token transfer failed");

        IERC20(tokenIn).approve(v2Router, 0);
        IERC20(tokenIn).approve(v2Router, amountIn);

        uint256 balBefore = address(this).balance;

        IUniswapV2Router(v2Router).swapExactTokensForETHSupportingFeeOnTransferTokens(
            amountIn,
            amountOutMin,
            path,
            address(this),
            deadline
        );

        uint256 nativeOut = address(this).balance - balBefore;
        uint256 overhead = quoteOverhead(nativeOut);
        require(nativeOut > overhead, "Too small");

        _payOverhead(overhead);
        _payNative(to, nativeOut - overhead);
    }

    function sellV3(
        uint256 amountIn,
        uint256 amountOutMinWrapped,
        address tokenIn,
        uint24 feeTier,
        address user
    ) external nonReentrant {
        require(user != address(0), "Bad user");
        require(tokenIn != address(0), "Bad tokenIn");
        require(amountIn > 0, "Zero amount");

        _requireV3Pool(tokenIn, wrappedNative, feeTier);

        bool ok = IERC20(tokenIn).transferFrom(msg.sender, address(this), amountIn);
        require(ok, "Token transfer failed");

        IERC20(tokenIn).approve(v3Router, 0);
        IERC20(tokenIn).approve(v3Router, amountIn);

        IUniswapV3Router.ExactInputSingleParams memory p =
            IUniswapV3Router.ExactInputSingleParams({
                tokenIn: tokenIn,
                tokenOut: wrappedNative,
                fee: feeTier,
                recipient: address(this),
                amountIn: amountIn,
                amountOutMinimum: amountOutMinWrapped,
                sqrtPriceLimitX96: 0
            });

        uint256 wrappedOut = IUniswapV3Router(v3Router).exactInputSingle(p);
        IWrappedNative(wrappedNative).withdraw(wrappedOut);

        uint256 overhead = quoteOverhead(wrappedOut);
        require(wrappedOut > overhead, "Too small");

        _payOverhead(overhead);
        _payNative(user, wrappedOut - overhead);
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "osaka",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.