Update the following code to allow the change of the marketingFee and reflectionFee…
- User
Update the following code to allow the change of the marketingFee and reflectionFee based on a specific day. For example: on December 25th the reflectionFee = 0 and the marketingFee = 1. I would like to do this for other days on the calendar. Like, Valentine ’s Day, Thanksgiving and other holidays. Please take into account leap years.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import "@openzeppelin/contracts/access/Ownable.sol";
contract Reflect is ERC20, ERC20Burnable, Ownable { // The marketing wallet address address public marketingWallet;
// The percentage of fee to be sent to the marketing wallet uint256 public marketingFee = 3; // The percentage of fee to be distributed to all token holders uint256 public reflectionFee = 2; // The total fee percentage uint256 public totalFee = marketingFee + reflectionFee; // The maximum fee percentage allowed uint256 public constant MAX_FEE = 10; // The total amount of tokens that have been reflected uint256 public totalReflected; // The total amount of fees that have been deducted uint256 public totalFees; // A mapping of the current reflection balance of each account mapping (address => uint256) private _reflectionBalances; // A mapping of the current token balance of each account (exluding reflection) mapping (address => uint256) private _tokenBalances; // A mapping of whether an account is excluded from reflection mapping (address => bool) private _isExcluded; // An array of accounts that are excluded from reflection address[] private _excluded; // The total amount of reflection uint256 private _reflectionTotal; // The name of the token string private _name; // The symbol of the token string private _symbol; // The decimals of the token uint8 private _decimals; // The total supply of the token uint256 private _totalSupply; // A flag to prevent recursive calls bool private _inTransfer; // Events event MarketingFeeUpdated(uint256 newMarketingFee); event ReflectionFeeUpdated(uint256 newReflectionFee); event ExcludedFromReflection(address account); event IncludedInReflection(address account); // Modifiers modifier lockTheTransfer { _inTransfer = true; _; _inTransfer = false; } /** * @dev Constructor function */ constructor (address _marketingWallet) ERC20("Reflect", "RFT") { // Set the marketing wallet address marketingWallet = _marketingWallet; // Set the name of the token _name = "Reflect"; // Set the symbol of the token _symbol = "RFT"; // Set the decimals of the token _decimals = 18; // Set the total supply of the token _totalSupply = 1 * 10**9 * 10**_decimals; // Set the initial reflection total _reflectionTotal = (~uint256(0) - (~uint256(0) % _totalSupply)); // Exclude the contract and the burn address from reflection _isExcluded[address(this)] = true; _isExcluded[0x000000000000000000000000000000000000dEaD] = true; _excluded.push(address(this)); _excluded.push(0x000000000000000000000000000000000000dEaD); // Mint the total supply to the owner _reflectionBalances[_msgSender()] = _reflectionTotal; emit Transfer(address(0), _msgSender(), _totalSupply); } /** * @dev Returns the name of the token */ function name() public view override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token */ function symbol() public view override returns (string memory) { return _symbol; } /** * @dev Returns the decimals of the token */ function decimals() public view override returns (uint8) { return _decimals; } /** * @dev Returns the total supply of the token */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev Returns the balance of an account */ function balanceOf(address account) public view override returns (uint256) { if (_isExcluded[account]) { return _tokenBalances[account]; } return tokenFromReflection(_reflectionBalances[account]); } /** * @dev Returns the reflection amount from a token amount */ function reflectionFromToken(uint256 amount, bool deductFee) public view returns (uint256) { require(amount <= _totalSupply, "Amount must be less than supply"); if (!deductFee) { return amount * _getRate(); } else { return (amount - (amount * totalFee / 100)) * _getRate(); } } /** * @dev Returns the token amount from a reflection amount */ function tokenFromReflection(uint256 amount) public view returns (uint256) { require(amount <= _reflectionTotal, "Amount must be less than total reflections"); uint256 rate = _getRate(); return amount / rate; } /** * @dev Transfers tokens to another account */ function transfer(address recipient, uint256 amount) public override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev Allows an account to spend tokens on behalf of another account */ function approve(address spender, uint256 amount) public override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev Returns the allowance of an account */ function allowance(address owner, address spender) public view override returns (uint256) { return super.allowance(owner, spender); } /** * @dev Transfers tokens from one account to another */ function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), super.allowance(sender, _msgSender()) - amount); return true; } /** * @dev Increases the allowance of an account */ function increaseAllowance(address spender, uint256 addedValue) public override returns (bool) { _approve(_msgSender(), spender, super.allowance(_msgSender(), spender) + addedValue); return true; } /** * @dev Decreases the allowance of an account */ function decreaseAllowance(address spender, uint256 subtractedValue) public override returns (bool) { _approve(_msgSender(), spender, super.allowance(_msgSender(), spender) - subtractedValue); return true; } /** * @dev Updates the marketing fee percentage */ function updateMarketingFee(uint256 newMarketingFee) public onlyOwner { require(newMarketingFee <= MAX_FEE, "Marketing fee must not exceed the max fee"); marketingFee = newMarketingFee; totalFee = marketingFee + reflectionFee; emit MarketingFeeUpdated(newMarketingFee); } /** * @dev Updates the reflection fee percentage */ function updateReflectionFee(uint256 newReflectionFee) public onlyOwner { require(newReflectionFee - Assistant
(sender, recipient, amount);
// If the recipient is excluded, update their token balance if (_isExcluded[recipient]) { _tokenBalances[recipient] += amount; }
// Reflect the fee to all token holders _reflectFee(feeAmount);
// Update the total supply _totalSupply -= feeAmount;
// Update the total reflected and fees totalReflected -= feeAmount; totalFees += feeAmount;
// Emit the transfer event emit Transfer(sender, recipient, amount - feeAmount);
// Burn the fee amount _burn(sender, feeAmount);
// Update the reflection balances of sender and recipient _reflectionBalances[sender] -= reflectionAmount; _reflectionBalances[recipient] += (reflectionAmount - feeAmount);
// If the sender or recipient is excluded, update their token balance if (_isExcluded[sender]) { _tokenBalances[sender] -= amount; } if (_isExcluded[recipient]) { _tokenBalances[recipient] += amount; }
// Emit the transfer event emit Transfer(sender, recipient, amount); }
/** *@dev Reflects the fee to all token holders */ function _reflectFee(uint256 feeAmount) private { _reflectionTotal -= feeAmount * _getRate(); totalReflected += feeAmount * _getRate(); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.