Token 10X: Africa's First Cryptocurrency Hub
PiratesKing Token
PiratesKing is a pirate world simulation game on Blockchain platform. Players can collect NFT, fight with monsters to be rewarded. PiratesKing provides players with various characters, monsters and upgraded items while playing.
...
About PiratesKing
PiratesKing is a pirate world simulation game on Blockchain platform. Players can collect NFT, fight with monsters to be rewarded. PiratesKing provides players with various characters, monsters and upgraded items while playing.
851 total visits
Token information and links
Circulating Supply
100000000000000000000000000
Token Contract (BSC Chain)
0X4CBD8ADCD7ECA7D1B71ADBBF484F1E8014681A9D
Contract license: None
Launch Date
In 1 Day
KYC Information
No
Audit Information
None
Team Information
Team leader: None
Team leader contact: None
Contract source code
pragma solidity ^0.8.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
);
}
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
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);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a b;
}
/**
* @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 a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
/**
* @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 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) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// OpenZeppelin Contracts v4.4.1 (access/Ownable.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.
*/
abstract 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() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual 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 {
_transferOwnership(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");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IPancakeswapV2Factory {
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;
}
interface IPancakeswapV2Router01 {
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);
}
interface IPancakeswapV2Router02 is IPancakeswapV2Router01 {
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: Unlicensed
contract PiratesKingToken is Context, IBEP20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
address payable public bnbPoolAddress;
address payable public prPoolAddress;
uint256 private _tTotal = 100 * 10**6 * 10**18;
uint256 private constant MAX = ~uint256(0);
string private _name = "PiratesKing";
string private _symbol = "PKT";
uint8 private _decimals = 18;
uint256 public _BNBFee = 0;
uint256 private _previousBNBFee = _BNBFee;
uint256 public _PRFee = 0;
uint256 private _previousPRFee = _PRFee;
uint256 public _buyFee = 0;
uint256 private _previousBuyFee = _buyFee;
uint256 public _liquidityFee = 0;
uint256 private _previousLiquidityFee = _liquidityFee;
IPancakeswapV2Router02 public pancakeswapV2Router;
address public pancakeswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
// 00
uint256 public _maxTxAmount = 100 * 10**6 * 10**18;
uint256 private numTokensToSwap = 1 * 10**3 * 10**18;
uint256 public swapCoolDownTime = 0;
uint256 private lastSwapTime;
mapping(address => uint256) private lastTxTimes;
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiquidity
);
event ExcludedFromFee(address account);
event IncludedToFee(address account);
event UpdateFees(uint256 bnbFee, uint256 liquidityFee, uint256 prFee, uint256 buyFee);
event UpdatedMaxTxAmount(uint256 maxTxAmount);
event UpdateNumTokensToSwap(uint256 amount);
event UpdateBNBPoolAddress(address account);
event UpdatePRPoolAddress(address account);
event SwapAndCharged(uint256 token, uint256 liquidAmount, uint256 bnbPool, uint256 prPool, uint256 bnbLiquidity);
event UpdatedCoolDowntime(uint256 timeForContract);
event SwapTokensForEth(bool status);
event AddLiquidity (bool status);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () {
//Test Net
// IPancakeswapV2Router02 _pancakeswapV2Router = IPancakeswapV2Router02(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3);
//Main Net
IPancakeswapV2Router02 _pancakeswapV2Router = IPancakeswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
pancakeswapV2Pair = IPancakeswapV2Factory(_pancakeswapV2Router.factory())
.createPair(address(this), _pancakeswapV2Router.WETH());
// set the rest of the contract variables
pancakeswapV2Router = _pancakeswapV2Router;
//exclude owner and this contract from fee
_isExcludedFromFee[_msgSender()] = true;
_isExcludedFromFee[address(this)] = true;
_balances[_msgSender()] = _tTotal;
bnbPoolAddress = payable(0x6D5527D0c4494Dd9D8a2Fad80FF7872558eD9FdC);
prPoolAddress = payable(0x9B5b98D20042c29293289Fea8324ef1584e9c78E);
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
emit Transfer(address(0), owner(), _tTotal);
}
function symbol() external view override returns (string memory) {
return _symbol;
}
function name() external view override returns (string memory) {
return _name;
}
function decimals() external view override returns (uint8) {
return _decimals;
}
function totalSupply() external view override returns (uint256) {
return _tTotal;
}
function getOwner() external view override returns (address) {
return owner();
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[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, "BEP20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero"));
return true;
}
function setBNBPoolAddress(address account) external onlyOwner {
require(account != bnbPoolAddress, 'This address was already used');
bnbPoolAddress = payable(account);
emit UpdateBNBPoolAddress(account);
}
function setPRPoolAddress(address account) external onlyOwner {
require(account != prPoolAddress, 'This address was already used');
prPoolAddress = payable(account);
emit UpdatePRPoolAddress(account);
}
function setCoolDownTime(uint256 timeForContract) external onlyOwner {
require(swapCoolDownTime != timeForContract);
swapCoolDownTime = timeForContract;
emit UpdatedCoolDowntime(timeForContract);
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
emit ExcludedFromFee(account);
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
emit IncludedToFee(account);
}
function setFees(uint256 bnbFee, uint256 liquidityFee, uint256 prFee, uint256 buyFee) external onlyOwner() {
require(bnbFee liquidityFee prFee <= 8 && buyFee <= 4);
_BNBFee = bnbFee;
_liquidityFee = liquidityFee;
_PRFee = prFee;
_buyFee = buyFee;
emit UpdateFees(bnbFee, liquidityFee, prFee, buyFee);
}
function setMaxTxAmount(uint256 percent) external onlyOwner() {
require(percent > 1 , 'percent must > 1');
_maxTxAmount = _tTotal.mul(percent).div(10**2);
emit UpdatedMaxTxAmount(_maxTxAmount);
}
function setNumTokensToSwap(uint256 amount) external onlyOwner() {
require(numTokensToSwap != amount);
numTokensToSwap = amount;
emit UpdateNumTokensToSwap(amount);
}
function setSwapAndLiquifyEnabled(bool _enabled) external onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
//to receive ETH from pancakeswapV2Router when swapping
receive() external payable {
require(msg.sender == address(pancakeswapV2Router), "Only router is allowed");
}
function _getBuyFeeValues(uint256 tAmount) private view returns (uint256) {
uint256 fee = tAmount.mul(_buyFee).div(10**2);
uint256 tTransferAmount = tAmount.sub(fee);
return tTransferAmount;
}
function _getSellFeeValues(uint256 tAmount) private view returns (uint256) {
uint256 fee = tAmount.mul(_BNBFee _PRFee _liquidityFee).div(10**2);
uint256 tTransferAmount = tAmount.sub(fee);
return tTransferAmount;
}
function removeAllFee() private {
if(_BNBFee == 0 && _liquidityFee == 0 && _PRFee == 0 && _buyFee == 0) return;
_previousBNBFee = _BNBFee;
_previousLiquidityFee = _liquidityFee;
_previousPRFee = _PRFee;
_previousBuyFee = _buyFee;
_BNBFee = 0;
_liquidityFee = 0;
_PRFee = 0;
_buyFee = 0;
}
function restoreAllFee() private {
_BNBFee = _previousBNBFee;
_liquidityFee = _previousLiquidityFee;
_PRFee = _previousPRFee;
_buyFee = _previousBuyFee;
}
function isExcludedFromFee(address account) external view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "BEP20: approve from the zero address");
require(spender != address(0), "BEP20: 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), "BEP20: transfer from the zero address");
require(to != address(0), "BEP20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(
!_isExcludedFromFee[from] &&
!_isExcludedFromFee[to] &&
balanceOf(pancakeswapV2Pair) > 0 &&
!inSwapAndLiquify &&
from != address(pancakeswapV2Router) &&
(from == pancakeswapV2Pair || to == pancakeswapV2Pair)
) {
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
}
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap liquidity lock?
// also, don't get caught in a circular liquidity event.
// also, don't swap & liquify if sender is pancakeswap pair.
uint256 tokenBalance = balanceOf(address(this));
if(tokenBalance >= _maxTxAmount)
{
tokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = tokenBalance >= numTokensToSwap;
if (
overMinTokenBalance &&
!inSwapAndLiquify &&
from != pancakeswapV2Pair &&
swapAndLiquifyEnabled &&
block.timestamp >= lastSwapTime swapCoolDownTime
) {
tokenBalance = numTokensToSwap;
swapAndCharge(tokenBalance);
lastSwapTime = block.timestamp;
}
//indicates if fee should be deducted from transfer
bool takeFee = false;
if (balanceOf(pancakeswapV2Pair) > 0 && (from == pancakeswapV2Pair || to == pancakeswapV2Pair)) {
takeFee = true;
}
//if any account belongs to _isExcludedFromFee account then remove the fee
if (_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from,to,amount,takeFee);
}
function swapAndCharge(uint256 tokenBalance) private lockTheSwap {
uint256 initialBalance = address(this).balance;
uint256 liquidBalance = tokenBalance.mul(_liquidityFee).div(_liquidityFee _BNBFee _PRFee).div(2);
tokenBalance = tokenBalance.sub(liquidBalance);
swapTokensForEth(tokenBalance);
uint256 newBalance = address(this).balance.sub(initialBalance);
uint256 bnbForLiquid = newBalance.mul(liquidBalance).div(tokenBalance);
addLiquidity(liquidBalance, bnbForLiquid);
uint256 poolBalance = address(this).balance;
uint256 prBalance = poolBalance.div(_BNBFee _PRFee _liquidityFee).mul(_PRFee);
uint256 rewardBalance = poolBalance - prBalance;
(bool r_success, ) = payable(bnbPoolAddress).call{value: rewardBalance}("");
(bool p_success, ) = payable(prPoolAddress).call{value: prBalance}("");
if(r_success && p_success) {
emit SwapAndCharged(tokenBalance, liquidBalance, rewardBalance, prBalance, bnbForLiquid);
}
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the pancakeswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pancakeswapV2Router.WETH();
if (allowance(address(this), address(pancakeswapV2Router)) <= tokenAmount) {
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
}
// make the swap
try pancakeswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
) {
emit SwapTokensForEth(true);
} catch Error(string memory /*reason*/) {
emit SwapTokensForEth(false);
}
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
if (allowance(address(this), address(pancakeswapV2Router)) <= tokenAmount) {
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
}
// add the liquidity
try pancakeswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
) {
emit AddLiquidity(true);
} catch Error(string memory /*reason*/) {
emit AddLiquidity(false);
}
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private {
if(!takeFee)
removeAllFee();
uint256 tTransferAmount = amount;
if (recipient == pancakeswapV2Pair) {
tTransferAmount = _getSellFeeValues(amount);
} else if (sender == pancakeswapV2Pair) {
tTransferAmount = _getBuyFeeValues(amount);
}
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(tTransferAmount);
_balances[address(this)] = _balances[address(this)].add(amount.sub(tTransferAmount));
emit Transfer(sender, recipient, tTransferAmount);
emit Transfer(sender, address(this) , amount.sub(tTransferAmount));
if(!takeFee)
restoreAllFee();
}
}
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
);
}
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
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);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @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) {
return a b;
}
/**
* @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 a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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 a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting 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) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
/**
* @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 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) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// OpenZeppelin Contracts v4.4.1 (access/Ownable.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.
*/
abstract 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() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual 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 {
_transferOwnership(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");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IPancakeswapV2Factory {
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;
}
interface IPancakeswapV2Router01 {
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);
}
interface IPancakeswapV2Router02 is IPancakeswapV2Router01 {
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: Unlicensed
contract PiratesKingToken is Context, IBEP20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
address payable public bnbPoolAddress;
address payable public prPoolAddress;
uint256 private _tTotal = 100 * 10**6 * 10**18;
uint256 private constant MAX = ~uint256(0);
string private _name = "PiratesKing";
string private _symbol = "PKT";
uint8 private _decimals = 18;
uint256 public _BNBFee = 0;
uint256 private _previousBNBFee = _BNBFee;
uint256 public _PRFee = 0;
uint256 private _previousPRFee = _PRFee;
uint256 public _buyFee = 0;
uint256 private _previousBuyFee = _buyFee;
uint256 public _liquidityFee = 0;
uint256 private _previousLiquidityFee = _liquidityFee;
IPancakeswapV2Router02 public pancakeswapV2Router;
address public pancakeswapV2Pair;
bool inSwapAndLiquify;
bool public swapAndLiquifyEnabled = false;
// 00
uint256 public _maxTxAmount = 100 * 10**6 * 10**18;
uint256 private numTokensToSwap = 1 * 10**3 * 10**18;
uint256 public swapCoolDownTime = 0;
uint256 private lastSwapTime;
mapping(address => uint256) private lastTxTimes;
event SwapAndLiquifyEnabledUpdated(bool enabled);
event SwapAndLiquify(
uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiquidity
);
event ExcludedFromFee(address account);
event IncludedToFee(address account);
event UpdateFees(uint256 bnbFee, uint256 liquidityFee, uint256 prFee, uint256 buyFee);
event UpdatedMaxTxAmount(uint256 maxTxAmount);
event UpdateNumTokensToSwap(uint256 amount);
event UpdateBNBPoolAddress(address account);
event UpdatePRPoolAddress(address account);
event SwapAndCharged(uint256 token, uint256 liquidAmount, uint256 bnbPool, uint256 prPool, uint256 bnbLiquidity);
event UpdatedCoolDowntime(uint256 timeForContract);
event SwapTokensForEth(bool status);
event AddLiquidity (bool status);
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
constructor () {
//Test Net
// IPancakeswapV2Router02 _pancakeswapV2Router = IPancakeswapV2Router02(0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3);
//Main Net
IPancakeswapV2Router02 _pancakeswapV2Router = IPancakeswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
pancakeswapV2Pair = IPancakeswapV2Factory(_pancakeswapV2Router.factory())
.createPair(address(this), _pancakeswapV2Router.WETH());
// set the rest of the contract variables
pancakeswapV2Router = _pancakeswapV2Router;
//exclude owner and this contract from fee
_isExcludedFromFee[_msgSender()] = true;
_isExcludedFromFee[address(this)] = true;
_balances[_msgSender()] = _tTotal;
bnbPoolAddress = payable(0x6D5527D0c4494Dd9D8a2Fad80FF7872558eD9FdC);
prPoolAddress = payable(0x9B5b98D20042c29293289Fea8324ef1584e9c78E);
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
emit Transfer(address(0), owner(), _tTotal);
}
function symbol() external view override returns (string memory) {
return _symbol;
}
function name() external view override returns (string memory) {
return _name;
}
function decimals() external view override returns (uint8) {
return _decimals;
}
function totalSupply() external view override returns (uint256) {
return _tTotal;
}
function getOwner() external view override returns (address) {
return owner();
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[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, "BEP20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "BEP20: decreased allowance below zero"));
return true;
}
function setBNBPoolAddress(address account) external onlyOwner {
require(account != bnbPoolAddress, 'This address was already used');
bnbPoolAddress = payable(account);
emit UpdateBNBPoolAddress(account);
}
function setPRPoolAddress(address account) external onlyOwner {
require(account != prPoolAddress, 'This address was already used');
prPoolAddress = payable(account);
emit UpdatePRPoolAddress(account);
}
function setCoolDownTime(uint256 timeForContract) external onlyOwner {
require(swapCoolDownTime != timeForContract);
swapCoolDownTime = timeForContract;
emit UpdatedCoolDowntime(timeForContract);
}
function excludeFromFee(address account) external onlyOwner {
_isExcludedFromFee[account] = true;
emit ExcludedFromFee(account);
}
function includeInFee(address account) external onlyOwner {
_isExcludedFromFee[account] = false;
emit IncludedToFee(account);
}
function setFees(uint256 bnbFee, uint256 liquidityFee, uint256 prFee, uint256 buyFee) external onlyOwner() {
require(bnbFee liquidityFee prFee <= 8 && buyFee <= 4);
_BNBFee = bnbFee;
_liquidityFee = liquidityFee;
_PRFee = prFee;
_buyFee = buyFee;
emit UpdateFees(bnbFee, liquidityFee, prFee, buyFee);
}
function setMaxTxAmount(uint256 percent) external onlyOwner() {
require(percent > 1 , 'percent must > 1');
_maxTxAmount = _tTotal.mul(percent).div(10**2);
emit UpdatedMaxTxAmount(_maxTxAmount);
}
function setNumTokensToSwap(uint256 amount) external onlyOwner() {
require(numTokensToSwap != amount);
numTokensToSwap = amount;
emit UpdateNumTokensToSwap(amount);
}
function setSwapAndLiquifyEnabled(bool _enabled) external onlyOwner {
swapAndLiquifyEnabled = _enabled;
emit SwapAndLiquifyEnabledUpdated(_enabled);
}
//to receive ETH from pancakeswapV2Router when swapping
receive() external payable {
require(msg.sender == address(pancakeswapV2Router), "Only router is allowed");
}
function _getBuyFeeValues(uint256 tAmount) private view returns (uint256) {
uint256 fee = tAmount.mul(_buyFee).div(10**2);
uint256 tTransferAmount = tAmount.sub(fee);
return tTransferAmount;
}
function _getSellFeeValues(uint256 tAmount) private view returns (uint256) {
uint256 fee = tAmount.mul(_BNBFee _PRFee _liquidityFee).div(10**2);
uint256 tTransferAmount = tAmount.sub(fee);
return tTransferAmount;
}
function removeAllFee() private {
if(_BNBFee == 0 && _liquidityFee == 0 && _PRFee == 0 && _buyFee == 0) return;
_previousBNBFee = _BNBFee;
_previousLiquidityFee = _liquidityFee;
_previousPRFee = _PRFee;
_previousBuyFee = _buyFee;
_BNBFee = 0;
_liquidityFee = 0;
_PRFee = 0;
_buyFee = 0;
}
function restoreAllFee() private {
_BNBFee = _previousBNBFee;
_liquidityFee = _previousLiquidityFee;
_PRFee = _previousPRFee;
_buyFee = _previousBuyFee;
}
function isExcludedFromFee(address account) external view returns(bool) {
return _isExcludedFromFee[account];
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "BEP20: approve from the zero address");
require(spender != address(0), "BEP20: 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), "BEP20: transfer from the zero address");
require(to != address(0), "BEP20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if(
!_isExcludedFromFee[from] &&
!_isExcludedFromFee[to] &&
balanceOf(pancakeswapV2Pair) > 0 &&
!inSwapAndLiquify &&
from != address(pancakeswapV2Router) &&
(from == pancakeswapV2Pair || to == pancakeswapV2Pair)
) {
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
}
// is the token balance of this contract address over the min number of
// tokens that we need to initiate a swap liquidity lock?
// also, don't get caught in a circular liquidity event.
// also, don't swap & liquify if sender is pancakeswap pair.
uint256 tokenBalance = balanceOf(address(this));
if(tokenBalance >= _maxTxAmount)
{
tokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = tokenBalance >= numTokensToSwap;
if (
overMinTokenBalance &&
!inSwapAndLiquify &&
from != pancakeswapV2Pair &&
swapAndLiquifyEnabled &&
block.timestamp >= lastSwapTime swapCoolDownTime
) {
tokenBalance = numTokensToSwap;
swapAndCharge(tokenBalance);
lastSwapTime = block.timestamp;
}
//indicates if fee should be deducted from transfer
bool takeFee = false;
if (balanceOf(pancakeswapV2Pair) > 0 && (from == pancakeswapV2Pair || to == pancakeswapV2Pair)) {
takeFee = true;
}
//if any account belongs to _isExcludedFromFee account then remove the fee
if (_isExcludedFromFee[from] || _isExcludedFromFee[to]){
takeFee = false;
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from,to,amount,takeFee);
}
function swapAndCharge(uint256 tokenBalance) private lockTheSwap {
uint256 initialBalance = address(this).balance;
uint256 liquidBalance = tokenBalance.mul(_liquidityFee).div(_liquidityFee _BNBFee _PRFee).div(2);
tokenBalance = tokenBalance.sub(liquidBalance);
swapTokensForEth(tokenBalance);
uint256 newBalance = address(this).balance.sub(initialBalance);
uint256 bnbForLiquid = newBalance.mul(liquidBalance).div(tokenBalance);
addLiquidity(liquidBalance, bnbForLiquid);
uint256 poolBalance = address(this).balance;
uint256 prBalance = poolBalance.div(_BNBFee _PRFee _liquidityFee).mul(_PRFee);
uint256 rewardBalance = poolBalance - prBalance;
(bool r_success, ) = payable(bnbPoolAddress).call{value: rewardBalance}("");
(bool p_success, ) = payable(prPoolAddress).call{value: prBalance}("");
if(r_success && p_success) {
emit SwapAndCharged(tokenBalance, liquidBalance, rewardBalance, prBalance, bnbForLiquid);
}
}
function swapTokensForEth(uint256 tokenAmount) private {
// generate the pancakeswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pancakeswapV2Router.WETH();
if (allowance(address(this), address(pancakeswapV2Router)) <= tokenAmount) {
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
}
// make the swap
try pancakeswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
) {
emit SwapTokensForEth(true);
} catch Error(string memory /*reason*/) {
emit SwapTokensForEth(false);
}
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
// approve token transfer to cover all possible scenarios
if (allowance(address(this), address(pancakeswapV2Router)) <= tokenAmount) {
_approve(address(this), address(pancakeswapV2Router), ~uint256(0));
}
// add the liquidity
try pancakeswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable
0, // slippage is unavoidable
owner(),
block.timestamp
) {
emit AddLiquidity(true);
} catch Error(string memory /*reason*/) {
emit AddLiquidity(false);
}
}
//this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private {
if(!takeFee)
removeAllFee();
uint256 tTransferAmount = amount;
if (recipient == pancakeswapV2Pair) {
tTransferAmount = _getSellFeeValues(amount);
} else if (sender == pancakeswapV2Pair) {
tTransferAmount = _getBuyFeeValues(amount);
}
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(tTransferAmount);
_balances[address(this)] = _balances[address(this)].add(amount.sub(tTransferAmount));
emit Transfer(sender, recipient, tTransferAmount);
emit Transfer(sender, address(this) , amount.sub(tTransferAmount));
if(!takeFee)
restoreAllFee();
}
}