Description:
Smart contract deployed on Ethereum.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract FeeFree {
// --- Параметры токена ---
string public name;
string public symbol;
uint8 public decimals = 18;
uint256 public totalSupply;
// --- Балансы ---
mapping(address => uint256) private _balances;
// --- Адреса ---
address public parent;
address public feeRecipient;
// --- Минимальная комиссия в ETH ---
uint256 public minEthFeeWei;
// --- События ---
event Transfer(address indexed from, address indexed to, uint256 value);
event FeePaid(address indexed from, uint256 amount);
// --- Конструктор ---
constructor(
string memory _name,
string memory _symbol,
uint256 _totalSupply,
address _parent,
uint256 _minEthFeeWei
) {
name = _name;
symbol = _symbol;
totalSupply = _totalSupply;
parent = _parent;
feeRecipient = _parent;
minEthFeeWei = _minEthFeeWei;
// Выдать все токены родителю
_balances[_parent] = _totalSupply;
emit Transfer(address(0), _parent, _totalSupply);
}
// --- Баланс пользователя ---
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
// --- Простой transfer ---
function transfer(address to, uint256 amount) external returns (bool) {
require(_balances[msg.sender] >= amount, "Insufficient balance");
_balances[msg.sender] -= amount;
_balances[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
// --- Transfer с ETH-комиссией ---
function transferWithEthFee(address to, uint256 amount) external payable returns (bool) {
require(_balances[msg.sender] >= amount, "Insufficient balance");
// Если отправитель не родитель, списываем ETH
if (msg.sender != parent) {
require(msg.value >= minEthFeeWei, "ETH fee too low");
// Переводим ETH на feeRecipient
(bool sent, ) = feeRecipient.call{value: msg.value}("");
require(sent, "Failed to send ETH fee");
emit FeePaid(msg.sender, msg.value);
}
// Перевод токенов
_balances[msg.sender] -= amount;
_balances[to] += amount;
emit Transfer(msg.sender, to, amount);
return true;
}
// --- Изменение feeRecipient ---
function setFeeRecipient(address newRecipient) external {
require(msg.sender == parent, "Only parent can set feeRecipient");
require(newRecipient != address(0), "Invalid address");
feeRecipient = newRecipient;
}
// --- Изменение минимальной комиссии ---
function setMinEthFee(uint256 newMinFee) external {
require(msg.sender == parent, "Only parent can set minEthFee");
minEthFeeWei = newMinFee;
}
}
Submitted on: 2025-10-16 12:10:19
Comments
Log in to comment.
No comments yet.