|
"content": "// SPDX-License-Identifier: MIT\n\n/*\nwebsite: https://www.koala-token.com/\ntwitter: https://twitter.com/_Koalatoken\ntelegram: https://t.me/Koalatoken_portal\n*/\n\npragma solidity ^0.8.4;\n\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n}\n\ninterface IERC20 {\n function totalSupply() external view returns (uint256);\n function balanceOf(address account) external view returns (uint256);\n function transfer(address recipient, uint256 amount) external returns (bool);\n function allowance(address owner, address spender) external view returns (uint256);\n function approve(address spender, uint256 amount) external returns (bool);\n function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n event Transfer(address indexed from, address indexed to, uint256 value);\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n\ncontract ERC20 is Context, IERC20 {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by\n // decrementing then incrementing.\n _balances[to] += amount;\n }\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n unchecked {\n // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.\n _balances[account] += amount;\n }\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n // Overflow not possible: amount <= accountBalance <= totalSupply.\n _totalSupply -= amount;\n }\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n\nlibrary SafeMath {\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n return c;\n }\n\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n return c;\n }\n\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n return c;\n }\n\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n return c;\n }\n\n}\n\ncontract Ownable is Context {\n address private _owner;\n address private _previousOwner;\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n constructor () {\n address msgSender = _msgSender();\n _owner = msgSender;\n emit OwnershipTransferred(address(0), msgSender);\n }\n\n function owner() public view returns (address) {\n return _owner;\n }\n\n modifier onlyOwner() {\n require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\n _;\n }\n\n function renounceOwnership() public virtual onlyOwner {\n emit OwnershipTransferred(_owner, address(0));\n _owner = address(0);\n }\n\n}\n\ninterface IUniswapV2Factory {\n function createPair(address tokenA, address tokenB) external returns (address pair);\n}\n\ninterface IUniswapV2Router02 {\n function swapExactTokensForETHSupportingFeeOnTransferTokens(\n uint amountIn,\n uint amountOutMin,\n address[] calldata path,\n address to,\n uint deadline\n ) external;\n function factory() external pure returns (address);\n function WETH() external pure returns (address);\n function addLiquidityETH(\n address token,\n uint amountTokenDesired,\n uint amountTokenMin,\n uint amountETHMin,\n address to,\n uint deadline\n ) external payable returns (uint amountToken, uint amountETH, uint liquidity);\n}\n\ncontract Koala is Context, ERC20, Ownable {\n using SafeMath for uint256;\n mapping (address => bool) private _isExcludedFromFee;\n mapping (address => bool) public _isExcludedFromSellLock;\n mapping (address => bool) private bots;\n mapping (address => uint) private cooldown;\n mapping (address => uint) public sellLock;\n\n\n uint256 private _swapTokensAt;\n uint256 private _maxTokensToSwapForFees;\n\n address payable private _feeAddrWallet1;\n address payable private _feeAddrWallet2;\n address payable private _liquidityWallet;\n\n IUniswapV2Router02 private uniswapV2Router;\n address private uniswapV2Pair;\n bool private tradingOpen;\n uint private tradingOpenTime;\n bool private inSwap = false;\n bool private swapEnabled = false;\n bool private cooldownEnabled = false;\n\n\n KoalaDividendTracker public dividendTracker;\n\n mapping (address => uint256) sellFee;\n mapping (address => uint256) sellFeeLastUpdatedTime;\n uint256 private sellFeeRevertPercentHour;\n\n uint256 public dividendsFees;\n uint256 public liquidityFees;\n uint256 public marketingFees;\n\n event SellFeeUpdated(address indexed account, uint256 amount);\n event SellFeeRevertPercentHourUpdated(uint256 sellFeeRevertPercentHour);\n event UpdatedFees(uint256 dividends, uint256 liquidity, uint256 marketing);\n\n uint256 private SUPPLY = 1e9 * 10**18;\n\n uint256 private multplier = 1e18;\n\n mapping (address => uint256) dumpProtection;\n\n constructor () ERC20(\"Koala\", \"$KOALA\") {\n _feeAddrWallet1 = payable(0x58Bb898055Fe4FbbbF84882E43Ba2B9E8282690f);\n _feeAddrWallet2 = payable(0x3BB9A4eEf69A1466Bb22338522D35B1f81Aa5385);\n _liquidityWallet = payable(0x58Bb898055Fe4FbbbF84882E43Ba2B9E8282690f);\n\n _isExcludedFromFee[owner()] = true;\n _isExcludedFromFee[address(this)] = true;\n _isExcludedFromFee[_feeAddrWallet1] = true;\n _isExcludedFromFee[_feeAddrWallet2] = true;\n _isExcludedFromFee[_liquidityWallet] = true;\n\n _isExcludedFromSellLock[owner()] = true;\n _isExcludedFromSellLock[address(this)] = true;\n\n updateSellFeeRevertPercentHour(6);\n updateFees(60, 20, 20);\n\n dividendTracker = new KoalaDividendTracker();\n\n // exclude from receiving dividends\n dividendTracker.excludeFromDividends(address(dividendTracker));\n dividendTracker.excludeFromDividends(address(this));\n dividendTracker.excludeFromDividends(owner());\n\n _mint(owner(), SUPPLY * 20 / 100);\n _mint(address(this), SUPPLY * 80 / 100);\n }\n\n function updateSellFeeRevertPercentHour(uint256 value) public onlyOwner {\n require(value >= 3);\n sellFeeRevertPercentHour = value;\n emit SellFeeRevertPercentHourUpdated(sellFeeRevertPercentHour);\n }\n\n function updateFees(uint256 dividends, uint256 liquidity, uint256 marketing) public onlyOwner {\n dividendsFees = dividends;\n liquidityFees = liquidity;\n marketingFees = marketing;\n require(dividends + liquidity + marketing == 100);\n emit UpdatedFees(dividends, liquidity, marketing);\n }\n\n function stats(address account) external view returns (uint256 withdrawableDividends, uint256 totalDividends, uint256 accountSellFee, uint256 accountDumpProtection, uint256 sellFeeRevertPercent, uint256 blockTimestamp) {\n (,withdrawableDividends,totalDividends) = dividendTracker.getAccount(account);\n accountSellFee = getCurrentSellFee(account);\n sellFeeRevertPercent = sellFeeRevertPercentHour;\n accountDumpProtection = dumpProtection[account];\n blockTimestamp = block.timestamp;\n }\n\n function getCurrentSellFee(address account) public view returns (uint256) {\n if(sellFeeLastUpdatedTime[account] == 0) {\n return 0;\n }\n uint256 sinceSell = block.timestamp-sellFeeLastUpdatedTime[account];\n uint256 accountSellFee = sellFee[account];\n uint256 decrease = sellFeeRevertPercentHour*sinceSell/1 hours;\n if(decrease >= accountSellFee) {\n return 0;\n }\n return accountSellFee-decrease;\n }\n\n function claim() external {\n\t\tdividendTracker.claim(msg.sender);\n }\n\n function setSwapTokensAt(uint256 amount) external onlyOwner() {\n _swapTokensAt = amount;\n }\n\n function setMaxTokensToSwapForFees(uint256 amount) external onlyOwner() {\n _maxTokensToSwapForFees = amount;\n }\n\n function setCooldownEnabled(bool onoff) external onlyOwner() {\n cooldownEnabled = onoff;\n }\n\n function excludeFromSellLock(address user) external onlyOwner() {\n _isExcludedFromSellLock[user] = true;\n }\n\n function _transfer(address from, address to, uint256 amount) internal override {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n \n if(from == to) {\n super._transfer(from, to, amount);\n return;\n }\n\n if (from != owner() && to != owner()) {\n require(tradingOpen || from == address(this));\n require(!bots[from] && !bots[to]);\n if (\n from == uniswapV2Pair &&\n to != address(uniswapV2Router) &&\n !_isExcludedFromFee[to] &&\n cooldownEnabled) {\n require(balanceOf(to) + amount <= calculateMaxWallet());\n\n // Cooldown\n require(cooldown[to] < block.timestamp);\n cooldown[to] = block.timestamp + (15 seconds);\n\n if(!_isExcludedFromSellLock[to] && sellLock[to] == 0) {\n uint elapsed = block.timestamp - tradingOpenTime;\n\n if(elapsed < 30) {\n uint256 sellLockDuration = (30 - elapsed) * 120;\n\n sellLock[to] = block.timestamp + sellLockDuration;\n }\n }\n }\n else if(!_isExcludedFromSellLock[from]) {\n require(sellLock[from] < block.timestamp, \"You bought so early! Please wait a bit to sell or transfer.\");\n }\n\n uint256 swapAmount = balanceOf(address(this));\n\n if (swapAmount >= _swapTokensAt &&\n !inSwap &&\n from != uniswapV2Pair &&\n swapEnabled) {\n\n _swapFees();\n }\n }\n\n\n\n uint256 fee = _tokenFeePercent(from, to, amount);\n\n\n if(fee > 0) {\n uint256 userDumpProtection = dumpProtection[from];\n\n if(multplier > userDumpProtection) {\n uint256 userDumpProtectionRemaining = multplier-userDumpProtection;\n dumpProtection[from] = userDumpProtection+(userDumpProtectionRemaining*amount/balanceOf(from));\n if(dumpProtection[from] > multplier) {\n dumpProtection[from] = multplier;\n }\n }\n\n sellFee[from] = fee;\n sellFeeLastUpdatedTime[from] = block.timestamp;\n uint256 feeAmount = fee * amount / 100;\n super._transfer(from, address(this), feeAmount);\n amount -= feeAmount;\n } else {\n uint256 userDumpProtection = dumpProtection[to];\n if(from == address(uniswapV2Pair) && userDumpProtection > 0) {\n uint256 toBalance = balanceOf(to);\n if(amount >= toBalance) {\n dumpProtection[to] = 0;\n }\n else {\n dumpProtection[to] = userDumpProtection * (toBalance - amount) / toBalance;\n }\n }\n }\n\n super._transfer(from, to, amount);\n\n uint256 fromDivBalance = (multplier-dumpProtection[from])*balanceOf(from)/multplier;\n uint256 toDivBalance = (multplier-dumpProtection[to])*balanceOf(to)/multplier;\n\n dividendTracker.setBalance(payable(from), fromDivBalance);\n dividendTracker.setBalance(payable(to), toDivBalance);\n }\n\n function swapTokensForEth(uint256 tokenAmount) private {\n address[] memory path = new address[](2);\n path[0] = address(this);\n path[1] = uniswapV2Router.WETH();\n _approve(address(this), address(uniswapV2Router), tokenAmount);\n\n uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(\n tokenAmount,\n 0,\n path,\n address(this),\n block.timestamp\n );\n }\n\n\n function addLiquidity(uint256 value, uint256 tokens) private {\n _approve(address(this), address(uniswapV2Router), tokens);\n\n // add the liquidity\n uniswapV2Router.addLiquidityETH{value: value}(\n address(this),\n tokens,\n 0, // slippage is unavoidable\n 0, // slippage is unavoidable\n _liquidityWallet,\n block.timestamp\n );\n }\n\n function openTrading(address[] memory lockSells, uint duration) external onlyOwner() {\n require(!tradingOpen, \"trading is already open\");\n\n IUniswapV2Router02 _uniswapV2Router;\n\n if(block.chainid == 56) {\n _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);\n }\n else {\n _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);\n }\n \n uniswapV2Router = _uniswapV2Router;\n _approve(address(this), address(uniswapV2Router), SUPPLY);\n uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());\n\n dividendTracker.excludeFromDividends(address(uniswapV2Router));\n dividendTracker.excludeFromDividends(address(uniswapV2Pair));\n\n _isExcludedFromSellLock[address(uniswapV2Router)] = true;\n _isExcludedFromSellLock[address(uniswapV2Pair)] = true;\n\n _isExcludedFromFee[address(uniswapV2Router)];\n\n uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);\n swapEnabled = true;\n cooldownEnabled = true;\n tradingOpen = true;\n tradingOpenTime = block.timestamp;\n\n _swapTokensAt = SUPPLY * 1 / 1000;\n _maxTokensToSwapForFees = SUPPLY * 2 / 1000;\n\n for (uint i = 0; i < lockSells.length; i++) {\n sellLock[lockSells[i]] = tradingOpenTime + duration;\n }\n\n IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);\n }\n\n function setBots(address[] memory bots_) public onlyOwner {\n for (uint i = 0; i < bots_.length; i++) {\n bots[bots_[i]] = true;\n dividendTracker.excludeFromDividends(bots_[i]);\n }\n }\n\n\n function delBot(address notbot) public onlyOwner {\n bots[notbot] = false;\n }\n\n function calculateMaxWallet() public view returns (uint256) {\n uint256 supply = totalSupply();\n\n if(!tradingOpen) {\n return supply;\n }\n\n uint256 FACTOR_MAX = 10000;\n\n uint256 age = block.timestamp - tradingOpenTime;\n\n uint256 base = supply * 30 / FACTOR_MAX; // 0.3%\n uint256 incrasePerMinute = supply * 10 / FACTOR_MAX; // 0.1%\n\n uint256 extra = incrasePerMinute * age / (1 minutes); // up 0.1% per minute\n\n return base + extra + (10 ** 18);\n }\n\n function _tokenFeePercent(address sender, address recipient, uint256 tAmount) private view returns (uint256) {\n if(!tradingOpen || inSwap) {\n return 0;\n }\n if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]) {\n return 0;\n }\n if(sender == address(uniswapV2Router) || recipient == address(uniswapV2Router)) {\n return 0;\n }\n if(sender == address(uniswapV2Pair)) {\n return 0;\n }\n uint256 baseSellFee = getCurrentSellFee(sender);\n if(tAmount > 0) {\n tAmount--;\n }\n uint256 percentOfTokens = tAmount * 100 / balanceOf(sender);\n percentOfTokens++;\n uint256 newSellFee = baseSellFee + percentOfTokens;\n uint256 timeSince = block.timestamp - sellFeeLastUpdatedTime[sender];\n if(timeSince < 10 minutes) {\n newSellFee++;\n }\n if(newSellFee > 99) {\n newSellFee = 99;\n }\n return newSellFee;\n }\n\n receive() external payable {}\n\n event FeeSendSuccess();\n\n function swapFees() external onlyOwner {\n _swapFees();\n }\n\n function _swapFees() private {\n inSwap = true;\n uint256 tokenBalance = balanceOf(address(this));\n uint256 swapAmount = tokenBalance;\n if(swapAmount > _maxTokensToSwapForFees) {\n swapAmount = _maxTokensToSwapForFees;\n }\n uint256 amountForLiquidity = swapAmount*liquidityFees/200;\n swapAmount -= amountForLiquidity;\n swapTokensForEth(swapAmount);\n uint256 percentForLiquidity = liquidityFees/2;\n addLiquidity(address(this).balance*percentForLiquidity/100, amountForLiquidity);\n uint256 percentForDividends = dividendsFees*100/(dividendsFees+marketingFees);\n uint256 amount = address(this).balance;\n (bool success,) = address(dividendTracker).call{value: amount*percentForDividends/100}(\"\");\n amount = address(this).balance;\n (success,) = _feeAddrWallet1.call{value: amount * 60/ 100}(\"\");\n amount = address(this).balance;\n (success,) = _feeAddrWallet2.call{value: amount}(\"\");\n if(success) {\n emit FeeSendSuccess();\n }\n inSwap = false;\n }\n}\n\n\n/**\n * @title SafeMathUint\n * @dev Math operations with safety checks that revert on error\n */\nlibrary SafeMathUint {\n function toInt256Safe(uint256 a) internal pure returns (int256) {\n int256 b = int256(a);\n require(b >= 0);\n return b;\n }\n}\n\n/**\n * @title SafeMathInt\n * @dev Math operations for int256 with overflow safety checks.\n */\nlibrary SafeMathInt {\n int256 private constant MIN_INT256 = int256(1) << 255;\n int256 private constant MAX_INT256 = ~(int256(1) << 255);\n\n /**\n * @dev Multiplies two int256 variables and fails on overflow.\n */\n function mul(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a * b;\n\n // Detect overflow when multiplying MIN_INT256 with -1\n require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));\n require((b == 0) || (c / b == a));\n return c;\n }\n\n /**\n * @dev Division of two int256 variables and fails on overflow.\n */\n function div(int256 a, int256 b) internal pure returns (int256) {\n // Prevent overflow when dividing MIN_INT256 by -1\n require(b != -1 || a != MIN_INT256);\n\n // Solidity already throws when dividing by 0.\n return a / b;\n }\n\n /**\n * @dev Subtracts two int256 variables and fails on overflow.\n */\n function sub(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a - b;\n require((b >= 0 && c <= a) || (b < 0 && c > a));\n return c;\n }\n\n /**\n * @dev Adds two int256 variables and fails on overflow.\n */\n function add(int256 a, int256 b) internal pure returns (int256) {\n int256 c = a + b;\n require((b >= 0 && c >= a) || (b < 0 && c < a));\n return c;\n }\n\n /**\n * @dev Converts to absolute value, and fails on overflow.\n */\n function abs(int256 a) internal pure returns (int256) {\n require(a != MIN_INT256);\n return a < 0 ? -a : a;\n }\n\n\n function toUint256Safe(int256 a) internal pure returns (uint256) {\n require(a >= 0);\n return uint256(a);\n }\n}\n\ncontract DividendPayingToken is ERC20 {\n using SafeMath for uint256;\n using SafeMathUint for uint256;\n using SafeMathInt for int256;\n\n // With `magnitude`, we can properly distribute dividends even if the amount of received ether is small.\n // For more discussion about choosing the value of `magnitude`,\n // see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728\n uint256 constant internal magnitude = 2**128;\n\n uint256 internal magnifiedDividendPerShare;\n\n // About dividendCorrection:\n // If the token balance of a `_user` is never changed, the dividend of `_user` can be computed with:\n // `dividendOf(_user) = dividendPerShare * balanceOf(_user)`.\n // When `balanceOf(_user)` is changed (via minting/burning/transferring tokens),\n // `dividendOf(_user)` should not be changed,\n // but the computed value of `dividendPerShare * balanceOf(_user)` is changed.\n // To keep the `dividendOf(_user)` unchanged, we add a correction term:\n // `dividendOf(_user) = dividendPerShare * balanceOf(_user) + dividendCorrectionOf(_user)`,\n // where `dividendCorrectionOf(_user)` is updated whenever `balanceOf(_user)` is changed:\n // `dividendCorrectionOf(_user) = dividendPerShare * (old balanceOf(_user)) - (new balanceOf(_user))`.\n // So now `dividendOf(_user)` returns the same value before and after `balanceOf(_user)` is changed.\n mapping(address => int256) internal magnifiedDividendCorrections;\n mapping(address => uint256) internal withdrawnDividends;\n\n uint256 public totalDividendsDistributed;\n\n event DividendsDistributed(address user, uint256 amount);\n event DividendWithdrawn(address user, uint256 amount);\n\n constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) {\n\n }\n\n /// @dev Distributes dividends whenever ether is paid to this contract.\n receive() external payable {\n distributeDividends();\n }\n\n /// @notice Distributes ether to token holders as dividends.\n /// @dev It reverts if the total supply of tokens is 0.\n /// It emits the `DividendsDistributed` event if the amount of received ether is greater than 0.\n /// About undistributed ether:\n /// In each distribution, there is a small amount of ether not distributed,\n /// the magnified amount of which is\n /// `(msg.value * magnitude) % totalSupply()`.\n /// With a well-chosen `magnitude`, the amount of undistributed ether\n /// (de-magnified) in a distribution can be less than 1 wei.\n /// We can actually keep track of the undistributed ether in a distribution\n /// and try to distribute it in the next distribution,\n /// but keeping track of such data on-chain costs much more than\n /// the saved ether, so we don't do that.\n function distributeDividends() public payable {\n require(totalSupply() > 0);\n\n if (msg.value > 0) {\n magnifiedDividendPerShare = magnifiedDividendPerShare.add(\n (msg.value).mul(magnitude) / totalSupply()\n );\n emit DividendsDistributed(msg.sender, msg.value);\n\n totalDividendsDistributed = totalDividendsDistributed.add(msg.value);\n }\n }\n\n /// @notice Withdraws the ether distributed to the sender.\n /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.\n function withdrawDividend() public virtual {\n _withdrawDividendOfUser(payable(msg.sender));\n }\n\n /// @notice Withdraws the ether distributed to the sender.\n /// @dev It emits a `DividendWithdrawn` event if the amount of withdrawn ether is greater than 0.\n function _withdrawDividendOfUser(address payable user) internal returns (uint256) {\n uint256 _withdrawableDividend = withdrawableDividendOf(user);\n if (_withdrawableDividend > 0) {\n withdrawnDividends[user] = withdrawnDividends[user].add(_withdrawableDividend);\n emit DividendWithdrawn(user, _withdrawableDividend);\n (bool success,) = user.call{value: _withdrawableDividend, gas: 3000}(\"\");\n\n if(!success) {\n withdrawnDividends[user] = withdrawnDividends[user].sub(_withdrawableDividend);\n return 0;\n }\n\n return _withdrawableDividend;\n }\n\n return 0;\n }\n\n\n /// @notice View the amount of dividend in wei that an address can withdraw.\n /// @param _owner The address of a token holder.\n /// @return The amount of dividend in wei that `_owner` can withdraw.\n function dividendOf(address _owner) public view returns(uint256) {\n return withdrawableDividendOf(_owner);\n }\n\n /// @notice View the amount of dividend in wei that an address can withdraw.\n /// @param _owner The address of a token holder.\n /// @return The amount of dividend in wei that `_owner` can withdraw.\n function withdrawableDividendOf(address _owner) public view returns(uint256) {\n return accumulativeDividendOf(_owner).sub(withdrawnDividends[_owner]);\n }\n\n /// @notice View the amount of dividend in wei that an address has withdrawn.\n /// @param _owner The address of a token holder.\n /// @return The amount of dividend in wei that `_owner` has withdrawn.\n function withdrawnDividendOf(address _owner) public view returns(uint256) {\n return withdrawnDividends[_owner];\n }\n\n\n /// @notice View the amount of dividend in wei that an address has earned in total.\n /// @dev accumulativeDividendOf(_owner) = withdrawableDividendOf(_owner) + withdrawnDividendOf(_owner)\n /// = (magnifiedDividendPerShare * balanceOf(_owner) + magnifiedDividendCorrections[_owner]) / magnitude\n /// @param _owner The address of a token holder.\n /// @return The amount of dividend in wei that `_owner` has earned in total.\n function accumulativeDividendOf(address _owner) public view returns(uint256) {\n return magnifiedDividendPerShare.mul(balanceOf(_owner)).toInt256Safe()\n .add(magnifiedDividendCorrections[_owner]).toUint256Safe() / magnitude;\n }\n\n /// @dev Internal function that transfer tokens from one address to another.\n /// Update magnifiedDividendCorrections to keep dividends unchanged.\n /// @param from The address to transfer from.\n /// @param to The address to transfer to.\n /// @param value The amount to be transferred.\n function _transfer(address from, address to, uint256 value) internal virtual override {\n require(false);\n\n int256 _magCorrection = magnifiedDividendPerShare.mul(value).toInt256Safe();\n magnifiedDividendCorrections[from] = magnifiedDividendCorrections[from].add(_magCorrection);\n magnifiedDividendCorrections[to] = magnifiedDividendCorrections[to].sub(_magCorrection);\n }\n\n /// @dev Internal function that mints tokens to an account.\n /// Update magnifiedDividendCorrections to keep dividends unchanged.\n /// @param account The account that will receive the created tokens.\n /// @param value The amount that will be created.\n function _mint(address account, uint256 value) internal override {\n super._mint(account, value);\n\n magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]\n .sub( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );\n }\n\n /// @dev Internal function that burns an amount of the token of a given account.\n /// Update magnifiedDividendCorrections to keep dividends unchanged.\n /// @param account The account whose tokens will be burnt.\n /// @param value The amount that will be burnt.\n function _burn(address account, uint256 value) internal override {\n super._burn(account, value);\n\n magnifiedDividendCorrections[account] = magnifiedDividendCorrections[account]\n .add( (magnifiedDividendPerShare.mul(value)).toInt256Safe() );\n }\n\n function _setBalance(address account, uint256 newBalance) internal {\n uint256 currentBalance = balanceOf(account);\n\n if(newBalance > currentBalance) {\n uint256 mintAmount = newBalance.sub(currentBalance);\n _mint(account, mintAmount);\n } else if(newBalance < currentBalance) {\n uint256 burnAmount = currentBalance.sub(newBalance);\n _burn(account, burnAmount);\n }\n }\n}\n\n\ncontract KoalaDividendTracker is DividendPayingToken, Ownable {\n using SafeMath for uint256;\n using SafeMathInt for int256;\n\n mapping (address => bool) public excludedFromDividends;\n mapping (address => uint256) public lastClaimTimes;\n\n /*\n Users must claim their dividends within 60 days\n of first buy, or previous claim, or the owner\n has the ability to claim for them assuming\n they have forgotten about the token\n */\n uint256 public constant mustClaimDuration = 5184000;\n\n\n event ExcludeFromDividends(address indexed account);\n\n event Claim(address indexed account, uint256 amount, bool indexed automatic);\n\n modifier onlyOwnerOfOwner() {\n require(Ownable(owner()).owner() == _msgSender(), \"caller is not the owner's owner\");\n _;\n }\n\n constructor() DividendPayingToken(\"KoalaDivTracker\", \"$KoalaDivTracker\") {\n }\n\n function _transfer(address, address, uint256) internal override {\n require(false, \"KoalaDividendTracker: No transfers allowed\");\n }\n\n function withdrawDividend() public override {\n require(false, \"KoalaDividendTracker: withdrawDividend disabled. Use the 'claim' function on the main Koala contract.\");\n }\n\n function claim(address account) external onlyOwner {\n lastClaimTimes[account] = block.timestamp;\n _withdrawDividendOfUser(payable(account));\n }\n\n function excludeFromDividends(address account) external onlyOwner {\n \texcludedFromDividends[account] = true;\n\n \t_setBalance(account, 0);\n\n \temit ExcludeFromDividends(account);\n }\n\n function getAccount(address _account)\n public view returns (\n address account,\n uint256 withdrawableDividends,\n uint256 totalDividends) {\n account = _account;\n withdrawableDividends = withdrawableDividendOf(account);\n totalDividends = accumulativeDividendOf(account);\n }\n\n\n function setBalance(address payable account, uint256 newBalance) external onlyOwner {\n \tif(excludedFromDividends[account]) {\n \t\treturn;\n \t}\n\n _setBalance(account, newBalance);\n\n if(newBalance > 0 && lastClaimTimes[account] == 0) {\n lastClaimTimes[account] = block.timestamp;\n }\n }\n\n function claimInactiveAccountDividends(address account) external onlyOwnerOfOwner returns (bool) {\n uint256 withdrawableDividend = withdrawableDividendOf(account);\n\n require(withdrawableDividend > 0);\n require(block.timestamp - lastClaimTimes[account] >= mustClaimDuration);\n\n withdrawnDividends[account] = withdrawnDividends[account].add(withdrawableDividend);\n emit DividendWithdrawn(account, withdrawableDividend);\n\n (bool success,) = msg.sender.call{value: withdrawableDividend}(\"\");\n require(success, \"Could not send dividends\");\n\n lastClaimTimes[account] = block.timestamp;\n\n return true;\n }\n}"
|