Skip to content
Verified contractExactUNLICENSED

TokenFactoryV2

Address0x6c5cf7036b0de9b3ac388fbbe3f5fa5dfa57552e
Balance

1.324477 ETH

 

Transactions

19

 

Compiler

solc 0.8.20

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
shanghai
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,036,547
Creation transaction
0x1d86471e20…c426f01915

src/vista/TokenFactory.sol

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

import {ITokenLogic, TokenLogicV2} from "./TokenLogic.sol";
// utils
import {IERC20} from "../IERC20.sol";
import {IXpRouter} from "../IXpRouter.sol";
import {IXpFactory} from "../IXpFactory.sol";

interface ITokenFactory {
    enum LaunchStatus {
        LAUNCH_ACTIVE,
        LIQUIDITY_BURNED,
        LIQUIDITY_REFUNDED
    }

    struct TokenInfo {
        bool isChildToken;
        uint256 uniqueId;
        LaunchStatus launchStatus;
        uint256 feesReceived; // eth amount received so far from the token
    }

    function childTokens(address) external view returns (bool, uint256, LaunchStatus, uint256);
    function getTokenUniqueId(address token) external view returns (bytes32);
}

interface IExcempt {
    function addExemptFromFee(address _address) external;
}

contract TokenFactoryV2 is ITokenFactory {
    bytes public constant TOKEN_PROXY_BYTECODE =
        hex"60a060405234801561000f575f80fd5b506040516102dc3803806102dc833981810160405281019061003191906100c9565b8073ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff1681525050506100f4565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100988261006f565b9050919050565b6100a88161008e565b81146100b2575f80fd5b50565b5f815190506100c38161009f565b92915050565b5f602082840312156100de576100dd61006b565b5b5f6100eb848285016100b5565b91505092915050565b6080516101cb6101115f395f81816030015260ea01526101cb5ff3fe60806040526004361061002c575f3560e01c8063629c52a914610070578063d77177501461009a5761002d565b5b5f7f00000000000000000000000000000000000000000000000000000000000000009050365f80375f80365f845af43d5f803e805f811461006c573d5ff35b3d5ffd5b34801561007b575f80fd5b506100846100c4565b6040516100919190610124565b60405180910390f35b3480156100a5575f80fd5b506100ae6100e8565b6040516100bb919061017c565b60405180910390f35b7f10eeeeffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f819050919050565b61011e8161010c565b82525050565b5f6020820190506101375f830184610115565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6101668261013d565b9050919050565b6101768161015c565b82525050565b5f60208201905061018f5f83018461016d565b9291505056fea26469706673582212208caaf51ee3f849b605f6e63e26072b5c076726d07d40423546787cda62f1dc5b64736f6c63430008140033";
    bytes public TOKEN_PROXY_DEPLOY_BYTECODE; // deployment bytecode got from TOKEN_PROXY_BYTECODE and constructor argument (token logic)
    uint256 public uniqueId = 0x1000200000000000000000000000000000000000000000000000000000000000; // first child token unique id (used to keep track of token bytecode uniqueness)

    address payable public protocolFeesRecipient;

    address public immutable tokenLogic; // token logic passed to the newly created tokens

    IXpRouter public uniswapRouter;
    IXpFactory immutable uniswapFactory;

    uint8 public stakingFees = 50; // percentage of protocol fees forwarded to staking
    address payable public stakingContract;

    bool private stakingRenounced;

    address public owner;

    address public vitalikAddress;

    mapping(address => TokenInfo) public childTokens;
    mapping(address => address[]) public tokensDeployed;
    mapping(address => bool) public withdrawalAddresses;
    mapping(address => uint256) public tokenInitialLiquidity;

    event TokenCreated(address indexed token, address indexed deployer, string name, string symbol);
    event Socials(address token, string telegram, string website, string twitter, string logo);
    event LiquidityBurned(address indexed token);
    event LiquidityRefunded(address indexed token);

    constructor(address _protocolFeesRecipient, address _stakingContract, address _uniswapRouter, address _hardlock) {
        protocolFeesRecipient = payable(_protocolFeesRecipient);
        uniswapRouter = IXpRouter(payable(_uniswapRouter));
        tokenLogic = address(new TokenLogicV2(address(this), _uniswapRouter, _hardlock));

        // concatenate base creation bytecode of token proxy with token logic (token proxy constructor parameter)
        TOKEN_PROXY_DEPLOY_BYTECODE = abi.encodePacked(TOKEN_PROXY_BYTECODE, abi.encode(tokenLogic));

        uniswapFactory = IXpFactory(uniswapRouter.factory());

        stakingContract = payable(_stakingContract);

        owner = msg.sender;
    }

    function updateOwner(address _owner) external {
        require(msg.sender == owner, "Unauthorized");
        owner = _owner;
    }

    function setVitalikAddress(address _vitalikAddress) external {
        require(msg.sender == owner, "Unauthorized");
        vitalikAddress = _vitalikAddress;
    }

    function setUniswapRouter(address _uniswapRouter) external {
        require(msg.sender == owner, "Unauthorized");
        uniswapRouter = IXpRouter(payable(_uniswapRouter));
    }

    modifier onlyEoa() {
        require(tx.origin == msg.sender, "Not EOA");
        _;
    }

    function setStaking(address _stakingContract, uint8 _stakingFees) external {
        require(msg.sender == protocolFeesRecipient && !stakingRenounced);
        require(_stakingFees <= 100, "Invalid fees");
        stakingFees = _stakingFees;
        stakingContract = payable(_stakingContract);
    }

    function setProtocolFeesRecipient(address payable _protocolFeesRecipient) external {
        require(msg.sender == protocolFeesRecipient);
        protocolFeesRecipient = _protocolFeesRecipient;
    }

    function renounceStakingUpgrade() external {
        require(msg.sender == protocolFeesRecipient);
        stakingRenounced = true;
    }

    // deploy a child token with its name and symbol and return its address
    function deployToken(
        string memory _name,
        string memory _symbol,
        string memory _telegram,
        string memory _website,
        string memory _twitter,
        string memory _logo,
        string memory _description,
        uint256 toVitalik
    ) external payable onlyEoa returns (address) {
        require(msg.value == 1 ether || msg.value == 2 ether || msg.value == 3 ether, "Wrong initial liquidity");

        require(toVitalik == 10 || toVitalik == 25 || toVitalik == 50, "Wrong vitaleek share");
        address deployer = msg.sender;
        address token = deployNewBytecode();

        TokenLogicV2(payable(token)).initialize{value: msg.value}(
            deployer, _name, _symbol, 5, 5, 5, 10, toVitalik, vitalikAddress
        );

        TokenLogicV2(payable(token)).setSocials(_telegram, _website, _twitter, _logo, _description);

        IExcempt(address(uniswapRouter)).addExemptFromFee(token);

        childTokens[token].isChildToken = true;
        childTokens[token].uniqueId = uniqueId - 1;
        tokensDeployed[deployer].push(token);

        tokenInitialLiquidity[token] = msg.value;

        emit TokenCreated(token, deployer, _name, _symbol);
        emit Socials(token, _telegram, _website, _twitter, _logo);

        return token;
    }

    // deploy a new token proxy bytecode with the current uniqueId
    function deployNewBytecode() private returns (address token) {
        bytes memory bytecode = TOKEN_PROXY_DEPLOY_BYTECODE;
        bytes32 _id = bytes32(uniqueId);

        assembly {
            mstore(add(bytecode, 503), _id) // dynamically replace the current unique id in the bytecode to deploy

            token := create(0, add(bytecode, 0x20), mload(bytecode))

            if iszero(extcodesize(token)) { revert(0, 0) }
        }
        uniqueId++;
    }

    // receive function, used by the child tokens to forward fees from tokens swaps
    receive() external payable {
        address token = msg.sender;
        if (token == address(uniswapRouter)) return;

        require(childTokens[token].isChildToken, "Unknown token");

        childTokens[token].feesReceived += msg.value;

        bool result = _tryBurn(token);

        // stop acumulating fees and distribute if launch is active
        if (!result && childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) {
            uint256 protocolFees = msg.value / 5;
            _distributeFees(token, msg.value - protocolFees, protocolFees);
        }
    }

    // Function to receive ETH without triggering fallback when removing liquidity
    function receiveEth() external payable {}

    // allow to externally withdraw liquidity (in case there is no tx for a while)
    function withdrawLiquidity(address token) external {
        require(childTokens[token].isChildToken == true, "Unknown token");
        require(msg.sender == ITokenLogic(token).deployer() || withdrawalAddresses[msg.sender], "Unauthorized");

        // if liquidity is already burned or refunded, then checking for burn is useless
        if (childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) return;

        // if we could burn lp, just return
        if (_tryBurn(token)) return;

        require(block.timestamp - ITokenLogic(token).launchTimestamp() > 5 days, "Token not ready to refund");

        childTokens[token].launchStatus = LaunchStatus.LIQUIDITY_REFUNDED;

        // Remove liquidity and keep track of the amount of token and eth removed
        uint256 amountToken = IERC20(token).balanceOf(address(this));
        uint256 ethBalance = address(this).balance;

        uint256 amountETH = TokenLogicV2(payable(token)).withdrawLiquidity();

        ethBalance = address(this).balance - ethBalance;
        amountToken = IERC20(token).balanceOf(address(this)) - amountToken;

        IERC20(token).burn(amountToken);

        // refund eth from liquidity back to deployer 1 ether and tip the protocol with the remainder
        (uint256 deployerFees, uint256 protocolFees) = getTokenFees(token);

        uint256 initialLiquidity = tokenInitialLiquidity[token];

        uint256 protocolTip;
        uint256 deployerRefund;
        uint256 buyBackAmount;

        if (amountETH >= initialLiquidity) {
            protocolTip = amountETH - initialLiquidity;
            deployerRefund = initialLiquidity;
            buyBackAmount = deployerFees;
        } else {
            uint256 devAvailableEth = amountETH + deployerFees;
            protocolTip = 0;
            deployerRefund = min(initialLiquidity, devAvailableEth);
            buyBackAmount = devAvailableEth > initialLiquidity ? devAvailableEth - initialLiquidity : 0;
        }

        _distributeFees(token, deployerRefund, protocolTip + protocolFees);

        // Send excess fees to the protocol
        if (buyBackAmount > 0) {
            (bool result,) = protocolFeesRecipient.call{value: buyBackAmount}("");
            require(result, "Failed to send excess fees to protocol");
        }

        emit LiquidityRefunded(token);
    }

    function externalTryBurn(address token) external {
        require(childTokens[token].isChildToken == true, "Unknown token");

        _tryBurn(token);
    }

    function _tryBurn(address token) private returns (bool) {
        // if liquidity is already burned or refunded, then checking for burn is useless
        if (childTokens[token].launchStatus != LaunchStatus.LAUNCH_ACTIVE) return false;

        (uint256 deployerFees, uint256 protocolFees) = getTokenFees(token);
        uint256 initialLiquidity = tokenInitialLiquidity[token];
        // check if we can burn the liquidity
        if (deployerFees >= initialLiquidity) {
            childTokens[token].launchStatus = LaunchStatus.LIQUIDITY_BURNED;

            // Lock token instead of burning
            TokenLogicV2(payable(token)).lock();

            _distributeFees(token, deployerFees, protocolFees);

            emit LiquidityBurned(token);
            return true;
        }
        return false;
    }

    function getTokenFees(address token) public view returns (uint256 deployerFees, uint256 protocolFees) {
        uint256 totalFees = childTokens[token].feesReceived;
        protocolFees = totalFees / 5;
        deployerFees = totalFees - protocolFees;
    }

    // distribute fees to token deployer and protocol fees recipient
    function _distributeFees(address token, uint256 deployerFees, uint256 protocolFees) private {
        // refund deployer
        if (deployerFees != 0) {
            (bool result,) = ITokenLogic(token).deployer().call{value: deployerFees}("");
            require(result, "Failed to refund deployer");
        }
        // distribute protocol fees
        if (protocolFees != 0) {
            uint256 feesToStaking = (stakingFees * protocolFees) / 100;
            uint256 feesToDev = protocolFees - feesToStaking;
            if (feesToDev != 0) {
                (bool result,) = protocolFeesRecipient.call{value: feesToDev}("");
                require(result, "Failed to forward");
            }
            if (feesToStaking != 0) {
                (bool result,) = stakingContract.call{value: feesToStaking}("");
                require(result, "Failed to forward");
            }
        }
    }

    function feeAccrued(address token) external view returns (uint256) {
        return childTokens[token].feesReceived;
    }

    // return token unique id in bytes32
    function getTokenUniqueId(address token) external view returns (bytes32) {
        return bytes32(childTokens[token].uniqueId);
    }

    function getTokenData(ITokenLogic token) external view returns (uint256, LaunchStatus) {
        TokenInfo memory infos = childTokens[address(token)];
        return (infos.feesReceived, infos.launchStatus);
    }

    function getChildTokenFees(ITokenLogic token) external view returns (uint8) {
        uint256 tokenFeesTier = uint8(ITokenLogic(address(token)).feesTier());
        if (tokenFeesTier == 0) return 20;
        if (tokenFeesTier == 1) return 5;
        else return childTokens[address(token)].isChildToken ? 0 : 1;
    }

    function getTokensDeployed(address deployer) external view returns (address[] memory) {
        return tokensDeployed[deployer];
    }

    function min(uint256 a, uint256 b) private pure returns (uint256) {
        return a < b ? a : b;
    }
}

src/Context.sol

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

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

src/ERC20Logic.sol

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

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

interface IERC20Metadata is IERC20 {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
}

// contract implementing the logic of ERC20 standard (thus usable from proxies)
contract ERC20Logic is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 public totalSupply;

    string public name;
    string public symbol;

    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    function burn(uint256 value) public virtual {
        _burn(_msgSender(), value);
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        _balances[sender] = senderBalance - amount;
        _balances[recipient] += amount;
        emit Transfer(sender, recipient, amount);
    }

    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);
    }

    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        totalSupply -= amount;

        emit Transfer(account, address(0), amount);
    }

    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
}

src/IERC20.sol

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

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function burn(uint256 value) external;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

src/IWETH.sol

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

interface IWETH {
    function deposit() external payable;
    function transfer(address to, uint256 value) external returns (bool);
    function withdraw(uint256) external;
    function approve(address spender, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

src/IXpFactory.sol

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

interface IXpFactory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint256);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);
    function routerSetter() external view returns (address);
    function router() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint256) external view returns (address pair);
    function allPairsLength() external view returns (uint256);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
    function setRouterSetter(address) external;
    function setRouter(address) external;
}

src/IXpPair.sol

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

interface IXpPair {
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Transfer(address indexed from, address indexed to, uint256 value);

    function setMetadata(
        string calldata website,
        string calldata image,
        string calldata description,
        string calldata chat,
        string calldata social
    ) external;
    function fetchMetadata()
        external
        view
        returns (string memory, string memory, string memory, string memory, string memory);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint256);
    function balanceOf(address owner) external view returns (uint256);
    function allowance(address owner, address spender) external view returns (uint256);

    function updateProvider(address user) external;
    function euler(uint256) external view returns (uint256);
    function viewShare() external view returns (uint256 share);
    function claimShare() external;
    function poolBalance() external view returns (uint256);
    function totalCollected() external view returns (uint256);

    function updateProtocol(address) external;
    function setProtocol() external;
    function protocol() external view returns (address);
    function payableProtocol() external view returns (address payable origin);

    function creator() external view returns (address);
    function renounce() external;

    function setFees() external;
    function updateFees(uint8, uint8, uint8, uint8) external;
    function buyLpFee() external view returns (uint8);
    function sellLpFee() external view returns (uint8);
    function buyProtocolFee() external view returns (uint8);
    function sellProtocolFee() external view returns (uint8);
    function buyTotalFee() external view returns (uint8);
    function sellTotalFee() external view returns (uint8);

    function approve(address spender, uint256 value) external returns (bool);
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint256);

    function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        external;

    event Mint(address indexed sender, uint256 amount0, uint256 amount1);
    event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint256);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint256);
    function price1CumulativeLast() external view returns (uint256);
    function kLast() external view returns (uint256);

    function first_mint(
        address to,
        uint8 buyLp,
        uint8 sellLp,
        uint8 buyProtocol,
        uint8 sellProtocol,
        address protocolAddress
    ) external returns (uint256 liquidity);
    function mint(address to) external returns (uint256 liquidity);
    function burn(address to) external returns (uint256 amount0, uint256 amount1);
    function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address _token0, address _token1) external;
}

