// SPDX-License-Identifier: Unlicensedpragmasolidity ^0.8.23;import {Context} from"@openzeppelin/contracts/utils/Context.sol";
import {ReentrancyGuard} from"@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IUniswapV2Factory} from"src/interfaces/IUniswapV2Factory.sol";
import {IUniswapV2Router02} from"src/interfaces/IUniswapV2Router02.sol";
import {ICindr} from"src/interfaces/ICindr.sol";
/**
* @title Cindr Token
* @dev Implementation of the Cindr Token with reflection mechanism, auto liquidity, and fees for marketing and development.
* Inspired by SafeMoon mechanisms and code: https://github.com/safemoonprotocol/Safemoon.sol/blob/main/Safemoon.sol
*/contractCindrisICindr, Context, ReentrancyGuard{
/************************************* Token description ****************************************//// @notice Token namestringprivate _name;
/// @notice Token symbolstringprivate _symbol;
/// @notice Token decimalsuint16privateconstant _decimals =9;
/************************************************************************************************//********************************** ERC20 Token mappings ****************************************//// @notice Reflects the owned tokens of each addressmapping(address=>uint256) private _rOwned;
/// @notice Actual token balance of each addressmapping(address=>uint256) private _tOwned;
/// @notice Allowances for each address to spend on behalf of another addressmapping(address=>mapping(address=>uint256)) private _allowances;
/************************************************************************************************//// @notice Tracks addresses that are excluded from feemapping(address=>bool) private _isExcludedFromFee;
/// @notice Tracks addresses that are excluded from rewardmapping(address=>bool) private _isExcluded;
/// @notice List of excluded addressesaddress[] private _excluded;
/// @notice Maximum value for uint256uint256privateconstant MAX =type(uint256).max;
/// @notice Total supply of tokensuint256private _tTotal;
/// @notice Reflected total supplyuint256private _rTotal;
/********************************* Fee Percentages and amounts ************************************//// @notice Total fee collecteduint256private _tFeeTotal;
/// @notice Current tax fee percentageuint16publicconstant taxFee =15; // 1.5%;/// @notice Current burn fee percentageuint16publicconstant burnFee =15; // 1.5%;/// @notice Current liquidity fee percentageuint16publicconstant liquidityFee =10; // 1%;/// @notice Current marketing fee percentageuint16publicconstant marketingFee =10; // 1%;/************************************************************************************************//********************************* Treasury Wallets ************************************//// @notice Address of the marketing walletaddresspublic marketingWallet;
/************************************************************************************************//********************************* Defi Behavior ************************************//// @notice Instance of UniswapV2Router
IUniswapV2Router02 publicimmutable uniswapV2Router;
/// @notice Address of the UniswapV2 pair for this tokenaddresspublicimmutable uniswapV2Pair;
/// @notice Boolean to lock the swap and liquify processbool inSwapAndLiquify;
/// @notice Flag to enable or disable swap and liquifyboolpublic swapAndLiquifyEnabled =true;
/// @notice Maximum transaction amountuint256publicconstant _maxTxAmount =5_000_000*10**6*10**9;
/// @notice Number of tokens to sell and add to liquidityuint256privateconstant numTokensSellToAddToLiquidity =5_000_000*10**9;
/********************************* Events ************************************//**
* @dev Prevents reentrancy during the swap and liquify process
* Sets the inSwapAndLiquify flag to true before executing the function and resets it to false after the function execution
*/modifierlockTheSwap() {
inSwapAndLiquify =true;
_;
inSwapAndLiquify =false;
}
/**
* @notice Constructor for the Cindr token
* @param name_ Name of the token
* @param symbol_ Symbol of the token
* @param totalSupply_ Total Supply of the token
* @param _uniswapV2RouterAddress Address of the UniswapV2Router
* @param _marketingWallet Address of the marketing wallet
*/constructor(stringmemory name_,
stringmemory symbol_,
uint256 totalSupply_,
address _uniswapV2RouterAddress,
address _marketingWallet
) {
// Ensure the parameters are validrequire(bytes(name_).length>0, "Token name cannot be empty");
require(bytes(symbol_).length>0, "Token symbol cannot be empty");
require(totalSupply_ >0, "Total supply must be greater than zero");
require(
_uniswapV2RouterAddress !=address(0),
"UniswapV2Router address cannot be zero address"
);
require(
_marketingWallet !=address(0),
"Marketing wallet address cannot be zero address"
);
_tTotal = totalSupply_ *10** _decimals;
_rTotal = (MAX - (MAX % _tTotal));
_rOwned[_msgSender()] = _rTotal;
_name = name_;
_symbol = symbol_;
marketingWallet = _marketingWallet;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
_uniswapV2RouterAddress
);
// Create a uniswap pair for this new token
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
// Set the rest of the contract variables
uniswapV2Router = _uniswapV2Router;
// Exclude this contract from fee
_isExcludedFromFee[uniswapV2Pair] =true;
_isExcludedFromFee[address(this)] =true;
emit Transfer(address(0), _msgSender(), _tTotal);
}
receive() externalpayable{}
/************************************************************************************************//****************************** EXTERNAL FUNCTIONS (ICindr INTERFACE) ****************************//************************************************************************************************//**
* @dev See {ICindr-isExcludedFromReward}.
*/functionisExcludedFromReward(address account
) externalviewreturns (bool) {
return _isExcluded[account];
}
/**
* @dev See {ICindr-totalFees}.
*/functiontotalFees() externalviewreturns (uint256) {
return _tFeeTotal;
}
/**
* @dev See {ICindr-deliver}.
*/functiondeliver(uint256 tAmount) external{
address sender = _msgSender();
require(
!_isExcluded[sender],
"Excluded addresses cannot call this function"
);
(uint256 rAmount, , , , , ) = _getValues(tAmount);
_rOwned[sender] = _rOwned[sender] - (rAmount);
_rTotal = _rTotal - (rAmount);
_tFeeTotal = _tFeeTotal + (tAmount);
}
/**
* @dev See {ICindr-reflectionFromToken}.
*/functionreflectionFromToken(uint256 tAmount,
bool deductTransferFee
) externalviewreturns (uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferFee) {
(uint256 rAmount, , , , , ) = _getValues(tAmount);
return rAmount;
} else {
(, uint256 rTransferAmount, , , , ) = _getValues(tAmount);
return rTransferAmount;
}
}
/************************************************************************************************//****************************** PUBLIC FUNCTIONS (ERC20 INTERFACE) ****************************//************************************************************************************************//**
* @dev See {IERC20-name}.
*/functionname() publicviewreturns (stringmemory) {
return _name;
}
/**
* @dev See {IERC20-symbol}.
*/functionsymbol() publicviewreturns (stringmemory) {
return _symbol;
}
/**
* @dev See {IERC20-decimals}.
*/functiondecimals() publicviewreturns (uint16) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewoverridereturns (uint256) {
return _tTotal;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewoverridereturns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
/**
* @dev See {IERC20-transfer}.
*/functiontransfer(address to,
uint256 amount
) publicoverridereturns (bool) {
_transfer(_msgSender(), to, amount);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner,
address spender
) publicviewoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev Approves the specified amount of tokens for the specified spender
* @param spender The address of the spender
* @param amount The amount of tokens to approve
*/functionapprove(address spender,
uint256 amount
) publicoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
functiontransferFrom(address sender,
address recipient,
uint256 amount
) publicoverridereturns (bool) {
_transfer(sender, recipient, amount);
_approve(
sender,
_msgSender(),
_allowances[sender][_msgSender()] - amount
);
returntrue;
}
functionincreaseAllowance(address spender,
uint256 addedValue
) publicvirtualreturns (bool) {
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] + addedValue
);
returntrue;
}
functiondecreaseAllowance(address spender,
uint256 subtractedValue
) publicvirtualreturns (bool) {
_approve(
_msgSender(),
spender,
_allowances[_msgSender()][spender] - subtractedValue
);
returntrue;
}
/************************************************************************************************//************************************************************************************************//****************************** PUBLIC FUNCTIONS (ICindr INTERFACE) ****************************//************************************************************************************************//**
* @dev See {ICindr-isExcludedFromFee}.
*/functionisExcludedFromFee(address account) publicviewreturns (bool) {
return _isExcludedFromFee[account];
}
/**
* @dev See {ICindr-tokenFromReflection}.
*/functiontokenFromReflection(uint256 rAmount
) publicviewreturns (uint256) {
require(
rAmount <= _rTotal,
"Amount must be less than total reflections"
);
uint256 currentRate = _getRate();
return rAmount / (currentRate);
}
/************************************************************************************************//************************************************************************************************//****************************** PRIVATE FUNCTIONS (REFLECTION METHODOLOGY) ****************************//************************************************************************************************//**
* @dev Distributes the fee by reducing the total reflections and adding to the total fee collected.
* @param rFee The reflection fee to be subtracted from the total reflections.
* @param tFee The token fee to be added to the total fee collected.
*/function_reflectFee(uint256 rFee, uint256 tFee) private{
_rTotal = _rTotal - (rFee);
_tFeeTotal = _tFeeTotal + (tFee);
}
/**
* @dev Takes the liquidity fee from the transaction amount
* @param tLiquidity The amount of tokens to be taken as liquidity fee
*/function_takeLiquidity(uint256 tLiquidity) private{
uint256 currentRate = _getRate();
uint256 rLiquidity = tLiquidity * (currentRate);
_rOwned[address(this)] = _rOwned[address(this)] + (rLiquidity);
if (_isExcluded[address(this)])
_tOwned[address(this)] = _tOwned[address(this)] + (tLiquidity);
}
/**
* @dev Transfers tokens between addresses with fee considerations
* @param sender The address sending the tokens
* @param recipient The address receiving the tokens
* @param amount The amount of tokens to transfer
* @param takeFee Whether to apply fees to the transfer
*/function_tokenTransfer(address sender,
address recipient,
uint256 amount,
bool takeFee
) private{
_transferStandard(sender, recipient, amount);
}
/**
* @dev Standard transfer function applying fees
* @param sender The address sending the tokens
* @param recipient The address receiving the tokens
* @param tAmount The amount of tokens to transfer
*/function_transferStandard(address sender,
address recipient,
uint256 tAmount
) private{
(
uint256 rAmount,
uint256 rTransferAmount,
uint256 rFee,
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getValues(tAmount);
if (_rOwned[sender] < rAmount) {
revert InsufficientBalance(sender, _rOwned[sender], rAmount);
}
_rOwned[sender] -= rAmount;
_rOwned[recipient] += rTransferAmount;
_takeLiquidity(tLiquidity);
_takeBurnFromTAmount(tAmount);
_takeMarketingFromTAmount(tAmount);
_reflectFee(rFee, tFee);
emit Transfer(sender, recipient, tTransferAmount);
}
/**
* @dev Takes the burn fee from the transaction amount
* @param tAmount The amount of tokens to be burned
*/function_takeBurnFromTAmount(uint256 tAmount) private{
uint256 currentRate = _getRate();
uint256 tBurn = _calculateBurnFee(tAmount);
uint256 rBurn = tBurn * (currentRate);
_rTotal = _rTotal - (rBurn);
_tTotal = _tTotal - (tBurn);
}
/**
* @dev Takes the marketing fee from the transaction amount
* @param tAmount The amount of tokens to be taken as marketing fee
*/function_takeMarketingFromTAmount(uint256 tAmount) private{
uint256 currentRate = _getRate();
uint256 tMarketing = _calculateMarketingFee(tAmount);
uint256 rMarketing = tMarketing * (currentRate);
_rOwned[marketingWallet] += rMarketing;
if (_isExcluded[marketingWallet])
_tOwned[marketingWallet] += tMarketing;
}
function_approve(address owner, address spender, uint256 amount) private{
require(owner !=address(0), "ERC20: approve from the zero address");
require(spender !=address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function_transfer(addressfrom, address to, uint256 amount) private{
require(from!=address(0), "ERC20: transfer from the zero address");
require(to !=address(0), "ERC20: transfer to the zero address");
require(amount >0, "Transfer amount must be greater than zero");
// 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 uniswap pair.uint256 contractTokenBalance = balanceOf(address(this));
if (contractTokenBalance >= _maxTxAmount) {
contractTokenBalance = _maxTxAmount;
}
bool overMinTokenBalance = contractTokenBalance >=
numTokensSellToAddToLiquidity;
if (
overMinTokenBalance &&!inSwapAndLiquify &&from!= uniswapV2Pair &&
swapAndLiquifyEnabled
) {
contractTokenBalance = numTokensSellToAddToLiquidity;
//add liquidity
_swapAndLiquify(contractTokenBalance);
}
//indicates if fee should be deducted from transferbool takeFee =true;
//if any account belongs to _isExcludedFromFee account then remove the feeif (_isExcludedFromFee[from] || _isExcludedFromFee[to]) {
takeFee =false;
}
//transfer amount, it will take tax, burn, liquidity fee
_tokenTransfer(from, to, amount, takeFee);
}
/**
* @dev Swaps tokens for ETH and adds liquidity to Uniswap
* @param contractTokenBalance The amount of tokens to swap and liquify
*/function_swapAndLiquify(uint256 contractTokenBalance) privatelockTheSwap{
// split the contract balance into halvesuint256 half = contractTokenBalance / (2);
uint256 otherHalf = contractTokenBalance - (half);
// capture the contract's current ETH balance.// this is so that we can capture exactly the amount of ETH that the// swap creates, and not make the liquidity event include any ETH that// has been manually sent to the contractuint256 initialBalance =address(this).balance;
// swap tokens for ETH
_swapTokensForEth(half); // <- this breaks the ETH -> HATE swap when swap+liquify is triggered// how much ETH did we just swap into?uint256 newBalance =address(this).balance- (initialBalance);
// add liquidity to uniswap
_addLiquidity(otherHalf, newBalance);
emit SwapAndLiquify(half, newBalance, otherHalf);
}
/**
* @dev Swaps the specified amount of tokens for ETH
* @param tokenAmount The amount of tokens to swap for ETH
*/function_swapTokensForEth(uint256 tokenAmount) privatenonReentrant{
// 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, // (tokenAmount * 950) / 1000, // 15% slippage tolerance
path,
address(this),
block.timestamp
);
}
/**
* @dev Adds liquidity to Uniswap
* @param tokenAmount The amount of tokens to add as liquidity
* @param ethAmount The amount of ETH to add as liquidity
*/function_addLiquidity(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, // (tokenAmount * 850) / 1000, // 15% slippage tolerance0, // (ethAmount * 850) / 1000, // 15% slippage toleranceaddress(this), // Send LP tokens to the contract itselfblock.timestamp
);
}
/**
* @dev Gets the values required for the transfer
* @param tAmount The amount of tokens to transfer
* @return The calculated values for the transfer
*/function_getValues(uint256 tAmount
)
privateviewreturns (uint256, uint256, uint256, uint256, uint256, uint256)
{
(
uint256 tTransferAmount,
uint256 tFee,
uint256 tLiquidity
) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(
tAmount,
tFee,
tLiquidity,
_getRate()
);
return (
rAmount,
rTransferAmount,
rFee,
tTransferAmount,
tFee,
tLiquidity
);
}
/**
* @dev Gets the transaction values
* @param tAmount The amount of tokens to transfer
* @return The calculated values for the transaction
*/function_getTValues(uint256 tAmount
) privateviewreturns (uint256, uint256, uint256) {
uint256 tFee = _calculateTaxFee(tAmount);
uint256 tLiquidity = _calculateLiquidityFee(tAmount);
uint256 tBurn = _calculateBurnFee(tAmount);
uint256 tMarketing = _calculateMarketingFee(tAmount);
uint256 tTransferAmount = tAmount -
tFee -
tLiquidity -
tBurn -
tMarketing;
return (tTransferAmount, tFee, tLiquidity);
}
/**
* @dev Gets the current rate of reflections
* @return The current rate of reflections
*/function_getRate() privateviewreturns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply / (tSupply);
}
/**
* @dev Gets the current supply of tokens
* @return The current supply of tokens
*/function_getCurrentSupply() privateviewreturns (uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i =0; i < _excluded.length; i++) {
if (
_rOwned[_excluded[i]] > rSupply ||
_tOwned[_excluded[i]] > tSupply
) return (_rTotal, _tTotal);
rSupply = rSupply - (_rOwned[_excluded[i]]);
tSupply = tSupply - (_tOwned[_excluded[i]]);
}
if (rSupply < _rTotal / (_tTotal)) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
/**
* @dev Calculates the tax fee
* @param _amount The amount of tokens to calculate the fee for
* @return The calculated tax fee
*/function_calculateTaxFee(uint256 _amount) privateviewreturns (uint256) {
return (_amount * (taxFee)) / (10**3);
}
/**
* @dev Calculates the burn fee
* @param _amount The amount of tokens to calculate the fee for
* @return The calculated burn fee
*/function_calculateBurnFee(uint256 _amount) privateviewreturns (uint256) {
return (_amount * (burnFee)) / (10**3);
}
/**
* @dev Calculates the liquidity fee
* @param _amount The amount of tokens to calculate the fee for
* @return The calculated liquidity fee
*/function_calculateLiquidityFee(uint256 _amount
) privatepurereturns (uint256) {
return (_amount * (liquidityFee)) / (10**3);
}
/**
* @dev Calculates the marketing fee
* @param _amount The amount of tokens to calculate the fee for
* @return The calculated marketing fee
*/function_calculateMarketingFee(uint256 _amount
) privatepurereturns (uint256) {
return (_amount * (marketingFee)) / (10**3);
}
function_getRValues(uint256 tAmount,
uint256 tFee,
uint256 tLiquidity,
uint256 currentRate
) privatepurereturns (uint256, uint256, uint256) {
uint256 rAmount = tAmount * (currentRate);
uint256 rFee = tFee * (currentRate);
uint256 rLiquidity = tLiquidity * (currentRate);
uint256 rTransferAmount = rAmount - (rFee) - (rLiquidity);
return (rAmount, rTransferAmount, rFee);
}
}
Contract Source Code
File 2 of 8: Context.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)pragmasolidity ^0.8.20;/**
* @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.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
function_contextSuffixLength() internalviewvirtualreturns (uint256) {
return0;
}
}
Contract Source Code
File 3 of 8: ICindr.sol
// SPDX-License-Identifier: Unlicensedpragmasolidity ^0.8.23;import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
interfaceICindrisIERC20{
/**
* @notice Event emitted when tokens or ETH are recovered.
* @param to The address to which the recovered tokens or ETH are sent.
* @param amount The amount of tokens or ETH recovered.
*/eventTokensRecovered(addressindexed to, uint256 amount);
/**
* @notice Event emitted when the maximum transaction amount is updated.
* @param maxTxPercent The new maximum transaction amount percentage.
*/eventMaxTxPercentUpdated(uint256 maxTxPercent);
/**
* @dev Error for insufficient token balance.
* @param account The address of the account with insufficient balance.
* @param balance The current token balance of the account.
* @param required The required token balance for the operation.
*/errorInsufficientBalance(address account,
uint256 balance,
uint256 required
);
/**
* @dev Error for insufficient reflection balance.
* @param account The address of the account with insufficient reflection balance.
* @param balance The current reflection balance of the account.
* @param required The required reflection balance for the operation.
*/errorInsufficientReflectionBalance(address account,
uint256 balance,
uint256 required
);
/**
* @dev Emitted when the minimum number of tokens before initiating a swap is updated
* @param minTokensBeforeSwap The new minimum number of tokens before initiating a swap
*/eventMinTokensBeforeSwapUpdated(uint256 minTokensBeforeSwap);
/**
* @dev Emitted when the swap and liquify feature is enabled or disabled
* @param enabled A boolean indicating whether the swap and liquify feature is enabled
*/eventSwapAndLiquifyEnabledUpdated(bool enabled);
/**
* @dev Emitted when tokens are swapped and liquidity is added
* @param tokensSwapped The amount of tokens that were swapped
* @param ethReceived The amount of ETH received from the swap
* @param tokensIntoLiquidity The amount of tokens that were added to the liquidity pool
*/eventSwapAndLiquify(uint256 tokensSwapped,
uint256 ethReceived,
uint256 tokensIntoLiquidity
);
/**
* @dev Checks if an account is excluded from receiving rewards.
* @param account The address to check.
*/functionisExcludedFromReward(address account) externalviewreturns (bool);
/**
* @dev Returns the total fees collected.
*/functiontotalFees() externalviewreturns (uint256);
/**
* @dev Delivers the specified amount of tokens to the sender.
* @param tAmount The amount of tokens to deliver.
*/functiondeliver(uint256 tAmount) external;
/**
* @dev Returns the reflection from the specified token amount.
* @param tAmount The amount of tokens.
* @param deductTransferFee Whether to deduct the transfer fee.
*/functionreflectionFromToken(uint256 tAmount,
bool deductTransferFee
) externalviewreturns (uint256);
/**
* @dev Returns the token amount from the specified reflection amount.
* @param rAmount The amount of reflection.
*/functiontokenFromReflection(uint256 rAmount
) externalviewreturns (uint256);
/**
* @dev Receives Ether to the contract.
*/receive() externalpayable;
}
Contract Source Code
File 4 of 8: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.20;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @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);
/**
* @dev Returns the value of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 value) 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 a `value` amount of tokens 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.
*/functionapprove(address spender, uint256 value) externalreturns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom, address to, uint256 value) externalreturns (bool);
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)pragmasolidity ^0.8.20;/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/abstractcontractReentrancyGuard{
// Booleans are more expensive than uint256 or any type that takes up a full// word because each write operation emits an extra SLOAD to first read the// slot's contents, replace the bits taken up by the boolean, and then write// back. This is the compiler's defense against contract upgrades and// pointer aliasing, and it cannot be disabled.// The values being non-zero value makes deployment a bit more expensive,// but in exchange the refund on every call to nonReentrant will be lower in// amount. Since refunds are capped to a percentage of the total// transaction's gas, it is best to keep them low in cases like this one, to// increase the likelihood of the full refund coming into effect.uint256privateconstant NOT_ENTERED =1;
uint256privateconstant ENTERED =2;
uint256private _status;
/**
* @dev Unauthorized reentrant call.
*/errorReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/modifiernonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function_nonReentrantBefore() private{
// On the first call to nonReentrant, _status will be NOT_ENTEREDif (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function_nonReentrantAfter() private{
// By storing the original value once again, a refund is triggered (see// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/function_reentrancyGuardEntered() internalviewreturns (bool) {
return _status == ENTERED;
}
}