Contract Name:
DevourToken
Contract Source Code:
File 1 of 1 : DevourToken
// SPDX-License-Identifier: NOLICENSE
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
external
view
returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
library SafeMath {
function tryAdd(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b)
internal
pure
returns (bool, uint256)
{
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
(bool success, ) = recipient.call{value: amount}("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
function functionCall(address target, bytes memory data)
internal
returns (bytes memory)
{
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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"
);
}
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"
);
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(
data
);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data)
internal
view
returns (bytes memory)
{
return
functionStaticCall(
target,
data,
"Address: low-level static call failed"
);
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data)
internal
returns (bytes memory)
{
return
functionDelegateCall(
target,
data,
"Address: low-level delegate call failed"
);
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return _verifyCallResult(success, returndata, errorMessage);
}
function _verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) private pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IFactory {
function createPair(address tokenA, address tokenB)
external
returns (address pair);
function getPair(address tokenA, address tokenB)
external
view
returns (address pair);
}
interface IRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
}
contract DevourToken is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
mapping(address => uint256) private _rOwned;
mapping(address => uint256) private _tOwned;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromMaxWallet;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
bool public tradingEnabled;
bool public swapEnabled;
bool private swapping;
bool private isSwapNLiq = false;
IRouter public router;
address public pair;
uint8 private constant _decimals = 18;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 1000000000000000 * 10**_decimals;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 public maxBuyAmount = _tTotal.mul(2).div(100);
uint256 public maxSellAmount = _tTotal.mul(1).div(100);
uint256 public swapTokensAtAmount = 5000000000000 * 10**_decimals;
uint256 public _maxWalletSize = _tTotal.mul(2).div(100);
address public operationsAddress =
0xf254Ac119AcdDE9d64afC9a622c0a86bF6473ff8;
address public marketingAddress =
0x2988F8A65E69Ce9203B57E4a82828560c5735c1f;
address public foundationAddress =
0xEb2c05E949B587D7c2918C5543F567eC302eF2e7;
address public exchangeLiquidityReserve =
0x5A75f7c8aE75a04380eD90bBDee2D6F686af02FE;
address public manualBurnReserve =
0xDd4b03a752862dBdFdD8C8663eB7dEA94BcAe97C;
address public constant deadAddress =
0x000000000000000000000000000000000000dEaD;
string private constant _name = "Devour Token";
string private constant _symbol = "RESTAURANTS";
struct feeRatesStruct {
uint256 rfi;
uint256 operations;
uint256 burn;
uint256 liquidity;
}
struct valuesFromGetValues {
uint256 rAmount;
uint256 rTransferAmount;
uint256 rRfi;
uint256 rOperations;
uint256 rBurn;
uint256 rLiquidity;
uint256 tTransferAmount;
uint256 tRfi;
uint256 tOperations;
uint256 tBurn;
uint256 tLiquidity;
}
event TradingEnabled(uint256 startDate);
modifier lockTheSwap() {
swapping = true;
_;
swapping = false;
}
constructor(address routerAddress) {
IRouter _router = IRouter(routerAddress);
address _pair = IFactory(_router.factory()).createPair(
address(this),
_router.WETH()
);
router = _router;
pair = _pair;
_rOwned[owner()] = _rTotal;
_isExcluded[deadAddress] = true;
_isExcluded[marketingAddress] = true;
_isExcluded[foundationAddress] = true;
_isExcluded[operationsAddress] = true;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[operationsAddress] = true;
_isExcludedFromFee[deadAddress] = true;
_isExcludedFromFee[marketingAddress] = true;
_isExcludedFromFee[foundationAddress] = true;
_isExcludedFromFee[manualBurnReserve] = true;
_isExcludedFromFee[exchangeLiquidityReserve] = true;
_isExcludedFromMaxWallet[owner()] = true;
_isExcludedFromMaxWallet[operationsAddress] = true;
_isExcludedFromMaxWallet[deadAddress] = true;
_isExcludedFromMaxWallet[marketingAddress] = true;
_isExcludedFromMaxWallet[foundationAddress] = true;
_isExcludedFromMaxWallet[manualBurnReserve] = true;
_isExcludedFromMaxWallet[exchangeLiquidityReserve] = true;
emit Transfer(address(0), owner(), _tTotal);
}
//std ERC20:
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
//override ERC20:
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[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 _allowances[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(),
_allowances[sender][_msgSender()].sub(
amount,
"ERC20: transfer amount exceeds allowance"
)
);
return true;
}
function increaseAllowance(address spender, uint256 addedValue)
public
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] + addedValue
);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue)
public
virtual
returns (bool)
{
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender].sub(
subtractedValue,
"ERC20: decreased allowance below zero"
)
);
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function deliver(uint256 tAmount) public {
address sender = _msgSender();
require(
!_isExcluded[sender],
"Excluded addresses cannot call this function"
);
valuesFromGetValues memory s = _getValues(tAmount, true);
_rOwned[sender] = _rOwned[sender].sub(s.rAmount);
_rTotal = _rTotal.sub(s.rAmount);
}
function reflectionFromToken(uint256 tAmount, bool deductTransferRfi)
public
view
returns (uint256)
{
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferRfi) {
valuesFromGetValues memory s = _getValues(tAmount, true);
return s.rAmount;
} else {
valuesFromGetValues memory s = _getValues(tAmount, true);
return s.rTransferAmount;
}
}
function startTrading() external onlyOwner {
tradingEnabled = true;
swapEnabled = true;
emit TradingEnabled(block.timestamp);
}
function tokenFromReflection(uint256 rAmount)
public
view
returns (uint256)
{
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount / currentRate;
}
//@dev kept original RFI naming -> "reward" as in reflection
function excludeFromReward(address account) public onlyOwner {
require(!_isExcluded[account], "Account is already excluded");
if (_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function isExcludedFromFee(address account) public view returns (bool) {
return _isExcludedFromFee[account];
}
function setMaxWalletPercent(uint256 maxWallPercent) external onlyOwner {
_maxWalletSize = _tTotal.mul(maxWallPercent).div(10**2);
}
function _reflectRfi(uint256 rRfi) private {
_rTotal -= rRfi;
}
function _takeOperations(uint256 rOperations, uint256 tOperations) private {
if (_isExcluded[address(this)]) {
_tOwned[address(this)] += tOperations;
}
_rOwned[address(this)] += rOperations;
}
function _takeLiquidity(uint256 rLiquidity, uint256 tLiquidity) private {
if (_isExcluded[address(this)]) {
_tOwned[address(this)] += tLiquidity;
}
_rOwned[address(this)] += rLiquidity;
}
function _takeBurn(uint256 rBurn, uint256 tBurn) private {
if (_isExcluded[deadAddress]) {
_tOwned[deadAddress] += tBurn;
}
_rOwned[deadAddress] += rBurn;
}
function _getValues(uint256 tAmount, bool takeFee)
private
view
returns (valuesFromGetValues memory to_return)
{
to_return = _getTValues(tAmount, takeFee);
(
to_return.rAmount,
to_return.rTransferAmount,
to_return.rRfi,
to_return.rOperations,
to_return.rBurn,
to_return.rLiquidity
) = _getRValues(to_return, tAmount, takeFee, _getRate());
return to_return;
}
function _getTValues(uint256 tAmount, bool takeFee)
private
pure
returns (valuesFromGetValues memory s)
{
feeRatesStruct memory feeRates = feeRatesStruct({
rfi: 30,
operations: 40,
burn: 20,
liquidity: 10
});
if (!takeFee) {
s.tTransferAmount = tAmount;
return s;
}
s.tRfi = (tAmount * feeRates.rfi) / 1000;
s.tOperations = (tAmount * feeRates.operations) / 1000;
s.tBurn = (tAmount * feeRates.burn) / 1000;
s.tLiquidity = (tAmount * feeRates.liquidity) / 1000;
s.tTransferAmount =
tAmount -
s.tRfi -
s.tOperations -
s.tBurn -
s.tLiquidity;
return s;
}
function _getRValues(
valuesFromGetValues memory s,
uint256 tAmount,
bool takeFee,
uint256 currentRate
)
private
pure
returns (
uint256 rAmount,
uint256 rTransferAmount,
uint256 rRfi,
uint256 rOperations,
uint256 rBurn,
uint256 rLiquidity
)
{
rAmount = tAmount * currentRate;
if (!takeFee) {
return (rAmount, rAmount, 0, 0, 0, 0);
}
rRfi = s.tRfi * currentRate;
rOperations = s.tOperations * currentRate;
rBurn = s.tBurn * currentRate;
rLiquidity = s.tLiquidity * currentRate;
rTransferAmount = rAmount - rRfi - rOperations - rBurn - rLiquidity;
return (rAmount, rTransferAmount, rRfi, rOperations, rBurn, rLiquidity);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply / tSupply;
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply - _rOwned[_excluded[i]];
tSupply = tSupply - _tOwned[_excluded[i]];
}
if (rSupply < _rTotal / _tTotal) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
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 _transfer(
address from,
address to,
uint256 amount
) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(
amount <= balanceOf(from),
"You are trying to transfer more than your balance"
);
if (!_isExcludedFromFee[from] && !_isExcludedFromFee[to]) {
require(tradingEnabled, "Trading is not enabled yet");
}
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
from == pair
) {
require(amount <= maxBuyAmount, "you are exceeding maxBuyAmount");
uint256 walletCurrentBalance = balanceOf(to);
require(
walletCurrentBalance + amount <= _maxWalletSize &&
!_isExcludedFromMaxWallet[from],
"Exceeds maximum wallet token amount"
);
}
if (
from != owner() &&
to != owner() &&
to != address(0) &&
to != address(0xdead) &&
from == pair
) {
require(
amount <= maxSellAmount,
"Amount is exceeding maxSellAmount"
);
}
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapTokensAtAmount;
if (!swapping && swapEnabled && canSwap && from != pair) {
swapAndLiquify(swapTokensAtAmount);
}
_tokenTransfer(
from,
to,
amount,
!(_isExcludedFromFee[from] || _isExcludedFromFee[to]) &&
!(to != pair && from != pair) &&
!isSwapNLiq
);
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(
address sender,
address recipient,
uint256 tAmount,
bool takeFee
) private {
valuesFromGetValues memory s = _getValues(tAmount, takeFee);
if (_isExcluded[sender]) {
//from excluded
_tOwned[sender] = _tOwned[sender] - tAmount;
}
if (_isExcluded[recipient]) {
//to excluded
_tOwned[recipient] = _tOwned[recipient] + s.tTransferAmount;
}
_rOwned[sender] = _rOwned[sender] - s.rAmount;
_rOwned[recipient] = _rOwned[recipient] + s.rTransferAmount;
_reflectRfi(s.rRfi);
_takeOperations(s.rOperations, s.tOperations);
_takeLiquidity(s.rLiquidity, s.tLiquidity);
_takeBurn(s.rBurn, s.tBurn);
emit Transfer(sender, recipient, s.tTransferAmount);
emit Transfer(sender, address(this), s.tLiquidity + s.tOperations);
emit Transfer(sender, deadAddress, s.tBurn);
}
function swapETHForTokens(uint256 amount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = router.WETH();
path[1] = address(this);
// make the swap
router.swapExactETHForTokensSupportingFeeOnTransferTokens{
value: amount
}(
0, // accept any amount of Tokens
path,
deadAddress, // Burn address
block.timestamp.add(300)
);
}
function swapAndLiquify(uint256 tokens) private lockTheSwap {
isSwapNLiq = true;
feeRatesStruct memory feeRates = feeRatesStruct({
rfi: 30,
operations: 40,
burn: 20,
liquidity: 10
});
// Split the contract balance into halves
uint256 denominator = (feeRates.liquidity + feeRates.operations) * 2;
uint256 tokensToAddLiquidityWith = (tokens * feeRates.liquidity) /
denominator;
uint256 toSwap = tokens - tokensToAddLiquidityWith;
uint256 initialBalance = address(this).balance;
swapTokensForETH(toSwap);
uint256 deltaBalance = address(this).balance - initialBalance;
uint256 unitBalance = deltaBalance / (denominator - feeRates.liquidity);
uint256 ethToAddLiquidityWith = unitBalance * feeRates.liquidity;
if (ethToAddLiquidityWith > 0) {
// Add liquidity to uniswap
addLiquidity(tokensToAddLiquidityWith, ethToAddLiquidityWith);
}
// Send ETH to operationsWallet
uint256 operationsAmt = unitBalance * 2 * feeRates.operations;
if (operationsAmt > 0) {
payable(operationsAddress).transfer(operationsAmt);
}
isSwapNLiq = false;
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(router), tokenAmount);
// add the liquidity
router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
);
}
function swapTokensForETH(uint256 tokenAmount) 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);
// make the swap
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
function updateSwapEnabled(bool _enabled) external onlyOwner {
swapEnabled = _enabled;
}
//Emergency swap unlock before ownership renoucement
function rescueLock() external onlyOwner {
swapping = !swapping;
}
//Use this in case ETH are sent to the contract by mistake
function rescueETH(uint256 weiAmount) external onlyOwner {
require(address(this).balance >= weiAmount, "insufficient ETH balance");
payable(msg.sender).transfer(weiAmount);
}
function rescueERC20Tokens(address tokenAddress) external onlyOwner {
IERC20(tokenAddress).transfer(
msg.sender,
IERC20(tokenAddress).balanceOf(address(this))
);
}
/// @dev Update router address in case of uniswap migration
function setRouterAddress(address newRouter) external onlyOwner {
require(newRouter != address(router));
IRouter _newRouter = IRouter(newRouter);
address get_pair = IFactory(_newRouter.factory()).getPair(
address(this),
_newRouter.WETH()
);
if (get_pair == address(0)) {
pair = IFactory(_newRouter.factory()).createPair(
address(this),
_newRouter.WETH()
);
} else {
pair = get_pair;
}
router = _newRouter;
}
receive() external payable {}
}