Skip to content
Verified contractPartialUNLICENSED

BananaGunRouter

Address0xdb5889e35e379ef0498aae126fc2cce1fbd23216
Balance

0.225587 ETH

 

Transactions

1,534,146

 

Compiler

solc 0.8.21

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.21+commit.d9974bed
Language
solidity
Optimization
Yes, 200 runs
EVM version
shanghai
License
UNLICENSED
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
18,046,127
Creation transaction
0x0dad2d8da0…29a63d416d

3 files

BananaGunRouter.sol

// Rebuilt by the imd.fun swarm
// ◇ IMD · an onchain AI agent workforce · $IMD 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7
// Seat #723 · explorer.imd.fun/goals/a05f7d2f-c42e-423e-bb75-fb80ed455626
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

import "./Interfaces.sol";
import "./Libraries.sol";

/// @notice Source recovery of the September 2023 Banana Gun router.
/// @dev Fixed literals and unusual control flow preserve the deployed program.
contract BananaGunRouter {
    using LowGasSafeMath for uint256;
    using SafeCast for uint256;

    uint256 public feesOwed = 0;
    uint256 private amountInCached = 0;
    uint256 private autoFeeNumerator = 99;
    uint256 private autoFeeDenominator = 100;
    uint256 private manualFeeNumerator = 199;
    uint256 private manualFeeDenominator = 200;
    bool public isPromoActive = true;

    address private constant OWNER = 0x37aAb97476bA8dC785476611006fD5dDA4eed66B;
    address private constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    address private constant HELPER = 0xC6265979793435b496e28e61af1500C22C3ba277;

    address private constant V3_ROUTER = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
    address private constant V2_ROUTER = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;

    event FeesCollected(uint256 amount, address account);
    event Reorg(address token);
    event Sell(uint256 amount);
    event Referral(uint256 amount, uint256 referral);
    // The event name is unknown; the indexed signature reproduces its LOG1.
    event SwapResult(uint256 indexed signature, uint256 amount, uint256 quoted, uint256 received) anonymous;

    modifier onlyOwner() {
        require(msg.sender == OWNER, "Hmm");
        _;
    }

    receive() external payable {}

    function swapETHForExactTokens(
        uint256[] calldata values,
        address[] calldata path,
        address router,
        uint256 maxTax,
        uint256 feeType,
        uint256 referral,
        uint256 timestamp
    ) external payable {
        if (timestamp != 0) {
            if (block.timestamp != timestamp) {
                emit Reorg(path[path.length - 1]);
                revert("Chain Re-org detected");
            }
        }
        if (values[2] > 0 && msg.value >= values[2]) payable(block.coinbase).transfer(values[2]);
        uint256 available = amountAfterFee(feeType, values[2]);
        if (values[0] > 0) {
            uint256[] memory amounts = IV2Helper(HELPER).op_0000000058e60385(values[0], path, router);
            if (amounts[0] <= available) {
                IWETH(WETH).deposit{value: amounts[0]}();
                assert(
                    IWETH(WETH).transfer(IV2Helper(HELPER).op_000000008bdb52dc(router, path[0], path[1]), amounts[0])
                );
                uint256 received = IERC20(path[path.length - 1]).balanceOf(msg.sender);
                IV2Helper(HELPER).op_0000000063aec299(amounts, path, msg.sender, router);
                received = IERC20(path[path.length - 1]).balanceOf(msg.sender).sub(received);
                if (received < values[0].mul(100 - maxTax).div(100)) revert("too much buy tax");
                collectFees(amounts[0], feeType, referral);
                refundETH();
                emit SwapResult(
                    0x9f849d23f4955d98202378ea318f2b0c7533695d3c9fb2a3931f0f919fa8c420, amounts[0], received, values[0]
                );
                if (values[1] > 0 && received < values[1]) revert("Not enough tokens out");
                return;
            }
        }
        uint256 quoted = IV2Helper(HELPER).op_000000004a5a52e8(available, path, router)[path.length - 1];
        IWETH(WETH).deposit{value: available}();
        assert(IWETH(WETH).transfer(IV2Helper(HELPER).op_000000008bdb52dc(router, path[0], path[1]), available));
        uint256 received = IERC20(path[path.length - 1]).balanceOf(msg.sender);
        IV2Helper(HELPER).op_00000002d721de41(path, msg.sender, router);
        received = IERC20(path[path.length - 1]).balanceOf(msg.sender).sub(received);
        if (received < quoted.mul(100 - maxTax).div(100)) revert("too much buy tax");
        collectFees(available, feeType, referral);
        refundETH();
        emit SwapResult(0x9f849d23f4955d98202378ea318f2b0c7533695d3c9fb2a3931f0f919fa8c420, available, received, quoted);
        if (values[1] > 0 && received < values[1]) revert("Not enough tokens out");
    }

    function transferTokens(address token) external onlyOwner {
        if (token == WETH) TransferHelper.safeTransferETH(OWNER, address(this).balance);
        uint256 balance = IERC20(token).balanceOf(address(this));
        require(balance > 0, "No Balance in Contract");
        require(IERC20(token).transfer(OWNER, balance), "Transfer failed");
    }

    function togglePromoStatus() external onlyOwner {
        if (isPromoActive) isPromoActive = false;
        else isPromoActive = true;
    }

    function setFees(uint256 autoNum, uint256 autoDen, uint256 manualNum, uint256 manualDen) external onlyOwner {
        autoFeeNumerator = autoNum;
        autoFeeDenominator = autoDen;
        manualFeeNumerator = manualNum;
        manualFeeDenominator = manualDen;
    }

    // Selector 0x8024c73a; the original name is unknown.
    function op_000000002da9ab6f() external onlyOwner {
        require(feesOwed > 0, "No Fees Currently Owed");
        require(address(this).balance >= feesOwed, "Not Enough Balance To Cover Fees");
        TransferHelper.safeTransferETH(OWNER, feesOwed);
        feesOwed = 0;
    }

    struct CallbackData {
        address tokenIn;
        address tokenOut;
        address recipient;
        address payer;
        address transferProxy;
        uint256 amountInMaximum;
        bool skipAmountCache;
    }

    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external {
        require(amount0Delta > 0 || amount1Delta > 0);
        CallbackData memory decoded = abi.decode(data, (CallbackData));
        require(
            msg.sender
                == IHelper(HELPER).computeV3Pair(decoded.tokenIn, decoded.tokenOut, IUniswapV3Pool(msg.sender).fee()),
            "Fake callback"
        );
        (bool isExactInput, uint256 amountToPay) = amount0Delta > 0
            ? (decoded.tokenIn < decoded.tokenOut, uint256(amount0Delta))
            : (decoded.tokenOut < decoded.tokenIn, uint256(amount1Delta));
        if (amountToPay <= decoded.amountInMaximum) {
            if (decoded.skipAmountCache == false) amountInCached = amountToPay;
            if (isExactInput) {
                if (decoded.tokenIn == WETH) {
                    pay(decoded.tokenIn, decoded.payer, msg.sender, amountToPay);
                } else {
                    ITransferProxy(decoded.transferProxy)
                        .transferTokensProxy(decoded.tokenIn, decoded.payer, msg.sender, amountToPay);
                }
            } else {
                if (decoded.tokenIn == WETH) {
                    pay(decoded.tokenOut, decoded.payer, msg.sender, amountToPay);
                } else {
                    ITransferProxy(decoded.transferProxy)
                        .transferTokensProxy(decoded.tokenOut, decoded.payer, msg.sender, amountToPay);
                }
            }
        }
    }

    function pay(address token, address payer, address recipient, uint256 value) internal {
        if (token == WETH && address(this).balance >= value) {
            IWETH(WETH).deposit{value: value}();
            IWETH(WETH).transfer(recipient, value);
        } else if (payer == address(this)) {
            TransferHelper.safeTransfer(token, recipient, value);
        } else {
            TransferHelper.safeTransferFrom(token, payer, recipient, value);
        }
    }

    function amountAfterFee(uint256 feeType, uint256 tip) internal view returns (uint256 amount) {
        uint256 available = msg.value.sub(tip);
        if (feeType != 0) {
            if (feeType == 2) {
                if (isPromoActive) return available.mul(1983).div(2000);
                else return available.mul(autoFeeNumerator).div(autoFeeDenominator);
            } else {
                return available.mul(manualFeeNumerator).div(manualFeeDenominator);
            }
        } else {
            return available;
        }
    }

    function collectFees(uint256 amount, uint256 feeType, uint256 referral) internal {
        require(amount > 0, "exploiter?");
        if (feeType != 0) {
            uint256 fee;
            if (feeType == 2) {
                if (isPromoActive) fee = amount.mul(17).div(2000);
                else fee = amount.mul(1).div(100);
            } else {
                fee = amount.mul(1).div(200);
            }
            if (referral != 0) emit Referral(fee, referral);
            feesOwed = feesOwed.add(fee);
            emit FeesCollected(fee, msg.sender);
        }
    }

    function swapV2(address tokenIn, address tokenOut, uint256 amountIn) internal {
        address[] memory path = new address[](2);
        path[0] = tokenIn;
        path[1] = tokenOut;
        pay(tokenIn, address(this), IV2Helper(HELPER).op_000000008bdb52dc(V2_ROUTER, path[0], path[1]), amountIn);
        IV2Helper(HELPER).op_00000002d721de41(path, address(this), V2_ROUTER);
    }

    struct SwapParams {
        uint256 amountOut;
        bool isBuy;
        uint256 maxTax;
        uint256 tip;
        address pool;
        address transferProxy;
        uint256 feeType;
        uint256 amountInMaximum;
        uint256 referral;
    }

    // Selector 0xa82deeb0; a mined signature preimage, not the original name.
    function op_000000002d0ddacf(
        address pair,
        address router,
        uint256 percentage,
        uint256 amount,
        address transferProxy,
        address[] memory path
    ) public returns (uint256 result0, uint256 result1, uint256 result2) {
        uint256[] memory values = new uint256[](3);
        if (percentage > 0 && amount == 0) {
            if (percentage == 100) values[0] = IERC20(path[0]).balanceOf(msg.sender);
            else values[0] = IERC20(path[0]).balanceOf(msg.sender).mul(percentage).div(100);
        } else if (amount != 0) {
            if (percentage == 0) values[0] = IERC20(path[0]).balanceOf(msg.sender);
            else values[0] = amount;
        }
        require(values[0] > 0, "ZERO_BALANCE");
        if (router == V3_ROUTER) {
            SwapParams memory params = SwapParams(0, false, 0, 0, pair, transferProxy, 0, values[0], 0);
            if (percentage == 0 && amount > 0) params.amountOut = amount;
            address[] memory v3path = new address[](2);
            v3path[0] = path[0];
            v3path[1] = path[1];
            (result0, result2, result1) = swapV3(v3path, params);
            return (result0, values[0], result2);
        } else {
            uint256[] memory amounts;
            if (percentage == 0 && amount > 0) {
                amounts = IV2Helper(HELPER).op_0000000058e60385(amount, path, router);
                if (amounts[0] <= values[0]) values[0] = amounts[0];
            }
            values[1] = IERC20(path[0]).balanceOf(pair);
            ITransferProxy(transferProxy).transferTokensProxy(path[0], msg.sender, pair, values[0]);
            values[1] = IERC20(path[0]).balanceOf(pair) - values[1];
            values[2] = IERC20(WETH).balanceOf(address(this));
            IV2Helper(HELPER).op_00000002d721de41(path, address(this), router);
            uint256 received = IERC20(WETH).balanceOf(address(this)) - values[2];
            require(received > 0, "NO TOKENS RECEIVED");
            return (values[1], values[0], received);
        }
    }

    // Selector 0x70fef1da; the original function name is unknown.
    function op_00000000f4415551(
        address tokenA,
        address tokenB,
        address router,
        address pair,
        uint256 amountIn,
        uint256 minimumOut,
        address transferProxy,
        uint256[] memory values
    ) public {
        if (values[4] > 0) {
            if (block.timestamp != values[4]) {
                emit Reorg(tokenA);
                revert("Chain Re-org detected");
            }
        }
        address[] memory path;
        if (tokenB == WETH) {
            path = new address[](2);
            path[0] = tokenA;
            path[1] = tokenB;
        } else {
            path = new address[](3);
            path[0] = tokenA;
            path[1] = tokenB;
            path[2] = WETH;
        }
        uint256 balance = IERC20(tokenA).balanceOf(msg.sender);
        if (router == V3_ROUTER) {
            SwapParams memory params = SwapParams(0, false, 0, 0, pair, transferProxy, values[1], 0, values[2]);
            if (amountIn == 0) {
                if (values[0] == 100) params.amountInMaximum = balance;
                else params.amountInMaximum = balance.mul(values[0]).div(100);
            } else {
                params.amountInMaximum = amountIn;
            }
            if (values[5] > 0) params.amountOut = values[5];
            address[] memory v3path = new address[](2);
            v3path[0] = tokenA;
            v3path[1] = tokenB;
            (, uint256 received,) = swapV3(v3path, params);
            emit Sell(received);
            if (minimumOut > 0 && received < minimumOut) revert("Not enough tokens out");
            return;
        } else {
            if (amountIn != 0) {
                ITransferProxy(transferProxy).transferTokensProxy(path[0], msg.sender, pair, amountIn);
            } else if (minimumOut != 0) {
                uint256[] memory amounts = IV2Helper(HELPER).op_000000004aedaaf4(minimumOut, path, router, values[3]);
                if (amounts[0] < balance) {
                    ITransferProxy(transferProxy).transferTokensProxy(path[0], msg.sender, pair, amounts[0]);
                } else {
                    ITransferProxy(transferProxy).transferTokensProxy(path[0], msg.sender, pair, balance);
                }
            } else {
                if (values[0] == 100) {
                    ITransferProxy(transferProxy).transferTokensProxy(path[0], msg.sender, pair, balance);
                } else {
                    ITransferProxy(transferProxy)
                        .transferTokensProxy(path[0], msg.sender, pair, balance.mul(values[0]).div(100));
                }
            }
            IV2Helper(HELPER).op_00000002d721de41(path, address(this), router);
            uint256 received = IERC20(WETH).balanceOf(address(this));
            if (received > 0) IWETH(WETH).withdraw(received);
            collectFees(received, values[1], values[2]);
            refundETH();
            emit Sell(received);
            if (minimumOut > 0 && received < minimumOut) revert("Not enough tokens out");
        }
    }

    // Selector 0x0e8f4106; the original function name is unknown.
    function op_00000002da02d6fe(address tokenA, address tokenB, address pair, address router, uint256[] memory values)
        public
        payable
        returns (uint256 receivedV3, uint256 quotedV3, uint256 spent)
    {
        if (router == V3_ROUTER) {
            address[] memory path = new address[](2);
            path[0] = tokenA;
            path[1] = tokenB;
            SwapParams memory params =
                SwapParams(values[0], true, 0, 0, pair, address(0), values[1], msg.value, values[2]);
            (spent, receivedV3, quotedV3) = swapV3(path, params);
            return (receivedV3, quotedV3, spent);
        } else {
            uint256 available = amountAfterFee(values[1], 0);
            address[] memory path;
            if (tokenB == WETH) {
                path = new address[](2);
                path[0] = tokenB;
                path[1] = tokenA;
            } else {
                path = new address[](3);
                path[0] = WETH;
                path[1] = tokenB;
                path[2] = tokenA;
            }
            bool exact;
            uint256[] memory amounts;
            if (values[0] > 0) {
                amounts = IV2Helper(HELPER).op_0000000058e60385(values[0], path, router);
                if (amounts[0] <= available) {
                    exact = true;
                    spent = amounts[0];
                } else {
                    spent = available;
                }
            } else {
                spent = available;
            }
            uint256 quoted = IV2Helper(HELPER).op_000000004a5a52e8(spent, path, router)[path.length - 1];
            IWETH(WETH).deposit{value: spent}();
            assert(IWETH(WETH).transfer(IV2Helper(HELPER).op_000000008bdb52dc(router, path[0], path[1]), spent));
            uint256 balanceBefore = IERC20(tokenA).balanceOf(msg.sender);
            if (exact) IV2Helper(HELPER).op_0000000063aec299(amounts, path, msg.sender, router);
            else IV2Helper(HELPER).op_00000002d721de41(path, msg.sender, router);
            uint256 received = IERC20(tokenA).balanceOf(msg.sender) - balanceBefore;
            require(received > 0, "NO TOKENS RECEIVED");
            return (received, quoted, spent);
        }
    }

    function v3SwapHelper(
        address tokenA,
        address tokenB,
        uint256 tip,
        uint256 minimumOut,
        uint256 amountOut,
        uint256 maximumIn,
        address pool,
        bool isBuy,
        uint256 maxTax,
        uint256 feeType,
        uint256 referral,
        uint256 timestamp
    ) public payable returns (uint256 result0, uint256 result1) {
        if (timestamp != 0) {
            if (block.timestamp != timestamp) {
                emit Reorg(tokenA);
                revert("Chain Re-org detected");
            }
        }
        if (tip > 0 && msg.value >= tip) payable(block.coinbase).transfer(tip);
        address[] memory path = new address[](2);
        path[0] = tokenA;
        path[1] = tokenB;
        SwapParams memory params =
            SwapParams(amountOut, isBuy, maxTax, tip, pool, address(0), feeType, maximumIn, referral);
        (, result0, result1) = swapV3(path, params);
        if (minimumOut != 0 && result0 < minimumOut) revert("Not enough tokens out");
    }

    function swapV3(address[] memory path, SwapParams memory params)
        internal
        returns (uint256 result0, uint256 result1, uint256 quoted)
    {
        CallbackData memory callback = CallbackData(
            path[1], path[0], msg.sender, address(this), params.transferProxy, params.amountInMaximum, true
        );
        uint256 ethBefore = address(this).balance;
        if (params.isBuy == true) {
            uint256 available;
            if (path[1] == WETH) {
                available = amountAfterFee(params.feeType, params.tip);
            } else {
                swapV2(WETH, path[1], amountAfterFee(params.feeType, params.tip));
                available = IERC20(path[1]).balanceOf(address(this));
            }
            callback.tokenIn = path[1];
            callback.tokenOut = path[0];
            callback.recipient = msg.sender;
            callback.payer = address(this);
            callback.skipAmountCache = true;
            callback.amountInMaximum = available;
        } else {
            callback.tokenIn = path[0];
            callback.tokenOut = path[1];
            callback.recipient = address(this);
            callback.payer = msg.sender;
            callback.skipAmountCache = false;
            callback.amountInMaximum = params.amountInMaximum;
            if (params.amountOut != 0 && path[1] != WETH) {
                address[] memory quotePath = new address[](2);
                quotePath[0] = path[1];
                quotePath[1] = WETH;
                uint256[] memory amounts = IV2Helper(HELPER).op_0000000058e60385(params.amountOut, quotePath, V2_ROUTER);
                params.amountOut = amounts[0];
            }
        }
        uint256 expected;
        if (params.amountOut != 0) {
            (, int24 tick,,,,,) = IUniswapV3Pool(params.pool).slot0();
            uint160 sqrtRatio = TickMath.getSqrtRatioAtTick(tick);
            if (sqrtRatio <= type(uint128).max) {
                uint256 ratioX192 = uint256(sqrtRatio) * sqrtRatio;
                expected = callback.tokenIn < callback.tokenOut
                    ? FullMath.mulDiv(ratioX192, uint128(callback.amountInMaximum), 1 << 192)
                    : FullMath.mulDiv(1 << 192, uint128(callback.amountInMaximum), ratioX192);
            } else {
                uint256 ratioX128 = FullMath.mulDiv(sqrtRatio, sqrtRatio, 1 << 64);
                expected = callback.tokenIn < callback.tokenOut
                    ? FullMath.mulDiv(ratioX128, uint128(callback.amountInMaximum), 1 << 128)
                    : FullMath.mulDiv(1 << 128, uint128(callback.amountInMaximum), ratioX128);
            }
        }
        if (params.amountOut != 0 && expected >= params.amountOut) {
            uint256 received = IERC20(callback.tokenOut).balanceOf(callback.recipient);
            (int256 amount0, int256 amount1) = IUniswapV3Pool(params.pool)
                .swap(
                    callback.recipient,
                    callback.tokenIn < callback.tokenOut,
                    -params.amountOut.toInt256(),
                    callback.tokenIn < callback.tokenOut ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1,
                    abi.encode(callback)
                );
            (, quoted) = callback.tokenIn < callback.tokenOut
                ? (uint256(amount0), uint256(-amount1))
                : (uint256(amount1), uint256(-amount0));
            received = IERC20(callback.tokenOut).balanceOf(callback.recipient).sub(received);
            require(received > 0, "no tokens out");
            if (params.maxTax < 100 && params.maxTax > 0) {
                if (received < quoted.mul(100 - params.maxTax).div(100)) revert("too much tax");
            }
            result1 = received;
        } else {
            uint256 received = IERC20(callback.tokenOut).balanceOf(callback.recipient);
            (int256 amount0, int256 amount1) = IUniswapV3Pool(params.pool)
                .swap(
                    callback.recipient,
                    callback.tokenIn < callback.tokenOut,
                    callback.amountInMaximum.toInt256(),
                    callback.tokenIn < callback.tokenOut ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1,
                    abi.encode(callback)
                );
            quoted = uint256(-(callback.tokenIn < callback.tokenOut ? amount1 : amount0));
            received = IERC20(callback.tokenOut).balanceOf(callback.recipient).sub(received);
            require(received > 0, "no tokens out");
            if (params.maxTax < 100 && params.maxTax > 0) {
                if (received < quoted.mul(100 - params.maxTax).div(100)) revert("too much tax");
            }
            result1 = received;
        }
        if (params.isBuy == false) {
            if (callback.tokenOut != WETH) {
                uint256 balance = IERC20(callback.tokenOut).balanceOf(address(this));
                if (balance > 0) swapV2(callback.tokenOut, WETH, balance);
            }
            uint256 wrappedBalance = IERC20(WETH).balanceOf(address(this));
            if (wrappedBalance > 0) IWETH(WETH).withdraw(wrappedBalance);
            collectFees(wrappedBalance, params.feeType, params.referral);
            result1 = wrappedBalance;
            refundETH();
            emit SwapResult(
                0x9f849d23f4955d98202378ea318f2b0c7533695d3c9fb2a3931f0f919fa8c420,
                callback.amountInMaximum,
                result1,
                quoted
            );
            result0 = amountInCached;
            amountInCached = 0;
        } else if (params.isBuy == true) {
            if (callback.tokenIn != WETH) {
                uint256 balance = IERC20(callback.tokenIn).balanceOf(address(this));
                if (balance > 0) swapV2(callback.tokenIn, WETH, IERC20(callback.tokenIn).balanceOf(address(this)));
            }
            uint256 wrappedBalance = IERC20(WETH).balanceOf(address(this));
            if (wrappedBalance > 0) {
                IWETH(WETH).withdraw(wrappedBalance);
                result0 = ethBefore - address(this).balance;
                require(result0 > 0, "no money spent");
                collectFees(result0, params.feeType, params.referral);
                refundETH();
            } else {
                result0 = ethBefore - address(this).balance;
                require(result0 > 0, "no money spent");
                collectFees(result0, params.feeType, params.referral);
                refundETH();
            }
            emit SwapResult(
                0x9f849d23f4955d98202378ea318f2b0c7533695d3c9fb2a3931f0f919fa8c420, result0, result1, quoted
            );
        }
    }

    function refundETH() internal {
        uint256 balance = address(this).balance.sub(feesOwed);
        if (balance > 0) TransferHelper.safeTransferETH(msg.sender, balance);
    }
}

