Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x80f0A851d80F37A9D3Be1817f85118FC31d0FB1D
Balance 0 ETH
Nonce 1
Code Size 8371 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

8371 bytes
0x6080604052600436106100d65760003560e01c80638da5cb5b1161007f578063f05c5fed11610059578063f05c5fed14610214578063f2fde38b14610234578063f97b04e514610254578063fc7fb4991461027457600080fd5b80638da5cb5b146101955780639023e182146101c7578063a5ece941146101f457600080fd5b806362192f34116100b057806362192f3414610144578063715018a6146101575780637fd6f15c1461016c57600080fd5b80632369bf83146100e25780634215c1e91461010457806344dba3801461012457600080fd5b366100dd57005b600080fd5b3480156100ee57600080fd5b506101026100fd3660046118e7565b610287565b005b34801561011057600080fd5b5061010261011f36600461190b565b61029b565b34801561013057600080fd5b5061010261013f3660046119bd565b61076d565b610102610152366004611a18565b610994565b34801561016357600080fd5b50610102610c3b565b34801561017857600080fd5b5061018260035481565b6040519081526020015b60405180910390f35b3480156101a157600080fd5b506000546001600160a01b03165b6040516001600160a01b03909116815260200161018c565b3480156101d357600080fd5b506101e76101e2366004611a8c565b610c4f565b60405161018c9190611ad8565b34801561020057600080fd5b506002546101af906001600160a01b031681565b34801561022057600080fd5b5061010261022f366004611b1b565b610cf3565b34801561024057600080fd5b5061010261024f3660046118e7565b610d3c565b34801561026057600080fd5b5061010261026f366004611a18565b610d95565b610102610282366004611b34565b61112e565b61028f61124a565b61029881611290565b50565b60008590506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156102e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103049190611b87565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610346573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061036a9190611b87565b9050866001600160a01b0316826001600160a01b0316141580156103a05750866001600160a01b0316816001600160a01b031614155b806103f057506001600160a01b03821673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2148015906103f057506001600160a01b03811673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214155b1561040e576040516320db826760e01b815260040160405180910390fd5b6104236001600160a01b038816338a896112e6565b600080846001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015610464573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104889190611bc7565b50915091506000808a6001600160a01b0316866001600160a01b0316146104b05782846104b3565b83835b6dffffffffffffffffffffffffffff918216935016905060006104f16127106104e061ffff8c168e611c2d565b6104ea9190611c44565b8484611362565b905089811015610514576040516342301c2360e01b815260040160405180910390fd5b6000808d6001600160a01b0316896001600160a01b0316146105385782600061053c565b6000835b604080516000815260208101918290527f022c0d9f0000000000000000000000000000000000000000000000000000000090915291935091506001600160a01b038b169063022c0d9f906105999085908590309060248101611c7c565b600060405180830381600087803b1580156105b357600080fd5b505af11580156105c7573d6000803e3d6000fd5b50506040516370a0823160e01b81523060048201526000925073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc291506370a0823190602401602060405180830381865afa15801561061d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106419190611ce8565b90508381101561067d576040517fbc9fcb4e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604051632e1a7d4d60e01b81526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b1580156106ca57600080fd5b505af11580156106de573d6000803e3d6000fd5b5050505060006106ed826113b1565b604051909150600090339083908381818185875af1925050503d8060008114610732576040519150601f19603f3d011682016040523d82523d6000602084013e610737565b606091505b505090508061075957604051630b7cc7c360e11b815260040160405180910390fd5b505050505050505050505050505050505050565b610775611452565b82826002811015610799576040516320db826760e01b815260040160405180910390fd5b60006107a58686611495565b90506107e633308a898960008181106107c0576107c0611d01565b90506020020160208101906107d591906118e7565b6001600160a01b03169291906112e6565b610837737a250d5630b4cf539739df2c5dacb4c659f2488d898888600081811061081257610812611d01565b905060200201602081019061082791906118e7565b6001600160a01b03169190611652565b6040517f18cbafe5000000000000000000000000000000000000000000000000000000008152600090737a250d5630b4cf539739df2c5dacb4c659f2488d906318cbafe590610892908c908c90879030908c90600401611d5c565b6000604051808303816000875af11580156108b1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526108d99190810190611d98565b9050600081600183516108ec9190611e65565b815181106108fc576108fc611d01565b602002602001015190506000610911826113b1565b604051909150600090339083908381818185875af1925050503d8060008114610956576040519150601f19603f3d011682016040523d82523d6000602084013e61095b565b606091505b505090508061097d576040516312171d8360e31b815260040160405180910390fd5b5050505050505061098d60018055565b5050505050565b61099c611452565b346000036109bd57604051630b7cc7c360e11b815260040160405180910390fd5b6000808080806109cf86880188611e8b565b9398509196509450925090506001600160a01b03851615610a035760405163e6c4247b60e01b815260040160405180910390fd5b6000610a0e346113b1565b905080831115610a31576040516312171d8360e31b815260040160405180910390fd5b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015610a8057600080fd5b505af1158015610a94573d6000803e3d6000fd5b505060405163095ea7b360e01b815273e592427a0aece92de3edee1f18e0157c0586156460048201526024810185905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2935063095ea7b3925060440190506020604051808303816000875af1158015610b06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2a9190611ee4565b50604080516101008101825273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281526001600160a01b038716602082015262ffffff86169181019190915233606082015260009060808101610b824261012c611f06565b815260200185815260200184815260200160006001600160a01b0316815250905073e592427a0aece92de3edee1f18e0157c058615646001600160a01b031663414bf389826040518263ffffffff1660e01b8152600401610be39190611fa0565b6020604051808303816000875af1158015610c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c269190611ce8565b5050505050505050610c3760018055565b5050565b610c4361124a565b610c4d60006116f5565b565b6040517fd06ca61f000000000000000000000000000000000000000000000000000000008152606090737a250d5630b4cf539739df2c5dacb4c659f2488d9063d06ca61f90610ca690879087908790600401611faf565b600060405180830381865afa158015610cc3573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ceb9190810190611d98565b949350505050565b610cfb61124a565b6101f4811115610d37576040517f25ef66ea00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600355565b610d4461124a565b6001600160a01b038116610d8c576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024015b60405180910390fd5b610298816116f5565b610d9d611452565b6000808080610dae85870187611ff9565b929650909450925090506001600160a01b03831615610de05760405163e6c4247b60e01b815260040160405180910390fd5b6040516370a0823160e01b81523360048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015610e27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e4b9190611ce8565b905081811015610e6e576040516342301c2360e01b815260040160405180910390fd5b610e836001600160a01b0386163330846112e6565b610eab6001600160a01b03861673e592427a0aece92de3edee1f18e0157c0586156483611652565b60408051610100810182526001600160a01b038716815273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2602082015262ffffff85169181019190915230606082015260009060808101610f0242610708611f06565b815260200184815260200183815260200160006001600160a01b0316815250905073e592427a0aece92de3edee1f18e0157c058615646001600160a01b031663db3e2198826040518263ffffffff1660e01b8152600401610f639190611fa0565b6020604051808303816000875af1158015610f82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fa69190611ce8565b506040516370a0823160e01b815230600482015260009073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906370a0823190602401602060405180830381865afa158015610ff9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061101d9190611ce8565b905083811015611040576040516342301c2360e01b815260040160405180910390fd5b604051632e1a7d4d60e01b81526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b15801561108d57600080fd5b505af11580156110a1573d6000803e3d6000fd5b5050505060006110b0826113b1565b604051909150600090339083908381818185875af1925050503d80600081146110f5576040519150601f19603f3d011682016040523d82523d6000602084013e6110fa565b606091505b505090508061111c576040516312171d8360e31b815260040160405180910390fd5b505050505050505050610c3760018055565b611136611452565b3460000361115757604051630b7cc7c360e11b815260040160405180910390fd5b8282600281101561117b576040516320db826760e01b815260040160405180910390fd5b60006111878686611495565b90506000611194346113b1565b6040517f7ff36ab5000000000000000000000000000000000000000000000000000000008152909150737a250d5630b4cf539739df2c5dacb4c659f2488d90637ff36ab59083906111ef908c90879033908c90600401612048565b60006040518083038185885af115801561120d573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f191682016040526112369190810190611d98565b505050505061124460018055565b50505050565b6000546001600160a01b03163314610c4d576040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152602401610d83565b6001600160a01b0381166112b75760405163e6c4247b60e01b815260040160405180910390fd5b6002805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b6040516001600160a01b0384811660248301528381166044830152606482018390526112449186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611752565b600080611371856103e5611c2d565b9050600061137f8483611c2d565b9050600082611390876103e8611c2d565b61139a9190611f06565b90506113a68183611c44565b979650505050505050565b600080612710600354846113c59190611c2d565b6113cf9190611c44565b6002546040519192506000916001600160a01b039091169083908381818185875af1925050503d8060008114611421576040519150601f19603f3d011682016040523d82523d6000602084013e611426565b606091505b5050905080611448576040516312171d8360e31b815260040160405180910390fd5b610ceb8285611e65565b60026001540361148e576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600155565b60608167ffffffffffffffff8111156114b0576114b0611c66565b6040519080825280602002602001820160405280156114d9578160200160208202803683370190505b50905060005b82811015611540578383828181106114f9576114f9611d01565b905060200201602081019061150e91906118e7565b82828151811061152057611520611d01565b6001600160a01b03909216602092830291909101909101526001016114df565b5060006001600160a01b03168160008151811061155f5761155f611d01565b60200260200101516001600160a01b0316036115be5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28160008151811061159d5761159d611d01565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000600182516115ce9190611e65565b905060006001600160a01b03168282815181106115ed576115ed611d01565b60200260200101516001600160a01b03160361164b5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc282828151811061162a5761162a611d01565b60200260200101906001600160a01b031690816001600160a01b0316815250505b5092915050565b6040517fdd62ed3e0000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156116bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116df9190611ce8565b905061124484846116f08585611f06565b6117dc565b600080546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080602060008451602086016000885af180611775576040513d6000823e3d81fd5b50506000513d9150811561178d57806001141561179a565b6001600160a01b0384163b155b15611244576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610d83565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b1790526118428482611881565b611244576040516001600160a01b0384811660248301526000604483015261187791869182169063095ea7b39060640161131b565b6112448482611752565b6000806000806020600086516020880160008a5af192503d915060005190508280156118c6575081156118b757806001146118c6565b6000866001600160a01b03163b115b93505050505b92915050565b6001600160a01b038116811461029857600080fd5b6000602082840312156118f957600080fd5b8135611904816118d2565b9392505050565b600080600080600060a0868803121561192357600080fd5b853561192e816118d2565b9450602086013561193e816118d2565b93506040860135925060608601359150608086013561ffff8116811461196357600080fd5b809150509295509295909350565b60008083601f84011261198357600080fd5b50813567ffffffffffffffff81111561199b57600080fd5b6020830191508360208260051b85010111156119b657600080fd5b9250929050565b6000806000806000608086880312156119d557600080fd5b8535945060208601359350604086013567ffffffffffffffff8111156119fa57600080fd5b611a0688828901611971565b96999598509660600135949350505050565b60008060208385031215611a2b57600080fd5b823567ffffffffffffffff811115611a4257600080fd5b8301601f81018513611a5357600080fd5b803567ffffffffffffffff811115611a6a57600080fd5b856020828401011115611a7c57600080fd5b6020919091019590945092505050565b600080600060408486031215611aa157600080fd5b83359250602084013567ffffffffffffffff811115611abf57600080fd5b611acb86828701611971565b9497909650939450505050565b602080825282518282018190526000918401906040840190835b81811015611b10578351835260209384019390920191600101611af2565b509095945050505050565b600060208284031215611b2d57600080fd5b5035919050565b60008060008060608587031215611b4a57600080fd5b84359350602085013567ffffffffffffffff811115611b6857600080fd5b611b7487828801611971565b9598909750949560400135949350505050565b600060208284031215611b9957600080fd5b8151611904816118d2565b80516dffffffffffffffffffffffffffff81168114611bc257600080fd5b919050565b600080600060608486031215611bdc57600080fd5b611be584611ba4565b9250611bf360208501611ba4565b9150604084015163ffffffff81168114611c0c57600080fd5b809150509250925092565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176118cc576118cc611c17565b600082611c6157634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052604160045260246000fd5b8481528360208201526001600160a01b0383166040820152608060608201526000825180608084015260005b81811015611cc557602081860181015160a0868401015201611ca8565b50600060a0828501015260a0601f19601f83011684010191505095945050505050565b600060208284031215611cfa57600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600081518084526020840193506020830160005b82811015611d525781516001600160a01b0316865260209586019590910190600101611d2b565b5093949350505050565b85815284602082015260a060408201526000611d7b60a0830186611d17565b6001600160a01b0394909416606083015250608001529392505050565b600060208284031215611daa57600080fd5b815167ffffffffffffffff811115611dc157600080fd5b8201601f81018413611dd257600080fd5b805167ffffffffffffffff811115611dec57611dec611c66565b8060051b604051601f19603f830116810181811067ffffffffffffffff82111715611e1957611e19611c66565b604052918252602081840181019290810187841115611e3757600080fd5b6020850194505b83851015611e5a57845180825260209586019590935001611e3e565b509695505050505050565b818103818111156118cc576118cc611c17565b803562ffffff81168114611bc257600080fd5b600080600080600060a08688031215611ea357600080fd5b8535611eae816118d2565b94506020860135611ebe816118d2565b9350611ecc60408701611e78565b94979396509394606081013594506080013592915050565b600060208284031215611ef657600080fd5b8151801515811461190457600080fd5b808201808211156118cc576118cc611c17565b6001600160a01b0381511682526001600160a01b03602082015116602083015262ffffff60408201511660408301526060810151611f6260608401826001600160a01b03169052565b506080810151608083015260a081015160a083015260c081015160c083015260e0810151611f9b60e08401826001600160a01b03169052565b505050565b61010081016118cc8284611f19565b838152604060208201819052810182905260008360608301825b85811015611e5a578235611fdc816118d2565b6001600160a01b0316825260209283019290910190600101611fc9565b6000806000806080858703121561200f57600080fd5b843561201a816118d2565b9350602085013561202a816118d2565b925061203860408601611e78565b9396929550929360600135925050565b8481526080602082015260006120616080830186611d17565b6001600160a01b0394909416604083015250606001529291505056fea26469706673582212206a96201952df90537d67bb7c64f418687f84ca54d9ef2c7e13445030433a094964736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: paris Optimization: Yes (1000 runs)
DexedSwapServiceV1.sol 338 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import "./interfaces/IWETH.sol";
import "./interfaces/Errors.sol";
import "./libraries/UniswapV2Library.sol";
import "./interfaces/IUniswapV2Pair.sol";

