TokenGatedReferenceModule

Git Source

Inherits: HubRestricted, IReferenceModule

Author: Lens Protocol

A reference module that validates that the user who tries to reference has a required minimum balance of ERC20/ERC721 token.

State Variables

UINT256_BYTES

uint256 internal constant UINT256_BYTES = 32;

_gateParams

mapping(uint256 pointedProfileId => mapping(uint256 pointedPubId => GateParams gateParams)) internal _gateParams;

Functions

constructor

constructor(address hub) HubRestricted(hub);

initializeReferenceModule

Initializes data for the given publication being published with this Reference module.

The gating token address and minimum balance threshold is passed during initialization in data field.

function initializeReferenceModule(uint256 profileId, uint256 pubId, address, bytes calldata data)
    external
    override
    onlyHub
    returns (bytes memory);

Parameters

NameTypeDescription
profileIduint256The token ID of the profile publishing the publication.
pubIduint256The associated publication's LensHub publication ID.
<none>address
databytesArbitrary data passed from the user to be decoded by the Reference Module during initialization.

Returns

NameTypeDescription
<none>bytesbytes Any custom ABI-encoded data. This will be a LensHub event params that can be used by indexers or UIs.

processComment

Processes a comment being published. This includes any module logic like transferring tokens, checking for conditions (e.g. token-gated), etc.

Validates that the commenting profile's owner has enough balance of the gating token.

function processComment(Types.ProcessCommentParams calldata processCommentParams)
    external
    view
    override
    onlyHub
    returns (bytes memory);

Parameters

NameTypeDescription
processCommentParamsTypes.ProcessCommentParamsThe parameters for processing a comment.

Returns

NameTypeDescription
<none>bytesbalance The ABI-encoded gate token balance of the profile trying to comment/quote/mirror.

processQuote

Processes a quote being published. This includes any module logic like transferring tokens, checking for conditions (e.g. token-gated), etc.

Validates that the commenting profile's owner has enough balance of the gating token.

function processQuote(Types.ProcessQuoteParams calldata processQuoteParams)
    external
    view
    override
    onlyHub
    returns (bytes memory);

Parameters

NameTypeDescription
processQuoteParamsTypes.ProcessQuoteParamsThe parameters for processing a quote.

Returns

NameTypeDescription
<none>bytesbalance The ABI-encoded gate token balance of the profile trying to comment/quote/mirror.

processMirror

Processes a mirror being published. This includes any module logic like transferring tokens, checking for conditions (e.g. token-gated), etc.

Validates that the mirroring profile's owner has enough balance of the gating token.

function processMirror(Types.ProcessMirrorParams calldata processMirrorParams)
    external
    view
    override
    onlyHub
    returns (bytes memory);

Parameters

NameTypeDescription
processMirrorParamsTypes.ProcessMirrorParamsThe parameters for processing a mirror.

Returns

NameTypeDescription
<none>bytesbalance The ABI-encoded gate token balance of the profile trying to comment/quote/mirror.

_validateTokenBalance

Validates the profile's owner balance of gating token. It can work with both ERC20 and ERC721 as both interfaces shares balanceOf function prototype.

function _validateTokenBalance(uint256 profileId, uint256 pointedProfileId, uint256 pointedPubId)
    internal
    view
    returns (uint256);

Parameters

NameTypeDescription
profileIduint256The ID of the profile trying to comment/quote/mirror.
pointedProfileIduint256The ID of the pointed publication's author.
pointedPubIduint256The ID of the pointed publication.

Returns

NameTypeDescription
<none>uint256uint256 The gate token balance of the profile trying to comment/quote/mirror.

Events

TokenGatedReferencePublicationCreated

event TokenGatedReferencePublicationCreated(
    uint256 indexed profileId, uint256 indexed pubId, address tokenAddress, uint256 minThreshold
);

Errors

NotEnoughBalance

error NotEnoughBalance();