Interfaces.sol

// Part of a rebuild by the imd.fun swarm · $IMD 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7
// Rebuilt by the imd.fun swarm
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
}

interface IWETH is IERC20 {
    function deposit() external payable;
    function withdraw(uint256 amount) external;
}

interface IUniswapV3Pool {
    function fee() external view returns (uint24);
    function slot0() external view returns (uint160, int24, uint16, uint16, uint16, uint8, bool);
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);
}

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

interface ITransferProxy {
    function transferTokensProxy(address token, address from, address to, uint256 amount) external;
}

interface IV2Helper {
    // op_* names are selector preimages. Parameter types and mutabilities
    // are recovered from the deployed ABI encoders.
    function op_000000004aedaaf4(uint256 amountOut, address[] calldata path, address router, uint256 tax)
        external
        view
        returns (uint256[] memory);
    function op_000000004a5a52e8(uint256 amountIn, address[] calldata path, address router)
        external
        view
        returns (uint256[] memory);
    function op_0000000063aec299(uint256[] calldata amounts, address[] calldata path, address to, address router)
        external;
    function op_0000000058e60385(uint256 amountOut, address[] calldata path, address router)
        external
        view
        returns (uint256[] memory);
    function op_000000008bdb52dc(address router, address tokenA, address tokenB) external view returns (address);
    function op_00000002d721de41(address[] calldata path, address to, address router) external;
}

Libraries.sol

// Part of a rebuild by the imd.fun swarm · $IMD 0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7
// Rebuilt by the imd.fun swarm
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

// The original retains redundant overflow guards even under Solidity 0.8.
library LowGasSafeMath {
    function add(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x + y) >= x);
    }

    function sub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require((z = x - y) <= x);
    }

    function mul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        require(x == 0 || (z = x * y) / x == y);
    }

    function div(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x / y;
    }
}

library SafeCast {
    function toInt256(uint256 value) internal pure returns (int256) {
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

library TransferHelper {
    function safeTransfer(address token, address to, uint256 value) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), "TransferHelper: INTERNAL TRANSFER_FAILED");
    }

    function safeTransferFrom(address token, address from, address to, uint256 value) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
        require(
            success && (data.length == 0 || abi.decode(data, (bool))), "TransferHelper: INTERNAL TRANSFER_FROM_FAILED"
        );
    }

    function safeTransferETH(address to, uint256 value) internal {
        (bool success,) = to.call{value: value}(new bytes(0));
        require(success, "TransferHelper: INTERNAL ETH_TRANSFER_FAILED");
    }
}

/// @dev Uniswap-style 512-bit multiplication and division. The unchecked
/// arithmetic and assembly are intrinsic to the full-width algorithm.
library FullMath {
    function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            uint256 prod0;
            uint256 prod1;
            assembly {
                let mm := mulmod(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }
            if (prod1 == 0) {
                require(denominator > 0);
                assembly { result := div(prod0, denominator) }
                return result;
            }
            require(denominator > prod1);
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }
            uint256 twos = (0 - denominator) & denominator;
            assembly {
                denominator := div(denominator, twos)
                prod0 := div(prod0, twos)
                twos := add(div(sub(0, twos), twos), 1)
            }
            prod0 |= prod1 * twos;
            uint256 inv = (3 * denominator) ^ 2;
            inv *= 2 - denominator * inv;
            inv *= 2 - denominator * inv;
            inv *= 2 - denominator * inv;
            inv *= 2 - denominator * inv;
            inv *= 2 - denominator * inv;
            inv *= 2 - denominator * inv;
            result = prod0 * inv;
            return result;
        }
    }
}

library TickMath {
    error InvalidTick();
    int24 internal constant MIN_TICK = -887272;
    int24 internal constant MAX_TICK = 887272;
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert InvalidTick();
            uint256 ratio =
                absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
            // Solidity's checked division is retained in the deployed library.
            if (tick > 0) ratio = type(uint256).max / ratio;
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.