Skip to content

Commit

Permalink
refactor: MockProfileCreationProxy replicates ProfileCreationProxy ex…
Browse files Browse the repository at this point in the history
…cept for Ownable and suffix
  • Loading branch information
donosonaumczuk committed May 9, 2022
1 parent 853c4c4 commit 5b3c665
Showing 1 changed file with 15 additions and 53 deletions.
68 changes: 15 additions & 53 deletions contracts/mocks/MockProfileCreationProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,31 @@ import {Errors} from '../libraries/Errors.sol';
* @title MockProfileCreationProxy
* @author Lens Protocol
*
* @dev This is a proxy to allow profiles to be created from any address while adding some handle restrictions.
* @notice This is an ownable proxy contract that enforces ".test" handle suffixes at profile creation.
*/
contract MockProfileCreationProxy {
ILensHub immutable LENS_HUB;

address governance;
uint256 requiredMinHandleLengthBeforeSuffix;
string requiredHandleSuffix;
mapping(bytes1 => bool) isCharacterInvalid;

modifier onlyGov() {
if (msg.sender != governance) revert Errors.NotGovernance();
_;
}

constructor(
uint256 minHandleLengthBeforeSuffix,
string memory handleSuffix,
string memory invalidCharacters,
address newGovernance,
address hub
) {
requiredMinHandleLengthBeforeSuffix = minHandleLengthBeforeSuffix;
requiredHandleSuffix = handleSuffix;
for (uint256 i = 0; i < bytes(invalidCharacters).length; ++i) {
isCharacterInvalid[bytes(invalidCharacters)[i]] = true;
}
governance = newGovernance;
LENS_HUB = ILensHub(hub);
constructor(ILensHub hub) {
LENS_HUB = hub;
}

function proxyCreateProfile(DataTypes.CreateProfileData memory vars) external {
uint256 handleLength = bytes(vars.handle).length;
if (handleLength < requiredMinHandleLengthBeforeSuffix) {
revert Errors.HandleLengthInvalid();
}
for (uint256 i = 0; i < handleLength; ++i) {
if (isCharacterInvalid[bytes(vars.handle)[i]]) {
revert Errors.HandleContainsInvalidCharacters();
}
}
if (bytes(requiredHandleSuffix).length > 0) {
vars.handle = string(abi.encodePacked(vars.handle, requiredHandleSuffix));
}
LENS_HUB.createProfile(vars);
}

function setRequiredHandleSuffix(string memory handleSuffix) external onlyGov {
requiredHandleSuffix = handleSuffix;
}
if (handleLength < 5) revert Errors.HandleLengthInvalid();

function setCharacterValidity(bytes1 character, bool isValid) external onlyGov {
isCharacterInvalid[character] = !isValid;
}
bytes1 firstByte = bytes(vars.handle)[0];
if (firstByte == '-' || firstByte == '_' || firstByte == '.')
revert Errors.HandleFirstCharInvalid();

function setRequiredMinHandleLengthBeforeSuffix(uint256 minHandleLengthBeforeSuffix)
external
onlyGov
{
requiredMinHandleLengthBeforeSuffix = minHandleLengthBeforeSuffix;
}
for (uint256 i = 1; i < handleLength; ) {
if (bytes(vars.handle)[i] == '.') revert Errors.HandleContainsInvalidCharacters();
unchecked {
++i;
}
}

function setGovernance(address newGovernance) external onlyGov {
governance = newGovernance;
vars.handle = string(abi.encodePacked(vars.handle, '.test'));
LENS_HUB.createProfile(vars);
}
}

0 comments on commit 5b3c665

Please sign in to comment.