Betarena / bta_smart

BTA Bitarena Smart Contract
GNU General Public License v3.0
0 stars 0 forks source link

BTA Exclude Project Addresses from Fees #4

Open jonsnowpt opened 1 year ago

jonsnowpt commented 1 year ago

📝 Issue Description

All project addresses should be excluded from transaction fees.


Code Example

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

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

contract MyToken is ERC20, Ownable {
    mapping(address => bool) public projectAddresses;

    constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}

    function setProjectAddress(address _projectAddress, bool _excluded) external onlyOwner {
        projectAddresses[_projectAddress] = _excluded;
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        if (projectAddresses[_msgSender()]) {
            _transfer(_msgSender(), recipient, amount);
        } else {
            uint256 fee = amount / 200;
            _transfer(_msgSender(), recipient, amount - fee);
            _transfer(_msgSender(), owner(), fee);
        }
        return true;
    }
}

In this code example, the setProjectAddress function can be called by the contract owner to set whether a project address should be excluded from transaction fees. The transfer function checks whether the sender is a project address, and if so, simply transfers the tokens without a fee. If the sender is not a project address, a fee is calculated as 0.5% of the transaction amount, and then subtracted from the transferred amount. Finally, the fee is transferred to the contract owner.


🎯 Acceptance Criteria


📝 Additional Notes

The setProjectAddress function should only be callable by the contract owner. The contract owner should not be able to exclude their own address from transaction fees.

migbash commented 1 month ago

🟧 UPDATE