EntityEligibilityGuard Documentation
Overview
EntityEligibilityGuard is a reusable abstract guard for contracts that need to check whether a wallet belongs to an enabled entity and whether that entity's type is allowed for a protocol flow. The checks resolve account and entity state through EntityRegistry.
The guard is used through EligibilityModuleBase, which combines:
DependenciesBase: one-shot dependency setters forBondRegistry,EscrowManager, andEntityRegistryEntityEligibilityGuard: internal entity-enabled and entity-type checksIEntityEligibilityAdmin: admin-facing entity type allowlist setters
Current marketplace usage is documented in Marketplace.
Prerequisites
- Inheriting contracts must grant
ADMINto accounts authorized to wire dependencies and entity-type allowlists EntityRegistrymust be configured when eligibility checks are intended to be enforced- Allowed entity type IDs must be configured before guarded flows are opened
Contract Architecture
DependenciesBasestores_bondRegistry,_escrowManager, and_entityRegistry- Dependency setters are one-shot and revert if the dependency has already been set
EntityEligibilityGuardstoresmapping(uint256 typeId => bool allowed) _allowedEntityTypesEligibilityModuleBaseexposessetAllowedEntityTypeandsetAllowedEntityTypes
Authorization Model
ADMIN: Can set dependencies throughsetBondRegistry,setEscrowManager,setEntityRegistryADMIN: Can update allowed entity types throughsetAllowedEntityTypeandsetAllowedEntityTypes- Owner: Can grant/revoke
ADMINthroughOwnableRolesExtension
Core Functions and Flows
setBondRegistry(address bondRegistry)
Stores the BondRegistry dependency.
Important Notes:
- Reverts with
ZeroAddress()for zero address - Reverts with
DependenciesBase__BondRegistryAlreadySet()if already configured
setEscrowManager(address escrowManager)
Stores the EscrowManager dependency.
Important Notes:
- Reverts with
ZeroAddress()for zero address - Reverts with
DependenciesBase__EscrowManagerAlreadySet()if already configured
setEntityRegistry(address entityRegistry)
Stores the EntityRegistry dependency used by eligibility checks.
Important Notes:
- Reverts with
ZeroAddress()for zero address - Reverts with
DependenciesBase__EntityRegistryAlreadySet()if already configured
setAllowedEntityType(uint256 typeId, bool allowed)
Enables or disables one entity type ID.
Events:
EntityTypeAllowed(typeId, allowed)
setAllowedEntityTypes(uint256[] calldata typeIds, bool allowed)
Batch version of setAllowedEntityType.
_validateEntityWalletEnabled(address wallet)
Internal validation used by inheriting modules.
Behavior:
- If
EntityRegistryis not configured, returns without reverting - Otherwise requires
IEntityRegistry(entityRegistry).isAccountEnabled(wallet) == true
Errors:
EntityEligibilityGuard__EntityWalletNotAllowed(wallet)
_validateEntityTypeAllowed(address wallet)
Internal validation for entity type allowlisting.
Behavior:
- If
EntityRegistryis not configured, returns without reverting - Otherwise resolves
getEntityTypeIdByAccount(wallet)and requires that type ID to be allowed
Errors:
EntityEligibilityGuard__EntityTypeNotAllowed(typeId)
_validateEntityWalletAndTypeAllowed(address wallet)
Checks wallet enablement first, then entity type allowlist status.
_validateEntityWalletsAndTypesAllowed(address[] memory wallets)
Batch version of _validateEntityWalletAndTypeAllowed.
Trust and Security Notes
- Leaving
EntityRegistryunset disables the guard checks. This is useful for staged initialization but should be treated as a bootstrap-only state when eligibility is required. - Dependency setters are intentionally one-shot in
DependenciesBase; rotating these dependencies requires an inheriting contract to provide an explicit override. - Entity type IDs are protocol configuration. Docs and deployment scripts should keep the expected entity type IDs aligned with
EntityRegistrysetup.