# OrchestratorFactory\_v1.sol

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/2a8a4c80ff4f24a59546d4e6126b81bc51228c94/src/factories/OrchestratorFactory_v1.sol)

**Inherits:** [IOrchestratorFactory\_v1](https://docs.inverter.network/contracts/technical-reference/factories/interfaces/iorchestratorfactory_v1.sol), [ERC2771ContextUpgradeable](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/f1b3e103cd6d48861e71357a7ac32b416c1b066f/contracts/metatx/ERC2771ContextUpgradeable.sol), [Ownable2StepUpgradeable](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/access/Ownable2StepUpgradeable.sol), [ERC165Upgradeable](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/utils/introspection/ERC165Upgradeable.sol)

**Author:** Inverter Network

OrchestratorFactory\_v1 facilitates the deployment of [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol)s and their associated modules for the Inverter Network, ensuring seamless creation and configuration of various components in a single transaction.

*Utilizes* [*{ERC2771ContextUpgradeable}*](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/f1b3e103cd6d48861e71357a7ac32b416c1b066f/contracts/metatx/ERC2771ContextUpgradeable.sol) *for meta-transaction capabilities and* [*{ERC165Upgradeable}*](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/utils/introspection/ERC165Upgradeable.sol) *for interface detection.* [*{Orchestrator\_v1}*](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol)*s are deployed through EIP-1167 minimal proxies for efficiency. Integrates with the module factory to instantiate necessary modules with custom configurations, supporting complex setup with interdependencies among modules.*

### State Variables

#### beacon

Returns the [{IOrchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/interfaces/iorchestrator_v1.sol) [{IInverterBeacon\_v1}](https://docs.inverter.network/contracts/technical-reference/proxies/interfaces/iinverterbeacon_v1.sol) address.

```solidity
IInverterBeacon_v1 public override beacon;
```

#### moduleFactory

Returns the [{IModuleFactory\_v1}](https://docs.inverter.network/contracts/technical-reference/factories/interfaces/imodulefactory_v1.sol) implementation address.

```solidity
address public override moduleFactory;
```

#### \_orchestrators

*Maps the `id` to the* [*{Orchestrator\_v1}*](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol)*s.*

```solidity
mapping(uint => address) private _orchestrators;
```

#### \_orchestratorIdCounter

*The counter of the current* [*{Orchestrator\_v1}*](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol) *`id`.*

*Starts counting from 1.*

```solidity
uint private _orchestratorIdCounter;
```

#### \_deploymentNonces

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

```solidity
mapping(address => uint) private _deploymentNonces;
```

#### \_\_gap

*Storage gap for future upgrades.*

```solidity
uint[50] private __gap;
```

### Functions

#### supportsInterface

*See* [*{IERC165-supportsInterface}*](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/utils/introspection/IERC165.sol#L24)*.*

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

#### validOrchestratorId

*Modifier to guarantee that the given id is valid.*

```solidity
modifier validOrchestratorId(uint id);
```

#### constructor

```solidity
constructor(address _trustedForwarder)
    ERC2771ContextUpgradeable(_trustedForwarder);
```

#### init

The factories initializer function.

```solidity
function init(
    address governor_,
    IInverterBeacon_v1 beacon_,
    address moduleFactory_
) external initializer;
```

**Parameters**

| Name             | Type                 | Description                                                                                                                                                                                                                                                                                         |
| ---------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `governor_`      | `address`            | The address of the [{Governor\_v1}](https://docs.inverter.network/contracts/technical-reference/external/governance/governor_v1.sol) contract.                                                                                                                                                      |
| `beacon_`        | `IInverterBeacon_v1` | The address of the [{IInverterBeacon\_v1}](https://docs.inverter.network/contracts/technical-reference/proxies/interfaces/iinverterbeacon_v1.sol) containing the [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol) implementation. |
| `moduleFactory_` | `address`            | The address of the [{ModuleFactory\_v1}](https://docs.inverter.network/contracts/technical-reference/factories/modulefactory_v1.sol) contract.                                                                                                                                                      |

#### createOrchestrator

Creates a new [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol).

```solidity
function createOrchestrator(
    WorkflowConfig memory workflowConfig,
    ModuleConfig memory fundingManagerConfig,
    ModuleConfig memory authorizerConfig,
    ModuleConfig memory paymentProcessorConfig,
    ModuleConfig[] memory moduleConfigs
) external returns (IOrchestrator_v1);
```

**Parameters**

| Name                     | Type             | Description                                                                                                                                                                                                                                                                   |
| ------------------------ | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `workflowConfig`         | `WorkflowConfig` | The workflow's config data.                                                                                                                                                                                                                                                   |
| `fundingManagerConfig`   | `ModuleConfig`   | The config data for the orchestrator's [{IFundingManager\_v1} ](https://docs.inverter.network/contracts/technical-reference/modules/funding-manager/ifundingmanager_v1.sol)instance.                                                                                          |
| `authorizerConfig`       | `ModuleConfig`   | The config data for the [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol)'s [{IAuthorizer\_v1}](https://docs.inverter.network/contracts/technical-reference/modules/authorizer/iauthorizer_v1.sol) instance. |
| `paymentProcessorConfig` | `ModuleConfig`   | The config data for the orchestrator's [{IPaymentProcessor\_v1} ](https://docs.inverter.network/contracts/technical-reference/modules/payment-processor/ipaymentprocessor_v1.sol)instance.                                                                                    |
| `moduleConfigs`          | `ModuleConfig[]` | Variable length set of optional module's config data.                                                                                                                                                                                                                         |

**Returns**

| Name     | Type               | Description                                                   |
| -------- | ------------------ | ------------------------------------------------------------- |
| `<none>` | `IOrchestrator_v1` | CreatedOrchestrator Returns the created orchestrator instance |

#### getOrchestratorByID

Returns the [{IOrchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/interfaces/iorchestrator_v1.sol) address that corresponds to the given id.

```solidity
function getOrchestratorByID(uint id)
    external
    view
    validOrchestratorId(id)
    returns (address);
```

**Parameters**

| Name | Type      | Description                      |
| ---- | --------- | -------------------------------- |
| `id` | `uint256` | The requested orchestrator's id. |

**Returns**

| Name     | Type      | Description                                                                                                                                                              |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `<none>` | `address` | orchestratorAddress The address of the corresponding [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol). |

#### getOrchestratorIDCounter

Returns the counter of the current [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol) id.

```solidity
function getOrchestratorIDCounter() external view returns (uint);
```

**Returns**

| Name     | Type      | Description                                                                                                                                       |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<none>` | `uint256` | id The id of the next created [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol). |

#### \_createModuleProxies

*Creates the modules based on their \`moduleConfigs\`.*

```solidity
function _createModuleProxies(
    ModuleConfig[] memory moduleConfigs,
    address orchestratorProxy,
    WorkflowConfig memory workflowConfig
) internal returns (address[] memory);
```

**Parameters**

| Name                | Type             | Description                                                                                                                                                                     |
| ------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `moduleConfigs`     | `ModuleConfig[]` | The config data of the modules that will be created with this function call.                                                                                                    |
| `orchestratorProxy` | `address`        | The address of the [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol) Proxy that will be linked to the modules. |
| `workflowConfig`    | `WorkflowConfig` | The workflow's config data.                                                                                                                                                     |

#### \_initModules

*Internal function to initialize the modules.*

```solidity
function _initModules(
    address[] memory modules,
    ModuleConfig[] memory moduleConfigs,
    address proxy
) internal;
```

**Parameters**

| Name            | Type             | Description                                                                                                                                                                     |
| --------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `modules`       | `address[]`      | The modules to initialize.                                                                                                                                                      |
| `moduleConfigs` | `ModuleConfig[]` | The config data of the modules that will be initialized.                                                                                                                        |
| `proxy`         | `address`        | The address of the [{Orchestrator\_v1}](https://docs.inverter.network/contracts/technical-reference/orchestrator/orchestrator_v1.sol) Proxy that will be linked to the modules. |

#### \_createSalt

*Internal function to generate 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.*

```solidity
function _createSalt() internal returns (bytes32);
```

#### \_msgSender

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

```solidity
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.

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

#### \_contextSuffixLength

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