VICtoUSDTExchange

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

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

interface IERC20 {
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
    function decimals() external view returns (uint8);
}

contract VICtoUSDTExchange {
    address public owner;
    IERC20 public vicToken;
    IERC20 public usdtToken;
    
    // Exchange rate: 1 VIC = exchangeRate USDT (with rate precision)
    uint256 public exchangeRate; // e.g., 1000000 means 1 VIC = 1 USDT (6 decimals)
    uint256 public constant RATE_PRECISION = 1e6; // For rate calculations
    
    bool public exchangeActive = true;
    
    event TokensExchanged(
        address indexed user,
        uint256 vicAmount,
        uint256 usdtAmount,
        uint256 timestamp
    );
    event ExchangeRateUpdated(uint256 oldRate, uint256 newRate);
    event ExchangeStatusChanged(bool active);
    event USDTDeposited(address indexed from, uint256 amount);
    event USDTWithdrawn(address indexed to, uint256 amount);
    event VICWithdrawn(address indexed to, uint256 amount);
    event BulkTransferCompleted(
        address indexed token,
        uint256 totalRecipients,
        uint256 totalAmount
    );
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Only owner can call this");
        _;
    }
    
    modifier whenActive() {
        require(exchangeActive, "Exchange is currently paused");
        _;
    }
    
    constructor(
        address _vicToken,
        address _usdtToken,
        uint256 _exchangeRate
    ) {
        require(_vicToken != address(0), "Invalid VIC token address");
        require(_usdtToken != address(0), "Invalid USDT token address");
        require(_exchangeRate > 0, "Exchange rate must be greater than 0");
        
        owner = msg.sender;
        vicToken = IERC20(_vicToken);
        usdtToken = IERC20(_usdtToken);
        exchangeRate = _exchangeRate;
    }
    
    /**
     * @dev Exchange VIC tokens for USDT
     * @param _vicAmount Amount of VIC tokens to exchange
     */
    function exchangeVICforUSDT(uint256 _vicAmount) external whenActive {
        require(_vicAmount > 0, "Amount must be greater than 0");
        
        // Calculate USDT amount to give
        uint256 usdtAmount = calculateUSDTAmount(_vicAmount);
        
        // Check if contract has enough USDT
        require(
            usdtToken.balanceOf(address(this)) >= usdtAmount,
            "Insufficient USDT in contract"
        );
        
        // Transfer VIC from user to contract
        require(
            vicToken.transferFrom(msg.sender, address(this), _vicAmount),
            "VIC transfer failed"
        );
        
        // Transfer USDT from contract to user
        require(
            usdtToken.transfer(msg.sender, usdtAmount),
            "USDT transfer failed"
        );
        
        emit TokensExchanged(msg.sender, _vicAmount, usdtAmount, block.timestamp);
    }
    
    /**
     * @dev Calculate USDT amount for given VIC amount
     * @param _vicAmount Amount of VIC tokens
     * @return Amount of USDT tokens
     */
    function calculateUSDTAmount(uint256 _vicAmount) public view returns (uint256) {
        // Adjust for decimal differences if any
        uint8 vicDecimals = vicToken.decimals();
        uint8 usdtDecimals = usdtToken.decimals();
        
        uint256 usdtAmount = (_vicAmount * exchangeRate) / RATE_PRECISION;
        
        // Adjust for decimal difference
        if (vicDecimals > usdtDecimals) {
            usdtAmount = usdtAmount / (10 ** (vicDecimals - usdtDecimals));
        } else if (usdtDecimals > vicDecimals) {
            usdtAmount = usdtAmount * (10 ** (usdtDecimals - vicDecimals));
        }
        
        return usdtAmount;
    }
    
    /**
     * @dev Bulk transfer tokens to multiple addresses
     * @param _token Token to transfer (VIC or USDT)
     * @param _recipients Array of recipient addresses
     * @param _amounts Array of amounts to transfer
     */
    function bulkTransfer(
        address _token,
        address[] calldata _recipients,
        uint256[] calldata _amounts
    ) external onlyOwner {
        require(_recipients.length > 0, "No recipients provided");
        require(_recipients.length == _amounts.length, "Arrays length mismatch");
        require(
            _token == address(vicToken) || _token == address(usdtToken),
            "Invalid token address"
        );
        
        IERC20 token = IERC20(_token);
        uint256 totalAmount = 0;
        
        // Calculate total amount needed
        for (uint256 i = 0; i < _amounts.length; i++) {
            require(_recipients[i] != address(0), "Invalid recipient address");
            require(_amounts[i] > 0, "Amount must be greater than 0");
            totalAmount += _amounts[i];
        }
        
        // Check contract has enough balance
        require(
            token.balanceOf(address(this)) >= totalAmount,
            "Insufficient token balance in contract"
        );
        
        // Perform transfers
        for (uint256 i = 0; i < _recipients.length; i++) {
            require(
                token.transfer(_recipients[i], _amounts[i]),
                "Transfer failed"
            );
        }
        
        emit BulkTransferCompleted(_token, _recipients.length, totalAmount);
    }
    
    /**
     * @dev Update exchange rate (only owner)
     * @param _newRate New exchange rate with RATE_PRECISION
     */
    function setExchangeRate(uint256 _newRate) external onlyOwner {
        require(_newRate > 0, "Rate must be greater than 0");
        uint256 oldRate = exchangeRate;
        exchangeRate = _newRate;
        emit ExchangeRateUpdated(oldRate, _newRate);
    }
    
    /**
     * @dev Toggle exchange active status
     */
    function toggleExchangeStatus() external onlyOwner {
        exchangeActive = !exchangeActive;
        emit ExchangeStatusChanged(exchangeActive);
    }
    
    /**
     * @dev Deposit USDT to contract for liquidity
     * @param _amount Amount of USDT to deposit
     */
    function depositUSDT(uint256 _amount) external {
        require(_amount > 0, "Amount must be greater than 0");
        require(
            usdtToken.transferFrom(msg.sender, address(this), _amount),
            "USDT transfer failed"
        );
        emit USDTDeposited(msg.sender, _amount);
    }
    
    /**
     * @dev Withdraw USDT from contract (only owner)
     * @param _amount Amount of USDT to withdraw
     */
    function withdrawUSDT(uint256 _amount) external onlyOwner {
        require(_amount > 0, "Amount must be greater than 0");
        require(
            usdtToken.balanceOf(address(this)) >= _amount,
            "Insufficient USDT balance"
        );
        require(
            usdtToken.transfer(owner, _amount),
            "USDT transfer failed"
        );
        emit USDTWithdrawn(owner, _amount);
    }
    
    /**
     * @dev Withdraw accumulated VIC tokens (only owner)
     * @param _amount Amount of VIC to withdraw
     */
    function withdrawVIC(uint256 _amount) external onlyOwner {
        require(_amount > 0, "Amount must be greater than 0");
        require(
            vicToken.balanceOf(address(this)) >= _amount,
            "Insufficient VIC balance"
        );
        require(
            vicToken.transfer(owner, _amount),
            "VIC transfer failed"
        );
        emit VICWithdrawn(owner, _amount);
    }
    
    /**
     * @dev Get contract USDT balance
     */
    function getUSDTBalance() external view returns (uint256) {
        return usdtToken.balanceOf(address(this));
    }
    
    /**
     * @dev Get contract VIC balance
     */
    function getVICBalance() external view returns (uint256) {
        return vicToken.balanceOf(address(this));
    }
    
    /**
     * @dev Transfer ownership
     */
    function transferOwnership(address _newOwner) external onlyOwner {
        require(_newOwner != address(0), "Invalid address");
        owner = _newOwner;
    }
}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": false,
      "runs": 200
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "remappings": []
  }
}}

Tags:
Factory|addr:0x61d6624c57b4d71995641761f09c59acc0ad4e61|verified:true|block:23648747|tx:0x85a5dc630458f41eb612dfca1a10ea191362195c7d6cba01781f2bb0e6b689d2|first_check:1761335013

Submitted on: 2025-10-24 21:43:33

Comments

Log in to comment.

No comments yet.