// The cut part of the code pragma solidity ^0.6.12; import "./Context.sol"; import "./SafeMath.sol"; import "./Ownable.sol"; import "../interfaces/IERC20.sol"; abstract contract ReflectToken is Context, IERC20, Ownable { using SafeMath for uint256; mapping (address => uint256) private _rOwned; mapping (address => uint256) private _tOwned; mapping (address => mapping (address => uint256)) private _allowances; mapping (address => bool) private _isExcluded; address[] private _excluded; uint8 private constant _decimals = 18; uint256 private _tTotal; uint256 private _rTotal; uint256 private _tFeeTotal; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_, uint256 tTotal_) public { _name = name_; _symbol = symbol_; _tTotal = tTotal_; uint256 MAX = type(uint256).max; _rTotal = (MAX - (MAX % _tTotal)); _rOwned[_msgSender()] = _rTotal; emit Transfer(address(0), _msgSender(), _tTotal); } /** * @dev Amount of tokens to be charged as a reflection fee. Must be in range 0..amount. */ function _calculateReflectionFee(address sender, address recipient, uint256 amount) internal virtual view returns (uint256); /** * @dev Amount of tokens to be charged and stored in this contract. Must be in range 0..amount. */ function _calculateAccumulationFee(address sender, address recipient, uint256 amount) internal virtual view returns (uint256); /** * @dev Distributes reflection rewards. * @param rFee Fee taken from the sender"s account. * @param tFee Fee with considering of a rate (real amount of tokens). */ function _reflectFee(uint256 rFee, uint256 tFee) private { _rTotal = _rTotal.sub(rFee); _tFeeTotal = _tFeeTotal.add(tFee); } /** * @dev Accumulates accumulation fee on the contract"s balance with considering of its involvement in rewards reflection. */ function _accumulateFee(uint256 rAccumulation, uint256 tAccumulation) private { _rOwned[address(this)] = _rOwned[address(this)].add(rAccumulation); if(_isExcluded[address(this)]) { _tOwned[address(this)] = _tOwned[address(this)].add(tAccumulation); } } /** * @dev Returns results of `_getTValues` and `_getRValues` methods. */ function _getValues(address sender, address recipient, uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) { (uint256 tTransferAmount, uint256 tFee, uint256 tAccumulation) = _getTValues(sender, recipient, tAmount); (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 rAccumulation) = _getRValues(tAmount, tFee, tAccumulation); return (rAmount, rTransferAmount, rFee, rAccumulation, tTransferAmount, tFee, tAccumulation); } /** * @dev Computes and returns transfer amount, reflection fee, accumulation fee in tokens. */ function _getTValues(address sender, address recipient, uint256 tAmount) private view returns (uint256, uint256, uint256) { uint256 tFee = _calculateReflectionFee(sender, recipient, tAmount); uint256 tAccumulation = _calculateAccumulationFee(sender, recipient, tAmount); uint256 tTransferAmount = tAmount.sub(tFee).sub(tAccumulation); return (tTransferAmount, tFee, tAccumulation); } /** * @dev Computes and returns amount, transfer amount, reflection fee, accumulation fee in reflection. */ function _getRValues(uint256 tAmount, uint256 tFee, uint256 tAccumulation) private view returns (uint256, uint256, uint256, uint256) { uint256 currentRate = _getRate(); uint256 rAmount = tAmount.mul(currentRate); uint256 rFee = tFee.mul(currentRate); uint256 rAccumulation = tAccumulation.mul(currentRate); uint256 rTransferAmount = rAmount.sub(rFee).sub(rAccumulation); return (rAmount, rTransferAmount, rFee, rAccumulation); } /** * @dev Returns reflection to token rate. */ function _getRate() private view returns(uint256) { (uint256 rSupply, uint256 tSupply) = _getCurrentSupply(); return rSupply.div(tSupply); } /** * @dev Returns current supply. */ function _getCurrentSupply() private view returns(uint256, uint256) { uint256 rSupply = _rTotal; uint256 tSupply = _tTotal; uint256 len = _excluded.length; for (uint256 i = 0; i < len; i++) { address account = _excluded[i]; uint256 rBalance = _rOwned[account]; uint256 tBalance = _tOwned[account]; if (rBalance > rSupply || tBalance > tSupply) return (_rTotal, _tTotal); rSupply = rSupply.sub(rBalance); tSupply = tSupply.sub(tBalance); } if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal); return (rSupply, tSupply); } }
0.4.18