@@ -45,9 +45,6 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
45
45
/// @notice The codehash for `ClonableBeaconProxy` contract.
46
46
bytes32 public constant cloneableProxyHash = keccak256 (type (ClonableBeaconProxy).creationCode);
47
47
48
- // solhint-disable-next-line var-name-mixedcase
49
- bytes32 private constant _REFERRAL_TYPEHASH = keccak256 ("Referral(address referrer,address owner,uint256 deadline) " );
50
-
51
48
/**
52
49
*
53
50
* Structs *
@@ -151,46 +148,6 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
151
148
*
152
149
*/
153
150
154
- /// @inheritdoc IProfileRegistry
155
- function mint (string calldata username , bytes memory referral ) external payable override returns (address ) {
156
- address receiver = treasury;
157
- address referrer;
158
- uint256 mintFee = MINT_FEE;
159
- if (referral.length > 0 ) {
160
- uint256 deadline;
161
- bytes memory signature;
162
- (receiver, deadline, signature) = abi.decode (referral, (address , uint256 , bytes ));
163
- if (deadline < block .timestamp ) revert ExpiredSignature ();
164
- if (! isProfileMinted[getProfile (receiver)]) {
165
- revert InvalidReferrer ();
166
- }
167
-
168
- bytes32 structHash = keccak256 (abi.encode (_REFERRAL_TYPEHASH, receiver, _msgSender (), deadline));
169
- bytes32 hash = _hashTypedDataV4 (structHash);
170
- address recovered = ECDSAUpgradeable.recover (hash, signature);
171
- if (signer != recovered) revert InvalidSignature ();
172
-
173
- // half mint fee and fee goes to referral
174
- mintFee = MINT_FEE / 2 ;
175
- referrer = receiver;
176
- }
177
- if (msg .value != mintFee) revert MsgValueMismatchWithMintFee ();
178
- Address.sendValue (payable (receiver), mintFee);
179
-
180
- if (isProfileMinted[getProfile (_msgSender ())]) {
181
- revert ProfileAlreadyMinted ();
182
- }
183
-
184
- if (referrer != address (0 )) {
185
- ReferrerData memory cached = referrerData[referrer];
186
- cached.referred += 1 ;
187
- cached.earned += uint128 (mintFee);
188
- referrerData[referrer] = cached;
189
- }
190
-
191
- return _mintProfile (_msgSender (), username, referrer);
192
- }
193
-
194
151
/// @inheritdoc IProfileRegistry
195
152
function registerUsername (string memory username ) external override onlyProfile {
196
153
_validateUsername (username);
@@ -260,7 +217,7 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
260
217
/// @dev Internal function to mint a profile with given account address and username.
261
218
/// @param account The address of user to mint profile.
262
219
/// @param username The username of the profile.
263
- function _mintProfile (address account , string calldata username , address referrer ) private returns (address ) {
220
+ function _mintProfile (address account , string calldata username , address referrer ) internal returns (address ) {
264
221
// deployment will fail and this function will revert if contract `salt` is not unique
265
222
bytes32 salt = keccak256 (abi.encode (account));
266
223
address profile = address (new ClonableBeaconProxy {salt: salt}());
@@ -322,3 +279,59 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
322
279
}
323
280
}
324
281
}
282
+
283
+ contract ProfileRegistryMintable is ProfileRegistry {
284
+ /**
285
+ *
286
+ * Constants *
287
+ *
288
+ */
289
+
290
+ // solhint-disable-next-line var-name-mixedcase
291
+ bytes32 private constant _REFERRAL_TYPEHASH = keccak256 ("Referral(address referrer,address owner,uint256 deadline) " );
292
+
293
+ /**
294
+ *
295
+ * Public Mutating Functions *
296
+ *
297
+ */
298
+
299
+ function mint (string calldata username , bytes memory referral ) external payable returns (address ) {
300
+ address receiver = treasury;
301
+ address referrer;
302
+ uint256 mintFee = MINT_FEE;
303
+ if (referral.length > 0 ) {
304
+ uint256 deadline;
305
+ bytes memory signature;
306
+ (receiver, deadline, signature) = abi.decode (referral, (address , uint256 , bytes ));
307
+ if (deadline < block .timestamp ) revert ExpiredSignature ();
308
+ if (! isProfileMinted[getProfile (receiver)]) {
309
+ revert InvalidReferrer ();
310
+ }
311
+
312
+ bytes32 structHash = keccak256 (abi.encode (_REFERRAL_TYPEHASH, receiver, _msgSender (), deadline));
313
+ bytes32 hash = _hashTypedDataV4 (structHash);
314
+ address recovered = ECDSAUpgradeable.recover (hash, signature);
315
+ if (signer != recovered) revert InvalidSignature ();
316
+
317
+ // half mint fee and fee goes to referral
318
+ mintFee = MINT_FEE / 2 ;
319
+ referrer = receiver;
320
+ }
321
+ if (msg .value != mintFee) revert MsgValueMismatchWithMintFee ();
322
+ Address.sendValue (payable (receiver), mintFee);
323
+
324
+ if (isProfileMinted[getProfile (_msgSender ())]) {
325
+ revert ProfileAlreadyMinted ();
326
+ }
327
+
328
+ if (referrer != address (0 )) {
329
+ ReferrerData memory cached = referrerData[referrer];
330
+ cached.referred += 1 ;
331
+ cached.earned += uint128 (mintFee);
332
+ referrerData[referrer] = cached;
333
+ }
334
+
335
+ return _mintProfile (_msgSender (), username, referrer);
336
+ }
337
+ }
0 commit comments