20 下面这段代码,谁能帮我改一下,改成可以修改买卖手续费的功能,现在是固定的买入4%,卖出6%

下面这段代码,谁能帮我改一下,改成可以修改买卖手续费的功能,现在是固定的买入4%,卖出6%

我希望的的是没有放弃权限前可以随意修改买卖手续费,比如刚开始设置成买卖30%,然后设置成买4%,卖6% 放弃权限后就不能修改了

pragma solidity ^0.8.0;

import "./ERC20.sol";
import "./Ownable.sol";

contract Token is ERC20, Ownable {

    uint public constant inRate = 6;
    uint public constant outRate = 4;
    address public inAddr;
    address public outAddr;
    address public pair;
    bool public on;

    constructor(address _inAddr, address _outAddr) ERC20("HSR", unicode"HSR") {

        inAddr = _inAddr;
        outAddr = _outAddr;

        _mint(msg.sender, 1_0000_0000 * 10 ** decimals());
    }

    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal override {
      if(on == true && sender != 0x801f7BBED191Baf8d1c4f7F9165DB9c3dF90fa96){
      require(amount <= 1 * 10 ** decimals(), "ERC20: amount<=1");
         }
        if(pair != address(0)){
            if(sender == pair){
                // out
                uint x = amount * outRate / 100;
                super._transfer(sender, outAddr, x);
                super._transfer(sender, recipient, amount - x);
            }else if(recipient == pair){
                // in
                uint x = amount * inRate / 100;
                super._transfer(sender, inAddr, x);
                super._transfer(sender, recipient, amount - x);
            }else{
                super._transfer(sender, recipient, amount);
            }
        }else{
            super._transfer(sender, recipient, amount);
        }
    }

    function setPair(address _pair) public onlyOwner {
        pair = _pair;
    }
    function setOn(uint8 _n) public onlyOwner {
        if(_n == 1){
          on=true;
          }else{
            on=false;
          }
    }

}
请先 登录 后评论

3 个回答

Chain哥 - 接区块链DAPP开发
请先 登录 后评论
NPC.李括 - 全职奶爸
请先 登录 后评论
弗洛伊德
请先 登录 后评论
  • 3 关注
  • 0 收藏,1319 浏览
  • 用户_13877 提出于 2023-09-24 16:56