How Module Instances Are Deployed

All contracts that inherit from HatsModule can be deployed as minimal proxy clones via HatsModuleFactory, which offers several operations:

  • create a single module instance

  • batch create multiple module instances

  • predict the address of a module instance

  • check if a module instance has already been deployed

Each of these functions can be called directly on the HatsModuleFactory contract, or they can be accessed via the Modules SDK to easily deploy new module instances and more.

Create New Instance

The createHatsModule function deploys a new proxy instance, for the provided implementation, to a deterministic address. The instance's immutable arguments are set its creation, and then instance.setUp is called with the provided initialization data.

function createHatsModule(
    address _implementation,
    uint256 _hatId,
    bytes calldata _otherImmutableArgs,
    bytes calldata _initData
) public returns (address _instance)

Parameters:

  • _implementation - The address of the implementation contract for which to deploy a clone.

  • _hatId - The hat for which to deploy the module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

  • _initData - Encoded data (via abi.encode) to pass to the setUp function of the new instance.

Returns:

  • _instance - The new instance's address.

Events:

Once the new module deployment and setup have completed, the function will emit the following event, which contains the new instance address:

event HatsModuleFactory_ModuleDeployed(
    address implementation, address instance, uint256 hatId, bytes otherImmutableArgs, bytes initData
);

Batch Create Multiple Instances

The batchCreateHatsModule function creates multiple instances, using the createHatsModule function.

The necessary creation parameters are passed as arrays, which must have the same length, equal to the number of modules to be created. For each module, the createHatsModule function will be called with the arrays entries, on the same corresponding index.

function batchCreateHatsModule(
    address[] calldata _implementations,
    uint256[] calldata _hatIds,
    bytes[] calldata _otherImmutableArgsArray,
    bytes[] calldata _initDataArray
) public returns (bool success)

Parameters:

  • _implementations - The addresses of the implementation contracts for which to deploy a clone.

  • _hatIds - The hats for which to deploy the modules.

  • _otherImmutableArgsArray: Immutable argumentss to pass to the clones, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

  • _initDataArray - Encoded data (via abi.encode) to pass to the setUp function of each new module instance.

Returns:

  • success - True if all modules were successfully created and initialized, false otherwise.

Events:

For every successfully created module, the function will emit the following event, which contains the new instance address:

event HatsModuleFactory_ModuleDeployed(
    address implementation, address instance, uint256 hatId, bytes otherImmutableArgs, bytes initData
);

Predict Module's Address

The getHatsModuleAddress function predicts the address of a module instance before it was created.

function getHatsModuleAddress(address _implementation, uint256 _hatId, bytes calldata _otherImmutableArgs)
    public
    view
returns (address)

Parameters:

  • _implementation - The address of the implementation contract.

  • _hatId - The hat for which to deploy a module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

Returns:

  • The predicted instance address.

Check If Deployed

The deployed function checks if a certain module instance has been deployed.

function deployed(address _implementation, uint256 _hatId, bytes calldata _otherImmutableArgs)
    public
    view
returns (bool)

Parameters:

  • _implementation - The address of the implementation contract.

  • _hatId - The hat for which to deploy a module.

  • _otherImmutableArgs: Immutable arguments to pass to the clone, packed encoded (via abi.encodePacked). These are additional to the ones already included in HatsModule.

Returns:

  • True if the instance has been deployed, false otherwise.

HatsModuleFactory Deployments

HatsModuleFactory v0.6.0 is deployed to the same address on all networks: 0xfE661c01891172046feE16D3a57c3Cf456729efA

It is known to have been deployed to the following networks:

Last updated