Last active
July 16, 2022 03:33
-
-
Save wangshouh/dc3a0f9b4a1bdd522aa6d38f133a3417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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