src/IXpRouter.sol

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

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

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        uint256 deadline
    ) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);

    function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
    function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
        external
        pure
        returns (uint256 amountOut);
    function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
        external
        pure
        returns (uint256 amountIn);
    function getAmountsOut(uint256 amountIn, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);
    function getAmountsIn(uint256 amountOut, address[] calldata path)
        external
        view
        returns (uint256[] memory amounts);

    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        uint256 deadline
    ) external returns (uint256 amountETH);

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

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

    function launch(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        uint8 buyLpFee,
        uint8 sellLpFee,
        uint8 buyProtocolFee,
        uint8 sellProtocolFee,
        address protocolAddress
    ) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);

    function updateSelf(address _token) external;

    function safeTransferLp(address _token, address to, uint256 _amount) external;

    function hardstake(address _contract, address _token, uint256 _amount) external;

    function exemptFromFee(address _address) external returns (bool);
}

src/vista/EthSplitter.sol

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

contract EthSplitter {
    address public tokenStaking = 0x4547BC9cC66725d8A607ACbB6D8A94E8ccdb48e1;
    address public protocolReceiver = 0x4547BC9cC66725d8A607ACbB6D8A94E8ccdb48e1;
    address public deployer;

    constructor(address _deployer) {
        deployer = _deployer;
    }

    function split() external payable {
        // 50% Deployer of token
        // 25% $XP LP Staking rewards
        // 25% $XP team
        uint256 deployerAmount = msg.value / 2;
        uint256 stakingAmount = msg.value / 4;
        uint256 teamAmount = msg.value / 4;

        (bool success,) = payable(deployer).call{value: deployerAmount}("");
        require(success, "Transfer failed");

        (success,) = payable(tokenStaking).call{value: stakingAmount}("");
        require(success, "Transfer failed");

        (success,) = payable(protocolReceiver).call{value: teamAmount}("");
        require(success, "Transfer failed");
    }

    function _split() internal {
        uint256 deployerAmount = msg.value / 2;
        uint256 stakingAmount = msg.value / 4;
        uint256 teamAmount = msg.value / 4;

        (bool success,) = payable(deployer).call{value: deployerAmount}("");
        require(success, "Transfer failed");

        (success,) = payable(tokenStaking).call{value: stakingAmount}("");
        require(success, "Transfer failed");

        (success,) = payable(protocolReceiver).call{value: teamAmount}("");
        require(success, "Transfer failed");
    }

    fallback() external payable {
        _split();
    }

    receive() external payable {
        _split();
    }
}

