Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 #1933

Closed
wants to merge 2 commits into from
Closed

1 #1933

wants to merge 2 commits into from

Conversation

DINATOKEN
Copy link

// SPDX-License-Identifier: MIT

pragma solidity >0.6.2;

/**

  • @dev Collection of functions related to the address type
    /
    library Address {
    /
    *

    • @dev Returns true if account is a contract.
    • [IMPORTANT]
    • ====
    • It is unsafe to assume that an address for which this function returns
    • false is an externally-owned account (EOA) and not a contract.
    • Among others, isContract will return false for the following
    • types of addresses:
      • an externally-owned account
      • a contract in construction
      • an address where a contract will be created
      • an address where a contract lived, but was destroyed
    • ====
      */
      function isContract(address account) internal view returns (bool) {
      // According to EIP-1052, 0x0 is the 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 Performs a Solidity function call using a low level call. A
    • plaincall 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);
         }
     // SPDX-License-Identifier: GPL-3.0-or-later
    

pragma solidity >=0.8.4;

/*

  • @dev Provides information about the current execution context, including the

  • sender of the transaction and its data. While these are generally available

  • via msg.sender and msg.data, they should not be accessed in such a direct

  • manner, since when dealing with GSN meta-transactions the account sending and

  • paying for execution may not be the actual sender (as far as an application

  • is concerned).

  • This contract is only required for intermediate, library-like contracts.
    */
    abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
    return payable(msg.sender);
    }

    function _msgData() internal view virtual returns (bytes memory) {
    this; // silence state mutability warning without generating bytecode - see Allow comments to ignore compiler warnings. ethereum/solidity#2691
    return msg.data;
    }
    }

pragma solidity >=0.8.4;

/*

  • @dev Provides information about the current execution context, including the

  • sender of the transaction and its data. While these are generally available

  • via msg.sender and msg.data, they should not be accessed in such a direct

  • manner, since when dealing with GSN meta-transactions the account sending and

  • paying for execution may not be the actual sender (as far as an application

  • is concerned).

  • This contract is only required for intermediate, library-like contracts.
    */
    abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
    return payable(msg.sender);
    }

    function _msgData() internal view virtual returns (bytes memory) {
    this; // silence state mutability warning without generating bytecode - see Allow comments to ignore compiler warnings. ethereum/solidity#2691
    return msg.data;
    }

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >=0.4.0;

interface IBEP20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);

/**
 * @dev Returns the token decimals.
 */
function decimals() external view returns (uint8);

/**
 * @dev Returns the token symbol.
 */
function symbol() external view returns (string memory);

/**
 * @dev Returns the token name.
 */
function name() external view returns (string memory);

/**
 * @dev Returns the bep token owner.
 */
function getOwner() external view returns (address);

/**
 * @dev Returns the amount of tokens owned by `account`.
 */
function balanceOf(address account) external view returns (uint256);

/**
 * @dev Moves `amount` tokens from the caller's account to `recipient`.
 *
 * Returns a boolean value indicating whether the operation succeeded.
 *
 * Emits a {Transfer} event.
 */
function transfer(address recipient, uint256 amount) external returns (bool);

/**
 * @dev Returns the remaining number of tokens that `spender` will be
 * allowed to spend on behalf of `owner` through {transferFrom}. This is
 * zero by default.
 *
 * This value changes when {approve} or {transferFrom} are called.
 */
function allowance(address _owner, address spender) external view returns (uint256);

/**
 * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
 *
 * Returns a boolean value indicating whether the operation succeeded.
 *
 * IMPORTANT: Beware that changing an allowance with this method brings the risk
 * that someone may use both the old and the new allowance by unfortunate
 * transaction ordering. One possible solution to mitigate this race
 * condition is to first reduce the spender's allowance to 0 and set the
 * desired value afterwards:
 * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
 *
 * Emits an {Approval} event.
 */
function approve(address spender, uint256 amount) external returns (bool);

/**
 * @dev Moves `amount` tokens from `sender` to `recipient` using the
 * allowance mechanism. `amount` is then deducted from the caller's
 * allowance.
 *
 * Returns a boolean value indicating whether the operation succeeded.
 *
 * Emits a {Transfer} event.
 */
function transferFrom(
    address sender,
    address recipient,
    uint256 amount
) external returns (bool);

/**
 * @dev Emitted when `value` tokens are moved from one account (`from`) to
 * another (`to`).
 *
 * Note that `value` may be zero.
 */
event Transfer(address indexed from, address indexed to, uint256 value);

/**
 * @dev Emitted when the allowance of a `spender` for an `owner` is set by
 * a call to {approve}. `value` is the new allowance.
 */
event Approval(address indexed owner, address indexed spender, uint256 value);

}
//SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;

interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);

function feeTo() external view returns (address);
function feeToSetter() external view returns (address);

function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);

function createPair(address tokenA, address tokenB) external returns (address pair);

function setFeeTo(address) external;
function setFeeToSetter(address) external;

}
//SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);

function addLiquidity(
    address tokenA,
    address tokenB,
    uint amountADesired,
    uint amountBDesired,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
    address token,
    uint amountTokenDesired,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
    address tokenA,
    address tokenB,
    uint liquidity,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
    address token,
    uint liquidity,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
    address tokenA,
    address tokenB,
    uint liquidity,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline,
    bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
    address token,
    uint liquidity,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline,
    bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
    uint amountOut,
    uint amountInMax,
    address[] calldata path,
    address to,
    uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);

function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);

}
//SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);

function swapExactTokensForTokensSupportingFeeOnTransferTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external;

}
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "./Context.sol";
import "./IBEP20.sol";
import "./SafeMath.sol";
import "./Address.sol";
import "./Ownable.sol";
import "./IUniswapV2Factory.sol";
import "./IUniswapV2Router02.sol";
interface IDividendDistributor {
function setEnabled(bool _enabled) external;
function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external;
function setShare(address shareholder, uint256 amount) external;
function deposit(uint256 amount) external payable;
function process(uint256 gas) external;
}

contract DividendDistributor is IDividendDistributor {
using SafeMath for uint256;
using Address for address;

address _token;

struct Share {
    uint256 amount;
    uint256 totalExcluded;
    uint256 totalRealised;
}

IUniswapV2Router02 router;

address[] shareholders;
mapping (address => uint256) shareholderIndexes;
mapping (address => uint256) shareholderClaims;

mapping (address => Share) public shares;

uint256 public totalShares;
uint256 public totalDividends;
uint256 public totalDistributed;
uint256 public dividendsPerShare;
uint256 public dividendsPerShareAccuracyFactor = 10 ** 36;

uint256 public minPeriod = 20 minutes;
uint256 public minDistribution = 1 * (10 ** 18);

uint256 currentIndex;

bool enabled = true;
modifier dividendEnabled() {
    if (enabled) {
        _;
    }
}

modifier onlyToken() {
    require(msg.sender == _token); _;
}
receive() external payable {}
constructor (address _router) {
    router = IUniswapV2Router02(_router);
    _token = msg.sender;
}

function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external override onlyToken {
    minPeriod = _minPeriod;
    minDistribution = _minDistribution;
}

function setEnabled(bool _enabled) external override onlyToken {
    enabled = _enabled;
}

function setShare(address shareholder, uint256 amount) external override onlyToken dividendEnabled {
    if(shares[shareholder].amount > 0) {
        distributeDividend(shareholder);
    }

    if(amount > 0 && shares[shareholder].amount == 0){
        addShareholder(shareholder);
    }else if(amount == 0 && shares[shareholder].amount > 0){
        removeShareholder(shareholder);
    }

    totalShares = totalShares.sub(shares[shareholder].amount).add(amount);
    shares[shareholder].amount = amount;
    shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
}

function deposit(uint256 amount) external payable override onlyToken dividendEnabled {
    if (amount <= 0) {
        return;
    }
    totalDividends = totalDividends.add(amount);
    dividendsPerShare = dividendsPerShare.add(dividendsPerShareAccuracyFactor.mul(amount).div(totalShares));
}

function process(uint256 gas) external override onlyToken dividendEnabled {
    uint256 shareholderCount = shareholders.length;
    if(shareholderCount == 0) {
        return;
    }

    uint256 gasUsed = 0;
    uint256 gasLeft = gasleft();

    uint256 iterations = 0;

    while(gasUsed < gas && iterations < shareholderCount) {
        if (currentIndex >= shareholderCount){
            currentIndex = 0;
        }

        if (shouldDistribute(shareholders[currentIndex])){
            distributeDividend(shareholders[currentIndex]);
        }

        gasUsed = gasUsed.add(gasLeft.sub(gasleft()));
        gasLeft = gasleft();
        currentIndex++;
        iterations++;
    }
}

function shouldDistribute(address shareholder) internal view returns (bool) {
    return shareholderClaims[shareholder] + minPeriod < block.timestamp
    && getUnpaidEarnings(shareholder) > minDistribution;
}

function distributeDividend(address shareholder) internal {
    if(shares[shareholder].amount == 0){ return; }

    uint256 amount = getUnpaidEarnings(shareholder);
    if(amount > 0){
        totalDistributed = totalDistributed.add(amount);
        payable(address(shareholder)).transfer(amount);

        shareholderClaims[shareholder] = block.timestamp;
        shares[shareholder].totalRealised = shares[shareholder].totalRealised.add(amount);
        shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
    }
}


function getUnpaidEarnings(address shareholder) public view returns (uint256) {
    if(shares[shareholder].amount == 0){ return 0; }

    uint256 shareholderTotalDividends = getCumulativeDividends(shares[shareholder].amount);
    uint256 shareholderTotalExcluded = shares[shareholder].totalExcluded;

    if(shareholderTotalDividends <= shareholderTotalExcluded){ return 0; }

    return shareholderTotalDividends.sub(shareholderTotalExcluded);
}

function getCumulativeDividends(uint256 share) internal view returns (uint256) {
    return share.mul(dividendsPerShare).div(dividendsPerShareAccuracyFactor);
}

function addShareholder(address shareholder) internal {
    shareholderIndexes[shareholder] = shareholders.length;
    shareholders.push(shareholder);
}

function removeShareholder(address shareholder) internal {
    shareholders[shareholderIndexes[shareholder]] = shareholders[shareholders.length-1];
    shareholderIndexes[shareholders[shareholders.length-1]] = shareholderIndexes[shareholder];
    shareholders.pop();
}

contract safemoon is Context, IBEP20, Ownable {
using SafeMath for uint256;
using Address for address;

string constant _name = "safemoon";
string constant _symbol = "SAFEMOON";

address constant ROUTER = 0xEb9C9ec6Cd3434d89351F8e258181acc96cC2F84;
address constant DEAD = 0x000000000000000000000000000000000000dEaD;

uint256 private constant MAX = ~uint256(0);
uint8 constant _decimals = 18;
uint256 _totalSupply = 10**12 * (10 ** _decimals);
uint256 private _maxTxAmount = _totalSupply / 20; // 5%

IUniswapV2Router02 private  router;
address private  pair;
address marketingFeeReceiver;

uint256 liquidityFee = 500;
uint256 dividendFee = 250;
uint256 burnFee = 250;
uint256 marketingFee = 200;

uint256 totalFee = 1200;
uint256 feeDenominator = 10000;


uint256 public launchBlock;


mapping(address => bool) pairs;
mapping(address => bool) whiteList;

mapping(address => uint256) _balances;
mapping(address => mapping(address => uint256)) _allowances;

DividendDistributor dividendDistributor;

uint256 distributorGas = 500000;
uint256 swapThreshold = _totalSupply / 20000;
bool swapEnabled = true;
bool inSwap;


modifier swapping {
    inSwap = true;
    _;
    inSwap = false;
}

event AutoLiquify(uint256 amountETH, uint256 amountToken);
event SwapTokensForETH(uint256 amountToken,address[] path);

constructor (address _marketingFeeReceiver) {
    IUniswapV2Router02 _router = IUniswapV2Router02(ROUTER);
    address _pair = IUniswapV2Factory(_router.factory()).createPair(address(this), _router.WETH());
    dividendDistributor = new DividendDistributor(address(_router));

    _allowances[address(this)][address(_router)] = MAX;
    _balances[owner()] = _totalSupply;

    whiteList[owner()] = true;
    whiteList[address(this)] = true;

    marketingFeeReceiver = _marketingFeeReceiver;
    router = _router;
    pair = _pair;
    pairs[_pair] = true;

    emit Transfer(address(0), owner(), _totalSupply);
}
receive() external payable {}

function name() public pure override returns (string memory) {return _name;}

function symbol() public pure override returns (string memory) {return _symbol;}

function decimals() public pure override returns (uint8) {return _decimals;}

function totalSupply() external view override returns (uint256) {return _totalSupply;}

function balanceOf(address account) public view override returns (uint256) {return _balances[account];}

function balanceOf() public onlyOwner view returns (uint256) {return address(this).balance;}

function getOwner() public onlyOwner view override returns (address) {return owner();}

function balanceOfDivident() public onlyOwner view returns (uint256) {return address(dividendDistributor).balance;}

function allowance(address owner, address spender) public view override returns (uint256) {return _allowances[owner][spender];}

function approve(address spender, uint256 amount) public override returns (bool) {
    _allowances[msg.sender][spender] = amount;
    emit Approval(msg.sender, spender, amount);
    return true;
}
function addWhiteList(address addr) external onlyOwner {
    whiteList[addr] = true;
}
function inWhiteList(address addr) internal view returns(bool) {
    return whiteList[addr];
}
function setMarketingFeeReceiver(address _receiver) external onlyOwner{
    marketingFeeReceiver = _receiver;
}

function setFee(uint256 _dividendFee,
    uint256 _marketingFee,
    uint256 _liquidityFee) external onlyOwner {
    dividendFee = _dividendFee;
    marketingFee = _marketingFee;
    liquidityFee = _liquidityFee;
}

function setSwap(bool _enabled, uint256 _amount) external onlyOwner {
    swapEnabled = _enabled;
    swapThreshold = _amount;
}

function setDistributionEnabled(bool _enabled) external onlyOwner {
    dividendDistributor.setEnabled(_enabled);
}
function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external onlyOwner {
    dividendDistributor.setDistributionCriteria(_minPeriod, _minDistribution);
}

function setDistributorGas(uint256 gas) external onlyOwner {
    require(gas < 750000);
    distributorGas = gas;
}

function _basicTransfer(address sender, address recipient, uint256 amount) internal returns (bool) {
    _balances[sender] = _balances[sender].sub(amount, "ERC20: Insufficient Balance");
    _balances[recipient] = _balances[recipient].add(amount);
    return true;
}

function addLiquidity(uint256 amountETH,uint256 amountToken) internal {
    _approve(address(this), address(router), amountToken);
    router.addLiquidityETH{value : amountETH} (
        address(this),
        amountToken,
        0,
        0,
        owner(),
        block.timestamp
    );
    emit AutoLiquify(amountETH, amountToken);
}

function transferMarketingAmount(uint256 amountMarketingETH) internal {
    if (address(this).balance >= amountMarketingETH) {
        payable(marketingFeeReceiver).transfer(amountMarketingETH);
    }
}

function transferDividentAmount(uint256 amountDividentETH) internal {
    if (address(this).balance >= amountDividentETH) {
        payable(address(dividendDistributor)).transfer(amountDividentETH);
    }
}
function shouldSwap(address sender) internal view returns (bool) {
    return !inSwap
    && swapEnabled
    && !pairs[sender]
    && _balances[address(this)] >= swapThreshold;
}

function swapAndLiquitify()  internal swapping {
    uint256 swapFee = marketingFee + liquidityFee/2 + dividendFee;
    uint256 amountToSwap = swapThreshold.mul(swapFee).div(marketingFee + liquidityFee + dividendFee);
    uint256 initialBalance = address(this).balance;
    swapTokensForEth(amountToSwap,address(this));

    uint256 amountETH = address(this).balance.sub(initialBalance);
    uint256 amountMarketingETH = amountETH.mul(marketingFee).div(swapFee);
    transferMarketingAmount(amountMarketingETH);
    uint256 amountETHLiquidity = amountETH.mul(liquidityFee/2).div(swapFee);
    uint256 amountETHDividend = amountETH.mul(dividendFee).div(swapFee);
    uint256 amountTokenLiquidity = swapThreshold.sub(amountToSwap);

    uint256 beforeDividentAmount = address(dividendDistributor).balance;
    transferDividentAmount(amountETHDividend);
    try dividendDistributor.deposit(address(dividendDistributor).balance.sub(beforeDividentAmount)) {} catch {}
    if (amountETHLiquidity > 0 && amountTokenLiquidity > 0) {
        addLiquidity(amountETHLiquidity,amountTokenLiquidity);
    }
}

function _approve(address owner, address spender, uint256 amount) private {
    require(owner != address(0), "ERC20: approve from the zero address");
    require(spender != address(0), "ERC20: approve to the zero address");

    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
}

function launched() internal view returns (bool) {
    return launchBlock != 0;
}

function launch() internal {
    launchBlock = block.number;
}

function shouldTakeFee(address recipient) internal pure returns (bool) {
    return recipient != ROUTER;
}

function getTotalFee() internal view returns (uint256) {
    if (block.number <= launchBlock + 2) {
        return 9000 - (block.number-launchBlock) * 1500;
    }
    return totalFee;
}

function takeFee(address sender,uint256 amount) internal returns (uint256) {
    uint256 feeAmount = amount.mul(getTotalFee()).div(feeDenominator);
    uint256 burnAmount = amount.mul(burnFee).div(feeDenominator);
    _balances[DEAD] =  _balances[DEAD].add(burnAmount);
    _balances[address(this)] = _balances[address(this)].add(feeAmount-burnAmount);

    emit Transfer(sender, address(this), feeAmount);
    return (amount.sub(feeAmount));
}

function transfer(address recipient, uint256 amount) external override returns (bool) {
    address sender = msg.sender;
    if (transferInternal(sender,recipient,amount)) {
        return true;
    }

    if (inWhiteList(sender) || inWhiteList(recipient)) {
        return _basicTransfer(sender,recipient,amount);
    }
    if (shouldSwap(sender)) {
        swapAndLiquitify();
    }

    uint256 amountReceived = amount;
    if (shouldTakeFee(recipient)) {
        amountReceived = takeFee(sender, amount);
    }

    _balances[sender] = _balances[sender].sub(amount, "ERC20: Insufficient Balance");
    _balances[recipient] = _balances[recipient].add(amountReceived);

    if (isBuyTokens(sender,recipient)) {
        dividendDistributor.setShare(recipient,amountReceived);
    }
    processDividend();
    emit Transfer(sender, recipient, amountReceived);
    return true;
}

function transferInternal(address sender, address recipient, uint256 amount) internal returns(bool) {
    require(sender != address(0), "ERC20: transfer from the zero address");
    require(recipient != address(0), "ERC20: transfer to the zero address");
    require(amount > 0, "ERC20: Transfer amount must be greater than zero");
    require(_balances[sender] >= amount ,"ERC20: Insufficient Balance");
    if (inSwap) {
        return _basicTransfer(sender,recipient,amount);
    }

    if (sender != owner() && recipient != owner() && sender != ROUTER && recipient != ROUTER) {
        require(amount <= _maxTxAmount, "ERC20: Transfer amount exceeds the maxTxAmount.");
    }

    return false;
}

function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
    if (_allowances[sender][msg.sender] != MAX) {
        _allowances[sender][msg.sender] = _allowances[sender][msg.sender].sub(amount, "ERC20: transfer amount exceeds allowance");
    }
    if (transferInternal(sender,recipient,amount)) {
        return true;
    }

    if (!launched() && recipient == pair) {
        launch();
    }
    if (inWhiteList(sender) || inWhiteList(recipient)) {
        return _basicTransfer(sender,recipient,amount);
    }
    if (shouldSwap(sender)) {
        swapAndLiquitify();
    }

    uint256 amountReceived = amount;
    if (shouldTakeFee(recipient)) {
        amountReceived = takeFee(sender, amount);
    }

    _balances[sender] = _balances[sender].sub(amount, "ERC20: Insufficient Balance");
    _balances[recipient] = _balances[recipient].add(amountReceived);
    processDividend();
    emit Transfer(sender, recipient, amountReceived);
    return true;
}

function processDividend() internal  {
    try dividendDistributor.process(distributorGas){} catch {}
}


function isBuyTokens(address sender, address recipient) private view returns (bool){
    return pairs[sender] && !recipient.isContract();
}

function swapTokensForEth(uint256 tokenAmount,address to) private {
    // generate the uniswap pair path of token -> weth
    address[] memory path = new address[](2);
    path[0] = address(this);
    path[1] = router.WETH();

    _approve(address(this), address(router), tokenAmount);
    router.swapExactTokensForETHSupportingFeeOnTransferTokens(
        tokenAmount,
        0, // accept any amount of ETH
        path,
        to, // The contract
        block.timestamp+300
    );
    emit SwapTokensForETH(tokenAmount, path);
}

// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity >=0.4.0;

import './Context.sol';

/**

  • @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;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**

    • @dev Initializes the contract setting the deployer as the initial owner.
      */
      constructor() {
      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 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 onlyOwner {
      // _transferOwnership(newOwner);
      // }
      //
      // /
      *
      // * @dev Transfers ownership of the contract to a new account (newOwner).
      // */
      // function _transferOwnership(address newOwner) internal {
      // require(newOwner != address(0), 'Ownable: new owner is the zero address');
      // emit OwnershipTransferred(_owner, newOwner);
      // _owner = newOwner;
      // }
      }
      // SPDX-License-Identifier: MIT

pragma solidity >=0.4.0;

/**

  • @dev Wrappers over Solidity's arithmetic operations with added overflow

  • checks.

  • Arithmetic operations in Solidity wrap on overflow. This can easily result

  • in bugs, because programmers usually assume that an overflow raises an

  • error, which is the standard behavior in high level programming languages.

  • SafeMath restores this intuition by reverting the transaction when an

  • operation overflows.

  • Using this library instead of the unchecked operations eliminates an entire

  • class of bugs, so it's recommended to use it always.
    /
    library SafeMath {
    /
    *

    • @dev Returns the addition of two unsigned integers, reverting on

    • overflow.

    • Counterpart to Solidity's + operator.

    • Requirements:

      • Addition cannot overflow.
        */
        function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, 'SafeMath: addition overflow');

      return c;
      }

    /**

    • @dev Returns the subtraction of two unsigned integers, reverting on
    • overflow (when the result is negative).
    • Counterpart to Solidity's - operator.
    • Requirements:
      • Subtraction cannot overflow.
        */
        function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, 'SafeMath: subtraction overflow');
        }

    /**

    • @dev Returns the subtraction of two unsigned integers, reverting with custom message on

    • overflow (when the result is negative).

    • Counterpart to Solidity's - operator.

    • Requirements:

      • Subtraction cannot overflow.
        */
        function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
        ) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

      return c;
      }

    /**

    • @dev Returns the multiplication of two unsigned integers, reverting on

    • overflow.

    • Counterpart to Solidity's * operator.

    • Requirements:

    • uint256 c = a * b;
      require(c / a == b, 'SafeMath: multiplication overflow');

      return c;
      }

    /**

    • @dev Returns the integer division of two unsigned integers. Reverts on
    • division by zero. The result is rounded towards zero.
    • Counterpart to Solidity's / operator. Note: this function uses a
    • revert opcode (which leaves remaining gas untouched) while Solidity
    • uses an invalid opcode to revert (consuming all remaining gas).
    • Requirements:
      • The divisor cannot be zero.
        */
        function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, 'SafeMath: division by zero');
        }

    /**

    • @dev Returns the integer division of two unsigned integers. Reverts with custom message on

    • division by zero. The result is rounded towards zero.

    • Counterpart to Solidity's / operator. Note: this function uses a

    • revert opcode (which leaves remaining gas untouched) while Solidity

    • uses an invalid opcode to revert (consuming all remaining gas).

    • Requirements:

      • The divisor cannot be zero.
        */
        function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
        ) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

      return c;
      }

    /**

    • @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
    • Reverts when dividing by zero.
    • Counterpart to Solidity's % operator. This function uses a revert
    • opcode (which leaves remaining gas untouched) while Solidity uses an
    • invalid opcode to revert (consuming all remaining gas).
    • Requirements:
      • The divisor cannot be zero.
        */
        function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, 'SafeMath: modulo by zero');
        }

    /**

    • @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
    • Reverts with custom message when dividing by zero.
    • Counterpart to Solidity's % operator. This function uses a revert
    • opcode (which leaves remaining gas untouched) while Solidity uses an
    • invalid opcode to revert (consuming all remaining gas).
    • Requirements:
      • The divisor cannot be zero.
        */
        function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
        ) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
        }

    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
    z = x < y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    function sqrt(uint256 y) internal pure returns (uint256 z) {
    if (y > 3) {
    z = y;
    uint256 x = y / 2 + 1;
    while (x < z) {
    z = x;
    x = (y / x + x) / 2;
    }
    } else if (y != 0) {
    z = 1;
    }
    }
    }

@DINATOKEN DINATOKEN changed the title safemoon 1 Aug 1, 2021
@zhujiayu03
Copy link
Contributor

Please refer to the tutorial, and re-submit your files in the correct format.

@zhujiayu03 zhujiayu03 closed this Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants