-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathRabbitHoleTickets.sol
227 lines (201 loc) · 8.43 KB
/
RabbitHoleTickets.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;
import {Ownable} from "solady/auth/Ownable.sol";
import {ERC1155} from "solady/tokens/ERC1155.sol";
import {Base64} from "solady/utils/Base64.sol";
import {Initializable} from "openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol";
import {
IERC165Upgradeable,
IERC2981Upgradeable
} from "openzeppelin-contracts-upgradeable/interfaces/IERC2981Upgradeable.sol";
contract RabbitHoleTickets is Initializable, Ownable, ERC1155, IERC2981Upgradeable {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
error OnlyMinter();
event RoyaltyFeeSet(uint256 indexed royaltyFee);
event MinterAddressSet(address indexed minterAddress);
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
address public royaltyRecipient;
address public minterAddress;
uint256 public royaltyFee;
string public imageIPFSCID;
string public animationUrlIPFSCID;
// insert new vars here at the end to keep the storage layout the same
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @custom:oz-upgrades-unsafe-allow constructor
// solhint-disable-next-line func-visibility
constructor() {
_disableInitializers();
}
function initialize(
address royaltyRecipient_,
address minterAddress_,
uint256 royaltyFee_,
address owner_,
string memory imageIPFSCID_,
string memory animationUrlIPFSCID_
) external initializer {
_initializeOwner(owner_);
royaltyRecipient = royaltyRecipient_;
minterAddress = minterAddress_;
royaltyFee = royaltyFee_;
imageIPFSCID = imageIPFSCID_;
animationUrlIPFSCID = animationUrlIPFSCID_;
}
/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
modifier onlyMinter() {
if (msg.sender != minterAddress) revert OnlyMinter();
_;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL UPDATE
//////////////////////////////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////
MINT
//////////////////////////////////////////////////////////////*/
/// @dev mint a single ticket, only callable by the allowed minter
/// @param to_ the address to mint the ticket to
/// @param id_ the id of the ticket to mint
/// @param amount_ the amount of the ticket to mint
/// @param data_ the data to pass to the mint function
function mint(address to_, uint256 id_, uint256 amount_, bytes memory data_) external onlyMinter {
_mint(to_, id_, amount_, data_);
}
/// @dev mint a batch of tickets, only callable by the allowed minter
/// @param to_ the address to mint the tickets to
/// @param ids_ the ids of the tickets to mint
/// @param amounts_ the amounts of the tickets to mint
/// @param data_ the data to pass to the mint function
function mintBatch(
address to_,
uint256[] memory ids_,
uint256[] memory amounts_,
bytes memory data_
) external onlyMinter {
_batchMint(to_, ids_, amounts_, data_);
}
/*//////////////////////////////////////////////////////////////
SET
//////////////////////////////////////////////////////////////*/
/// @dev set the animation url IPFS CID
/// @param animationUrlIPFSCID_ the animation url IPFS CID
function setAnimationUrlIPFSCID(string memory animationUrlIPFSCID_) external onlyOwner {
animationUrlIPFSCID = animationUrlIPFSCID_;
}
/// @dev set the image IPFS CID
/// @param imageIPFSCID_ the image IPFS CID
function setImageIPFSCID(string memory imageIPFSCID_) external onlyOwner {
imageIPFSCID = imageIPFSCID_;
}
/// @dev set the minter address
/// @param minterAddress_ the address of the minter
function setMinterAddress(address minterAddress_) external onlyOwner {
minterAddress = minterAddress_;
emit MinterAddressSet(minterAddress_);
}
/// @dev set the royalty fee
/// @param royaltyFee_ the royalty fee
function setRoyaltyFee(uint256 royaltyFee_) external onlyOwner {
royaltyFee = royaltyFee_;
emit RoyaltyFeeSet(royaltyFee_);
}
/// @dev set the royalty recipient
/// @param royaltyRecipient_ the address of the royalty recipient
function setRoyaltyRecipient(address royaltyRecipient_) external onlyOwner {
royaltyRecipient = royaltyRecipient_;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL VIEW
//////////////////////////////////////////////////////////////*/
/// @dev See {IERC165-royaltyInfo}
/// @param salePrice_ the sale price
function royaltyInfo(
uint256,
uint256 salePrice_
) external view override returns (address receiver, uint256 royaltyAmount) {
uint256 royaltyPayment = (salePrice_ * royaltyFee) / 10_000;
return (royaltyRecipient, royaltyPayment);
}
/// @dev returns true if the supplied interface id is supported
/// @param interfaceId_ the interface id
function supportsInterface(bytes4 interfaceId_)
public
view
virtual
override (ERC1155, IERC165Upgradeable)
returns (bool)
{
return interfaceId_ == type(IERC2981Upgradeable).interfaceId || super.supportsInterface(interfaceId_);
}
/// @dev returns the token uri
function uri(uint256 tokenId_) public view override (ERC1155) returns (string memory) {
bytes memory dataURI = generateDataURI(tokenId_);
return string(abi.encodePacked("data:application/json;base64,", Base64.encode(dataURI)));
}
/*//////////////////////////////////////////////////////////////
INTERNAL VIEW
//////////////////////////////////////////////////////////////*/
/// @dev returns the data uri in json format
function generateDataURI(uint256 tokenId_) internal view virtual returns (bytes memory) {
// solhint-disable quotes
bytes memory dataURI = abi.encodePacked(
"{",
'"name": "',
getNameForToken(tokenId_),
'",',
'"description": "',
getDescriptionForToken(tokenId_),
'",',
'"image": "',
makeIPFSUrl(getImageCidForToken(tokenId_)),
'",',
'"animation_url": "',
makeIPFSUrl(getAnimationCidForToken(tokenId_)),
'"',
"}"
);
// solhint-enable quotes
return dataURI;
}
function getNameForToken(uint256 tokenId_) internal view virtual returns (string memory) {
if(tokenId_ == 2) {
return "2023 RabbitHole Holiday Reward";
} else {
return "RabbitHole Ticket";
}
}
function getDescriptionForToken(uint256 tokenId_) internal view virtual returns (string memory) {
if(tokenId_ == 2) {
return "You unwrapped a Christmas gift from RabbitHole for being a loyal member and completing our 2023 Holiday campaign";
} else {
return "RabbitHole Tickets";
}
}
function getAnimationCidForToken(uint256 tokenId_) internal view virtual returns (string memory) {
if(tokenId_ == 2) {
return "bafybeig7sfklww3qsd2yah4tottv6ewvroad5cqidvxswtdrblzvd7gf64";
} else {
return animationUrlIPFSCID;
}
}
function getImageCidForToken(uint256 tokenId_) internal view virtual returns (string memory) {
if(tokenId_ == 2) {
return "bafybeigoo4rnwlmeyyq2rgcteqb3srxaida24jpiedxsoqa7cvpbjhnzni";
} else {
return imageIPFSCID;
}
}
function makeIPFSUrl(string memory ipfsCid_) internal view virtual returns (string memory) {
if (bytes(ipfsCid_).length == 0) {
return "";
}
return string(abi.encodePacked("ipfs://", ipfsCid_));
}
}