Skip to content

Commit

Permalink
feat(protocol): tokens can only mint once (#13252)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Mar 4, 2023
1 parent 9732cc0 commit 72d152b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/protocol/contracts/test/erc20/FreeMintERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// An ERC20 Token with a mint function anyone can call, for free, to receive
// 5 tokens.
contract FreeMintERC20 is ERC20 {
error HasMinted();

mapping(address minter => bool hasMinted) public minters;

constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

function mint(address to) public {
_mint(to, 5 * (10 ** decimals()));
if (minters[msg.sender]) {
revert HasMinted();
}

minters[msg.sender] = true;
_mint(to, 50 * (10 ** decimals()));
}
}
11 changes: 10 additions & 1 deletion packages/protocol/contracts/test/erc20/MayFailFreeMintERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// This token has 50% of failure on transfers so we can
// test the bridge's error handling.
contract MayFailFreeMintERC20 is ERC20 {
error HasMinted();

mapping(address minter => bool hasMinted) public minters;

constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

function mint(address to) public {
_mint(to, 5 * (10 ** decimals()));
if (minters[msg.sender]) {
revert HasMinted();
}

minters[msg.sender] = true;
_mint(to, 50 * (10 ** decimals()));
}

function transfer(
Expand Down

0 comments on commit 72d152b

Please sign in to comment.