Skip to main content
PulseScanner.io

Address

0x6710684bfd5eaaa79654ea8683054c780dbe9fa9
Current Holdings
$0.00
TXs sent
not counted
First Active
2024-05-28
block 20,484,786
Last Active
843 days ago
block 20,484,786
Funded By
not identified

Net worth historyi

No net-worth snapshots recorded yet
partial matchTokenFactorysolc 0.8.26+commit.8a97fa7aruntime partial · creation not verified
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "./libraries/SimpleFairToken.sol"; // Ensure this import points to the correct ERC20 implementation
import "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract TokenFactory is UUPSUpgradeable, PausableUpgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
    address public uniswapRouter;
    uint256 public factoryFee; // Factory fee set to 1000 ETH
    uint256 public minETHLiquidity; // Factory fee set to 1000 ETH
    address public  DEAD_ADDRESS;
    address[] public deployedTokens; // Array to store addresses of deployed tokens
    address public fairDexTokenAddress;
    using SafeMath for uint256;
    using SafeERC20 for IERC20;

    event TokenCreated(address tokenAddress);

    function initialize(address _uniswapRouter, address _fairDexTokenAddress) initializer public {
        __Ownable_init(msg.sender);
        __Pausable_init();
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();
        uniswapRouter = _uniswapRouter;
        factoryFee = 1000 ether; 
        minETHLiquidity = 10000 ether;
        fairDexTokenAddress = _fairDexTokenAddress;
        DEAD_ADDRESS=address(0x0000000000000000000000000000000000000369);
    }

    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

    function setSwapRouter(address _uniswapRouter) external onlyOwner {
        uniswapRouter = _uniswapRouter;
    }

    function setFairDexTokenAddress(address _fairDexTokenAddress) external onlyOwner {
        fairDexTokenAddress = _fairDexTokenAddress;
    }


    function createTokenAndAddLiquidity(
        string memory _name,
        string memory _symbol,
        uint _supply
       
    ) external payable nonReentrant whenNotPaused {
         require(msg.value >= factoryFee.add(minETHLiquidity) , "Incorrect ETH amount sent");
        // Deploy new ERC20 token
        SimpleFairToken _token = new SimpleFairToken(_name, _symbol, _supply);
        deployedTokens.push(address(_token)); // Track deployed token
        emit TokenCreated(address(_token));
        IERC20 token =IERC20(_token);
       
        IUniswapV2Router02 router = IUniswapV2Router02(uniswapRouter);
        IUniswapV2Factory factory = IUniswapV2Factory(router.factory());
        if (factory.getPair(router.WETH(), address(token)) == address(0)) {
            factory.createPair(router.WETH(), address(token));
        }

        require(token.approve(uniswapRouter, token.totalSupply()),'Approval Failed');

        require(factory.getPair(router.WETH(), address(token)) != address(0),'Pair creation failed');
       
        uint256 ethAmount= msg.value.sub(factoryFee);
        // Add liquidity to Uniswap
        router.addLiquidityETH{value: ethAmount}(
            address(token),
            token.totalSupply(),
            0, // slippage is inevitable
            0, // slippage is inevitable
            address(0),
            block.timestamp
        );

        _token.transferOwnership(DEAD_ADDRESS);

        // Handle buy and burn of FairDexToken 
        uint256 feeToBurn = uint256(factoryFee).div(3);
        _buyAndBurnFairDexToken(feeToBurn, msg.sender);

        

    }

    function _buyAndBurnFairDexToken(uint256 amount,address _deployer) internal   {
        IUniswapV2Router02 router = IUniswapV2Router02(uniswapRouter);
        
        // Generate the Uniswap pair path of WETH -> FairDexToken
        address[] memory path = new address[](2);
        path[0] = router.WETH();
        path[1] = fairDexTokenAddress;

        // Swap ETH for FairDexToken
        router.swapExactETHForTokens{value: amount}(
            0, // accept any amount of FairDexToken
            path,
            address(this), // The contract itself will receive the tokens
            block.timestamp+30000
        );

        uint256 fairDexTokenBalance = IERC20(fairDexTokenAddress).balanceOf(address(this));
        // Calculate the amount with 1% slippage
        uint256 slippageAmount = fairDexTokenBalance.mul(1).div(100); // 1% of the balance
        uint256 adjustedAmount = fairDexTokenBalance.sub(slippageAmount); // balance after subtracting 1%

        // Calculate the amount to be burned and transferred, subtracting 2 units for rounding safety
        uint256 _amount = adjustedAmount.div(2).sub(2);
        
        require(_amount>0,"amount cannot be zero");
       
        // 50% FairDexToken is Burned 
        require(IERC20(fairDexTokenAddress).transfer(DEAD_ADDRESS, _amount), "Burn transfer failed");
        
        // 50% FairDexToken is transfered to token deployer
        require(IERC20(fairDexTokenAddress).transfer(_deployer, _amount), "deployer transfer failed");

    }

    // Function to get all deployed tokens
    function getDeployedTokens() external view returns (address[] memory) {
        return deployedTokens;
    }

    function pause() external onlyOwner {
        _pause();
    }

    function unpause() external onlyOwner {
        _unpause();
    }

    function setFactoryFee(uint256 _factoryFee) external onlyOwner {
        factoryFee=_factoryFee;
    }

    function setMinETHLiquidity(uint256 _minETHLiquidity) external onlyOwner {
        minETHLiquidity=_minETHLiquidity;
    }


    // Allow the contract to receive ETH
    receive() external payable {}

    function withdrawETH(address payable _to, uint256 _amount) external onlyOwner {
        require(_to != address(0), "Invalid address");
        require(_amount <= address(this).balance, "Insufficient balance");

        _to.transfer(_amount);
    }
}