NOXAutoSwap

Description:

Decentralized Finance (DeFi) protocol contract providing Swap, Liquidity, Factory functionality.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "contracts/NOXAutoSwap.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

interface IUniswapV2Router02 {
    function WETH() external view returns (address);
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline
    ) external;
}

/// @title NOXAutoSwap - Instant tax swapping
/// @notice Receives NOX fees and immediately swaps to ETH
contract NOXAutoSwap {
    address public immutable noxToken;
    address public immutable router;
    address public immutable liquidityCollector;
    address public immutable treasury; 
    address public immutable devWallet;
    uint16 public immutable liquidityShare; // 4000 = 40%
    uint16 public immutable treasuryShare;  // 2000 = 20%
    uint16 public immutable devShare;       // 3000 = 30%
    uint16 public constant BPS = 10000;
    
    bool private inSwap;
    modifier swapping() { inSwap = true; _; inSwap = false; }

    constructor(
        address _noxToken,
        address _router, 
        address _liquidityCollector,
        address _treasury,
        address _devWallet
    ) {
        noxToken = _noxToken;
        router = _router;
        liquidityCollector = _liquidityCollector;
        treasury = _treasury;
        devWallet = _devWallet;
        liquidityShare = 4000; // 40%
        treasuryShare = 2000;  // 20% 
        devShare = 3000;       // 30%
    }

    /// @notice Called automatically when NOX fees are sent here
    receive() external payable {
        // Handle ETH if needed
    }

    /// @notice Automatically swap any NOX received
    function autoSwap() external {
        if (inSwap) return;
        uint256 noxBalance = IERC20(noxToken).balanceOf(address(this));
        if (noxBalance > 0) {
            _swapAndDistribute(noxBalance);
        }
    }

    /// @notice Internal swap and distribute
    function _swapAndDistribute(uint256 amount) private swapping {
        // Approve router
        IERC20(noxToken).approve(router, amount);
        
        // Swap NOX -> ETH
        address[] memory path = new address[](2);
        path[0] = noxToken;
        path[1] = IUniswapV2Router02(router).WETH();
        
        try IUniswapV2Router02(router).swapExactTokensForETHSupportingFeeOnTransferTokens(
            amount, 0, path, address(this), block.timestamp
        ) {
            // Distribute ETH
            uint256 ethBalance = address(this).balance;
            if (ethBalance > 0) {
                uint256 toLiq = (ethBalance * liquidityShare) / BPS;
                uint256 toTre = (ethBalance * treasuryShare) / BPS;
                uint256 toDev = ethBalance - toLiq - toTre;
                
                if (toLiq > 0) payable(liquidityCollector).transfer(toLiq);
                if (toTre > 0) payable(treasury).transfer(toTre);
                if (toDev > 0) payable(devWallet).transfer(toDev);
            }
        } catch {
            // If swap fails, do nothing (keep NOX)
        }
    }

    /// @notice Trigger swap manually if needed
    function triggerSwap() external {
        if (inSwap) return;
        uint256 noxBalance = IERC20(noxToken).balanceOf(address(this));
        if (noxBalance > 0) {
            _swapAndDistribute(noxBalance);
        }
    }
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
DeFi, Swap, Liquidity, Factory|addr:0x6ca4a02c8397f4f6869acf61abd98307332a540a|verified:true|block:23502552|tx:0xc88fac1dc38b23f772db6fb12e7697a9b02faaa427125836d7eb952f42625124|first_check:1759570347

Submitted on: 2025-10-04 11:32:27

Comments

Log in to comment.

No comments yet.