Skip to content

Commit

Permalink
Move _mint outside of constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
aviggiano committed Sep 25, 2024
1 parent 20ed8e1 commit 312fa78
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/ERC20OpenZeppelin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract ERC20OpenZeppelin is ERC20 {
uint8 private immutable decimals_ = 18;

constructor(string memory _name, string memory _symbol, uint8 _decimals, address owner, uint256 supply)
ERC20(_name, _symbol)
{
constructor(string memory _name, string memory _symbol, uint8 _decimals) ERC20(_name, _symbol) {
decimals_ = _decimals;
_mint(owner, supply);
}

function mint(address to, uint256 amount) public {
_mint(to, amount);
}

function burn(address from, uint256 amount) public {
_burn(from, amount);
}

function decimals() public pure override returns (uint8) {
Expand Down
10 changes: 8 additions & 2 deletions src/ERC20Solady.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ contract ERC20Solady is ERC20 {
string internal symbol_;
uint8 internal decimals_;

constructor(string memory _name, string memory _symbol, uint8 _decimals, address owner, uint256 supply) {
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name_ = _name;
symbol_ = _symbol;
decimals_ = _decimals;
}

function mint(address to, uint256 amount) public {
_mint(to, amount);
}

_mint(owner, supply);
function burn(address from, uint256 amount) public {
_burn(from, amount);
}

function name() public view virtual override returns (string memory) {
Expand Down
12 changes: 8 additions & 4 deletions src/ERC20Solmate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ pragma solidity ^0.8.13;
import {ERC20} from "@solmate/tokens/ERC20.sol";

contract ERC20Solmate is ERC20 {
constructor(string memory _name, string memory _symbol, uint8 _decimals, address owner, uint256 supply)
ERC20(_name, _symbol, _decimals)
{
_mint(owner, supply);
constructor(string memory _name, string memory _symbol, uint8 _decimals) ERC20(_name, _symbol, _decimals) {}

function mint(address to, uint256 amount) public {
_mint(to, amount);
}

function burn(address from, uint256 amount) public {
_burn(from, amount);
}

function permit(address, address, uint256, uint256, uint8, bytes32, bytes32) public virtual override {
Expand Down
11 changes: 7 additions & 4 deletions test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {IERC20} from "forge-std/interfaces/IERC20.sol";
import {ERC20OpenZeppelin} from "@src/ERC20OpenZeppelin.sol";
import {ERC20Solady} from "@src/ERC20Solady.sol";
import {ERC20Solmate} from "@src/ERC20Solmate.sol";
import {MockERC20} from "@solmate/test/utils/mocks/MockERC20.sol";

/// @custom:halmos --storage-layout=generic --array-lengths senders=3 --array-lengths calls=3 --array-lengths staticcalls=3 --loop 256
contract ERC20Test is Test, SymTest {
Expand All @@ -18,17 +19,19 @@ contract ERC20Test is Test, SymTest {
bytes4[] callSelectors;

function setUp() public {
openzeppelin = new ERC20OpenZeppelin("Token", "TOK", 6, address(0x1337), 123e18);
solady = new ERC20Solady("Token", "TOK", 6, address(0x1337), 123e18);
solmate = new ERC20Solmate("Token", "TOK", 6, address(0x1337), 123e18);
openzeppelin = new ERC20OpenZeppelin("Token", "TOK", 6);
solady = new ERC20Solady("Token", "TOK", 6);
solmate = new ERC20Solmate("Token", "TOK", 6);

staticcallSelectors = [
IERC20.balanceOf.selector,
IERC20.allowance.selector,
IERC20.name.selector,
IERC20.symbol.selector,
IERC20.decimals.selector,
IERC20.totalSupply.selector
IERC20.totalSupply.selector,
MockERC20.burn.selector,
MockERC20.mint.selector
];

callSelectors = [IERC20.transfer.selector, IERC20.approve.selector, IERC20.transferFrom.selector];
Expand Down

0 comments on commit 312fa78

Please sign in to comment.