Unaxi documents
  • Start here
  • Disclaimer
  • User Docs
    • Introduction
  • Fund Overview
  • UNAXI Tokens
  • Protecting Your Investment
  • HOW-TO GUIDES
    • Buy
    • Sell
  • Presale
  • DEVELOPER DOCS
    • Contract Addresses
  • Core Contract
  • OFFICEIAL LINKS
    • Website
  • Socials
  • Audits
  • Contracts
  • TERMS
    • Terms and Conditions
    • Privacy policy
    • AML
Powered by GitBook
On this page
Export as PDF

Core Contract

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

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

contract LocalTradingToken is ERC20, Ownable, ReentrancyGuard {
    uint256 public cachedTokenPrice = 100 * 10 ** 2; // 1.00
    uint256 public cachedBuyFee = 200; // 2%
    uint256 public cachedSellFee = 200; // 2%

    uint256 public lastFeeUpdate;
    uint256 public lastPriceUpdate;

    // events
    event TokenPriceSynced(uint256 newPrice);
    event FeesSynced(uint256 newBuyFee, uint256 newSellFee);

    // contrcuts
    constructor() ERC20("LocalTradingToken", "LTT") Ownable(msg.sender) {}

    // floats of token
    function decimals() public pure override returns (uint8) {
        return 2;
    }

    // local oracle
    function updateFromOracle(
        uint256 newPrice,
        uint256 buyFee,
        uint256 sellFee
    ) external onlyOwner {
        cachedTokenPrice = newPrice * 10 ** 2;
        cachedBuyFee = buyFee;
        cachedSellFee = sellFee;
        lastPriceUpdate = block.timestamp;
        lastFeeUpdate = block.timestamp;

        emit TokenPriceSynced(newPrice);
        emit FeesSynced(buyFee, sellFee);
    }

    // buy token
    function buyTokens(uint256 amount) external payable nonReentrant {
        uint256 cost = (amount * cachedTokenPrice) / 10 ** 2;
        uint256 fee = (cost * cachedBuyFee) / 10000;
        uint256 total = cost + fee;
        require(msg.value >= total, unicode"not eno");

        _mint(msg.sender, amount);
    }

    // sell tokens
    function sellTokens(uint256 amount) external nonReentrant {
        uint256 value = (amount * cachedTokenPrice) / 10 ** 2;
        uint256 fee = (value * cachedSellFee) / 10000;
        uint256 net = value - fee;
        require(address(this).balance >= net, unicode"not eno");

        _burn(msg.sender, amount);
        payable(msg.sender).transfer(net);
    }

    // with draw owner
    function withdraw() external onlyOwner {
        payable(owner()).transfer(address(this).balance);
    }

    //
    receive() external payable {}
}
PreviousContract AddressesNextSocials

Last updated 1 month ago