Skip to content

Instantly share code, notes, and snippets.

@DoctorNasa
Created September 26, 2024 09:01
Show Gist options
  • Save DoctorNasa/3ceb52efa3628ae9687457c120a4b365 to your computer and use it in GitHub Desktop.
Save DoctorNasa/3ceb52efa3628ae9687457c120a4b365 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.26+commit.8a97fa7a.js&optimize=true&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
/// @custom:security-contact [email protected]
contract Moodeng is ERC20, ERC20Burnable, ERC20Pausable, Ownable, ERC20Permit, ERC20Votes, ERC20FlashMint {
using SafeMath for uint256;
uint256 public constant MAX_SUPPLY = 1_000_000_000 * (10 ** 18); // 1 billion tokens (with 18 decimals)
uint256 public taxFee; // Tax fee percentage (1% = 100, so 100 = 1%)
uint256 public reflectionFee; // Reflection fee percentage (1% = 100, so 100 = 1%)
uint256 public maxTxAmount; // Max transaction amount for anti-whale feature
address public taxWallet; // Wallet to collect tax fees
mapping(address => bool) private _holders; // Track active holders
address[] private _holderList; // Store the list of holder addresses
event FeeTaken(address indexed from, uint256 taxAmount, uint256 reflectionAmount);
event TokensAirdropped(address indexed recipient, uint256 amount);
constructor(
address initialOwner,
uint256 _taxFee,
uint256 _reflectionFee,
uint256 _maxTxAmount,
address _taxWallet
)
ERC20("Moodeng", "MDNG")
Ownable(initialOwner)
ERC20Permit("Moodeng")
{
taxFee = _taxFee;
reflectionFee = _reflectionFee;
maxTxAmount = _maxTxAmount;
taxWallet = _taxWallet;
// Mint initial supply to the deployer (ensure initial supply does not exceed max supply)
_mint(msg.sender, 9 * 10 ** decimals());
}
// Internal function to remove a holder from the list
function _removeHolder(address holder) private {
_holders[holder] = false;
// Remove holder from the _holderList array
for (uint256 i = 0; i < _holderList.length; i++) {
if (_holderList[i] == holder) {
_holderList[i] = _holderList[_holderList.length - 1]; // Move the last element into the place of the one being removed
_holderList.pop(); // Remove the last element
break;
}
}
}
// Reflection: Redistribute tokens to holders
function _reflectFee(uint256 reflectionAmount) private {
uint256 currentSupply = totalSupply();
for (uint256 i = 0; i < _holderList.length; i++) {
address holder = _holderList[i];
uint256 balance = balanceOf(holder);
if (balance > 0) {
uint256 holderShare = reflectionAmount.mul(balance).div(currentSupply);
_mint(holder, holderShare);
}
}
}
// Airdrop function
function airdrop(address[] calldata recipients, uint256[] calldata amounts) external onlyOwner {
require(recipients.length == amounts.length, "Recipients and amounts length mismatch");
for (uint256 i = 0; i < recipients.length; i++) {
require(balanceOf(_msgSender()) >= amounts[i], "Insufficient balance for airdrop");
_transfer(_msgSender(), recipients[i], amounts[i]);
emit TokensAirdropped(recipients[i], amounts[i]);
}
}
// Mint function with max supply check
function mint(address to, uint256 amount) public onlyOwner {
require(totalSupply().add(amount) <= MAX_SUPPLY, "Max supply exceeded");
_mint(to, amount);
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function clock() public view override returns (uint48) {
return uint48(block.timestamp);
}
// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public pure override returns (string memory) {
return "mode=timestamp";
}
// The following functions are overrides required by Solidity.
function _update(address from, address to, uint256 value)
internal
override(ERC20, ERC20Pausable, ERC20Votes) // Include ERC20, ERC20Pausable, and ERC20Votes in the override
{
super._update(from, to, value);
// Custom logic to track holders
if (value > 0 && !_holders[to] && to != address(0)) {
_holders[to] = true;
_holderList.push(to);
}
if (from != address(0) && balanceOf(from) == 0) {
_removeHolder(from);
}
}
function nonces(address owner)
public
view
override(ERC20Permit, Nonces)
returns (uint256)
{
return super.nonces(owner);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment