ModuleFactory_v1.sol

Git Source

Inherits: IModuleFactory_v1, ERC2771ContextUpgradeable, Ownable2StepUpgradeable, ERC165Upgradeable

Author: Inverter Network

Enables the creation and registration of Inverter Modules, facilitating the deployment of module instances linked to specific beacons. Allows for configuration of modules starting state via provided deployment data.

An owned factory for deploying modules. The owner can register module metadata's to an {IInverterBeacon_v1} implementations. Note that a metadata's registered {IInverterBeacon_v1} implementation can not be changed after registration!

State Variables

reverter

Returns the address of the {InverterReverter_v1} contract.

address public immutable reverter;

governor

Returns the {Governor_v1} contract address.

address public governor;

_beacons

Mapping of metadata identifier to {IInverterBeacon_v1} instance.

_MetadataLib.identifier(metadata) => {IInverterBeacon_v1}.

mapping(bytes32 => IInverterBeacon_v1) private _beacons;

_orchestratorOfProxy

Mapping of proxy address to orchestrator address.

moduleProxy => {IOrchestrator_v1}.

mapping(address => address) private _orchestratorOfProxy;

_deploymentNonces

Maps a users address to a nonce used for the create2-based deployment.

mapping(address => uint) private _deploymentNonces;

__gap

Storage gap for future upgrades.

uint[50] private __gap;

Functions

supportsInterface

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable)
    returns (bool);

validMetadata

Modifier to guarantee function is only callable with valid metadata.

modifier validMetadata(IModule_v1.Metadata memory data);

validBeacon

Modifier to guarantee function is only callable with valid {IInverterBeacon_v1} instance and if the owner of the beacon. is same as the {Governor_v1} of this contract.

modifier validBeacon(IInverterBeacon_v1 beacon);

constructor

The factories initializer function.

constructor(address _reverter, address _trustedForwarder)
    ERC2771ContextUpgradeable(_trustedForwarder);

Parameters

NameTypeDescription

_reverter

address

The address of the {InverterReverter_v1} contract.

_trustedForwarder

address

The address of the trusted forwarder contract.

init

The factories initializer function.

function init(
    address _governor,
    IModule_v1.Metadata[] memory initialMetadataRegistration,
    IInverterBeacon_v1[] memory initialBeaconRegistration
) external initializer;

Parameters

NameTypeDescription

_governor

address

The address of the {Governor_v1} contract.

initialMetadataRegistration

IModule_v1.Metadata[]

List of metadata that will be registered during the initialization.

initialBeaconRegistration

IInverterBeacon_v1[]

createAndInitModule

Creates a module instance identified by given metadata and initiates it.

function createAndInitModule(
    IModule_v1.Metadata memory metadata,
    IOrchestrator_v1 orchestrator,
    bytes memory configData,
    IOrchestratorFactory_v1.WorkflowConfig memory workflowConfig
) external returns (address);

Parameters

NameTypeDescription

metadata

IModule_v1.Metadata

The module's metadata.

orchestrator

IOrchestrator_v1

The {Orchestrator_v1} instance of the module.

configData

bytes

The configData of the module.

workflowConfig

IOrchestratorFactory_v1.WorkflowConfig

The configData of the workflow.

Returns

NameTypeDescription

<none>

address

moduleProxyAddress Returns the address of the created module proxy.

createModuleProxy

Creates a module proxy instance identified by given metadata.

function createModuleProxy(
    IModule_v1.Metadata memory metadata,
    IOrchestrator_v1 orchestrator,
    IOrchestratorFactory_v1.WorkflowConfig memory workflowConfig
) public returns (address);

Parameters

NameTypeDescription

metadata

IModule_v1.Metadata

The module's metadata.

orchestrator

IOrchestrator_v1

The {Orchestrator_v1} instance of the module.

workflowConfig

IOrchestratorFactory_v1.WorkflowConfig

The configData of the workflow.

Returns

NameTypeDescription

<none>

address

Returns the address of the created module proxy.

getBeaconAndId

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

function getBeaconAndId(IModule_v1.Metadata memory metadata)
    public
    view
    returns (IInverterBeacon_v1, bytes32);

Parameters

NameTypeDescription

metadata

IModule_v1.Metadata

The module's metadata.

Returns

NameTypeDescription

<none>

IInverterBeacon_v1

beacon The module's {IInverterBeacon_v1} instance registered.

<none>

bytes32

id The metadata's id.

getOrchestratorOfProxy

Returns the {Orchestrator_v1} address of a beacon proxy.

function getOrchestratorOfProxy(address proxy) public view returns (address);

Parameters

NameTypeDescription

proxy

address

The beacon proxy address.

Returns

NameTypeDescription

<none>

address

orchestratorAddress The corresponding {Orchestrator_v1} address for the provided proxy.

registerMetadata

Registers metadata metadata with {IInverterBeacon_v1} implementation beacon.

Only callable by owner.

function registerMetadata(
    IModule_v1.Metadata memory metadata,
    IInverterBeacon_v1 beacon
) external onlyOwner;

Parameters

NameTypeDescription

metadata

IModule_v1.Metadata

The module's metadata.

beacon

IInverterBeacon_v1

The module's {IInverterBeacon_v1} instance.

_registerMetadata

Internal function to register metadata.

function _registerMetadata(
    IModule_v1.Metadata memory metadata,
    IInverterBeacon_v1 beacon
) internal validMetadata(metadata) validBeacon(beacon);

Parameters

NameTypeDescription

metadata

IModule_v1.Metadata

The metadata to register.

beacon

IInverterBeacon_v1

The {IInverterBeacon_v1} to register the metadata to.

_createSalt

Internal function to generate a salt for the create2-based deployment flow. This salt is the hash of (msgSender, nonce), where the nonce is an increasing number for each user.

function _createSalt() internal returns (bytes32);

_msgSender

Needs to be overridden, because they are imported via the Ownable2Step as well.

function _msgSender()
    internal
    view
    virtual
    override(ERC2771ContextUpgradeable, ContextUpgradeable)
    returns (address sender);

_msgData

Needs to be overridden, because they are imported via the Ownable2Step as well.

function _msgData()
    internal
    view
    virtual
    override(ERC2771ContextUpgradeable, ContextUpgradeable)
    returns (bytes calldata);

_contextSuffixLength

function _contextSuffixLength()
    internal
    view
    virtual
    override(ERC2771ContextUpgradeable, ContextUpgradeable)
    returns (uint);

Last updated