Created
September 10, 2023 20:35
-
-
Save VuQuang/7de5237c21e2e79caa794edaa78586d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.19; | |
abstract contract Context { | |
function _msgSender() internal view virtual returns (address) { | |
return msg.sender; | |
} | |
function _msgData() internal view virtual returns (bytes memory) { | |
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 | |
return msg.data; | |
} | |
} | |
contract Ownable is Context { | |
address private _owner; | |
address private _previousOwner; | |
uint256 private _lockTime; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev Initializes the contract setting the deployer as the initial owner. | |
*/ | |
constructor () { | |
address msgSender = _msgSender(); | |
_owner = msgSender; | |
emit OwnershipTransferred(address(0), msgSender); | |
} | |
/** | |
* @dev Returns the address of the current owner. | |
*/ | |
function owner() public view returns (address) { | |
return _owner; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(_owner == _msgSender(), "Ownable: caller is not the owner"); | |
_; | |
} | |
/** | |
* @dev Leaves the contract without owner. It will not be possible to call | |
* `onlyOwner` functions anymore. Can only be called by the current owner. | |
* | |
* NOTE: Renouncing ownership will leave the contract without an owner, | |
* thereby removing any functionality that is only available to the owner. | |
*/ | |
function renounceOwnership() public virtual onlyOwner { | |
emit OwnershipTransferred(_owner, address(0)); | |
_owner = address(0); | |
} | |
/** | |
* @dev Transfers ownership of the contract to a new account (`newOwner`). | |
* Can only be called by the current owner. | |
*/ | |
function transferOwnership(address newOwner) public virtual onlyOwner { | |
require(newOwner != address(0), "Ownable: new owner is the zero address"); | |
emit OwnershipTransferred(_owner, newOwner); | |
_owner = newOwner; | |
} | |
} | |
interface IERC20 { | |
/** | |
* @dev Returns the amount of tokens in existence. | |
*/ | |
function totalSupply() external view returns (uint256); | |
/** | |
* @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); | |
} | |
interface IERC20Metadata is IERC20 { | |
function name() external view returns (string memory); | |
function symbol() external view returns (string memory); | |
function decimals() external view returns (uint8); | |
} | |
contract ShibaLord is Ownable, IERC20, IERC20Metadata { | |
mapping (address => uint256) private _balances; | |
mapping (address => mapping (address => uint256)) private _allowances; | |
mapping(address => bool) private _isExcludedFromFee; | |
uint256 private _totalSupply; | |
string private _name; | |
string private _symbol; | |
uint8 private constant _decimals = 18; | |
uint256 private constant _marketFee = 3; | |
uint256 private constant basePercent = 100; | |
uint256 private constant base = 10000; | |
address private marketWallet = 0x4BD25cfE6BDc1f20c371bdF2dFE5b0197eF37E6d; | |
bool public isEnableTrading = false; | |
constructor () { | |
_name = "Shiba Lord"; | |
_symbol = "SHIBLORD"; | |
_isExcludedFromFee[address(this)] = true; | |
_isExcludedFromFee[owner()] = true; | |
_isExcludedFromFee[marketWallet]=true; | |
_isExcludedFromFee[address(0)]=true; | |
uint256 initSupply = 100*10**12*10**18; | |
_mint(msg.sender, initSupply); | |
} | |
function name() public view virtual override returns (string memory) { | |
return _name; | |
} | |
function symbol() public view virtual override returns (string memory) { | |
return _symbol; | |
} | |
function decimals() public view virtual override returns (uint8) { | |
return _decimals; | |
} | |
function totalSupply() public view virtual override returns (uint256) { | |
return _totalSupply; | |
} | |
function balanceOf(address account) public view virtual override returns (uint256) { | |
return _balances[account]; | |
} | |
function findOnePercent(uint256 value) internal pure returns (uint256) { | |
uint256 onePercent = value * basePercent / base; | |
return onePercent; | |
} | |
function excludeFromFee(address account) public onlyOwner { | |
_isExcludedFromFee[account] = true; | |
} | |
function includeInFee(address account) public onlyOwner { | |
_isExcludedFromFee[account] = false; | |
} | |
function changeMarketWallet(address _newMarketWallet) public onlyOwner { | |
marketWallet=_newMarketWallet; | |
} | |
function isExcludedFromFee(address account) public view returns (bool) { | |
return _isExcludedFromFee[account]; | |
} | |
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { | |
_transfer(_msgSender(), recipient, amount); | |
return true; | |
} | |
function allowance(address owner, address spender) public view virtual override returns (uint256) { | |
return _allowances[owner][spender]; | |
} | |
function approve(address spender, uint256 amount) public virtual override returns (bool) { | |
_approve(_msgSender(), spender, amount); | |
return true; | |
} | |
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { | |
_transfer(sender, recipient, amount); | |
uint256 currentAllowance = _allowances[sender][_msgSender()]; | |
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); | |
_approve(sender, _msgSender(), currentAllowance - amount); | |
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) { | |
uint256 currentAllowance = _allowances[_msgSender()][spender]; | |
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); | |
_approve(_msgSender(), spender, currentAllowance - subtractedValue); | |
return true; | |
} | |
function enableTrading() external onlyOwner { | |
require(!isEnableTrading, "Trading already enabled"); | |
isEnableTrading = true; | |
} | |
function _transfer(address sender, address recipient, uint256 amount) internal returns (bool) { | |
require(_balances[sender] >= amount, "ERC20: transfer amount exceeds balance"); | |
require(sender != address(0), "ERC20: transfer from the zero address"); | |
require(recipient != address(0), "ERC20: transfer to the zero address"); | |
require(isEnableTrading || _isExcludedFromFee[sender], "Trading is not enabled"); | |
if(_isExcludedFromFee[sender] || _isExcludedFromFee[recipient]) | |
{ | |
_balances[sender] -= amount; | |
_balances[recipient] += amount; | |
emit Transfer(sender, recipient, amount); | |
} | |
else | |
{ | |
uint256 onePercent = findOnePercent(amount); | |
uint256 toMarketWallet = onePercent * _marketFee; | |
uint256 tokensToTransfer = amount - toMarketWallet; | |
_balances[sender] -= tokensToTransfer; | |
_balances[recipient] += tokensToTransfer; | |
_balances[marketWallet] += toMarketWallet; | |
_sendToMarket(sender, toMarketWallet); | |
emit Transfer(sender, recipient, tokensToTransfer); | |
} | |
return true; | |
} | |
function _sendToMarket(address account, uint256 amount) internal { | |
require(account != address(0), "ERC20: market from the zero address"); | |
_beforeTokenTransfer(account,marketWallet, amount); | |
uint256 accountBalance = _balances[account]; | |
require(accountBalance >= amount, "ERC20: market amount exceeds balance"); | |
_balances[account] = accountBalance - amount; | |
emit Transfer(account, marketWallet, amount); | |
} | |
function _mint(address account, uint256 amount) internal { | |
require(account != address(0), "ERC20: mint to the zero address"); | |
_beforeTokenTransfer(address(0), account, amount); | |
_totalSupply += amount; | |
_balances[account] += amount; | |
emit Transfer(address(0), account, amount); | |
} | |
function _approve(address owner, address spender, uint256 amount) internal { | |
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 _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment