Skip to content

Module Factory

Rahul Saxena edited this page Aug 7, 2023 · 1 revision

File: ModuleFactory.sol

Things to know

  1. Module Factory is an owned factory for deploying modules.
  2. Module factory handles the linking of a module's IModule.Metadata to its IBeacon instance contract using the _beacons mapping.
  3. The registered metadata is used to deploy and initialize inverter modules using the createModule function.
  4. A metadata's registered IBeacon implementation can not be changed after registration.
  5. You have to register a new IBeacon implementation by changing the metadata (e.g. by increasing the version).

Modifiers

  1. validMetadata
modifier validMetadata(IModule.Metadata memory data)

Modifier to guarantee function is only callable with valid metadata. The validity is checked via the isValid function from LibMetadata library.

  1. validBeacon
modifier validBeacon(IBeacon beacon) 

Modifier to guarantee function is only callable with valid {IBeacon} instance. Revert if beacon's implementation is zero address.

Read Functions

1. getBeaconAndId

    function getBeaconAndId(IModule.Metadata memory metadata)
        external
        view
        returns (IBeacon, bytes32);

Returns the {IBeacon} instance registered and the id for given metadata.

Parameters:

  1. metadata: The module's metadata of type IModule.Metadata

Return Data:

  1. IBeacon: The module's {IBeacon} instance registered
  2. bytes32: The metadata's id

Write Functions

1. createModule

    function createModule(
        IModule.Metadata memory metadata,
        IOrchestrator orchestrator,
        bytes memory configData
    ) external returns (address);

Creates a module instance identified by the metadata passed in the parameters.

Parameters:

  1. metadata: The module's metadata of type IModule.Metadata
  2. orchestrator: The orchestrator's instance of the module.
  3. configData: The configuration data of the module. Contains the information required to initialize the module.

Return Data:

  1. address: The address of the newly deployed module.

2. registerMetadata

    function registerMetadata(IModule.Metadata memory metadata, IBeacon beacon)
        external;

Registers metadata metadata with {IBeacon} implementation beacon. The function is only callable by the owner.

Parameters:

  1. metadata: The module's metadata of type IModule.Metadata
  2. beacon: The module's {IBeacon} instance.