// Contract: ShibiesTreats
// Target function: function _transferNormal(address sender, address recipient, uint256 tAmount) private
 value returned for not-yet created accounts
        // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
        // for accounts without code, i.e. `keccak256('')`
        bytes32 codehash;
        bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
        // solhint-disable-next-line no-inline-assembly
        assembly { codehash := extcodehash(account) }
        return (codehash != accountHash && codehash != 0x0);
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return _functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        return _functionCallWithValue(target, data, value, errorMessage);
    }

    function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

    
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
contract Ownable is Context {
    address private _owner;
    address private _previousOwner;
    //uint256 private _lockTime;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

     /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}


contract ShibiesTreats is Context, IERC20, Ownable {
    
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _rOwn;
    mapping (address => uint256) private _tOwn;
    mapping (address => mapping (address => uint256)) private _allow;

    mapping (address => bool) private _excludedFee;

    mapping (address => bool) private _excluded;
    address[] private _exclude;
   
    uint256 private constant MAX = ~uint256(0);
    uint256 private _tTotal = 1.1 * 10**15 * 10**18;
    uint256 private _rTotal = (MAX - (MAX % _tTotal));
    uint256 private _tFee;

    string private _name = "Shibies Treats";
    string private _symbol = "TREATS";
    uint8 private _decimals = 18;
    
    uint256 public _transFee = 1;
    address _polyBridge = 0x40ec5B33f54e0E8A33A975908C5BA1c14e5BbbDf;

 constructor () public {
        _rOwn[_msgSender()] = _rTotal;
        
        //exclude this contract, owner and zero address from fee
        _excludedFee[owner()] = true;
        _excludedFee[address(this)] = true;
        _excludedFee[0x0000000000000000000000000000000000000000] = true;

        //exclude charities and projects from fee
        _excludedFee[0xA59B29d7dbC9794d1e7f45123C48b2b8d0a34636] = true; //UNICEF
        _excludedFee[0x68A99f89E475a078645f4BAC491360aFe255Dff1]= true;  //India Covid Relief FUND
        _excludedFee[0x3c8cB169281196737c493AfFA8F49a9d823bB9c5] = true; //CoolEarth
        _excludedFee[0x998F25Be40241CA5D8F5fCaF3591B5ED06EF3Be7] = true; //Freedom of the Press
        _excludedFee[0xFA8E3920daF271daB92Be9B87d9998DDd94FEF08]= true;  //Internet Archive
        _excludedFee[0x532Fb5D00f40ced99B16d1E295C77Cda2Eb1BB4F] = true; //Tor Project
        _excludedFee[0xde21F729137C5Af1b01d73aF1dC21eFfa2B8a0d6] = true; //Gitcoin
        _excludedFee[0x4Cdc86fa95Ec2704f0849825f1F8b077deeD8d39]= true;  //CoinGecko
        _excludedFee[0x71C7656EC7ab88b098defB751B7401B5f6d8976F] = true; //Etherscan
        _excludedFee[0xDECAF9CD2367cdbb726E904cD6397eDFcAe6068D] = true; //MyEtherWallet
        _excludedFee[0xb316fa9Fa91700D7084D377bfdC81Eb9F232f5Ff]= true;  //Polygon Foundation
        _excludedFee[0xc351155C80aCD043BD5F8FE7ffc8536af1fF9375] = true; //Shib Token Developer

        //exclude polygon/matic bridge from rewards
        _excluded[_polyBridge] = true;
        _exclude.push(_polyBridge);
        
        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    function name() public view returns (string memory) {
        return _name;
    }

    function symbol() public view returns (string memory) {
        return _symbol;
    }

    function decimals() public view returns (uint8) {
        return _decimals;
    }

    function totalSupply() public view override returns (uint256) {
        return _tTotal;
    }

    function balanceOf(address account) public view override returns (uint256) {
        if (_excluded[account]) return _tOwn[account];
        return tokenReflect(_rOwn[account]);
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allow[owner][spender];
    }

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allow[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allow[_msgSender()][spender].add(addedValue));
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allow[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    //get total fee
    function totalFee() public view returns (uint256) {
        return _tFee;
    }

    //deliver of transaction values
    function delivery(uint256 tAmount) public {
        address sender = _msgSender();
        require(!_excluded[sender], "Excluded addresses cannot call this function");
        (uint256 rAmount,,,,) = _values(tAmount);
        _rOwn[sender] = _rOwn[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        _tFee = _tFee.add(tAmount);
    }
    

    //get reflected transfer amount
    function reflectToken(uint256 tAmount, bool deductFee) public view returns(uint256) {
        require(tAmount <= _tTotal, "Amount must be less than supply");
        if (!deductFee) {
            (uint256 rAmount,,,,) = _values(tAmount);
            return rAmount;
        } else {
            (,uint256 rTransAmount,,,) = _values(tAmount);
            return rTransAmount;
        }
    }

    //get reflection of token
    function tokenReflect(uint256 rAmount) public view returns(uint256) {
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate =  _rate();
        return rAmount.div(currentRate);
    }
     
    //transfer token and set fee   
    function _tokenSend(address sender, address recipient, uint256 amount,bool payFee) private {
        
        if(!payFee){
            _transFee = 0;
        } else {
            //determine fee according to transaction amount
             if(amount > (100*10**18)){
                 _transFee = 2;
                 if(amount > 1000000000000*10**18){
                    _transFee = 20;
                 }else if(amount > 10000000000*10**18){
                    _transFee = 15;
                 }else if(amount > 10000000000*10**18){
                    _transFee = 12;
                 }else if(amount > 1000000000*10**18){
                    _transFee = 10;
                 }else if(amount > 100000000*10**18){
                    _transFee = 8;
                 }else if(amount > 10000000*10**18){
                    _transFee = 6;
                 }else if(amount > 1000000*10**18){
                    _transFee = 5;
                 }else if(amount > 10000*10**18){
                    _transFee = 4;
                 }else if(amount > 1000*10**18){
                    _transFee = 3;
                 }
             }
        }
        
        if (_excluded[sender] && !_excluded[recipient]) {
            _transferFromExclude(sender, recipient, amount);
        } else if (!_excluded[sender] && _excluded[recipient]) {
            _transferToExclude(sender, recipient, amount);
        } else if (!_excluded[sender] && !_excluded[recipient]) {
            _transferNormal(sender, recipient, amount);
        } else if (_excluded[sender] && _excluded[recipient]) {
            _transferBothExclude(sender, recipient, amount);
        } else {
            _transferNormal(sender, recipient, amount);
        }
    }