//SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "./IERC20.sol";
import "./Ownable.sol";
contract FireToken is IERC20, Ownable {
// total supply
uint256 private _totalSupply = 4_500_000 * 10**18;
// token data
string private constant _name = "FIRE";
string private constant _symbol = "FIRE";
uint8 private constant _decimals = 18;
// balances
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
// Taxation on transfers
uint256 public buyFee = 500;
uint256 public sellFee = 1250;
uint256 public transferFee = 0;
uint256 public constant TAX_DENOM = 10000;
// permissions
struct Permissions {
bool isFeeExempt;
bool isLiquidityPool;
}
mapping ( address => Permissions ) public permissions;
// Fee Recipients
address public sellFeeRecipient;
address public buyFeeRecipient;
address public transferFeeRecipient;
// events
event SetBuyFeeRecipient(address recipient);
event SetSellFeeRecipient(address recipient);
event SetTransferFeeRecipient(address recipient);
event SetFeeExemption(address account, bool isFeeExempt);
event SetAutomatedMarketMaker(address account, bool isMarketMaker);
event SetFees(uint256 buyFee, uint256 sellFee, uint256 transferFee);
constructor() {
// set initial token data
address _owner = 0x42290Ba8C7770f7eFa8d8224675Ca3b658a9834C;
// exempt sender for tax-free initial distribution
permissions[msg.sender].isFeeExempt = true;
permissions[_owner].isFeeExempt = true;
// initial supply allocation
_balances[_owner] = _totalSupply;
emit Transfer(address(0), _owner, _totalSupply);
}
function totalSupply() external view override returns (uint256) { return _totalSupply; }
function balanceOf(address account) public view override returns (uint256) { return _balances[account]; }
function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; }
function name() public pure override returns (string memory) {
return _name;
}
function symbol() public pure override returns (string memory) {
return _symbol;
}
function decimals() public pure override returns (uint8) {
return _decimals;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_allowances[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
/** Transfer Function */
function transfer(address recipient, uint256 amount) external override returns (bool) {
return _transferFrom(msg.sender, recipient, amount);
}
/** Transfer Function */
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
require(
_allowances[sender][msg.sender] >= amount,
'Insufficient Allowance'
);
_allowances[sender][msg.sender] -= amount;
return _transferFrom(sender, recipient, amount);
}
function burn(uint256 amount) external returns (bool) {
return _burn(msg.sender, amount);
}
function burnFrom(address account, uint256 amount) external returns (bool) {
require(
_allowances[account][msg.sender] >= amount,
'Insufficient Allowance'
);
_allowances[account][msg.sender] -= amount;
return _burn(account, amount);
}
/** Internal Transfer */
function _transferFrom(address sender, address recipient, uint256 amount) internal returns (bool) {
require(
recipient != address(0),
'Zero Recipient'
);
require(
amount > 0,
'Zero Amount'
);
require(
amount <= _balances[sender],
'Insufficient Balance'
);
// decrement sender balance
_balances[sender] -= amount;
// fee for transaction
(uint256 fee, address feeDestination) = getTax(sender, recipient, amount);
// allocate fee
if (fee > 0) {
address feeRecipient = feeDestination == address(0) ? address(this) : feeDestination;
unchecked {
_balances[feeRecipient] += fee;
}
emit Transfer(sender, feeRecipient, fee);
}
// give amount to recipient
uint256 sendAmount = amount - fee;
unchecked {
_balances[recipient] += sendAmount;
}
// emit transfer
emit Transfer(sender, recipient, sendAmount);
return true;
}
function withdraw(address token) external onlyOwner {
require(token != address(0), 'Zero Address');
bool s = IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this)));
require(s, 'Failure On Token Withdraw');
}
function withdrawBNB() external onlyOwner {
(bool s,) = payable(msg.sender).call{value: address(this).balance}("");
require(s);
}
function setTransferFeeRecipient(address recipient) external onlyOwner {
require(recipient != address(0), 'Zero Address');
transferFeeRecipient = recipient;
permissions[recipient].isFeeExempt = true;
emit SetTransferFeeRecipient(recipient);
}
function setBuyFeeRecipient(address recipient) external onlyOwner {
require(recipient != address(0), 'Zero Address');
buyFeeRecipient = recipient;
permissions[recipient].isFeeExempt = true;
emit SetBuyFeeRecipient(recipient);
}
function setSellFeeRecipient(address recipient) external onlyOwner {
require(recipient != address(0), 'Zero Address');
sellFeeRecipient = recipient;
permissions[recipient].isFeeExempt = true;
emit SetSellFeeRecipient(recipient);
}
function registerAutomatedMarketMaker(address account) external onlyOwner {
require(account != address(0), 'Zero Address');
require(!permissions[account].isLiquidityPool, 'Already An AMM');
permissions[account].isLiquidityPool = true;
emit SetAutomatedMarketMaker(account, true);
}
function unRegisterAutomatedMarketMaker(address account) external onlyOwner {
require(account != address(0), 'Zero Address');
require(permissions[account].isLiquidityPool, 'Not An AMM');
permissions[account].isLiquidityPool = false;
emit SetAutomatedMarketMaker(account, false);
}
function setFees(uint _buyFee, uint _sellFee, uint _transferFee) external onlyOwner {
require(
_buyFee <= 2000,
'Buy Fee Too High'
);
require(
_sellFee <= 2000,
'Sell Fee Too High'
);
require(
_transferFee <= 2000,
'Transfer Fee Too High'
);
buyFee = _buyFee;
sellFee = _sellFee;
transferFee = _transferFee;
emit SetFees(_buyFee, _sellFee, _transferFee);
}
function setFeeExempt(address account, bool isExempt) external onlyOwner {
require(account != address(0), 'Zero Address');
permissions[account].isFeeExempt = isExempt;
emit SetFeeExemption(account, isExempt);
}
function getTax(address sender, address recipient, uint256 amount) public view returns (uint256, address) {
if ( permissions[sender].isFeeExempt || permissions[recipient].isFeeExempt ) {
return (0, address(0));
}
return permissions[sender].isLiquidityPool ?
((amount * buyFee) / TAX_DENOM, buyFeeRecipient) :
permissions[recipient].isLiquidityPool ?
((amount * sellFee) / TAX_DENOM, sellFeeRecipient) :
((amount * transferFee) / TAX_DENOM, transferFeeRecipient);
}
function _burn(address account, uint256 amount) internal returns (bool) {
require(
account != address(0),
'Zero Address'
);
require(
amount > 0,
'Zero Amount'
);
require(
amount <= _balances[account],
'Insufficient Balance'
);
_balances[account] -= amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
return true;
}
receive() external payable {}
}
//SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
interface IERC20 {
function totalSupply() external view returns (uint256);
function symbol() external view returns(string memory);
function name() external view returns(string memory);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Returns the number of decimal places
*/
function decimals() external view returns (uint8);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (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.
*/
function allowance(address owner, address spender) external view returns (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
* 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.
*/
function approve(address spender, uint256 amount) external returns (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.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed 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.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.20;
/**
* @title Owner
* @dev Set & change owner
*/
contract Ownable {
address private owner;
// event for EVM logging
event OwnerSet(address indexed oldOwner, address indexed newOwner);
// modifier to check if caller is owner
modifier onlyOwner() {
// If the first argument of 'require' evaluates to 'false', execution terminates and all
// changes to the state and to Ether balances are reverted.
// This used to consume all gas in old EVM versions, but not anymore.
// It is often a good idea to use 'require' to check if functions are called correctly.
// As a second argument, you can also provide an explanation about what went wrong.
require(msg.sender == owner, "Caller is not owner");
_;
}
/**
* @dev Set contract deployer as owner
*/
constructor() {
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
emit OwnerSet(address(0), owner);
}
/**
* @dev Change owner
* @param newOwner address of new owner
*/
function changeOwner(address newOwner) public onlyOwner {
emit OwnerSet(owner, newOwner);
owner = newOwner;
}
/**
* @dev Return owner address
* @return address of owner
*/
function getOwner() external view returns (address) {
return owner;
}
}
{
"compilationTarget": {
"FireToken.sol": "FireToken"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"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":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isMarketMaker","type":"bool"}],"name":"SetAutomatedMarketMaker","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"SetBuyFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isFeeExempt","type":"bool"}],"name":"SetFeeExemption","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"buyFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sellFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"transferFee","type":"uint256"}],"name":"SetFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"SetSellFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"SetTransferFeeRecipient","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":[],"name":"TAX_DENOM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","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":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"buyFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getTax","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"permissions","outputs":[{"internalType":"bool","name":"isFeeExempt","type":"bool"},{"internalType":"bool","name":"isLiquidityPool","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"registerAutomatedMarketMaker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sellFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sellFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"setBuyFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"isExempt","type":"bool"}],"name":"setFeeExempt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_buyFee","type":"uint256"},{"internalType":"uint256","name":"_sellFee","type":"uint256"},{"internalType":"uint256","name":"_transferFee","type":"uint256"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"setSellFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"setTransferFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"transferFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"unRegisterAutomatedMarketMaker","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawBNB","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]