-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathCarToken.sol
53 lines (46 loc) · 1.54 KB
/
CarToken.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-contracts/contracts/access/Ownable.sol";
/**
* @title CarToken contract
* @dev This is the implementation of the CarToken contract
* @notice There is a capped supply of 210,000 tokens.
* 10,000 tokens is reserved for the public
* A user can only mint once
*/
contract CarToken is ERC20, Ownable {
// ---- States ----
mapping(address => bool) hasMinted;
uint256 private constant MAX_SUPPLY = 210000 * 1e18;
uint256 public count;
/**
* @dev Car Company Contract Constructor.
*/
constructor() ERC20("Car Company", "CCY") Ownable(msg.sender) {}
/**
* @dev Checks to see if the user has minted previously.
*/
modifier hasNotMinted() {
require(!hasMinted[msg.sender], "Can only mint once");
_;
}
/**
* @dev Mint new tokens
*/
function mint() external hasNotMinted {
require(totalSupply() < MAX_SUPPLY, "Max Supply Reached");
hasMinted[msg.sender] = true;
_mint(msg.sender, 1 ether);
}
/**
* @dev Allows only the owner to mint new tokens
* @param _to Address to mint tokens to
* @param _amount The amount of tokens to mint to address
*/
function priviledgedMint(address _to, uint256 _amount) external onlyOwner hasNotMinted {
require(_amount + totalSupply() <= MAX_SUPPLY, "Max Supply Reached");
hasMinted[_to] = true;
_mint(_to, _amount);
}
}