BaseFeeCollectModule
Inherits: FeeModuleBase, ActionRestricted, IBaseFeeCollectModule
Author: Lens Protocol
This is base Lens CollectModule implementation, allowing customization of time to collect, number of collects and Followers-only restriction. Charges a fee for collect and distributing it among Receiver/Referrals/Treasury.
Here we use "Base" terminology to anything that represents this base functionality (base structs, base functions, base storage). Other collect modules can be built on top of the "Base" by inheriting from this contract and overriding functions. This contract is marked "abstract" as it requires you to implement initializePublicationCollectModule and getPublicationData functions when you inherit from it. See SimpleFeeCollectModule as an example implementation.
State Variables
HUB
address immutable HUB;
_dataByPublicationByProfile
mapping(uint256 => mapping(uint256 => BaseProfilePublicationData)) internal _dataByPublicationByProfile;
Functions
constructor
constructor(address hub, address actionModule) ActionRestricted(actionModule) FeeModuleBase(hub);
processCollect
Processes a collect by:
- Validating that collect action meets all needed criteria
- Processing the collect action either with or without referral
function processCollect(Types.ProcessCollectParams calldata processCollectParams)
external
virtual
onlyActionModule
returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
processCollectParams | Types.ProcessCollectParams | Collect action parameters (see Types.ProcessCollectParams struct) |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | bytes Any custom ABI-encoded data. This will be a LensHub event params that can be used by indexers or UIs. |
getBasePublicationData
Returns the Base publication data for a given publication, or an empty struct if that publication was not initialized with this module.
function getBasePublicationData(uint256 profileId, uint256 pubId)
public
view
virtual
returns (BaseProfilePublicationData memory);
Parameters
Name | Type | Description |
---|---|---|
profileId | uint256 | The token ID of the profile mapped to the publication to query. |
pubId | uint256 | The publication ID of the publication to query. |
Returns
Name | Type | Description |
---|---|---|
<none> | BaseProfilePublicationData | The BaseProfilePublicationData struct mapped to that publication. |
calculateFee
Calculates and returns the collect fee of a publication.
Override this function to use a different formula for the fee.
function calculateFee(Types.ProcessCollectParams calldata processCollectParams) public view virtual returns (uint160);
Returns
Name | Type | Description |
---|---|---|
<none> | uint160 | The collect fee of the specified publication. |
_validateBaseInitData
*Validates the Base parameters like:
- Is the currency whitelisted
- Is the referralFee in valid range
- Is the end of collects timestamp in valid range This should be called during initializePublicationCollectModule()*
function _validateBaseInitData(BaseFeeCollectModuleInitData memory baseInitData) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
baseInitData | BaseFeeCollectModuleInitData | Module initialization data (see BaseFeeCollectModuleInitData struct) |
_storeBasePublicationCollectParameters
Stores the initial module parameters This should be called during initializePublicationCollectModule()
function _storeBasePublicationCollectParameters(
uint256 profileId,
uint256 pubId,
BaseFeeCollectModuleInitData memory baseInitData
) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
profileId | uint256 | The token ID of the profile publishing the publication. |
pubId | uint256 | The publication ID. |
baseInitData | BaseFeeCollectModuleInitData | Module initialization data (see BaseFeeCollectModuleInitData struct) |
_validateAndStoreCollect
*Validates the collect action by checking that:
- the collector is a follower (if enabled)
- the number of collects after the action doesn't surpass the collect limit (if enabled)
- the current block timestamp doesn't surpass the end timestamp (if enabled) This should be called during processCollect()*
function _validateAndStoreCollect(Types.ProcessCollectParams calldata processCollectParams) internal virtual;
_processCollect
*Internal processing of a collect:
- Calculation of fees
- Validation that fees are what collector expected
- Transfer of fees to recipient(-s) and treasury*
function _processCollect(Types.ProcessCollectParams calldata processCollectParams) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
processCollectParams | Types.ProcessCollectParams | Parameters of the collect |
_processCollectWithReferral
*Internal processing of a collect with a referrals (if any). Same as _processCollect, but also includes transfer to referrals (if any):
- Calculation of fees
- Validation that fees are what collector expected
- Transfer of fees to treasury, referrals (if any) and recipients*
function _processCollectWithReferral(Types.ProcessCollectParams calldata processCollectParams) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
processCollectParams | Types.ProcessCollectParams | Parameters of the collect |
_transferToRecipients
Tranfers the fee to recipient(-s) Override this to add additional functionality (e.g. multiple recipients)
function _transferToRecipients(
Types.ProcessCollectParams calldata processCollectParams,
address currency,
uint256 amount
) internal virtual;
Parameters
Name | Type | Description |
---|---|---|
processCollectParams | Types.ProcessCollectParams | Parameters of the collect |
currency | address | Currency of the transaction |
amount | uint256 | Amount to transfer to recipient(-s) |
_transferToReferrals
Tranfers the part of fee to referral(-s) Override this to add additional functionality (e.g. different amounts to different referrals, etc)
function _transferToReferrals(
Types.ProcessCollectParams calldata processCollectParams,
address currency,
uint256 amount
) internal virtual returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
processCollectParams | Types.ProcessCollectParams | Parameters of the collect |
currency | address | Currency of the transaction |
amount | uint256 | Amount of the fee after subtracting the Treasury part. |