src/vista/TokenLogic.sol

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

// utils
import {ERC20Logic} from "../ERC20Logic.sol";
import {IXpRouter} from "../IXpRouter.sol";
import {IXpFactory} from "../IXpFactory.sol";
import {IXpPair} from "../IXpPair.sol";
import {IWETH} from "../IWETH.sol";
import {EthSplitter} from "./EthSplitter.sol";
import {TokenFactoryV2} from "./TokenFactory.sol";

interface ITokenLogic {
    enum FeesTier {
        HIGH_FEES, // 20/20 fees the first 5 minutes
        MEDIUM_FEES, // 5/5 fees until contract has less than 1% of the supply to sell
        NO_FEES // 0/0 then

    }

    function feesTier() external view returns (FeesTier);
    function initialize(
        address _deployer,
        string memory _name,
        string memory _symbol,
        uint8 lpBuyFee,
        uint8 lpSellFee,
        uint8 protocolBuyFee,
        uint8 protocolSellFee,
        uint256 toVitalik,
        address vitalikAddress
    ) external payable;
    function launchTimestamp() external view returns (uint256);
    function deployer() external view returns (address payable);
}

interface IHardlock {
    function claimShare(address token) external;
}

// token logic (code used by token proxies contracts)
contract TokenLogicV2 is ERC20Logic, ITokenLogic {
    // - token logic constants (not colliding proxies storages)

    uint256 private constant HIGH_FEES_DURATION = 300; // duration of the high fees stage (20% during 5 minutes)
    uint256 private constant LIMITS_DURATION = 1800; // duration of max tx and max wallet limits in seconds (30 minutes)
    uint256 private constant BASE_TOTAL_SUPPLY = 1_000_000_000 * 10 ** 18;
    uint256 public constant MAX_TX_AMOUNT = (1 * BASE_TOTAL_SUPPLY) / 100; // max tx 10M (1%)
    uint256 public constant MAX_WALLET_AMOUNT = (3 * BASE_TOTAL_SUPPLY) / 100; // max wallet 30M (3%)
    uint256 private constant LIQUIDITY_AMOUNT = (80 * BASE_TOTAL_SUPPLY) / 100; // uniswap liquidity (80%)

    bool initialLiquidityAdded = false;

    address public immutable tokenFactory;
    address public immutable WETH;

    IXpFactory public immutable uniswapFactory;
    IXpRouter public immutable uniswapRouter;

    // - instance token storage (stored in each token proxies)
    bool _swapping;

    uint256 public launchTimestamp; // token launch timestamp

    address payable public deployer;
    address public uniswapPair;

    FeesTier public feesTier; // current token fees tier (could be outdated and updated during the transaction)

    // Used to having custom distribution without triggering this contract's fallback
    address private userSplitter;

    string public telegram;
    string public website;
    string public twitter;
    string public logo;
    string public description;

    IHardlock public immutable hardlock;

    constructor(address _tokenFactory, address _router, address _hardlock) {
        tokenFactory = _tokenFactory;
        uniswapRouter = IXpRouter(payable(_router));
        uniswapFactory = IXpFactory(uniswapRouter.factory());
        WETH = uniswapRouter.WETH();
        hardlock = IHardlock(_hardlock);
    }

    modifier lockSwap() {
        _swapping = true;
        _;
        _swapping = false;
    }

    // initialize new token datas (called from the factory to the token proxy delegating the call here)
    function initialize(
        address _deployer,
        string memory _name,
        string memory _symbol,
        uint8 lpBuyFee,
        uint8 lpSellFee,
        uint8 protocolBuyFee,
        uint8 protocolSellFee,
        // Can be 1%, 2.5% or 5% of total supply
        uint256 toVitalik,
        address vitalikAddress
    ) external payable {
        require(msg.sender == tokenFactory, "Unauthorized"); // initialized only on the same deployment transaction from token factory
        require(msg.value == 1 ether || msg.value == 2 ether || msg.value == 3 ether, "Wrong initial liquidity");

        name = _name;
        symbol = _symbol;
        deployer = payable(_deployer);

        launchTimestamp = block.timestamp;

        uint256 toVitalik_ = (BASE_TOTAL_SUPPLY * toVitalik) / 1000;
        _mint(address(this), BASE_TOTAL_SUPPLY - LIQUIDITY_AMOUNT - toVitalik_); // mint clogged amount to the contract

        _mint(vitalikAddress, toVitalik_);

        uniswapPair = uniswapFactory.createPair(address(this), WETH);

        _mint(address(this), LIQUIDITY_AMOUNT); // mint liquidity amount to the pair

        _approve(address(this), address(uniswapRouter), LIQUIDITY_AMOUNT);

        address userSplitter_ = address(new EthSplitter(_deployer));

        uniswapRouter.launch{value: msg.value}(
            address(this), LIQUIDITY_AMOUNT, 0, 0, lpBuyFee, lpSellFee, protocolBuyFee, protocolSellFee, userSplitter_
        );

        userSplitter = userSplitter_;
        initialLiquidityAdded = true;
    }

    function setSocials(
        string memory _telegram,
        string memory _website,
        string memory _twitter,
        string memory _logo,
        string memory _description
    ) external {
        require(msg.sender == tokenFactory, "Unauthorized");

        telegram = _telegram;
        website = _website;
        twitter = _twitter;
        logo = _logo;
        description = _description;
    }

    // If the token is locked, the protocol share is claimed from the hardlock contract
    function claimProtocolShare(bool _isLocked) external {
        if (_isLocked) {
            uint256 balanceBefore = address(this).balance;
            hardlock.claimShare(address(uniswapPair));
            uint256 balanceAfter = address(this).balance;

            uint256 amount = balanceAfter - balanceBefore;

            (bool sent,) = payable(userSplitter).call{value: amount}("");

            require(sent, "Failed to send Ether");
        } else {
            uint256 balanceBefore = address(this).balance;
            IXpPair(payable(uniswapPair)).claimShare();
            uint256 balanceAfter = address(this).balance;

            uint256 amount = balanceAfter - balanceBefore;

            (bool sent,) = payable(userSplitter).call{value: amount}("");

            require(sent, "Failed to send Ether");
        }
    }

    function _transfer(address sender, address recipient, uint256 amount) internal override {
        if (_swapping) return super._transfer(sender, recipient, amount);

        uint256 fees = _takeFees(sender, recipient, amount);

        if (fees != 0) {
            super._transfer(sender, address(this), fees);
            amount -= fees;
        }

        if (initialLiquidityAdded && recipient == uniswapPair) _swapFees(amount);

        super._transfer(sender, recipient, amount);

        if (initialLiquidityAdded) _forwardFees();
    }

    // Instead of burning liquidity, we lock it in the hardlock contract
    // After lock, the protocol share is claimed from the hardlock instead of pair
    function lock() external {
        require(msg.sender == tokenFactory, "Unauthorized");

        ERC20Logic(address(uniswapPair)).approve(
            address(uniswapRouter), ERC20Logic(address(uniswapPair)).balanceOf(address(this))
        );

        uniswapRouter.hardstake(
            address(hardlock), address(uniswapPair), ERC20Logic(address(uniswapPair)).balanceOf(address(this))
        );
    }

    // return fees amount taken from the transfer (and check for tx and wallet limits)
    function _takeFees(address sender, address recipient, uint256 amount) private returns (uint256) {
        if (
            (sender != uniswapPair && recipient != uniswapPair) || recipient == tokenFactory || sender == address(this)
                || recipient == address(uniswapRouter)
        ) return 0;

        // ensure max tx and max wallet
        if (limitsActive() && sender == uniswapPair) {
            uint256 maxWalletAmount = MAX_TX_AMOUNT * 2;
            require(amount <= maxWalletAmount, "Max tx amount reached");
            require(balanceOf(recipient) + amount <= maxWalletAmount, "Max wallet amount reached");
        }

        // if token has no fees tier, fees are immutable at 0%
        if (feesTier == FeesTier.NO_FEES) {
            return 0;
        } // 0% fees
        // else, if token has medium fees, check if we can change tier and return correct fees
        else if (feesTier == FeesTier.MEDIUM_FEES) {
            if (balanceOf(address(this)) <= totalSupply / 100) {
                feesTier = FeesTier.NO_FEES;
                return 0; // 0% fees
            }
            return amount / 20; // 5% fees
        }
        // else, token is at high fees tier and we check if we can change tier and return correct fees
        else {
            if (block.timestamp - launchTimestamp > HIGH_FEES_DURATION) {
                feesTier = FeesTier.MEDIUM_FEES;
                return amount / 20; // 5% fees
            }
            return amount / 5; // 20% fees
        }
    }

    // swap some fees tokens to eth
    function _swapFees(uint256 maxAmount) private lockSwap {
        uint256 tokenAmount = min(min(maxAmount, balanceOf(address(this))), totalSupply / 100);
        if (tokenAmount < 1e18) return; // prevent too small swaps
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = WETH;

        _approve(address(this), address(uniswapRouter), tokenAmount);

        uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount, 0, path, address(this), block.timestamp
        );
    }

    function withdrawLiquidity() external returns (uint256) {
        require(msg.sender == tokenFactory, "Unauthorized");

        uint256 hereBalanceOfLp = ERC20Logic(address(uniswapPair)).balanceOf(address(this));

        uint256 balanceHereBefore = balanceOf(address(this));
        ERC20Logic(address(uniswapPair)).approve(address(uniswapRouter), hereBalanceOfLp);

        uint256 ethReceived = uniswapRouter.removeLiquidityETHSupportingFeeOnTransferTokens(
            address(this), hereBalanceOfLp, 0, 0, block.timestamp
        );

        // Avoid triggering fallback
        TokenFactoryV2(payable(tokenFactory)).receiveEth{value: ethReceived}();

        uint256 balanceHereAfter = balanceOf(address(this));

        uint256 amountWithdrawn = balanceHereAfter - balanceHereBefore;

        // Send received tokens to factory
        _transfer(address(this), msg.sender, amountWithdrawn);

        return ethReceived;
    }

    // return true if max wallet and max tx limitations are still active
    function limitsActive() public view returns (bool) {
        return block.timestamp - launchTimestamp <= LIMITS_DURATION;
    }

    // forward contract fees to token factory (also try to burn liquidity)
    function _forwardFees() private {
        uint256 balance = address(this).balance;

        if (balance == 0) return;

        (bool result,) = tokenFactory.call{value: balance}("");
        require(result, "Failed to forward fees");
    }

    function min(uint256 a, uint256 b) private pure returns (uint256) {
        return a < b ? a : b;
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": [
    ":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    ":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    ":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    ":forge-std/=lib/forge-std/src/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.