# InverterBeacon\_v1.sol

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

**Inherits:** [IInverterBeacon\_v1](https://docs.inverter.network/contracts/technical-reference/proxies/interfaces/iinverterbeacon_v1.sol), [ERC165](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/utils/introspection/ERC165.sol), [Ownable2Step](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/access/Ownable2Step.sol)

**Author:** Inverter Network

Manages upgrades and versioning for smart contract implementations, allowing contract administrators to dynamically change contract logic while maintaining the state. Supports emergency shutdown mechanisms to halt operations if needed.

*Extends*[ *{ERC165}*](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/utils/introspection/ERC165.sol) *for interface detection and implements both* [*{IInverterBeacon\_v1}*](https://docs.inverter.network/contracts/technical-reference/proxies/interfaces/iinverterbeacon_v1.sol) *and* [*{IBeacon}*](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/proxy/beacon/IBeacon.sol)*. Uses modifiers to enforce constraints on implementation upgrades. Unique features include emergency mode control and strict version handling with major, minor and patch version concepts.*

### State Variables

#### \_reverterAddress

*The address of the contract that will revert all transactions. Can only be set via the `constructor()` function.*

```solidity
address internal _reverterAddress;
```

#### \_implementationAddress

*The InverterBeacon\_v1's implementation address. Can only be changed via the `_setImplementation()` function.*

```solidity
address internal _implementationAddress;
```

#### \_implementationPointer

*The* [*{InverterBeacon\_v1}*](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol)*'s current implementation pointer. In case of emergency can be set to `_reverterAddress` to pause functionality.*

```solidity
address internal _implementationPointer;
```

#### \_emergencyMode

*Is the* [*{InverterBeacon\_v1}*](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol) *shut down / in emergency mode.*

```solidity
bool internal _emergencyMode;
```

#### majorVersion

*The major version of the implementation.*

```solidity
uint internal majorVersion;
```

#### minorVersion

*The minor version of the implementation.*

```solidity
uint internal minorVersion;
```

#### patchVersion

*The patch version of the implementation.*

```solidity
uint internal patchVersion;
```

### 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
    returns (bool);
```

#### validImplementation

*Modifier to ensure the implementation is valid.*

```solidity
modifier validImplementation(address newImplementation);
```

#### validNewMinorOrPatchVersion

*Modifier to ensure the new minor or patch version is valid.*

```solidity
modifier validNewMinorOrPatchVersion(
    uint newMinorVersion,
    uint newPatchVersion
);
```

#### constructor

```solidity
constructor(
    address reverter,
    address owner,
    uint _majorVersion,
    address _implementation,
    uint _newMinorVersion,
    uint _newPatchVersion
) Ownable(owner);
```

#### implementation

*Must return an address that can be used as a delegate call target. {UpgradeableBeacon} will check that this address is a contract.*

```solidity
function implementation() public view virtual override returns (address);
```

#### getReverterAddress

Returns the [{InverterReverter\_v1}](https://docs.inverter.network/contracts/technical-reference/external/reverter/inverterreverter_v1.sol) of the [{InverterBeacon\_v1}](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol).

```solidity
function getReverterAddress() external view virtual returns (address);
```

**Returns**

| Name     | Type      | Description                                           |
| -------- | --------- | ----------------------------------------------------- |
| `<none>` | `address` | ReverterAddress The address of the reverter contract. |

#### getImplementationAddress

Returns the implementation address of the [{InverterBeacon\_v1}](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol).

```solidity
function getImplementationAddress() external view virtual returns (address);
```

**Returns**

| Name     | Type      | Description                                              |
| -------- | --------- | -------------------------------------------------------- |
| `<none>` | `address` | ImplementationAddress The address of the implementation. |

#### emergencyModeActive

Returns wether the [{InverterBeacon\_v1](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol)} is in emergency mode or not.

```solidity
function emergencyModeActive() external view returns (bool);
```

**Returns**

| Name     | Type   | Description                                          |
| -------- | ------ | ---------------------------------------------------- |
| `<none>` | `bool` | emergencyModeActive Is the beacon in emergency mode. |

#### version

Returns the version of the linked implementation.

```solidity
function version() external view returns (uint, uint, uint);
```

**Returns**

| Name     | Type      | Description    |
| -------- | --------- | -------------- |
| `<none>` | `uint256` | Major version. |
| `<none>` | `uint256` | Minor version. |
| `<none>` | `uint256` | Patch version. |

#### upgradeTo

Upgrades the [{InverterBeacon\_v1](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol)} to a new implementation address.

*Only callable by owner.*

```solidity
function upgradeTo(
    address newImplementation,
    uint newMinorVersion,
    uint newPatchVersion,
    bool overrideShutdown
)
    public
    onlyOwner
    validNewMinorOrPatchVersion(newMinorVersion, newPatchVersion);
```

**Parameters**

| Name                | Type      | Description                                                 |
| ------------------- | --------- | ----------------------------------------------------------- |
| `newImplementation` | `address` | The new implementation address.                             |
| `newMinorVersion`   | `uint256` | The new minor version of the implementation contract.       |
| `newPatchVersion`   | `uint256` | The new patch version of the implementation contract.       |
| `overrideShutdown`  | `bool`    | Flag to enable upgradeTo function to override the shutdown. |

#### shutDownImplementation

Shuts down the [{InverterBeacon\_v1](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol)} and stops the system.

*Only callable by owner.*

```solidity
function shutDownImplementation() external onlyOwner;
```

#### restartImplementation

Restarts the [{InverterBeacon\_v1](https://docs.inverter.network/contracts/technical-reference/proxies/inverterbeacon_v1.sol)} and the system.

*Only callable by owner.*

```solidity
function restartImplementation() external onlyOwner;
```

#### \_upgradeTo

*Internal function to upgrade the implementation.*

```solidity
function _upgradeTo(
    address newImplementation,
    uint newMinorVersion,
    uint newPatchVersion,
    bool overrideShutdown
) internal;
```

**Parameters**

| Name                | Type      | Description                                          |
| ------------------- | --------- | ---------------------------------------------------- |
| `newImplementation` | `address` | The new implementation address.                      |
| `newMinorVersion`   | `uint256` | The new minor version.                               |
| `newPatchVersion`   | `uint256` | The new patch version.                               |
| `overrideShutdown`  | `bool`    | If the upgrade process should override the shutdown. |

#### \_setImplementation

*Internal function to set the implementation.*

```solidity
function _setImplementation(address newImplementation, bool overrideShutdown)
    internal
    virtual
    validImplementation(newImplementation);
```

**Parameters**

| Name                | Type      | Description                                          |
| ------------------- | --------- | ---------------------------------------------------- |
| `newImplementation` | `address` | The new implementation address.                      |
| `overrideShutdown`  | `bool`    | If the upgrade process should override the shutdown. |