/**
 * @title DexedSwapServiceV1
 * @notice This contract enables swapping native ETH <-> ERC20 tokens via Uniswap V2, Uniswap V3, and KyberSwap,
 *         applying a fixed percentage fee (in ETH) on each swap.
 */
contract DexedSwapServiceV1 is Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;

    /// @notice Address of WETH on Ethereum mainnet.
    address private constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    /// @notice Address of Uniswap V2 Router.
    IUniswapV2Router02 private constant uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);

    /// @notice Address of Uniswap V3 Router.
    ISwapRouter private constant uniswapV3Router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);

    /// @notice Marketing address for receiving fees.
    address public marketingAddress;

    /// @notice Fee percentage, e.g. 100 means 1% fee.
    uint256 public feePercent = 100;

    /**
     * @notice Ensures msg.value is not zero.
     */
    modifier checkValue() {
        if (msg.value == 0) revert NoETHSent();
        _;
    }

    /**
     * @notice Ensures swap path array has at least 2 elements.
     */
    modifier checkPath(address[] calldata path) {
        if (path.length < 2) revert InvalidPath();
        _;
    }

    /**
     * @notice Constructor for DexedSwapServiceV1.
     * @param _marketingAddress Address to receive fees.
     */
    constructor(address _marketingAddress) Ownable(_marketingAddress) {
        _updateMarketingAddress(_marketingAddress);
    }

    /**
     * @notice Updates the marketing address.
     * @param _marketingAddress New marketing address.
     */
    function updateMarketingAddress(address _marketingAddress) external onlyOwner {
        _updateMarketingAddress(_marketingAddress);
    }

    /**
     * @notice Updates the fee percentage, up to a maximum of 5%.
     * @param _feePercent New fee percentage (100 = 1%, 10 = 0.1%, etc.).
     */
    function updateFeePercent(uint256 _feePercent) external onlyOwner {
        if (_feePercent > 500) revert FeeExceedsLimit();
        feePercent = _feePercent;
    }

    /**
     * @notice Swaps ETH -> Tokens on Uniswap V2, taking an ETH fee.
     * @param amountOutMin Minimum output tokens.
     * @param path Swap path (first = address(0) or WETH, last = token).
     * @param deadline Swap deadline.
     */
    function swapETHForTokensUniswapV2(
        uint256 amountOutMin,
        address[] calldata path,
        uint256 deadline
    ) external payable nonReentrant checkValue checkPath(path) {
        address[] memory realPath = _mapETHtoWETH(path);
        uint256 netAmount = _deductFee(msg.value);

        IUniswapV2Router02(uniswapV2Router).swapExactETHForTokens{value: netAmount}(
            amountOutMin,
            realPath,
            msg.sender,
            deadline
        );
    }

    /**
     * @notice Swaps Tokens -> ETH on Uniswap V2, taking a fee in ETH.
     * @param amountIn Amount of input tokens.
     * @param amountOutMin Minimum ETH out.
     * @param path Swap path (first = token, last = address(0) or WETH).
     * @param deadline Swap deadline.
     */
    function swapTokensForETHUniswapV2(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        uint256 deadline
    ) external nonReentrant checkPath(path) {
        address[] memory realPath = _mapETHtoWETH(path);

        IERC20(path[0]).safeTransferFrom(msg.sender, address(this), amountIn);
        IERC20(path[0]).safeIncreaseAllowance(address(uniswapV2Router), amountIn);

        uint256[] memory amounts = IUniswapV2Router02(uniswapV2Router).swapExactTokensForETH(
            amountIn,
            amountOutMin,
            realPath,
            address(this),
            deadline
        );

        uint256 ethOut = amounts[amounts.length - 1];
        uint256 netAmount = _deductFee(ethOut);

        (bool sent, ) = msg.sender.call{value: netAmount}("");
        if (!sent) revert TransferFailed();
    }

    /**
    * @notice Swaps a specific amount of an input token for ETH via a Uniswap V2 pair containing WETH.
    * @dev This function interacts directly with a Uniswap V2 pair to perform the swap. 
    * It expects the pair to consist of the input token and WETH, and will revert if this condition is not met.
    * Additionally, it verifies that the output amount meets the minimum requirement and correctly handles fee 
    * deduction.
    *
    * @param pair The address of the Uniswap V2 pair contract.
    * @param tokenIn The address of the token being swapped into the pair.
    * @param amountIn The amount of `tokenIn` to swap.
    * @param amountOutMin The minimum amount of ETH expected from the swap to avoid slippage.
    *
    * @dev Reverts with `InvalidPath()` if the pair does not contain both the input token and WETH.
    * @dev Reverts with `InsufficientOutputAmount()` if the calculated output amount is less than `amountOutMin`.
    * @dev Reverts with `NoWETHSent()` if the received WETH balance is less than expected after swap.
    * @dev Reverts with `NoETHSent()` if sending ETH to the user fails.
    * 
    * @notice Ensure that the contract calling this function has approved the required `amountIn` of `tokenIn` 
    * to this contract before calling.
    */
    function swapTokensForETHViaPair(
        address pair,
        address tokenIn,
        uint256 amountIn,
        uint256 amountOutMin,
        uint16 sellTax
    ) external {
        IUniswapV2Pair pairContract = IUniswapV2Pair(pair);
        address token0 = pairContract.token0();
        address token1 = pairContract.token1();

        if ((token0 != tokenIn && token1 != tokenIn) || (token0 != WETH && token1 != WETH))
            revert InvalidPath();

        IERC20(tokenIn).safeTransferFrom(msg.sender, pair, amountIn);

        (uint112 reserve0, uint112 reserve1,) = pairContract.getReserves();
        (uint256 reserveIn, uint256 reserveOut) = (token0 == tokenIn)
            ? (reserve0, reserve1)
            : (reserve1, reserve0);
        uint256 amountOut = UniswapV2Library.getAmountOut(amountIn * sellTax / 10000, reserveIn, reserveOut);
        if (amountOut < amountOutMin) revert InsufficientOutputAmount();

        (uint256 amount0Out, uint256 amount1Out) = (token0 == tokenIn)
            ? (uint256(0), amountOut)
            : (amountOut, uint256(0));
        pairContract.swap(amount0Out, amount1Out, address(this), new bytes(0));

        uint256 wethBal = IERC20(WETH).balanceOf(address(this));
        if (wethBal < amountOut) revert NoWETHSent();

        IWETH(WETH).withdraw(wethBal);
        uint256 netEthToUser = _deductFee(wethBal);

        (bool sent, ) = msg.sender.call{value: netEthToUser}("");
        if (!sent) revert NoETHSent();
    }

    /**
     * @notice Swaps ETH -> Token on Uniswap V3 using exactInputSingle.
     * @param params Encoded (tokenIn, tokenOut, fee, amountIn, minAmount).
     */
    function swapETHForTokensUniswapV3(
        bytes calldata params
    ) external payable nonReentrant checkValue {
        (address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint256 minAmount) =
            abi.decode(params, (address, address, uint24, uint256, uint256));

        if (tokenIn != address(0)) revert InvalidAddress();

        uint256 netAmount = _deductFee(msg.value);
        if (amountIn > netAmount) revert TransferFailed();

        // Wrap netAmount in WETH
        IWETH(WETH).deposit{value: netAmount}();
        IWETH(WETH).approve(address(uniswapV3Router), netAmount);

        ISwapRouter.ExactInputSingleParams memory eisParams =
            ISwapRouter.ExactInputSingleParams({
                tokenIn: WETH,
                tokenOut: tokenOut,
                fee: fee,
                recipient: msg.sender,
                deadline: block.timestamp + 300,
                amountIn: amountIn,
                amountOutMinimum: minAmount,
                sqrtPriceLimitX96: 0
            });

        ISwapRouter(uniswapV3Router).exactInputSingle(eisParams);
    }

    /**
     * @notice Swaps Token -> ETH on Uniswap V3 using exactOutputSingle.
     * @param params Encoded (tokenIn, tokenOut, fee, amountOut).
     */
    function swapTokensForETHUniswapV3(
        bytes calldata params
    ) external nonReentrant {
        (address tokenIn, address tokenOut, uint24 fee, uint256 amountOut) =
            abi.decode(params, (address, address, uint24, uint256));

        if (tokenOut != address(0)) revert InvalidAddress();

        uint256 balanceIn = IERC20(tokenIn).balanceOf(msg.sender);
        if (balanceIn < amountOut) revert InsufficientOutputAmount();

        // Transfer tokens from user
        IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), balanceIn);
        IERC20(tokenIn).safeIncreaseAllowance(address(uniswapV3Router), balanceIn);

        // Prepare params for exactOutputSingle
        ISwapRouter.ExactOutputSingleParams memory eosParams =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: tokenIn,
                tokenOut: WETH,
                fee: fee,
                recipient: address(this),
                deadline: block.timestamp + 1800,
                amountOut: amountOut,
                amountInMaximum: balanceIn,
                sqrtPriceLimitX96: 0
            });

        ISwapRouter(uniswapV3Router).exactOutputSingle(eosParams);

        // Check WETH balance
        uint256 wethBalance = IERC20(WETH).balanceOf(address(this));
        if (wethBalance < amountOut) revert InsufficientOutputAmount();

        // Unwrap all
        IWETH(WETH).withdraw(wethBalance);

        // Deduct fee
        uint256 netAmount = _deductFee(wethBalance);

        // Send ETH to user
        (bool sent, ) = msg.sender.call{value: netAmount}("");
        if (!sent) revert TransferFailed();
    }

    /**
     * @notice Returns the amounts out for a swap on Uniswap V2 via `getAmountsOut`.
     * @dev For an ETH->Token or Token->ETH swap, replace the zero address with WETH in the path
     *      before calling this function.
     * @param amountIn Input amount.
     * @param path Swap path (length >= 2).
     * @return amounts Array of output amounts for each intermediate step.
     */
    function getAmountsOutUniswapV2(
        uint256 amountIn,
        address[] calldata path
    ) external view returns (uint[] memory amounts) {
        return IUniswapV2Router02(uniswapV2Router).getAmountsOut(amountIn, path);
    }

    /**
     * @notice Internal function that deducts fee from the given amount of ETH.
     * @param amount Amount of ETH.
     * @return netAmount Amount after deducting fee.
     */
    function _deductFee(uint256 amount) internal returns (uint256 netAmount) {
        uint256 fee = (amount * feePercent) / 10000;

        (bool sent, ) = marketingAddress.call{value: fee}("");
        if (!sent) revert TransferFailed();

        netAmount = amount - fee;
    }

    /**
     * @notice Updates the marketing address.
     * @param _marketingAddress New marketing address.
     */
    function _updateMarketingAddress(address _marketingAddress) internal {
        if (_marketingAddress == address(0)) revert InvalidAddress();
        marketingAddress = _marketingAddress;
    }

    /**
     * @notice Replaces any zero address in the path (ETH) with WETH, for Uniswap V2 swaps.
     * @param path Original path from user input.
     * @return newPath A copy where address(0) is replaced by WETH if found at start or end.
     */
    function _mapETHtoWETH(address[] calldata path) internal pure returns (address[] memory newPath) {
        newPath = new address[](path.length);
        for (uint i = 0; i < path.length; i++) {
            newPath[i] = path[i];
        }
        // If first element is zero address, replace with WETH
        if (newPath[0] == address(0)) {
            newPath[0] = WETH;
        }
        // If last element is zero address, replace with WETH
        uint lastIndex = newPath.length - 1;
        if (newPath[lastIndex] == address(0)) {
            newPath[lastIndex] = WETH;
        }
    }

    /**
     * @dev Allows receiving ETH from WETH withdraw.
     */
    receive() external payable {}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 198 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IUniswapV2Router01.sol 95 lines
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
IUniswapV2Router02.sol 44 lines
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}
IUniswapV3SwapCallback.sol 21 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}
ISwapRouter.sol 67 lines
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';

