-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPrivateSoulMinter.sol
120 lines (95 loc) · 3.83 KB
/
PrivateSoulMinter.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
// Credit to @Miguel Piedrafita for the SoulBound NFT contract skeleton
import "@openzeppelin/contracts/access/Ownable.sol";
/// @title PrivateSoulMinter
/// @author Enrico Bottazzi
/// @notice Barebones contract to mint ZK SBT
contract PrivateSoulMinter is Ownable{
/// @notice Thrown when trying to transfer a Soulbound token
error Soulbound();
/// @notice Emitted when minting a ZK SBT
/// @param from Who the token comes from. Will always be address(0)
/// @param to The token recipient
/// @param id The ID of the minted token
event Transfer(
address indexed from,
address indexed to,
uint256 indexed id
);
/// @notice The symbol for the token
string public constant symbol = "SOUL";
/// @notice The name for the token
string public constant name = "Soulbound NFT";
/// @notice Get the metadata URI for a certain tokenID
mapping(uint256 => string) public tokenURI;
/// @notice Get the hash of the claim metadata for a certain tokenID
mapping(uint256 => bytes32) public claimSignatureHash;
/// @notice Get the owner of a certain tokenID
mapping(uint256 => address) public ownerOf;
/// @notice Get how many SoulMinter NFTs a certain user owns
mapping(address => uint256) public balanceOf;
/// @dev Counter for the next tokenID, defaults to 1 for better gas on first mint
uint256 internal nextTokenId = 1;
constructor() payable {}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function approve(address, uint256) public virtual {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function isApprovedForAll(address, address) public pure {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function getApproved(uint256) public pure {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function setApprovalForAll(address, bool) public virtual {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function transferFrom(
address,
address,
uint256
) public virtual {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function safeTransferFrom(
address,
address,
uint256
) public virtual {
revert Soulbound();
}
/// @notice This function was disabled to make the token Soulbound. Calling it will revert
function safeTransferFrom(
address,
address,
uint256,
bytes calldata
) public virtual {
revert Soulbound();
}
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
return
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721
interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
}
/// @notice Mint a new Soulbound NFT to `to`
/// @param to The recipient of the NFT
/// @param metaURI The URL to the token metadata
function mint(address to, string calldata metaURI, bytes32 claimHashMetadata) public onlyOwner {
require(balanceOf[to] < 1, "You can only have one token associated to your soul");
unchecked {
balanceOf[to]++;
}
ownerOf[nextTokenId] = to;
tokenURI[nextTokenId] = metaURI;
claimSignatureHash[nextTokenId] = claimHashMetadata;
emit Transfer(address(0), to, nextTokenId++);
}
}