forked from lens-protocol/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: First implementation of a profile creation proxy with a whitelist.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
pragma solidity 0.8.10; | ||
|
||
import {ILensHub} from '../interfaces/ILensHub.sol'; | ||
import {DataTypes} from '../libraries/DataTypes.sol'; | ||
import {Errors} from '../libraries/Errors.sol'; | ||
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol'; | ||
|
||
/** | ||
* @title ProfileCreationProxy | ||
* @author Lens Protocol | ||
* | ||
* @notice This is an ownable proxy contract that enforces ".lens" handle suffixes at profile creation. | ||
* Only the owner can create profiles. | ||
*/ | ||
contract ProfileCreationProxy is Ownable { | ||
ILensHub immutable LENS_HUB; | ||
|
||
mapping(address => bool) internal _whitelisted; | ||
|
||
modifier onlyWhitelisted() { | ||
if (!_whitelisted[msg.sender]) revert Errors.NotWhitelisted(); | ||
_; | ||
} | ||
|
||
constructor(address owner, ILensHub hub) { | ||
_transferOwnership(owner); | ||
LENS_HUB = hub; | ||
} | ||
|
||
function whitelist(address creator, bool toWhitelist) external onlyOwner { | ||
_whitelisted[creator] = toWhitelist; | ||
} | ||
|
||
function proxyCreateProfile(DataTypes.CreateProfileData memory vars) external onlyWhitelisted { | ||
uint256 handleLength = bytes(vars.handle).length; | ||
if (handleLength < 5) revert Errors.HandleLengthInvalid(); | ||
bytes1 firstByte = bytes(vars.handle)[0]; | ||
if (firstByte == '-' || firstByte == '_' || firstByte == '.') | ||
revert Errors.HandleFirstCharInvalid(); | ||
for (uint256 i = 1; i < handleLength; ) { | ||
if (bytes(vars.handle)[i] == '.') revert Errors.HandleContainsInvalidCharacters(); | ||
unchecked { | ||
++i; | ||
} | ||
} | ||
vars.handle = string(abi.encodePacked(vars.handle, '.lens')); | ||
LENS_HUB.createProfile(vars); | ||
} | ||
} |