Skip to content
Verified contractExactMIT

SnipingBotWithSecurity

Address0x8a0937e40044de9d77bd751ef122add5b6164e7a
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.17

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.17+commit.8df45f5f
Language
solidity
Optimization
Yes, 1,000 runs
EVM version
london
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
20,791,103
Creation transaction
0x33982f7d43…330a979d22

contracts/SnipingBotWithSecurity.sol

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

interface IUniswapV2Router {
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, 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 WETH() external pure returns (address); // Ensure WETH function is declared in the interface
}

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

contract SnipingBotWithSecurity {
    address public owner;
    IUniswapV2Router public uniswapRouter;
    IUniswapV2Router public sushiswapRouter;
    address public token; // Token address for sniping
    uint public initialInvestment; // Track ETH investment
    uint public profitThreshold; // Set the profit threshold in percentage (e.g., 100 for 100%)
    uint public trailingStopLoss; // Set the trailing stop-loss threshold (e.g., 80 for 80%)
    address[] public path;
    modifier onlyOwner() {
        require(msg.sender == owner, "Not the owner");
        _;
    }

    constructor(address _uniswapRouter, address _sushiswapRouter, address _token) {
        owner = msg.sender;
        uniswapRouter = IUniswapV2Router(_uniswapRouter);
        sushiswapRouter = IUniswapV2Router(_sushiswapRouter);
        token = _token;
        profitThreshold = 100; // 100% profit
        trailingStopLoss = 80; // Trailing stop-loss at 80%
    }

    // This function buys the token and stores the initial investment amount (in ETH)
    function snipeOpportunity() external payable onlyOwner {
        require(msg.value > 0, "Send ETH to snipe");

        // Define path for ETH -> Token swaps
        
        path[0] = uniswapRouter.WETH(); // WETH address
        path[1] = token; // Target token

        // Store the initial ETH investment amount
        initialInvestment = msg.value;

        // Execute trade on Uniswap (for simplicity, using Uniswap here)
        uniswapRouter.swapExactETHForTokens{ value: msg.value }(1, path, address(this), block.timestamp + 1200);
    }

    // Function to sell the tokens and close the position
    function closePosition() public onlyOwner {
        uint tokenBalance = IERC20(token).balanceOf(address(this));
        require(tokenBalance > 0, "No tokens to sell");

        // Define the path for Token -> ETH swap
        
        path[0] = token;
        path[1] = uniswapRouter.WETH(); // Swap back to ETH

        // Approve the router to spend the tokens
        IERC20(token).approve(address(uniswapRouter), tokenBalance);

        // Execute the swap back to ETH
        uniswapRouter.swapExactTokensForETH(tokenBalance, 1, path, owner, block.timestamp + 1200);
    }

    // This function is called by the off-chain bot to check the profit percentage
    function checkProfit(uint currentTokenPrice) external view returns (uint) {
        // Calculate the profit percentage: (Current Value - Initial Value) / Initial Value * 100
        uint currentValue = currentTokenPrice * IERC20(token).balanceOf(address(this));
        uint profitPercentage = ((currentValue - initialInvestment) * 100) / initialInvestment;

        return profitPercentage;
    }

    // The off-chain bot will call this function when the profit hits the stop-loss threshold
    function triggerStopLoss(uint currentProfitPercentage) external onlyOwner {
        require(currentProfitPercentage < profitThreshold && currentProfitPercentage >= trailingStopLoss, "Stop-loss not triggered");

        // Close the position if the stop-loss threshold is hit
        closePosition();
    }

    function setProfitThreshold(uint _profitThreshold) external onlyOwner {
        profitThreshold = _profitThreshold;
    }

    function setTrailingStopLoss(uint _trailingStopLoss) external onlyOwner {
        trailingStopLoss = _trailingStopLoss;
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 1000,
    "enabled": true
  },
  "evmVersion": "london",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.