diff --git a/README.md b/README.md index 3a30373..3cd28f0 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,35 @@ -``` - &&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&& /&&&&&&&&&&&&&&&&& - &&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& &&&&& &&&&& &&&&&&( .&&&&&&* - &&&&& &&&&& &&&& &&&&& &&&&& &&&&/ &&&&& - &&&&& &&&&& &&&& &&&&& &&&&& &&&&& &&&&, - &&&&& &&&&& &&&& &&&&& &&&&& &&&&& &&&&& - &&&&& &&&&& &&&& &&&&& &&&&& &&&&&& - &&&&& &&&&& &&&& &&&&% &&&&& &&&&&&&&&&& - &&&&& &&&&&&&&&&&&&&&&&&&& &&&& &&&&/ &&&&& &&&&&&&&&&&&&& - &&&&& &&&&& &&&& &&&&* &&&&& ,&&&&&&&& - &&&&& &&&&& &&&& &&&& &&&&& (&&&&& - &&&&& &&&&& &&&& &&&& &&&&& &&&&& &&&& - &&&&& &&&&& &&&& &&&& &&&&& &&&& &&&& - &&&&& &&&&& &&&& *&&&& &&&&& /&&&&& &&&&& - &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& (&&&& &&&&& &&&&&&& &&&&&&& - &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& %&&&&&&&&&& &&&&&&&&&&&&&&&&&, - - - +``` + &&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&& &&&&& /&&&&&&&&&&&&&&&&& + &&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& &&&&& &&&&& &&&&&&( .&&&&&&* + &&&&& &&&&& &&&& &&&&& &&&&& &&&&/ &&&&& + &&&&& &&&&& &&&& &&&&& &&&&& &&&&& &&&&, + &&&&& &&&&& &&&& &&&&& &&&&& &&&&& &&&&& + &&&&& &&&&& &&&& &&&&& &&&&& &&&&&& + &&&&& &&&&& &&&& &&&&% &&&&& &&&&&&&&&&& + &&&&& &&&&&&&&&&&&&&&&&&&& &&&& &&&&/ &&&&& &&&&&&&&&&&&&& + &&&&& &&&&& &&&& &&&&* &&&&& ,&&&&&&&& + &&&&& &&&&& &&&& &&&& &&&&& (&&&&& + &&&&& &&&&& &&&& &&&& &&&&& &&&&& &&&& + &&&&& &&&&& &&&& &&&& &&&&& &&&& &&&& + &&&&& &&&&& &&&& *&&&& &&&&& /&&&&& &&&&& + &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& (&&&& &&&&& &&&&&&& &&&&&&& + &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&& &&&& %&&&&&&&&&& &&&&&&&&&&&&&&&&&, - _( )_ _ wWWWw _ _( )_ _ wWWWw _ - @@@@ (_ _) ( ) _ @@@@ (___) _( )_ @@@@ (_ _) ( ) _ @@@@ (___) _( )_ - @@()@@ wWWWw (_)\ ( ) _( )_ @@()@@ Y (_ _) @@()@@ wWWWw (_)\ ( ) _( )_ @@()@@ Y (_ _) - @@@@ (___) |/ ( ) (_____) @@@@ \|/ (_)\ @@@@ (___) |/ ( ) (_____) @@@@ \|/ (_)\ - / Y \| (_) | \| |/ | / Y \| (_) | \| |/ | - \ | \|/ | / \ | / \|/ |/ \ \|/ \ | \|/ | / \ | / \|/ |/ \ \|/ - | | | | | | | | | | | | | | | | + + + + _( )_ _ wWWWw _ _( )_ _ wWWWw _ + @@@@ (_ _) ( ) _ @@@@ (___) _( )_ @@@@ (_ _) ( ) _ @@@@ (___) _( )_ + @@()@@ wWWWw (_)\ ( ) _( )_ @@()@@ Y (_ _) @@()@@ wWWWw (_)\ ( ) _( )_ @@()@@ Y (_ _) + @@@@ (___) |/ ( ) (_____) @@@@ \|/ (_)\ @@@@ (___) |/ ( ) (_____) @@@@ \|/ (_)\ + / Y \| (_) | \| |/ | / Y \| (_) | \| |/ | + \ | \|/ | / \ | / \|/ |/ \ \|/ \ | \|/ | / \ | / \|/ |/ \ \|/ + | | | | | | | | | | | | | | | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - _//|\_ | |\ _//|\_ /|\ |\_ |\___ |\ _//|\_ | |\ _//|\_ /|\ |\_ |\___ |\ - | \_/ / \__ / \_ | \ _/ | _| | \_/ / \__ / \_ | \ _/ | _| - /|\_ _/ _/\ \__ /\_ / \_ |_ /|\_ _/ _/\ \__ /\_ / \_ |_ - / | | \___ \_ /\ \ / / | | \___ \_ /\ \ / + _//|\_ | |\ _//|\_ /|\ |\_ |\___ |\ _//|\_ | |\ _//|\_ /|\ |\_ |\___ |\ + | \_/ / \__ / \_ | \ _/ | _| | \_/ / \__ / \_ | \ _/ | _| + /|\_ _/ _/\ \__ /\_ / \_ |_ /|\_ _/ _/\ \__ /\_ / \_ |_ + / | | \___ \_ /\ \ / / | | \___ \_ /\ \ / ``` @@ -122,16 +122,16 @@ Publications are on-chain content created and published via profiles. Profile ow /** * @notice A struct containing data associated with each new publication. * - * @param profileIdPointed The profile token ID this publication points to, for mirrors and comments. - * @param pubIdPointed The publication ID this publication points to, for mirrors and comments. + * @param pointedProfileId The profile token ID this publication points to, for mirrors and comments. + * @param pointedPubId The publication ID this publication points to, for mirrors and comments. * @param contentURI The URI associated with this publication. * @param referenceModule The address of the current reference module in use by this profile, can be empty. * @param collectModule The address of the collect module associated with this publication, this exists for all publication. * @param collectNFT The address of the collectNFT associated with this publication, if any. */ struct PublicationStruct { - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; string contentURI; address referenceModule; address collectModule; diff --git a/contracts/core/LensHub.sol b/contracts/core/LensHub.sol index 8452827..a529d31 100644 --- a/contracts/core/LensHub.sol +++ b/contracts/core/LensHub.sol @@ -270,64 +270,107 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub ProfileLib.setFollowNFTURIWithSig(vars); } + /// ********************************* + /// ****** PUBLISHING FUNCTIONS ***** + /// ********************************* + /// @inheritdoc ILensHub - function post(DataTypes.PostData calldata vars) + function post(DataTypes.PostParams calldata postParams) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(msg.sender, postParams.profileId) returns (uint256) { - return PublishingLib.post(vars); + return PublishingLib.post({postParams: postParams, transactionExecutor: msg.sender}); } /// @inheritdoc ILensHub - function postWithSig(DataTypes.PostWithSigData calldata vars) + function postWithSig( + DataTypes.PostParams calldata postParams, + DataTypes.EIP712Signature calldata signature + ) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(signature.signer, postParams.profileId) returns (uint256) { - return PublishingLib.postWithSig(vars); + MetaTxHelpers.validateCommentSignature(signature, postParams); + return + PublishingLib.postWithSig({ + postParams: postParams, + transactionExecutor: signature.signer + }); } /// @inheritdoc ILensHub - function comment(DataTypes.CommentData calldata vars) + function comment(DataTypes.CommentParams calldata commentParams) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(msg.sender, commentParams.profileId) + onlyValidPointedPub(commentParams.pointedProfileId, commentParams.pointedPubId) + whenNotBlocked(commentParams.profileId, commentParams.pointedProfileId) returns (uint256) { - return PublishingLib.comment(vars); + return + PublishingLib.comment({commentParams: commentParams, transactionExecutor: msg.sender}); } /// @inheritdoc ILensHub - function commentWithSig(DataTypes.CommentWithSigData calldata vars) + function commentWithSig( + DataTypes.CommentParams calldata commentParams, + DataTypes.EIP712Signature calldata signature + ) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(signature.signer, commentParams.profileId) + onlyValidPointedPub(commentParams.pointedProfileId, commentParams.pointedPubId) + whenNotBlocked(commentParams.profileId, commentParams.pointedProfileId) returns (uint256) { - return PublishingLib.commentWithSig(vars); + MetaTxHelpers.validateCommentSignature(signature, commentParams); + return + PublishingLib.comment({ + commentParams: commentParams, + transactionExecutor: signature.signer + }); } /// @inheritdoc ILensHub - function mirror(DataTypes.MirrorData calldata vars) + function mirror(DataTypes.MirrorParams calldata mirrorParams) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(msg.sender, mirrorParams.profileId) + onlyValidPointedPub(mirrorParams.pointedProfileId, mirrorParams.pointedPubId) + whenNotBlocked(mirrorParams.profileId, mirrorParams.pointedProfileId) returns (uint256) { - return PublishingLib.mirror(vars); + return PublishingLib.mirror({mirrorParams: mirrorParams, transactionExecutor: msg.sender}); } /// @inheritdoc ILensHub - function mirrorWithSig(DataTypes.MirrorWithSigData calldata vars) + function mirrorWithSig( + DataTypes.MirrorParams calldata mirrorParams, + DataTypes.EIP712Signature calldata signature + ) external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(signature.signer, mirrorParams.profileId) + onlyValidPointedPub(mirrorParams.pointedProfileId, mirrorParams.pointedPubId) + whenNotBlocked(mirrorParams.profileId, mirrorParams.pointedProfileId) returns (uint256) { - return PublishingLib.mirrorWithSig(vars); + MetaTxHelpers.validateMirrorSignature(signature, mirrorParams); + return + PublishingLib.mirror({ + mirrorParams: mirrorParams, + transactionExecutor: signature.signer + }); } /// @inheritdoc ILensHub @@ -335,6 +378,9 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub external override whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(msg.sender, quoteParams.profileId) + onlyValidPointedPub(quoteParams.pointedProfileId, quoteParams.pointedPubId) + whenNotBlocked(quoteParams.profileId, quoteParams.pointedProfileId) returns (uint256) { return PublishingLib.quote({quoteParams: quoteParams, transactionExecutor: msg.sender}); @@ -343,11 +389,19 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub /// @inheritdoc ILensHub function quoteWithSig( DataTypes.QuoteParams calldata quoteParams, - address signer, DataTypes.EIP712Signature calldata signature - ) external override whenPublishingEnabled returns (uint256) { - MetaTxHelpers.validateQuoteSignature(signer, quoteParams, signature); - return PublishingLib.quote({quoteParams: quoteParams, transactionExecutor: signer}); + ) + external + override + whenPublishingEnabled + onlyProfileOwnerOrDelegatedExecutor(signature.signer, quoteParams.profileId) + onlyValidPointedPub(quoteParams.pointedProfileId, quoteParams.pointedPubId) + whenNotBlocked(quoteParams.profileId, quoteParams.pointedProfileId) + returns (uint256) + { + MetaTxHelpers.validateQuoteSignature(signature, quoteParams); + return + PublishingLib.quote({quoteParams: quoteParams, transactionExecutor: signature.signer}); } /** @@ -441,34 +495,37 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub } /// TODO: Inherit natspec - function collect( - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId, - uint256 collectorProfileId, - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - bytes calldata data - ) external override whenNotPaused returns (uint256) { - return - GeneralLib.collect({ - publicationCollectedProfileId: publicationCollectedProfileId, - publicationCollectedId: publicationCollectedId, - collectorProfileId: collectorProfileId, - passedReferrerProfileId: passedReferrerProfileId, - passedReferrerPubId: passedReferrerPubId, - collectModuleData: data, - collectNFTImpl: COLLECT_NFT_IMPL - }); - } - - /// @inheritdoc ILensHub - function collectWithSig(DataTypes.CollectWithSigData calldata vars) + function collect(DataTypes.CollectParams calldata collectParams) external override whenNotPaused + onlyProfileOwnerOrDelegatedExecutor(msg.sender, collectParams.collectorProfileId) + whenNotBlocked( + collectParams.collectorProfileId, + collectParams.publicationCollectedProfileId + ) returns (uint256) { - return GeneralLib.collectWithSig(vars, COLLECT_NFT_IMPL); + return GeneralLib.collect(collectParams, msg.sender, COLLECT_NFT_IMPL); // TODO: Think how we can not pass this + } + + /// @inheritdoc ILensHub + function collectWithSig( + DataTypes.CollectParams calldata collectParams, + DataTypes.EIP712Signature calldata signature + ) + external + override + whenNotPaused + onlyProfileOwnerOrDelegatedExecutor(signature.signer, collectParams.collectorProfileId) + whenNotBlocked( + collectParams.collectorProfileId, + collectParams.publicationCollectedProfileId + ) + returns (uint256) + { + MetaTxHelpers.validateCollectSignature(signature, collectParams); + return GeneralLib.collect(collectParams, signature.signer); } /// @inheritdoc ILensHub @@ -693,9 +750,9 @@ contract LensHub is LensNFTBase, VersionedInitializable, LensMultiState, LensHub override returns (uint256, uint256) { - uint256 profileIdPointed = _pubByIdByProfile[profileId][pubId].profileIdPointed; - uint256 pubIdPointed = _pubByIdByProfile[profileId][pubId].pubIdPointed; - return (profileIdPointed, pubIdPointed); + uint256 pointedProfileId = _pubByIdByProfile[profileId][pubId].pointedProfileId; + uint256 pointedPubId = _pubByIdByProfile[profileId][pubId].pointedPubId; + return (pointedProfileId, pointedPubId); } /// @inheritdoc ILensHub diff --git a/contracts/core/base/LensMultiState.sol b/contracts/core/base/LensMultiState.sol index 522936a..d1afa76 100644 --- a/contracts/core/base/LensMultiState.sol +++ b/contracts/core/base/LensMultiState.sol @@ -6,6 +6,7 @@ import {Events} from '../../libraries/Events.sol'; import {DataTypes} from '../../libraries/DataTypes.sol'; import {Errors} from '../../libraries/Errors.sol'; import {ILensMultiState} from '../../interfaces/ILensMultiState.sol'; +import {GeneralHelpers} from '../../libraries/helpers/GeneralHelpers.sol'; /** * @title LensMultiState @@ -29,6 +30,27 @@ abstract contract LensMultiState is ILensMultiState { _; } + modifier onlyProfileOwnerOrDelegatedExecutor( + address expectedOwnerOrDelegatedExecutor, + uint256 profileId + ) { + GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor( + expectedOwnerOrDelegatedExecutor, + profileId + ); + _; + } + + modifier whenNotBlocked(uint256 profile, uint256 byProfile) { + GeneralHelpers.validateNotBlocked(profile, byProfile); + _; + } + + modifier onlyValidPointedPub(uint256 profileId, uint256 pubId) { + GeneralHelpers.validatePointedPub(profileId, pubId); + _; + } + /** * @notice Returns the current protocol state. * diff --git a/contracts/core/modules/deprecated/reference/DeprecatedFollowerOnlyReferenceModule.sol b/contracts/core/modules/deprecated/reference/DeprecatedFollowerOnlyReferenceModule.sol index e051436..6a6583b 100644 --- a/contracts/core/modules/deprecated/reference/DeprecatedFollowerOnlyReferenceModule.sol +++ b/contracts/core/modules/deprecated/reference/DeprecatedFollowerOnlyReferenceModule.sol @@ -14,7 +14,10 @@ import {IERC721} from '@openzeppelin/contracts/token/ERC721/IERC721.sol'; * @notice A simple reference module that validates that comments or mirrors originate from a profile owned * by a follower. */ -contract DeprecatedFollowerOnlyReferenceModule is FollowValidationModuleBase, IDeprecatedReferenceModule { +contract DeprecatedFollowerOnlyReferenceModule is + FollowValidationModuleBase, + IDeprecatedReferenceModule +{ constructor(address hub) ModuleBase(hub) {} /** @@ -35,12 +38,12 @@ contract DeprecatedFollowerOnlyReferenceModule is FollowValidationModuleBase, ID */ function processComment( uint256 profileId, - uint256 profileIdPointed, + uint256 pointedProfileId, uint256, bytes calldata ) external view override { address commentCreator = IERC721(HUB).ownerOf(profileId); - _checkFollowValidity(profileIdPointed, commentCreator); + _checkFollowValidity(pointedProfileId, commentCreator); } /** @@ -50,11 +53,11 @@ contract DeprecatedFollowerOnlyReferenceModule is FollowValidationModuleBase, ID */ function processMirror( uint256 profileId, - uint256 profileIdPointed, + uint256 pointedProfileId, uint256, bytes calldata ) external view override { address mirrorCreator = IERC721(HUB).ownerOf(profileId); - _checkFollowValidity(profileIdPointed, mirrorCreator); + _checkFollowValidity(pointedProfileId, mirrorCreator); } } diff --git a/contracts/core/modules/reference/FollowerOnlyReferenceModule.sol b/contracts/core/modules/reference/FollowerOnlyReferenceModule.sol index a012fc9..dd7ee07 100644 --- a/contracts/core/modules/reference/FollowerOnlyReferenceModule.sol +++ b/contracts/core/modules/reference/FollowerOnlyReferenceModule.sol @@ -37,13 +37,13 @@ contract FollowerOnlyReferenceModule is FollowValidationModuleBase, IReferenceMo function processComment( uint256 profileId, address, - uint256 profileIdPointed, + uint256 pointedProfileId, uint256, uint256, bytes calldata ) external view override { address commentCreator = IERC721(HUB).ownerOf(profileId); - _checkFollowValidity(profileIdPointed, commentCreator); + _checkFollowValidity(pointedProfileId, commentCreator); } /** @@ -54,13 +54,13 @@ contract FollowerOnlyReferenceModule is FollowValidationModuleBase, IReferenceMo function processQuote( uint256 profileId, address, - uint256 profileIdPointed, + uint256 pointedProfileId, uint256, uint256, bytes calldata ) external view override { address quoteCreator = IERC721(HUB).ownerOf(profileId); - _checkFollowValidity(profileIdPointed, quoteCreator); + _checkFollowValidity(pointedProfileId, quoteCreator); } /** @@ -71,11 +71,11 @@ contract FollowerOnlyReferenceModule is FollowValidationModuleBase, IReferenceMo function processMirror( uint256 profileId, address, - uint256 profileIdPointed, + uint256 pointedProfileId, uint256, bytes calldata ) external view override { address mirrorCreator = IERC721(HUB).ownerOf(profileId); - _checkFollowValidity(profileIdPointed, mirrorCreator); + _checkFollowValidity(pointedProfileId, mirrorCreator); } } diff --git a/contracts/interfaces/IDeprecatedReferenceModule.sol b/contracts/interfaces/IDeprecatedReferenceModule.sol index a501099..0c452c2 100644 --- a/contracts/interfaces/IDeprecatedReferenceModule.sol +++ b/contracts/interfaces/IDeprecatedReferenceModule.sol @@ -29,14 +29,14 @@ interface IDeprecatedReferenceModule { * @notice Processes a comment action referencing a given publication. This can only be called by the hub. * * @param profileId The token ID of the profile associated with the publication being published. - * @param profileIdPointed The profile ID of the profile associated the publication being referenced. - * @param pubIdPointed The publication ID of the publication being referenced. + * @param pointedProfileId The profile ID of the profile associated the publication being referenced. + * @param pointedPubId The publication ID of the publication being referenced. * @param data Arbitrary data __passed from the commenter!__ to be decoded. */ function processComment( uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes calldata data ) external; @@ -44,14 +44,14 @@ interface IDeprecatedReferenceModule { * @notice Processes a mirror action referencing a given publication. This can only be called by the hub. * * @param profileId The token ID of the profile associated with the publication being published. - * @param profileIdPointed The profile ID of the profile associated the publication being referenced. - * @param pubIdPointed The publication ID of the publication being referenced. + * @param pointedProfileId The profile ID of the profile associated the publication being referenced. + * @param pointedPubId The publication ID of the publication being referenced. * @param data Arbitrary data __passed from the mirrorer!__ to be decoded. */ function processMirror( uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes calldata data ) external; } diff --git a/contracts/interfaces/ILensHub.sol b/contracts/interfaces/ILensHub.sol index 1043f63..5b344bf 100644 --- a/contracts/interfaces/ILensHub.sol +++ b/contracts/interfaces/ILensHub.sol @@ -227,59 +227,71 @@ interface ILensHub { /** * @notice Publishes a post to a given profile, must be called by the profile owner. * - * @param vars A PostData struct containing the needed parameters. + * @param postParams A PostParams struct containing the needed parameters. * * @return uint256 An integer representing the post's publication ID. */ - function post(DataTypes.PostData calldata vars) external returns (uint256); + function post(DataTypes.PostParams calldata postParams) external returns (uint256); /** * @notice Publishes a post to a given profile via signature with the specified parameters. The signer must * either be the profile owner or a delegated executor. * - * @param vars A PostWithSigData struct containing the regular parameters and an EIP712Signature struct. + * @param postParams A PostParams struct containing the needed parameters. + * @param signature The signature for the post. * * @return uint256 An integer representing the post's publication ID. */ - function postWithSig(DataTypes.PostWithSigData calldata vars) external returns (uint256); + function postWithSig( + DataTypes.PostParams calldata postParams, + DataTypes.EIP712Signature calldata signature + ) external returns (uint256); /** * @notice Publishes a comment to a given profile, must be called by the profile owner. * - * @param vars A CommentData struct containing the needed parameters. + * @param commentParams A CommentParams struct containing the needed parameters. * * @return uint256 An integer representing the comment's publication ID. */ - function comment(DataTypes.CommentData calldata vars) external returns (uint256); + function comment(DataTypes.CommentParams calldata commentParams) external returns (uint256); /** * @notice Publishes a comment to a given profile via signature with the specified parameters. The signer must * either be the profile owner or a delegated executor. * - * @param vars A CommentWithSigData struct containing the regular parameters and an EIP712Signature struct. + * @param commentParams A CommentWithSigData struct containing the regular parameters and an EIP712Signature struct. + * @param signature The signature for the comment. * * @return uint256 An integer representing the comment's publication ID. */ - function commentWithSig(DataTypes.CommentWithSigData calldata vars) external returns (uint256); + function commentWithSig( + DataTypes.CommentParams calldata commentParams, + DataTypes.EIP712Signature calldata signature + ) external returns (uint256); /** * @notice Publishes a mirror to a given profile, must be called by the profile owner. * - * @param vars A MirrorData struct containing the necessary parameters. + * @param mirrorParams A MirrorParams struct containing the necessary parameters. * * @return uint256 An integer representing the mirror's publication ID. */ - function mirror(DataTypes.MirrorData calldata vars) external returns (uint256); + function mirror(DataTypes.MirrorParams calldata mirrorParams) external returns (uint256); /** * @notice Publishes a mirror to a given profile via signature with the specified parameters. The signer must * either be the profile owner or a delegated executor. * - * @param vars A MirrorWithSigData struct containing the regular parameters and an EIP712Signature struct. + * @param mirrorParams A MirrorWithSigData struct containing the regular parameters and an EIP712Signature struct. + * @param signature The signature for the mirror. * * @return uint256 An integer representing the mirror's publication ID. */ - function mirrorWithSig(DataTypes.MirrorWithSigData calldata vars) external returns (uint256); + function mirrorWithSig( + DataTypes.MirrorParams calldata mirrorParams, + DataTypes.EIP712Signature calldata signature + ) external returns (uint256); /** * @notice Publishes a quote to a given profile, must be called by the profile owner. @@ -295,14 +307,12 @@ interface ILensHub { * either be the profile owner or a delegated executor. * * @param quoteParams A QuoteParams struct containing the needed parameters. - * @param signer The address of the signer. - * @param signature The signature of the quote. + * @param signature The signature for the quote. * * @return uint256 An integer representing the quote's publication ID. */ function quoteWithSig( DataTypes.QuoteParams calldata quoteParams, - address signer, DataTypes.EIP712Signature calldata signature ) external returns (uint256); @@ -382,26 +392,29 @@ interface ILensHub { */ function setBlockStatusWithSig(DataTypes.SetBlockStatusWithSigData calldata vars) external; - // TODO: Write natspec - function collect( - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId, - uint256 collectorProfileId, - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - bytes calldata data - ) external returns (uint256); + /** + * @notice Collects a given publication via signature with the specified parameters. The caller must either be the collector + * or a delegated executor. + * + * @param collectParams A CollectParams struct containing the parameters. + * + * @return uint256 An integer representing the minted token ID. + */ + function collect(DataTypes.CollectParams calldata collectParams) external returns (uint256); /** * @notice Collects a given publication via signature with the specified parameters. The signer must either be the collector * or a delegated executor. * - * @param vars A CollectWithSigData struct containing the regular parameters as well as the collector's address and - * an EIP712Signature struct. + * @param collectParams A CollectParams struct containing the parameters. + * @param signature The signature for the collect. * * @return uint256 An integer representing the minted token ID. */ - function collectWithSig(DataTypes.CollectWithSigData calldata vars) external returns (uint256); + function collectWithSig( + DataTypes.CollectParams calldata collectParams, + DataTypes.EIP712Signature calldata signature + ) external returns (uint256); /** * @dev Helper function to emit a detailed followNFT transfer event from the hub, to be consumed by indexers to diff --git a/contracts/interfaces/IReferenceModule.sol b/contracts/interfaces/IReferenceModule.sol index a54aa79..9dfc7d2 100644 --- a/contracts/interfaces/IReferenceModule.sol +++ b/contracts/interfaces/IReferenceModule.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; +import {DataTypes} from 'contracts/libraries/DataTypes.sol'; /** * @title IReferenceModule @@ -9,14 +10,6 @@ pragma solidity 0.8.15; * @notice This is the standard interface for all Lens-compatible ReferenceModules. */ interface IReferenceModule { - // function getModuleVersion() external view returns (uint256); - - // function processModuleChange( - // uint256 profileId, - // uint256 pubId, - // bytes calldata data - // ) external; - /** * @notice Initializes data for a given publication being published. This can only be called by the hub. * @@ -40,8 +33,8 @@ interface IReferenceModule { * * @param profileId The token ID of the profile associated with the publication being published. * @param executor The commenter or an approved delegated executor. - * @param profileIdPointed The profile ID of the profile associated the publication being referenced. - * @param pubIdPointed The publication ID of the publication being referenced. + * @param pointedProfileId The profile ID of the profile associated the publication being referenced. + * @param pointedPubId The publication ID of the publication being referenced. * @param referrerProfileId The ID of the profile authoring the mirror if the comment was done through it, zero if the comment was performed directly through the original publication. * @param data Arbitrary data __passed from the commenter!__ to be decoded. @@ -49,9 +42,11 @@ interface IReferenceModule { function processComment( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, uint256 referrerProfileId, + uint256 referrerPubId, + DataTypes.PublicationType referrerPubType, bytes calldata data ) external; @@ -60,8 +55,8 @@ interface IReferenceModule { * * @param profileId The token ID of the profile associated with the publication being published. * @param executor The profile owner or an approved delegated executor. - * @param profileIdPointed The profile ID of the profile associated the publication being quoted. - * @param pubIdPointed The publication ID of the publication being quoted. + * @param pointedProfileId The profile ID of the profile associated the publication being quoted. + * @param pointedPubId The publication ID of the publication being quoted. * @param referrerProfileId The ID of the profile authoring the mirror if the quote was done through it, zero if the quote was performed directly through the original publication. // TODO: is this correct? * @param data Arbitrary data __passed from the executor!__ to be decoded. @@ -69,9 +64,11 @@ interface IReferenceModule { function processQuote( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, uint256 referrerProfileId, + uint256 referrerPubId, + DataTypes.PublicationType referrerPubType, bytes calldata data ) external; @@ -80,15 +77,18 @@ interface IReferenceModule { * * @param profileId The token ID of the profile associated with the publication being published. * @param executor The mirror creator or an approved delegated executor. - * @param profileIdPointed The profile ID of the profile associated the publication being referenced. - * @param pubIdPointed The publication ID of the publication being referenced. + * @param pointedProfileId The profile ID of the profile associated the publication being referenced. + * @param pointedPubId The publication ID of the publication being referenced. * @param data Arbitrary data __passed from the mirrorer!__ to be decoded. */ function processMirror( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, + uint256 referrerProfileId, + uint256 referrerPubId, + DataTypes.PublicationType referrerPubType, bytes calldata data ) external; } diff --git a/contracts/libraries/Constants.sol b/contracts/libraries/Constants.sol index 06ebef9..c00b1ef 100644 --- a/contracts/libraries/Constants.sol +++ b/contracts/libraries/Constants.sol @@ -59,7 +59,7 @@ uint256 constant PROFILE_IMAGE_URI_OFFSET = 4; uint256 constant PROFILE_FOLLOW_NFT_URI_OFFSET = 5; // Publication struct offsets -// uint256 profileIdPointed; // offset 0 +// uint256 pointedProfileId; // offset 0 uint256 constant PUBLICATION_PUB_ID_POINTED_OFFSET = 1; uint256 constant PUBLICATION_CONTENT_URI_OFFSET = 2; // offset 2 uint256 constant PUBLICATION_REFERENCE_MODULE_OFFSET = 3; // offset 3 @@ -96,10 +96,13 @@ bytes32 constant POST_WITH_SIG_TYPEHASH = keccak256( 'PostWithSig(uint256 profileId,string contentURI,address collectModule,bytes collectModuleInitData,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)' ); bytes32 constant COMMENT_WITH_SIG_TYPEHASH = keccak256( - 'CommentWithSig(uint256 profileId,string contentURI,uint256 profileIdPointed,uint256 pubIdPointed,bytes referenceModuleData,address collectModule,bytes collectModuleInitData,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)' + 'CommentWithSig(uint256 profileId,string contentURI,uint256 pointedProfileId,uint256 pointedPubId,uint256 referrerProfileId,uint256 referrerPubId,bytes referenceModuleData,address collectModule,bytes collectModuleInitData,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)' ); bytes32 constant MIRROR_WITH_SIG_TYPEHASH = keccak256( - 'MirrorWithSig(uint256 profileId,uint256 profileIdPointed,uint256 pubIdPointed,bytes referenceModuleData,uint256 nonce,uint256 deadline)' + 'MirrorWithSig(uint256 profileId,uint256 pointedProfileId,uint256 pointedPubId,uint256 referrerProfileId,uint256 referrerPubId,bytes referenceModuleData,uint256 nonce,uint256 deadline)' +); +bytes32 constant QUOTE_WITH_SIG_TYPEHASH = keccak256( + 'QuoteWithSig(uint256 profileId,string contentURI,uint256 pointedProfileId,uint256 pointedPubId,uint256 referrerProfileId,uint256 referrerPubId,bytes referenceModuleData,address collectModule,bytes collectModuleInitData,address referenceModule,bytes referenceModuleInitData,uint256 nonce,uint256 deadline)' ); bytes32 constant FOLLOW_WITH_SIG_TYPEHASH = keccak256( 'FollowWithSig(uint256 followerProfileId,uint256[] idsOfProfilesToFollow,uint256[] followTokenIds,bytes[] datas,uint256 nonce,uint256 deadline)' @@ -111,7 +114,7 @@ bytes32 constant SET_BLOCK_STATUS_WITH_SIG_TYPEHASH = keccak256( 'SetBlockStatusWithSig(uint256 byProfileId,uint256[] idsOfProfilesToSetBlockStatus,bool[] blockStatus,uint256 nonce,uint256 deadline)' ); bytes32 constant COLLECT_WITH_SIG_TYPEHASH = keccak256( - 'CollectWithSig(uint256 collectorProfileId,uint256 publisherProfileId,uint256 pubId,bytes data,uint256 nonce,uint256 deadline)' + 'CollectWithSig(uint256 publicationCollectedProfileId,uint256 publicationCollectedId,uint256 collectorProfileId,uint256 referrerProfileId,uint256 referrerPubId,bytes collectModuleData,uint256 nonce,uint256 deadline)' ); bytes32 constant SET_PROFILE_METADATA_URI_WITH_SIG_TYPEHASH = keccak256( 'SetProfileMetadataURIWithSig(uint256 profileId,string metadata,uint256 nonce,uint256 deadline)' diff --git a/contracts/libraries/DataTypes.sol b/contracts/libraries/DataTypes.sol index b24da32..2e63f8f 100644 --- a/contracts/libraries/DataTypes.sol +++ b/contracts/libraries/DataTypes.sol @@ -42,12 +42,14 @@ library DataTypes { /** * @notice A struct containing the necessary information to reconstruct an EIP-712 typed data signature. * + * @param signer The address of the signer. * @param v The signature's recovery parameter. * @param r The signature's r parameter. * @param s The signature's s parameter * @param deadline The signature's deadline */ struct EIP712Signature { + address signer; uint8 v; bytes32 r; bytes32 s; @@ -74,8 +76,8 @@ library DataTypes { } struct PublicationStruct { - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; string contentURI; address referenceModule; address collectModule; @@ -184,7 +186,7 @@ library DataTypes { * @param referenceModule The reference module to set for the given publication, must be whitelisted. * @param referenceModuleInitData The data to be passed to the reference module for initialization. */ - struct PostData { + struct PostParams { uint256 profileId; string contentURI; address collectModule; @@ -193,48 +195,26 @@ library DataTypes { bytes referenceModuleInitData; } - /** - * @notice A struct containing the parameters required for the `postWithSig()` function. Parameters are the same as - * the regular `post()` function, with an added EIP712Signature. - * - * @param delegatedSigner The delegated executor signer, must be either zero, defaulting to the profile owner, or a delegated executor. - * @param profileId The token ID of the profile to publish to. - * @param contentURI The URI to set for this new publication. - * @param collectModule The collectModule to set for this new publication. - * @param collectModuleInitData The data to pass to the collectModule's initialization. - * @param referenceModule The reference module to set for the given publication, must be whitelisted. - * @param referenceModuleInitData The data to be passed to the reference module for initialization. - * @param sig The EIP712Signature struct containing the profile owner's signature. - */ - struct PostWithSigData { - address delegatedSigner; - uint256 profileId; - string contentURI; - address collectModule; - bytes collectModuleInitData; - address referenceModule; - bytes referenceModuleInitData; - EIP712Signature sig; - } - /** * @notice A struct containing the parameters required for the `comment()` function. * * @param profileId The token ID of the profile to publish to. * @param contentURI The URI to set for this new publication. - * @param profileIdPointed The profile token ID to point the comment to. - * @param pubIdPointed The publication ID to point the comment to. + * @param pointedProfileId The profile token ID to point the comment to. + * @param pointedPubId The publication ID to point the comment to. * @param referenceModuleData The data passed to the reference module. * @param collectModule The collect module to set for this new publication. * @param collectModuleInitData The data to pass to the collect module's initialization. * @param referenceModule The reference module to set for the given publication, must be whitelisted. * @param referenceModuleInitData The data to be passed to the reference module for initialization. */ - struct CommentData { + struct CommentParams { uint256 profileId; string contentURI; - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; + uint256 referrerProfileId; + uint256 referrerPubId; bytes referenceModuleData; address collectModule; bytes collectModuleInitData; @@ -242,43 +222,13 @@ library DataTypes { bytes referenceModuleInitData; } - /** - * @notice A struct containing the parameters required for the `commentWithSig()` function. Parameters are the same as - * the regular `comment()` function, with an added EIP712Signature. - * - * @param delegatedSigner The delegated executor signer, must be either zero, defaulting to the profile owner, or a delegated executor. - * @param profileId The token ID of the profile to publish to. - * @param contentURI The URI to set for this new publication. - * @param profileIdPointed The profile token ID to point the comment to. - * @param pubIdPointed The publication ID to point the comment to. - * @param referenceModuleData The data passed to the reference module. - * @param collectModule The collectModule to set for this new publication. - * @param collectModuleInitData The data to pass to the collectModule's initialization. - * @param referenceModule The reference module to set for the given publication, must be whitelisted. - * @param referenceModuleInitData The data to be passed to the reference module for initialization. - * @param sig The EIP712Signature struct containing the profile owner's signature. - */ - struct CommentWithSigData { - address delegatedSigner; - uint256 profileId; - string contentURI; - uint256 profileIdPointed; - uint256 pubIdPointed; - bytes referenceModuleData; - address collectModule; - bytes collectModuleInitData; - address referenceModule; - bytes referenceModuleInitData; - EIP712Signature sig; - } - /** * @notice A struct containing the parameters required for the `quote()` function. * * @param profileId The token ID of the profile to publish to. * @param contentURI The URI to set for this new publication. - * @param profileIdPointed The profile token ID of the publication author that is quoted. - * @param pubIdPointed The publication ID that is quoted. + * @param pointedProfileId The profile token ID of the publication author that is quoted. + * @param pointedPubId The publication ID that is quoted. * @param referenceModuleData The data passed to the reference module. * @param collectModule The collect module to set for this new publication. * @param collectModuleInitData The data to pass to the collect module's initialization. @@ -288,8 +238,10 @@ library DataTypes { struct QuoteParams { uint256 profileId; string contentURI; - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; + uint256 referrerProfileId; + uint256 referrerPubId; bytes referenceModuleData; address collectModule; bytes collectModuleInitData; @@ -297,43 +249,50 @@ library DataTypes { bytes referenceModuleInitData; } + /** + * @notice A struct containing the parameters required for the `comment()` or `quote()` internal functions. + * + * @param profileId The token ID of the profile to publish to. + * @param contentURI The URI to set for this new publication. + * @param pointedProfileId The profile token ID of the publication author that is quoted. + * @param pointedPubId The publication ID that is quoted. + * @param referenceModuleData The data passed to the reference module. + * @param collectModule The collect module to set for this new publication. + * @param collectModuleInitData The data to pass to the collect module's initialization. + * @param referenceModule The reference module to set for the given publication, must be whitelisted. + * @param referenceModuleInitData The data to be passed to the reference module for initialization. + */ + struct ReferencePubParams { + uint256 profileId; + string contentURI; + uint256 pointedProfileId; + uint256 pointedPubId; + bytes referenceModuleData; + uint256 referrerProfileId; + uint256 referrerPubId; + address collectModule; + bytes collectModuleInitData; + address referenceModule; + bytes referenceModuleInitData; + } + /** * @notice A struct containing the parameters required for the `mirror()` function. * * @param profileId The token ID of the profile to publish to. - * @param profileIdPointed The profile token ID to point the mirror to. - * @param pubIdPointed The publication ID to point the mirror to. + * @param pointedProfileId The profile token ID to point the mirror to. + * @param pointedPubId The publication ID to point the mirror to. * @param referenceModuleData The data passed to the reference module. */ - struct MirrorData { + struct MirrorParams { uint256 profileId; - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; + uint256 referrerProfileId; + uint256 referrerPubId; bytes referenceModuleData; } - /** - * @notice A struct containing the parameters required for the `mirrorWithSig()` function. Parameters are the same as - * the regular `mirror()` function, with an added EIP712Signature. - * - * @param delegatedSigner The delegated executor signer, must be either zero, defaulting to the profile owner, or a delegated executor. - * @param profileId The token ID of the profile to publish to. - * @param profileIdPointed The profile token ID to point the mirror to. - * @param pubIdPointed The publication ID to point the mirror to. - * @param referenceModuleData The data passed to the reference module. - * @param referenceModule The reference module to set for the given publication, must be whitelisted. - * @param referenceModuleInitData The data to be passed to the reference module for initialization. - * @param sig The EIP712Signature struct containing the profile owner's signature. - */ - struct MirrorWithSigData { - address delegatedSigner; - uint256 profileId; - uint256 profileIdPointed; - uint256 pubIdPointed; - bytes referenceModuleData; - EIP712Signature sig; - } - /** * @notice A struct containing the parameters required for the `followWithSig` function. Parameters are the same * as the regular `follow` function, with the signer address and an EIP712Signature added. @@ -408,27 +367,22 @@ library DataTypes { } /** - * @notice A struct containing the parameters required for the `collectWithSig()` function. Parameters are the same as - * the regular `collect()` function, with the collector's (signer) address and an EIP712Signature added. + * @notice A struct containing the parameters required for the `collect()` function. * - * @param delegatedSigner The delegated executor signer, must be either zero, defaulting to the collector profile owner, or a delegated executor. * @param publicationCollectedProfileId The token ID of the profile that published the publication to collect. * @param publicationCollectedId The publication to collect's publication ID. * @param collectorProfileId The collector profile. - * @param passedReferrerProfileId TODO - * @param passedReferrerPubId TODO + * @param referrerProfileId TODO + * @param referrerPubId TODO * @param collectModuleData The arbitrary data to pass to the collectModule if needed. - * @param sig The EIP712Signature struct containing the collector's signature. */ - struct CollectWithSigData { - address delegatedSigner; + struct CollectParams { uint256 publicationCollectedProfileId; uint256 publicationCollectedId; uint256 collectorProfileId; - uint256 passedReferrerProfileId; - uint256 passedReferrerPubId; + uint256 referrerProfileId; + uint256 referrerPubId; bytes collectModuleData; - EIP712Signature sig; } /** diff --git a/contracts/libraries/Errors.sol b/contracts/libraries/Errors.sol index 1065257..3aeb3d3 100644 --- a/contracts/libraries/Errors.sol +++ b/contracts/libraries/Errors.sol @@ -61,6 +61,8 @@ library Errors { error SelfBlock(); error NotFollowing(); error SelfFollow(); + error InvalidReferrer(); + error InvalidPointedPub(); // Module Errors error InitParamsInvalid(); diff --git a/contracts/libraries/Events.sol b/contracts/libraries/Events.sol index f34d93f..ebb4ffa 100644 --- a/contracts/libraries/Events.sol +++ b/contracts/libraries/Events.sol @@ -220,8 +220,8 @@ library Events { * @param profileId The profile's token ID. * @param pubId The new publication's ID. * @param contentURI The URI mapped to this new publication. - * @param profileIdPointed The profile token ID that this comment points to. - * @param pubIdPointed The publication ID that this comment points to. + * @param pointedProfileId The profile token ID that this comment points to. + * @param pointedPubId The publication ID that this comment points to. * @param referenceModuleData The data passed to the reference module. * @param collectModule The collect module mapped to this new publication. This CANNOT be the zero address. * @param collectModuleReturnData The data returned from the collect module's initialization for this given @@ -235,8 +235,8 @@ library Events { uint256 indexed profileId, uint256 indexed pubId, string contentURI, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes referenceModuleData, address collectModule, bytes collectModuleReturnData, @@ -250,16 +250,16 @@ library Events { * * @param profileId The profile's token ID. * @param pubId The new publication's ID. - * @param profileIdPointed The profile token ID that this mirror points to. - * @param pubIdPointed The publication ID that this mirror points to. + * @param pointedProfileId The profile token ID that this mirror points to. + * @param pointedPubId The publication ID that this mirror points to. * @param referenceModuleData The data passed to the reference module. * @param timestamp The current block timestamp. */ event MirrorCreated( uint256 indexed profileId, uint256 indexed pubId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes referenceModuleData, uint256 timestamp ); @@ -270,8 +270,8 @@ library Events { * @param profileId The profile's token ID. * @param pubId The new publication's ID. * @param contentURI The URI mapped to this new publication. - * @param profileIdPointed The profile token ID which author is being quoted. - * @param pubIdPointed The publication ID that is being quoted. + * @param pointedProfileId The profile token ID which author is being quoted. + * @param pointedPubId The publication ID that is being quoted. * @param referenceModuleData The data passed to the reference module. * @param collectModule The collect module mapped to this new publication. This CANNOT be the zero address. * @param collectModuleReturnData The data returned from the collect module's initialization for this given @@ -285,8 +285,8 @@ library Events { uint256 indexed profileId, uint256 indexed pubId, string contentURI, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes referenceModuleData, address collectModule, bytes collectModuleReturnData, diff --git a/contracts/libraries/GeneralLib.sol b/contracts/libraries/GeneralLib.sol index d291a00..c7f6e65 100644 --- a/contracts/libraries/GeneralLib.sol +++ b/contracts/libraries/GeneralLib.sol @@ -279,55 +279,11 @@ library GeneralLib { } function collect( - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId, - uint256 collectorProfileId, - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - bytes calldata collectModuleData, + DataTypes.CollectParams calldata collectParams, + address transactionExecutor, address collectNFTImpl ) external returns (uint256) { - return - InteractionHelpers.collect({ - publicationCollectedProfileId: publicationCollectedProfileId, - publicationCollectedId: publicationCollectedId, - collectorProfileId: collectorProfileId, - collectorProfileOwner: GeneralHelpers.ownerOf(collectorProfileId), - transactionExecutor: msg.sender, - passedReferrerProfileId: passedReferrerProfileId, - passedReferrerPubId: passedReferrerPubId, - collectNFTImpl: collectNFTImpl, - collectModuleData: collectModuleData - }); - } - - /** - * @notice Validates parameters and increments the nonce for a given owner using the - * `collectWithSig()` function. - * - * @param vars the CollectWithSigData struct containing the relevant parameters. - */ - function collectWithSig(DataTypes.CollectWithSigData calldata vars, address collectNFTImpl) - external - returns (uint256) - { - address transactionSigner = GeneralHelpers.getOriginatorOrDelegatedExecutorSigner( - vars.collectorProfileId, - vars.delegatedSigner - ); - MetaTxHelpers.baseCollectWithSig(transactionSigner, vars); - return - InteractionHelpers.collect({ - publicationCollectedProfileId: vars.publicationCollectedProfileId, - publicationCollectedId: vars.publicationCollectedId, - collectorProfileId: vars.collectorProfileId, - collectorProfileOwner: GeneralHelpers.ownerOf(vars.collectorProfileId), - transactionExecutor: transactionSigner, - passedReferrerProfileId: vars.passedReferrerProfileId, - passedReferrerPubId: vars.passedReferrerPubId, - collectNFTImpl: collectNFTImpl, - collectModuleData: vars.collectModuleData - }); + return InteractionHelpers.collect(collectParams, transactionExecutor, collectNFTImpl); } /** diff --git a/contracts/libraries/PublishingLib.sol b/contracts/libraries/PublishingLib.sol index 222700f..bea4f4c 100644 --- a/contracts/libraries/PublishingLib.sol +++ b/contracts/libraries/PublishingLib.sol @@ -16,158 +16,139 @@ library PublishingLib { /** * @notice Publishes a post to a given profile. * - * @param postData The PostData struct. + * @param postParams The PostParams struct. * * @return uint256 The created publication's pubId. */ - function post(DataTypes.PostData calldata postData) external returns (uint256) { - uint256 pubId = ++GeneralHelpers.getProfileStruct(postData.profileId).pubCount; - GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor( - msg.sender, - postData.profileId - ); - _createPost( - postData.profileId, - msg.sender, - pubId, - postData.contentURI, - postData.collectModule, - postData.collectModuleInitData, - postData.referenceModule, - postData.referenceModuleInitData - ); - return pubId; - } - - /** - * @notice Publishes a post to a given profile via signature. - * - * @param postWithSigData the PostWithSigData struct. - * - * @return uint256 The created publication's pubId. - */ - function postWithSig(DataTypes.PostWithSigData calldata postWithSigData) + function post(DataTypes.PostParams calldata postParams, address transactionExecutor) external returns (uint256) { - address signer = GeneralHelpers.getOriginatorOrDelegatedExecutorSigner( - postWithSigData.profileId, - postWithSigData.delegatedSigner + uint256 pubIdAssigned = ++GeneralHelpers.getProfileStruct(postParams.profileId).pubCount; + + DataTypes.PublicationStruct storage _post = GeneralHelpers.getPublicationStruct( + postParams.profileId, + pubIdAssigned ); - uint256 pubId = ++GeneralHelpers.getProfileStruct(postWithSigData.profileId).pubCount; - MetaTxHelpers.basePostWithSig(signer, postWithSigData); - _createPost( - postWithSigData.profileId, - signer, - pubId, - postWithSigData.contentURI, - postWithSigData.collectModule, - postWithSigData.collectModuleInitData, - postWithSigData.referenceModule, - postWithSigData.referenceModuleInitData + _post.contentURI = postParams.contentURI; + _post.pubType = DataTypes.PublicationType.Post; + + bytes memory collectModuleReturnData = _initPubCollectModule( + postParams.profileId, + transactionExecutor, + pubIdAssigned, + postParams.collectModule, + postParams.collectModuleInitData ); - return pubId; + + bytes memory referenceModuleReturnData = _initPubReferenceModule( + postParams.profileId, + transactionExecutor, + pubIdAssigned, + postParams.referenceModule, + postParams.referenceModuleInitData + ); + + emit Events.PostCreated( + postParams.profileId, + pubIdAssigned, + postParams.contentURI, + postParams.collectModule, + collectModuleReturnData, + postParams.referenceModule, + referenceModuleReturnData, + block.timestamp + ); + + return pubIdAssigned; } /** * @notice Publishes a comment to a given profile via signature. * - * @param commentData the CommentData struct. + * @param commentParams the CommentParams struct. * * @return uint256 The created publication's pubId. */ - function comment(DataTypes.CommentData calldata commentData) external returns (uint256) { - GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor( - msg.sender, - commentData.profileId - ); - GeneralHelpers.validateNotBlocked(commentData.profileId, commentData.profileIdPointed); - return _createComment({commentData: commentData, transactionExecutor: msg.sender}); - } - - /** - * @notice Publishes a comment to a given profile via signature. - * - * @param commentWithSigData the CommentWithSigData struct. - * - * @return uint256 The created publication's pubId. - */ - function commentWithSig(DataTypes.CommentWithSigData calldata commentWithSigData) + function comment(DataTypes.CommentParams calldata commentParams, address transactionExecutor) external returns (uint256) { - address signer = GeneralHelpers.getOriginatorOrDelegatedExecutorSigner( - commentWithSigData.profileId, - commentWithSigData.delegatedSigner - ); - GeneralHelpers.validateNotBlocked( - commentWithSigData.profileId, - commentWithSigData.profileIdPointed - ); - MetaTxHelpers.baseCommentWithSig(signer, commentWithSigData); - return - _createComment({ - commentData: DataTypes.CommentData({ - profileId: commentWithSigData.profileId, - contentURI: commentWithSigData.contentURI, - profileIdPointed: commentWithSigData.profileIdPointed, - pubIdPointed: commentWithSigData.pubIdPointed, - referenceModuleData: commentWithSigData.referenceModuleData, - collectModule: commentWithSigData.collectModule, - collectModuleInitData: commentWithSigData.collectModuleInitData, - referenceModule: commentWithSigData.referenceModule, - referenceModuleInitData: commentWithSigData.referenceModuleInitData - }), - transactionExecutor: signer - }); + ( + uint256 pubIdAssigned, + bytes memory collectModuleReturnData, + bytes memory referenceModuleReturnData + ) = _createReferencePublication( + DataTypes.ReferencePubParams(_copyToReferencePubParams(commentParams)), + transactionExecutor + ); + + _processCommentIfNeeded(commentParams, transactionExecutor); + + emit Events.CommentCreated({ + profileId: commentParams.profileId, + pubId: pubIdAssigned, + contentURI: commentParams.contentURI, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + referenceModuleData: commentParams.referenceModuleData, + collectModule: commentParams.collectModule, + collectModuleReturnData: collectModuleReturnData, + referenceModule: commentParams.referenceModule, + referenceModuleReturnData: referenceModuleReturnData, + timestamp: block.timestamp + }); + + return pubIdAssigned; } /** * @notice Publishes a mirror to a given profile. * - * @param mirrorData the MirrorData struct. + * @param mirrorParams the MirrorParams struct. * * @return uint256 The created publication's pubId. */ - function mirror(DataTypes.MirrorData calldata mirrorData) external returns (uint256) { - GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor( - msg.sender, - mirrorData.profileId - ); - GeneralHelpers.validateNotBlocked(mirrorData.profileId, mirrorData.profileIdPointed); - return _createMirror({mirrorData: mirrorData, transactionExecutor: msg.sender}); - } - - /** - * @notice Publishes a mirror to a given profile via signature. - * - * @param mirrorWithSigData the MirrorWithSigData struct. - * - * @return uint256 The created publication's pubId. - */ - function mirrorWithSig(DataTypes.MirrorWithSigData calldata mirrorWithSigData) + function mirror(DataTypes.MirrorParams calldata mirrorParams, address transactionExecutor) external returns (uint256) { - address signer = GeneralHelpers.getOriginatorOrDelegatedExecutorSigner( - mirrorWithSigData.profileId, - mirrorWithSigData.delegatedSigner + DataTypes.PublicationType referrerPubType = GeneralHelpers + .validateReferrerAndGetReferrerPubType( + mirrorParams.referrerProfileId, + mirrorParams.referrerPubId, + mirrorParams.publicationCollectedProfileId, + mirrorParams.publicationCollectedId + ); + + uint256 pubIdAssigned = ++GeneralHelpers.getProfileStruct(mirrorParams.profileId).pubCount; + + DataTypes.PublicationStruct storage _publication = GeneralHelpers.getPublicationStruct( + mirrorParams.profileId, + pubIdAssigned ); - GeneralHelpers.validateNotBlocked( - mirrorWithSigData.profileId, - mirrorWithSigData.profileIdPointed + _publication.pointedProfileId = mirrorParams.pointedProfileId; + _publication.pointedPubId = mirrorParams.pointedPubId; + _publication.pubType = DataTypes.PublicationType.Mirror; + + _processMirrorIfNeeded( + mirrorParams.profileId, + transactionExecutor, + mirrorParams.pointedProfileId, + mirrorParams.pointedPubId, + mirrorParams.referenceModuleData ); - MetaTxHelpers.baseMirrorWithSig(signer, mirrorWithSigData); - return - _createMirror({ - mirrorData: DataTypes.MirrorData({ - profileId: mirrorWithSigData.profileId, - profileIdPointed: mirrorWithSigData.profileIdPointed, - pubIdPointed: mirrorWithSigData.pubIdPointed, - referenceModuleData: mirrorWithSigData.referenceModuleData - }), - transactionExecutor: mirrorWithSigData.delegatedSigner - }); + + emit Events.MirrorCreated( + mirrorParams.profileId, + pubIdAssigned, + mirrorParams.pointedProfileId, + mirrorParams.pointedPubId, + mirrorParams.referenceModuleData, + block.timestamp + ); + + return pubIdAssigned; } /** @@ -181,319 +162,165 @@ library PublishingLib { external returns (uint256) { - // TODO: Start of shared code to abstract with the comment(...) - GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor( - transactionExecutor, - quoteParams.profileId - ); - GeneralHelpers.validateNotBlocked(quoteParams.profileId, quoteParams.profileIdPointed); - uint256 pubIdAssigned = ++GeneralHelpers.getProfileStruct(quoteParams.profileId).pubCount; - - (uint256 profileIdPointed, uint256 pubIdPointed, ) = GeneralHelpers.getPointedIfMirror( - quoteParams.profileIdPointed, - quoteParams.pubIdPointed - ); - - { - DataTypes.PublicationStruct storage _publication; - _publication = GeneralHelpers.getPublicationStruct( - quoteParams.profileId, - pubIdAssigned - ); - _publication.profileIdPointed = profileIdPointed; - _publication.pubIdPointed = pubIdPointed; - _publication.contentURI = quoteParams.contentURI; - _publication.pubType = DataTypes.PublicationType.Quote; - - DataTypes.PublicationStruct storage _publicationPointed = GeneralHelpers - .getPublicationStruct(profileIdPointed, pubIdPointed); - if (_publicationPointed.pubType == DataTypes.PublicationType.Post) { - _publication.rootProfileId = profileIdPointed; - _publication.rootPubId = pubIdPointed; - } else { - // The publication pointed is a comment or a quote. - _publication.rootProfileId = _publicationPointed.rootProfileId; - _publication.rootPubId = _publicationPointed.rootPubId; - } - } - - { - address referenceModule = quoteParams.referenceModule; // Stack-too-deep workaround. - - bytes memory collectModuleReturnData = _initPubCollectModule( - quoteParams.profileId, - transactionExecutor, - pubIdAssigned, - quoteParams.collectModule, - quoteParams.collectModuleInitData + ( + uint256 pubIdAssigned, + bytes memory collectModuleReturnData, + bytes memory referenceModuleReturnData + ) = _createReferencePublication( + _copyToReferencePubParams(quoteParams), + transactionExecutor ); - bytes memory referenceModuleReturnData = _initPubReferenceModule( - quoteParams.profileId, - transactionExecutor, - pubIdAssigned, - referenceModule, - quoteParams.referenceModuleInitData - ); + _processQuoteIfNeeded({ // TODO: How about old publications? Maybe we do processComment! + profileId: quoteParams.profileId, + transactionExecutor: transactionExecutor, + pointedProfileId: quoteParams.pointedProfileId, // We already have the correct pointed passed + pointedPubId: quoteParams.pointedPubId, + referrerProfileId: quoteParams.referrerProfileId, // TODO: But we don't have a referrer yet in params + referenceModuleData: quoteParams.referenceModuleData + }); - // TODO: End of shared code to abstract with the comment(...) - // Start of specific functionality... - - _processQuoteIfNeeded({ // TODO: How about old publications? Maybe we do processComment! - profileId: quoteParams.profileId, - executor: transactionExecutor, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, - referrerProfileId: quoteParams.profileIdPointed, - referenceModuleData: quoteParams.referenceModuleData - }); - - emit Events.QuoteCreated( - quoteParams.profileId, - pubIdAssigned, - quoteParams.contentURI, - profileIdPointed, - pubIdPointed, - quoteParams.referenceModuleData, - quoteParams.collectModule, - collectModuleReturnData, - referenceModule, - referenceModuleReturnData, - block.timestamp - ); - } - - return pubIdAssigned; - } - - function _setPublicationPointer( - uint256 profileId, - uint256 pubId, - uint256 profileIdPointed, - uint256 pubIdPointed - ) private { - DataTypes.PublicationStruct storage _publication = GeneralHelpers.getPublicationStruct( - profileId, - pubId - ); - _publication.profileIdPointed = profileIdPointed; - _publication.pubIdPointed = pubIdPointed; - } - - /** - * @notice Creates a post publication mapped to the given profile. - * - * @param profileId The profile ID to associate this publication to. - * @param executor The executor, which is either the owner or an approved delegated executor. - * @param pubId The publication ID to associate with this publication. - * @param contentURI The URI to set for this publication. - * @param collectModule The collect module to set for this publication. - * @param collectModuleInitData The data to pass to the collect module for publication initialization. - * @param referenceModule The reference module to set for this publication, if any. - * @param referenceModuleInitData The data to pass to the reference module for publication initialization. - */ - function _createPost( - uint256 profileId, - address executor, - uint256 pubId, - string calldata contentURI, - address collectModule, - bytes calldata collectModuleInitData, - address referenceModule, - bytes calldata referenceModuleInitData - ) private { - DataTypes.PublicationStruct storage _publication = GeneralHelpers.getPublicationStruct( - profileId, - pubId - ); - _publication.contentURI = contentURI; - _publication.pubType = DataTypes.PublicationType.Post; - - bytes memory collectModuleReturnData = _initPubCollectModule( - profileId, - executor, - pubId, - collectModule, - collectModuleInitData - ); - - bytes memory referenceModuleReturnData = _initPubReferenceModule( - profileId, - executor, - pubId, - referenceModule, - referenceModuleInitData - ); - - emit Events.PostCreated( - profileId, - pubId, - contentURI, - collectModule, + emit Events.QuoteCreated( + quoteParams.profileId, + pubIdAssigned, + quoteParams.contentURI, + quoteParams.pointedProfileId, + quoteParams.pointedPubId, + quoteParams.referenceModuleData, + quoteParams.collectModule, collectModuleReturnData, - referenceModule, + quoteParams.referenceModule, referenceModuleReturnData, block.timestamp ); - } - - /** - * @notice Creates a comment publication mapped to the given profile. - * - * @param commentData The CommentData struct to use to create the comment. - * @param transactionExecutor The address executing the transaction. It can be the msg.sender if it is a regular - * transaction, or the signer if it is a meta-tx. - * - * @return uint256 The publication ID assigned to the comment being done. - */ - function _createComment(DataTypes.CommentData memory commentData, address transactionExecutor) - private - returns (uint256) - { - uint256 pubIdAssigned = ++GeneralHelpers.getProfileStruct(commentData.profileId).pubCount; - - (uint256 profileIdPointed, uint256 pubIdPointed, ) = GeneralHelpers.getPointedIfMirror( - commentData.profileIdPointed, - commentData.pubIdPointed - ); - - { - DataTypes.PublicationStruct storage _publication; - _publication = GeneralHelpers.getPublicationStruct( - commentData.profileId, - pubIdAssigned - ); - _publication.profileIdPointed = profileIdPointed; - _publication.pubIdPointed = pubIdPointed; - _publication.contentURI = commentData.contentURI; - _publication.pubType = DataTypes.PublicationType.Comment; - - DataTypes.PublicationStruct storage _publicationPointed = GeneralHelpers - .getPublicationStruct(profileIdPointed, pubIdPointed); - if (_publicationPointed.pubType == DataTypes.PublicationType.Post) { - _publication.rootProfileId = profileIdPointed; - _publication.rootPubId = pubIdPointed; - } else { - // The publication pointed is a comment or quote. - _publication.rootProfileId = _publicationPointed.rootProfileId; - _publication.rootPubId = _publicationPointed.rootPubId; - } - } - - { - address referenceModule = commentData.referenceModule; // Stack-too-deep workaround. - - bytes memory collectModuleReturnData = _initPubCollectModule( - commentData.profileId, - transactionExecutor, - pubIdAssigned, - commentData.collectModule, - commentData.collectModuleInitData - ); - - bytes memory referenceModuleReturnData = _initPubReferenceModule( - commentData.profileId, - transactionExecutor, - pubIdAssigned, - referenceModule, - commentData.referenceModuleInitData - ); - - _processCommentIfNeeded({ - profileId: commentData.profileId, - executor: transactionExecutor, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, - referrerProfileId: commentData.profileIdPointed, - referenceModuleData: commentData.referenceModuleData - }); - - emit Events.CommentCreated( - commentData.profileId, - pubIdAssigned, - commentData.contentURI, - profileIdPointed, - pubIdPointed, - commentData.referenceModuleData, - commentData.collectModule, - collectModuleReturnData, - referenceModule, - referenceModuleReturnData, - block.timestamp - ); - } return pubIdAssigned; } - /** - * @notice Creates a mirror publication mapped to the given profile. - * - * @param mirrorData The MirrorData struct to use to create the mirror. - * @param transactionExecutor The address executing the transaction. It can be the msg.sender if it is a regular - * transaction, or the signer if it is a meta-tx. - * - * @return uint256 The publication ID to associate with this publication. - */ - function _createMirror(DataTypes.MirrorData memory mirrorData, address transactionExecutor) + function _copyToReferencePubParams(DataTypes.QuoteParams calldata quoteParams) private - returns (uint256) + returns (DataTypes.ReferencePubParams calldata) { - uint256 pubIdAssigned = ++GeneralHelpers.getProfileStruct(mirrorData.profileId).pubCount; + return + DataTypes.ReferencePubParams({ + profileId: quoteParams.profileId, + contentURI: quoteParams.contentURI, + pointedProfileId: quoteParams.pointedProfileId, + pointedPubId: quoteParams.pointedPubId, + referenceModuleData: quoteParams.referenceModuleData, + collectModule: quoteParams.collectModule, + collectModuleInitData: quoteParams.collectModuleInitData, + referenceModule: quoteParams.referenceModule, + referenceModuleInitData: quoteParams.referenceModuleInitData + }); + } - (uint256 profileIdPointed, uint256 pubIdPointed, ) = GeneralHelpers.getPointedIfMirror( - mirrorData.profileIdPointed, - mirrorData.pubIdPointed + function _copyToReferencePubParams(DataTypes.CommentParams calldata commentParams) + private + returns (DataTypes.ReferencePubParams calldata) + { + return + DataTypes.ReferencePubParams({ + profileId: commentParams.profileId, + contentURI: commentParams.contentURI, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + referenceModuleData: commentParams.referenceModuleData, + collectModule: commentParams.collectModule, + collectModuleInitData: commentParams.collectModuleInitData, + referenceModule: commentParams.referenceModule, + referenceModuleInitData: commentParams.referenceModuleInitData + }); + } + + function _createReferencePublication( + DataTypes.ReferencePubParams memory referencePubParams, + address transactionExecutor + ) + private + returns ( + uint256, + bytes memory, + bytes memory + ) + { + DataTypes.PublicationType referrerPubType = GeneralHelpers + .validateReferrerAndGetReferrerPubType( + referencePubParams.referrerProfileId, + referencePubParams.referrerPubId, + referencePubParams.pointedProfileId, + referencePubParams.pointedPubId + ); + + uint256 pubIdAssigned = _fillReferencePublicationStorage(referencePubParams); + + bytes memory collectModuleReturnData = _initPubCollectModule( + referencePubParams.profileId, + transactionExecutor, + pubIdAssigned, + referencePubParams.collectModule, + referencePubParams.collectModuleInitData ); - DataTypes.PublicationStruct storage _publication = GeneralHelpers.getPublicationStruct( - mirrorData.profileId, + bytes memory referenceModuleReturnData = _initPubReferenceModule( + referencePubParams.profileId, + transactionExecutor, + pubIdAssigned, + referencePubParams.referenceModule, + referencePubParams.referenceModuleInitData + ); + + return (pubIdAssigned, collectModuleReturnData, referenceModuleReturnData); + } + + function _fillReferencePublicationStorage( + DataTypes.ReferencePubParams memory referencePubParams + ) private returns (uint256) { + uint256 pubIdAssigned = ++GeneralHelpers + .getProfileStruct(referencePubParams.profileId) + .pubCount; + DataTypes.PublicationStruct storage _referencePub; + _referencePub = GeneralHelpers.getPublicationStruct( + referencePubParams.profileId, pubIdAssigned ); - _publication.profileIdPointed = profileIdPointed; - _publication.pubIdPointed = pubIdPointed; - _publication.pubType = DataTypes.PublicationType.Mirror; - - _processMirrorIfNeeded( - mirrorData.profileId, - transactionExecutor, - profileIdPointed, - pubIdPointed, - mirrorData.referenceModuleData + _referencePub.pointedProfileId = referencePubParams.pointedProfileId; + _referencePub.pointedPubId = referencePubParams.pointedPubId; + _referencePub.contentURI = referencePubParams.contentURI; + _referencePub.pubType = referencePubParams.pubType; + DataTypes.PublicationStruct storage _pubPointed = GeneralHelpers.getPublicationStruct( + referencePubParams.pointedProfileId, + referencePubParams.pointedPubId ); - - emit Events.MirrorCreated( - mirrorData.profileId, - pubIdAssigned, - profileIdPointed, - pubIdPointed, - mirrorData.referenceModuleData, - block.timestamp - ); - + if (_pubPointed.pubType == DataTypes.PublicationType.Post) { + _referencePub.rootProfileId = referencePubParams.pointedProfileId; + _referencePub.rootPubId = referencePubParams.pointedPubId; + } else { + // The publication pointed is either a comment or a quote. + _referencePub.rootProfileId = _pubPointed.rootProfileId; + _referencePub.rootPubId = _pubPointed.rootPubId; + } return pubIdAssigned; } function _processCommentIfNeeded( - uint256 profileId, - address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, - uint256 referrerProfileId, - bytes memory referenceModuleData + DataTypes.CommentParams calldata commentParams, + address transactionExecutor ) private { address refModule = GeneralHelpers - .getPublicationStruct(profileIdPointed, pubIdPointed) + .getPublicationStruct(commentParams.pointedProfileId, commentParams.pointedPubId) .referenceModule; if (refModule != address(0)) { try IReferenceModule(refModule).processComment({ - profileId: profileId, - executor: executor, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, - referrerProfileId: referrerProfileId, - data: referenceModuleData + profileId: commentParams.profileId, + executor: transactionExecutor, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + referrerProfileId: commentParams.referrerProfileId, + referrerPubId: commentParams.referrerPubId, + referrerPubType: commentParams.referrerPubType, + data: commentParams.referenceModuleData }) {} catch (bytes memory err) { assembly { @@ -504,14 +331,14 @@ library PublishingLib { revert(add(err, 32), length) } } - if (executor != GeneralHelpers.unsafeOwnerOf(profileId)) { + if (transactionExecutor != GeneralHelpers.unsafeOwnerOf(commentParams.profileId)) { revert Errors.ExecutorInvalid(); } IDeprecatedReferenceModule(refModule).processComment( - profileId, - profileIdPointed, - pubIdPointed, - referenceModuleData + commentParams.profileId, + commentParams.pointedProfileId, + commentParams.pointedPubId, + commentParams.referenceModuleData ); } } @@ -519,22 +346,22 @@ library PublishingLib { function _processQuoteIfNeeded( uint256 profileId, - address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + address transactionExecutor, + uint256 pointedProfileId, + uint256 pointedPubId, uint256 referrerProfileId, bytes memory referenceModuleData ) private { address refModule = GeneralHelpers - .getPublicationStruct(profileIdPointed, pubIdPointed) + .getPublicationStruct(pointedProfileId, pointedPubId) .referenceModule; if (refModule != address(0)) { try IReferenceModule(refModule).processQuote({ profileId: profileId, - executor: executor, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, + executor: transactionExecutor, + pointedProfileId: pointedProfileId, + pointedPubId: pointedPubId, referrerProfileId: referrerProfileId, data: referenceModuleData }) @@ -547,13 +374,13 @@ library PublishingLib { revert(add(err, 32), length) } } - if (executor != GeneralHelpers.unsafeOwnerOf(profileId)) { + if (transactionExecutor != GeneralHelpers.unsafeOwnerOf(profileId)) { revert Errors.ExecutorInvalid(); } IDeprecatedReferenceModule(refModule).processComment( profileId, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData ); } @@ -562,21 +389,21 @@ library PublishingLib { function _processMirrorIfNeeded( uint256 profileId, - address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + address transactionExecutor, + uint256 pointedProfileId, + uint256 pointedPubId, bytes memory referenceModuleData ) private { address refModule = GeneralHelpers - .getPublicationStruct(profileIdPointed, pubIdPointed) + .getPublicationStruct(pointedProfileId, pointedPubId) .referenceModule; if (refModule != address(0)) { try IReferenceModule(refModule).processMirror( profileId, - executor, - profileIdPointed, - pubIdPointed, + transactionExecutor, + pointedProfileId, + pointedPubId, referenceModuleData ) {} catch (bytes memory err) { @@ -588,13 +415,13 @@ library PublishingLib { revert(add(err, 32), length) } } - if (executor != GeneralHelpers.unsafeOwnerOf(profileId)) { + if (transactionExecutor != GeneralHelpers.unsafeOwnerOf(profileId)) { revert Errors.ExecutorInvalid(); } IDeprecatedReferenceModule(refModule).processMirror( profileId, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData ); } @@ -603,7 +430,7 @@ library PublishingLib { function _initPubCollectModule( uint256 profileId, - address executor, + address transactionExecutor, uint256 pubId, address collectModule, bytes memory collectModuleInitData @@ -614,14 +441,14 @@ library PublishingLib { ICollectModule(collectModule).initializePublicationCollectModule( profileId, pubId, - executor, + transactionExecutor, collectModuleInitData ); } function _initPubReferenceModule( uint256 profileId, - address executor, + address transactionExecutor, uint256 pubId, address referenceModule, bytes memory referenceModuleInitData @@ -632,7 +459,7 @@ library PublishingLib { return IReferenceModule(referenceModule).initializeReferenceModule( profileId, - executor, + transactionExecutor, pubId, referenceModuleInitData ); diff --git a/contracts/libraries/helpers/GeneralHelpers.sol b/contracts/libraries/helpers/GeneralHelpers.sol index 1e4e681..de6be03 100644 --- a/contracts/libraries/helpers/GeneralHelpers.sol +++ b/contracts/libraries/helpers/GeneralHelpers.sol @@ -42,22 +42,33 @@ library GeneralHelpers { } else { // The publication is either a mirror or a non-existent one. We determine that by checking the pointed // profile and publication IDs. - uint256 profileIdPointed = _publication.profileIdPointed; + uint256 pointedProfileId = _publication.pointedProfileId; // We validate existence here as an optimization, so validating in calling contracts is unnecessary. // As this publication is expected to be a mirror, it needs to be pointing to an existing publication, // otherwise this publication does not exist. - if (profileIdPointed == 0) { + if (pointedProfileId == 0) { revert Errors.PublicationDoesNotExist(); } - uint256 pubIdPointed = _publication.pubIdPointed; + uint256 pointedPubId = _publication.pointedPubId; return ( - profileIdPointed, - pubIdPointed, - getPublicationStruct(profileIdPointed, pubIdPointed).collectModule + pointedProfileId, + pointedPubId, + getPublicationStruct(pointedProfileId, pointedPubId).collectModule ); } } + function validatePointedPub(uint256 profileId, uint256 pubId) internal view { + // If it is pointing to itself it will fail because it will return non-existent type. + DataTypes.PublicationType pointedPubType = getPublicationType(profileId, pubId); + if ( + pointedPubType == DataTypes.PublicationType.Nonexistent || + pointedPubType == DataTypes.PublicationType.Mirror + ) { + revert Errors.InvalidPointedPub(); + } + } + /** * @dev This fetches the owner address for a given token ID. Note that this does not check and * revert upon loading a zero address. @@ -199,7 +210,7 @@ library GeneralHelpers { DataTypes.PublicationType pubType = _publication.pubType; if (uint8(pubType) == 0) { // If publication type is 0, we check using the legacy rules. - if (_publication.profileIdPointed != 0) { + if (_publication.pointedProfileId != 0) { // It is pointing to a publication, so it can be either a comment or a mirror, depending on if it has a // collect module or not. if (_publication.collectModule == address(0)) { @@ -244,6 +255,104 @@ library GeneralHelpers { return _profile; } + function validateReferrerAndGetReferrerPubType( + uint256 referrerProfileId, + uint256 referrerPubId, + uint256 profileId, + uint256 pubId + ) internal view returns (DataTypes.PublicationType) { + if (referrerProfileId == 0 && referrerPubId == 0) { + // No referrer was passed. + return DataTypes.PublicationType.Nonexistent; + } + + if ( + // Cannot pass itself as a referrer. + referrerProfileId == profileId && referrerPubId == pubId + ) { + revert Errors.InvalidReferrer(); + } + + DataTypes.PublicationType referrerPubType = GeneralHelpers.getPublicationType( + referrerProfileId, + referrerPubId + ); + + if (referrerPubType == DataTypes.PublicationType.Mirror) { + _validateReferrerAsMirror(referrerProfileId, referrerPubId, profileId, pubId); + } else if ( + referrerPubType == DataTypes.PublicationType.Comment || + referrerPubType == DataTypes.PublicationType.Quote + ) { + _validateReferrerAsCommentOrQuote(referrerProfileId, referrerPubId, profileId, pubId); + } else { + // Referrarls are only supported for mirrors, comments and quotes, not for posts. + revert Errors.InvalidReferrer(); + } + + return referrerPubType; + } + + function _validateReferrerAsMirror( + uint256 referrerProfileId, + uint256 referrerPubId, + uint256 profileId, + uint256 pubId + ) private view { + DataTypes.PublicationStruct storage _referrerMirror = GeneralHelpers.getPublicationStruct( + referrerProfileId, + referrerPubId + ); + if ( + // A mirror can only be a referrer of a publication if it is pointing to it. + _referrerMirror.pointedProfileId != profileId || _referrerMirror.pointedPubId != pubId + ) { + revert Errors.InvalidReferrer(); + } + } + + /** + * @dev Validates that the referrer publication and the interacted publilcation are linked. + * + * @param referrerProfileId The profile id of the referrer. + * @param referrerPubId The publication id of the referrer. + * @param profileId This is the ID of the profile who authored the publication being collected or referenced. + * @param pubId This is the pub user collects or references. + */ + function _validateReferrerAsCommentOrQuote( + uint256 referrerProfileId, + uint256 referrerPubId, + uint256 profileId, + uint256 pubId + ) private view { + DataTypes.PublicationStruct storage _referrerPub = GeneralHelpers.getPublicationStruct( + referrerProfileId, + referrerPubId + ); + DataTypes.PublicationType typeOfPubPointedByReferrer = GeneralHelpers.getPublicationType( + profileId, + pubId + ); + // We already know that the publication being collected/referenced is not a mirror nor a non-existent one. + if (typeOfPubPointedByReferrer == DataTypes.PublicationType.Post) { + // If the publication collected/referenced is a post, the referrer comment/quote must have it as root. + if (_referrerPub.rootProfileId != profileId || _referrerPub.rootPubId != pubId) { + revert Errors.InvalidReferrer(); + } + } else { + // The publication collected/referenced is a comment or a quote. + DataTypes.PublicationStruct storage _pubPointedByReferrer = GeneralHelpers + .getPublicationStruct(profileId, pubId); + // The referrer publication and the collected/referenced publication must share the same root. + if ( + _referrerPub.rootProfileId != _pubPointedByReferrer.rootProfileId || + _referrerPub.rootPubId != _pubPointedByReferrer.rootPubId + ) { + revert Errors.InvalidReferrer(); + } + } + } + function _validateModuleWhitelisted( uint256 whitelistMappingSlot, address moduleAddress, diff --git a/contracts/libraries/helpers/InteractionHelpers.sol b/contracts/libraries/helpers/InteractionHelpers.sol index 0ee9323..5ad9a42 100644 --- a/contracts/libraries/helpers/InteractionHelpers.sol +++ b/contracts/libraries/helpers/InteractionHelpers.sol @@ -165,78 +165,47 @@ library InteractionHelpers { } function collect( - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId, - uint256 collectorProfileId, - address collectorProfileOwner, + DataTypes.CollectParams calldata collectParams, address transactionExecutor, - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - address collectNFTImpl, - bytes calldata collectModuleData + address collectNFTImpl ) internal returns (uint256) { - uint256 publicationCollectedProfileIdCached = publicationCollectedProfileId; - uint256 publicationCollectedIdCached = publicationCollectedId; - uint256 collectorProfileIdCached = collectorProfileId; - address collectorProfileOwnerCached = collectorProfileOwner; - address transactionExecutorCached = transactionExecutor; - uint256 passedReferrerProfileIdCached = passedReferrerProfileId; - uint256 passedReferrerPubIdCached = passedReferrerPubId; - address collectNFTImplCached = collectNFTImpl; - - GeneralHelpers.validateAddressIsProfileOwnerOrDelegatedExecutor({ - expectedOwnerOrDelegatedExecutor: transactionExecutorCached, - profileId: collectorProfileIdCached - }); - - GeneralHelpers.validateNotBlocked({ - profile: collectorProfileIdCached, - byProfile: publicationCollectedProfileIdCached - }); - address collectModule; - DataTypes.PublicationType passedReferrerPubType; + DataTypes.PublicationType referrerPubType; uint256 tokenId; + address collectorProfileOwner = GeneralHelpers.ownerOf(collectParams.collectorProfileId); { DataTypes.PublicationStruct storage _collectedPublication = GeneralHelpers .getPublicationStruct( - publicationCollectedProfileIdCached, - publicationCollectedIdCached + collectParams.publicationCollectedProfileId, + collectParams.publicationCollectedId ); collectModule = _collectedPublication.collectModule; if (collectModule == address(0)) { // Doesn't have collectModule, thus it cannot be a collected (a mirror or non-existent). revert Errors.CollectNotAllowed(); } - passedReferrerPubType = _validateReferrerAndGetReferrersPubType( - passedReferrerProfileIdCached, - passedReferrerPubIdCached, - publicationCollectedProfileIdCached, - publicationCollectedIdCached + referrerPubType = GeneralHelpers.validateReferrerAndGetReferrerPubType( + collectParams.referrerProfileId, + collectParams.referrerPubId, + collectParams.publicationCollectedProfileId, + collectParams.publicationCollectedId ); address collectNFT = _getOrDeployCollectNFT( _collectedPublication, - publicationCollectedProfileIdCached, - publicationCollectedIdCached, - collectNFTImplCached + collectParams.publicationCollectedProfileId, + collectParams.publicationCollectedId, + collectNFTImpl ); - tokenId = ICollectNFT(collectNFT).mint(collectorProfileOwnerCached); + tokenId = ICollectNFT(collectNFT).mint(collectorProfileOwner); } - _processCollect( - ProcessCollectParams({ - publicationCollectedProfileId: publicationCollectedProfileIdCached, - publicationCollectedId: publicationCollectedIdCached, - collectorProfileId: collectorProfileIdCached, - collectorProfileOwner: collectorProfileOwnerCached, - transactionExecutor: transactionExecutorCached, - referrerProfileId: passedReferrerProfileIdCached, - referrerPubId: passedReferrerPubIdCached, - referrerPubType: passedReferrerPubType, - collectModule: collectModule - }), - collectModuleData - ); + _processCollect({ + collectParams: collectParams, + transactionExecutor: transactionExecutor, + collectorProfileOwner: collectorProfileOwner, + referrerPubType: referrerPubType, + collectModule: collectModule + }); return tokenId; } @@ -259,130 +228,24 @@ library InteractionHelpers { return collectNFT; } - function _validateReferrerAndGetReferrersPubType( - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId - ) private view returns (DataTypes.PublicationType) { - if ( - // Cannot pass itself as a referrer. - passedReferrerProfileId == publicationCollectedProfileId && - passedReferrerPubId == publicationCollectedId - ) { - revert Errors.InvalidParameter(); - } - - if (passedReferrerProfileId == 0 && passedReferrerPubId == 0) { - // The collector did not pass a referrer. - return DataTypes.PublicationType.Nonexistent; - } - - DataTypes.PublicationType passedReferrerPubType = GeneralHelpers.getPublicationType( - passedReferrerProfileId, - passedReferrerPubId - ); - - if (passedReferrerPubType == DataTypes.PublicationType.Mirror) { - _validateReferrerAsMirror( - passedReferrerProfileId, - passedReferrerPubId, - publicationCollectedProfileId, - publicationCollectedId - ); - } else if (passedReferrerPubType == DataTypes.PublicationType.Comment) { - _validateReferrerAsComment( - passedReferrerProfileId, - passedReferrerPubId, - publicationCollectedProfileId, - publicationCollectedId - ); - } else { - // Referrarls are only supported for mirrors, comments and quotes. - revert Errors.InvalidParameter(); - } - - return passedReferrerPubType; - } - - function _validateReferrerAsMirror( - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId - ) private view { - DataTypes.PublicationStruct storage _passedReferrerMirror = GeneralHelpers - .getPublicationStruct(passedReferrerProfileId, passedReferrerPubId); - if ( - _passedReferrerMirror.profileIdPointed != publicationCollectedProfileId || - _passedReferrerMirror.pubIdPointed != publicationCollectedId - ) { - revert Errors.InvalidParameter(); - } - } - - function _validateReferrerAsComment( - uint256 passedReferrerProfileId, - uint256 passedReferrerPubId, - uint256 publicationCollectedProfileId, - uint256 publicationCollectedId - ) private view { - DataTypes.PublicationStruct storage _passedReferrerComment = GeneralHelpers - .getPublicationStruct(passedReferrerProfileId, passedReferrerPubId); - DataTypes.PublicationType collectedPublicationType = GeneralHelpers.getPublicationType( - publicationCollectedProfileId, - publicationCollectedId - ); - // At this stage, we already know that the collected publication can not be a mirror or a non-existent one. - if (collectedPublicationType == DataTypes.PublicationType.Post) { - // The passed referrer comment must have the collected post as root post. - if ( - _passedReferrerComment.rootProfileId != publicationCollectedProfileId || - _passedReferrerComment.rootPubId != publicationCollectedId - ) { - revert Errors.InvalidParameter(); - } - } else { - // collectedPublicationType == DataTypes.PublicationType.Comment - DataTypes.PublicationStruct storage _collectedPublication = GeneralHelpers - .getPublicationStruct(publicationCollectedProfileId, publicationCollectedId); - // The passed referrer comment and the collected comment must share the same root post. - if ( - _passedReferrerComment.rootProfileId != _collectedPublication.rootProfileId || - _passedReferrerComment.rootPubId != _collectedPublication.rootPubId - ) { - revert Errors.InvalidParameter(); - } - } - } - - // TODO: Think about how to make this better... (it's needed for stack too deep) - struct ProcessCollectParams { - uint256 publicationCollectedProfileId; - uint256 publicationCollectedId; - uint256 collectorProfileId; - address collectorProfileOwner; - address transactionExecutor; - uint256 referrerProfileId; - uint256 referrerPubId; - DataTypes.PublicationType referrerPubType; - address collectModule; - } - - function _processCollect(ProcessCollectParams memory params, bytes calldata collectModuleData) - private - { + function _processCollect( + DataTypes.CollectParams calldata collectParams, + address transactionExecutor, + uint256 collectorProfileOwner, + DataTypes.PublicationType referrerPubType, + address collectModule + ) private { try - ICollectModule(params.collectModule).processCollect({ - publicationCollectedProfileId: params.publicationCollectedProfileId, - publicationCollectedId: params.publicationCollectedId, - collectorProfileId: params.collectorProfileId, - collectorProfileOwner: params.collectorProfileOwner, - executor: params.transactionExecutor, - referrerProfileId: params.referrerProfileId, - referrerPubId: params.referrerPubId, - referrerPubType: params.referrerPubType, - data: collectModuleData + ICollectModule(collectModule).processCollect({ + publicationCollectedProfileId: collectParams.publicationCollectedProfileId, + publicationCollectedId: collectParams.publicationCollectedId, + collectorProfileId: collectParams.collectorProfileId, + collectorProfileOwner: collectorProfileOwner, + executor: transactionExecutor, + referrerProfileId: collectParams.referrerProfileId, + referrerPubId: collectParams.referrerPubId, + referrerPubType: referrerPubType, + data: collectParams.collectModuleData }) {} catch (bytes memory err) { assembly { @@ -393,24 +256,23 @@ library InteractionHelpers { revert(add(err, 32), length) } } - if (params.collectorProfileOwner != params.transactionExecutor) - revert Errors.ExecutorInvalid(); - IDeprecatedCollectModule(params.collectModule).processCollect( - params.publicationCollectedProfileId, - params.collectorProfileOwner, - params.referrerProfileId, - params.referrerPubId, - collectModuleData + if (collectorProfileOwner != transactionExecutor) revert Errors.ExecutorInvalid(); + IDeprecatedCollectModule(collectModule).processCollect( + collectParams.publicationCollectedProfileId, + collectorProfileOwner, + collectParams.referrerProfileId, + collectParams.referrerPubId, + collectParams.collectModuleData ); } emit Events.Collected({ - publicationCollectedProfileId: params.publicationCollectedProfileId, - publicationCollectedId: params.publicationCollectedId, - collectorProfileId: params.collectorProfileId, - referrerProfileId: params.referrerProfileId, - referrerPubId: params.referrerPubId, - collectModuleData: collectModuleData, + publicationCollectedProfileId: collectParams.publicationCollectedProfileId, + publicationCollectedId: collectParams.publicationCollectedId, + collectorProfileId: collectParams.collectorProfileId, + referrerProfileId: collectParams.referrerProfileId, + referrerPubId: collectParams.referrerPubId, + collectModuleData: collectParams.collectModuleData, timestamp: block.timestamp }); } diff --git a/contracts/libraries/helpers/MetaTxHelpers.sol b/contracts/libraries/helpers/MetaTxHelpers.sol index 84b66c1..359c2e7 100644 --- a/contracts/libraries/helpers/MetaTxHelpers.sol +++ b/contracts/libraries/helpers/MetaTxHelpers.sol @@ -188,59 +188,64 @@ library MetaTxHelpers { ); } - function basePostWithSig(address signer, DataTypes.PostWithSigData calldata vars) internal { + function validatePostSignature( + DataTypes.EIP712Signature calldata sig, + DataTypes.PostParams calldata postParams + ) internal { _validateRecoveredAddress( _calculateDigest( keccak256( abi.encode( POST_WITH_SIG_TYPEHASH, - vars.profileId, - keccak256(bytes(vars.contentURI)), - vars.collectModule, - keccak256(vars.collectModuleInitData), - vars.referenceModule, - keccak256(vars.referenceModuleInitData), - _sigNonces(signer), - vars.sig.deadline + postParams.profileId, + keccak256(bytes(postParams.contentURI)), + postParams.collectModule, + keccak256(postParams.collectModuleInitData), + postParams.referenceModule, + keccak256(postParams.referenceModuleInitData), + _sigNonces(sig.signer), + sig.deadline ) ) ), - signer, - vars.sig + sig.signer, + sig ); } - function baseCommentWithSig(address signer, DataTypes.CommentWithSigData calldata vars) - internal - { + function validateCommentSignature( + DataTypes.EIP712Signature calldata sig, + DataTypes.CommentParams calldata commentParams + ) internal { _validateRecoveredAddress( _calculateDigest( keccak256( abi.encode( COMMENT_WITH_SIG_TYPEHASH, - vars.profileId, - keccak256(bytes(vars.contentURI)), - vars.profileIdPointed, - vars.pubIdPointed, - keccak256(vars.referenceModuleData), - vars.collectModule, - keccak256(vars.collectModuleInitData), - vars.referenceModule, - keccak256(vars.referenceModuleInitData), - _sigNonces(signer), - vars.sig.deadline + commentParams.profileId, + keccak256(bytes(commentParams.contentURI)), + commentParams.pointedProfileId, + commentParams.pointedPubId, + commentParams.referrerProfileId, + commentParams.referrerPubId, + keccak256(commentParams.referenceModuleData), + commentParams.collectModule, + keccak256(commentParams.collectModuleInitData), + commentParams.referenceModule, + keccak256(commentParams.referenceModuleInitData), + _sigNonces(sig.signer), + commentParams.sig.deadline ) ) ), - signer, - vars.sig + sig.signer, + commentParams.sig ); } function validateQuoteSignature( - address signer, // TODO: put a signer inside sig struct - DataTypes.QuoteParams calldata quoteParams, - DataTypes.EIP712Signature calldata sig + DataTypes.EIP712Signature calldata sig, + DataTypes.QuoteParams calldata quoteParams ) internal { _validateRecoveredAddress( _calculateDigest( @@ -249,40 +254,47 @@ library MetaTxHelpers { COMMENT_WITH_SIG_TYPEHASH, quoteParams.profileId, keccak256(bytes(quoteParams.contentURI)), - quoteParams.profileIdPointed, - quoteParams.pubIdPointed, + quoteParams.pointedProfileId, + quoteParams.pointedPubId, keccak256(quoteParams.referenceModuleData), + quoteParams.referrerProfileId, + quoteParams.referrerPubId, quoteParams.collectModule, keccak256(quoteParams.collectModuleInitData), quoteParams.referenceModule, keccak256(quoteParams.referenceModuleInitData), - _sigNonces(signer), + _sigNonces(sig.signer), sig.deadline ) ) ), - signer, + sig.signer, sig ); } - function baseMirrorWithSig(address signer, DataTypes.MirrorWithSigData calldata vars) internal { + function validateMirrorSignature( + DataTypes.EIP712Signature calldata sig, + DataTypes.MirrorParams calldata mirrorParams + ) internal { _validateRecoveredAddress( _calculateDigest( keccak256( abi.encode( MIRROR_WITH_SIG_TYPEHASH, - vars.profileId, - vars.profileIdPointed, - vars.pubIdPointed, - keccak256(vars.referenceModuleData), - _sigNonces(signer), - vars.sig.deadline + mirrorParams.profileId, + mirrorParams.pointedProfileId, + mirrorParams.pointedPubId, + mirrorParams.referrerProfileId, + mirrorParams.referrerPubId, + keccak256(mirrorParams.referenceModuleData), + _sigNonces(sig.signer), + sig.deadline ) ) ), - signer, - vars.sig + sig.signer, + sig ); } @@ -369,25 +381,28 @@ library MetaTxHelpers { ); } - function baseCollectWithSig(address signer, DataTypes.CollectWithSigData calldata vars) - internal - { + function validateCollectSignature( + DataTypes.EIP712Signature calldata sig, + DataTypes.CollectParams calldata collectParams + ) internal { _validateRecoveredAddress( _calculateDigest( keccak256( abi.encode( COLLECT_WITH_SIG_TYPEHASH, - vars.collectorProfileId, - vars.publicationCollectedProfileId, - vars.publicationCollectedId, - keccak256(vars.collectModuleData), - _sigNonces(signer), - vars.sig.deadline + collectParams.publicationCollectedProfileId, + collectParams.publicationCollectedId, + collectParams.collectorProfileId, + collectParams.referrerProfileId, + collectParams.referrerPubId, + keccak256(collectParams.collectModuleData), + _sigNonces(sig.signer), + sig.deadline ) ) ), - signer, - vars.sig + sig.signer, + sig ); } diff --git a/contracts/mocks/MockDeprecatedReferenceModule.sol b/contracts/mocks/MockDeprecatedReferenceModule.sol index 5c9d880..a5bb41b 100644 --- a/contracts/mocks/MockDeprecatedReferenceModule.sol +++ b/contracts/mocks/MockDeprecatedReferenceModule.sol @@ -20,15 +20,15 @@ contract MockDeprecatedReferenceModule is IDeprecatedReferenceModule { function processComment( uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes calldata data ) external override {} function processMirror( uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes calldata data ) external override {} } diff --git a/contracts/mocks/MockReferenceModule.sol b/contracts/mocks/MockReferenceModule.sol index f562c37..5204acc 100644 --- a/contracts/mocks/MockReferenceModule.sol +++ b/contracts/mocks/MockReferenceModule.sol @@ -22,8 +22,8 @@ contract MockReferenceModule is IReferenceModule { function processComment( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, uint256 referrerProfileId, bytes calldata data ) external override {} @@ -31,8 +31,8 @@ contract MockReferenceModule is IReferenceModule { function processQuote( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, uint256 referrerProfileId, bytes calldata data ) external override {} @@ -40,8 +40,8 @@ contract MockReferenceModule is IReferenceModule { function processMirror( uint256 profileId, address executor, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes calldata data ) external override {} } diff --git a/test/foundry/CollectingTest.t.sol b/test/foundry/CollectingTest.t.sol index 47135bb..5a3e895 100644 --- a/test/foundry/CollectingTest.t.sol +++ b/test/foundry/CollectingTest.t.sol @@ -54,7 +54,7 @@ contract CollectingTest_Base is BaseTest, SignatureHelpers, CollectingHelpers, S SigSetup.setUp(); vm.prank(profileOwner); - hub.post(mockPostData); + hub.post(mockPostParams); collectorProfileOwner = vm.addr(collectorProfileOwnerPk); collectorProfileId = _createProfile(collectorProfileOwner); @@ -83,7 +83,7 @@ contract CollectingTest_Generic is CollectingTest_Base { mockCollectData.pubId = 2; // Check that the publication doesn't exist. assertEq( - _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).profileIdPointed, + _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).pointedProfileId, 0 ); @@ -97,7 +97,7 @@ contract CollectingTest_Generic is CollectingTest_Base { mockCollectData.pubId = 0; // Check that the publication doesn't exist. assertEq( - _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).profileIdPointed, + _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).pointedProfileId, 0 ); @@ -139,7 +139,7 @@ contract CollectingTest_Generic is CollectingTest_Base { uint256 startNftId = _checkCollectNFTBefore(); vm.prank(profileOwner); - hub.mirror(mockMirrorData); + hub.mirror(mockMirrorParams); vm.prank(collectorProfileOwner); uint256 nftId = _mockCollect(); @@ -149,16 +149,16 @@ contract CollectingTest_Generic is CollectingTest_Base { function testCollectMirrorOfMirrorPointsToOriginalPost() public { uint256 startNftId = _checkCollectNFTBefore(); - uint256 startMirrorId = mockMirrorData.pubIdPointed; + uint256 startMirrorId = mockMirrorParams.pointedPubId; // mirror once vm.startPrank(profileOwner); - uint256 newPubId = hub.mirror(mockMirrorData); + uint256 newPubId = hub.mirror(mockMirrorParams); assertEq(newPubId, startMirrorId + 1); // mirror again - mockMirrorData.pubIdPointed = newPubId; - newPubId = hub.mirror(mockMirrorData); + mockMirrorParams.pointedPubId = newPubId; + newPubId = hub.mirror(mockMirrorParams); assertEq(newPubId, startMirrorId + 2); // We're expecting a mirror to point at the original post ID @@ -195,7 +195,7 @@ contract CollectingTest_Generic is CollectingTest_Base { // mirror, then delegate power to executor vm.prank(profileOwner); - hub.mirror(mockMirrorData); + hub.mirror(mockMirrorParams); _changeDelegatedExecutorsConfig( collectorProfileOwner, collectorProfileId, @@ -229,7 +229,7 @@ contract CollectingTest_WithSig is CollectingTest_Base { mockCollectData.pubId = 2; // Check that the publication doesn't exist. assertEq( - _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).profileIdPointed, + _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).pointedProfileId, 0 ); @@ -241,7 +241,7 @@ contract CollectingTest_WithSig is CollectingTest_Base { mockCollectData.pubId = 0; // Check that the publication doesn't exist. assertEq( - _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).profileIdPointed, + _getPub(mockCollectData.publisherProfileId, mockCollectData.pubId).pointedProfileId, 0 ); @@ -310,7 +310,7 @@ contract CollectingTest_WithSig is CollectingTest_Base { uint256 startNftId = _checkCollectNFTBefore(); vm.prank(profileOwner); - hub.mirror(mockMirrorData); + hub.mirror(mockMirrorParams); uint256 nftId = _mockCollectWithSig({ delegatedSigner: address(0), @@ -345,7 +345,7 @@ contract CollectingTest_WithSig is CollectingTest_Base { // mirror, then delegate power to executor vm.prank(profileOwner); - hub.mirror(mockMirrorData); + hub.mirror(mockMirrorParams); _changeDelegatedExecutorsConfig( collectorProfileOwner, collectorProfileId, diff --git a/test/foundry/Events.t.sol b/test/foundry/Events.t.sol index c8ac289..257f540 100644 --- a/test/foundry/Events.t.sol +++ b/test/foundry/Events.t.sol @@ -255,56 +255,56 @@ contract EventTest is BaseTest { emit Events.PostCreated( newProfileId, 1, - mockPostData.contentURI, - mockPostData.collectModule, + mockPostParams.contentURI, + mockPostParams.collectModule, '', - mockPostData.referenceModule, + mockPostParams.referenceModule, '', block.timestamp ); - hub.post(mockPostData); + hub.post(mockPostParams); } function testCommentingEmitsExpectedEvents() public { vm.startPrank(profileOwner); - hub.post(mockPostData); + hub.post(mockPostParams); vm.expectEmit(true, true, false, true, address(hub)); emit Events.CommentCreated( newProfileId, 2, - mockCommentData.contentURI, + mockCommentParams.contentURI, newProfileId, 1, '', - mockCommentData.collectModule, + mockCommentParams.collectModule, '', - mockCommentData.referenceModule, + mockCommentParams.referenceModule, '', block.timestamp ); - hub.comment(mockCommentData); + hub.comment(mockCommentParams); vm.stopPrank(); } function testMirroringEmitsExpectedEvents() public { vm.startPrank(profileOwner); - hub.post(mockPostData); + hub.post(mockPostParams); vm.expectEmit(true, true, false, true, address(hub)); emit Events.MirrorCreated({ profileId: newProfileId, pubId: 2, - profileIdPointed: newProfileId, - pubIdPointed: 1, + pointedProfileId: newProfileId, + pointedPubId: 1, referenceModuleData: '', timestamp: block.timestamp }); - hub.mirror(mockMirrorData); + hub.mirror(mockMirrorParams); vm.stopPrank(); } function testCollectingEmitsExpectedEvents() public { vm.startPrank(profileOwner); - hub.post(mockPostData); + hub.post(mockPostParams); uint256 expectedPubId = 1; address expectedCollectNFTAddress = predictContractAddress(address(hub), 0); @@ -360,8 +360,8 @@ contract EventTest is BaseTest { publicationCollectedProfileId: newProfileId, publicationCollectedId: expectedPubId, collectorProfileId: newProfileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: '' }); vm.stopPrank(); @@ -378,8 +378,8 @@ contract EventTest is BaseTest { string memory expectedNFTSymbol = '1-Cl-1'; vm.startPrank(profileOwner); - hub.post(mockPostData); - hub.mirror(mockMirrorData); + hub.post(mockPostParams); + hub.mirror(mockMirrorParams); // BaseInitialized vm.expectEmit(false, false, false, true, expectedCollectNFTAddress); @@ -430,8 +430,8 @@ contract EventTest is BaseTest { publicationCollectedProfileId: 1, publicationCollectedId: expectedPubId, collectorProfileId: newProfileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: '' }); vm.stopPrank(); diff --git a/test/foundry/MultiStateHubTest.t.sol b/test/foundry/MultiStateHubTest.t.sol index fd5b26f..d47e8fe 100644 --- a/test/foundry/MultiStateHubTest.t.sol +++ b/test/foundry/MultiStateHubTest.t.sol @@ -118,7 +118,7 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest { followerProfileId = _createProfile(me); vm.prank(profileOwner); - postId = _post(mockPostData); + postId = _post(mockPostParams); vm.prank(governance); _setState(DataTypes.ProtocolState.Paused); @@ -145,19 +145,19 @@ contract MultiStateHubTest_PausedState_Direct is BaseTest { function _mockPost() internal virtual { vm.prank(profileOwner); - _post(mockPostData); + _post(mockPostParams); } function _mockComment() internal virtual { - mockCommentData.pubIdPointed = postId; + mockCommentParams.pointedPubId = postId; vm.prank(profileOwner); - _comment(mockCommentData); + _comment(mockCommentParams); } function _mockMirror() internal virtual { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); - _mirror(mockMirrorData); + _mirror(mockMirrorParams); } function _mockBurn() internal virtual { @@ -400,38 +400,38 @@ contract MultiStateHubTest_PausedState_WithSig is } function _mockPost() internal override { - bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline); + bytes32 digest = _getPostTypedDataHash(mockPostParams, nonce, deadline); _postWithSig( _buildPostWithSigData({ delegatedSigner: address(0), - postData: mockPostData, + postParams: mockPostParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); } function _mockComment() internal override { - mockCommentData.pubIdPointed = postId; - bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline); + mockCommentParams.pointedPubId = postId; + bytes32 digest = _getCommentTypedDataHash(mockCommentParams, nonce, deadline); _commentWithSig( _buildCommentWithSigData({ delegatedSigner: address(0), - commentData: mockCommentData, + commentParams: mockCommentParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); } function _mockMirror() internal override { - mockMirrorData.pubIdPointed = postId; - bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline); + mockMirrorParams.pointedPubId = postId; + bytes32 digest = _getMirrorTypedDataHash(mockMirrorParams, nonce, deadline); _mirrorWithSig( _buildMirrorWithSigData({ delegatedSigner: address(0), - mirrorData: mockMirrorData, + mirrorParams: mockMirrorParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); @@ -500,7 +500,7 @@ contract MultiStateHubTest_PublishingPausedState_Direct is BaseTest { super.setUp(); vm.prank(profileOwner); - postId = _post(mockPostData); + postId = _post(mockPostParams); vm.prank(governance); _setState(DataTypes.ProtocolState.PublishingPaused); @@ -527,19 +527,19 @@ contract MultiStateHubTest_PublishingPausedState_Direct is BaseTest { function _mockPost() internal virtual { vm.prank(profileOwner); - _post(mockPostData); + _post(mockPostParams); } function _mockComment() internal virtual { - mockCommentData.pubIdPointed = postId; + mockCommentParams.pointedPubId = postId; vm.prank(profileOwner); - _comment(mockCommentData); + _comment(mockCommentParams); } function _mockMirror() internal virtual { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); - _mirror(mockMirrorData); + _mirror(mockMirrorParams); } function _mockBurn() internal virtual { @@ -729,38 +729,38 @@ contract MultiStateHubTest_PublishingPausedState_WithSig is } function _mockPost() internal override { - bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, deadline); + bytes32 digest = _getPostTypedDataHash(mockPostParams, nonce, deadline); _postWithSig( _buildPostWithSigData({ delegatedSigner: address(0), - postData: mockPostData, + postParams: mockPostParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); } function _mockComment() internal override { - mockCommentData.pubIdPointed = postId; - bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, deadline); + mockCommentParams.pointedPubId = postId; + bytes32 digest = _getCommentTypedDataHash(mockCommentParams, nonce, deadline); _commentWithSig( _buildCommentWithSigData({ delegatedSigner: address(0), - commentData: mockCommentData, + commentParams: mockCommentParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); } function _mockMirror() internal override { - mockMirrorData.pubIdPointed = postId; - bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, deadline); + mockMirrorParams.pointedPubId = postId; + bytes32 digest = _getMirrorTypedDataHash(mockMirrorParams, nonce, deadline); _mirrorWithSig( _buildMirrorWithSigData({ delegatedSigner: address(0), - mirrorData: mockMirrorData, + mirrorParams: mockMirrorParams, sig: _getSigStruct(profileOwnerKey, digest, deadline) }) ); diff --git a/test/foundry/PublishingTest.t.sol b/test/foundry/PublishingTest.t.sol index a03ae3f..a4aafd1 100644 --- a/test/foundry/PublishingTest.t.sol +++ b/test/foundry/PublishingTest.t.sol @@ -45,7 +45,7 @@ abstract contract PublishingTest is BaseTest, SignatureHelpers, PublishingHelper } function testCannotPublishNotWhitelistedCollectModule() public virtual { - mockPostData.collectModule = address(0xC0FFEE); + mockPostParams.collectModule = address(0xC0FFEE); replicateInitData(); vm.prank(profileOwner); vm.expectRevert(Errors.CollectModuleNotWhitelisted.selector); @@ -53,7 +53,7 @@ abstract contract PublishingTest is BaseTest, SignatureHelpers, PublishingHelper } function testCannotPublishNotWhitelistedReferenceModule() public virtual { - mockPostData.referenceModule = address(0xC0FFEE); + mockPostParams.referenceModule = address(0xC0FFEE); replicateInitData(); vm.prank(profileOwner); vm.expectRevert(Errors.ReferenceModuleNotWhitelisted.selector); @@ -61,14 +61,14 @@ abstract contract PublishingTest is BaseTest, SignatureHelpers, PublishingHelper } function testCannotPublishWithSigNotWhitelistedCollectModule() public virtual { - mockPostData.collectModule = address(0xC0FFEE); + mockPostParams.collectModule = address(0xC0FFEE); replicateInitData(); vm.expectRevert(Errors.CollectModuleNotWhitelisted.selector); _publishWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); } function testCannotPublishWithSigNotWhitelistedReferenceModule() public virtual { - mockPostData.referenceModule = address(0xC0FFEE); + mockPostParams.referenceModule = address(0xC0FFEE); replicateInitData(); vm.expectRevert(Errors.ReferenceModuleNotWhitelisted.selector); _publishWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); @@ -139,8 +139,8 @@ abstract contract PublishingTest is BaseTest, SignatureHelpers, PublishingHelper } function testPublishWithAWhitelistedReferenceModule() public { - mockPostData.referenceModule = address(mockReferenceModule); - mockPostData.referenceModuleInitData = abi.encode(1); + mockPostParams.referenceModule = address(mockReferenceModule); + mockPostParams.referenceModuleInitData = abi.encode(1); replicateInitData(); uint256 expectedPubId = _getPubCount(newProfileId) + 1; @@ -197,7 +197,7 @@ abstract contract PublishingTest is BaseTest, SignatureHelpers, PublishingHelper contract PostTest is PublishingTest { function _publish() internal virtual override returns (uint256) { - return _post(mockPostData); + return _post(mockPostParams); } function _publishWithSig( @@ -206,13 +206,13 @@ contract PostTest is PublishingTest { uint256 digestDeadline, uint256 sigDeadline ) internal virtual override returns (uint256) { - bytes32 digest = _getPostTypedDataHash(mockPostData, nonce, digestDeadline); + bytes32 digest = _getPostTypedDataHash(mockPostParams, nonce, digestDeadline); return _postWithSig( _buildPostWithSigData( delegatedSigner, - mockPostData, + mockPostParams, _getSigStruct(signerPrivKey, digest, sigDeadline) ) ); @@ -225,7 +225,7 @@ contract PostTest is PublishingTest { override returns (DataTypes.PublicationStruct memory) { - return _expectedPubFromInitData(mockPostData); + return _expectedPubFromInitData(mockPostParams); } } @@ -233,16 +233,16 @@ contract CommentTest is PublishingTest { uint256 postId; function replicateInitData() internal override { - mockCommentData.profileId = mockPostData.profileId; - mockCommentData.contentURI = mockPostData.contentURI; - mockCommentData.collectModule = mockPostData.collectModule; - mockCommentData.collectModuleInitData = mockPostData.collectModuleInitData; - mockCommentData.referenceModule = mockPostData.referenceModule; - mockCommentData.referenceModuleInitData = mockPostData.referenceModuleInitData; + mockCommentParams.profileId = mockPostParams.profileId; + mockCommentParams.contentURI = mockPostParams.contentURI; + mockCommentParams.collectModule = mockPostParams.collectModule; + mockCommentParams.collectModuleInitData = mockPostParams.collectModuleInitData; + mockCommentParams.referenceModule = mockPostParams.referenceModule; + mockCommentParams.referenceModuleInitData = mockPostParams.referenceModuleInitData; } function _publish() internal override returns (uint256) { - return _comment(mockCommentData); + return _comment(mockCommentParams); } function _publishWithSig( @@ -251,13 +251,13 @@ contract CommentTest is PublishingTest { uint256 digestDeadline, uint256 sigDeadline ) internal override returns (uint256) { - bytes32 digest = _getCommentTypedDataHash(mockCommentData, nonce, digestDeadline); + bytes32 digest = _getCommentTypedDataHash(mockCommentParams, nonce, digestDeadline); return _commentWithSig( _buildCommentWithSigData( delegatedSigner, - mockCommentData, + mockCommentParams, _getSigStruct(signerPrivKey, digest, sigDeadline) ) ); @@ -269,14 +269,14 @@ contract CommentTest is PublishingTest { override returns (DataTypes.PublicationStruct memory) { - return _expectedPubFromInitData(mockCommentData); + return _expectedPubFromInitData(mockCommentParams); } function setUp() public override { PublishingTest.setUp(); vm.prank(profileOwner); - postId = _post(mockPostData); + postId = _post(mockPostParams); } // negatives @@ -284,7 +284,7 @@ contract CommentTest is PublishingTest { uint256 nonExistentPubId = _getPubCount(newProfileId) + 10; replicateInitData(); - mockCommentData.pubIdPointed = nonExistentPubId; + mockCommentParams.pointedPubId = nonExistentPubId; vm.prank(profileOwner); vm.expectRevert(Errors.PublicationDoesNotExist.selector); @@ -295,7 +295,7 @@ contract CommentTest is PublishingTest { uint256 nonExistentPubId = _getPubCount(newProfileId) + 10; replicateInitData(); - mockCommentData.pubIdPointed = nonExistentPubId; + mockCommentParams.pointedPubId = nonExistentPubId; vm.expectRevert(Errors.PublicationDoesNotExist.selector); _publishWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); @@ -305,7 +305,7 @@ contract CommentTest is PublishingTest { uint256 nextPubId = _getPubCount(newProfileId) + 1; replicateInitData(); - mockCommentData.pubIdPointed = nextPubId; + mockCommentParams.pointedPubId = nextPubId; vm.prank(profileOwner); vm.expectRevert(Errors.PublicationDoesNotExist.selector); @@ -316,7 +316,7 @@ contract CommentTest is PublishingTest { uint256 nextPubId = _getPubCount(newProfileId) + 1; replicateInitData(); - mockCommentData.pubIdPointed = nextPubId; + mockCommentParams.pointedPubId = nextPubId; vm.expectRevert(Errors.PublicationDoesNotExist.selector); _publishWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); @@ -324,10 +324,10 @@ contract CommentTest is PublishingTest { function testCannotCommentIfBlocked() public { uint256 commenterProfileId = _createProfile(profileOwner); - mockCommentData.profileId = commenterProfileId; + mockCommentParams.profileId = commenterProfileId; vm.prank(profileOwner); hub.setBlockStatus( - mockPostData.profileId, + mockPostParams.profileId, _toUint256Array(commenterProfileId), _toBoolArray(true) ); @@ -338,10 +338,10 @@ contract CommentTest is PublishingTest { function testCannotCommentWithSigIfBlocked() public { uint256 commenterProfileId = _createProfile(profileOwner); - mockCommentData.profileId = commenterProfileId; + mockCommentParams.profileId = commenterProfileId; vm.prank(profileOwner); hub.setBlockStatus( - mockPostData.profileId, + mockPostParams.profileId, _toUint256Array(commenterProfileId), _toBoolArray(true) ); @@ -351,12 +351,12 @@ contract CommentTest is PublishingTest { // scenarios function testPostWithReferenceModuleAndComment() public { - mockPostData.referenceModule = address(mockReferenceModule); - mockPostData.referenceModuleInitData = abi.encode(1); + mockPostParams.referenceModule = address(mockReferenceModule); + mockPostParams.referenceModuleInitData = abi.encode(1); vm.prank(profileOwner); - postId = _post(mockPostData); + postId = _post(mockPostParams); - mockCommentData.pubIdPointed = postId; + mockCommentParams.pointedPubId = postId; vm.prank(profileOwner); uint256 commentPubId = _publish(); @@ -365,33 +365,33 @@ contract CommentTest is PublishingTest { } function testCommentOnMirrorShouldPointToOriginalPost() public { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); - uint256 mirrorId = _mirror(mockMirrorData); + uint256 mirrorId = _mirror(mockMirrorParams); - mockCommentData.pubIdPointed = mirrorId; + mockCommentParams.pointedPubId = mirrorId; vm.prank(profileOwner); uint256 commentId = _publish(); DataTypes.PublicationStruct memory pub = _getPub(newProfileId, commentId); - mockCommentData.pubIdPointed = postId; // We're expecting a mirror to point at the original post ID - _verifyPublication(pub, _expectedPubFromInitData(mockCommentData)); + mockCommentParams.pointedPubId = postId; // We're expecting a mirror to point at the original post ID + _verifyPublication(pub, _expectedPubFromInitData(mockCommentParams)); } function testCommentWithSigOnMirrorShouldPointToOriginalPost() public { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); - uint256 mirrorId = _mirror(mockMirrorData); + uint256 mirrorId = _mirror(mockMirrorParams); - mockCommentData.pubIdPointed = mirrorId; + mockCommentParams.pointedPubId = mirrorId; uint256 commentId = _publishWithSig({ delegatedSigner: address(0), signerPrivKey: profileOwnerKey }); DataTypes.PublicationStruct memory pub = _getPub(newProfileId, commentId); - mockCommentData.pubIdPointed = postId; // We're expecting a mirror to point at the original post ID - _verifyPublication(pub, _expectedPubFromInitData(mockCommentData)); + mockCommentParams.pointedPubId = postId; // We're expecting a mirror to point at the original post ID + _verifyPublication(pub, _expectedPubFromInitData(mockCommentParams)); } } @@ -399,11 +399,11 @@ contract MirrorTest is PublishingTest { uint256 postId; function replicateInitData() internal override { - mockMirrorData.profileId = mockPostData.profileId; + mockMirrorParams.profileId = mockPostParams.profileId; } function _publish() internal override returns (uint256) { - return _mirror(mockMirrorData); + return _mirror(mockMirrorParams); } function _publishWithSig( @@ -412,13 +412,13 @@ contract MirrorTest is PublishingTest { uint256 digestDeadline, uint256 sigDeadline ) internal override returns (uint256) { - bytes32 digest = _getMirrorTypedDataHash(mockMirrorData, nonce, digestDeadline); + bytes32 digest = _getMirrorTypedDataHash(mockMirrorParams, nonce, digestDeadline); return _mirrorWithSig( _buildMirrorWithSigData( delegatedSigner, - mockMirrorData, + mockMirrorParams, _getSigStruct(signerPrivKey, digest, sigDeadline) ) ); @@ -430,14 +430,14 @@ contract MirrorTest is PublishingTest { override returns (DataTypes.PublicationStruct memory) { - return _expectedPubFromInitData(mockMirrorData); + return _expectedPubFromInitData(mockMirrorParams); } function setUp() public override { PublishingTest.setUp(); vm.prank(profileOwner); - postId = _post(mockPostData); + postId = _post(mockPostParams); } // ignored - these tests don't apply to mirrors @@ -455,7 +455,7 @@ contract MirrorTest is PublishingTest { uint256 nonExistentPubId = _getPubCount(newProfileId) + 10; replicateInitData(); - mockMirrorData.pubIdPointed = nonExistentPubId; + mockMirrorParams.pointedPubId = nonExistentPubId; vm.prank(profileOwner); vm.expectRevert(Errors.PublicationDoesNotExist.selector); @@ -466,7 +466,7 @@ contract MirrorTest is PublishingTest { uint256 nonExistentPubId = _getPubCount(newProfileId) + 10; replicateInitData(); - mockMirrorData.pubIdPointed = nonExistentPubId; + mockMirrorParams.pointedPubId = nonExistentPubId; vm.expectRevert(Errors.PublicationDoesNotExist.selector); _publishWithSig({delegatedSigner: address(0), signerPrivKey: profileOwnerKey}); @@ -474,10 +474,10 @@ contract MirrorTest is PublishingTest { function testCannotMirrorIfBlocked() public { uint256 mirrorerProfileId = _createProfile(profileOwner); - mockMirrorData.profileId = mirrorerProfileId; + mockMirrorParams.profileId = mirrorerProfileId; vm.prank(profileOwner); hub.setBlockStatus( - mockPostData.profileId, + mockPostParams.profileId, _toUint256Array(mirrorerProfileId), _toBoolArray(true) ); @@ -488,10 +488,10 @@ contract MirrorTest is PublishingTest { function testCannotMirrorWithSigIfBlocked() public { uint256 mirrorerProfileId = _createProfile(profileOwner); - mockMirrorData.profileId = mirrorerProfileId; + mockMirrorParams.profileId = mirrorerProfileId; vm.prank(profileOwner); hub.setBlockStatus( - mockPostData.profileId, + mockPostParams.profileId, _toUint256Array(mirrorerProfileId), _toBoolArray(true) ); @@ -501,32 +501,32 @@ contract MirrorTest is PublishingTest { // scenarios function testMirrorAnotherMirrorShouldPointToOriginalPost() public { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); uint256 firstMirrorId = _publish(); - mockMirrorData.pubIdPointed = firstMirrorId; + mockMirrorParams.pointedPubId = firstMirrorId; vm.prank(profileOwner); uint256 secondMirrorId = _publish(); DataTypes.PublicationStruct memory pub = _getPub(newProfileId, secondMirrorId); - mockMirrorData.pubIdPointed = postId; // We're expecting a mirror to point at the original post ID - _verifyPublication(pub, _expectedPubFromInitData(mockMirrorData)); + mockMirrorParams.pointedPubId = postId; // We're expecting a mirror to point at the original post ID + _verifyPublication(pub, _expectedPubFromInitData(mockMirrorParams)); } function testMirrorAnotherMirrorWithSigShouldPointToOriginalPost() public { - mockMirrorData.pubIdPointed = postId; + mockMirrorParams.pointedPubId = postId; vm.prank(profileOwner); uint256 firstMirrorId = _publish(); - mockMirrorData.pubIdPointed = firstMirrorId; + mockMirrorParams.pointedPubId = firstMirrorId; uint256 secondMirrorId = _publishWithSig({ delegatedSigner: address(0), signerPrivKey: profileOwnerKey }); DataTypes.PublicationStruct memory pub = _getPub(newProfileId, secondMirrorId); - mockMirrorData.pubIdPointed = postId; // We're expecting a mirror to point at the original post ID - _verifyPublication(pub, _expectedPubFromInitData(mockMirrorData)); + mockMirrorParams.pointedPubId = postId; // We're expecting a mirror to point at the original post ID + _verifyPublication(pub, _expectedPubFromInitData(mockMirrorParams)); } } diff --git a/test/foundry/base/BaseTest.t.sol b/test/foundry/base/BaseTest.t.sol index 81558ae..6a77f26 100644 --- a/test/foundry/base/BaseTest.t.sol +++ b/test/foundry/base/BaseTest.t.sol @@ -141,18 +141,18 @@ contract BaseTest is TestSetup { } function _getPostTypedDataHash( - DataTypes.PostData memory postData, + DataTypes.PostParams memory postParams, uint256 nonce, uint256 deadline ) internal view returns (bytes32) { return _getPostTypedDataHash({ - profileId: postData.profileId, - contentURI: postData.contentURI, - collectModule: postData.collectModule, - collectModuleInitData: postData.collectModuleInitData, - referenceModule: postData.referenceModule, - referenceModuleInitData: postData.referenceModuleInitData, + profileId: postParams.profileId, + contentURI: postParams.contentURI, + collectModule: postParams.collectModule, + collectModuleInitData: postParams.collectModuleInitData, + referenceModule: postParams.referenceModule, + referenceModuleInitData: postParams.referenceModuleInitData, nonce: nonce, deadline: deadline }); @@ -161,8 +161,8 @@ contract BaseTest is TestSetup { function _getCommentTypedDataHash( uint256 profileId, string memory contentURI, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes memory referenceModuleData, address collectModule, bytes memory collectModuleInitData, @@ -176,8 +176,8 @@ contract BaseTest is TestSetup { COMMENT_WITH_SIG_TYPEHASH, profileId, keccak256(bytes(contentURI)), - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, keccak256(referenceModuleData), collectModule, keccak256(collectModuleInitData), @@ -191,21 +191,21 @@ contract BaseTest is TestSetup { } function _getCommentTypedDataHash( - DataTypes.CommentData memory commentData, + DataTypes.CommentParams memory commentParams, uint256 nonce, uint256 deadline ) internal view returns (bytes32) { return _getCommentTypedDataHash({ - profileId: commentData.profileId, - contentURI: commentData.contentURI, - profileIdPointed: commentData.profileIdPointed, - pubIdPointed: commentData.pubIdPointed, - referenceModuleData: commentData.referenceModuleData, - collectModule: commentData.collectModule, - collectModuleInitData: commentData.collectModuleInitData, - referenceModule: commentData.referenceModule, - referenceModuleInitData: commentData.referenceModuleInitData, + profileId: commentParams.profileId, + contentURI: commentParams.contentURI, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + referenceModuleData: commentParams.referenceModuleData, + collectModule: commentParams.collectModule, + collectModuleInitData: commentParams.collectModuleInitData, + referenceModule: commentParams.referenceModule, + referenceModuleInitData: commentParams.referenceModuleInitData, nonce: nonce, deadline: deadline }); @@ -213,8 +213,8 @@ contract BaseTest is TestSetup { function _getMirrorTypedDataHash( uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes memory referenceModuleData, uint256 nonce, uint256 deadline @@ -223,8 +223,8 @@ contract BaseTest is TestSetup { abi.encode( MIRROR_WITH_SIG_TYPEHASH, profileId, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, keccak256(referenceModuleData), nonce, deadline @@ -234,16 +234,16 @@ contract BaseTest is TestSetup { } function _getMirrorTypedDataHash( - DataTypes.MirrorData memory mirrorData, + DataTypes.MirrorParams memory mirrorParams, uint256 nonce, uint256 deadline ) internal view returns (bytes32) { return _getMirrorTypedDataHash({ - profileId: mirrorData.profileId, - profileIdPointed: mirrorData.profileIdPointed, - pubIdPointed: mirrorData.pubIdPointed, - referenceModuleData: mirrorData.referenceModuleData, + profileId: mirrorParams.profileId, + pointedProfileId: mirrorParams.pointedProfileId, + pointedPubId: mirrorParams.pointedPubId, + referenceModuleData: mirrorParams.referenceModuleData, nonce: nonce, deadline: deadline }); @@ -392,16 +392,16 @@ contract BaseTest is TestSetup { ); } - function _post(DataTypes.PostData memory postData) internal returns (uint256) { - return hub.post(postData); + function _post(DataTypes.PostParams memory postParams) internal returns (uint256) { + return hub.post(postParams); } - function _comment(DataTypes.CommentData memory commentData) internal returns (uint256) { - return hub.comment(commentData); + function _comment(DataTypes.CommentParams memory commentParams) internal returns (uint256) { + return hub.comment(commentParams); } - function _mirror(DataTypes.MirrorData memory mirrorData) internal returns (uint256) { - return hub.mirror(mirrorData); + function _mirror(DataTypes.MirrorParams memory mirrorParams) internal returns (uint256) { + return hub.mirror(mirrorParams); } function _collect( @@ -415,8 +415,8 @@ contract BaseTest is TestSetup { publicationCollectedProfileId: publisherProfileId, publicationCollectedId: pubId, collectorProfileId: collectorProfileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: data }); } diff --git a/test/foundry/base/TestSetup.t.sol b/test/foundry/base/TestSetup.t.sol index c44a857..c222fc3 100644 --- a/test/foundry/base/TestSetup.t.sol +++ b/test/foundry/base/TestSetup.t.sol @@ -57,9 +57,9 @@ contract TestSetup is Test, ForkManagement { DataTypes.CreateProfileData mockCreateProfileData; - DataTypes.PostData mockPostData; - DataTypes.CommentData mockCommentData; - DataTypes.MirrorData mockMirrorData; + DataTypes.PostParams mockPostParams; + DataTypes.CommentParams mockCommentParams; + DataTypes.MirrorParams mockMirrorParams; DataTypes.CollectData mockCollectData; function isEnvSet(string memory key) internal returns (bool) { @@ -233,7 +233,7 @@ contract TestSetup is Test, ForkManagement { }); // Precompute basic post data. - mockPostData = DataTypes.PostData({ + mockPostParams = DataTypes.PostParams({ profileId: newProfileId, contentURI: MOCK_URI, collectModule: address(mockCollectModule), @@ -243,11 +243,11 @@ contract TestSetup is Test, ForkManagement { }); // Precompute basic comment data. - mockCommentData = DataTypes.CommentData({ + mockCommentParams = DataTypes.CommentParams({ profileId: newProfileId, contentURI: MOCK_URI, - profileIdPointed: newProfileId, - pubIdPointed: FIRST_PUB_ID, + pointedProfileId: newProfileId, + pointedPubId: FIRST_PUB_ID, referenceModuleData: '', collectModule: address(mockCollectModule), collectModuleInitData: abi.encode(1), @@ -256,10 +256,10 @@ contract TestSetup is Test, ForkManagement { }); // Precompute basic mirror data. - mockMirrorData = DataTypes.MirrorData({ + mockMirrorParams = DataTypes.MirrorParams({ profileId: newProfileId, - profileIdPointed: newProfileId, - pubIdPointed: FIRST_PUB_ID, + pointedProfileId: newProfileId, + pointedPubId: FIRST_PUB_ID, referenceModuleData: '' }); diff --git a/test/foundry/fork/UpgradeForkTest.t.sol b/test/foundry/fork/UpgradeForkTest.t.sol index 915db81..026c2b6 100644 --- a/test/foundry/fork/UpgradeForkTest.t.sol +++ b/test/foundry/fork/UpgradeForkTest.t.sol @@ -24,10 +24,10 @@ struct OldCreateProfileData { string followNFTURI; } -struct OldMirrorData { +struct OldMirrorParams { uint256 profileId; - uint256 profileIdPointed; - uint256 pubIdPointed; + uint256 pointedProfileId; + uint256 pointedPubId; bytes referenceModuleData; address referenceModule; bytes referenceModuleInitData; @@ -36,7 +36,7 @@ struct OldMirrorData { interface IOldHub { function createProfile(OldCreateProfileData memory vars) external returns (uint256); - function mirror(OldMirrorData memory vars) external returns (uint256); + function mirror(OldMirrorParams memory vars) external returns (uint256); function follow(uint256[] calldata profileIds, bytes[] calldata datas) external; @@ -185,60 +185,60 @@ contract UpgradeForkTest is BaseTest { // Set the proper initial params, these must be redundantly reset as they may have been set // to different values in memory. - mockPostData.profileId = profileId; - mockPostData.collectModule = mockCollectModuleAddr; - mockPostData.referenceModule = mockReferenceModuleAddr; + mockPostParams.profileId = profileId; + mockPostParams.collectModule = mockCollectModuleAddr; + mockPostParams.referenceModule = mockReferenceModuleAddr; - mockCommentData.profileId = profileId; - mockCommentData.profileIdPointed = profileId; + mockCommentParams.profileId = profileId; + mockCommentParams.pointedProfileId = profileId; - mockMirrorData.profileId = profileId; - mockMirrorData.profileIdPointed = profileId; + mockMirrorParams.profileId = profileId; + mockMirrorParams.pointedProfileId = profileId; // Set the modern reference module, the modern collect module is already set by default. - mockPostData.referenceModule = mockReferenceModuleAddr; + mockPostParams.referenceModule = mockReferenceModuleAddr; - try hub.post(mockPostData) returns (uint256 retPubId) { + try hub.post(mockPostParams) returns (uint256 retPubId) { console2.log( 'Post published with modern collect and reference module, continuing with modern modules.' ); uint256 postId = retPubId; assertEq(postId, 1); - mockCommentData.collectModule = mockCollectModuleAddr; - mockCommentData.referenceModule = mockReferenceModuleAddr; + mockCommentParams.collectModule = mockCollectModuleAddr; + mockCommentParams.referenceModule = mockReferenceModuleAddr; // Validate post. assertEq(postId, 1); DataTypes.PublicationStruct memory pub = hub.getPub(profileId, postId); - assertEq(pub.profileIdPointed, 0); - assertEq(pub.pubIdPointed, 0); - assertEq(pub.contentURI, mockPostData.contentURI); - assertEq(pub.referenceModule, mockPostData.referenceModule); - assertEq(pub.collectModule, mockPostData.collectModule); + assertEq(pub.pointedProfileId, 0); + assertEq(pub.pointedPubId, 0); + assertEq(pub.contentURI, mockPostParams.contentURI); + assertEq(pub.referenceModule, mockPostParams.referenceModule); + assertEq(pub.collectModule, mockPostParams.collectModule); assertEq(pub.collectNFT, address(0)); // Comment. - uint256 commentId = hub.comment(mockCommentData); + uint256 commentId = hub.comment(mockCommentParams); // Validate comment. assertEq(commentId, 2); pub = hub.getPub(profileId, commentId); - assertEq(pub.profileIdPointed, mockCommentData.profileIdPointed); - assertEq(pub.pubIdPointed, mockCommentData.pubIdPointed); - assertEq(pub.contentURI, mockCommentData.contentURI); - assertEq(pub.referenceModule, mockCommentData.referenceModule); - assertEq(pub.collectModule, mockCommentData.collectModule); + assertEq(pub.pointedProfileId, mockCommentParams.pointedProfileId); + assertEq(pub.pointedPubId, mockCommentParams.pointedPubId); + assertEq(pub.contentURI, mockCommentParams.contentURI); + assertEq(pub.referenceModule, mockCommentParams.referenceModule); + assertEq(pub.collectModule, mockCommentParams.collectModule); assertEq(pub.collectNFT, address(0)); // Mirror. - uint256 mirrorId = hub.mirror(mockMirrorData); + uint256 mirrorId = hub.mirror(mockMirrorParams); // Validate mirror. assertEq(mirrorId, 3); pub = hub.getPub(profileId, mirrorId); - assertEq(pub.profileIdPointed, mockMirrorData.profileIdPointed); - assertEq(pub.pubIdPointed, mockMirrorData.pubIdPointed); + assertEq(pub.pointedProfileId, mockMirrorParams.pointedProfileId); + assertEq(pub.pointedPubId, mockMirrorParams.pointedPubId); assertEq(pub.contentURI, ''); assertEq(pub.referenceModule, address(0)); assertEq(pub.collectModule, address(0)); @@ -257,52 +257,52 @@ contract UpgradeForkTest is BaseTest { vm.stopPrank(); // Post. - mockPostData.collectModule = mockDeprecatedCollectModule; - mockPostData.referenceModule = mockDeprecatedReferenceModule; - uint256 postId = hub.post(mockPostData); + mockPostParams.collectModule = mockDeprecatedCollectModule; + mockPostParams.referenceModule = mockDeprecatedReferenceModule; + uint256 postId = hub.post(mockPostParams); // Validate post. assertEq(postId, 1); DataTypes.PublicationStruct memory pub = hub.getPub(profileId, postId); - assertEq(pub.profileIdPointed, 0); - assertEq(pub.pubIdPointed, 0); - assertEq(pub.contentURI, mockPostData.contentURI); - assertEq(pub.referenceModule, mockPostData.referenceModule); - assertEq(pub.collectModule, mockPostData.collectModule); + assertEq(pub.pointedProfileId, 0); + assertEq(pub.pointedPubId, 0); + assertEq(pub.contentURI, mockPostParams.contentURI); + assertEq(pub.referenceModule, mockPostParams.referenceModule); + assertEq(pub.collectModule, mockPostParams.collectModule); assertEq(pub.collectNFT, address(0)); // Comment. - mockCommentData.collectModule = mockDeprecatedCollectModule; - mockCommentData.referenceModule = mockDeprecatedReferenceModule; - uint256 commentId = hub.comment(mockCommentData); + mockCommentParams.collectModule = mockDeprecatedCollectModule; + mockCommentParams.referenceModule = mockDeprecatedReferenceModule; + uint256 commentId = hub.comment(mockCommentParams); // Validate comment. assertEq(commentId, 2); pub = hub.getPub(profileId, commentId); - assertEq(pub.profileIdPointed, mockCommentData.profileIdPointed); - assertEq(pub.pubIdPointed, mockCommentData.pubIdPointed); - assertEq(pub.contentURI, mockCommentData.contentURI); - assertEq(pub.referenceModule, mockCommentData.referenceModule); - assertEq(pub.collectModule, mockCommentData.collectModule); + assertEq(pub.pointedProfileId, mockCommentParams.pointedProfileId); + assertEq(pub.pointedPubId, mockCommentParams.pointedPubId); + assertEq(pub.contentURI, mockCommentParams.contentURI); + assertEq(pub.referenceModule, mockCommentParams.referenceModule); + assertEq(pub.collectModule, mockCommentParams.collectModule); assertEq(pub.collectNFT, address(0)); // Mirror. - OldMirrorData memory oldMirrorData = OldMirrorData({ - profileId: mockMirrorData.profileId, - profileIdPointed: mockMirrorData.profileIdPointed, - pubIdPointed: mockMirrorData.pubIdPointed, - referenceModuleData: mockMirrorData.referenceModuleData, + OldMirrorParams memory oldMirrorParams = OldMirrorParams({ + profileId: mockMirrorParams.profileId, + pointedProfileId: mockMirrorParams.pointedProfileId, + pointedPubId: mockMirrorParams.pointedPubId, + referenceModuleData: mockMirrorParams.referenceModuleData, referenceModule: mockDeprecatedReferenceModule, - referenceModuleInitData: mockCommentData.referenceModuleInitData + referenceModuleInitData: mockCommentParams.referenceModuleInitData }); - uint256 mirrorId = IOldHub(address(hub)).mirror(oldMirrorData); + uint256 mirrorId = IOldHub(address(hub)).mirror(oldMirrorParams); // Validate mirror. assertEq(mirrorId, 3); pub = hub.getPub(profileId, mirrorId); - assertEq(pub.profileIdPointed, mockMirrorData.profileIdPointed); - assertEq(pub.pubIdPointed, mockMirrorData.pubIdPointed); + assertEq(pub.pointedProfileId, mockMirrorParams.pointedProfileId); + assertEq(pub.pointedPubId, mockMirrorParams.pointedPubId); assertEq(pub.contentURI, ''); assertEq(pub.referenceModule, mockDeprecatedReferenceModule); assertEq(pub.collectModule, address(0)); @@ -333,24 +333,24 @@ contract UpgradeForkTest is BaseTest { publicationCollectedProfileId: profileId, publicationCollectedId: 1, collectorProfileId: profileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: '' }); hub.collect({ publicationCollectedProfileId: profileId, publicationCollectedId: 2, collectorProfileId: profileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: '' }); hub.collect({ publicationCollectedProfileId: profileId, publicationCollectedId: 3, collectorProfileId: profileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, data: '' }); } catch { @@ -419,7 +419,7 @@ contract UpgradeForkTest is BaseTest { }); // Precompute basic post data. - mockPostData = DataTypes.PostData({ + mockPostParams = DataTypes.PostParams({ profileId: 0, contentURI: MOCK_URI, collectModule: address(0), @@ -429,11 +429,11 @@ contract UpgradeForkTest is BaseTest { }); // Precompute basic comment data. - mockCommentData = DataTypes.CommentData({ + mockCommentParams = DataTypes.CommentParams({ profileId: 0, contentURI: MOCK_URI, - profileIdPointed: newProfileId, - pubIdPointed: 1, + pointedProfileId: newProfileId, + pointedPubId: 1, referenceModuleData: '', collectModule: address(0), collectModuleInitData: abi.encode(1), @@ -442,10 +442,10 @@ contract UpgradeForkTest is BaseTest { }); // Precompute basic mirror data. - mockMirrorData = DataTypes.MirrorData({ + mockMirrorParams = DataTypes.MirrorParams({ profileId: 0, - profileIdPointed: newProfileId, - pubIdPointed: 1, + pointedProfileId: newProfileId, + pointedPubId: 1, referenceModuleData: '' }); } diff --git a/test/foundry/helpers/PublishingHelpers.sol b/test/foundry/helpers/PublishingHelpers.sol index 725cb63..e3ad4e8 100644 --- a/test/foundry/helpers/PublishingHelpers.sol +++ b/test/foundry/helpers/PublishingHelpers.sol @@ -9,26 +9,26 @@ contract PublishingHelpers is Test { DataTypes.PublicationStruct memory pub, DataTypes.PublicationStruct memory expectedPub ) internal { - assertEq(pub.profileIdPointed, expectedPub.profileIdPointed, 'Unexpected profileIdPointed'); - assertEq(pub.pubIdPointed, expectedPub.pubIdPointed, 'Unexpected pubIdPointed'); + assertEq(pub.pointedProfileId, expectedPub.pointedProfileId, 'Unexpected pointedProfileId'); + assertEq(pub.pointedPubId, expectedPub.pointedPubId, 'Unexpected pointedPubId'); assertEq(pub.contentURI, expectedPub.contentURI, 'Unexpected contentURI'); assertEq(pub.referenceModule, expectedPub.referenceModule, 'Unexpected referenceModule'); assertEq(pub.collectModule, expectedPub.collectModule, 'Unexpected collectModule'); assertEq(pub.collectNFT, expectedPub.collectNFT, 'Unexpected collectNFT'); } - function _expectedPubFromInitData(DataTypes.PostData memory postData) + function _expectedPubFromInitData(DataTypes.PostParams memory postParams) internal pure returns (DataTypes.PublicationStruct memory) { return DataTypes.PublicationStruct({ - profileIdPointed: 0, - pubIdPointed: 0, - contentURI: postData.contentURI, - referenceModule: postData.referenceModule, - collectModule: postData.collectModule, + pointedProfileId: 0, + pointedPubId: 0, + contentURI: postParams.contentURI, + referenceModule: postParams.referenceModule, + collectModule: postParams.collectModule, collectNFT: address(0), pubType: DataTypes.PublicationType.Post, rootProfileId: 0, @@ -36,41 +36,41 @@ contract PublishingHelpers is Test { }); } - function _expectedPubFromInitData(DataTypes.CommentData memory commentData) + function _expectedPubFromInitData(DataTypes.CommentParams memory commentParams) internal pure returns (DataTypes.PublicationStruct memory) { return DataTypes.PublicationStruct({ - profileIdPointed: commentData.profileIdPointed, - pubIdPointed: commentData.pubIdPointed, - contentURI: commentData.contentURI, - referenceModule: commentData.referenceModule, - collectModule: commentData.collectModule, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + contentURI: commentParams.contentURI, + referenceModule: commentParams.referenceModule, + collectModule: commentParams.collectModule, collectNFT: address(0), pubType: DataTypes.PublicationType.Comment, - rootProfileId: commentData.profileIdPointed, - rootPubId: commentData.pubIdPointed + rootProfileId: commentParams.pointedProfileId, + rootPubId: commentParams.pointedPubId }); } - function _expectedPubFromInitData(DataTypes.MirrorData memory mirrorData) + function _expectedPubFromInitData(DataTypes.MirrorParams memory mirrorParams) internal pure returns (DataTypes.PublicationStruct memory) { return DataTypes.PublicationStruct({ - profileIdPointed: mirrorData.profileIdPointed, - pubIdPointed: mirrorData.pubIdPointed, + pointedProfileId: mirrorParams.pointedProfileId, + pointedPubId: mirrorParams.pointedPubId, contentURI: '', referenceModule: address(0), collectModule: address(0), collectNFT: address(0), pubType: DataTypes.PublicationType.Mirror, - rootProfileId: mirrorData.profileIdPointed, - rootPubId: mirrorData.pubIdPointed + rootProfileId: mirrorParams.pointedProfileId, + rootPubId: mirrorParams.pointedPubId }); } } diff --git a/test/foundry/helpers/SignatureHelpers.sol b/test/foundry/helpers/SignatureHelpers.sol index 891f1f1..53bfcbb 100644 --- a/test/foundry/helpers/SignatureHelpers.sol +++ b/test/foundry/helpers/SignatureHelpers.sol @@ -40,18 +40,18 @@ contract SignatureHelpers { function _buildPostWithSigData( address delegatedSigner, - DataTypes.PostData memory postData, + DataTypes.PostParams memory postParams, DataTypes.EIP712Signature memory sig ) internal pure returns (DataTypes.PostWithSigData memory) { return _buildPostWithSigData( delegatedSigner, - postData.profileId, - postData.contentURI, - postData.collectModule, - postData.collectModuleInitData, - postData.referenceModule, - postData.referenceModuleInitData, + postParams.profileId, + postParams.contentURI, + postParams.collectModule, + postParams.collectModuleInitData, + postParams.referenceModule, + postParams.referenceModuleInitData, sig ); } @@ -60,8 +60,8 @@ contract SignatureHelpers { address delegatedSigner, uint256 profileId, string memory contentURI, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes memory referenceModuleData, address collectModule, bytes memory collectModuleInitData, @@ -74,8 +74,8 @@ contract SignatureHelpers { delegatedSigner, profileId, contentURI, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData, collectModule, collectModuleInitData, @@ -87,21 +87,21 @@ contract SignatureHelpers { function _buildCommentWithSigData( address delegatedSigner, - DataTypes.CommentData memory commentData, + DataTypes.CommentParams memory commentParams, DataTypes.EIP712Signature memory sig ) internal pure returns (DataTypes.CommentWithSigData memory) { return _buildCommentWithSigData({ delegatedSigner: delegatedSigner, - profileId: commentData.profileId, - contentURI: commentData.contentURI, - profileIdPointed: commentData.profileIdPointed, - pubIdPointed: commentData.pubIdPointed, - referenceModuleData: commentData.referenceModuleData, - collectModule: commentData.collectModule, - collectModuleInitData: commentData.collectModuleInitData, - referenceModule: commentData.referenceModule, - referenceModuleInitData: commentData.referenceModuleInitData, + profileId: commentParams.profileId, + contentURI: commentParams.contentURI, + pointedProfileId: commentParams.pointedProfileId, + pointedPubId: commentParams.pointedPubId, + referenceModuleData: commentParams.referenceModuleData, + collectModule: commentParams.collectModule, + collectModuleInitData: commentParams.collectModuleInitData, + referenceModule: commentParams.referenceModule, + referenceModuleInitData: commentParams.referenceModuleInitData, sig: sig }); } @@ -109,8 +109,8 @@ contract SignatureHelpers { function _buildMirrorWithSigData( address delegatedSigner, uint256 profileId, - uint256 profileIdPointed, - uint256 pubIdPointed, + uint256 pointedProfileId, + uint256 pointedPubId, bytes memory referenceModuleData, DataTypes.EIP712Signature memory sig ) internal pure returns (DataTypes.MirrorWithSigData memory) { @@ -118,8 +118,8 @@ contract SignatureHelpers { DataTypes.MirrorWithSigData( delegatedSigner, profileId, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData, sig ); @@ -127,16 +127,16 @@ contract SignatureHelpers { function _buildMirrorWithSigData( address delegatedSigner, - DataTypes.MirrorData memory mirrorData, + DataTypes.MirrorParams memory mirrorParams, DataTypes.EIP712Signature memory sig ) internal pure returns (DataTypes.MirrorWithSigData memory) { return _buildMirrorWithSigData({ delegatedSigner: delegatedSigner, - profileId: mirrorData.profileId, - profileIdPointed: mirrorData.profileIdPointed, - pubIdPointed: mirrorData.pubIdPointed, - referenceModuleData: mirrorData.referenceModuleData, + profileId: mirrorParams.profileId, + pointedProfileId: mirrorParams.pointedProfileId, + pointedPubId: mirrorParams.pointedPubId, + referenceModuleData: mirrorParams.referenceModuleData, sig: sig }); } @@ -152,8 +152,8 @@ contract SignatureHelpers { publicationCollectedProfileId: collectData.publisherProfileId, publicationCollectedId: collectData.pubId, collectorProfileId: collectData.collectorProfileId, - passedReferrerProfileId: 0, - passedReferrerPubId: 0, + referrerProfileId: 0, + referrerPubId: 0, collectModuleData: collectData.data, sig: sig }); diff --git a/test/helpers/utils.ts b/test/helpers/utils.ts index 3ef34b9..920eb54 100644 --- a/test/helpers/utils.ts +++ b/test/helpers/utils.ts @@ -28,13 +28,13 @@ import { readFileSync } from 'fs'; import { join } from 'path'; import { CollectWithSigDataStruct, - CommentDataStruct, + CommentParamsStruct, CommentWithSigDataStruct, CreateProfileDataStruct, FollowWithSigDataStruct, - MirrorDataStruct, + MirrorParamsStruct, MirrorWithSigDataStruct, - PostDataStruct, + PostParamsStruct, PostWithSigDataStruct, } from '../../typechain-types/LensHub'; @@ -419,8 +419,8 @@ export async function getPostWithSigMessageParts( export async function getCommentWithSigParts( profileId: BigNumberish, contentURI: string, - profileIdPointed: BigNumberish, - pubIdPointed: string, + pointedProfileId: BigNumberish, + pointedPubId: string, referenceModuleData: Bytes | string, collectModule: string, collectModuleInitData: Bytes | string, @@ -432,8 +432,8 @@ export async function getCommentWithSigParts( const msgParams = buildCommentWithSigParams( profileId, contentURI, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData, collectModule, collectModuleInitData, @@ -447,8 +447,8 @@ export async function getCommentWithSigParts( export async function getMirrorWithSigParts( profileId: BigNumberish, - profileIdPointed: BigNumberish, - pubIdPointed: string, + pointedProfileId: BigNumberish, + pointedPubId: string, referenceModuleData: Bytes | string, referenceModule: string, referenceModuleInitData: Bytes | string, @@ -457,8 +457,8 @@ export async function getMirrorWithSigParts( ): Promise<{ v: number; r: string; s: string }> { const msgParams = buildMirrorWithSigParams( profileId, - profileIdPointed, - pubIdPointed, + pointedProfileId, + pointedPubId, referenceModuleData, referenceModule, referenceModuleInitData, @@ -603,7 +603,7 @@ export async function collectReturningTokenIds({ export interface CommentReturningTokenIdStruct { sender?: Signer; - vars: CommentDataStruct | CommentWithSigDataStruct; + vars: CommentParamsStruct | CommentWithSigDataStruct; } export async function commentReturningTokenId({ @@ -623,7 +623,7 @@ export async function commentReturningTokenId({ export interface MirrorReturningTokenIdStruct { sender?: Signer; - vars: MirrorDataStruct | MirrorWithSigDataStruct; + vars: MirrorParamsStruct | MirrorWithSigDataStruct; } export async function mirrorReturningTokenId({ @@ -643,7 +643,7 @@ export async function mirrorReturningTokenId({ export interface PostReturningTokenIdStruct { sender?: Signer; - vars: PostDataStruct | PostWithSigDataStruct; + vars: PostParamsStruct | PostWithSigDataStruct; } export async function postReturningTokenId({ @@ -901,8 +901,8 @@ const buildPostWithSigParams = ( const buildCommentWithSigParams = ( profileId: BigNumberish, contentURI: string, - profileIdPointed: BigNumberish, - pubIdPointed: string, + pointedProfileId: BigNumberish, + pointedPubId: string, referenceModuleData: Bytes | string, collectModule: string, collectModuleInitData: Bytes | string, @@ -915,8 +915,8 @@ const buildCommentWithSigParams = ( CommentWithSig: [ { name: 'profileId', type: 'uint256' }, { name: 'contentURI', type: 'string' }, - { name: 'profileIdPointed', type: 'uint256' }, - { name: 'pubIdPointed', type: 'uint256' }, + { name: 'pointedProfileId', type: 'uint256' }, + { name: 'pointedPubId', type: 'uint256' }, { name: 'referenceModuleData', type: 'bytes' }, { name: 'collectModule', type: 'address' }, { name: 'collectModuleInitData', type: 'bytes' }, @@ -930,8 +930,8 @@ const buildCommentWithSigParams = ( value: { profileId: profileId, contentURI: contentURI, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, + pointedProfileId: pointedProfileId, + pointedPubId: pointedPubId, referenceModuleData: referenceModuleData, collectModule: collectModule, collectModuleInitData: collectModuleInitData, @@ -944,8 +944,8 @@ const buildCommentWithSigParams = ( const buildMirrorWithSigParams = ( profileId: BigNumberish, - profileIdPointed: BigNumberish, - pubIdPointed: string, + pointedProfileId: BigNumberish, + pointedPubId: string, referenceModuleData: Bytes | string, referenceModule: string, referenceModuleInitData: Bytes | string, @@ -955,8 +955,8 @@ const buildMirrorWithSigParams = ( types: { MirrorWithSig: [ { name: 'profileId', type: 'uint256' }, - { name: 'profileIdPointed', type: 'uint256' }, - { name: 'pubIdPointed', type: 'uint256' }, + { name: 'pointedProfileId', type: 'uint256' }, + { name: 'pointedPubId', type: 'uint256' }, { name: 'referenceModuleData', type: 'bytes' }, { name: 'referenceModule', type: 'address' }, { name: 'referenceModuleInitData', type: 'bytes' }, @@ -967,8 +967,8 @@ const buildMirrorWithSigParams = ( domain: domain(), value: { profileId: profileId, - profileIdPointed: profileIdPointed, - pubIdPointed: pubIdPointed, + pointedProfileId: pointedProfileId, + pointedPubId: pointedPubId, referenceModuleData: referenceModuleData, referenceModule: referenceModule, referenceModuleInitData: referenceModuleInitData, diff --git a/test/other/misc.spec.ts b/test/other/misc.spec.ts index 5fb36d5..5b7020c 100644 --- a/test/other/misc.spec.ts +++ b/test/other/misc.spec.ts @@ -260,8 +260,8 @@ makeSuiteCleanRoom('Misc', function () { lensHub.comment({ profileId: FIRST_PROFILE_ID, contentURI: MOCK_URI, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], collectModule: freeCollectModule.address, collectModuleInitData: abiCoder.encode(['bool'], [true]), @@ -294,8 +294,8 @@ makeSuiteCleanRoom('Misc', function () { await expect( lensHub.mirror({ profileId: FIRST_PROFILE_ID, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], referenceModule: ZERO_ADDRESS, referenceModuleInitData: [], @@ -346,8 +346,8 @@ makeSuiteCleanRoom('Misc', function () { lensHub.comment({ profileId: FIRST_PROFILE_ID, contentURI: OTHER_MOCK_URI, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], collectModule: freeCollectModule.address, collectModuleInitData: abiCoder.encode(['bool'], [true]), @@ -378,8 +378,8 @@ makeSuiteCleanRoom('Misc', function () { await expect( lensHub.mirror({ profileId: FIRST_PROFILE_ID, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], referenceModule: ZERO_ADDRESS, referenceModuleInitData: [], @@ -426,8 +426,8 @@ makeSuiteCleanRoom('Misc', function () { await expect( lensHub.mirror({ profileId: FIRST_PROFILE_ID, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], referenceModule: ZERO_ADDRESS, referenceModuleInitData: [], @@ -438,8 +438,8 @@ makeSuiteCleanRoom('Misc', function () { lensHub.comment({ profileId: FIRST_PROFILE_ID, contentURI: OTHER_MOCK_URI, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 2, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 2, referenceModuleData: [], collectModule: freeCollectModule.address, collectModuleInitData: abiCoder.encode(['bool'], [true]), @@ -470,8 +470,8 @@ makeSuiteCleanRoom('Misc', function () { await expect( lensHub.mirror({ profileId: FIRST_PROFILE_ID, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], referenceModule: ZERO_ADDRESS, referenceModuleInitData: [], @@ -501,8 +501,8 @@ makeSuiteCleanRoom('Misc', function () { lensHub.comment({ profileId: FIRST_PROFILE_ID, contentURI: OTHER_MOCK_URI, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], collectModule: freeCollectModule.address, collectModuleInitData: abiCoder.encode(['bool'], [true]), @@ -514,8 +514,8 @@ makeSuiteCleanRoom('Misc', function () { await expect( lensHub.mirror({ profileId: FIRST_PROFILE_ID, - profileIdPointed: FIRST_PROFILE_ID, - pubIdPointed: 1, + pointedProfileId: FIRST_PROFILE_ID, + pointedPubId: 1, referenceModuleData: [], referenceModule: ZERO_ADDRESS, referenceModuleInitData: [], @@ -735,8 +735,8 @@ makeSuiteCleanRoom('Misc', function () { expect(profileByProfileIdStruct.imageURI).to.eq(MOCK_PROFILE_URI); expect(profileByProfileIdStruct.followNFTURI).to.eq(MOCK_FOLLOW_NFT_URI); - expect(pubByProfileIdStruct.profileIdPointed).to.eq(0); - expect(pubByProfileIdStruct.pubIdPointed).to.eq(0); + expect(pubByProfileIdStruct.pointedProfileId).to.eq(0); + expect(pubByProfileIdStruct.pointedPubId).to.eq(0); expect(pubByProfileIdStruct.contentURI).to.eq(secondURI); expect(pubByProfileIdStruct.referenceModule).to.eq(ZERO_ADDRESS); expect(pubByProfileIdStruct.collectModule).to.eq(freeCollectModule.address); @@ -754,8 +754,8 @@ makeSuiteCleanRoom('Misc', function () { expect(profileByHandleStruct.imageURI).to.eq(MOCK_PROFILE_URI); expect(profileByHandleStruct.followNFTURI).to.eq(MOCK_FOLLOW_NFT_URI); - expect(pubByHandleStruct.profileIdPointed).to.eq(0); - expect(pubByHandleStruct.pubIdPointed).to.eq(0); + expect(pubByHandleStruct.pointedProfileId).to.eq(0); + expect(pubByHandleStruct.pointedPubId).to.eq(0); expect(pubByHandleStruct.contentURI).to.eq(secondURI); expect(pubByHandleStruct.referenceModule).to.eq(ZERO_ADDRESS); expect(pubByHandleStruct.collectModule).to.eq(freeCollectModule.address);