-
Notifications
You must be signed in to change notification settings - Fork 3
/
CollectionMinter.sol
207 lines (182 loc) · 8.62 KB
/
CollectionMinter.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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.18 <=0.8.24;
import {CollectionHelpers, CreateCollectionData, CollectionMode, CollectionLimitValue, CollectionLimitField, CollectionNestingAndPermission, Property, TokenPropertyPermission, PropertyPermission, TokenPermissionField} from "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
import "./UniquePrecompiles.sol";
struct DefaultTokenPropertyPermission {
bool isMutable;
bool collectionAdmin;
bool tokenOwner;
}
/**
* @title CollectionMinter
* @dev Abstract contract for minting collections in the Unique V2 Schema.
*/
abstract contract CollectionMinter is UniquePrecompiles {
DefaultTokenPropertyPermission private s_defaultTokenPropertyPermissions;
/**
* @dev Initializes the contract with default property permissions.
* @param _mutable Boolean indicating if properties are mutable by default.
* @param _tokenOwner Boolean indicating if the token owner has permissions by default.
* @param _admin Boolean indicating if the collection admin has permissions by default.
*/
constructor(bool _mutable, bool _admin, bool _tokenOwner) {
s_defaultTokenPropertyPermissions = DefaultTokenPropertyPermission(_mutable, _admin, _tokenOwner);
}
/**
* @dev Function to create a new collection with default settings.
*
* @param _name The name of the collection to be created.
* @param _description A brief description of the collection.
* @param _symbol The symbol prefix that will be used for the tokens in this collection.
* @param _collectionCover A URL pointing to the cover image of the collection.
*
* @return address The address of the newly created collection.
*/
function _createCollection(
string memory _name,
string memory _description,
string memory _symbol,
string memory _collectionCover
) internal returns (address) {
return
_createCollection(
_name,
_description,
_symbol,
_collectionCover,
CollectionNestingAndPermission({
token_owner: true,
collection_admin: true,
restricted: new address[](0)
}),
new CollectionLimitValue[](0),
new Property[](0),
new TokenPropertyPermission[](0)
);
}
/**
* @dev Function to create a new collection.
* @param _name Name of the collection.
* @param _description Description of the collection.
* @param _symbol Symbol prefix for the tokens in the collection.
* @param _collectionCover URL of the cover image for the collection.
* @param _customCollectionProperties Array of custom properties for the collection.
* @param _customTokenPropertyPermissions Array of custom token property permissions.
* @return Address of the created collection.
*/
function _createCollection(
string memory _name,
string memory _description,
string memory _symbol,
string memory _collectionCover,
CollectionNestingAndPermission memory nesting_settings,
CollectionLimitValue[] memory _limits,
Property[] memory _customCollectionProperties,
TokenPropertyPermission[] memory _customTokenPropertyPermissions
) internal returns (address) {
CreateCollectionData memory data;
data.name = _name;
data.description = _description;
data.mode = CollectionMode.Nonfungible;
data.token_prefix = _symbol;
data.limits = _limits;
data.nesting_settings = nesting_settings;
DefaultTokenPropertyPermission memory defaultTPPs = s_defaultTokenPropertyPermissions;
data.token_property_permissions = _withUniqueV2TokenPropertyPermissions(
_customTokenPropertyPermissions,
defaultTPPs.isMutable,
defaultTPPs.collectionAdmin,
defaultTPPs.tokenOwner
);
data.properties = _withUniqueV2CollectionProperties(_customCollectionProperties, _collectionCover);
address collection = COLLECTION_HELPERS.createCollection{value: COLLECTION_HELPERS.collectionCreationFee()}(
data
);
return collection;
}
/**
* @dev Extends default token property permissions with custom permissions.
* @param _customTPPs Array of custom Token Property Permissions.
* @return Array of extended Token Property Permissions.
*/
function _withUniqueV2TokenPropertyPermissions(
TokenPropertyPermission[] memory _customTPPs,
bool _defaultMutable,
bool _defaultCollectionAdmin,
bool _defaultTokenOwner
) private pure returns (TokenPropertyPermission[] memory) {
uint256 tppLength = _customTPPs.length + 8;
TokenPropertyPermission[] memory extendedTPPs = new TokenPropertyPermission[](tppLength);
PropertyPermission[] memory defaultTPP = _getDefaultTokenPropertyPermission(
_defaultMutable,
_defaultTokenOwner,
_defaultCollectionAdmin
);
// Add unique-v2 metadata attributes
extendedTPPs[0] = TokenPropertyPermission({key: "URI", permissions: defaultTPP});
extendedTPPs[1] = TokenPropertyPermission({key: "URISuffix", permissions: defaultTPP});
extendedTPPs[2] = TokenPropertyPermission({key: "customizing_overrides", permissions: defaultTPP});
extendedTPPs[3] = TokenPropertyPermission({key: "overrides", permissions: defaultTPP});
extendedTPPs[4] = TokenPropertyPermission({key: "royalties", permissions: defaultTPP});
extendedTPPs[5] = TokenPropertyPermission({key: "schemaName", permissions: defaultTPP});
extendedTPPs[6] = TokenPropertyPermission({key: "schemaVersion", permissions: defaultTPP});
extendedTPPs[7] = TokenPropertyPermission({key: "tokenData", permissions: defaultTPP});
// Add custom tokenPropertyPermissions
for (uint256 i = 0; i < _customTPPs.length; i++) {
extendedTPPs[8 + i] = _customTPPs[i];
}
return extendedTPPs;
}
/**
* @dev Constructs collection properties with Unique Schema 2.0 specifications.
* @param coverImage URL of the cover image.
* @param customCollectionProperties Array of custom collection properties.
* @return Array of collection properties including Unique Schema 2.0 specifications.
*/
function _withUniqueV2CollectionProperties(
Property[] memory customCollectionProperties,
string memory coverImage
) private pure returns (Property[] memory) {
uint256 totalPropertiesLength = customCollectionProperties.length + 3;
Property[] memory propertiesV2 = new Property[](totalPropertiesLength);
// Set properties related to Unique Schema 2.0
propertiesV2[0] = Property({key: "schemaName", value: "unique"});
propertiesV2[1] = Property({key: "schemaVersion", value: "2.0.0"});
string memory collectionInfo = string(
abi.encodePacked('{"schemaName":"unique","schemaVersion":"2.0.0","cover_image":{"url":"', coverImage, '"}}')
);
propertiesV2[2] = Property({key: "collectionInfo", value: bytes(collectionInfo)});
// Set custom collection properties
for (uint256 i = 0; i < customCollectionProperties.length; i++) {
propertiesV2[3 + i] = customCollectionProperties[i];
}
return propertiesV2;
}
/**
* @dev Generates default token property permissions.
* @param _defaultMutable Whether properties are mutable by default.
* @param _defaultCollectionAdmin Whether the collection admin has permissions by default.
* @param _defaultTokenOwner Whether the token owner has permissions by default.
* @return Array of default PropertyPermissions.
*/
function _getDefaultTokenPropertyPermission(
bool _defaultMutable,
bool _defaultCollectionAdmin,
bool _defaultTokenOwner
) private pure returns (PropertyPermission[] memory) {
PropertyPermission[] memory defaultPropertyPermissions = new PropertyPermission[](3);
defaultPropertyPermissions[0] = PropertyPermission({
code: TokenPermissionField.Mutable,
value: _defaultMutable
});
defaultPropertyPermissions[1] = PropertyPermission({
code: TokenPermissionField.TokenOwner,
value: _defaultCollectionAdmin
});
defaultPropertyPermissions[2] = PropertyPermission({
code: TokenPermissionField.CollectionAdmin,
value: _defaultTokenOwner
});
return defaultPropertyPermissions;
}
}