mirror of
https://github.com/lens-protocol/core.git
synced 2026-01-10 14:48:15 -05:00
misc: Modules return empty bytes instead of redundant input data
Co-authored-by: Victor Naumik <vicnaum@gmail.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import {IPublicationActionModule} from 'contracts/interfaces/IPublicationActionM
|
||||
import {ICollectModule} from 'contracts/interfaces/ICollectModule.sol';
|
||||
import {ICollectNFT} from 'contracts/interfaces/ICollectNFT.sol';
|
||||
import {Types} from 'contracts/libraries/constants/Types.sol';
|
||||
import {Events} from 'contracts/libraries/constants/Events.sol';
|
||||
import {Clones} from '@openzeppelin/contracts/proxy/Clones.sol';
|
||||
import {Errors} from 'contracts/libraries/constants/Errors.sol';
|
||||
import {HubRestricted} from 'contracts/base/HubRestricted.sol';
|
||||
@@ -20,6 +19,49 @@ contract CollectPublicationAction is HubRestricted, IPublicationActionModule {
|
||||
|
||||
event CollectModuleWhitelisted(address collectModule, bool whitelist, uint256 timestamp);
|
||||
|
||||
/**
|
||||
* @dev Emitted when a collectNFT clone is deployed using a lazy deployment pattern.
|
||||
*
|
||||
* @param profileId The publisher's profile token ID.
|
||||
* @param pubId The publication associated with the newly deployed collectNFT clone's ID.
|
||||
* @param collectNFT The address of the newly deployed collectNFT clone.
|
||||
* @param timestamp The current block timestamp.
|
||||
*/
|
||||
event CollectNFTDeployed(
|
||||
uint256 indexed profileId,
|
||||
uint256 indexed pubId,
|
||||
address indexed collectNFT,
|
||||
uint256 timestamp
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Emitted upon a successful collect action.
|
||||
*
|
||||
* @param collectedProfileId The token ID of the profile that published the collected publication.
|
||||
* @param collectedPubId The ID of the collected publication.
|
||||
* @param collectorProfileId The token ID of the profile that collected the publication.
|
||||
* @param nftRecipient The address that received the collect NFT.
|
||||
* @param collectActionData The custom data passed to the collect module, if any.
|
||||
* @param collectActionResult The data returned from the collect module's collect action. This is ABI-encoded
|
||||
* and depends on the collect module chosen.
|
||||
* @param collectNFT The address of the NFT collection where the minted collect NFT belongs to.
|
||||
* @param tokenId The token ID of the collect NFT that was minted as a collect of the publication.
|
||||
* @param transactionExecutor The address of the account that executed this operation.
|
||||
* @param timestamp The current block timestamp.
|
||||
*/
|
||||
event Collected(
|
||||
uint256 indexed collectedProfileId,
|
||||
uint256 indexed collectedPubId,
|
||||
uint256 indexed collectorProfileId,
|
||||
address nftRecipient,
|
||||
bytes collectActionData,
|
||||
bytes collectActionResult,
|
||||
address collectNFT,
|
||||
uint256 tokenId,
|
||||
address transactionExecutor,
|
||||
uint256 timestamp
|
||||
);
|
||||
|
||||
address public immutable COLLECT_NFT_IMPL;
|
||||
address public immutable MODULE_GLOBALS;
|
||||
|
||||
@@ -57,7 +99,7 @@ contract CollectPublicationAction is HubRestricted, IPublicationActionModule {
|
||||
transactionExecutor,
|
||||
collectModuleInitData
|
||||
);
|
||||
return data;
|
||||
return '';
|
||||
}
|
||||
|
||||
function processPublicationAction(
|
||||
@@ -99,7 +141,7 @@ contract CollectPublicationAction is HubRestricted, IPublicationActionModule {
|
||||
address collectNFT,
|
||||
uint256 tokenId
|
||||
) private {
|
||||
emit Events.Collected({
|
||||
emit Collected({
|
||||
collectedProfileId: processActionParams.publicationActedProfileId,
|
||||
collectedPubId: processActionParams.publicationActedId,
|
||||
collectorProfileId: processActionParams.actorProfileId,
|
||||
@@ -155,7 +197,7 @@ contract CollectPublicationAction is HubRestricted, IPublicationActionModule {
|
||||
address collectNFT = Clones.clone(collectNFTImpl);
|
||||
|
||||
ICollectNFT(collectNFT).initialize(profileId, pubId);
|
||||
emit Events.CollectNFTDeployed(profileId, pubId, collectNFT, block.timestamp);
|
||||
emit CollectNFTDeployed(profileId, pubId, collectNFT, block.timestamp);
|
||||
|
||||
return collectNFT;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ contract MultirecipientFeeCollectModule is BaseFeeCollectModule {
|
||||
function initializePublicationCollectModule(
|
||||
uint256 profileId,
|
||||
uint256 pubId,
|
||||
address, /* transactionExecutor */
|
||||
address /* transactionExecutor */,
|
||||
bytes calldata data
|
||||
) external override onlyActionModule returns (bytes memory) {
|
||||
MultirecipientFeeCollectModuleInitData memory initData = abi.decode(
|
||||
@@ -108,7 +108,9 @@ contract MultirecipientFeeCollectModule is BaseFeeCollectModule {
|
||||
|
||||
// Zero amount for collect doesn't make sense here (in a module with 5 recipients)
|
||||
// Better use SimpleFeeCollect module instead which allows 0 amount
|
||||
if (baseInitData.amount == 0) revert Errors.InitParamsInvalid();
|
||||
if (baseInitData.amount == 0) {
|
||||
revert Errors.InitParamsInvalid();
|
||||
}
|
||||
_validateBaseInitData(baseInitData);
|
||||
_validateAndStoreRecipients(initData.recipients, profileId, pubId);
|
||||
_storeBasePublicationCollectParameters(profileId, pubId, baseInitData);
|
||||
@@ -122,19 +124,19 @@ contract MultirecipientFeeCollectModule is BaseFeeCollectModule {
|
||||
* @param profileId The profile ID who is publishing the publication.
|
||||
* @param pubId The associated publication's LensHub publication ID.
|
||||
*/
|
||||
function _validateAndStoreRecipients(
|
||||
RecipientData[] memory recipients,
|
||||
uint256 profileId,
|
||||
uint256 pubId
|
||||
) internal {
|
||||
function _validateAndStoreRecipients(RecipientData[] memory recipients, uint256 profileId, uint256 pubId) internal {
|
||||
uint256 len = recipients.length;
|
||||
|
||||
// Check number of recipients is supported
|
||||
if (len == 0) revert Errors.InitParamsInvalid();
|
||||
if (len == 0) {
|
||||
revert Errors.InitParamsInvalid();
|
||||
}
|
||||
|
||||
// Skip loop check if only 1 recipient in the array
|
||||
if (len == 1) {
|
||||
if (recipients[0].split != BPS_MAX) revert InvalidRecipientSplits();
|
||||
if (recipients[0].split != BPS_MAX) {
|
||||
revert InvalidRecipientSplits();
|
||||
}
|
||||
|
||||
// If single recipient passes check above, store and return
|
||||
_recipientsByPublicationByProfile[profileId][pubId].push(recipients[0]);
|
||||
@@ -153,7 +155,9 @@ contract MultirecipientFeeCollectModule is BaseFeeCollectModule {
|
||||
}
|
||||
}
|
||||
|
||||
if (totalSplits != BPS_MAX) revert InvalidRecipientSplits();
|
||||
if (totalSplits != BPS_MAX) {
|
||||
revert InvalidRecipientSplits();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,14 +209,12 @@ contract MultirecipientFeeCollectModule is BaseFeeCollectModule {
|
||||
*
|
||||
* @return The BaseProfilePublicationData struct mapped to that publication.
|
||||
*/
|
||||
function getPublicationData(uint256 profileId, uint256 pubId)
|
||||
external
|
||||
view
|
||||
returns (MultirecipientFeeCollectProfilePublicationData memory)
|
||||
{
|
||||
function getPublicationData(
|
||||
uint256 profileId,
|
||||
uint256 pubId
|
||||
) external view returns (MultirecipientFeeCollectProfilePublicationData memory) {
|
||||
BaseProfilePublicationData memory baseData = getBasePublicationData(profileId, pubId);
|
||||
RecipientData[] memory recipients = _recipientsByPublicationByProfile[profileId][pubId];
|
||||
|
||||
return
|
||||
MultirecipientFeeCollectProfilePublicationData({
|
||||
amount: baseData.amount,
|
||||
|
||||
@@ -39,13 +39,13 @@ contract SimpleFeeCollectModule is BaseFeeCollectModule {
|
||||
function initializePublicationCollectModule(
|
||||
uint256 profileId,
|
||||
uint256 pubId,
|
||||
address, /* transactionExecutor */
|
||||
address /* transactionExecutor */,
|
||||
bytes calldata data
|
||||
) external override onlyActionModule returns (bytes memory) {
|
||||
BaseFeeCollectModuleInitData memory baseInitData = abi.decode(data, (BaseFeeCollectModuleInitData));
|
||||
_validateBaseInitData(baseInitData);
|
||||
_storeBasePublicationCollectParameters(profileId, pubId, baseInitData);
|
||||
return data;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,12 +57,10 @@ contract SimpleFeeCollectModule is BaseFeeCollectModule {
|
||||
*
|
||||
* @return The BaseProfilePublicationData struct mapped to that publication.
|
||||
*/
|
||||
function getPublicationData(uint256 profileId, uint256 pubId)
|
||||
external
|
||||
view
|
||||
virtual
|
||||
returns (BaseProfilePublicationData memory)
|
||||
{
|
||||
function getPublicationData(
|
||||
uint256 profileId,
|
||||
uint256 pubId
|
||||
) external view virtual returns (BaseProfilePublicationData memory) {
|
||||
return getBasePublicationData(profileId, pubId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,9 @@ abstract contract BaseFeeCollectModule is FeeModuleBase, ActionRestricted, IBase
|
||||
(baseInitData.amount != 0 && !_currencyWhitelisted(baseInitData.currency)) ||
|
||||
baseInitData.referralFee > BPS_MAX ||
|
||||
(baseInitData.endTimestamp != 0 && baseInitData.endTimestamp < block.timestamp)
|
||||
) revert Errors.InitParamsInvalid();
|
||||
) {
|
||||
revert Errors.InitParamsInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -63,7 +63,7 @@ contract FeeFollowModule is FeeModuleBase, HubRestricted, IFollowModule {
|
||||
}
|
||||
}
|
||||
_feeConfig[profileId] = feeConfig;
|
||||
return data;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ contract FeeFollowModule is FeeModuleBase, HubRestricted, IFollowModule {
|
||||
revert Errors.InvalidParams();
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user