BaseFeeCollectModule

Git Source

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:

  1. Validating that collect action meets all needed criteria
  2. Processing the collect action either with or without referral
function processCollect(Types.ProcessCollectParams calldata processCollectParams)
    external
    virtual
    onlyActionModule
    returns (bytes memory);

Parameters

NameTypeDescription
processCollectParamsTypes.ProcessCollectParamsCollect action parameters (see Types.ProcessCollectParams struct)

Returns

NameTypeDescription
<none>bytesbytes 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

NameTypeDescription
profileIduint256The token ID of the profile mapped to the publication to query.
pubIduint256The publication ID of the publication to query.

Returns

NameTypeDescription
<none>BaseProfilePublicationDataThe 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

NameTypeDescription
<none>uint160The collect fee of the specified publication.

_validateBaseInitData

*Validates the Base parameters like:

  1. Is the currency whitelisted
  2. Is the referralFee in valid range
  3. Is the end of collects timestamp in valid range This should be called during initializePublicationCollectModule()*
function _validateBaseInitData(BaseFeeCollectModuleInitData memory baseInitData) internal virtual;

Parameters

NameTypeDescription
baseInitDataBaseFeeCollectModuleInitDataModule 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

NameTypeDescription
profileIduint256The token ID of the profile publishing the publication.
pubIduint256The publication ID.
baseInitDataBaseFeeCollectModuleInitDataModule initialization data (see BaseFeeCollectModuleInitData struct)

_validateAndStoreCollect

*Validates the collect action by checking that:

  1. the collector is a follower (if enabled)
  2. the number of collects after the action doesn't surpass the collect limit (if enabled)
  3. 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:

  1. Calculation of fees
  2. Validation that fees are what collector expected
  3. Transfer of fees to recipient(-s) and treasury*
function _processCollect(Types.ProcessCollectParams calldata processCollectParams) internal virtual;

Parameters

NameTypeDescription
processCollectParamsTypes.ProcessCollectParamsParameters 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):

  1. Calculation of fees
  2. Validation that fees are what collector expected
  3. Transfer of fees to treasury, referrals (if any) and recipients*
function _processCollectWithReferral(Types.ProcessCollectParams calldata processCollectParams) internal virtual;

Parameters

NameTypeDescription
processCollectParamsTypes.ProcessCollectParamsParameters 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

NameTypeDescription
processCollectParamsTypes.ProcessCollectParamsParameters of the collect
currencyaddressCurrency of the transaction
amountuint256Amount 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

NameTypeDescription
processCollectParamsTypes.ProcessCollectParamsParameters of the collect
currencyaddressCurrency of the transaction
amountuint256Amount of the fee after subtracting the Treasury part.