Skip to content

Commit 5e4872e

Browse files
authored
feat: remove ProfileRegistry mint (#59)
1 parent d202680 commit 5e4872e

File tree

5 files changed

+69
-62
lines changed

5 files changed

+69
-62
lines changed

src/interfaces/IProfileRegistry.sol

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ interface IProfileRegistry {
7272
*
7373
*/
7474

75-
/// @notice Mint a profile for caller with given username.
76-
/// @param username The username of the profile.
77-
/// @param referral The referral data.
78-
/// @return The address of minted profile.
79-
function mint(string calldata username, bytes calldata referral) external payable returns (address);
80-
8175
/// @notice Register an username.
8276
/// @param username The username to register.
8377
function registerUsername(string memory username) external;

src/profile/ProfileRegistry.sol

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
4545
/// @notice The codehash for `ClonableBeaconProxy` contract.
4646
bytes32 public constant cloneableProxyHash = keccak256(type(ClonableBeaconProxy).creationCode);
4747

48-
// solhint-disable-next-line var-name-mixedcase
49-
bytes32 private constant _REFERRAL_TYPEHASH = keccak256("Referral(address referrer,address owner,uint256 deadline)");
50-
5148
/**
5249
*
5350
* Structs *
@@ -151,46 +148,6 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
151148
*
152149
*/
153150

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-
194151
/// @inheritdoc IProfileRegistry
195152
function registerUsername(string memory username) external override onlyProfile {
196153
_validateUsername(username);
@@ -260,7 +217,7 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
260217
/// @dev Internal function to mint a profile with given account address and username.
261218
/// @param account The address of user to mint profile.
262219
/// @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) {
264221
// deployment will fail and this function will revert if contract `salt` is not unique
265222
bytes32 salt = keccak256(abi.encode(account));
266223
address profile = address(new ClonableBeaconProxy{salt: salt}());
@@ -322,3 +279,59 @@ contract ProfileRegistry is OwnableUpgradeable, EIP712Upgradeable, IBeacon, IPro
322279
}
323280
}
324281
}
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+
}

test/Profile.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525

2626
import {EmptyContract} from "../src/misc/EmptyContract.sol";
2727
import {Profile} from "../src/profile/Profile.sol";
28-
import {ProfileRegistry} from "../src/profile/ProfileRegistry.sol";
28+
import {ProfileRegistryMintable} from "../src/profile/ProfileRegistry.sol";
2929
import {ScrollBadge} from "../src/badge/ScrollBadge.sol";
3030
import {ScrollBadgeResolver} from "../src/resolver/ScrollBadgeResolver.sol";
3131

@@ -75,7 +75,7 @@ contract ProfileRegistryTest is Test {
7575
ScrollBadge private badge;
7676

7777
Profile private profileImpl;
78-
ProfileRegistry private profileRegistry;
78+
ProfileRegistryMintable private profileRegistry;
7979
Profile private profile;
8080

8181
receive() external payable {}
@@ -95,10 +95,10 @@ contract ProfileRegistryTest is Test {
9595
resolver.toggleBadge(address(badge), true);
9696

9797
profileImpl = new Profile(address(resolver));
98-
ProfileRegistry profileRegistryImpl = new ProfileRegistry();
98+
ProfileRegistryMintable profileRegistryImpl = new ProfileRegistryMintable();
9999
vm.prank(PROXY_ADMIN_ADDRESS);
100100
ITransparentUpgradeableProxy(profileRegistryProxy).upgradeTo(address(profileRegistryImpl));
101-
profileRegistry = ProfileRegistry(profileRegistryProxy);
101+
profileRegistry = ProfileRegistryMintable(profileRegistryProxy);
102102
profileRegistry.initialize(TREASURY_ADDRESS, TREASURY_ADDRESS, address(profileImpl));
103103
profile = Profile(profileRegistry.mint{value: 0.001 ether}("xxxxx", new bytes(0)));
104104
}

test/ProfileRegistry.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515

1616
import {EmptyContract} from "../src/misc/EmptyContract.sol";
1717
import {Profile} from "../src/profile/Profile.sol";
18-
import {ProfileRegistry} from "../src/profile/ProfileRegistry.sol";
18+
import {ProfileRegistryMintable} from "../src/profile/ProfileRegistry.sol";
1919
import {ScrollBadgeResolver} from "../src/resolver/ScrollBadgeResolver.sol";
2020

2121
contract ProfileRegistryTest is Test {
@@ -40,7 +40,7 @@ contract ProfileRegistryTest is Test {
4040
VmSafe.Wallet private signer;
4141

4242
Profile private profileImpl;
43-
ProfileRegistry private profileRegistry;
43+
ProfileRegistryMintable private profileRegistry;
4444

4545
receive() external payable {}
4646

@@ -58,10 +58,10 @@ contract ProfileRegistryTest is Test {
5858
signer = vm.createWallet(10_001);
5959

6060
profileImpl = new Profile(address(resolver));
61-
ProfileRegistry profileRegistryImpl = new ProfileRegistry();
61+
ProfileRegistryMintable profileRegistryImpl = new ProfileRegistryMintable();
6262
vm.prank(PROXY_ADMIN_ADDRESS);
6363
ITransparentUpgradeableProxy(profileRegistryProxy).upgradeTo(address(profileRegistryImpl));
64-
profileRegistry = ProfileRegistry(profileRegistryProxy);
64+
profileRegistry = ProfileRegistryMintable(profileRegistryProxy);
6565
profileRegistry.initialize(TREASURY_ADDRESS, signer.addr, address(profileImpl));
6666
vm.warp(1_000_000);
6767
}

test/SCRHoldingBadge.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {ITransparentUpgradeableProxy, TransparentUpgradeableProxy} from "@openze
1616

1717
import {EmptyContract} from "../src/misc/EmptyContract.sol";
1818
import {Profile} from "../src/profile/Profile.sol";
19-
import {ProfileRegistry} from "../src/profile/ProfileRegistry.sol";
19+
import {ProfileRegistryMintable} from "../src/profile/ProfileRegistry.sol";
2020
import {ScrollBadge} from "../src/badge/ScrollBadge.sol";
2121
import {ScrollBadgeResolver} from "../src/resolver/ScrollBadgeResolver.sol";
2222
import {SCRHoldingBadge} from "../src/badge/examples/SCRHoldingBadge.sol";
@@ -42,7 +42,7 @@ contract SCRHoldingBadgeTest is Test {
4242
Token private token;
4343

4444
Profile private profileImpl;
45-
ProfileRegistry private profileRegistry;
45+
ProfileRegistryMintable private profileRegistry;
4646
Profile private profile;
4747

4848
receive() external payable {}
@@ -64,10 +64,10 @@ contract SCRHoldingBadgeTest is Test {
6464
resolver.updateSelfAttestedBadge(0, address(badge));
6565

6666
profileImpl = new Profile(address(resolver));
67-
ProfileRegistry profileRegistryImpl = new ProfileRegistry();
67+
ProfileRegistryMintable profileRegistryImpl = new ProfileRegistryMintable();
6868
vm.prank(PROXY_ADMIN_ADDRESS);
6969
ITransparentUpgradeableProxy(profileRegistryProxy).upgradeTo(address(profileRegistryImpl));
70-
profileRegistry = ProfileRegistry(profileRegistryProxy);
70+
profileRegistry = ProfileRegistryMintable(profileRegistryProxy);
7171
profileRegistry.initialize(TREASURY_ADDRESS, TREASURY_ADDRESS, address(profileImpl));
7272
profile = Profile(profileRegistry.mint{value: 0.001 ether}("xxxxx", new bytes(0)));
7373
}

0 commit comments

Comments
 (0)