/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
Errors.sol 13 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

/**
 * @dev Custom errors.
 */
error InvalidAddress();
error TransferFailed();
error InsufficientOutputAmount();
error NoETHSent();
error NoWETHSent();
error InvalidPath();
error FeeExceedsLimit();
IUniswapV2Pair.sol 18 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

interface IUniswapV2Pair {
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (
        uint112 _reserve0,
        uint112 _reserve1,
        uint32 _blockTimestampLast
    );
    function swap(
        uint256 amount0Out,
        uint256 amount1Out,
        address to,
        bytes calldata data
    ) external;
}
IWETH.sol 9 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

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

interface IWETH is IERC20 {
    function deposit() external payable;
    function withdraw(uint256 wad) external;
}
UniswapV2Library.sol 18 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

library UniswapV2Library {
    // Классическая формула Uniswap V2 (без учёта fee-on-transfer внутри пула)
    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) internal pure returns (uint256 amountOut) {
        // В обычной Uniswap V2 (0.3% fee) множитель 997, здесь — 1000 - 3 = 997
        // Если фи другая — подставьте нужные числа
        uint256 amountInWithFee = amountIn * 997;
        uint256 numerator = amountInWithFee * reserveOut;
        uint256 denominator = reserveIn * 1000 + amountInWithFee;
        amountOut = numerator / denominator;
    }
}

Read Contract

feePercent 0x7fd6f15c → uint256
getAmountsOutUniswapV2 0x9023e182 → uint256[]
marketingAddress 0xa5ece941 → address
owner 0x8da5cb5b → address

Write Contract 9 functions

These functions modify contract state and require a wallet transaction to execute.

renounceOwnership 0x715018a6
No parameters
swapETHForTokensUniswapV2 0xfc7fb499
uint256 amountOutMin
address[] path
uint256 deadline
swapETHForTokensUniswapV3 0x62192f34
bytes params
swapTokensForETHUniswapV2 0x44dba380
uint256 amountIn
uint256 amountOutMin
address[] path
uint256 deadline
swapTokensForETHUniswapV3 0xf97b04e5
bytes params
swapTokensForETHViaPair 0x4215c1e9
address pair
address tokenIn
uint256 amountIn
uint256 amountOutMin
uint16 sellTax
transferOwnership 0xf2fde38b
address newOwner
updateFeePercent 0xf05c5fed
uint256 _feePercent
updateMarketingAddress 0x2369bf83
address _marketingAddress

Recent Transactions

No transactions found for this address