-
Notifications
You must be signed in to change notification settings - Fork 2
/
HelpAFrenVoteToken.sol
96 lines (80 loc) · 3.43 KB
/
HelpAFrenVoteToken.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Votes.sol";
contract HelpAFrenVoteToken is ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Burnable, AccessControl, EIP712, ERC721Votes {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
// uint256 private _nextTokenId;
// map the address to the token id
mapping(address => uint256) public tokenIds;
constructor(address defaultAdmin, address minter)
ERC721("HelpAFrenToken", "HAF")
EIP712("HelpAFrenToken", "1")
{
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_grantRole(MINTER_ROLE, minter);
}
function safeMint(address to, string memory uri, uint256 tokenId) public onlyRole(MINTER_ROLE) {
// require tokenID to not already exist
require(tokenIds[to] != tokenId, "Not authorized, proposal already has been voted on by address");
// // require to address to not already have a token
// require(balanceOf(to) == 0, "Address already has a voting token");
// uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
}
function tokensByOwner(address owner) public view returns (uint256[] memory) {
uint256 tokenCount = balanceOf(owner);
uint256[] memory result = new uint256[](tokenCount);
for (uint256 i = 0; i < tokenCount; i++) {
result[i] = tokenOfOwnerByIndex(owner, i);
}
return result;
}
// Allow Admin or Minter to burn token
function burn(uint256 tokenId) public override {
require(ownerOf(tokenId) == msg.sender || hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Caller is not owner nor admin");
super.burn(tokenId);
}
// Do not allow transfer of tokens
function transferFrom(address from, address to, uint256 tokenId) public override(ERC721, IERC721) {
// Make token soulbound only allowing to mint and burn token
require(from == address(0) || to == address(0), "Transferring token is not allowed");
_update(to, tokenId, msg.sender);
}
// The following functions are overrides required by Solidity.
function _update(address to, uint256 tokenId, address auth)
internal
override(ERC721, ERC721Enumerable, ERC721Votes)
returns (address)
{
return super._update(to, tokenId, auth);
}
function _increaseBalance(address account, uint128 value)
internal
override(ERC721, ERC721Enumerable, ERC721Votes)
{
super._increaseBalance(account, value);
}
function tokenURI(uint256 tokenId)
public
view
override(ERC721, ERC721URIStorage)
returns (string memory)
{
return super.tokenURI(tokenId);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC721, ERC721Enumerable, ERC721URIStorage, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
}