fix: Shrinking the size of LensHub by making library functions external

This commit is contained in:
vicnaum
2023-03-03 11:51:06 +01:00
parent dfacc6f509
commit 7ea23f65bc
6 changed files with 24 additions and 33 deletions

View File

@@ -28,7 +28,7 @@ library CollectLib {
address transactionExecutor,
address collectorProfileOwner,
address collectNFTImpl
) internal returns (uint256) {
) external returns (uint256) {
address collectModule;
Types.PublicationType[] memory referrerPubTypes;
uint256 tokenId;

View File

@@ -18,7 +18,7 @@ library FollowLib {
uint256[] calldata idsOfProfilesToFollow,
uint256[] calldata followTokenIds,
bytes[] calldata followModuleDatas
) internal returns (uint256[] memory) {
) external returns (uint256[] memory) {
if (
idsOfProfilesToFollow.length != followTokenIds.length ||
idsOfProfilesToFollow.length != followModuleDatas.length
@@ -55,7 +55,7 @@ library FollowLib {
uint256 unfollowerProfileId,
address transactionExecutor,
uint256[] calldata idsOfProfilesToUnfollow
) internal {
) external {
uint256 i;
while (i < idsOfProfilesToUnfollow.length) {
uint256 idOfProfileToUnfollow = idsOfProfilesToUnfollow[i];
@@ -98,7 +98,7 @@ library FollowLib {
uint256 idOfProfileToFollow,
uint256 followTokenId,
bytes calldata followModuleData
) internal returns (uint256) {
) private returns (uint256) {
Types.Profile storage _profileToFollow = StorageLib.getProfile(idOfProfileToFollow);
address followNFT = _profileToFollow.followNFT;

View File

@@ -59,11 +59,6 @@ library GovernanceLib {
emit Events.StateSet(msg.sender, prevState, newState, block.timestamp);
}
function whitelistFollowModule(address followModule, bool whitelist) internal {
// _followModuleWhitelisted[followModule] = whitelist; // StorageLib
emit Events.FollowModuleWhitelisted(followModule, whitelist, block.timestamp);
}
function _setState(Types.ProtocolState newState) private returns (Types.ProtocolState) {
Types.ProtocolState prevState = StorageLib.getState();
StorageLib.setState(newState);

View File

@@ -44,7 +44,7 @@ library MetaTxLib {
Types.EIP712Signature calldata signature,
uint256 profileId,
string calldata metadataURI
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -66,7 +66,7 @@ library MetaTxLib {
uint256 profileId,
address followModule,
bytes calldata followModuleInitData
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -91,7 +91,7 @@ library MetaTxLib {
bool[] calldata approvals,
uint64 configNumber,
bool switchToGivenConfig
) internal {
) external {
uint256 nonce = _getAndIncrementNonce(signature.signer);
uint256 deadline = signature.deadline;
_validateRecoveredAddress(
@@ -117,7 +117,7 @@ library MetaTxLib {
Types.EIP712Signature calldata signature,
uint256 profileId,
string calldata imageURI
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -138,7 +138,7 @@ library MetaTxLib {
Types.EIP712Signature calldata signature,
uint256 profileId,
string calldata followNFTURI
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -158,7 +158,7 @@ library MetaTxLib {
function validatePostSignature(
Types.EIP712Signature calldata signature,
Types.PostParams calldata postParams
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -222,7 +222,7 @@ library MetaTxLib {
function validateCommentSignature(
Types.EIP712Signature calldata signature,
Types.CommentParams calldata commentParams
) internal {
) external {
bytes32 contentURIHash = keccak256(bytes(commentParams.contentURI));
bytes32 referenceModuleDataHash = keccak256(commentParams.referenceModuleData);
bytes32 collectModuleInitDataHash = keccak256(commentParams.collectModuleInitData);
@@ -253,7 +253,7 @@ library MetaTxLib {
function validateQuoteSignature(
Types.EIP712Signature calldata signature,
Types.QuoteParams calldata quoteParams
) internal {
) external {
bytes32 contentURIHash = keccak256(bytes(quoteParams.contentURI));
bytes32 referenceModuleDataHash = keccak256(quoteParams.referenceModuleData);
bytes32 collectModuleInitDataHash = keccak256(quoteParams.collectModuleInitData);
@@ -284,7 +284,7 @@ library MetaTxLib {
function validateMirrorSignature(
Types.EIP712Signature calldata signature,
Types.MirrorParams calldata mirrorParams
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -305,7 +305,7 @@ library MetaTxLib {
);
}
function validateBurnSignature(Types.EIP712Signature calldata signature, uint256 tokenId) internal {
function validateBurnSignature(Types.EIP712Signature calldata signature, uint256 tokenId) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -322,7 +322,7 @@ library MetaTxLib {
uint256[] calldata idsOfProfilesToFollow,
uint256[] calldata followTokenIds,
bytes[] calldata datas
) internal {
) external {
uint256 dataLength = datas.length;
bytes32[] memory dataHashes = new bytes32[](dataLength);
for (uint256 i = 0; i < dataLength; ) {
@@ -356,7 +356,7 @@ library MetaTxLib {
Types.EIP712Signature calldata signature,
uint256 unfollowerProfileId,
uint256[] calldata idsOfProfilesToUnfollow
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -378,7 +378,7 @@ library MetaTxLib {
uint256 byProfileId,
uint256[] calldata idsOfProfilesToSetBlockStatus,
bool[] calldata blockStatus
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -399,7 +399,7 @@ library MetaTxLib {
function validateCollectSignature(
Types.EIP712Signature calldata signature,
Types.CollectParams calldata collectParams
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(
@@ -424,7 +424,7 @@ library MetaTxLib {
Types.EIP712Signature calldata signature,
address spender,
uint256 tokenId
) internal {
) external {
_validateRecoveredAddress(
_calculateDigest(
keccak256(

View File

@@ -13,7 +13,7 @@ import {IFollowNFT} from 'contracts/interfaces/IFollowNFT.sol';
library ProfileLib {
uint16 constant MAX_PROFILE_IMAGE_URI_LENGTH = 6000;
function ownerOf(uint256 profileId) internal view returns (address) {
function ownerOf(uint256 profileId) external view returns (address) {
address profileOwner = StorageLib.getTokenData(profileId).owner;
if (profileOwner == address(0)) {
revert Errors.TokenDoesNotExist();
@@ -100,11 +100,7 @@ library ProfileLib {
* @param followModule The follow module to set for the given profile, if any.
* @param followModuleInitData The data to pass to the follow module for profile initialization.
*/
function setFollowModule(
uint256 profileId,
address followModule,
bytes calldata followModuleInitData
) external {
function setFollowModule(uint256 profileId, address followModule, bytes calldata followModuleInitData) external {
StorageLib.getProfile(profileId).followModule = followModule;
bytes memory followModuleReturnData;
if (followModule != address(0)) {
@@ -145,7 +141,7 @@ library ProfileLib {
uint256 byProfileId,
uint256[] calldata idsOfProfilesToSetBlockStatus,
bool[] calldata blockStatus
) internal {
) external {
if (idsOfProfilesToSetBlockStatus.length != blockStatus.length) {
revert Errors.ArrayMismatch();
}
@@ -225,7 +221,7 @@ library ProfileLib {
);
}
function isExecutorApproved(uint256 delegatorProfileId, address executor) internal view returns (bool) {
function isExecutorApproved(uint256 delegatorProfileId, address executor) external view returns (bool) {
Types.DelegatedExecutorsConfig storage _delegatedExecutorsConfig = StorageLib.getDelegatedExecutorsConfig(
delegatorProfileId
);

View File

@@ -188,7 +188,7 @@ library PublicationLib {
return pubType;
}
function getContentURI(uint256 profileId, uint256 pubId) internal view returns (string memory) {
function getContentURI(uint256 profileId, uint256 pubId) external view returns (string memory) {
Types.Publication storage _publication = StorageLib.getPublication(profileId, pubId);
Types.PublicationType pubType = _publication.pubType;
if (pubType == Types.PublicationType.Nonexistent) {