AssetRegistry

Git Source

Inherits: AccessControlEnumerable

This contract provides functionality to add, enable, pause, and manage assets, with role-based access control.

Manages the registration and status of assets in the system.

Utilizes OpenZeppelin's AccessControlEnumerable for granular permission management.

Supports three asset states: DISABLED -> ENABLED <-> PAUSED.

State Variables

_MANAGER_ROLE

CONSTANTS ///

Role responsible for managing assets in the registry.

bytes32 private constant _MANAGER_ROLE = keccak256("MANAGER_ROLE");

_MAX_ASSETS

Maximum number of assets that can be registered in the system.

uint256 private constant _MAX_ASSETS = 255;

_assetList

STATE VARIABLES ///

Array of assets registered in the system.

address[] private _assetList;

_assetRegistry

Mapping from asset address to AssetData struct containing the asset's index and status.

mapping(address asset => AssetData) private _assetRegistry;

enabledAssets

Bit flag representing the enabled assets in the registry.

uint256 public enabledAssets;

Functions

constructor

Initializes the AssetRegistry contract

Sets up initial roles for admin and manager

*Reverts if:

  • The admin address is zero (Errors.ZeroAddress)*
constructor(address admin) payable;

Parameters

NameTypeDescription
adminaddressThe address to be granted the DEFAULT_ADMIN_ROLE

addAsset

Adds a new asset to the registry

Only callable by accounts with the MANAGER_ROLE

*Reverts if:

  • The caller doesn't have the MANAGER_ROLE (OpenZeppelin's AccessControl)
  • The asset address is zero (Errors.ZeroAddress)
  • The asset is already enabled (AssetAlreadyEnabled)
  • The maximum number of assets has been reached (MaxAssetsReached)*
function addAsset(address asset) external onlyRole(_MANAGER_ROLE);

Parameters

NameTypeDescription
assetaddressThe address of the asset to be added

setAssetStatus

Sets the status of an asset in the registry

Only callable by accounts with the MANAGER_ROLE

*Reverts if:

  • The caller doesn't have the MANAGER_ROLE (OpenZeppelin's AccessControl)
  • The asset address is zero (Errors.ZeroAddress)
  • The asset is not enabled in the registry (AssetNotEnabled)
  • The new status is invalid (AssetInvalidStatusUpdate)*
function setAssetStatus(address asset, AssetStatus newStatus) external onlyRole(_MANAGER_ROLE);

Parameters

NameTypeDescription
assetaddressThe address of the asset to update
newStatusAssetStatusThe new status to set (ENABLED or PAUSED)

getAssetStatus

Retrieves the status of an asset

Returns the status of the asset. For non-existent assets, returns status as DISABLED

function getAssetStatus(address asset) external view returns (AssetStatus);

Parameters

NameTypeDescription
assetaddressThe address of the asset to query

Returns

NameTypeDescription
<none>AssetStatusAssetStatus The status of the asset

getAssets

Retrieves the list of assets in the registry. Parameter bitFlag is used to filter the assets.

function getAssets(uint256 bitFlag) external view returns (address[] memory assets);

Parameters

NameTypeDescription
bitFlaguint256The bit flag to filter the assets.

Returns

NameTypeDescription
assetsaddress[]The list of assets in the registry.

getAllAssets

Retrieves the addresses of all assets in the registry without any filtering.

function getAllAssets() external view returns (address[] memory);

Returns

NameTypeDescription
<none>address[]assets The list of addresses of all assets in the registry.

hasPausedAssets

Checks if any assets in the given bit flag are paused.

function hasPausedAssets(uint256 bitFlag) external view returns (bool);

Parameters

NameTypeDescription
bitFlaguint256The bit flag representing a set of assets.

Returns

NameTypeDescription
<none>boolbool True if any of the assets are paused, false otherwise.

getAssetsBitFlag

Retrieves the bit flag for a given list of assets.

*This function is for off-chain usage to get the bit flag for a list of assets. Reverts if:

  • the number of assets exceeds the maximum number of assets
  • an asset is not enabled in the registry*
function getAssetsBitFlag(address[] memory assets) external view returns (uint256);

Parameters

NameTypeDescription
assetsaddress[]The list of assets to get the bit flag for.

Returns

NameTypeDescription
<none>uint256bitFlag The bit flag representing the list of assets.

Events

AddAsset

EVENTS ///

Emitted when a new asset is added to the registry.

event AddAsset(address indexed asset);

SetAssetStatus

Emitted when an asset's status is updated.

event SetAssetStatus(address indexed asset, AssetStatus status);

Errors

AssetAlreadyEnabled

ERRORS ///

Thrown when attempting to add an asset that is already enabled in the registry.

error AssetAlreadyEnabled();

AssetNotEnabled

Thrown when attempting to perform an operation on an asset that is not enabled in the registry.

error AssetNotEnabled();

AssetInvalidStatusUpdate

Thrown when attempting to set the asset status to an invalid status.

error AssetInvalidStatusUpdate();

MaxAssetsReached

Thrown when attempting to add an asset when the maximum number of assets has been reached.

error MaxAssetsReached();

AssetExceedsMaximum

Thrown when length of the requested assets exceeds the maximum number of assets.

error AssetExceedsMaximum();

Structs

AssetData

STRUCTS ///

Contains the index and status of an asset in the registry.

struct AssetData {
    uint32 indexPlusOne;
    AssetStatus status;
}

Enums

AssetStatus

ENUMS ///

enum AssetStatus {
    DISABLED,
    ENABLED,
    PAUSED
}