4ART Swapping Functionality

Smart Contract Code

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract EthOrUsdtTo4Art is Ownable {
    IERC20 public fourArtToken;
    address public priceOracle;
    uint256 public constant BONUS_RATE = 10; // 10% bonus

    event ExchangeCompleted(address indexed user, uint256 fourArtAmount);

    constructor(
        address _fourArtToken,
        address _priceOracle
    ) Ownable(msg.sender) {
        fourArtToken = IERC20(_fourArtToken);
        priceOracle = _priceOracle;
    }

    function getPrices() public view returns (uint256, uint256) {
        (bool success, bytes memory data) = priceOracle.staticcall(
            abi.encodeWithSignature("getPrices()")
        );
        require(success, "Failed to fetch prices from oracle");
        return abi.decode(data, (uint256, uint256));
    }

    function calculate4ArtAmount(
        uint256 baseAmount
    ) internal pure returns (uint256) {
        uint256 bonusAmount = (baseAmount * BONUS_RATE) / 100;
        return baseAmount + bonusAmount;
    }

    receive() external payable {
        if (msg.sender == owner()) {
            return;
        }
        require(msg.value > 0, "Send some ETH");

        // Get prices
        (uint256 ethToUsdtPrice, uint256 usdtTo4ArtPrice) = getPrices();

        // Calculate USDT equivalent
        uint256 ethToUsdt = (msg.value * ethToUsdtPrice) / 1 ether;

        // Calculate 4ART amount with bonus
        uint256 base4ArtAmount = (ethToUsdt * 1 ether) / usdtTo4ArtPrice;
        uint256 fourArtAmount = calculate4ArtAmount(base4ArtAmount);

        require(
            fourArtToken.transfer(msg.sender, fourArtAmount),
            "4ART transfer failed"
        );
        emit ExchangeCompleted(msg.sender, fourArtAmount);
    }

    function withdraw4Art(uint256 amount) external onlyOwner {
        require(
            fourArtToken.transfer(owner(), amount),
            "4ART withdrawal failed"
        );
    }

    function withdrawEth() external onlyOwner {
        (bool sent, ) = owner().call{value: address(this).balance}("");
        require(sent, "ETH withdrawal failed");
    }
}

Detailed Functionality Analysis

The EthOrUsdtTo4Art smart contract facilitates the swapping of ETH for 4ART tokens with a 10% bonus. Below is a breakdown of its features:

Why Use This Contract?

Users can trust this contract for the following reasons: