// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The caller is not authorized to call the function.
error Unauthorized();
/// @dev The `newOwner` cannot be the zero address.
error NewOwnerIsZeroAddress();
/// @dev The `pendingOwner` does not have a valid handover request.
error NoHandoverRequest();
/// @dev Cannot double-initialize.
error AlreadyInitialized();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ownership is transferred from `oldOwner` to `newOwner`.
/// This event is intentionally kept the same as OpenZeppelin's Ownable to be
/// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
/// despite it not being as lightweight as a single argument event.
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
/// @dev An ownership handover to `pendingOwner` has been requested.
event OwnershipHandoverRequested(address indexed pendingOwner);
/// @dev The ownership handover to `pendingOwner` has been canceled.
event OwnershipHandoverCanceled(address indexed pendingOwner);
/// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
/// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
/// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The owner slot is given by:
/// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
/// It is intentionally chosen to be a high value
/// to avoid collision with lower slots.
/// The choice of manual storage layout is to enable compatibility
/// with both regular and upgradeable contracts.
bytes32 internal constant _OWNER_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
/// The ownership handover slot of `newOwner` is given by:
/// ```
/// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
/// let handoverSlot := keccak256(0x00, 0x20)
/// ```
/// It stores the expiry timestamp of the two-step ownership handover.
uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
/// @dev Initializes the owner directly without authorization guard.
/// This function must be called upon initialization,
/// regardless of whether the contract is upgradeable or not.
/// This is to enable generalization to both regular and upgradeable contracts,
/// and to save gas in case the initial owner is not the caller.
/// For performance reasons, this function will not check if there
/// is an existing owner.
function _initializeOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
if sload(ownerSlot) {
mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
revert(0x1c, 0x04)
}
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
} else {
/// @solidity memory-safe-assembly
assembly {
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(_OWNER_SLOT, newOwner)
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
}
}
/// @dev Sets the owner directly without authorization guard.
function _setOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
}
} else {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, newOwner)
}
}
}
/// @dev Throws if the sender is not the owner.
function _checkOwner() internal view virtual {
/// @solidity memory-safe-assembly
assembly {
// If the caller is not the stored owner, revert.
if iszero(eq(caller(), sload(_OWNER_SLOT))) {
mstore(0x00, 0x82b42900) // `Unauthorized()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Returns how long a two-step ownership handover is valid for in seconds.
/// Override to return a different value if needed.
/// Made internal to conserve bytecode. Wrap it in a public function if needed.
function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
return 48 * 3600;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC UPDATE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Allows the owner to transfer the ownership to `newOwner`.
function transferOwnership(address newOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
if iszero(shl(96, newOwner)) {
mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
revert(0x1c, 0x04)
}
}
_setOwner(newOwner);
}
/// @dev Allows the owner to renounce their ownership.
function renounceOwnership() public payable virtual onlyOwner {
_setOwner(address(0));
}
/// @dev Request a two-step ownership handover to the caller.
/// The request will automatically expire in 48 hours (172800 seconds) by default.
function requestOwnershipHandover() public payable virtual {
unchecked {
uint256 expires = block.timestamp + _ownershipHandoverValidFor();
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to `expires`.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), expires)
// Emit the {OwnershipHandoverRequested} event.
log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
}
}
}
/// @dev Cancels the two-step ownership handover to the caller, if any.
function cancelOwnershipHandover() public payable virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), 0)
// Emit the {OwnershipHandoverCanceled} event.
log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
}
}
/// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
/// Reverts if there is no existing ownership handover requested by `pendingOwner`.
function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
let handoverSlot := keccak256(0x0c, 0x20)
// If the handover does not exist, or has expired.
if gt(timestamp(), sload(handoverSlot)) {
mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
revert(0x1c, 0x04)
}
// Set the handover slot to 0.
sstore(handoverSlot, 0)
}
_setOwner(pendingOwner);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC READ FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the owner of the contract.
function owner() public view virtual returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_OWNER_SLOT)
}
}
/// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
function ownershipHandoverExpiresAt(address pendingOwner)
public
view
virtual
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
// Compute the handover slot.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
// Load the handover slot.
result := sload(keccak256(0x0c, 0x20))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MODIFIERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Marks a function as only callable by the owner.
modifier onlyOwner() virtual {
_checkOwner();
_;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import {Ownable} from "solady/src/auth/Ownable.sol";
import {ERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.5/contracts/token/ERC20/ERC20.sol";
interface IUniswapV2Router {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (
uint amountToken,
uint amountETH,
uint liquidity
);
}
interface IUniswapV2Factory {
function createPair(
address tokenA,
address tokenB
) external returns (address pair);
}
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
}
contract WhirlToken is ERC20, Ownable {
error MhhAreYouOk();
error CannotBlacklist();
error SwapAmountTooLow();
error MaxSwapTokensTooLow();
error MaxTradingAmountTooLow();
error MaxWalletAmountTooLow();
error BuySellFeesTooHigh();
error FeeDistributionTooHigh();
error CannotRemoveFromAMMPair();
error TransferToZeroAddr();
error TransferFromZeroAddr();
error BlacklistedFrom();
error BlacklistedTo();
error TradingNotActive();
error AmountExceedsMax();
error MaxWalletReached();
error ZeroTokenAddress();
error RevokedBlacklist();
error CannotBlacklistUni();
struct Flags {
bool feeExcluded;
bool isAmmp;
bool blacklisted;
bool flaggedBot;
bool maxExcluded;
}
uint8 private constant _NOT_SWAPPING = 1;
uint8 private constant _SWAPPING = 2;
address private constant _UNIV2_ROUTER
= 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
uint256 private constant _FEE_BASE = 1000;
uint256 private constant _SUPPLY = 10_000_000_000_000_000_000_000_000;
uint256 private constant _LIQ = 3_234_782_598_740_000_000_000_000;
uint256 private constant _FLAG_B = 0x2;
uint256 private constant _FLAG_TAX = 0x190;
uint256 private constant _STAGE1_TIME = 45;
// 5m including 45s from stage 1 = 4.15m period
uint256 private constant _STAGE2_TIME = 300;
IUniswapV2Router public immutable uniswapV2Router;
// Removing immutability to avoid emitting a pair created on constructor
address public uniswapV2Pair;
uint256 private _feesStage1;
uint256 private _feesStage2;
uint256 public maxTradingAmount = _SUPPLY * 25 / 10000;
uint256 public maxWallet = _SUPPLY * 50 / 10000;
uint256 public swapTokensAtAmount = _SUPPLY * 25 / 10000;
uint256 public maxSwapTokens = _SUPPLY * 25 / 10000;
uint256 public revMinHoldings = _SUPPLY * 20 / 10000;
uint256 public revEpochDuration = 7 days;
uint256 public revStart;
uint256 public tradingStartedAt;
uint256 public tradingBlock;
address public marketWallet = 0xe4742A92147628ea668b35e245088d31E1292A6B;
address public revWallet = 0x50349E0A700c4AeA3420E3628d175107DA3Ee7bD;
address public teamWallet = 0x5D4453912DC5c932F2dE84Cd156F84CD8870A1E8;
bool public blacklistRenounced;
bool private initialized;
uint256 private _swapping = _NOT_SWAPPING;
uint256 public buyFees = 50;
uint256 public sellFees = 50;
// 20% of total fees, 20% of 5% => 1% total fees
uint256 public marketFee = 200;
// 20% of total fees, 20% of 5% => 1% total fees
uint256 public revFee = 200;
// 60% of total fees, 60% of 5% => 3% total fees
uint256 public teamFee = 600;
// Packed it!
mapping(address => Flags) public flags;
event ExcludeFromFees(address indexed account, bool isExcluded);
event ExcludedFromMaxTrading(address addr, bool isEx);
event AutomatedMarkerPairUpdated(address pair, bool value);
event BlacklistUpdated(address indexed addr, bool value);
event BlacklistLpUpdated(address indexed lpAddr, bool value);
event MarketWalletUpdated(address addr);
event RevWalletUpdated(address addr);
event TeamWalletUpdated(address addr);
event RevMinHoldingUpdated(uint256 min);
event RevStarted(uint256 duration);
event Accrued(address addr, uint256 amount);
constructor() ERC20("Whirl Token", "WHIRL") payable {
_initializeOwner(msg.sender);
assembly {
sstore(add(0x2, 0x4), mul(0xa, add(0x1b, 0xd)))
sstore(sub(0x1d, 0x16), add(0xb4, div(0xf0, 0xc)))
}
uniswapV2Router = IUniswapV2Router(_UNIV2_ROUTER);
flags[_UNIV2_ROUTER].maxExcluded = true;
// Vesting batch
flags[0xEa07DdBBeA804E7fe66b958329F8Fa5cDA95Bd55].maxExcluded = true;
// Vesting lockup
flags[0x7CC7e125d83A581ff438608490Cc0f7bDff79127].maxExcluded = true;
flags[msg.sender] = Flags(
true,
false,
false,
false,
true
);
flags[address(this)] = Flags(
true,
false,
false,
false,
true
);
_mint(msg.sender, _SUPPLY - _LIQ);
}
receive() external payable {}
// OWNER
function init() payable external {
_checkOwner();
if (initialized) _revert(MhhAreYouOk.selector);
initialized = true;
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory())
.createPair(address(this), uniswapV2Router.WETH());
flags[address(uniswapV2Pair)] = Flags(
false,
true,
false,
false,
true
);
_mint(address(this), _LIQ);
_addLiquidity(_LIQ, address(this).balance);
}
function startNow() external {
_checkOwner();
if (tradingStartedAt != 0) _revert(MhhAreYouOk.selector);
tradingStartedAt = block.timestamp;
tradingBlock = block.number;
}
function updateSwapTokensAtAmount(uint256 amount_) external {
_checkOwner();
// No OF here if correct supply
unchecked {
// Min 0.00001% total supply => 100
if (amount_ < _SUPPLY / 100000)
_revert(SwapAmountTooLow.selector);
}
swapTokensAtAmount = amount_;
}
function updateMaxSwapTokens(uint256 max_) external {
_checkOwner();
// No OF here if correct supply
unchecked {
// Min 0.0001% total supply => 1000
if (max_ < _SUPPLY / 10000)
_revert(MaxSwapTokensTooLow.selector);
}
maxSwapTokens = max_;
}
function updateMaxTradingAmount(uint256 max_) external {
_checkOwner();
unchecked {
// Min (0.1% supply) => 10k
if (max_ < _SUPPLY / 1000)
_revert(MaxTradingAmountTooLow.selector);
}
maxTradingAmount = max_;
}
function updateMaxWalletAmount(uint256 max_) external {
_checkOwner();
unchecked {
// TODO: See min (1% supply) => 100k
if (max_ < _SUPPLY / 100)
_revert(MaxWalletAmountTooLow.selector);
}
maxWallet = max_;
}
function excludeFromMaxTrading(address addr_, bool isEx_) external {
_checkOwner();
flags[addr_].maxExcluded = isEx_;
emit ExcludedFromMaxTrading(addr_, isEx_);
}
function updateFees(uint256 buyFees_, uint256 sellFees_) external {
_checkOwner();
// Max 10%
if (buyFees_ > 100 || sellFees_ > 100)
_revert(BuySellFeesTooHigh.selector);
buyFees = buyFees_;
sellFees = sellFees_;
}
function updateStageFees(
uint256 stage1_,
uint256 stage2_
) external {
_checkOwner();
// 50% max, honnest!
uint256 max = _FEE_BASE / 2;
if (stage1_ > max) _revert(MhhAreYouOk.selector);
if (stage2_ > max) _revert(MhhAreYouOk.selector);
_feesStage1 = stage1_;
_feesStage2 = stage2_;
}
function updateFeeDistribution(
uint256 marketFee_,
uint256 revFee_
) external {
_checkOwner();
if (marketFee_ + revFee_ > _FEE_BASE)
_revert(FeeDistributionTooHigh.selector);
marketFee = marketFee_;
revFee = revFee_;
// OF checked above
unchecked {
teamFee = _FEE_BASE - marketFee_ - revFee_;
}
}
function excludeFromFees(address addr_, bool excluded_) external {
_checkOwner();
flags[addr_].feeExcluded = excluded_;
emit ExcludeFromFees(addr_, excluded_);
}
function setAutomatedMarketMakerPair(address pair_, bool value_) external {
_checkOwner();
if (pair_ == uniswapV2Pair) _revert(CannotRemoveFromAMMPair.selector);
flags[pair_].isAmmp = value_;
emit AutomatedMarkerPairUpdated(pair_, value_);
}
function updateMarketWallet(address wallet_) external {
_checkOwner();
marketWallet = wallet_;
emit MarketWalletUpdated(wallet_);
}
function updateRevWallet(address wallet_) external {
_checkOwner();
revWallet = wallet_;
emit RevWalletUpdated(wallet_);
}
function updateTeamWallet(address wallet_) external {
_checkOwner();
teamWallet = wallet_;
emit TeamWalletUpdated(wallet_);
}
function withdrawStuckERC20(address token_, address to_) external {
_checkOwner();
if (token_ == address(0)) _revert(ZeroTokenAddress.selector);
uint256 _contractBalance = IERC20(token_).balanceOf(address(this));
IERC20(token_).transfer(to_, _contractBalance);
}
function withdrawStuckETH(address addr_) external {
_checkOwner();
(bool success, ) = addr_.call{value: address(this).balance}("");
require(success);
}
function renounceBlacklist() external {
_checkOwner();
blacklistRenounced = true;
}
function updateBlacklist(address addr_, bool value_) external {
_checkOwner();
if (blacklistRenounced) _revert(RevokedBlacklist.selector);
if (addr_ == address(uniswapV2Pair) || addr_ == _UNIV2_ROUTER)
_revert(CannotBlacklistUni.selector);
flags[addr_].blacklisted = value_;
emit BlacklistUpdated(addr_, value_);
}
function updateBlacklistLp(address addr_, bool value_) external {
_checkOwner();
if (blacklistRenounced) _revert(RevokedBlacklist.selector);
if (addr_ == address(uniswapV2Pair) || addr_ == _UNIV2_ROUTER)
_revert(CannotBlacklistUni.selector);
flags[addr_].blacklisted = value_;
emit BlacklistLpUpdated(addr_, value_);
}
function updateRevMinHoldings(uint256 min_) external {
_checkOwner();
revMinHoldings = min_;
emit RevMinHoldingUpdated(min_);
}
function updateRevEpochDuration(uint256 duration_) external {
_checkOwner();
// Avoids potential OF on weight, 1 year being already such a long wait
if (duration_ > 31536000)
_revert(MhhAreYouOk.selector);
revEpochDuration = duration_;
// Since epoch start are computed off revStart / duration,
// we restart if changing duration
revStart = block.timestamp;
emit RevStarted(duration_);
}
function startRev() external {
_checkOwner();
if (revStart == 0) {
revStart = block.timestamp;
emit RevStarted(revEpochDuration);
}
}
// PUB/EXTERNAL
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}
// PRV/INTERNAL
function _transfer(
address from_,
address to_,
uint256 amount_
) internal override {
if (from_ == address(0)) _revert(TransferFromZeroAddr.selector);
if (to_ == address(0)) _revert(TransferToZeroAddr.selector);
Flags memory fromFlags = flags[from_];
Flags memory toFlags = flags[to_];
if (fromFlags.blacklisted) _revert(BlacklistedFrom.selector);
if (toFlags.blacklisted) _revert(BlacklistedTo.selector);
if (amount_ == 0) return super._transfer(from_, to_, 0);
uint256 cachedTradingStart = tradingStartedAt;
bool notSwapping = _swapping == _NOT_SWAPPING;
address owner = owner();
if (
from_ != owner &&
to_ != owner &&
to_ != address(0) &&
notSwapping
) _secureTransfer(
cachedTradingStart,
amount_,
fromFlags,
toFlags,
to_
);
bool canSwap = balanceOf(address(this)) >= swapTokensAtAmount;
if (
canSwap &&
notSwapping &&
!fromFlags.isAmmp &&
!fromFlags.feeExcluded &&
!toFlags.feeExcluded
) {
_swapping = _SWAPPING;
_swapBack();
_swapping = _NOT_SWAPPING;
}
bool takeFee = !fromFlags.feeExcluded && !toFlags.feeExcluded && notSwapping;
if (takeFee) {
uint256 fees = amount_ * _getFeeRates(
cachedTradingStart,
from_,
to_,
fromFlags.isAmmp,
toFlags.isAmmp
) / _FEE_BASE;
amount_ -= fees;
if (fees > 0) super._transfer(from_, address(this), fees);
}
if (revStart != 0) {
_processRevAccrual(from_, fromFlags.isAmmp);
_processRevAccrual(to_, toFlags.isAmmp);
}
super._transfer(from_, to_, amount_);
}
function _secureTransfer(
uint256 tradingStart_,
uint256 amount_,
Flags memory fromFlags_,
Flags memory toFlags_,
address to_
) internal view {
if (tradingStart_ == 0)
if (!fromFlags_.feeExcluded && !toFlags_.feeExcluded)
_revert(TradingNotActive.selector);
if (fromFlags_.isAmmp && !toFlags_.maxExcluded) {
// buying
if (amount_ > maxTradingAmount)
_revert(AmountExceedsMax.selector);
if (amount_ + balanceOf(to_) > maxWallet)
_revert(MaxWalletReached.selector);
} else if (toFlags_.isAmmp && !fromFlags_.maxExcluded) {
// selling
if (amount_ > maxTradingAmount)
_revert(AmountExceedsMax.selector);
} else if (!toFlags_.maxExcluded) {
// transfer
if (amount_ + balanceOf(to_) > maxWallet)
_revert(MaxWalletReached.selector);
}
}
function _getFeeRates(
uint256 tradingStart_,
address from_,
address to_,
bool fromAmmp_,
bool toAmmp_
) internal returns (uint256) {
unchecked {
// Flagged uh uh!
if (flags[from_].flaggedBot) return _FLAG_TAX;
// Regular fees applied, short path
if (block.timestamp > tradingStart_ + _STAGE2_TIME) {
// Buying
if (fromAmmp_) return buyFees;
// Selling
if (toAmmp_) return sellFees;
// Transfer
return 0;
}
if (fromAmmp_ && block.number <= tradingBlock + _FLAG_B)
// Flagged uh uh!
flags[to_].flaggedBot = true;
// First mins of trading, lauch fees applied on buy/sell
if (fromAmmp_ || toAmmp_) return _launchFeeRates(tradingStart_);
// Transfer launch fees
return 0;
}
}
function _launchFeeRates(
uint256 tradingStart_
) internal view returns (uint256) {
if (block.timestamp > tradingStart_ + _STAGE1_TIME)
return _feesStage2;
return _feesStage1;
}
// Used offchain to weight user holdings, snapshots the previous balance
function _processRevAccrual(
address holder_,
bool isAMMP_
) private {
if (isAMMP_) return;
uint256 balance = balanceOf(holder_);
if (balance < revMinHoldings) return;
emit Accrued(holder_, balance);
}
function _swapTokensForEth(uint256 amount_) private {
IUniswapV2Router cachedRouter = uniswapV2Router;
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = cachedRouter.WETH();
_approve(address(this), address(cachedRouter), amount_);
cachedRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
amount_,
0,
path,
address(this),
block.timestamp
);
}
function _swapBack() private {
uint256 toSwap = balanceOf(address(this));
if (toSwap == 0) return;
uint256 cachedMaxSwapTokens = maxSwapTokens;
if (toSwap > cachedMaxSwapTokens)
toSwap = cachedMaxSwapTokens;
uint256 initialETHBalance = address(this).balance;
_swapTokensForEth(toSwap);
uint256 marketETH;
uint256 revETH;
uint256 teamETH;
// Cannot OF since no ETH is sent during swap, worse case would be receiving 0 => bal - bal = 0
unchecked {
uint256 ethBalance = address(this).balance - initialETHBalance;
// OF here would require an incredibly huge amount of ETH,
// see if leaving it checked anyway
marketETH = ethBalance * marketFee / _FEE_BASE;
revETH = ethBalance * revFee / _FEE_BASE;
teamETH = ethBalance - marketETH - revETH;
}
bool success;
(success, ) = address(marketWallet).call{value: marketETH}("");
(success, ) = address(revWallet).call{value: revETH}("");
(success, ) = address(teamWallet).call{value: teamETH}("");
}
function _addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0,
0,
msg.sender,
block.timestamp
);
}
function _revert(bytes4 code_) private pure {
assembly {
mstore(0x0, code_)
revert(0x0, 0x4)
}
}
}
{
"compilationTarget": {
"contracts/WhirlToken.sol": "WhirlToken"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 500
},
"remappings": []
}
[{"inputs":[],"stateMutability":"payable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"AmountExceedsMax","type":"error"},{"inputs":[],"name":"BlacklistedFrom","type":"error"},{"inputs":[],"name":"BlacklistedTo","type":"error"},{"inputs":[],"name":"BuySellFeesTooHigh","type":"error"},{"inputs":[],"name":"CannotBlacklist","type":"error"},{"inputs":[],"name":"CannotBlacklistUni","type":"error"},{"inputs":[],"name":"CannotRemoveFromAMMPair","type":"error"},{"inputs":[],"name":"FeeDistributionTooHigh","type":"error"},{"inputs":[],"name":"MaxSwapTokensTooLow","type":"error"},{"inputs":[],"name":"MaxTradingAmountTooLow","type":"error"},{"inputs":[],"name":"MaxWalletAmountTooLow","type":"error"},{"inputs":[],"name":"MaxWalletReached","type":"error"},{"inputs":[],"name":"MhhAreYouOk","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"RevokedBlacklist","type":"error"},{"inputs":[],"name":"SwapAmountTooLow","type":"error"},{"inputs":[],"name":"TradingNotActive","type":"error"},{"inputs":[],"name":"TransferFromZeroAddr","type":"error"},{"inputs":[],"name":"TransferToZeroAddr","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"ZeroTokenAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Accrued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"bool","name":"value","type":"bool"}],"name":"AutomatedMarkerPairUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lpAddr","type":"address"},{"indexed":false,"internalType":"bool","name":"value","type":"bool"}],"name":"BlacklistLpUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"bool","name":"value","type":"bool"}],"name":"BlacklistUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isExcluded","type":"bool"}],"name":"ExcludeFromFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"bool","name":"isEx","type":"bool"}],"name":"ExcludedFromMaxTrading","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"MarketWalletUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"min","type":"uint256"}],"name":"RevMinHoldingUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"}],"name":"RevStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"RevWalletUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"}],"name":"TeamWalletUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"blacklistRenounced","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"buyFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"excluded_","type":"bool"}],"name":"excludeFromFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"isEx_","type":"bool"}],"name":"excludeFromMaxTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"flags","outputs":[{"internalType":"bool","name":"feeExcluded","type":"bool"},{"internalType":"bool","name":"isAmmp","type":"bool"},{"internalType":"bool","name":"blacklisted","type":"bool"},{"internalType":"bool","name":"flaggedBot","type":"bool"},{"internalType":"bool","name":"maxExcluded","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"init","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"marketFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSwapTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTradingAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxWallet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceBlacklist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"revEpochDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revMinHoldings","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sellFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pair_","type":"address"},{"internalType":"bool","name":"value_","type":"bool"}],"name":"setAutomatedMarketMakerPair","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startNow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startRev","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapTokensAtAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"teamFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"teamWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tradingStartedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"uniswapV2Pair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapV2Router","outputs":[{"internalType":"contract IUniswapV2Router","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"value_","type":"bool"}],"name":"updateBlacklist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"},{"internalType":"bool","name":"value_","type":"bool"}],"name":"updateBlacklistLp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"marketFee_","type":"uint256"},{"internalType":"uint256","name":"revFee_","type":"uint256"}],"name":"updateFeeDistribution","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"buyFees_","type":"uint256"},{"internalType":"uint256","name":"sellFees_","type":"uint256"}],"name":"updateFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet_","type":"address"}],"name":"updateMarketWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"max_","type":"uint256"}],"name":"updateMaxSwapTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"max_","type":"uint256"}],"name":"updateMaxTradingAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"max_","type":"uint256"}],"name":"updateMaxWalletAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"duration_","type":"uint256"}],"name":"updateRevEpochDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"min_","type":"uint256"}],"name":"updateRevMinHoldings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet_","type":"address"}],"name":"updateRevWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"stage1_","type":"uint256"},{"internalType":"uint256","name":"stage2_","type":"uint256"}],"name":"updateStageFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"updateSwapTokensAtAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet_","type":"address"}],"name":"updateTeamWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"to_","type":"address"}],"name":"withdrawStuckERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr_","type":"address"}],"name":"withdrawStuckETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]