0
function transferToAddress(address _to, uint _value, bytes memory _data) internal returns (bool success) {
        require (_to != msg.sender && _to != address(0));
        uint fee = calculateFee(_value);
        require (_value > 0);
        require (balances[msg.sender] >= _value);
        require (balances[_to].add(_value) >= balances[_to]);
        uint sendAmount = _value.sub(fee);
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(sendAmount);
        if (fee > 0) {
            balances[owner] = balances[owner].add(fee);
            emit Transfer(msg.sender, owner, fee,_data);
        }
        holderIsExist(_to);
        emit Transfer(msg.sender, _to, _value, _data);
        emit Transfer(msg.sender, _to, _value);
        return true;
    }


function calculateFee(uint _amount)public view returns(uint){
            uint fee = (_amount.mul(basisPointsRate)).div(1000);
            if (fee > maximumFee) {
                    fee = maximumFee;
            }
            if (fee < minimumFee) {
                fee = minimumFee;
            }
            return fee;
        }
2

Its not about why divide by 1000. This can be any no raised to power 10. The reason behind such division is

You can not use decimals in smart contracts

and hence what if you want to have have x % of fee ?

You need to use logic

fee = amount * x / 100;

But them the min value of x is 1. So if you want your x to be as low as 0.1, you can use:

fee = amount * x / 1000;

So when you need fee to be 10 % in later case you need to use x = 100.

This is similar to why we have decimals in ERC-20 tokens.

Suggestion

My personal prefrence to have such divisions is use a combination of 2 values.

  • basisPointsRate_N (Numerator)
  • basisPointsRate_D (Denominator)

fee = amount * basisPointsRate_N / basisPointsRate_D

Now you can set whatever min values you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.