Skip to content
Rahul Saxena edited this page Aug 14, 2023 · 7 revisions

File: Module.sol

Things to know

  1. This contract acts as the base contract for modules.
  2. This contract provides a framework for triggering and receiving orchestrator callbacks (via call)
  3. This contract also provides a modifier to authenticate callers via the module's orchestrator.
  4. Each module is identified via a unique identifier based on its major version, title, and url given in the metadata.
  5. Modules will automatically be updated in case of minor updates, however they won't be automatically updated in case of major updates

Modifier(s)

1. onlyAuthorized

modifier onlyAuthorized()

Modifier to guarantee function is only callable by addresses authorized via Orchestrator.

2. onlyOrchestrator

modifier onlyOrchestrator() 

Modifier to guarantee function is only callable by the orchestrator. onlyOrchestrator functions MUST only access the module's storage, i.e. __Module_ variables. Advised to use function prefix __Module_

3. onlyAuthorizedOrManager()

modifier onlyAuthorizedOrManager()

Modifier to guarantee function is only callable either by addresses authorized via Orchestrator or the Orchestrator's manager.

4. initializer2

modifier initializer2()

Same functioning as the OpenZeppelin initializer, which is to prevent re-initialization of init functions, but for the init2 function.

5. validDependencyData

modifier validDependencyData(bytes memory dependencyData)

Modifier to ensure that the dependencyData passed is valid or not. This simply checks whether the first decoded element from the dependencyData is a boolean or not and then whether it is true or not.

View Function(s)

1. identifier

function identifier() external view returns (bytes32);

Returns the module's identifier. The identifier is defined as the keccak256 hash of the module's abi packed encoded major version, URL, and title.

Return Data

  1. Returns the module's identifier. (Each module is identified via a unique identifier based on its major version, title, and url given in the metadata.)

2. version

function version() external view returns (uint, unit);

This function returns the module's version.

Return data

  1. The module's major version.
  2. The module's minor version.

3. url

function url() external view returns (string memory);

This function returns the module's URL.

Return data

  1. The module's URL.

4. title

function title() external view returns (string memory);

This function returns the module's title.

Return data

  1. The module's title.

5. ##orchestrator**

function orchestrator() external view returns (IOrchestrator);

This function returns the module's {IOrchestrator} orchestrator instance.

Return data

  1. The module's orchestrator.

Write Function(s)

1. init

function init( IOrchestrator orchestrator, Metadata memory metadata, bytes memory configdata) external;

The module's initializer function. CAN be overriden by downstream contract. MUST call __Module_init().

Parameter(s)

  1. IOrchestrator orchestrator -> The module's orchestrator instance.
  2. Metadata metadata -> The module's metadata.
  3. bytes configdata -> Variable config data for specific module implementations.

2. init2

function init2(IOrchestrator orchestrator, bytes memory configData)
        external;

This is the second initialization function of the module to take care of (cross)dependencies.

Parameters

  1. IOrchestrator orchestrator: The module's orchestrator instance.
  2. bytes configData: Variable config data for specific module implementations.

Extra Explanations

This is a section of the documentation that breaks down the Module documentation in more granular details.

Modules

Modules are used within the Inverter Network to implement specific business logic that can be added to an orchestrator during its initialization.

Trust assumptions

Modules must be trusted by the orchestrator creator.

Initilization

Modules are activated in an orchestrator during its initialization. They can be deactivated by authorized addresses at any time.

The contract provides a __Module_init(orchestrator) function for initialization that MUST be called during the downstream module contract's init() function in order to correctly initialize the storage.

The init() function is declared inside the base Module contract and, therefore, has to be implemented inside the downstream contract.

Similarly, the init2() function is also declared inside the base Module contract and can be implemented inside the downstream contracts if that module has a requirement for a late dependency injection.

User Authentication

Users are authenticated using the orchestrator's IAuthenticator instance. This ensures that all access management is handled solely by the orchestrator.

Orchestrator Callbacks

The base Module contract (src/modules/base/Module.sol) provides a framework for triggering and receiving orchestrator callbacks (via call) and a modifier to authenticate callers via the module's orchestrator using the IAuthorizer interface.

A module can trigger a callback from its orchestrator via the internal _triggerOrchestratorCallback(bytes memory data) function. The callback is executed via call in the module's context.

Per convention, the function name SHOULD be prefixed with __Module_.

Orchestrator callbacks executed in the module's context MUST be authenticated via the onlyOrchestrator modifier!