2025-07-30 08:51:26 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
pragma solidity >=0.8.19 <0.9.0;
|
|
|
|
|
|
|
|
|
|
import { BaseScript } from "../script/Base.s.sol";
|
2025-08-26 17:34:32 +02:00
|
|
|
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
|
|
|
|
|
import { ERC20PermitUpgradeable } from
|
|
|
|
|
"@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
|
|
|
|
|
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
|
|
|
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
|
|
|
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
2025-09-25 09:56:36 +02:00
|
|
|
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
2025-07-30 08:51:26 +02:00
|
|
|
|
2025-08-07 10:17:04 +02:00
|
|
|
error AccountNotMinter();
|
|
|
|
|
error AccountAlreadyMinter();
|
|
|
|
|
error AccountNotInMinterList();
|
2025-09-11 10:45:43 +02:00
|
|
|
error InsufficientETH();
|
|
|
|
|
error ExceedsMaxSupply();
|
2025-09-25 09:56:36 +02:00
|
|
|
error InvalidMaxSupply(uint256 supplied);
|
2025-08-07 10:17:04 +02:00
|
|
|
|
2025-08-26 17:34:32 +02:00
|
|
|
contract TestStableToken is
|
|
|
|
|
Initializable,
|
|
|
|
|
ERC20Upgradeable,
|
|
|
|
|
ERC20PermitUpgradeable,
|
|
|
|
|
OwnableUpgradeable,
|
|
|
|
|
UUPSUpgradeable
|
|
|
|
|
{
|
2025-08-07 10:17:04 +02:00
|
|
|
mapping(address => bool) public isMinter;
|
2025-09-11 10:45:43 +02:00
|
|
|
uint256 public maxSupply;
|
2025-08-07 10:17:04 +02:00
|
|
|
|
|
|
|
|
event MinterAdded(address indexed account);
|
|
|
|
|
event MinterRemoved(address indexed account);
|
2025-09-11 10:45:43 +02:00
|
|
|
event ETHBurned(uint256 amount, address indexed minter, address indexed to, uint256 tokensMinted);
|
|
|
|
|
event MaxSupplySet(uint256 oldMaxSupply, uint256 newMaxSupply);
|
2025-08-07 10:17:04 +02:00
|
|
|
|
|
|
|
|
modifier onlyOwnerOrMinter() {
|
2025-09-15 14:03:03 +02:00
|
|
|
if (msg.sender != owner() && !isMinter[msg.sender]) revert("AccountNotMinter");
|
2025-08-07 10:17:04 +02:00
|
|
|
_;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-26 17:34:32 +02:00
|
|
|
constructor() {
|
|
|
|
|
_disableInitializers();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-11 10:45:43 +02:00
|
|
|
function initialize(uint256 _maxSupply) public initializer {
|
2025-08-26 17:34:32 +02:00
|
|
|
__ERC20_init("TestStableToken", "TST");
|
|
|
|
|
__ERC20Permit_init("TestStableToken");
|
|
|
|
|
__Ownable_init();
|
|
|
|
|
__UUPSUpgradeable_init();
|
2025-09-25 09:56:36 +02:00
|
|
|
if (_maxSupply == 0) revert InvalidMaxSupply(_maxSupply);
|
2025-09-11 10:45:43 +02:00
|
|
|
|
|
|
|
|
maxSupply = _maxSupply;
|
2025-08-26 17:34:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _authorizeUpgrade(address newImplementation) internal override onlyOwner { }
|
2025-07-30 08:51:26 +02:00
|
|
|
|
2025-08-07 10:17:04 +02:00
|
|
|
function addMinter(address account) external onlyOwner {
|
|
|
|
|
if (isMinter[account]) revert AccountAlreadyMinter();
|
|
|
|
|
isMinter[account] = true;
|
|
|
|
|
emit MinterAdded(account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function removeMinter(address account) external onlyOwner {
|
|
|
|
|
if (!isMinter[account]) revert AccountNotInMinterList();
|
|
|
|
|
isMinter[account] = false;
|
|
|
|
|
emit MinterRemoved(account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function mint(address to, uint256 amount) external onlyOwnerOrMinter {
|
2025-09-11 10:45:43 +02:00
|
|
|
if (totalSupply() + amount > maxSupply) revert ExceedsMaxSupply();
|
2025-07-30 08:51:26 +02:00
|
|
|
_mint(to, amount);
|
|
|
|
|
}
|
2025-09-11 10:45:43 +02:00
|
|
|
|
|
|
|
|
function mintWithETH(address to) external payable {
|
|
|
|
|
if (msg.value == 0) revert InsufficientETH();
|
|
|
|
|
if (totalSupply() + msg.value > maxSupply) revert ExceedsMaxSupply();
|
|
|
|
|
|
|
|
|
|
// Burn ETH by sending to zero address
|
|
|
|
|
payable(address(0)).transfer(msg.value);
|
|
|
|
|
|
|
|
|
|
_mint(to, msg.value);
|
|
|
|
|
|
|
|
|
|
emit ETHBurned(msg.value, msg.sender, to, msg.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setMaxSupply(uint256 _maxSupply) external onlyOwner {
|
|
|
|
|
if (_maxSupply < totalSupply()) revert ExceedsMaxSupply();
|
|
|
|
|
|
|
|
|
|
uint256 oldMaxSupply = maxSupply;
|
|
|
|
|
maxSupply = _maxSupply;
|
|
|
|
|
|
|
|
|
|
emit MaxSupplySet(oldMaxSupply, _maxSupply);
|
|
|
|
|
}
|
2025-07-30 08:51:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contract TestStableTokenFactory is BaseScript {
|
|
|
|
|
function run() public broadcast returns (address) {
|
|
|
|
|
return address(new TestStableToken());
|
|
|
|
|
}
|
|
|
|
|
}
|