Skip to content

Commit

Permalink
feat: First implementation of a profile creation proxy with a whitelist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zer0dot committed May 6, 2022
1 parent 1456844 commit 63c2054
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ library Errors {
error HandleTaken();
error HandleLengthInvalid();
error HandleContainsInvalidCharacters();
error HandleFirstCharInvalid();
error ProfileImageURILengthInvalid();
error CallerNotFollowNFT();
error CallerNotCollectNFT();
error BlockNumberInvalid();
error ArrayMismatch();
error CannotCommentOnSelf();
error NotWhitelisted();

// Module Errors
error InitParamsInvalid();
Expand Down
51 changes: 51 additions & 0 deletions contracts/misc/ProfileCreationProxy.sol
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);
}
}

0 comments on commit 63c2054

Please sign in to comment.