Skip to content

Instantly share code, notes, and snippets.

@wangshouh
Last active July 16, 2022 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangshouh/dc3a0f9b4a1bdd522aa6d38f133a3417 to your computer and use it in GitHub Desktop.
Save wangshouh/dc3a0f9b4a1bdd522aa6d38f133a3417 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "solmate/tokens/ERC20.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
error NoPayMintPrice();
error WithdrawTransfer();
error MaxSupply();
contract SDUFECoin is ERC20, Ownable {
uint256 public constant MINT_PRICE = 0.00000001 ether;
uint256 public constant MAX_SUPPLY = 1_000_000;
constructor (
string memory _name,
string memory _symbol,
uint8 _decimals
) ERC20 (_name, _symbol, _decimals) {}
function mintTo(address recipient) public payable {
if (msg.value < MINT_PRICE) {
revert NoPayMintPrice();
} else {
uint256 amount = msg.value / MINT_PRICE;
uint256 nowAmount = totalSupply + amount;
if (nowAmount <= MAX_SUPPLY) {
_mint(recipient, amount);
} else {
revert MaxSupply();
}
}
}
function withdrawPayments(address payable payee) external onlyOwner {
uint256 balance = address(this).balance;
(bool transferTx, ) = payee.call{value: balance}("");
if (!transferTx) {
revert WithdrawTransfer();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment