Module_v1.sol

Git Source

Inherits: IModule_v1, Initializable, ERC2771ContextUpgradeable, ERC165Upgradeable

Author: Inverter Network

This Contract is the basic building block for all Modules in the Inverter Network. It contains references to other contracts, modifier for access restriction, metadata to identify the module type as well as utility functions for general module interactions. This contract provides a framework for triggering and receiving {Orchestrator_v1} callbacks (via call) and a modifier to authenticate callers via the module's {Orchestrator_v1}. Each module is identified via a unique identifier based on its major version, title, and url given in the metadata.

State Variables

__Module_orchestrator

The module's orchestrator instance.

IOrchestrator_v1 internal __Module_orchestrator;

__Module_metadata

The module's metadata.

Metadata internal __Module_metadata;

__gap

Storage gap for future upgrades.

uint[50] private __gap;

Functions

supportsInterface

See {IERC165-supportsInterface}.

onlyOrchestratorAdmin

Modifier to guarantee function is only callable by addresses authorized via {Orchestrator_v1}.

onlyPaymentClient

Modifier to guarantee function is only callable by a module registered within the workflows's {Orchestrator_v1} and the module is implementing the {IERC20PaymentClientBase_v1} interface.

onlyModuleRole

Modifier to guarantee function is only callable by addresses that hold a specific module-assigned role.

onlyModuleRoleAdmin

Modifier to guarantee function is only callable by addresses that hold a specific module-assigned role.

onlyOrchestrator

Modifier to guarantee function is only callable by the {Orchestrator_v1}.

onlyOrchestrator functions MUST only access the module's storage, i.e. __Module_ variables.

Note to use function prefix __Module_.

validAddress

Checks if the given Address is valid.

Parameters

Name
Type
Description

to

address

The address to check.

constructor

init

The module's initializer function.

CAN be overridden by downstream contract.

Parameters

Name
Type
Description

orchestrator_

IOrchestrator_v1

metadata

Metadata

The module's metadata.

<none>

bytes

__Module_init

The initialization function MUST be called by the upstream contract in their overridden init() function.

Parameters

Name
Type
Description

orchestrator_

IOrchestrator_v1

The module's {Orchestrator_v1}.

metadata

Metadata

identifier

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.

Returns

Name
Type
Description

<none>

bytes32

The module's identifier.

version

Returns the module's version.

Returns

Name
Type
Description

<none>

uint256

The module's major version.

<none>

uint256

<none>

uint256

url

Returns the module's URL.

Returns

Name
Type
Description

<none>

string

The module's URL.

title

Returns the module's title.

Returns

Name
Type
Description

<none>

string

The module's title.

orchestrator

Returns the module's {Orchestrator_v1} interface, {IOrchestrator_v1}.

Returns

Name
Type
Description

<none>

IOrchestrator_v1

The module's {Orchestrator_1}.

grantModuleRole

Grants a module role to a target address.

Parameters

Name
Type
Description

role

bytes32

The role to grant.

target

address

The target address to grant the role to.

grantModuleRoleBatched

Grants a module role to multiple target addresses.

Parameters

Name
Type
Description

role

bytes32

The role to grant.

targets

address[]

The target addresses to grant the role to.

revokeModuleRole

Revokes a module role from a target address.

Parameters

Name
Type
Description

role

bytes32

The role to revoke.

target

address

The target address to revoke the role from.

revokeModuleRoleBatched

Revokes a module role from multiple target addresses.

Parameters

Name
Type
Description

role

bytes32

The role to revoke.

targets

address[]

The target addresses to revoke the role from.

_getFeeManagerCollateralFeeData

Returns the collateral fee for the specified workflow module function and the according treasury address of this workflow.

FunctionSelector is always passed as selector of this module / address.

Parameters

Name
Type
Description

functionSelector

bytes4

The function selector of the target function.

Returns

Name
Type
Description

fee

uint256

The collateral fee amount in relation to the BPS of the {FeeManager_v1}.

treasury

address

The address of the treasury.

_getFeeManagerIssuanceFeeData

Returns the issuance fee for the specified workflow module function and the according treasury address of this workflow.

FunctionSelector is always passed as selector of this module / address.

Parameters

Name
Type
Description

functionSelector

bytes4

The function selector of the target function.

Returns

Name
Type
Description

fee

uint256

The issuance fee amount in relation to the BPS of the {FeeManager_v1}.

treasury

address

The address of the treasury.

_checkRoleModifier

Checks if the caller has the specified role.

Parameters

Name
Type
Description

role

bytes32

The role to check.

addr

address

The address to check.

_onlyOrchestratorModifier

Checks if the caller is the orchestrator.

_validAddressModifier

Checks if the given address is an valid address.

Parameters

Name
Type
Description

to

address

The address to check.

_onlyPaymentClientModifier

Checks if the caller is an {ERC20PaymentClientBase_v1} module.

isTrustedForwarder

Checks if the provided address is the trusted forwarder.

We imitate here the EIP2771 Standard to enable metatransactions As it currently stands we dont want to feed the forwarder address to each module individually and we decided to move this to the orchestrator.

Parameters

Name
Type
Description

forwarder

address

The contract address to be verified.

Returns

Name
Type
Description

<none>

bool

bool Is the given address the trusted forwarder.

trustedForwarder

Returns the trusted forwarder.

We imitate here the EIP2771 Standard to enable metatransactions. As it currently stands we dont want to feed the forwarder address to each module individually and we decided to move this to the orchestrator.

Returns

Name
Type
Description

<none>

address

address The trusted forwarder.

Last updated